Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def factoryReset(self, full: bool = False):
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)")
Comment on lines 731 to 735
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.

# If sending to a remote node, wait for ACK/NAK
Expand Down
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
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.


@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
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.
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