- M1: supported_features += TURN_ON/TURN_OFF (сервисы в HA 2026.9), async_turn_off; удалён мёртвый _enable_turn_on_off_backwards_compat; тест turn_on/turn_off → operation_mode 1/0 - M2: достижимый диапазон = override ∩ raw-таблица шаблона; raw клампится в from_display, clamp() по достижимому диапазону (молчаливый кламп ядра устранён); тесты scaled override - M3: mock_ac сбрасывает crypto/active на DELETE; тест reload → снова ONLINE - гонка: async_sync_now больше не перезаписывает данные устаревшим снимком (ONLINE мог потеряться при быстром старте) — стабильность 4×37 тестов - m1: превью-текст учитывает выбранный в форме шаблон; m2: убрана недостижимая проверка шага; m3: удалён мёртвый translation_key climate - m4: бит 21 op_status (шаблон B); m5: lru_cache template_info/prop_info; m6: operation_mode=1 без истории → hvac_mode unknown; m7: ошибка команды → HomeAssistantError; m8: unload возвращает False, не разбирая runtime - n2: уточнены описания data_description в переводах
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
"""Switches: флаги-свойства (economy/powerful/min_heat/...)."""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from homeassistant.components.switch import SwitchEntity
|
|
|
|
from pyfglair import Prop
|
|
from pyfglair.templates import prop_info
|
|
|
|
from .const import SWITCH_PROPS
|
|
from .coordinator import FglairCoordinator, FglairRuntime
|
|
from .entity import FglairEntity
|
|
|
|
|
|
class FglairSwitch(FglairEntity, SwitchEntity):
|
|
def __init__(
|
|
self,
|
|
coordinator: FglairCoordinator,
|
|
prop: Prop,
|
|
key: str,
|
|
) -> None:
|
|
super().__init__(coordinator, prop.name.lower(), key)
|
|
self._prop = prop
|
|
|
|
@property
|
|
def is_on(self) -> bool:
|
|
return self.raw_value(self._prop) == 1
|
|
|
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
|
await self.coordinator.async_write([(self._prop, 1)])
|
|
|
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
|
await self.coordinator.async_write([(self._prop, 0)])
|
|
|
|
|
|
async def async_setup_entry(hass, entry, async_add_entities) -> None:
|
|
runtime: FglairRuntime = entry.runtime_data
|
|
coordinator = runtime.coordinator
|
|
template = runtime.client.template
|
|
|
|
entities = []
|
|
for prop, (key, capability) in SWITCH_PROPS.items():
|
|
if prop_info(template, prop) is None:
|
|
continue
|
|
if not _capability_supported(coordinator, capability):
|
|
continue
|
|
entities.append(FglairSwitch(coordinator, prop, key))
|
|
async_add_entities(entities)
|
|
|
|
|
|
def _capability_supported(
|
|
coordinator: FglairCoordinator, bit: int | None
|
|
) -> bool:
|
|
if bit is None:
|
|
return True
|
|
caps = coordinator.data.values.get(Prop.DEVICE_CAPABILITIES)
|
|
if caps is None or not caps.int_value:
|
|
return True
|
|
return bool(caps.int_value & (1 << bit))
|