Skip to content

Commit

Permalink
Добавлена выгрузка диагностических данных
Browse files Browse the repository at this point in the history
  • Loading branch information
dext0r committed Apr 25, 2024
1 parent 6a952e4 commit 2d6852f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
24 changes: 24 additions & 0 deletions custom_components/yandex_station_intents/diagnostics.py
Original file line number Diff line number Diff line change
@@ -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,
}
14 changes: 9 additions & 5 deletions custom_components/yandex_station_intents/yandex_quasar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/test_backward.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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
from custom_components.yandex_station_intents.yandex_session import YandexSession

for o in [
async_setup,
async_get_config_entry_diagnostics,
YandexSmartHomeIntentsFlowHandler,
YandexStationIntentMediaPlayer,
IntentManager,
Expand Down

0 comments on commit 2d6852f

Please sign in to comment.