From c5fc51ea37dd2cf6446f137998376f2ef5f6c237 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 17 Apr 2026 05:03:56 -0500 Subject: [PATCH] Update factory reset to use integer for config reset --- meshtastic/node.py | 2 +- meshtastic/tests/test_node.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/meshtastic/node.py b/meshtastic/node.py index 66b6312..b806942 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -731,7 +731,7 @@ class Node: 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)") # If sending to a remote node, wait for ACK/NAK diff --git a/meshtastic/tests/test_node.py b/meshtastic/tests/test_node.py index 986c178..c397fb0 100644 --- a/meshtastic/tests/test_node.py +++ b/meshtastic/tests/test_node.py @@ -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) + + +@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 + mock_send_admin.assert_called_once_with(amesg, onResponse=anode.onAckNak) + + @pytest.mark.unit def test_setURL_empty_url(capsys): """Test reboot"""