From c5fc51ea37dd2cf6446f137998376f2ef5f6c237 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 17 Apr 2026 05:03:56 -0500 Subject: [PATCH 1/2] 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""" From badf7279af12db7d7efcd039976f360daf02948b Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Sun, 31 May 2026 12:30:34 -0700 Subject: [PATCH 2/2] Update the other factory reset to use integer too --- meshtastic/node.py | 2 +- meshtastic/tests/test_node.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/meshtastic/node.py b/meshtastic/node.py index b806942..b18eff0 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -728,7 +728,7 @@ class Node: self.ensureSessionKey() p = admin_pb2.AdminMessage() if full: - p.factory_reset_device = True + p.factory_reset_device = 1 logger.info(f"Telling node to factory reset (full device reset)") else: p.factory_reset_config = 1 diff --git a/meshtastic/tests/test_node.py b/meshtastic/tests/test_node.py index c397fb0..bd0644d 100644 --- a/meshtastic/tests/test_node.py +++ b/meshtastic/tests/test_node.py @@ -269,7 +269,7 @@ def test_factoryReset_config_uses_int_field(): anode = Node(iface, 1234567890, noProto=True) amesg = admin_pb2.AdminMessage() - with patch("meshtastic.admin_pb2.AdminMessage", return_value=amesg): + with patch("meshtastic.node.admin_pb2.AdminMessage", return_value=amesg): with patch.object(anode, "_sendAdmin") as mock_send_admin: anode.factoryReset(full=False) @@ -284,11 +284,11 @@ def test_factoryReset_full_sets_device_field(): anode = Node(iface, 1234567890, noProto=True) amesg = admin_pb2.AdminMessage() - with patch("meshtastic.admin_pb2.AdminMessage", return_value=amesg): + with patch("meshtastic.node.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 + assert amesg.factory_reset_device == 1 mock_send_admin.assert_called_once_with(amesg, onResponse=anode.onAckNak)