work: Добваил нагрев в автоматизацию
This commit is contained in:
+17
-13
@@ -196,9 +196,7 @@ def _parse_action(
|
||||
action_type_raw = data.get("type")
|
||||
|
||||
try:
|
||||
action_type = ScheduleActionType(
|
||||
action_type_raw
|
||||
)
|
||||
action_type = ScheduleActionType(action_type_raw)
|
||||
|
||||
except ValueError as exc:
|
||||
raise ValueError(
|
||||
@@ -208,32 +206,38 @@ def _parse_action(
|
||||
|
||||
if action_type == ScheduleActionType.AUTO:
|
||||
|
||||
extra = set(data) - {
|
||||
allowed_fields = {
|
||||
"type",
|
||||
"speed",
|
||||
"target_temp",
|
||||
}
|
||||
|
||||
extra = set(data) - allowed_fields
|
||||
|
||||
if extra:
|
||||
raise ValueError(
|
||||
"AUTO action supports only "
|
||||
f"'speed': {sorted(extra)}"
|
||||
"'speed' and 'target_temp': "
|
||||
f"{sorted(extra)}"
|
||||
)
|
||||
|
||||
if "speed" not in data:
|
||||
raise ValueError(
|
||||
"AUTO action must contain "
|
||||
"fallback speed"
|
||||
"AUTO action requires 'speed'"
|
||||
)
|
||||
|
||||
settings = _parse_settings(
|
||||
{
|
||||
"speed": data["speed"],
|
||||
}
|
||||
)
|
||||
settings_data = {
|
||||
"speed": data["speed"],
|
||||
}
|
||||
|
||||
if "target_temp" in data:
|
||||
settings_data["target_temp"] = (
|
||||
data["target_temp"]
|
||||
)
|
||||
|
||||
return ScheduleAction(
|
||||
type=ScheduleActionType.AUTO,
|
||||
settings=settings,
|
||||
settings=_parse_settings(settings_data),
|
||||
)
|
||||
|
||||
settings_data = {
|
||||
|
||||
+2
-1
@@ -117,4 +117,5 @@ class ScheduleResolution:
|
||||
scheduled_settings: ScheduledSettings
|
||||
|
||||
auto_active: bool
|
||||
auto_fallback_speed: int | None
|
||||
auto_fallback_speed: int | None
|
||||
auto_target_temp: int | None = None
|
||||
+13
-49
@@ -191,15 +191,9 @@ class ScheduleService:
|
||||
|
||||
# Недели назад достаточно,
|
||||
# поскольку расписание повторяется каждые 7 дней.
|
||||
start_date = (
|
||||
now.date()
|
||||
- timedelta(days=7)
|
||||
)
|
||||
start_date = now.date() - timedelta(days=7)
|
||||
|
||||
end_date = (
|
||||
now.date()
|
||||
+ timedelta(days=7)
|
||||
)
|
||||
end_date = now.date() + timedelta(days=7)
|
||||
|
||||
occurrences = self._build_occurrences(
|
||||
start_date,
|
||||
@@ -231,17 +225,14 @@ class ScheduleService:
|
||||
)
|
||||
)
|
||||
|
||||
auto_active = (
|
||||
current.point.action.type
|
||||
== ScheduleActionType.AUTO
|
||||
)
|
||||
auto_active = current.point.action.type == ScheduleActionType.AUTO
|
||||
|
||||
auto_fallback_speed = None
|
||||
auto_target_temp = None
|
||||
|
||||
if auto_active:
|
||||
auto_fallback_speed = (
|
||||
current.point.action.settings.speed
|
||||
)
|
||||
auto_fallback_speed = current.point.action.settings.speed
|
||||
auto_target_temp = current.point.action.settings.target_temp
|
||||
|
||||
return ScheduleResolution(
|
||||
enabled=True,
|
||||
@@ -250,6 +241,7 @@ class ScheduleService:
|
||||
scheduled_settings=scheduled_settings,
|
||||
auto_active=auto_active,
|
||||
auto_fallback_speed=auto_fallback_speed,
|
||||
auto_target_temp=auto_target_temp,
|
||||
)
|
||||
|
||||
def _build_occurrences(
|
||||
@@ -384,39 +376,6 @@ class ScheduleService:
|
||||
except Exception as exc:
|
||||
self._last_error = f"{type(exc).__name__}: {exc}"
|
||||
|
||||
# async def _process(self, *, initial: bool = False) -> None:
|
||||
#
|
||||
# resolution = self.resolve()
|
||||
#
|
||||
# if not resolution.enabled:
|
||||
# return
|
||||
#
|
||||
# current = resolution.current
|
||||
#
|
||||
# if current is None:
|
||||
# return
|
||||
#
|
||||
# # Эта точка уже применена.
|
||||
# if (
|
||||
# not initial
|
||||
# and self._last_applied_when == current.when
|
||||
# ):
|
||||
# return
|
||||
#
|
||||
# # AUTO пока только распознаём.
|
||||
# # Сам AutoController подключим позже.
|
||||
# if (
|
||||
# current.point.action.type
|
||||
# == ScheduleActionType.AUTO
|
||||
# ):
|
||||
# self._last_applied_when = current.when
|
||||
# return
|
||||
#
|
||||
# settings = resolution.scheduled_settings
|
||||
#
|
||||
# await self._apply_settings(settings)
|
||||
#
|
||||
# self._last_applied_when = current.when
|
||||
|
||||
async def _process(self) -> None:
|
||||
now = datetime.now()
|
||||
@@ -477,7 +436,12 @@ class ScheduleService:
|
||||
# Остальные параметры расписания
|
||||
# (power, heater, temperature, mode...)
|
||||
# должны продолжать работать.
|
||||
settings = replace(settings, speed=None)
|
||||
settings = replace(
|
||||
settings,
|
||||
speed=None,
|
||||
heater=None,
|
||||
target_temp=None,
|
||||
)
|
||||
|
||||
await self._apply_settings(settings)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user