Update factory reset to use integer for config reset by thebentern · Pull Request #917 · meshtastic/python · GitHub
Skip to content
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
2 changes: 1 addition & 1 deletion meshtastic/node.py
30 changes: 30 additions & 0 deletions meshtastic/tests/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,36 @@ def test_shutdown(caplog):
assert re.search(r"Telling node to shutdown", caplog.text, re.MULTILINE)


@pytest.mark.unit
def test_factoryReset_config_uses_int_field():
"""Test factoryReset(config) sets int32 protobuf field with an int value."""
iface = MagicMock(autospec=MeshInterface)
anode = Node(iface, 1234567890, noProto=True)

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)
Comment on lines +271 to +277

Copilot AI Apr 17, 2026

Copy link

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.


@pytest.mark.unit
def test_factoryReset_full_sets_device_field():
"""Test factoryReset(full=True) sets the full-device reset protobuf field."""
iface = MagicMock(autospec=MeshInterface)
anode = Node(iface, 1234567890, noProto=True)

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=True)

assert amesg.factory_reset_device is True

Copilot AI Apr 17, 2026

Copy link

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

Copilot uses AI. Check for mistakes.
mock_send_admin.assert_called_once_with(amesg, onResponse=anode.onAckNak)


@pytest.mark.unit
def test_setURL_empty_url(capsys):
"""Test reboot"""
Expand Down
Loading