Skip to content

Commit 846130e

Browse files
authored
Don't fail on energy scan with legacy modules (#166)
* Don't fail on energy scan with legacy modules * Use new InvalidCommand exception
1 parent 626bce6 commit 846130e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

tests/test_application.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,20 @@ async def test_energy_scan(app):
731731
}
732732

733733

734+
async def test_energy_scan_legacy_module(app):
735+
"""Test channel energy scan."""
736+
app._api._at_command = mock.AsyncMock(
737+
spec=XBee._at_command, side_effect=InvalidCommand
738+
)
739+
time_s = 3
740+
count = 3
741+
energy = await app.energy_scan(
742+
channels=list(range(11, 27)), duration_exp=time_s, count=count
743+
)
744+
app._api._at_command.assert_called_once_with("ED", bytes([time_s]))
745+
assert energy == {c: 0 for c in range(11, 27)}
746+
747+
734748
def test_neighbors_updated(app, device):
735749
"""Test LQI from neighbour scan."""
736750
router = device(ieee=b"\x01\x02\x03\x04\x05\x06\x07\x08")

zigpy_xbee/zigbee/application.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,12 @@ async def energy_scan(
197197
all_results = {}
198198

199199
for _ in range(count):
200-
results = await self._api._at_command("ED", bytes([duration_exp]))
200+
try:
201+
results = await self._api._at_command("ED", bytes([duration_exp]))
202+
except InvalidCommand:
203+
LOGGER.warning("Coordinator does not support energy scanning")
204+
return {c: 0 for c in channels}
205+
201206
results = {
202207
channel: -int(rssi) for channel, rssi in zip(range(11, 27), results)
203208
}

0 commit comments

Comments
 (0)