From 2d6852facac7528077ae6105eb8fa7c8f7dbe571 Mon Sep 17 00:00:00 2001 From: Artem Sorokin Date: Thu, 25 Apr 2024 16:23:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D1=8B=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B4=D0=B8=D0=B0=D0=B3=D0=BD=D0=BE=D1=81=D1=82=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=B8=D1=85=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yandex_station_intents/diagnostics.py | 24 +++++++++++++++++++ .../yandex_station_intents/yandex_quasar.py | 14 +++++++---- tests/test_backward.py | 2 ++ 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 custom_components/yandex_station_intents/diagnostics.py diff --git a/custom_components/yandex_station_intents/diagnostics.py b/custom_components/yandex_station_intents/diagnostics.py new file mode 100644 index 0000000..a0878c5 --- /dev/null +++ b/custom_components/yandex_station_intents/diagnostics.py @@ -0,0 +1,24 @@ +from typing import Any + +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant + +from . import Component +from .const import DOMAIN + + +async def async_get_config_entry_diagnostics(hass: HomeAssistant, entry: ConfigEntry) -> dict[str, Any]: + component: Component = hass.data[DOMAIN] + entry_data = component.entry_datas[entry.entry_id] + + try: + scenarios: Any = await entry_data.quasar.async_get_scenarios() + except Exception as e: + scenarios = e + + return { + "yaml_config": component.yaml_config, + "devices": entry_data.quasar.devices, + "scenarios": scenarios, + "intents": entry_data.intent_manager.intents, + } diff --git a/custom_components/yandex_station_intents/yandex_quasar.py b/custom_components/yandex_station_intents/yandex_quasar.py index ffca450..666b7d0 100644 --- a/custom_components/yandex_station_intents/yandex_quasar.py +++ b/custom_components/yandex_station_intents/yandex_quasar.py @@ -147,16 +147,20 @@ async def async_get_intent_player_device_id(self) -> str | None: return None - async def async_get_intents(self) -> dict[str, str]: - """Получает список интенетов, которые управляются компонентом.""" - _LOGGER.debug("Получение списка интентов") - + async def async_get_scenarios(self) -> list[dict[str, Any]]: r = await self._session.get(f"{URL_USER}/scenarios") resp = await r.json() assert resp["status"] == "ok", resp + assert isinstance(resp["scenarios"], list) + + return resp["scenarios"] + + async def async_get_intents(self) -> dict[str, str]: + """Получает список интенетов, которые управляются компонентом.""" + _LOGGER.debug("Получение списка интентов") rv = {} - for scenario in resp["scenarios"]: + for scenario in await self.async_get_scenarios(): if INTENT_ID_MARKER not in scenario["name"]: continue diff --git a/tests/test_backward.py b/tests/test_backward.py index 70cbdda..0a58d44 100644 --- a/tests/test_backward.py +++ b/tests/test_backward.py @@ -1,6 +1,7 @@ def test_backward() -> None: from custom_components.yandex_station_intents import async_setup from custom_components.yandex_station_intents.config_flow import YandexSmartHomeIntentsFlowHandler + from custom_components.yandex_station_intents.diagnostics import async_get_config_entry_diagnostics from custom_components.yandex_station_intents.media_player import YandexStationIntentMediaPlayer from custom_components.yandex_station_intents.yandex_intent import IntentManager from custom_components.yandex_station_intents.yandex_quasar import YandexQuasar @@ -8,6 +9,7 @@ def test_backward() -> None: for o in [ async_setup, + async_get_config_entry_diagnostics, YandexSmartHomeIntentsFlowHandler, YandexStationIntentMediaPlayer, IntentManager,