Skip to content

Commit 04f9501

Browse files
authored
Implement channel migration (#220)
1 parent c310ce2 commit 04f9501

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tests/test_application.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,3 +588,22 @@ async def test_energy_scan(app):
588588
)
589589

590590
assert results == {c: c * 3 for c in Channels.ALL_CHANNELS}
591+
592+
593+
async def test_channel_migration(app):
594+
app._api.write_parameter = AsyncMock()
595+
app._change_network_state = AsyncMock()
596+
597+
await app._move_network_to_channel(new_channel=26, new_nwk_update_id=0x12)
598+
599+
assert app._api.write_parameter.mock_calls == [
600+
mock.call(
601+
deconz_api.NetworkParameter.channel_mask, Channels.from_channel_list([26])
602+
),
603+
mock.call(deconz_api.NetworkParameter.nwk_update_id, 0x12),
604+
]
605+
606+
assert app._change_network_state.mock_calls == [
607+
mock.call(deconz_api.NetworkState.OFFLINE),
608+
mock.call(deconz_api.NetworkState.CONNECTED),
609+
]

zigpy_deconz/zigbee/application.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,19 @@ async def energy_scan(
349349
# The Conbee seems to max out at an LQI of 85, which is exactly 255/3
350350
return {c: v * 3 for c, v in results.items()}
351351

352+
async def _move_network_to_channel(
353+
self, new_channel: int, new_nwk_update_id: int
354+
) -> None:
355+
"""Move device to a new channel."""
356+
channel_mask = zigpy.types.Channels.from_channel_list([new_channel])
357+
await self._api.write_parameter(NetworkParameter.channel_mask, channel_mask)
358+
await self._api.write_parameter(
359+
NetworkParameter.nwk_update_id, new_nwk_update_id
360+
)
361+
362+
await self._change_network_state(NetworkState.OFFLINE)
363+
await self._change_network_state(NetworkState.CONNECTED)
364+
352365
async def add_endpoint(self, descriptor: zdo_t.SimpleDescriptor) -> None:
353366
"""Register an endpoint on the device, replacing any with conflicting IDs."""
354367

0 commit comments

Comments
 (0)