182 files

This commit is contained in:
Home Assistant Version Control
2026-08-17 12:11:35 +00:00
parent 7dddf6bb13
commit ece15a1c1b
183 changed files with 11457 additions and 3092 deletions
@@ -12,7 +12,6 @@ from homeassistant.util import dt as dt_util
from ..const import (
CONF_OBJECT,
CONF_TASKS,
CONF_VACATION_BUFFER_DAYS,
CONF_VACATION_ENABLED,
CONF_VACATION_END,
@@ -24,7 +23,7 @@ from ..const import (
)
from ..helpers.schedule import read_legacy_fields
from ..helpers.vacation import compute_preview, get_vacation_state
from . import _get_global_entry, _get_object_entries
from . import _get_merged_tasks, _get_object_entries, _load_global_options, _save_global_options
def _state_payload(hass: HomeAssistant) -> dict[str, Any]:
@@ -64,12 +63,10 @@ async def ws_vacation_update(
msg: dict[str, Any],
) -> None:
"""Patch vacation config on the global entry. Partial updates allowed."""
global_entry = _get_global_entry(hass)
if global_entry is None:
connection.send_error(msg["id"], "not_found", "Global entry not found")
ctx = _load_global_options(hass, connection, msg)
if ctx is None:
return
options = dict(global_entry.options or global_entry.data)
global_entry, options = ctx
if "enabled" in msg:
options[CONF_VACATION_ENABLED] = bool(msg["enabled"])
@@ -126,7 +123,7 @@ async def ws_vacation_update(
break
options[CONF_VACATION_EXEMPT_TASK_IDS] = cleaned
hass.config_entries.async_update_entry(global_entry, options=options)
_save_global_options(hass, global_entry, options)
connection.send_result(msg["id"], _state_payload(hass))
@@ -157,12 +154,8 @@ async def ws_vacation_preview(
for entry in _get_object_entries(hass):
obj_data = entry.data.get(CONF_OBJECT, {})
obj_name = obj_data.get("name", "")
tasks_data = entry.data.get(CONF_TASKS, {})
# Merge dynamic store fields (last_performed, etc.) when available.
rd = getattr(entry, "runtime_data", None)
store = getattr(rd, "store", None) if rd else None
merged: dict[str, dict[str, Any]] = store.merge_all_tasks(tasks_data) if store is not None else dict(tasks_data)
merged = _get_merged_tasks(entry)
for task_id, task_data in merged.items():
sched = read_legacy_fields(task_data)
@@ -203,12 +196,11 @@ async def ws_vacation_end_now(
msg: dict[str, Any],
) -> None:
"""Disable vacation mode immediately, preserve the date config for reuse."""
global_entry = _get_global_entry(hass)
if global_entry is None:
connection.send_error(msg["id"], "not_found", "Global entry not found")
ctx = _load_global_options(hass, connection, msg)
if ctx is None:
return
global_entry, options = ctx
options = dict(global_entry.options or global_entry.data)
options[CONF_VACATION_ENABLED] = False
# Optionally clamp end-date to today so the historical record reflects when
# the user actually returned. Use HA's configured timezone — the user's
@@ -222,7 +214,7 @@ async def ws_vacation_end_now(
except (TypeError, ValueError):
pass
hass.config_entries.async_update_entry(global_entry, options=options)
_save_global_options(hass, global_entry, options)
connection.send_result(msg["id"], _state_payload(hass))