Skip to content

Commit

Permalink
Fix #269 Adjust method to get list of devices to current ZHA code
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeweerd committed Dec 26, 2024
1 parent be0367e commit 41a286d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions custom_components/zha_toolkit/ota.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def download_koenkk_ota(listener, ota_dir):
# Get manufacturers
manfs = {}
for info in [
device.zha_device_info for device in listener.devices.values()
device.zha_device_info for device in u.get_zha_devices(listener)
]:
manfs[info["manufacturer_code"]] = True

Expand Down Expand Up @@ -111,7 +111,7 @@ async def download_sonoff_ota(listener, ota_dir):
# Get manufacturers
manfs = {}
for info in [
device.zha_device_info for device in listener.devices.values()
device.zha_device_info for device in u.get_zha_devices(listener)
]:
manfs[info["manufacturer_code"]] = True

Expand Down
11 changes: 10 additions & 1 deletion custom_components/zha_toolkit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
MANIFEST: dict[str, str | list[str]] = {}


def get_zha_gateway(hass: HomeAssistant) -> ZHAGateway:
def get_zha_gateway(hass: HomeAssistant) -> ZHAGateway | zha_helpers.ZHAGatewayProxy:
"""Get the ZHA gateway object."""
if parse_version(HA_VERSION) >= parse_version("2024.8"):
return zha_helpers.get_zha_gateway(hass)
Expand All @@ -67,6 +67,15 @@ def get_zha_gateway(hass: HomeAssistant) -> ZHAGateway:
return zha.gateway


def get_zha_devices(listener: ZHAGateway | zha_helpers.ZHAGatewayProxy):
devices = getattr(listener, "device_proxies", None)
if devices is None:

Check failure on line 72 in custom_components/zha_toolkit/utils.py

View workflow job for this annotation

GitHub Actions / pre-commit

R1710: Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)

Check failure on line 72 in custom_components/zha_toolkit/utils.py

View workflow job for this annotation

GitHub Actions / pre-commit

R1710: Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)
# Old method
devices = getattr(listener, "devices", None)
if devices is not None:
return devices.values()


def get_zha_gateway_hass(
hass: HomeAssistant,
) -> ZHAGateway | zha_helpers.ZHAGatewayProxy:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/zha_toolkit/zha.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def zha_devices(
# 'signature'
# 'endpoints'

devices = [device.zha_device_info for device in listener.devices.values()]
devices = [device.zha_device_info for device in listener.device_proxies.values()]

if ieee is not None:
ieee = str(ieee)
Expand Down

0 comments on commit 41a286d

Please sign in to comment.