- 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
77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
"""Selects: положения заслонок (af_*_direction, число позиций из num_dir)."""
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.components.select import SelectEntity
|
|
|
|
from pyfglair import Prop
|
|
from pyfglair.templates import prop_info
|
|
|
|
from .coordinator import FglairCoordinator, FglairRuntime
|
|
from .entity import FglairEntity
|
|
|
|
|
|
class FglairDirectionSelect(FglairEntity, SelectEntity):
|
|
def __init__(
|
|
self,
|
|
coordinator: FglairCoordinator,
|
|
prop: Prop,
|
|
num_dir_prop: Prop,
|
|
key: str,
|
|
) -> None:
|
|
super().__init__(coordinator, prop.name.lower(), key)
|
|
self._prop = prop
|
|
self._num_dir_prop = num_dir_prop
|
|
|
|
@property
|
|
def options(self) -> list[str]:
|
|
num = self.raw_value(self._num_dir_prop)
|
|
if num is None or num <= 0 or num > 15:
|
|
return ["0"]
|
|
return [str(value) for value in range(num)]
|
|
|
|
@property
|
|
def current_option(self) -> str | None:
|
|
value = self.raw_value(self._prop)
|
|
if value is None:
|
|
return None
|
|
text = str(value)
|
|
return text if text in self.options else self.options[0]
|
|
|
|
async def async_select_option(self, option: str) -> None:
|
|
await self.coordinator.async_write([(self._prop, int(option))])
|
|
|
|
|
|
async def async_setup_entry(hass, entry, async_add_entities) -> None:
|
|
runtime: FglairRuntime = entry.runtime_data
|
|
coordinator = runtime.coordinator
|
|
template = runtime.client.template
|
|
|
|
entities = []
|
|
if (
|
|
coordinator.features.enabled("af_vertical_direction")
|
|
and prop_info(template, Prop.AF_VERTICAL_DIRECTION) is not None
|
|
and prop_info(template, Prop.AF_VERTICAL_NUM_DIR) is not None
|
|
):
|
|
entities.append(
|
|
FglairDirectionSelect(
|
|
coordinator,
|
|
Prop.AF_VERTICAL_DIRECTION,
|
|
Prop.AF_VERTICAL_NUM_DIR,
|
|
"af_vertical_direction",
|
|
)
|
|
)
|
|
if (
|
|
coordinator.features.enabled("af_horizontal_direction")
|
|
and prop_info(template, Prop.AF_HORIZONTAL_DIRECTION) is not None
|
|
and prop_info(template, Prop.AF_HORIZONTAL_NUM_DIR) is not None
|
|
):
|
|
entities.append(
|
|
FglairDirectionSelect(
|
|
coordinator,
|
|
Prop.AF_HORIZONTAL_DIRECTION,
|
|
Prop.AF_HORIZONTAL_NUM_DIR,
|
|
"af_horizontal_direction",
|
|
)
|
|
)
|
|
async_add_entities(entities)
|