diff --git a/docs/changelog.md b/docs/changelog.md index 6c39a6b9..d56c8740 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -19,6 +19,23 @@ docstring gives: it is a record, not a claim about now. ## 2026-11-18 +- **`make up` now restarts Home Assistant, and the wall's alerts can no longer + crowd out its calendar.** + - **Home Assistant:** after the wall's house-and-calendar change deployed, + `sensor.wall_today`, `sensor.wall_alarm` and + `binary_sensor.wall_office_lights` did not exist until Home Assistant was + restarted by hand. Its `packages/` directory is mounted whole, so a changed + file is inside the container at once, and Home Assistant reads it only at + start. `scripts/reload-config.sh` now restarts it on every `make up` of a + stack that declares it, on the terms it already restarts Alloy. + - **The wall's left column:** with 12 alerts firing, the Alerts panel took + most of the column, its last row was cut in half, and Today showed two + events. Alerts now take at most half the column and four rows, worst + first, with "+N more". Both panels keep only the rows that fit. A + `.more` line height of 1 overhung its box by 3 px, which read as overflow + and emptied a panel; that is fixed too. Rendered against the pinned Caddy + with 12, 2 and 0 alerts, Today held at least four events each time. + - **CI now checks that a guarded SOPS value is one render writes.** [#1566](https://github.com/Gerrrt/HomeLab/issues/1566) added the `${WALL_HA_TOKEN:?}` guard to `stacks/sensitive/compose.yaml` and a diff --git a/scripts/reload-config.sh b/scripts/reload-config.sh index 2f1c963a..752fc841 100755 --- a/scripts/reload-config.sh +++ b/scripts/reload-config.sh @@ -38,6 +38,10 @@ # of this file, for reasons written out there. Its absence from this script is # what made `make up` a silent no-op for every config.alloy change. # +# Home Assistant is restarted at the bottom too, in a stack that declares it, for +# the same reason: it reads its packages only at start (see +# restart_home_assistant). +# # The snmp-exporter reload works only because render-config.sh writes the # rendered file with `>`, truncating in place and keeping the inode. The # container bind-mounts the file, not the directory, so switching to @@ -328,6 +332,41 @@ restart_alloy() { ok "alloy (restarted)" } +# Home Assistant is restarted on the same terms as Alloy. Its packages/ and +# custom_components/ are mounted as directories, so a changed file reaches the +# container's view at once (check_mounted_config.py has nothing to re-pin) and +# its process never: Home Assistant reads YAML only at start. Before this, the +# wall's packages from #1566 were on disk and in the container for a whole +# deploy, and sensor.wall_today, sensor.wall_alarm and +# binary_sensor.wall_office_lights did not exist until someone restarted it by +# hand. Its own reload services cover some integrations and not packages as a +# whole, and they need an admin token this script does not hold. +# +# Every `make up` of the stack, not only the ones that changed its YAML, for +# the reason restart_alloy gives against comparing mtimes. It costs about a +# minute without automations, and only on a deploy: converge's hourly no-op runs +# no `make up` at all. Waiting only for `running` here is enough, because +# check_container_health.py runs next and waits for the healthcheck. +restart_home_assistant() { + local stable=0 deadline + + is_running home-assistant || die \ + "home-assistant is not running, so there is nothing to reload. Check 'make ps', then 'make up'." + + "${COMPOSE[@]}" restart home-assistant >/dev/null 2>&1 || die "could not restart home-assistant" + + deadline=$((SECONDS + TIMEOUT)) + while ((stable < 3)); do + if is_running home-assistant; then stable=$((stable + 1)); else stable=0; fi + if ((SECONDS >= deadline)); then + die "home-assistant did not stay up within ${TIMEOUT}s. Check 'make logs SERVICE=home-assistant'." + fi + sleep 1 + done + + ok "home-assistant (restarted: it reads its packages only at start)" +} + # The socket proxy is restarted too, for the same reason as Alloy and one more. # HAProxy reads stacks/observability/docker-socket-proxy/haproxy.cfg only at # start, and that file is mounted as a directory, so a config-only change @@ -405,5 +444,11 @@ fi if [[ -z "${declared}" ]] || grep -qx alloy <<<"${declared}"; then restart_alloy fi +# Only when the stack declares it, with no fall-back to "restart it anyway": +# one stack runs Home Assistant, and a compose that cannot list its services is +# not a reason to restart a service it may not have. +if grep -qx home-assistant <<<"${declared}"; then + restart_home_assistant +fi printf '\033[0;32mreloaded\033[0m — every service re-read its config from disk\n' diff --git a/stacks/sensitive/home-assistant/packages/README.md b/stacks/sensitive/home-assistant/packages/README.md index cd15fdf7..e6e4af84 100644 --- a/stacks/sensitive/home-assistant/packages/README.md +++ b/stacks/sensitive/home-assistant/packages/README.md @@ -31,6 +31,13 @@ and nothing else. This README is not YAML and Home Assistant ignores it. | `wall_calendar.yaml` | `sensor.wall_today`: today's and tomorrow's events, asked of `calendar.get_events` every five minutes, for the office wall's Today panel (ADR-0119). The calendars are those labelled `wall_calendar` in the UI, or all of them when none is labelled, so no calendar is named here. Unavailable, not empty, when a calendar cannot be read | | `wall_house.yaml` | `sensor.wall_alarm` and `binary_sensor.wall_office_lights` for the office wall (ADR-0119): the house's one alarm panel's mode, and whether any light whose id contains `office` is on. Their own ids name the city and a person, so the wall reads these instead. Unavailable when nothing matches | +Home Assistant reads these files only when it starts, and the directory is +mounted as a whole, so a changed package is visible inside the container at +once and loaded by nothing. `make up` therefore restarts Home Assistant on every +deploy of this stack (`scripts/reload-config.sh`, `restart_home_assistant`). A +package change takes effect on the next converge or `make up`, with no restart +by hand, at the cost of about a minute without automations on each deploy. + There is no `automations.yaml`. The UI automation editor writes that file into `/config` and needs `automation: !include automations.yaml` to load it, and that include fails hard on a file that does not exist yet — which on a fresh diff --git a/stacks/sensitive/wall/wall.css b/stacks/sensitive/wall/wall.css index f46f1456..7f963964 100644 --- a/stacks/sensitive/wall/wall.css +++ b/stacks/sensitive/wall/wall.css @@ -117,11 +117,12 @@ html, body { color: var(--mute); } /* The left column: alerts on top, sized to what is firing, and the day's - events in what is left. Alerts come first; a busy alert list squeezes the - calendar, never the other way round. */ + events in what is left. Alerts come first, but only up to half the column: + at most four rows and a "+N more", so the calendar always keeps room for + about four events. */ .left { grid-area: left; display: flex; flex-direction: column; gap: 22px; min-height: 0; } -.alerts { flex: 0 1 auto; max-height: 70%; } -.today { flex: 1 1 0; min-height: 200px; } +.alerts { flex: 0 0 auto; max-height: 50%; box-sizing: border-box; } +.today { flex: 1 1 0; min-height: 300px; } .nodes { grid-area: nodes; } .wan { grid-area: wan; } .power { grid-area: power; } @@ -129,7 +130,7 @@ html, body { .household h2 { margin: 0; } /* ---------- alerts ---------- */ -.alerts-body { display: flex; flex-direction: column; gap: 14px; min-height: 0; } +.alerts-body { display: flex; flex-direction: column; gap: 14px; min-height: 0; overflow: hidden; } .quiet { font: 600 56px/1.15 var(--sans); color: var(--fg-dim); margin-top: 20px; } .quiet small { display: block; font: 400 28px/1.4 var(--sans); color: var(--mute); margin-top: 12px; } .al { display: flex; gap: 16px; align-items: stretch; } @@ -139,7 +140,7 @@ html, body { .al .m { font: 600 30px/1.2 var(--sans); min-width: 0; overflow-wrap: anywhere; } .al .m small { display: block; font: 400 22px/1.3 var(--mono); color: var(--mute); margin-top: 4px; } .al.critical .m { color: var(--red); } -.more { font: 400 24px/1 var(--mono); color: var(--mute); } +.more { font: 400 24px/1.3 var(--mono); color: var(--mute); } .broken { font: 600 40px/1.2 var(--sans); color: var(--red); } .broken small { display: block; font: 400 26px/1.4 var(--sans); color: var(--fg-dim); margin-top: 10px; } diff --git a/stacks/sensitive/wall/wall.js b/stacks/sensitive/wall/wall.js index 203f40d0..8e729387 100644 --- a/stacks/sensitive/wall/wall.js +++ b/stacks/sensitive/wall/wall.js @@ -56,6 +56,43 @@ }; const num = (r) => Number(r && r.value && r.value[1]); + // Keep the rows of a list that fit in its box, and say how many did not, so + // no panel ever ends on half a row. `rowClass` marks what counts as a row; + // `already` is how many were left out before rendering. A day heading + // ("Tomorrow") with nothing under it goes too. + function fitList(box, rowClass, already = 0) { + let hidden = already; + // Two pixels of slack: a glyph's descender can overhang its line box by a + // pixel or so, and counting that as overflow drops a row that fits. + const over = () => box.scrollHeight > box.clientHeight + 2; + const isRow = (e) => e.classList.contains(rowClass); + // A row is dropped even when it is the only thing left: one alert whose + // name wraps past the box is counted as "+1 more", not clipped. What is + // never dropped is a lone line that is not a row ("Nothing else today", + // or the "+N more" itself), since an empty panel says less than it does. + const canDrop = () => box.lastElementChild && (box.children.length > 1 || isRow(box.lastElementChild)); + const dropLast = () => { + if (isRow(box.lastElementChild)) hidden += 1; + box.lastElementChild.remove(); + }; + const dropHeading = () => { + while (box.lastElementChild && box.lastElementChild.classList.contains("day")) box.lastElementChild.remove(); + }; + while (over() && canDrop()) dropLast(); + dropHeading(); + if (!hidden) return; + const more = el("div", "more", ""); + for (;;) { + more.textContent = `+${hidden} more`; + box.append(more); + if (!over() || box.children.length === 1) return; + more.remove(); + dropLast(); + dropHeading(); + } + } + + // ---------- layout: scale the 1920x1080 stage to the window ---------- const stage = $("stage"); function fit() { @@ -161,7 +198,9 @@ verdict.dataset.state = worst; text.textContent = `${faults.length} alert${faults.length === 1 ? "" : "s"} firing`; - const SHOWN = 7; + // At most four, worst first, so a bad day cannot push the calendar off + // the wall. The rest are counted, and so is any row the box cannot fit. + const SHOWN = 4; for (const a of faults.slice(0, SHOWN)) { const m = a.metric; const row = el("div", `al ${m.severity || ""}`); @@ -172,7 +211,7 @@ row.append(msg); body.append(row); } - if (faults.length > SHOWN) body.append(el("div", "more", `+${faults.length - SHOWN} more`)); + fitList(body, "al", Math.max(0, faults.length - SHOWN)); } // ---------- nodes ---------- @@ -425,26 +464,7 @@ for (const e of later) box.append(eventRow(e, now)); } - // Keep what fits, and say how many did not. A "Tomorrow" heading with - // nothing under it goes too. - let hidden = 0; - while (box.scrollHeight > box.clientHeight && box.children.length > 1) { - if (box.lastElementChild.classList.contains("ev")) hidden += 1; - box.lastElementChild.remove(); - } - if (box.lastElementChild && box.lastElementChild.classList.contains("day")) box.lastElementChild.remove(); - if (hidden) { - const more = el("div", "more", `+${hidden} more`); - box.append(more); - while (box.scrollHeight > box.clientHeight && box.children.length > 1) { - more.remove(); - const last = box.lastElementChild; - if (last.classList.contains("ev")) hidden += 1; - last.remove(); - more.textContent = `+${hidden} more`; - box.append(more); - } - } + fitList(box, "ev"); } function render() {