Skip to content

Commit

Permalink
Don't fail on energy scan with legacy modules (#166)
Browse files Browse the repository at this point in the history
* Don't fail on energy scan with legacy modules

* Use new InvalidCommand exception
  • Loading branch information
Shulyaka authored Nov 20, 2023
1 parent 626bce6 commit 846130e
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 @@ -731,6 +731,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=InvalidCommand
)
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", bytes([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 @@ -197,7 +197,12 @@ async def energy_scan(
all_results = {}

for _ in range(count):
results = await self._api._at_command("ED", bytes([duration_exp]))
try:
results = await self._api._at_command("ED", bytes([duration_exp]))
except InvalidCommand:
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 846130e

Please sign in to comment.