Commit ade6fd0 1 parent 285c0d2 commit ade6fd0 Copy full SHA for ade6fd0
File tree 2 files changed +25
-6
lines changed
custom_components/zha_toolkit
2 files changed +25
-6
lines changed Original file line number Diff line number Diff line change 1
1
import importlib
2
2
import logging
3
- from typing import Optional
3
+ from typing import Any , Optional
4
4
5
5
import homeassistant .helpers .config_validation as cv
6
6
import voluptuous as vol
@@ -677,8 +677,8 @@ async def toolkit_service(service):
677
677
global LOADED_VERSION # pylint: disable=global-variable-not-assigned
678
678
679
679
zha = hass_ref .data ["zha" ]
680
- zha_gw : Optional [ZHAGateway ] = None
681
- zha_gw = u .get_zha_gateway (hass )
680
+ zha_gw : Optional [ZHAGateway ] = u . get_zha_gateway ( hass )
681
+ zha_gw_hass : Any = u .get_zha_gateway_hass (hass )
682
682
683
683
if zha_gw is None :
684
684
LOGGER .error (
@@ -725,7 +725,7 @@ async def toolkit_service(service):
725
725
726
726
app = zha_gw .application_controller # type: ignore
727
727
728
- ieee = await u .get_ieee (app , zha_gw , ieee_str )
728
+ ieee = await u .get_ieee (app , zha_gw_hass , ieee_str )
729
729
730
730
slickParams = params .copy ()
731
731
for k in params :
@@ -783,7 +783,7 @@ async def toolkit_service(service):
783
783
try :
784
784
handler_result = await handler (
785
785
zha_gw .application_controller , # type: ignore
786
- zha_gw ,
786
+ zha_gw_hass ,
787
787
ieee ,
788
788
cmd ,
789
789
cmd_data ,
Original file line number Diff line number Diff line change 19
19
from homeassistant .components .zha .core .gateway import ZHAGateway
20
20
21
21
from homeassistant .components import zha
22
- from homeassistant .components .zha import helpers as zha_helpers
22
+
23
+ try :
24
+ from homeassistant .components .zha import helpers as zha_helpers
25
+ except ImportError :
26
+ zha_helpers = None
27
+
23
28
from homeassistant .util import dt as dt_util
24
29
from pkg_resources import get_distribution , parse_version
25
30
from zigpy import types as t
@@ -62,6 +67,20 @@ def get_zha_gateway(hass: HomeAssistant) -> ZHAGateway:
62
67
return zha .gateway
63
68
64
69
70
+ def get_zha_gateway_hass (
71
+ hass : HomeAssistant ,
72
+ ) -> ZHAGateway | zha_helpers .ZHAGatewayProxy :
73
+ """
74
+ Get the ZHA gateway proxy object.
75
+
76
+ Fallback to the gateway object prior to 2024.8 which still has an attached
77
+ HASS object.
78
+ """
79
+ if parse_version (HA_VERSION ) >= parse_version ("2024.8" ):
80
+ return zha_helpers .get_zha_gateway_proxy (hass )
81
+ return get_zha_gateway (hass )
82
+
83
+
65
84
def getHaVersion () -> str :
66
85
"""Get HA Version"""
67
86
return HA_VERSION
You can’t perform that action at this time.
0 commit comments