Repository: zigpy/zigpy-xbee (language: python)

Issue:
Don't fail on energy scan with legacy modules
Fixes https://github.com/home-assistant/core/issues/103208

If we receive the `RuntimeError` exeption on `ED` command, return zero energy scanning results instead of raising the exception.


Discussion / hints:
Thanks! It would be nice to use a more specific exception than `RuntimeError` to deal with unknown commands.

Fix patch:
diff --git a/zigpy_xbee/zigbee/application.py b/zigpy_xbee/zigbee/application.py
index d5c0d65..5733fc9 100644
--- a/zigpy_xbee/zigbee/application.py
+++ b/zigpy_xbee/zigbee/application.py
@@ -196,7 +196,7 @@ async def energy_scan(
         all_results = {}
 
         for _ in range(count):
-            results = await self._api._at_command("ED", duration_exp)
+            results = await self._api._at_command("ED", bytes([duration_exp]))
             results = {
                 channel: -int(rssi) for channel, rssi in zip(range(11, 27), results)
             }


Test patch:
diff --git a/tests/test_application.py b/tests/test_application.py
index 03ce25c..a508caf 100644
--- a/tests/test_application.py
+++ b/tests/test_application.py
@@ -709,7 +709,7 @@ async def test_energy_scan(app):
     energy = await app.energy_scan(
         channels=list(range(11, 27)), duration_exp=time_s, count=count
     )
-    assert app._api._at_command.mock_calls == [mock.call("ED", time_s)] * count
+    assert app._api._at_command.mock_calls == [mock.call("ED", bytes([time_s]))] * count
     assert {k: round(v, 3) for k, v in energy.items()} == {
         11: 254.032,
         12: 253.153,