182 files
This commit is contained in:
@@ -19,6 +19,7 @@ from ..const import (
|
||||
DEFAULT_WARNING_DAYS,
|
||||
DOMAIN,
|
||||
GLOBAL_UNIQUE_ID,
|
||||
task_unique_id,
|
||||
)
|
||||
from ..helpers.aggregate import get_object_entries, get_runtime_data
|
||||
|
||||
@@ -38,22 +39,10 @@ _get_runtime_data = get_runtime_data
|
||||
|
||||
|
||||
def _get_merged_tasks(entry: ConfigEntry) -> dict[str, Any]:
|
||||
"""Return merged task data (static ConfigEntry + dynamic Store) for an entry."""
|
||||
tasks_data = entry.data.get(CONF_TASKS, {})
|
||||
rd = getattr(entry, "runtime_data", None)
|
||||
store = getattr(rd, "store", None) if rd else None
|
||||
if store is not None:
|
||||
merged = store.merge_all_tasks(tasks_data)
|
||||
# #73: overlay the in-cycle checklist ticks HERE rather than via the
|
||||
# merge whitelist — merged dicts feed MaintenanceTask.from_dict all
|
||||
# over the coordinator, and this field is presentation state the model
|
||||
# never needs.
|
||||
for tid, td in merged.items():
|
||||
progress = store.get_task_state(tid).get("checklist_progress")
|
||||
if progress:
|
||||
td["checklist_progress"] = progress
|
||||
return merged
|
||||
return tasks_data
|
||||
"""Return merged task data (thin re-export of helpers.aggregate.merged_tasks)."""
|
||||
from ..helpers.aggregate import merged_tasks
|
||||
|
||||
return merged_tasks(entry)
|
||||
|
||||
|
||||
# How many recent history entries ride in the LIST payload. Chosen to cover
|
||||
@@ -181,7 +170,7 @@ def _build_task_summary(
|
||||
er.async_get(hass).async_get_entity_id(
|
||||
"sensor",
|
||||
"maintenance_supporter",
|
||||
f"maintenance_supporter_{object_slug}_{task_id}",
|
||||
task_unique_id(object_slug, task_id),
|
||||
)
|
||||
if object_slug
|
||||
else None
|
||||
@@ -190,7 +179,7 @@ def _build_task_summary(
|
||||
er.async_get(hass).async_get_entity_id(
|
||||
"binary_sensor",
|
||||
"maintenance_supporter",
|
||||
f"maintenance_supporter_{object_slug}_{task_id}_overdue",
|
||||
task_unique_id(object_slug, task_id, "overdue"),
|
||||
)
|
||||
if object_slug
|
||||
else None
|
||||
@@ -412,6 +401,30 @@ def _get_global_entry(hass: HomeAssistant) -> ConfigEntry | None:
|
||||
return get_global_entry(hass)
|
||||
|
||||
|
||||
def _load_global_options(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
msg: dict[str, Any],
|
||||
) -> tuple[ConfigEntry, dict[str, Any]] | None:
|
||||
"""Resolve the global entry and a mutable copy of its options, or send the
|
||||
standard not-found error and return None.
|
||||
|
||||
The load → ``dict(options or data)`` → mutate → write-back triad was
|
||||
copied across groups/vacation/dashboard/saved-views handlers, each with a
|
||||
slightly different error message for the identical condition.
|
||||
"""
|
||||
global_entry = _get_global_entry(hass)
|
||||
if global_entry is None:
|
||||
connection.send_error(msg["id"], "not_found", "Global config entry not found")
|
||||
return None
|
||||
return global_entry, dict(global_entry.options or global_entry.data)
|
||||
|
||||
|
||||
def _save_global_options(hass: HomeAssistant, entry: ConfigEntry, options: dict[str, Any]) -> None:
|
||||
"""Write back a mutated global-options dict."""
|
||||
hass.config_entries.async_update_entry(entry, options=options)
|
||||
|
||||
|
||||
def _load_object_entry(
|
||||
hass: HomeAssistant,
|
||||
connection: websocket_api.ActiveConnection,
|
||||
@@ -556,6 +569,7 @@ def async_register_commands(hass: HomeAssistant) -> None:
|
||||
ws_export_csv,
|
||||
ws_export_data,
|
||||
ws_export_objects_csv,
|
||||
ws_export_settings,
|
||||
ws_generate_qr,
|
||||
ws_get_templates,
|
||||
ws_import_csv,
|
||||
@@ -658,6 +672,7 @@ def async_register_commands(hass: HomeAssistant) -> None:
|
||||
websocket_api.async_register_command(hass, ws_get_templates)
|
||||
websocket_api.async_register_command(hass, ws_version)
|
||||
websocket_api.async_register_command(hass, ws_export_data)
|
||||
websocket_api.async_register_command(hass, ws_export_settings)
|
||||
websocket_api.async_register_command(hass, ws_get_budget_status)
|
||||
websocket_api.async_register_command(hass, ws_schedule_preview)
|
||||
websocket_api.async_register_command(hass, ws_export_csv)
|
||||
|
||||
Reference in New Issue
Block a user