Commit 285c0d2 1 parent 780292e commit 285c0d2 Copy full SHA for 285c0d2
File tree 2 files changed +13
-4
lines changed
custom_components/zha_toolkit
2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -678,10 +678,7 @@ async def toolkit_service(service):
678
678
679
679
zha = hass_ref .data ["zha" ]
680
680
zha_gw : Optional [ZHAGateway ] = None
681
- if isinstance (zha , dict ):
682
- zha_gw = zha .get ("zha_gateway" , None )
683
- else :
684
- zha_gw = zha .gateway
681
+ zha_gw = u .get_zha_gateway (hass )
685
682
686
683
if zha_gw is None :
687
684
LOGGER .error (
Original file line number Diff line number Diff line change 11
11
12
12
import aiofiles
13
13
import zigpy
14
+ from homeassistant .core import HomeAssistant
14
15
15
16
try :
16
17
from homeassistant .components .zha import Gateway as ZHAGateway
17
18
except ImportError :
18
19
from homeassistant .components .zha .core .gateway import ZHAGateway
19
20
21
+ from homeassistant .components import zha
22
+ from homeassistant .components .zha import helpers as zha_helpers
20
23
from homeassistant .util import dt as dt_util
21
24
from pkg_resources import get_distribution , parse_version
22
25
from zigpy import types as t
50
53
MANIFEST : dict [str , str | list [str ]] = {}
51
54
52
55
56
+ def get_zha_gateway (hass : HomeAssistant ) -> ZHAGateway :
57
+ """Get the ZHA gateway object."""
58
+ if parse_version (HA_VERSION ) >= parse_version ("2024.8" ):
59
+ return zha_helpers .get_zha_gateway (hass )
60
+ if isinstance (zha , dict ):
61
+ return zha .get ("zha_gateway" , None )
62
+ return zha .gateway
63
+
64
+
53
65
def getHaVersion () -> str :
54
66
"""Get HA Version"""
55
67
return HA_VERSION
You can’t perform that action at this time.
0 commit comments