Skip to content

Commit

Permalink
Disable energy scanning and implement channel migration (#144)
Browse files Browse the repository at this point in the history
* Disable energy scanning

* Implement channel migration
  • Loading branch information
puddly authored Apr 24, 2023
1 parent 455373d commit 2f1fb28
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/test_application.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest.mock import AsyncMock, MagicMock, patch, sentinel
from unittest.mock import AsyncMock, MagicMock, patch, sentinel, call

import pytest
import logging
Expand Down Expand Up @@ -178,3 +178,24 @@ async def test_send_group_request(app):
await app.send_packet(packet)

app._api.raw_aps_data_request.assert_called_once()


@pytest.mark.asyncio
async def test_energy_scanning(app, caplog):
with caplog.at_level(logging.WARNING):
scan_results = await app.energy_scan(channels=zigpy_t.Channels.ALL_CHANNELS, duration_exp=2, count=5)

assert scan_results == {c: 0 for c in zigpy_t.Channels.ALL_CHANNELS}

# We never send a request when scanning
assert len(app._api.raw_aps_data_request.mock_calls) == 0

assert "does not support energy scanning" in caplog.text


@pytest.mark.asyncio
async def test_channel_migration(app, caplog):
app._api.set_channel = AsyncMock()
await app._move_network_to_channel(17, new_nwk_update_id=2)

assert app._api.set_channel.mock_calls == [call(17)]
14 changes: 14 additions & 0 deletions zigpy_zigate/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ async def write_network_info(self, *, network_info, node_info):
async def permit_with_key(self, node, code, time_s = 60):
LOGGER.warning("ZiGate does not support joins with install codes")

async def _move_network_to_channel(
self, new_channel: int, *, new_nwk_update_id: int
) -> None:
"""Moves the network to a new channel."""
await self._api.set_channel(new_channel)

async def energy_scan(
self, channels: zigpy.types.Channels, duration_exp: int, count: int
) -> dict[int, float]:
"""Runs an energy detection scan and returns the per-channel scan results."""

LOGGER.warning("Coordinator does not support energy scanning")
return {c: 0 for c in channels}

async def force_remove(self, dev):
await self._api.remove_device(self.state.node_info.ieee, dev.ieee)

Expand Down

0 comments on commit 2f1fb28

Please sign in to comment.