189 files

This commit is contained in:
Home Assistant Version Control committed 2026-09-08 18:05:32 +00:00
1 parent 79fefc0a7c
commit 303886f212
189 files changed
+21402 -3514

No files matched your search

@@ -116,9 +116,19 @@ _FRESH_COPY_STRIP_KEYS = (
"adaptive_config",
"archived_at",
"archived_reason",
# #170: a copy is a new task — it gets its own reference number.
"ref_no",
)
def strip_object_reference(obj: dict[str, Any]) -> dict[str, Any]:
"""A copied / successor object is a new object (#170): drop the reference
number and the task counter so the setup pass numbers it afresh."""
obj.pop("ref_no", None)
obj.pop("next_task_ref", None)
return obj
def strip_task_runtime_state(task: dict[str, Any]) -> dict[str, Any]:
"""Remove unique/dynamic state from a task dict copy, in place.
@@ -164,6 +174,12 @@ def cap_task_fields(task_data: dict[str, Any]) -> dict[str, Any]:
lo, hi = EARLIEST_COMPLETION_RANGE
task_data["earliest_completion_days"] = max(lo, min(ecd, hi))
# #170: a reference number is a positive int or nothing — junk from a
# hand-edited backup must not poison the counters.
ref = task_data.get("ref_no")
if ref is not None and (not isinstance(ref, int) or isinstance(ref, bool) or ref < 1):
task_data.pop("ref_no", None)
cl = task_data.get("checklist")
if cl is not None:
if not isinstance(cl, list):
@@ -175,6 +191,17 @@ def cap_task_fields(task_data: dict[str, Any]) -> dict[str, Any]:
cleaned = [c for c in cleaned if c]
task_data["checklist"] = cleaned[:MAX_CHECKLIST_ITEMS]
# #161 phase 2: reading slots — validated by the shared helper; an
# empty/invalid list simply means "single value" and is dropped.
rs = task_data.get("readings")
if rs is not None:
from .reading_slots import sanitize_reading_slots
slots = sanitize_reading_slots(rs)
if slots:
task_data["readings"] = slots
else:
task_data.pop("readings", None)
lb = task_data.get("labels")
if lb is not None:
task_data["labels"] = sanitize_labels(lb)