From 17f36057365751d23db46557b4eb203e639d5734 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Thu, 5 Sep 2024 13:58:02 -0700 Subject: [PATCH] Ensure set-owner combined with set-owner-short sets both values --- meshtastic/__main__.py | 27 ++++++++++++--------------- meshtastic/node.py | 4 ++-- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index a8e1547..3184d2a 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -315,19 +315,16 @@ def onConnected(interface): # can include lat/long/alt etc: latitude = 37.5, longitude = -122.1 interface.localNode.setFixedPosition(lat, lon, alt) - if args.set_owner: + if args.set_owner or args.set_owner_short: closeNow = True waitForAckNak = True - print(f"Setting device owner to {args.set_owner}") - interface.getNode(args.dest, False).setOwner(args.set_owner) - - if args.set_owner_short: - closeNow = True - waitForAckNak = True - print(f"Setting device owner short to {args.set_owner_short}") - interface.getNode(args.dest, False).setOwner( - long_name=None, short_name=args.set_owner_short - ) + 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 + print(f"Setting device owner short to {args.set_owner_short}") + interface.getNode(args.dest, False).setOwner(long_name=args.set_owner, short_name=args.set_owner_short) # TODO: add to export-config and configure if args.set_canned_message: @@ -1452,6 +1449,10 @@ def initParser(): group.add_argument("--set-owner", help="Set device owner name", action="store") + group.add_argument( + "--set-owner-short", help="Set device owner short name", action="store" + ) + group.add_argument( "--set-canned-message", help="Set the canned messages plugin message (up to 200 characters).", @@ -1464,10 +1465,6 @@ def initParser(): action="store", ) - group.add_argument( - "--set-owner-short", help="Set device owner short name", action="store" - ) - group.add_argument( "--set-ham", help="Set licensed Ham ID and turn off encryption", action="store" ) diff --git a/meshtastic/node.py b/meshtastic/node.py index 48b9508..5f5ed7d 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -5,7 +5,7 @@ import base64 import logging import time -from typing import Union +from typing import Optional, Union from meshtastic.protobuf import admin_pb2, apponly_pb2, channel_pb2, localonly_pb2, mesh_pb2, portnums_pb2 from meshtastic.util import ( @@ -279,7 +279,7 @@ class Node: return c.index return 0 - def setOwner(self, long_name=None, short_name=None, is_licensed=False): + def setOwner(self, long_name: Optional[str]=None, short_name: Optional[str]=None, is_licensed: bool=False): """Set device owner name""" logging.debug(f"in setOwner nodeNum:{self.nodeNum}") p = admin_pb2.AdminMessage()