Skip to content

Commit ade6fd0

Browse files
committed
Get the proxy as well as the gateway
1 parent 285c0d2 commit ade6fd0

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

custom_components/zha_toolkit/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import importlib
22
import logging
3-
from typing import Optional
3+
from typing import Any, Optional
44

55
import homeassistant.helpers.config_validation as cv
66
import voluptuous as vol
@@ -677,8 +677,8 @@ async def toolkit_service(service):
677677
global LOADED_VERSION # pylint: disable=global-variable-not-assigned
678678

679679
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)
682682

683683
if zha_gw is None:
684684
LOGGER.error(
@@ -725,7 +725,7 @@ async def toolkit_service(service):
725725

726726
app = zha_gw.application_controller # type: ignore
727727

728-
ieee = await u.get_ieee(app, zha_gw, ieee_str)
728+
ieee = await u.get_ieee(app, zha_gw_hass, ieee_str)
729729

730730
slickParams = params.copy()
731731
for k in params:
@@ -783,7 +783,7 @@ async def toolkit_service(service):
783783
try:
784784
handler_result = await handler(
785785
zha_gw.application_controller, # type: ignore
786-
zha_gw,
786+
zha_gw_hass,
787787
ieee,
788788
cmd,
789789
cmd_data,

custom_components/zha_toolkit/utils.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
from homeassistant.components.zha.core.gateway import ZHAGateway
2020

2121
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+
2328
from homeassistant.util import dt as dt_util
2429
from pkg_resources import get_distribution, parse_version
2530
from zigpy import types as t
@@ -62,6 +67,20 @@ def get_zha_gateway(hass: HomeAssistant) -> ZHAGateway:
6267
return zha.gateway
6368

6469

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+
6584
def getHaVersion() -> str:
6685
"""Get HA Version"""
6786
return HA_VERSION

0 commit comments

Comments
 (0)