mirror of
https://github.com/meshtastic/python.git
synced 2026-01-14 10:47:59 -05:00
Merge pull request #794 from pdxlocations/is-unmessageable
add --set-is-unmessageable to CLI commands
This commit is contained in:
@@ -339,7 +339,7 @@ def onConnected(interface):
|
||||
# can include lat/long/alt etc: latitude = 37.5, longitude = -122.1
|
||||
interface.getNode(args.dest, False, **getNode_kwargs).setFixedPosition(lat, lon, alt)
|
||||
|
||||
if args.set_owner or args.set_owner_short:
|
||||
if args.set_owner or args.set_owner_short or args.set_is_unmessageable:
|
||||
closeNow = True
|
||||
waitForAckNak = True
|
||||
|
||||
@@ -358,9 +358,22 @@ def onConnected(interface):
|
||||
print(f"Setting device owner to {args.set_owner} and short name to {args.set_owner_short}")
|
||||
elif args.set_owner:
|
||||
print(f"Setting device owner to {args.set_owner}")
|
||||
else: # short name only
|
||||
elif args.set_owner_short and not args.set_owner:
|
||||
print(f"Setting device owner short to {args.set_owner_short}")
|
||||
interface.getNode(args.dest, False, **getNode_kwargs).setOwner(long_name=args.set_owner, short_name=args.set_owner_short)
|
||||
|
||||
if args.set_is_unmessageable:
|
||||
unmessagable = (
|
||||
meshtastic.util.fromStr(args.set_is_unmessageable)
|
||||
if isinstance(args.set_is_unmessageable, str)
|
||||
else args.set_is_unmessageable
|
||||
)
|
||||
|
||||
if unmessagable is not None:
|
||||
print(f"Setting device owner is_unmessageable to {unmessagable}")
|
||||
interface.getNode(
|
||||
args.dest, False, **getNode_kwargs).setOwner(long_name=args.set_owner,
|
||||
short_name=args.set_owner_short, is_unmessagable=unmessagable
|
||||
)
|
||||
|
||||
# TODO: add to export-config and configure
|
||||
if args.set_canned_message:
|
||||
@@ -1595,6 +1608,11 @@ def addConfigArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
|
||||
"--set-ham", help="Set licensed Ham ID and turn off encryption", action="store"
|
||||
)
|
||||
|
||||
group.add_argument(
|
||||
"--set-is-unmessageable", "--set-is-unmessagable",
|
||||
help="Set if a node is messageable or not", action="store"
|
||||
)
|
||||
|
||||
group.add_argument(
|
||||
"--ch-set-url", "--seturl",
|
||||
help="Set all channels and set LoRa config from a supplied URL",
|
||||
|
||||
@@ -298,7 +298,7 @@ class Node:
|
||||
return c.index
|
||||
return 0
|
||||
|
||||
def setOwner(self, long_name: Optional[str]=None, short_name: Optional[str]=None, is_licensed: bool=False):
|
||||
def setOwner(self, long_name: Optional[str]=None, short_name: Optional[str]=None, is_licensed: bool=False, is_unmessagable: Optional[bool]=None):
|
||||
"""Set device owner name"""
|
||||
logging.debug(f"in setOwner nodeNum:{self.nodeNum}")
|
||||
self.ensureSessionKey()
|
||||
@@ -321,11 +321,14 @@ class Node:
|
||||
short_name = short_name[:nChars]
|
||||
print(f"Maximum is 4 characters, truncated to {short_name}")
|
||||
p.set_owner.short_name = short_name
|
||||
if is_unmessagable is not None:
|
||||
p.set_owner.is_unmessagable = is_unmessagable
|
||||
|
||||
# Note: These debug lines are used in unit tests
|
||||
logging.debug(f"p.set_owner.long_name:{p.set_owner.long_name}:")
|
||||
logging.debug(f"p.set_owner.short_name:{p.set_owner.short_name}:")
|
||||
logging.debug(f"p.set_owner.is_licensed:{p.set_owner.is_licensed}")
|
||||
logging.debug(f"p.set_owner.is_unmessagable:{p.set_owner.is_unmessagable}:")
|
||||
# If sending to a remote node, wait for ACK/NAK
|
||||
if self == self.iface.localNode:
|
||||
onResponse = None
|
||||
|
||||
@@ -454,6 +454,37 @@ def test_main_set_owner_short_to_bob(capsys):
|
||||
assert err == ""
|
||||
mo.assert_called()
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.usefixtures("reset_mt_config")
|
||||
def test_main_set_is_unmessageable_to_true(capsys):
|
||||
"""Test --set-is-unmessageable true"""
|
||||
sys.argv = ["", "--set-is-unmessageable", "true"]
|
||||
mt_config.args = sys.argv
|
||||
|
||||
iface = MagicMock(autospec=SerialInterface)
|
||||
with patch("meshtastic.serial_interface.SerialInterface", return_value=iface) as mo:
|
||||
main()
|
||||
out, err = capsys.readouterr()
|
||||
assert re.search(r"Connected to radio", out, re.MULTILINE)
|
||||
assert re.search(r"Setting device owner is_unmessageable to True", out, re.MULTILINE)
|
||||
assert err == ""
|
||||
mo.assert_called()
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.usefixtures("reset_mt_config")
|
||||
def test_main_set_is_unmessagable_to_true(capsys):
|
||||
"""Test --set-is-unmessagable true"""
|
||||
sys.argv = ["", "--set-is-unmessagable", "true"]
|
||||
mt_config.args = sys.argv
|
||||
|
||||
iface = MagicMock(autospec=SerialInterface)
|
||||
with patch("meshtastic.serial_interface.SerialInterface", return_value=iface) as mo:
|
||||
main()
|
||||
out, err = capsys.readouterr()
|
||||
assert re.search(r"Connected to radio", out, re.MULTILINE)
|
||||
assert re.search(r"Setting device owner is_unmessageable to True", out, re.MULTILINE)
|
||||
assert err == ""
|
||||
mo.assert_called()
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.usefixtures("reset_mt_config")
|
||||
|
||||
1
nanopb
Submodule
1
nanopb
Submodule
Submodule nanopb added at 4380dd9e94
Reference in New Issue
Block a user