Skip to content

Commit

Permalink
Allow forming a network quickly, without writing keys and tables (#208)
Browse files Browse the repository at this point in the history
* Allow forming a network quickly, without writing keys and tables

* Add a unit test
  • Loading branch information
puddly authored Mar 29, 2023
1 parent a73b278 commit 3f6ba1b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
22 changes: 22 additions & 0 deletions tests/api/test_network_state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from unittest import mock

import pytest

Expand All @@ -10,6 +11,7 @@
FORMED_DEVICES,
BaseZStack1CC2531,
FormedZStack3CC2531,
FormedLaunchpadCC26X2R1,
)


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

# TCLK was not changed
assert formed_znp.network_info == empty_znp.network_info


@pytest.mark.parametrize("device", ALL_DEVICES)
async def test_write_settings_fast(device, make_connected_znp):
formed_znp, _ = await make_connected_znp(server_cls=FormedLaunchpadCC26X2R1)
await formed_znp.load_network_info()
formed_znp.close()

znp, _ = await make_connected_znp(server_cls=device)

formed_znp.network_info.stack_specific["form_quickly"] = True

with mock.patch("zigpy_znp.znp.security.write_devices") as mock_write_devices:
await znp.write_network_info(
network_info=formed_znp.network_info,
node_info=formed_znp.node_info,
)

# We don't waste time writing device info
assert len(mock_write_devices.mock_awaits) == 0
11 changes: 10 additions & 1 deletion zigpy_znp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ async def write_network_info(
"""
from zigpy_znp.znp import security

await self.reset_network_info()
if not network_info.stack_specific.get("form_quickly", False):
await self.reset_network_info()

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

if network_info.stack_specific.get("form_quickly", False):
await self.nvram.osal_write(
OsalNvIds.ZIGPY_ZNP_MIGRATION_ID,
t.uint8_t(NVRAM_MIGRATION_ID),
create=True,
)
return

LOGGER.debug("Writing actual network settings")

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

0 comments on commit 3f6ba1b

Please sign in to comment.