"""Диагностика: параметры для ESPHome и маскировка ключа.""" from __future__ import annotations import asyncio import time from helpers import DSN, LANIP_KEY from homeassistant.core import HomeAssistant from test_entities import MOCK_SETTINGS, _setup_entry from custom_components.fglair.diagnostics import ( async_get_config_entry_diagnostics, ) from pyfglair import Prop, State async def _wait_for(predicate, timeout: float = 20.0): deadline = time.monotonic() + timeout while time.monotonic() < deadline: result = predicate() if result: return result await asyncio.sleep(0.1) raise AssertionError("условие не выполнено за отведённое время") async def test_diagnostics(hass: HomeAssistant, mock_ac, socket_enabled): proc = mock_ac(MOCK_SETTINGS) entry = await _setup_entry(hass, proc.port) runtime = entry.runtime_data await _wait_for( lambda: runtime.client.state == State.ONLINE and runtime.client.cached(Prop.OPERATION_MODE) is not None and runtime.client.cached(Prop.DISPLAY_TEMPERATURE) is not None ) diag = await async_get_config_entry_diagnostics(hass, entry) assert diag["config"]["dsn"] == DSN assert diag["config"]["host"] == "127.0.0.1" assert diag["config"]["template"] == "A" assert diag["esp_home"]["lanip_key"] == LANIP_KEY assert diag["esp_home"]["lanip_key_id"] == 64201 assert diag["esp_home_masked"]["lanip_key"] != LANIP_KEY assert "REDACTED" in diag["esp_home_masked"]["lanip_key"] assert diag["entry_data"]["lanip_key"] == "**REDACTED**" assert diag["runtime"]["state"] == "online" assert diag["runtime"]["events_dropped"] == 0 assert diag["runtime"]["values"]["operation_mode"]["raw"] == 6 assert diag["runtime"]["values"]["operation_mode"]["display"] == 6 assert ( diag["runtime"]["values"]["display_temperature"]["display"] == 200 ) assert await hass.config_entries.async_unload(entry.entry_id)