work: Полностью реализовал логику управления бризером.

This commit is contained in:
Fedorov Dmitriy
2026-09-13 19:39:07 +03:00
parent 9241da63c3
commit 5cc125db3f
8 changed files with 373 additions and 9 deletions
+56
View File
@@ -0,0 +1,56 @@
from dataclasses import asdict, dataclass
from typing import Any, Mapping
def _is_on(value: Any) -> bool:
return value == "on"
@dataclass(frozen=True, slots=True)
class TionState:
power: bool
heater: bool
heating: bool
sound: bool
mode: str
out_temp: int
in_temp: int
target_temp: int
fan_speed: int
filter_remain: float
device_time: str
request_error_code: int
model: str
light: bool | None = None
@classmethod
def from_raw(cls, data: Mapping[str, Any]) -> "TionState":
light_raw = data.get("light")
return cls(
power=_is_on(data["state"]),
heater=_is_on(data["heater"]),
heating=_is_on(data["heating"]),
sound=_is_on(data["sound"]),
mode=str(data["mode"]),
out_temp=int(data["out_temp"]),
in_temp=int(data["in_temp"]),
target_temp=int(data["heater_temp"]),
fan_speed=int(data["fan_speed"]),
filter_remain=float(data["filter_remain"]),
device_time=str(data["time"]),
request_error_code=int(data["request_error_code"]),
model=str(data["model"]),
light=None if light_raw is None else _is_on(light_raw),
)
def to_dict(self) -> dict:
return asdict(self)