# plugins/homeassistant/timeline.py """What Home Assistant maintenance puts on the timeline: each update once it ends.""" from __future__ import annotations from steward.timeline import catalog from steward.timeline.record import record_or_update TYPES = ( ("homeassistant.updated", "Home Assistant updated", "automation", "service", True, "Steward installed a Home Assistant update after a confirmed backup."), ("homeassistant.update_failed", "Home Assistant update failed", "automation", "service", True, "A Home Assistant update Steward was asked to install didn't finish."), ) def register() -> None: for t in TYPES: catalog.register_type(*t) from .models import HomeAssistantUpdate catalog.register_ref("homeassistant_update", HomeAssistantUpdate) async def update_entry(session, run) -> None: done = run.state == "done" versions = f"{run.from_version} to {run.to_version}" if run.to_version else "a new version" summary = (f"{run.title} updated from {versions}" if done else f"{run.title} update failed: {run.message}") await record_or_update( session, ("homeassistant_update", run.id), type="homeassistant.updated" if done else "homeassistant.update_failed", at=run.started_at, until=run.finished_at, summary=summary, subject=run.title, detail={"entity_id": run.entity_id, "from": run.from_version, "to": run.to_version, "url": "/plugins/homeassistant/"}, actor=run.started_by or "Steward")