Skip to content

Commit 3f6ba1b

Browse files
authored
Allow forming a network quickly, without writing keys and tables (#208)
* Allow forming a network quickly, without writing keys and tables * Add a unit test
1 parent a73b278 commit 3f6ba1b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

tests/api/test_network_state.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from unittest import mock
23

34
import pytest
45

@@ -10,6 +11,7 @@
1011
FORMED_DEVICES,
1112
BaseZStack1CC2531,
1213
FormedZStack3CC2531,
14+
FormedLaunchpadCC26X2R1,
1315
)
1416

1517

@@ -92,3 +94,23 @@ async def test_state_write_tclk_zstack3(device, make_connected_znp, caplog):
9294

9395
# TCLK was not changed
9496
assert formed_znp.network_info == empty_znp.network_info
97+
98+
99+
@pytest.mark.parametrize("device", ALL_DEVICES)
100+
async def test_write_settings_fast(device, make_connected_znp):
101+
formed_znp, _ = await make_connected_znp(server_cls=FormedLaunchpadCC26X2R1)
102+
await formed_znp.load_network_info()
103+
formed_znp.close()
104+
105+
znp, _ = await make_connected_znp(server_cls=device)
106+
107+
formed_znp.network_info.stack_specific["form_quickly"] = True
108+
109+
with mock.patch("zigpy_znp.znp.security.write_devices") as mock_write_devices:
110+
await znp.write_network_info(
111+
network_info=formed_znp.network_info,
112+
node_info=formed_znp.node_info,
113+
)
114+
115+
# We don't waste time writing device info
116+
assert len(mock_write_devices.mock_awaits) == 0

zigpy_znp/api.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ async def write_network_info(
344344
"""
345345
from zigpy_znp.znp import security
346346

347-
await self.reset_network_info()
347+
if not network_info.stack_specific.get("form_quickly", False):
348+
await self.reset_network_info()
348349

349350
# Form a network with completely random settings to get NVRAM to a known state
350351
for item, value in {
@@ -377,6 +378,14 @@ async def write_network_info(
377378
await self.start_network()
378379
await self.reset()
379380

381+
if network_info.stack_specific.get("form_quickly", False):
382+
await self.nvram.osal_write(
383+
OsalNvIds.ZIGPY_ZNP_MIGRATION_ID,
384+
t.uint8_t(NVRAM_MIGRATION_ID),
385+
create=True,
386+
)
387+
return
388+
380389
LOGGER.debug("Writing actual network settings")
381390

382391
# Now that we have a formed network, update its state

0 commit comments

Comments
 (0)