Skip to content

Commit

Permalink
Merge pull request #671 from ianmcorvidae/factory-reset-update
Browse files Browse the repository at this point in the history
Split factory reset into two variants
  • Loading branch information
ianmcorvidae authored Sep 11, 2024
2 parents ef6db0e + 21ff4a1 commit 23e6eca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 11 additions & 4 deletions meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
)

Expand Down
10 changes: 7 additions & 3 deletions meshtastic/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 23e6eca

Please sign in to comment.