Skip to content

Commit

Permalink
Merge pull request #277 from mdeweerd/dev
Browse files Browse the repository at this point in the history
Fix #269 Adjust method to get list of devices to current ZHA code
  • Loading branch information
mdeweerd authored Dec 26, 2024
2 parents be0367e + 0f9458f commit ee11ddb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions STATS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Badges showing number of downloads per version

- ![badge latest](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/latest/total.svg)
- ![badge v1.1.23](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v1.1.23/total.svg)
- ![badge v1.1.22](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v1.1.22/total.svg)
- ![badge v1.1.21](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v1.1.21/total.svg)
- ![badge v1.1.20](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v1.1.20/total.svg)
- ![badge v1.1.19](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v1.1.19/total.svg)
Expand Down
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
14 changes: 13 additions & 1 deletion custom_components/zha_toolkit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
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 +69,16 @@ 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:
# Old method
devices = getattr(listener, "devices", None)
if devices is not None:
return devices.values()
return []


def get_zha_gateway_hass(
hass: HomeAssistant,
) -> ZHAGateway | zha_helpers.ZHAGatewayProxy:
Expand Down
4 changes: 3 additions & 1 deletion custom_components/zha_toolkit/zha.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ 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 ee11ddb

Please sign in to comment.