feat: toggle and remember right utility overview visibility

This commit is contained in:
jhartworks committed 2026-11-11 13:00:36 +01:00
1 parent 5fd674bb00
commit 6bd3598779
7 files changed
+130 -91

No files matched your search

+14 -3
View File
@@ -126,6 +126,7 @@ export class NfView3d extends LitElement {
_liveCards: { state: true },
_liveCardOn: { state: true },
_houseFolded: { state: true },
_utilityOverviewVisible: { state: true },
_swipe: { state: true },
_menu: { state: true },
_pluginWindow: { state: true },
@@ -407,6 +408,8 @@ export class NfView3d extends LitElement {
private declare _liveCardOn: boolean;
/** The house card folded to its ring by the small corner button; remembered in this browser. */
private declare _houseFolded: boolean;
/** Visibility of the right utility overview, remembered independently of the top totals. */
private declare _utilityOverviewVisible: boolean;
private viewer: NextFloorViewer | null = null;
private starting = false;
@@ -455,6 +458,8 @@ export class NfView3d extends LitElement {
this._liveCards = [];
this._liveCardOn = localStorage.getItem("nextfloor.cards") !== "0";
this._houseFolded = localStorage.getItem("nextfloor.house_card_folded") === "1";
try { this._utilityOverviewVisible = localStorage.getItem("nextfloor.utility_overview") !== "0"; }
catch { this._utilityOverviewVisible = true; }
this.selectedFurniture = null;
this.selectedDevice = null;
this._sky = 0;
@@ -2746,17 +2751,23 @@ export class NfView3d extends LitElement {
</button>`;
}
/** The plan's own sensors at the top (outside temperature, the alarm…): their name and state; a tap opens their details. */
/** Native utility readings for the current building/floor scope. */
private utilityOverview(inline: boolean) {
const b = this.building;
if (!b || !isSymcon(this.hass) || !this.showEnergy || this.clean || this.roomId || this.panelOpen) return nothing;
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;
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>`;
}
/** The plan's own sensors and utility controls at the top. */
private ownSensors() {
const summary = this.utilityOverview(true);
const overviewToggle = summary === nothing ? nothing : html`<button class="nf-energy-item nf-flow-toggle nf-utility-overview-toggle" aria-label="Rechte Übersicht" aria-pressed=${this._utilityOverviewVisible} title=${this._utilityOverviewVisible ? "Rechte Übersicht ausblenden" : "Rechte Übersicht einblenden"} @click=${() => {
this._utilityOverviewVisible = !this._utilityOverviewVisible;
try { localStorage.setItem("nextfloor.utility_overview", this._utilityOverviewVisible ? "1" : "0"); } catch { /* Keep the choice for this view when storage is unavailable. */ }
}}><span>Übersicht</span><b aria-hidden="true"><svg width="18" height="16" viewBox="0 0 20 16" fill="none" stroke="currentColor" stroke-width="1.3"><rect x="1" y="1" width="18" height="14" rx="2"/><path d="M12 1v14m2-10h3m-3 3h3m-3 3h3"/></svg></b></button>`;
const ids = this.sensorBar && this.hass ? (this.building?.settings.status_entities ?? []) : [];
const people = isSymcon(this.hass) ? (this.building?.presence ?? []).filter((link) => isSymconVariable(this.hass, link.person, [0])).map((link) => html`<div class="nf-energy-item nf-presence-state"><span>${link.name || entityName(this.hass, link.person)}</span><b>${nativeBool(this.hass.states[link.person]) === null ? "–" : nativeBool(this.hass.states[link.person]) ? "Anwesend" : "Abwesend"}${trendButton(this.hass, [link.person], link.name || "Anwesenheit")}</b></div>`) : [];
const weather = isSymcon(this.hass) ? Object.entries(this.building?.settings.weather_variables ?? {}).filter((entry): entry is [keyof typeof WEATHER_VARIABLE_LABELS, string] => !!entry[1] && entry[1] !== "none").map(([key, id]) => [WEATHER_VARIABLE_LABELS[key] || key, id]) : [];
@@ -2766,7 +2777,7 @@ export class NfView3d extends LitElement {
const floors = isSymcon(this.hass) ? (this.building?.floors ?? []).filter((f) => !this.floorId || f.id === this.floorId).map((f) => ({ floor: f, readings: floorUtilityReadings(this.hass, f, this.building?.floors.flatMap((x) => x.rooms)) })).filter((f) => f.readings.length) : [];
const utilities = floors.length ? html`<button class="nf-energy-item nf-flow-toggle nf-utility-toggle" aria-label="Stockwerkszähler anzeigen" title="Stockwerkszähler anzeigen" aria-haspopup="dialog" @click=${() => this.renderRoot.querySelector<HTMLDialogElement>(".nf-utility-dialog")?.showModal()}><span>Stockwerkszähler</span><b aria-hidden="true">⚡ 💧</b></button>
<dialog class="nf-weather-dialog nf-utility-dialog" aria-label="Stockwerkszähler" @keydown=${(event: KeyboardEvent) => event.stopPropagation()}><header><b>Stockwerkszähler</b><button type="button" class="nf-chip" aria-label="Schließen" @click=${() => this.renderRoot.querySelector<HTMLDialogElement>(".nf-utility-dialog")?.close()}>×</button></header>${floors.map(({ floor, readings }) => html`<h3>${floor.name}</h3><nf-utility-report .hass=${this.hass} .readings=${readings}></nf-utility-report>`)}</dialog>` : nothing;
return [this.utilityOverview(true), ...people, weatherValues, utilities, ...ids
return [overviewToggle, summary, ...people, weatherValues, utilities, ...ids
.filter((id) => this.hass.states[id])
.map(
(id) => html`<button class="nf-energy-item nf-own-sensor" title=${entityName(this.hass, id)} @click=${() => openMoreInfo(this, id)}>