work: добавил автоматический режим
This commit is contained in:
+20
-5
@@ -208,16 +208,32 @@ def _parse_action(
|
||||
|
||||
if action_type == ScheduleActionType.AUTO:
|
||||
|
||||
extra = set(data) - {"type"}
|
||||
extra = set(data) - {
|
||||
"type",
|
||||
"speed",
|
||||
}
|
||||
|
||||
if extra:
|
||||
raise ValueError(
|
||||
"AUTO action cannot contain "
|
||||
f"SET fields: {sorted(extra)}"
|
||||
"AUTO action supports only "
|
||||
f"'speed': {sorted(extra)}"
|
||||
)
|
||||
|
||||
if "speed" not in data:
|
||||
raise ValueError(
|
||||
"AUTO action must contain "
|
||||
"fallback speed"
|
||||
)
|
||||
|
||||
settings = _parse_settings(
|
||||
{
|
||||
"speed": data["speed"],
|
||||
}
|
||||
)
|
||||
|
||||
return ScheduleAction(
|
||||
type=ScheduleActionType.AUTO
|
||||
type=ScheduleActionType.AUTO,
|
||||
settings=settings,
|
||||
)
|
||||
|
||||
settings_data = {
|
||||
@@ -233,7 +249,6 @@ def _parse_action(
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def _parse_template(
|
||||
name: str,
|
||||
data: Any,
|
||||
|
||||
+2
-1
@@ -116,4 +116,5 @@ class ScheduleResolution:
|
||||
|
||||
scheduled_settings: ScheduledSettings
|
||||
|
||||
auto_active: bool
|
||||
auto_active: bool
|
||||
auto_fallback_speed: int | None
|
||||
+22
-3
@@ -16,6 +16,7 @@ from .models import (
|
||||
ScheduledSettings,
|
||||
)
|
||||
|
||||
from dataclasses import replace
|
||||
|
||||
WEEKDAYS = (
|
||||
"mon",
|
||||
@@ -230,12 +231,20 @@ class ScheduleService:
|
||||
== ScheduleActionType.AUTO
|
||||
)
|
||||
|
||||
auto_fallback_speed = None
|
||||
|
||||
if auto_active:
|
||||
auto_fallback_speed = (
|
||||
current.point.action.settings.speed
|
||||
)
|
||||
|
||||
return ScheduleResolution(
|
||||
enabled=True,
|
||||
current=current,
|
||||
next=next_point,
|
||||
scheduled_settings=scheduled_settings,
|
||||
auto_active=auto_active,
|
||||
auto_fallback_speed=auto_fallback_speed,
|
||||
)
|
||||
|
||||
def _build_occurrences(
|
||||
@@ -451,18 +460,28 @@ class ScheduleService:
|
||||
return
|
||||
|
||||
# --------------------------------------------------
|
||||
# 4. Приводим Tion к ПОЛНОМУ актуальному
|
||||
# состоянию расписания
|
||||
# 4. Применяем состояние расписания
|
||||
# --------------------------------------------------
|
||||
|
||||
await self._apply_settings(resolution.scheduled_settings)
|
||||
settings = resolution.scheduled_settings
|
||||
|
||||
if resolution.auto_active:
|
||||
# В режиме AUTO скорость принадлежит
|
||||
# AutoController.
|
||||
#
|
||||
# Остальные параметры расписания
|
||||
# (power, heater, temperature, mode...)
|
||||
# должны продолжать работать.
|
||||
settings = replace(settings, speed=None)
|
||||
|
||||
await self._apply_settings(settings)
|
||||
|
||||
# Ставим только ПОСЛЕ успешного применения.
|
||||
self._last_applied_when = current.when
|
||||
self._last_error = None
|
||||
|
||||
|
||||
|
||||
async def _apply_settings(self, settings: ScheduledSettings) -> None:
|
||||
|
||||
if self._tion is None:
|
||||
|
||||
Reference in New Issue
Block a user