Skip to content

add --set-is-unmessageable to CLI commands #794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,31 @@
# 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 or args.set_is_unmessagable:
closeNow = True
waitForAckNak = True
if args.set_owner and args.set_owner_short:
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)
unmessageable = (
args.set_is_unmessageable
if args.set_is_unmessageable is not None
else args.set_is_unmessagable
)

Check warning on line 355 in meshtastic/__main__.py

View check run for this annotation

Codecov / codecov/patch

meshtastic/__main__.py#L355

Added line #L355 was not covered by tests
set_is_unmessagable = (
meshtastic.util.fromStr(unmessageable)
if isinstance(unmessageable, str)

Check warning on line 358 in meshtastic/__main__.py

View check run for this annotation

Codecov / codecov/patch

meshtastic/__main__.py#L358

Added line #L358 was not covered by tests
else unmessageable
)
if set_is_unmessagable is not None:
print(f"Setting device owner is_unmessageable to {set_is_unmessagable}")
interface.getNode(
args.dest, False, **getNode_kwargs).setOwner(long_name=args.set_owner,
short_name=args.set_owner_short, is_unmessagable=set_is_unmessagable
)

# TODO: add to export-config and configure
if args.set_canned_message:
Expand Down Expand Up @@ -1540,6 +1555,13 @@
"--set-ham", help="Set licensed Ham ID and turn off encryption", action="store"
)

group.add_argument(
"--set-is-unmessageable", help="Set if a node is messageable or not", action="store"
)

group.add_argument(
"--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",
Expand Down
5 changes: 4 additions & 1 deletion meshtastic/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
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()
Expand All @@ -315,11 +315,14 @@
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}:")

Check warning on line 325 in meshtastic/node.py

View check run for this annotation

Codecov / codecov/patch

meshtastic/node.py#L325

Added line #L325 was not covered by tests
# If sending to a remote node, wait for ACK/NAK
if self == self.iface.localNode:
onResponse = None
Expand Down
31 changes: 31 additions & 0 deletions meshtastic/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading