Skip to content

Commit 1b5b07e

Browse files
committed
add --set-is-unmessageable
1 parent ab997aa commit 1b5b07e

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

meshtastic/__main__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,26 @@ def onConnected(interface):
350350
print(f"Setting device owner short to {args.set_owner_short}")
351351
interface.getNode(args.dest, False, **getNode_kwargs).setOwner(long_name=args.set_owner, short_name=args.set_owner_short)
352352

353+
if args.set_is_unmessageable:
354+
closeNow = True
355+
waitForAckNak = True
356+
print(f"Setting is_unmessagable to {args.set_is_unmessageable}")
357+
if isinstance(args.set_is_unmessageable, str):
358+
val = meshtastic.util.fromStr(args.set_is_unmessageable)
359+
else:
360+
val = args.set_is_unmessageable
361+
interface.getNode(args.dest, **getNode_kwargs).setIsUnmessageable(is_unmessagable=val)
362+
363+
if args.set_is_unmessagable:
364+
closeNow = True
365+
waitForAckNak = True
366+
print(f"Setting is_unmessagable to {args.set_is_unmessageable}")
367+
if isinstance(args.set_is_unmessageable, str):
368+
val = meshtastic.util.fromStr(args.set_is_unmessageable)
369+
else:
370+
val = args.set_is_unmessageable
371+
interface.getNode(args.dest, **getNode_kwargs).setIsUnmessageable(is_unmessagable=val)
372+
353373
# TODO: add to export-config and configure
354374
if args.set_canned_message:
355375
closeNow = True
@@ -1540,6 +1560,13 @@ def addConfigArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
15401560
"--set-ham", help="Set licensed Ham ID and turn off encryption", action="store"
15411561
)
15421562

1563+
group.add_argument(
1564+
"--set-is-unmessageable", help="Set if a node is messageable or not", action="store"
1565+
)
1566+
1567+
group.add_argument(
1568+
"--set-is-unmessagable", help="Set if a node is messageable or not", action="store"
1569+
)
15431570
group.add_argument(
15441571
"--ch-set-url", "--seturl",
15451572
help="Set all channels and set LoRa config from a supplied URL",

meshtastic/node.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,23 @@ def setOwner(self, long_name: Optional[str]=None, short_name: Optional[str]=None
326326
else:
327327
onResponse = self.onAckNak
328328
return self._sendAdmin(p, onResponse=onResponse)
329+
330+
def setIsUnmessageable(self, is_unmessagable: Optional[bool]=False):
331+
"""Set if a device is messagable or not"""
332+
self.ensureSessionKey()
333+
p = admin_pb2.AdminMessage()
334+
335+
if is_unmessagable is not None:
336+
p.set_owner.is_unmessagable = is_unmessagable
337+
338+
# Note: These debug lines are used in unit tests
339+
logging.debug(f"p.set_owner.is_unmessageable:{p.set_owner.is_unmessagable}:")
340+
# If sending to a remote node, wait for ACK/NAK
341+
if self == self.iface.localNode:
342+
onResponse = None
343+
else:
344+
onResponse = self.onAckNak
345+
return self._sendAdmin(p, onResponse=onResponse)
329346

330347
def getURL(self, includeAll: bool = True):
331348
"""The sharable URL that describes the current channel"""

0 commit comments

Comments
 (0)