fix: v1.5.7 исправил архитектуру управления температурой. Теперь отдельный контроллер отвечает за нагрев для всех режимов авто ручной или временный ручной. Раньше в каждом режиме была своя логика.
This commit is contained in:
+211
-113
@@ -57,6 +57,20 @@ class AutoConfig:
|
||||
elica_assist: ElicaAssistConfig
|
||||
|
||||
|
||||
@dataclass(
|
||||
frozen=True,
|
||||
slots=True,
|
||||
)
|
||||
class AutoConfigComponents:
|
||||
version: int
|
||||
check_interval: float
|
||||
|
||||
co2: Co2Config | None
|
||||
temperature: TemperatureConfig | None
|
||||
elica_assist: ElicaAssistConfig | None
|
||||
|
||||
errors: dict[str, str]
|
||||
|
||||
def _require_dict(name: str, value: Any) -> dict:
|
||||
|
||||
if not isinstance(value, dict):
|
||||
@@ -262,111 +276,32 @@ def _parse_co2(value: Any) -> Co2Config:
|
||||
thresholds=thresholds,
|
||||
)
|
||||
|
||||
|
||||
def load_auto_config(path: str | Path) -> AutoConfig:
|
||||
|
||||
path = Path(path)
|
||||
|
||||
with path.open(
|
||||
"r",
|
||||
encoding="utf-8",
|
||||
) as file:
|
||||
raw = yaml.safe_load(file)
|
||||
def _parse_temperature(value: Any) -> TemperatureConfig:
|
||||
|
||||
data = _require_dict(
|
||||
"AUTO config",
|
||||
raw,
|
||||
)
|
||||
|
||||
unknown = set(data) - {
|
||||
"version",
|
||||
"check_interval",
|
||||
"co2",
|
||||
"temperature",
|
||||
"elica_assist",
|
||||
}
|
||||
|
||||
if unknown:
|
||||
raise ValueError(
|
||||
f"Unknown AUTO config fields: "
|
||||
f"{sorted(unknown)}"
|
||||
)
|
||||
|
||||
version = data.get("version")
|
||||
|
||||
if version != 1:
|
||||
raise ValueError(
|
||||
f"Unsupported AUTO config "
|
||||
f"version: {version!r}"
|
||||
)
|
||||
|
||||
check_interval = data.get(
|
||||
"check_interval"
|
||||
value,
|
||||
)
|
||||
|
||||
if (
|
||||
type(check_interval) not in {
|
||||
int,
|
||||
float,
|
||||
}
|
||||
):
|
||||
raise ValueError(
|
||||
"check_interval must be a number"
|
||||
)
|
||||
|
||||
if check_interval <= 0:
|
||||
raise ValueError(
|
||||
"check_interval must be > 0"
|
||||
)
|
||||
|
||||
# --------------------------------------------------
|
||||
# CO2
|
||||
# --------------------------------------------------
|
||||
|
||||
if "co2" not in data:
|
||||
raise ValueError(
|
||||
"co2 config is required"
|
||||
)
|
||||
|
||||
co2 = _parse_co2(
|
||||
data["co2"]
|
||||
)
|
||||
|
||||
# --------------------------------------------------
|
||||
# Temperature
|
||||
# --------------------------------------------------
|
||||
|
||||
if "temperature" not in data:
|
||||
raise ValueError(
|
||||
"temperature config is required"
|
||||
)
|
||||
|
||||
temperature_data = _require_dict(
|
||||
"temperature",
|
||||
data["temperature"],
|
||||
)
|
||||
|
||||
unknown_temperature = (
|
||||
set(temperature_data)
|
||||
unknown = (
|
||||
set(data)
|
||||
- {
|
||||
"hysteresis",
|
||||
}
|
||||
)
|
||||
|
||||
if unknown_temperature:
|
||||
if unknown:
|
||||
raise ValueError(
|
||||
f"Unknown temperature config fields: "
|
||||
f"{sorted(unknown_temperature)}"
|
||||
f"{sorted(unknown)}"
|
||||
)
|
||||
|
||||
temperature_hysteresis = (
|
||||
temperature_data.get(
|
||||
"hysteresis"
|
||||
)
|
||||
hysteresis = data.get(
|
||||
"hysteresis"
|
||||
)
|
||||
|
||||
if (
|
||||
type(temperature_hysteresis)
|
||||
type(hysteresis)
|
||||
not in {
|
||||
int,
|
||||
float,
|
||||
@@ -377,45 +312,40 @@ def load_auto_config(path: str | Path) -> AutoConfig:
|
||||
"must be a number"
|
||||
)
|
||||
|
||||
temperature_hysteresis = float(
|
||||
temperature_hysteresis
|
||||
)
|
||||
hysteresis = float(hysteresis)
|
||||
|
||||
if temperature_hysteresis < 0:
|
||||
if hysteresis < 0:
|
||||
raise ValueError(
|
||||
"temperature.hysteresis "
|
||||
"must be >= 0"
|
||||
)
|
||||
|
||||
temperature = TemperatureConfig(
|
||||
hysteresis=temperature_hysteresis,
|
||||
return TemperatureConfig(
|
||||
hysteresis=hysteresis,
|
||||
)
|
||||
|
||||
def _parse_elica_assist(value: Any) -> ElicaAssistConfig:
|
||||
|
||||
# --------------------------------------------------
|
||||
# Elica Auto Assist
|
||||
# --------------------------------------------------
|
||||
|
||||
if "elica_assist" not in data:
|
||||
raise ValueError("elica_assist config is required")
|
||||
|
||||
elica_data = _require_dict(
|
||||
data = _require_dict(
|
||||
"elica_assist",
|
||||
data["elica_assist"],
|
||||
value,
|
||||
)
|
||||
|
||||
unknown_elica = (
|
||||
set(elica_data)
|
||||
unknown = (
|
||||
set(data)
|
||||
- {
|
||||
"enabled",
|
||||
"speed_map",
|
||||
}
|
||||
)
|
||||
|
||||
if unknown_elica:
|
||||
raise ValueError(f"Unknown elica_assist config fields: {sorted(unknown_elica)}")
|
||||
if unknown:
|
||||
raise ValueError(
|
||||
"Unknown elica_assist config fields: "
|
||||
f"{sorted(unknown)}"
|
||||
)
|
||||
|
||||
enabled = elica_data.get("enabled")
|
||||
enabled = data.get("enabled")
|
||||
|
||||
if type(enabled) is not bool:
|
||||
raise ValueError(
|
||||
@@ -423,19 +353,25 @@ def load_auto_config(path: str | Path) -> AutoConfig:
|
||||
"must be a boolean"
|
||||
)
|
||||
|
||||
speed_map_data = elica_data.get("speed_map")
|
||||
speed_map_data = data.get(
|
||||
"speed_map"
|
||||
)
|
||||
|
||||
if not isinstance(
|
||||
speed_map_data,
|
||||
dict,
|
||||
):
|
||||
raise ValueError("elica_assist.speed_map must be an object")
|
||||
raise ValueError(
|
||||
"elica_assist.speed_map "
|
||||
"must be an object"
|
||||
)
|
||||
|
||||
speed_map = []
|
||||
|
||||
for tion_speed, elica_speed in (
|
||||
speed_map_data.items()
|
||||
):
|
||||
|
||||
if type(tion_speed) is not int:
|
||||
raise ValueError(
|
||||
"elica_assist.speed_map keys "
|
||||
@@ -478,21 +414,183 @@ def load_auto_config(path: str | Path) -> AutoConfig:
|
||||
|
||||
speed_map.sort()
|
||||
|
||||
elica_assist = ElicaAssistConfig(
|
||||
return ElicaAssistConfig(
|
||||
enabled=enabled,
|
||||
speed_map=tuple(speed_map),
|
||||
)
|
||||
|
||||
def _load_auto_root(path: str | Path) -> tuple[dict, int, float]:
|
||||
path = Path(path)
|
||||
|
||||
with path.open(
|
||||
"r",
|
||||
encoding="utf-8",
|
||||
) as file:
|
||||
raw = yaml.safe_load(file)
|
||||
|
||||
data = _require_dict(
|
||||
"AUTO config",
|
||||
raw,
|
||||
)
|
||||
|
||||
unknown = set(data) - {
|
||||
"version",
|
||||
"check_interval",
|
||||
"co2",
|
||||
"temperature",
|
||||
"elica_assist",
|
||||
}
|
||||
|
||||
if unknown:
|
||||
raise ValueError(
|
||||
f"Unknown AUTO config fields: "
|
||||
f"{sorted(unknown)}"
|
||||
)
|
||||
|
||||
version = data.get("version")
|
||||
|
||||
if version != 1:
|
||||
raise ValueError(
|
||||
f"Unsupported AUTO config "
|
||||
f"version: {version!r}"
|
||||
)
|
||||
|
||||
check_interval = data.get(
|
||||
"check_interval"
|
||||
)
|
||||
|
||||
if (
|
||||
type(check_interval)
|
||||
not in {int,float,}
|
||||
):
|
||||
raise ValueError(
|
||||
"check_interval must be a number"
|
||||
)
|
||||
|
||||
if check_interval <= 0:
|
||||
raise ValueError(
|
||||
"check_interval must be > 0"
|
||||
)
|
||||
|
||||
return (data, version, float(check_interval))
|
||||
|
||||
|
||||
def load_auto_config(
|
||||
path: str | Path,
|
||||
) -> AutoConfig:
|
||||
|
||||
(
|
||||
data,
|
||||
version,
|
||||
check_interval,
|
||||
) = _load_auto_root(path)
|
||||
|
||||
# --------------------------------------------------
|
||||
# Result
|
||||
# CO2
|
||||
# --------------------------------------------------
|
||||
|
||||
if "co2" not in data:
|
||||
raise ValueError("co2 config is required")
|
||||
co2 = _parse_co2(data["co2"])
|
||||
|
||||
# --------------------------------------------------
|
||||
# Temperature
|
||||
# --------------------------------------------------
|
||||
|
||||
if "temperature" not in data:
|
||||
raise ValueError("temperature config is required")
|
||||
|
||||
temperature = _parse_temperature(data["temperature"])
|
||||
|
||||
# --------------------------------------------------
|
||||
# Elica Auto Assist
|
||||
# --------------------------------------------------
|
||||
|
||||
if "elica_assist" not in data:
|
||||
raise ValueError("elica_assist config is required")
|
||||
|
||||
elica_assist = _parse_elica_assist(data["elica_assist"])
|
||||
|
||||
return AutoConfig(
|
||||
version=version,
|
||||
check_interval=float(check_interval),
|
||||
check_interval=check_interval,
|
||||
co2=co2,
|
||||
temperature=temperature,
|
||||
elica_assist=elica_assist,
|
||||
)
|
||||
|
||||
def load_auto_config_components(path: str | Path) -> AutoConfigComponents:
|
||||
|
||||
( data,
|
||||
version,
|
||||
check_interval,
|
||||
) = _load_auto_root(path)
|
||||
|
||||
errors: dict[str, str] = {}
|
||||
|
||||
# --------------------------------------------------
|
||||
# CO2
|
||||
# --------------------------------------------------
|
||||
|
||||
co2 = None
|
||||
|
||||
if "co2" not in data:
|
||||
errors["co2"] = "ValueError: co2 config is required"
|
||||
|
||||
else:
|
||||
try:
|
||||
co2 = _parse_co2(data["co2"])
|
||||
|
||||
except Exception as exc:
|
||||
errors["co2"] = (
|
||||
f"{type(exc).__name__}: {exc}"
|
||||
)
|
||||
|
||||
# --------------------------------------------------
|
||||
# Temperature
|
||||
# --------------------------------------------------
|
||||
|
||||
temperature = None
|
||||
|
||||
if "temperature" not in data:
|
||||
errors["temperature"] = "ValueError: temperature config is required"
|
||||
|
||||
else:
|
||||
try:
|
||||
temperature = _parse_temperature(data["temperature"])
|
||||
|
||||
except Exception as exc:
|
||||
errors["temperature"] = (
|
||||
f"{type(exc).__name__}: {exc}"
|
||||
)
|
||||
|
||||
# --------------------------------------------------
|
||||
# Elica Assist
|
||||
# --------------------------------------------------
|
||||
|
||||
elica_assist = None
|
||||
|
||||
if "elica_assist" not in data:
|
||||
errors["elica_assist"] = "ValueError: elica_assist config is required"
|
||||
|
||||
else:
|
||||
try:
|
||||
elica_assist = _parse_elica_assist(data["elica_assist"])
|
||||
|
||||
except Exception as exc:
|
||||
errors["elica_assist"] = (
|
||||
f"{type(exc).__name__}: {exc}"
|
||||
)
|
||||
|
||||
return AutoConfigComponents(
|
||||
version=version,
|
||||
check_interval=check_interval,
|
||||
|
||||
co2=co2,
|
||||
temperature=temperature,
|
||||
elica_assist=elica_assist,
|
||||
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user