Skip to content

Update factory reset to use integer for config reset#917

Open
thebentern wants to merge 1 commit intomasterfrom
fix-factory-reset
Open

Update factory reset to use integer for config reset#917
thebentern wants to merge 1 commit intomasterfrom
fix-factory-reset

Conversation

@thebentern
Copy link
Copy Markdown
Contributor

Alternative fix to #914

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to avoid protobuf runtime type errors (seen with newer protobuf versions) by updating the factory reset admin message to use an integer value for the config-reset field, as an alternative to dependency pinning discussed in #914.

Changes:

  • Update Node.factoryReset(full=False) to set factory_reset_config using an integer (1) instead of a boolean.
  • Add unit tests intended to validate the protobuf field assignments for config reset vs full device reset.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
meshtastic/node.py Changes the factory reset (config) protobuf field assignment to use an integer value.
meshtastic/tests/test_node.py Adds unit tests for factory reset behavior and expected protobuf field values.

Comment thread meshtastic/node.py
Comment on lines 731 to 735
p.factory_reset_device = True
logger.info(f"Telling node to factory reset (full device reset)")
else:
p.factory_reset_config = True
p.factory_reset_config = 1
logger.info(f"Telling node to factory reset (config reset)")
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

factory_reset_device is also an int32 field in AdminMessage (same as factory_reset_config). Leaving it as True will likely still raise a TypeError under newer protobuf runtimes that reject bools for int fields. Consider setting factory_reset_device to an int value (e.g., 1) for consistency and to fully address the factory reset compatibility issue.

Copilot uses AI. Check for mistakes.
Comment on lines +271 to +277
amesg = admin_pb2.AdminMessage()
with patch("meshtastic.admin_pb2.AdminMessage", return_value=amesg):
with patch.object(anode, "_sendAdmin") as mock_send_admin:
anode.factoryReset(full=False)

assert amesg.factory_reset_config == 1
mock_send_admin.assert_called_once_with(amesg, onResponse=anode.onAckNak)
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests patch "meshtastic.admin_pb2.AdminMessage", but there is no meshtastic/admin_pb2.py module in the source tree; the generated module is meshtastic.protobuf.admin_pb2, and Node references admin_pb2 from meshtastic.node. This patch target will raise ModuleNotFoundError (or won’t affect Node.factoryReset) and the assertions against amesg won’t be validating the message actually sent. Patch the symbol where it is used (e.g., "meshtastic.node.admin_pb2.AdminMessage" or "meshtastic.protobuf.admin_pb2.AdminMessage"), or alternatively assert on the AdminMessage instance passed to _sendAdmin via mock_send_admin.call_args.

Copilot uses AI. Check for mistakes.
with patch.object(anode, "_sendAdmin") as mock_send_admin:
anode.factoryReset(full=True)

assert amesg.factory_reset_device is True
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

factory_reset_device is an int32 field in AdminMessage, so asserting is True will either fail (if the code is corrected to use an int) or will lock in the bool assignment that breaks under newer protobuf type checking. Update this assertion to expect an int value (e.g., 1) consistent with the protobuf field type and the config-reset test.

Suggested change
assert amesg.factory_reset_device is True
assert amesg.factory_reset_device == 1

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants