mirror of
https://github.com/smkrv/ha-text-ai.git
synced 2026-07-29 11:43:56 +08:00
Release v2.0.0
This commit is contained in:
@@ -128,12 +128,14 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
|
|
||||||
async def _async_update_data(self) -> Dict[str, Any]:
|
async def _async_update_data(self) -> Dict[str, Any]:
|
||||||
"""Update data via API."""
|
"""Update data via API."""
|
||||||
if not self._is_ready or self._question_queue.empty():
|
# Возвращаем существующие ответы, если нет новых вопросов
|
||||||
return {}
|
if self._question_queue.empty():
|
||||||
|
return self._responses
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with async_timeout.timeout(DEFAULT_TIMEOUT):
|
async with async_timeout.timeout(DEFAULT_TIMEOUT):
|
||||||
self._is_processing = True
|
self._is_processing = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
priority, question_data = await self._question_queue.get()
|
priority, question_data = await self._question_queue.get()
|
||||||
question = question_data["question"]
|
question = question_data["question"]
|
||||||
@@ -151,6 +153,10 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
question, response_data, params, priority
|
question, response_data, params, priority
|
||||||
)
|
)
|
||||||
|
|
||||||
|
except asyncio.QueueEmpty:
|
||||||
|
# Если очередь пуста, просто возвращаем существующие ответы
|
||||||
|
return self._responses
|
||||||
|
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
_LOGGER.error("Timeout while processing API request")
|
_LOGGER.error("Timeout while processing API request")
|
||||||
await self._handle_api_error(question, "Request timeout")
|
await self._handle_api_error(question, "Request timeout")
|
||||||
@@ -163,12 +169,6 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
_LOGGER.error("Error processing question: %s", str(err))
|
_LOGGER.error("Error processing question: %s", str(err))
|
||||||
await self._handle_api_error(question, err)
|
await self._handle_api_error(question, err)
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
_LOGGER.error("Critical error in _async_update_data: %s", str(e))
|
|
||||||
self._is_ready = False
|
|
||||||
self._endpoint_status = "error"
|
|
||||||
return {}
|
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
self._is_processing = False
|
self._is_processing = False
|
||||||
self._question_queue.task_done()
|
self._question_queue.task_done()
|
||||||
@@ -450,7 +450,7 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
|
|
||||||
await self._question_queue.put((priority_level, question_data))
|
await self._question_queue.put((priority_level, question_data))
|
||||||
_LOGGER.debug("Question added to queue with priority %d", priority_level)
|
_LOGGER.debug("Question added to queue with priority %d", priority_level)
|
||||||
await self.async_refresh()
|
|
||||||
|
|
||||||
except asyncio.QueueFull:
|
except asyncio.QueueFull:
|
||||||
_LOGGER.error("Question queue is full. Try again later.")
|
_LOGGER.error("Question queue is full. Try again later.")
|
||||||
@@ -459,6 +459,7 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
_LOGGER.error("Error in async_ask_question: %s", str(e))
|
_LOGGER.error("Error in async_ask_question: %s", str(e))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
async def async_shutdown(self) -> None:
|
async def async_shutdown(self) -> None:
|
||||||
"""Shutdown the coordinator."""
|
"""Shutdown the coordinator."""
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user