feat: show metered devices below rooms in utility overview

This commit is contained in:
jhartworks committed 2026-11-12 14:44:02 +01:00
1 parent 173d02e3cc
commit df4a6f36a3
14 files changed
+1791 -1577

No files matched your search

+11 -6
View File
@@ -4,7 +4,7 @@ import type { HomeAssistant } from "../types.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 → native areas → rooms with their own explicit meters. */
/** Building → floors, floor → native areas → rooms → placed devices with a linked power value. */
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;
@@ -37,9 +37,9 @@ 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 ? 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);
const entries = floor ? floorUtilityAreas(this.hass, floor, rooms, true).map((area) => ({ ...area, hasDetails: area.rooms.length > 0 }))
: [...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: [], hasDetails: floorUtilityAreas(this.hass, f, rooms, true).length > 0 }));
const shown = entries.filter((e) => e.readings.length || e.hasDetails);
if (!shown.length) return nothing;
const folded = this.folded ?? this.compact;
return html`<section class="panel" aria-label=${floor ? "Bereichszähler" : "Stockwerkszähler"}>
@@ -48,7 +48,9 @@ class NfUtilityOverview extends LitElement {
${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>`)}
${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)}
${room.devices.map((device) => html`<section class="device-entry" data-device=${device.id}><div class="entry-name device-name" title=${device.name}><span aria-hidden="true">↳</span> ${device.name}</div>${this.rows(device.readings)}</section>`)}
</section>`)}
</section>`)}
</div>`}
</section>`;
@@ -79,7 +81,10 @@ class NfUtilityOverview extends LitElement {
.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; }
.room-entry>.entry-name { padding-left:12px; color:var(--nf-muted); font-weight:normal; }
.device-entry { margin-top:4px; }
.device-entry>.device-name { padding-left:24px; color:var(--nf-muted); font-weight:normal; }
.device-name:hover { color:var(--nf-muted); }
.row { min-height:20px; }
.kind { color:var(--nf-muted); font-size:10px; white-space:nowrap; }
.row .value b { font-size:11px; font-weight:normal; }
+2 -2
View File
@@ -55,7 +55,7 @@ import { fixtureGlow } from "../entities/kinds.ts";
import { coverTiltEntity } from "../entities/covers.ts";
import { isSymcon, isSymconVariable, nativeBool, nativeText } from "../entities/symcon-values.ts";
import { WEATHER_VARIABLE_LABELS } from "../symcon-weather.ts";
import { floorUtilityReadings, utilityText } from "../utilities.ts";
import { floorUtilityAreas, floorUtilityReadings, utilityText } from "../utilities.ts";
import "./utility-report.ts";
import "./utility-overview.ts";
import { trendButton } from "./trend-button.ts";
@@ -2790,7 +2790,7 @@ export class NfView3d extends LitElement {
const b = this.building;
if (!b || !isSymcon(this.hass) || !this.showEnergy || this.clean || this.roomId || this.panelOpen || (!inline && !this._utilityOverviewVisible)) return nothing;
const rooms = b.floors.flatMap((f) => f.rooms), floors = this.floorId ? b.floors.filter((f) => f.id === this.floorId) : b.floors;
if (!floors.some((f) => floorUtilityReadings(this.hass, f, rooms).length)) return nothing;
if (!floors.some((f) => floorUtilityReadings(this.hass, f, rooms).length || floorUtilityAreas(this.hass, f, rooms, true).length)) return nothing;
return html`<nf-utility-overview ?inline=${inline} .hass=${this.hass} .floors=${b.floors} .floorId=${this.floorId} .compact=${this._narrowStage}
@utility-open=${(e: CustomEvent<{ floorId: string; roomId: string | null }>) => { e.stopPropagation(); if (e.detail.roomId) this.openRoom(e.detail.floorId, e.detail.roomId); else this.fire("floor-tap", { floorId: e.detail.floorId }); }}></nf-utility-overview>`;
}