Skip to content

Allow forming a network quickly, without writing keys and tables #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -345,7 +345,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 @@ -378,6 +379,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