Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split factory reset into two variants #671

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading