Skip to content

Commit 58967e1

Browse files
authored
Merge pull request #794 from pdxlocations/is-unmessageable
add --set-is-unmessageable to CLI commands
2 parents 4adcbb6 + 17f7e8e commit 58967e1

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

meshtastic/__main__.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def onConnected(interface):
339339
# can include lat/long/alt etc: latitude = 37.5, longitude = -122.1
340340
interface.getNode(args.dest, False, **getNode_kwargs).setFixedPosition(lat, lon, alt)
341341

342-
if args.set_owner or args.set_owner_short:
342+
if args.set_owner or args.set_owner_short or args.set_is_unmessageable:
343343
closeNow = True
344344
waitForAckNak = True
345345

@@ -358,9 +358,22 @@ def onConnected(interface):
358358
print(f"Setting device owner to {args.set_owner} and short name to {args.set_owner_short}")
359359
elif args.set_owner:
360360
print(f"Setting device owner to {args.set_owner}")
361-
else: # short name only
361+
elif args.set_owner_short and not args.set_owner:
362362
print(f"Setting device owner short to {args.set_owner_short}")
363-
interface.getNode(args.dest, False, **getNode_kwargs).setOwner(long_name=args.set_owner, short_name=args.set_owner_short)
363+
364+
if args.set_is_unmessageable:
365+
unmessagable = (
366+
meshtastic.util.fromStr(args.set_is_unmessageable)
367+
if isinstance(args.set_is_unmessageable, str)
368+
else args.set_is_unmessageable
369+
)
370+
371+
if unmessagable is not None:
372+
print(f"Setting device owner is_unmessageable to {unmessagable}")
373+
interface.getNode(
374+
args.dest, False, **getNode_kwargs).setOwner(long_name=args.set_owner,
375+
short_name=args.set_owner_short, is_unmessagable=unmessagable
376+
)
364377

365378
# TODO: add to export-config and configure
366379
if args.set_canned_message:
@@ -1595,6 +1608,11 @@ def addConfigArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
15951608
"--set-ham", help="Set licensed Ham ID and turn off encryption", action="store"
15961609
)
15971610

1611+
group.add_argument(
1612+
"--set-is-unmessageable", "--set-is-unmessagable",
1613+
help="Set if a node is messageable or not", action="store"
1614+
)
1615+
15981616
group.add_argument(
15991617
"--ch-set-url", "--seturl",
16001618
help="Set all channels and set LoRa config from a supplied URL",

meshtastic/node.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def _getAdminChannelIndex(self):
298298
return c.index
299299
return 0
300300

301-
def setOwner(self, long_name: Optional[str]=None, short_name: Optional[str]=None, is_licensed: bool=False):
301+
def setOwner(self, long_name: Optional[str]=None, short_name: Optional[str]=None, is_licensed: bool=False, is_unmessagable: Optional[bool]=None):
302302
"""Set device owner name"""
303303
logging.debug(f"in setOwner nodeNum:{self.nodeNum}")
304304
self.ensureSessionKey()
@@ -321,11 +321,14 @@ def setOwner(self, long_name: Optional[str]=None, short_name: Optional[str]=None
321321
short_name = short_name[:nChars]
322322
print(f"Maximum is 4 characters, truncated to {short_name}")
323323
p.set_owner.short_name = short_name
324+
if is_unmessagable is not None:
325+
p.set_owner.is_unmessagable = is_unmessagable
324326

325327
# Note: These debug lines are used in unit tests
326328
logging.debug(f"p.set_owner.long_name:{p.set_owner.long_name}:")
327329
logging.debug(f"p.set_owner.short_name:{p.set_owner.short_name}:")
328330
logging.debug(f"p.set_owner.is_licensed:{p.set_owner.is_licensed}")
331+
logging.debug(f"p.set_owner.is_unmessagable:{p.set_owner.is_unmessagable}:")
329332
# If sending to a remote node, wait for ACK/NAK
330333
if self == self.iface.localNode:
331334
onResponse = None

meshtastic/tests/test_main.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,37 @@ def test_main_set_owner_short_to_bob(capsys):
454454
assert err == ""
455455
mo.assert_called()
456456

457+
@pytest.mark.unit
458+
@pytest.mark.usefixtures("reset_mt_config")
459+
def test_main_set_is_unmessageable_to_true(capsys):
460+
"""Test --set-is-unmessageable true"""
461+
sys.argv = ["", "--set-is-unmessageable", "true"]
462+
mt_config.args = sys.argv
463+
464+
iface = MagicMock(autospec=SerialInterface)
465+
with patch("meshtastic.serial_interface.SerialInterface", return_value=iface) as mo:
466+
main()
467+
out, err = capsys.readouterr()
468+
assert re.search(r"Connected to radio", out, re.MULTILINE)
469+
assert re.search(r"Setting device owner is_unmessageable to True", out, re.MULTILINE)
470+
assert err == ""
471+
mo.assert_called()
472+
473+
@pytest.mark.unit
474+
@pytest.mark.usefixtures("reset_mt_config")
475+
def test_main_set_is_unmessagable_to_true(capsys):
476+
"""Test --set-is-unmessagable true"""
477+
sys.argv = ["", "--set-is-unmessagable", "true"]
478+
mt_config.args = sys.argv
479+
480+
iface = MagicMock(autospec=SerialInterface)
481+
with patch("meshtastic.serial_interface.SerialInterface", return_value=iface) as mo:
482+
main()
483+
out, err = capsys.readouterr()
484+
assert re.search(r"Connected to radio", out, re.MULTILINE)
485+
assert re.search(r"Setting device owner is_unmessageable to True", out, re.MULTILINE)
486+
assert err == ""
487+
mo.assert_called()
457488

458489
@pytest.mark.unit
459490
@pytest.mark.usefixtures("reset_mt_config")

nanopb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 4380dd9e947e6f40e1f31f9eaeda7994ac1872ae

0 commit comments

Comments
 (0)