Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 253 #254

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions custom_components/zha_toolkit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import importlib
import logging
from typing import Optional
from typing import Any, Optional

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

zha = hass_ref.data["zha"]
zha_gw: Optional[ZHAGateway] = None
zha_gw = u.get_zha_gateway(hass)
zha_gw: Optional[ZHAGateway] = u.get_zha_gateway(hass)
zha_gw_hass: Any = u.get_zha_gateway_hass(hass)

if zha_gw is None:
LOGGER.error(
Expand Down Expand Up @@ -725,7 +725,7 @@ async def toolkit_service(service):

app = zha_gw.application_controller # type: ignore

ieee = await u.get_ieee(app, zha_gw, ieee_str)
ieee = await u.get_ieee(app, zha_gw_hass, ieee_str)

slickParams = params.copy()
for k in params:
Expand Down Expand Up @@ -783,7 +783,7 @@ async def toolkit_service(service):
try:
handler_result = await handler(
zha_gw.application_controller, # type: ignore
zha_gw,
zha_gw_hass,
ieee,
cmd,
cmd_data,
Expand Down
21 changes: 20 additions & 1 deletion custom_components/zha_toolkit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
from homeassistant.components.zha.core.gateway import ZHAGateway

from homeassistant.components import zha
from homeassistant.components.zha import helpers as zha_helpers

try:
from homeassistant.components.zha import helpers as zha_helpers
except ImportError:
zha_helpers = None

from homeassistant.util import dt as dt_util
from pkg_resources import get_distribution, parse_version
from zigpy import types as t
Expand Down Expand Up @@ -62,6 +67,20 @@ def get_zha_gateway(hass: HomeAssistant) -> ZHAGateway:
return zha.gateway


def get_zha_gateway_hass(
hass: HomeAssistant,
) -> ZHAGateway | zha_helpers.ZHAGatewayProxy:
"""
Get the ZHA gateway proxy object.

Fallback to the gateway object prior to 2024.8 which still has an attached
HASS object.
"""
if parse_version(HA_VERSION) >= parse_version("2024.8"):
return zha_helpers.get_zha_gateway_proxy(hass)
return get_zha_gateway(hass)


def getHaVersion() -> str:
"""Get HA Version"""
return HA_VERSION
Expand Down
Loading