182 files
This commit is contained in:
@@ -108,24 +108,17 @@ def _coerce_int(value: Any, default: int) -> int:
|
||||
|
||||
def _global_options(hass: HomeAssistant) -> dict[str, Any]:
|
||||
"""Return the global entry's options (or data), or {} when absent."""
|
||||
from ..const import DOMAIN, GLOBAL_UNIQUE_ID
|
||||
from .global_options import get_global_options
|
||||
|
||||
for entry in hass.config_entries.async_entries(DOMAIN):
|
||||
if entry.unique_id == GLOBAL_UNIQUE_ID:
|
||||
opts: dict[str, Any] = dict(entry.options or entry.data)
|
||||
return opts
|
||||
return {}
|
||||
return dict(get_global_options(hass))
|
||||
|
||||
|
||||
def _merged_tasks(entry: Any) -> dict[str, Any]:
|
||||
"""Static (ConfigEntry) + dynamic (Store) task data for an object entry."""
|
||||
from ..const import CONF_TASKS
|
||||
|
||||
tasks = entry.data.get(CONF_TASKS, {})
|
||||
rd = getattr(entry, "runtime_data", None)
|
||||
store = getattr(rd, "store", None) if rd else None
|
||||
merged: dict[str, Any] = store.merge_all_tasks(tasks) if store is not None else tasks
|
||||
return merged
|
||||
from .aggregate import merged_tasks
|
||||
|
||||
return merged_tasks(entry)
|
||||
|
||||
|
||||
async def async_run_retention_sweep(hass: HomeAssistant) -> None:
|
||||
@@ -171,17 +164,18 @@ async def async_run_retention_sweep(hass: HomeAssistant) -> None:
|
||||
continue
|
||||
|
||||
if to_archive:
|
||||
new_tasks = dict(entry.data.get(CONF_TASKS, {}))
|
||||
from .entry_tasks import write_tasks
|
||||
|
||||
existing = entry.data.get(CONF_TASKS, {})
|
||||
updates: dict[str, dict[str, Any]] = {}
|
||||
for tid in to_archive:
|
||||
if tid not in new_tasks:
|
||||
if tid not in existing:
|
||||
continue
|
||||
td = dict(new_tasks[tid])
|
||||
td = dict(existing[tid])
|
||||
td["archived_at"] = now_iso
|
||||
td["archived_reason"] = _REASON_AUTO
|
||||
new_tasks[tid] = td
|
||||
new_data = dict(entry.data)
|
||||
new_data[CONF_TASKS] = new_tasks
|
||||
hass.config_entries.async_update_entry(entry, data=new_data)
|
||||
updates[tid] = td
|
||||
write_tasks(hass, entry, updates)
|
||||
_LOGGER.info(
|
||||
"Auto-archived %d completed one-off task(s) in %s",
|
||||
len(to_archive),
|
||||
|
||||
Reference in New Issue
Block a user