From 0279517a42d9db3e3430e52d6b83e55ed5c10d44 Mon Sep 17 00:00:00 2001 From: SMKRV Date: Sat, 23 Nov 2024 01:34:05 +0300 Subject: [PATCH] Release v2.0.0 --- custom_components/ha_text_ai/coordinator.py | 30 +++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/custom_components/ha_text_ai/coordinator.py b/custom_components/ha_text_ai/coordinator.py index 077335c..d5a4758 100644 --- a/custom_components/ha_text_ai/coordinator.py +++ b/custom_components/ha_text_ai/coordinator.py @@ -10,7 +10,7 @@ import aiohttp import httpx import voluptuous as vol -from homeassistant import config_entries +from homeassistant import config_entries from homeassistant.helpers import aiohttp_client from openai import AsyncOpenAI, APIError, AuthenticationError, RateLimitError from anthropic import AsyncAnthropic @@ -44,13 +44,8 @@ class HATextAICoordinator(DataUpdateCoordinator): session: Optional[Any] = None, is_anthropic: bool = False, ) -> None: - super().__init__( - hass, - _LOGGER, - name=name, - update_interval=timedelta(seconds=float(request_interval)), - ) - self._name = name + """Initialize coordinator.""" + self._name = name # Инициализируем name до вызова super().__init__ self._validate_params(api_key, temperature, max_tokens) self._entity_id = None self.api_key = api_key @@ -80,7 +75,19 @@ class HATextAICoordinator(DataUpdateCoordinator): self._last_request_time = 0 self._is_anthropic = is_anthropic self._session = session or aiohttp_client.async_get_clientsession(hass) - self.client = None # Initialize client as None + self.client = None + + super().__init__( + hass, + _LOGGER, + name=self._name, # Используем уже установленное значение + update_interval=timedelta(seconds=float(request_interval)), + ) + + @property + def name(self) -> str: + """Return the name of the coordinator.""" + return self._name async def async_initialize(self) -> None: """Initialize coordinator.""" @@ -515,11 +522,6 @@ class HATextAICoordinator(DataUpdateCoordinator): """Set entity ID.""" self._entity_id = value - @property - def name(self) -> str: - """Get coordinator name.""" - return self._name - @property def performance_metrics(self) -> Dict[str, Any]: """Return current performance metrics."""