Update factory reset to use integer for config reset#917
Update factory reset to use integer for config reset#917thebentern wants to merge 1 commit intomasterfrom
Conversation
There was a problem hiding this comment.
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 setfactory_reset_configusing 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. |
| 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)") |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
| with patch.object(anode, "_sendAdmin") as mock_send_admin: | ||
| anode.factoryReset(full=True) | ||
|
|
||
| assert amesg.factory_reset_device is True |
There was a problem hiding this comment.
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.
| assert amesg.factory_reset_device is True | |
| assert amesg.factory_reset_device == 1 |
Alternative fix to #914