- repairs: issue key_mismatch (ERROR, fixable) при состоянии key_error, ConfirmRepairFlow, снятие issue при online/unload/remove - config flow: async_step_reconfigure (меню, prefill ручной формы, unique_id_mismatch, update_reload_and_abort) — путь «перепровижинировать» - diagnostics: config/esp_home (dsn/lanip_key/key_id/host для secrets.yaml) + esp_home_masked и redacted entry_data, runtime-снимок значений (raw/display) из кэша ядра - translations: issues.key_mismatch (title/description/fix_flow) en/ru, abort unique_id_mismatch/reconfigure_successful; тест согласованности strings↔en↔ru - FglairClient.events_dropped; mock_ac: параметр key_id в фикстуре - тесты: diagnostics, repairs issue+fix-flow, reconfigure (успех/чужое устройство), translations (45 components)
57 lines
2.0 KiB
Python
57 lines
2.0 KiB
Python
"""Диагностика: параметры для 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)
|