From 41a286d52957d57ff9a623b9ebdb48571dda6dcd Mon Sep 17 00:00:00 2001 From: mdeweerd Date: Thu, 26 Dec 2024 20:06:05 +0100 Subject: [PATCH 1/3] Fix #269 Adjust method to get list of devices to current ZHA code --- custom_components/zha_toolkit/ota.py | 4 ++-- custom_components/zha_toolkit/utils.py | 11 ++++++++++- custom_components/zha_toolkit/zha.py | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/custom_components/zha_toolkit/ota.py b/custom_components/zha_toolkit/ota.py index 3ce00b1..29d3f94 100644 --- a/custom_components/zha_toolkit/ota.py +++ b/custom_components/zha_toolkit/ota.py @@ -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 @@ -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 diff --git a/custom_components/zha_toolkit/utils.py b/custom_components/zha_toolkit/utils.py index b416174..d842977 100644 --- a/custom_components/zha_toolkit/utils.py +++ b/custom_components/zha_toolkit/utils.py @@ -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) @@ -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: + # 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: diff --git a/custom_components/zha_toolkit/zha.py b/custom_components/zha_toolkit/zha.py index c6e831d..4999c5e 100644 --- a/custom_components/zha_toolkit/zha.py +++ b/custom_components/zha_toolkit/zha.py @@ -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) From c8fe4f07b63a1c23eecb7521e3e3994f8bdf1260 Mon Sep 17 00:00:00 2001 From: mdeweerd Date: Thu, 26 Dec 2024 20:13:54 +0100 Subject: [PATCH 2/3] Fix formatting --- STATS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/STATS.md b/STATS.md index 1a00b39..09dfa97 100644 --- a/STATS.md +++ b/STATS.md @@ -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) From 0f9458fa1946aacce0b60538573fba57529748a3 Mon Sep 17 00:00:00 2001 From: mdeweerd Date: Thu, 26 Dec 2024 20:21:26 +0100 Subject: [PATCH 3/3] Fix formatting --- custom_components/zha_toolkit/utils.py | 17 ++++++++++------- custom_components/zha_toolkit/zha.py | 4 +++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/custom_components/zha_toolkit/utils.py b/custom_components/zha_toolkit/utils.py index d842977..f874379 100644 --- a/custom_components/zha_toolkit/utils.py +++ b/custom_components/zha_toolkit/utils.py @@ -58,7 +58,9 @@ MANIFEST: dict[str, str | list[str]] = {} -def get_zha_gateway(hass: HomeAssistant) -> ZHAGateway | zha_helpers.ZHAGatewayProxy: +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) @@ -68,12 +70,13 @@ def get_zha_gateway(hass: HomeAssistant) -> ZHAGateway | zha_helpers.ZHAGatewayP 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() + 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( diff --git a/custom_components/zha_toolkit/zha.py b/custom_components/zha_toolkit/zha.py index 4999c5e..5b85e60 100644 --- a/custom_components/zha_toolkit/zha.py +++ b/custom_components/zha_toolkit/zha.py @@ -45,7 +45,9 @@ async def zha_devices( # 'signature' # 'endpoints' - devices = [device.zha_device_info for device in listener.device_proxies.values()] + devices = [ + device.zha_device_info for device in listener.device_proxies.values() + ] if ieee is not None: ieee = str(ieee)