Skip to content

Commit a44de4f

Browse files
committed
Don't fail on energy scan with legacy modules
1 parent 34bebb7 commit a44de4f

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
@@ -735,6 +735,20 @@ async def test_energy_scan(app):
735735
}
736736

737737

738+
async def test_energy_scan_legacy_module(app):
739+
"""Test channel energy scan."""
740+
app._api._at_command = mock.AsyncMock(
741+
spec=XBee._at_command, side_effect=RuntimeError
742+
)
743+
time_s = 3
744+
count = 3
745+
energy = await app.energy_scan(
746+
channels=list(range(11, 27)), duration_exp=time_s, count=count
747+
)
748+
app._api._at_command.assert_called_once_with("ED", time_s)
749+
assert energy == {c: 0 for c in range(11, 27)}
750+
751+
738752
def test_neighbors_updated(app, device):
739753
"""Test LQI from neighbour scan."""
740754
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
@@ -196,7 +196,12 @@ async def energy_scan(
196196
all_results = {}
197197

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

0 commit comments

Comments
 (0)