From f5cc7fbb8f28accde5d888af0ccf2b0840762454 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Mon, 14 Apr 2025 21:29:00 +0300 Subject: [PATCH] feat: use hass helper to create httpx.AsyncClient --- custom_components/ouman_eh800/__init__.py | 1 + custom_components/ouman_eh800/eh800.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/custom_components/ouman_eh800/__init__.py b/custom_components/ouman_eh800/__init__.py index 5ed4b02..e750ef9 100644 --- a/custom_components/ouman_eh800/__init__.py +++ b/custom_components/ouman_eh800/__init__.py @@ -29,6 +29,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: config = dict(entry.data) eh800 = EH800( + hass, config[CONF_HOST], config[CONF_PORT], config[CONF_USERNAME], diff --git a/custom_components/ouman_eh800/eh800.py b/custom_components/ouman_eh800/eh800.py index fdda8c1..0229d0f 100644 --- a/custom_components/ouman_eh800/eh800.py +++ b/custom_components/ouman_eh800/eh800.py @@ -2,6 +2,8 @@ import dataclasses import logging from httpx import AsyncClient +from homeassistant.core import HomeAssistant +from homeassistant.helpers.httpx_client import get_async_client _LOGGER = logging.getLogger(__name__) @@ -80,11 +82,13 @@ OPERATION_MODES: tuple[OperationMode, ...] = ( class EH800: - def __init__(self, host: str, port: int, username: str, password: str) -> None: + def __init__( + self, hass: HomeAssistant, host: str, port: int, username: str, password: str + ) -> None: self._uri = f"http://{host}:{port}" self._login = f"uid={username};pwd={password};" - self._client = AsyncClient() + self._client: AsyncClient = get_async_client(hass) self._request_query = "request?" for value in VALUES: -- 2.44.1