Merge pull request #671 from ianmcorvidae/factory-reset-update

Split factory reset into two variants
This commit is contained in:
Ian McEwen
2024-09-11 09:43:16 -07:00
committed by GitHub
2 changed files with 18 additions and 7 deletions

View File

@@ -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",
)

View File

@@ -629,12 +629,16 @@ class Node:
)
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: