Skip to content

Commit

Permalink
Fixed get_routes_and_neighbours for Zigpy changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeweerd committed Jul 23, 2023
1 parent 20aaaaf commit a13806e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions custom_components/zha_toolkit/neighbours.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from random import uniform

import zigpy.zdo.types as zdo_t
from homeassistant.util.json import save_json
from . import utils as u
from zigpy.exceptions import DeliveryError

LOGGER = logging.getLogger(__name__)
Expand All @@ -31,7 +31,7 @@ async def get_routes_and_neighbours(
"scans",
f"routes_and_neighbours_{ieee_tail}.json",
)
save_json(fname, event_data["result"])
u.helper_save_json(fname, event_data["result"])

LOGGER.debug("Wrote scan results to '%s'", fname)

Expand Down Expand Up @@ -78,7 +78,7 @@ async def all_routes_and_neighbours(
"scans",
"all_routes_and_neighbours.json",
)
save_json(all_routes_name, all_routes)
u.helper_save_json(all_routes_name, all_routes)


async def async_get_neighbours(device):
Expand Down Expand Up @@ -122,13 +122,22 @@ def _process_neighbour(nbg):
LOGGER.debug("%s: Could not deliver 'Mgmt_Lqi_req'", device.ieee)
break

# LOGGER.debug(f"NEIGHBORS: {val!r}")
neighbours = val.neighbor_table_list
LOGGER.debug(f"NEIGHBORS: {val!r}")

if hasattr(val, "neighbor_table_list"):
neighbours = val.neighbor_table_list
entries = val.entries
else:
neighbours = val.NeighborTableList
entries = val.Entries

for neighbour in neighbours:
result.append(_process_neighbour(neighbour))
idx += 1
if idx >= val.entries:

if idx >= entries:
break

await asyncio.sleep(uniform(1.0, 1.5))

return sorted(result, key=lambda x: x["ieee"])
Expand Down

0 comments on commit a13806e

Please sign in to comment.