Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail on energy scan with legacy modules #166

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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