From 21ff4a1a4a4e324c4b5f6b532df0aae3104d5022 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Wed, 11 Sep 2024 09:40:26 -0700 Subject: [PATCH] Split factory reset into two variants --- meshtastic/__main__.py | 15 +++++++++++---- meshtastic/node.py | 10 +++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 3184d2a3..eafb4922 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -416,10 +416,11 @@ def onConnected(interface): closeNow = True interface.getNode(args.dest, False).commitSettingsTransaction() - if args.factory_reset: + if args.factory_reset or args.factory_reset_device: closeNow = True waitForAckNak = True - interface.getNode(args.dest, False).factoryReset() + full = bool(args.factory_reset_device) + interface.getNode(args.dest, False).factoryReset(full=full) if args.remove_node: closeNow = True @@ -1549,8 +1550,14 @@ def initParser(): ) group.add_argument( - "--factory-reset", - help="Tell the destination node to install the default config", + "--factory-reset", "--factory-reset-config", + help="Tell the destination node to install the default config, preserving BLE bonds & PKI keys", + action="store_true", + ) + + group.add_argument( + "--factory-reset-device", + help="Tell the destination node to install the default config and clear BLE bonds & PKI keys", action="store_true", ) diff --git a/meshtastic/node.py b/meshtastic/node.py index ca1977c4..415154db 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -629,12 +629,16 @@ def getMetadata(self): ) self.iface.waitForAckNak() - def factoryReset(self): + def factoryReset(self, full: bool = False): """Tell the node to factory reset.""" self.ensureSessionKey() p = admin_pb2.AdminMessage() - p.factory_reset = True - logging.info(f"Telling node to factory reset") + if full: + p.factory_reset_device = True + logging.info(f"Telling node to factory reset (full device reset)") + else: + p.factory_reset_config = True + logging.info(f"Telling node to factory reset (config reset)") # If sending to a remote node, wait for ACK/NAK if self == self.iface.localNode: