mirror of
https://github.com/meshtastic/python.git
synced 2026-01-13 18:28:03 -05:00
combine with set_owner handling
This commit is contained in:
@@ -339,36 +339,31 @@ 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 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)
|
||||
|
||||
if args.set_is_unmessageable:
|
||||
closeNow = True
|
||||
waitForAckNak = True
|
||||
print(f"Setting is_unmessagable to {args.set_is_unmessageable}")
|
||||
if isinstance(args.set_is_unmessageable, str):
|
||||
val = meshtastic.util.fromStr(args.set_is_unmessageable)
|
||||
else:
|
||||
val = args.set_is_unmessageable
|
||||
interface.getNode(args.dest, **getNode_kwargs).setIsUnmessageable(is_unmessagable=val)
|
||||
|
||||
if args.set_is_unmessagable:
|
||||
closeNow = True
|
||||
waitForAckNak = True
|
||||
print(f"Setting is_unmessagable to {args.set_is_unmessagable}")
|
||||
if isinstance(args.set_is_unmessagable, str):
|
||||
val = meshtastic.util.fromStr(args.set_is_unmessagable)
|
||||
else:
|
||||
val = args.set_is_unmessagable
|
||||
interface.getNode(args.dest, **getNode_kwargs).setIsUnmessageable(is_unmessagable=val)
|
||||
unmessageable = (
|
||||
args.set_is_unmessageable
|
||||
if args.set_is_unmessageable is not None
|
||||
else args.set_is_unmessagable
|
||||
)
|
||||
set_is_unmessagable = (
|
||||
meshtastic.util.fromStr(unmessageable)
|
||||
if isinstance(unmessageable, str)
|
||||
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:
|
||||
|
||||
@@ -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()
|
||||
@@ -315,27 +315,13 @@ 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}")
|
||||
# If sending to a remote node, wait for ACK/NAK
|
||||
if self == self.iface.localNode:
|
||||
onResponse = None
|
||||
else:
|
||||
onResponse = self.onAckNak
|
||||
return self._sendAdmin(p, onResponse=onResponse)
|
||||
|
||||
def setIsUnmessageable(self, is_unmessagable: Optional[bool]=False):
|
||||
"""Set if a device is messagable or not"""
|
||||
self.ensureSessionKey()
|
||||
p = admin_pb2.AdminMessage()
|
||||
|
||||
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.is_unmessagable:{p.set_owner.is_unmessagable}:")
|
||||
# If sending to a remote node, wait for ACK/NAK
|
||||
if self == self.iface.localNode:
|
||||
|
||||
@@ -466,7 +466,7 @@ def test_main_set_is_unmessageable_to_true(capsys):
|
||||
main()
|
||||
out, err = capsys.readouterr()
|
||||
assert re.search(r"Connected to radio", out, re.MULTILINE)
|
||||
assert re.search(r"Setting is_unmessagable to true", out, re.MULTILINE)
|
||||
assert re.search(r"Setting device owner is_unmessageable to True", out, re.MULTILINE)
|
||||
assert err == ""
|
||||
mo.assert_called()
|
||||
|
||||
@@ -482,7 +482,7 @@ def test_main_set_is_unmessagable_to_true(capsys):
|
||||
main()
|
||||
out, err = capsys.readouterr()
|
||||
assert re.search(r"Connected to radio", out, re.MULTILINE)
|
||||
assert re.search(r"Setting is_unmessagable to true", out, re.MULTILINE)
|
||||
assert re.search(r"Setting device owner is_unmessageable to True", out, re.MULTILINE)
|
||||
assert err == ""
|
||||
mo.assert_called()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user