Skip to content

Commit def8435

Browse files
committed
Implement reset_network_info
1 parent 9c535cd commit def8435

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

tests/application/test_startup.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from zigpy_znp.types.nvids import ExNvIds, OsalNvIds
1111

1212
from ..conftest import (
13+
ALL_DEVICES,
1314
EMPTY_DEVICES,
1415
FORMED_DEVICES,
1516
CoroutineMock,
@@ -270,7 +271,7 @@ async def test_zstack_build_id_empty(device, make_application, mocker):
270271

271272

272273
@pytest.mark.parametrize("device", [FormedLaunchpadCC26X2R1])
273-
async def test_deprecated_concurrency_config(device, make_application, mocker):
274+
async def test_deprecated_concurrency_config(device, make_application):
274275
with pytest.raises(vol.MultipleInvalid) as exc:
275276
app, znp_server = await make_application(
276277
server_cls=device,
@@ -282,3 +283,13 @@ async def test_deprecated_concurrency_config(device, make_application, mocker):
282283
)
283284

284285
assert "max_concurrent_requests" in str(exc.value)
286+
287+
288+
@pytest.mark.parametrize("device", ALL_DEVICES)
289+
async def test_reset_network_info(device, make_application):
290+
app, znp_server = await make_application(server_cls=device)
291+
await app.connect()
292+
await app.reset_network_info()
293+
294+
with pytest.raises(NetworkNotFormed):
295+
await app.start_network()

zigpy_znp/api.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,11 @@ async def start_network(self):
310310

311311
await asyncio.sleep(1)
312312

313-
async def write_network_info(
314-
self,
315-
*,
316-
network_info: zigpy.state.NetworkInfo,
317-
node_info: zigpy.state.NodeInfo,
318-
) -> None:
313+
async def reset_network_info(self):
319314
"""
320-
Writes network and node state to NVRAM.
315+
Resets node network information and leaves the current network.
321316
"""
322317

323-
from zigpy_znp.znp import security
324-
325318
# Delete any existing NV items that store formation state
326319
await self.nvram.osal_delete(OsalNvIds.HAS_CONFIGURED_ZSTACK1)
327320
await self.nvram.osal_delete(OsalNvIds.HAS_CONFIGURED_ZSTACK3)
@@ -336,6 +329,19 @@ async def write_network_info(
336329

337330
await self.reset()
338331

332+
async def write_network_info(
333+
self,
334+
*,
335+
network_info: zigpy.state.NetworkInfo,
336+
node_info: zigpy.state.NodeInfo,
337+
) -> None:
338+
"""
339+
Writes network and node state to NVRAM.
340+
"""
341+
from zigpy_znp.znp import security
342+
343+
await self.reset_network_info()
344+
339345
# Form a network with completely random settings to get NVRAM to a known state
340346
for item, value in {
341347
OsalNvIds.PANID: t.uint16_t(0xFFFF),

zigpy_znp/zigbee/application.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ async def load_network_info(self, *, load_devices=False) -> None:
161161
self.state.node_info = self._znp.node_info
162162
self.state.network_info = self._znp.network_info
163163

164+
async def reset_network_info(self) -> None:
165+
"""
166+
Resets node network information and leaves the current network.
167+
"""
168+
169+
await self._znp.reset_network_info()
170+
164171
async def write_network_info(
165172
self,
166173
*,

0 commit comments

Comments
 (0)