Skip to content

Commit

Permalink
Don't fail on energy scan with legacy modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Shulyaka committed Nov 2, 2023
1 parent b8564a8 commit 1afd02b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,20 @@ async def test_energy_scan(app):
}


async def test_energy_scan_legacy_module(app):
"""Test channel energy scan."""
app._api._at_command = mock.AsyncMock(
spec=XBee._at_command, side_effect=RuntimeError
)
time_s = 3
count = 3
energy = await app.energy_scan(
channels=list(range(11, 27)), duration_exp=time_s, count=count
)
app._api._at_command.assert_called_once_with("ED", time_s)
assert energy == {c: 0 for c in range(11, 27)}


def test_neighbors_updated(app, device):
"""Test LQI from neighbour scan."""
router = device(ieee=b"\x01\x02\x03\x04\x05\x06\x07\x08")
Expand Down
7 changes: 6 additions & 1 deletion zigpy_xbee/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ async def energy_scan(
all_results = {}

for _ in range(count):
results = await self._api._at_command("ED", duration_exp)
try:
results = await self._api._at_command("ED", duration_exp)
except RuntimeError:
LOGGER.warning("Coordinator does not support energy scanning")
return {c: 0 for c in channels}

results = {
channel: -int(rssi) for channel, rssi in zip(range(11, 27), results)
}
Expand Down

0 comments on commit 1afd02b

Please sign in to comment.