- config flow: шаг preview (шаблон A/B/F, диапазон/шаг уставки, линейные коэффициенты num/den/offset, текст-превью по данным trial: hvac/fan/ swing/capabilities/текущая температура) - coordinator: push-driven DataUpdateCoordinator (снимок кэша, доступность online/recovering, первичный GET-батч, один batch_commit на действие) - overrides.py: ConversionSet (ручные линейные конверсии и диапазон поверх таблиц ядра, применяются в HA) - entity.py: DeviceInfo/unique_id/доступность, capabilities-фильтры - climate: hvac/fan/swing/vertical+horizontal swing/preset ECO-BOOST, уставка 16-30 °C (шаг по шаблону), current_temperature - sensor: room_temperature, error_code, connection_state (диагностика) - binary_sensor: connectivity + флаги op_status (PROTOCOL §8.4) - switch: 8 флагов-свойств; select: положения заслонок 0..N-1 - тесты: превью/конверсии/ошибки диапазона, сущности против mock_ac (снимок, команды, capabilities-фильтр, ручная конверсия), ConversionSet - mock_ac: --set NAME=VALUE (0b/0x) для сценариев - план: demand_control отложен (семантика не зафиксирована)
75 lines
2.3 KiB
Python
75 lines
2.3 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 (
|
|
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 (
|
|
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)
|