A new plugin reads Home Assistant with a read-only token every 5 minutes and shows which Core, OS and add-on updates are waiting and how old the last backup is. Install takes a backup through a local-only webhook, confirms Home Assistant's last-backup time moved, installs, and follows the update to its end, through Home Assistant's and Steward's own restarts. One runs at a time. Each ends as one timeline entry. Steward holds nothing that can act on the house: the webhook's automation can only take a backup or install an allowed update (System 231's ruling). A refused token stops polling, as Home Assistant bans an address after a few refusals. Milestone 576 steps 1 to 5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
2.8 KiB
Python
60 lines
2.8 KiB
Python
"""Home Assistant: the connection and the updates Steward was asked to install
|
|
|
|
Revision ID: homeassistant_001_connection
|
|
Revises: (none — a branch off core via depends_on)
|
|
Create Date: 2026-10-31
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision: str = "homeassistant_001_connection"
|
|
down_revision: Union[str, None] = None
|
|
branch_labels: Union[str, Sequence[str], None] = "homeassistant"
|
|
depends_on: Union[str, Sequence[str], None] = ("0004_app_settings",)
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"homeassistant_connection",
|
|
sa.Column("id", sa.String(36), primary_key=True),
|
|
sa.Column("url", sa.String(500), nullable=False),
|
|
sa.Column("token", sa.Text, nullable=False),
|
|
sa.Column("webhook_id", sa.Text, nullable=False),
|
|
sa.Column("verify_tls", sa.Boolean, nullable=False, server_default=sa.true()),
|
|
sa.Column("refused", sa.Boolean, nullable=False, server_default=sa.false()),
|
|
sa.Column("last_polled_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("last_ok_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("last_error", sa.Text, nullable=True),
|
|
sa.Column("updates", sa.JSON, nullable=False, server_default="[]"),
|
|
sa.Column("backup", sa.JSON, nullable=False, server_default="{}"),
|
|
sa.Column("automation", sa.String(20), nullable=True),
|
|
)
|
|
op.create_table(
|
|
"homeassistant_updates",
|
|
sa.Column("id", sa.String(36), primary_key=True),
|
|
sa.Column("entity_id", sa.String(255), nullable=False),
|
|
sa.Column("title", sa.String(255), nullable=False),
|
|
sa.Column("kind", sa.String(10), nullable=False),
|
|
sa.Column("from_version", sa.String(100), nullable=True),
|
|
sa.Column("to_version", sa.String(100), nullable=True),
|
|
sa.Column("state", sa.String(20), nullable=False, server_default="backing_up"),
|
|
sa.Column("message", sa.Text, nullable=True),
|
|
sa.Column("started_by", sa.String(100), nullable=False, server_default=""),
|
|
sa.Column("started_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column("backup_before", sa.String(64), nullable=True),
|
|
sa.Column("backup_event_before", sa.String(64), nullable=True),
|
|
sa.Column("triggered_before", sa.String(64), nullable=True),
|
|
sa.Column("backup_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("install_sent_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("finished_at", sa.DateTime(timezone=True), nullable=True),
|
|
)
|
|
op.execute("CREATE UNIQUE INDEX uq_homeassistant_update_under_way ON homeassistant_updates ((true)) "
|
|
"WHERE state IN ('backing_up', 'installing')")
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_table("homeassistant_updates")
|
|
op.drop_table("homeassistant_connection")
|