ha(ux): мастер из трёх страниц, feature-модель и capabilities-фильтрация
- config flow: template (A/B/F с пояснениями, значения с устройства, определение по oem_model; для неизвестных моделей — пробинг A/B/F тремя короткими сессиями) -> capabilities (23 тумблера с описаниями, дефолты из device_capabilities/num_dir/ответов) -> limits (диапазон/шаг, ручная конверсия); каждая страница с пометкой «значения определены автоматически, можно пропустить» - features.py: FeatureSet/LiveValues/device_default/resolve_features; entry.data["features"] хранит выбор пользователя; reconfigure предзаполняет; YAML-import получает дефолты - сущности создаются только для включённых фич: climate (режимы/скорости/ swing/пресеты), switch, select заслонок (caps+num_dir), датчик комнаты; исправлено появление select без ламелей - trial: caps/num_dir и presence-зонды (необязательные свойства), answered; координатор ждёт первые свойства перед созданием сущностей (feature- дефолты без гонки) - атрибут description у сущностей (HA не поддерживает тултипы) + описания фич в мастере (en/ru) - тесты: features, probing, обновлённые flow/entities/repairs; 57 components
This commit is contained in:
@@ -8,7 +8,13 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from pyfglair import Prop, Value
|
||||
|
||||
from .const import CONF_DSN, CONF_MODEL, CONF_NAME, DOMAIN
|
||||
from .const import (
|
||||
CONF_DSN,
|
||||
CONF_MODEL,
|
||||
CONF_NAME,
|
||||
DOMAIN,
|
||||
entity_description,
|
||||
)
|
||||
from .coordinator import FglairCoordinator
|
||||
|
||||
|
||||
@@ -22,6 +28,7 @@ class FglairEntity(CoordinatorEntity[FglairCoordinator]):
|
||||
coordinator: FglairCoordinator,
|
||||
unique_suffix: str,
|
||||
translation_key: Optional[str],
|
||||
description_key: Optional[str] = None,
|
||||
) -> None:
|
||||
super().__init__(coordinator)
|
||||
data = coordinator.client.data
|
||||
@@ -29,6 +36,7 @@ class FglairEntity(CoordinatorEntity[FglairCoordinator]):
|
||||
self._attr_unique_id = f"{dsn}_{unique_suffix}"
|
||||
if translation_key is not None:
|
||||
self._attr_translation_key = translation_key
|
||||
self._description_key = description_key or translation_key
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, dsn)},
|
||||
name=data.get(CONF_NAME) or dsn,
|
||||
@@ -40,6 +48,18 @@ class FglairEntity(CoordinatorEntity[FglairCoordinator]):
|
||||
def available(self) -> bool:
|
||||
return self.coordinator.data.available and super().available
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> Optional[dict]:
|
||||
"""HA не поддерживает тултипы сущностей: краткое описание видно в
|
||||
атрибутах (More info → Атрибуты)."""
|
||||
if self._description_key is None:
|
||||
return None
|
||||
text = entity_description(self.hass.config.language, self._description_key)
|
||||
return {"description": text} if text else None
|
||||
|
||||
def feature_enabled(self, key: str) -> bool:
|
||||
return self.coordinator.features.enabled(key)
|
||||
|
||||
def value(self, prop: Prop) -> Optional[Value]:
|
||||
return self.coordinator.data.values.get(prop)
|
||||
|
||||
@@ -54,19 +74,4 @@ class FglairEntity(CoordinatorEntity[FglairCoordinator]):
|
||||
return None
|
||||
return self.coordinator.conversions.to_display(prop, raw)
|
||||
|
||||
def capabilities(self) -> Optional[int]:
|
||||
return self.raw_value(Prop.DEVICE_CAPABILITIES)
|
||||
|
||||
def capability(self, bit: int) -> Optional[bool]:
|
||||
caps = self.capabilities()
|
||||
if not caps:
|
||||
# 0/None: возможностей ещё не сообщили — не фильтруем.
|
||||
return None
|
||||
return bool(caps & (1 << bit))
|
||||
|
||||
def supports_capability(self, bit: Optional[int]) -> bool:
|
||||
"""None — считать поддержанным (capabilities ещё не пришли)."""
|
||||
if bit is None:
|
||||
return True
|
||||
cap = self.capability(bit)
|
||||
return True if cap is None else cap
|
||||
|
||||
Reference in New Issue
Block a user