fix: group utility overview by area and show explicit room meters

This commit is contained in:
jhartworks committed 2026-11-12 12:09:21 +01:00
1 parent 8c6b23bd22
commit 93c015ec77
17 files changed
+1475 -1253

No files matched your search

+2 -1
View File
@@ -15,6 +15,7 @@ import { generateWalls, innerSize, type Wall } from "../../../geometry/walls.ts"
import { countsAsLiving, roomArea } from "../../../geometry/living-area.ts";
import { roomSpeaker } from "../../../live/announce.ts";
import { isSymcon } from "../../../entities/symcon-values.ts";
import { renderSymconRoomMeters } from "../symcon-fields.ts";
/** What the room form makes the editor do, and the parts of it that the editor still draws itself. */
export interface RoomActions {
@@ -189,7 +190,7 @@ export function renderRoomForm(host: EditorHost, state: SideState, room: Room, a
<button class="nf-btn" title=${t("room_start_view_hint")} ?disabled=${!host.admin} @click=${() => actions.rememberView()}>${t("room_start_view")}</button>
${room.start_view ? html`<button class="nf-btn" title=${t("room_start_view_reset")} ?disabled=${!host.admin} @click=${() => actions.patch({ start_view: null })}>↺</button>` : nothing}
</div>
${actions.wallHeights} ${actions.climate} ${corners(host, room, rectangle, actions)}
${actions.wallHeights} ${actions.climate} ${isSymcon(host.hass) ? renderSymconRoomMeters(host, room, (change) => actions.patch(change)) : nothing} ${corners(host, room, rectangle, actions)}
${host.admin
? html`<div class="nf-actions">
<button class="nf-btn nf-primary" @click=${() => (state.packages = !state.packages)}>${t("pkg_open")}</button>
@@ -1,5 +1,6 @@
import { html, nothing } from "lit";
import { WEATHER_VARIABLE_KEYS, type BuildingSettings, type PresenceLink, type Room, type RoomHvac } from "../../model.ts";
import { UTILITY_KINDS, WEATHER_VARIABLE_KEYS, type BuildingSettings, type PresenceLink, type Room, type RoomHvac } from "../../model.ts";
import { UTILITY_ICONS, UTILITY_LABELS } from "../../utilities.ts";
import { WEATHER_VARIABLE_LABELS } from "../../symcon-weather.ts";
import { ROOM_HVAC_FIELDS } from "../../entities/room-hvac.ts";
import { isSymconVariable } from "../../entities/symcon-values.ts";
@@ -8,6 +9,18 @@ import { entityOptions } from "./entities.ts";
import { checkField, entityField, hint, textField } from "./fields.ts";
import type { EditorHost } from "./host.ts";
export function renderSymconRoomMeters(host: EditorHost, room: Room, patch: (change: Partial<Room>) => void) {
const options = entityOptions(host.hass, (id) => isSymconVariable(host.hass, id, [1, 2]));
return html`<details class="nf-room-utility-meters"><summary>Eigene Raumzähler</summary><div class="nf-form">
${hint("Nur direkt zugewiesene Raumzähler erscheinen als eingerückte Raumzeile unter dem verknüpften Bereich. Die Bereichswerte stehen einmal beim Bereich; vorhandene Bereichssummen enthalten die Raumwerte bereits. Fehlt dem Bereich ein passender Zähler, werden dafür die eigenen Raumzähler summiert.", "nf-wide")}
${UTILITY_KINDS.map((kind) => html`<b class="nf-wide">${UTILITY_ICONS[kind]} ${UTILITY_LABELS[kind]}</b>${(["power", "energy"] as const).map((metric) => entityField(host, metric === "power" ? "Leistung / Durchfluss" : "Energie / Verbrauch", room.utility_meters?.[kind]?.[metric] ?? null, undefined, options, (v) => {
const meters = { ...room.utility_meters, [kind]: { ...room.utility_meters?.[kind], [metric]: v === "none" ? null : v } };
if (!Object.values(meters[kind]!).some((id) => id && id !== "none")) delete meters[kind];
patch({ utility_meters: Object.keys(meters).length ? meters : null });
}, { types: [1, 2] }))}`)}
</div></details>`;
}
export function renderSymconRoomHvac(host: EditorHost, room: Room, patch: (change: Partial<Room>) => void) {
const set = (change: Partial<RoomHvac>) => patch({ hvac: { ...room.hvac, ...change } });
const schedules = room.hvac?.schedules ?? [];
+19 -10
View File
@@ -1,10 +1,10 @@
import { css, html, LitElement, nothing } from "lit";
import { UTILITY_KINDS, type Floor } from "../model.ts";
import type { HomeAssistant } from "../types.ts";
import { buildingUtilityReadings, floorUtilityReadings, roomUtilityReadings, UTILITY_ICONS, UTILITY_LABELS, utilityMetricLabel, utilityText, type UtilityReading } from "../utilities.ts";
import { buildingUtilityReadings, floorUtilityAreas, floorUtilityReadings, UTILITY_ICONS, UTILITY_LABELS, utilityMetricLabel, utilityText, type UtilityReading } from "../utilities.ts";
import { trendButton } from "./trend-button.ts";
/** Building → floors, floor → rooms: the same native readings in the bar and the quiet side card. */
/** Building → floors, floor → native areas → rooms with their own explicit meters. */
class NfUtilityOverview extends LitElement {
static properties = { hass: { attribute: false }, floors: { attribute: false }, floorId: { attribute: false }, inline: { type: Boolean, reflect: true }, compact: { type: Boolean }, folded: { state: true } };
declare hass: HomeAssistant;
@@ -16,10 +16,17 @@ class NfUtilityOverview extends LitElement {
constructor() { super(); this.floors = []; this.floorId = null; this.inline = false; this.compact = false; this.folded = null; }
private value(row: UtilityReading | undefined) {
return row ? html`<span class="value" title=${`${utilityMetricLabel(row)}${row.manual ? " · eigener Stockwerkszähler" : ""}`}><b>${utilityText(this.hass, row)}</b>${row.period !== "total" ? html`<small>${({ day: "heute", month: "Monat", year: "Jahr" })[row.period]}</small>` : nothing}${trendButton(this.hass, row.sources, `${UTILITY_LABELS[row.kind]} · ${utilityMetricLabel(row)}`)}</span>` : nothing;
return row ? html`<span class="value" title=${`${utilityMetricLabel(row)}${row.manual ? " · eigener Zähler" : ""}`}><b>${utilityText(this.hass, row)}</b>${row.period !== "total" ? html`<small>${({ day: "heute", month: "Monat", year: "Jahr" })[row.period]}</small>` : nothing}${trendButton(this.hass, row.sources, `${UTILITY_LABELS[row.kind]} · ${utilityMetricLabel(row)}`)}</span>` : nothing;
}
private open(id: string, room: boolean) { this.dispatchEvent(new CustomEvent("utility-open", { detail: { floorId: room ? this.floorId : id, roomId: room ? id : null }, bubbles: true, composed: true })); }
private rows(readings: UtilityReading[]) {
return UTILITY_KINDS.map((kind) => {
const powers = readings.filter((r) => r.kind === kind && r.metric === "power"), energies = readings.filter((r) => r.kind === kind && r.metric === "energy");
return Array.from({ length: Math.max(powers.length, energies.length) }, (_, i) => html`<div class="row"><span class="kind" title=${UTILITY_LABELS[kind]}>${i ? "" : `${UTILITY_ICONS[kind]} ${UTILITY_LABELS[kind]}`}</span>${powers[i] ? this.value(powers[i]) : html`<span></span>`}${energies[i] ? this.value(energies[i]) : html`<span></span>`}</div>`);
});
}
render() {
if (!this.hass) return nothing;
const rooms = this.floors.flatMap((f) => f.rooms), floor = this.floors.find((f) => f.id === this.floorId);
@@ -30,19 +37,18 @@ class NfUtilityOverview extends LitElement {
return readings.length ? html`<div class="meter" aria-label=${`${floor?.name || "Gesamtgebäude"} · ${UTILITY_LABELS[kind]}`}><span class="medium" title=${floor?.name || "Gesamtgebäude"}>${UTILITY_ICONS[kind]} ${UTILITY_LABELS[kind]}</span><div class="values">${readings.map((r) => this.value(r))}</div></div>` : nothing;
})}`;
}
const entries = floor ? floor.rooms.map((r) => ({ id: r.id, name: r.name, readings: roomUtilityReadings(this.hass, r, rooms) }))
: [...this.floors].sort((a, b) => b.elevation - a.elevation).map((f) => ({ id: f.id, name: f.name, readings: floorUtilityReadings(this.hass, f, rooms) }));
const entries = floor ? floorUtilityAreas(this.hass, floor, rooms)
: [...this.floors].sort((a, b) => b.elevation - a.elevation).map((f) => ({ id: f.id, name: f.name, path: "", readings: floorUtilityReadings(this.hass, f, rooms), rooms: [] }));
const shown = entries.filter((e) => e.readings.length);
if (!shown.length) return nothing;
const folded = this.folded ?? this.compact;
return html`<section class="panel" aria-label=${floor ? "Bereichszähler" : "Stockwerkszähler"}>
<button class="heading" aria-expanded=${!folded} @click=${() => { this.folded = !folded; }}><span>${floor ? "Bereiche" : "Stockwerke"}<small>${floor?.name || "Gesamtgebäude"}</small></span><span aria-hidden="true">${folded ? "+" : "−"}</span></button>
${folded ? nothing : html`<div class="entries"><div class="columns"><span></span><span title="Leistung bzw. Durchfluss">Leistung</span><span>Energie / Verbrauch</span></div>
${shown.map((entry) => html`<section class="entry"><button class="entry-name" title=${entry.name} @click=${() => this.open(entry.id, !!floor)}>${entry.name}</button>
${UTILITY_KINDS.map((kind) => {
const powers = entry.readings.filter((r) => r.kind === kind && r.metric === "power"), energies = entry.readings.filter((r) => r.kind === kind && r.metric === "energy");
return Array.from({ length: Math.max(powers.length, energies.length) }, (_, i) => html`<div class="row"><span class="kind" title=${UTILITY_LABELS[kind]}>${i ? "" : `${UTILITY_ICONS[kind]} ${UTILITY_LABELS[kind]}`}</span>${powers[i] ? this.value(powers[i]) : html`<span></span>`}${energies[i] ? this.value(energies[i]) : html`<span></span>`}</div>`);
})}
${shown.map((entry) => html`<section class="entry" data-area=${floor ? entry.id : nothing}>
${floor ? html`<div class="entry-name area-name" title=${entry.path || entry.name}>${entry.name}</div>` : html`<button class="entry-name" title=${entry.name} @click=${() => this.open(entry.id, false)}>${entry.name}</button>`}
${this.rows(entry.readings)}
${entry.rooms.map((room) => html`<section class="room-entry" data-room=${room.id}><button class="entry-name" title=${room.name} @click=${() => this.open(room.id, true)}><span aria-hidden="true">↳</span> ${room.name}</button>${this.rows(room.readings)}</section>`)}
</section>`)}
</div>`}
</section>`;
@@ -71,6 +77,9 @@ class NfUtilityOverview extends LitElement {
.entry:last-child { padding-bottom:0; }
.entry-name { display:block; width:100%; padding:0 0 3px; font-size:11px; font-weight:600; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; }
.entry-name:hover { color:var(--nf-accent); }
.area-name:hover { color:inherit; }
.room-entry { margin-top:5px; padding-top:4px; border-top:1px dotted var(--nf-line); }
.room-entry .entry-name { padding-left:12px; color:var(--nf-muted); font-weight:normal; }
.row { min-height:20px; }
.kind { color:var(--nf-muted); font-size:10px; white-space:nowrap; }
.row .value b { font-size:11px; font-weight:normal; }
+1 -1
View File
@@ -15,7 +15,7 @@ class NfUtilityReport extends LitElement {
render() {
return html`${UTILITY_KINDS.filter((kind) => this.readings.some((r) => r.kind === kind)).map((kind) => html`<section aria-label=${UTILITY_LABELS[kind]}>
<h4>${UTILITY_ICONS[kind]} ${UTILITY_LABELS[kind]}</h4>
${this.readings.filter((r) => r.kind === kind).map((r) => html`<div class="reading" title=${`${r.manual ? "Stockwerkszähler" : "Bereichszähler"}${r.incomplete ? " · Err: Mindestens ein Wert fehlt; angezeigt wird die Summe der verfügbaren Werte." : ""}\n${r.sources.map((id) => this.hass.states[id]?.attributes.symcon_path || this.hass.states[id]?.attributes.friendly_name || id).join("\n")}`}>
${this.readings.filter((r) => r.kind === kind).map((r) => html`<div class="reading" title=${`${r.manual ? "Eigener Zähler" : "Bereichszähler"}${r.incomplete ? " · Err: Mindestens ein Wert fehlt; angezeigt wird die Summe der verfügbaren Werte." : ""}\n${r.sources.map((id) => this.hass.states[id]?.attributes.symcon_path || this.hass.states[id]?.attributes.friendly_name || id).join("\n")}`}>
<span>${utilityMetricLabel(r)}${r.manual ? html` <small>· Zähler</small>` : ""}</span><b>${utilityText(this.hass, r)}${trendButton(this.hass, r.sources, `${UTILITY_LABELS[r.kind]} · ${utilityMetricLabel(r)}`)}</b>
</div>`)}
</section>`)}`;