Skip to content

Commit c5fc51e

Browse files
committed
Update factory reset to use integer for config reset
1 parent cec79a7 commit c5fc51e

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

meshtastic/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ def factoryReset(self, full: bool = False):
731731
p.factory_reset_device = True
732732
logger.info(f"Telling node to factory reset (full device reset)")
733733
else:
734-
p.factory_reset_config = True
734+
p.factory_reset_config = 1
735735
logger.info(f"Telling node to factory reset (config reset)")
736736

737737
# If sending to a remote node, wait for ACK/NAK

meshtastic/tests/test_node.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,36 @@ def test_shutdown(caplog):
262262
assert re.search(r"Telling node to shutdown", caplog.text, re.MULTILINE)
263263

264264

265+
@pytest.mark.unit
266+
def test_factoryReset_config_uses_int_field():
267+
"""Test factoryReset(config) sets int32 protobuf field with an int value."""
268+
iface = MagicMock(autospec=MeshInterface)
269+
anode = Node(iface, 1234567890, noProto=True)
270+
271+
amesg = admin_pb2.AdminMessage()
272+
with patch("meshtastic.admin_pb2.AdminMessage", return_value=amesg):
273+
with patch.object(anode, "_sendAdmin") as mock_send_admin:
274+
anode.factoryReset(full=False)
275+
276+
assert amesg.factory_reset_config == 1
277+
mock_send_admin.assert_called_once_with(amesg, onResponse=anode.onAckNak)
278+
279+
280+
@pytest.mark.unit
281+
def test_factoryReset_full_sets_device_field():
282+
"""Test factoryReset(full=True) sets the full-device reset protobuf field."""
283+
iface = MagicMock(autospec=MeshInterface)
284+
anode = Node(iface, 1234567890, noProto=True)
285+
286+
amesg = admin_pb2.AdminMessage()
287+
with patch("meshtastic.admin_pb2.AdminMessage", return_value=amesg):
288+
with patch.object(anode, "_sendAdmin") as mock_send_admin:
289+
anode.factoryReset(full=True)
290+
291+
assert amesg.factory_reset_device is True
292+
mock_send_admin.assert_called_once_with(amesg, onResponse=anode.onAckNak)
293+
294+
265295
@pytest.mark.unit
266296
def test_setURL_empty_url(capsys):
267297
"""Test reboot"""

0 commit comments

Comments
 (0)