feat: show scoped utility overviews and compact trend controls
This commit is contained in:
1 parent
2bf5f4a60a
commit
5fd674bb00
17 files changed
+987
-456
No files matched your search
@@ -14,7 +14,7 @@ export class NfTrendDialog extends LitElement {
|
||||
hass: { attribute: false }, ids: { attribute: false }, label: { attribute: false },
|
||||
from: { state: true }, to: { state: true }, resolution: { state: true }, chartStyle: { state: true }, field: { state: true },
|
||||
min: { state: true }, max: { state: true }, zero: { state: true }, band: { state: true }, live: { state: true },
|
||||
series: { state: true }, hiddenSeries: { state: true }, loading: { state: true }, errors: { state: true }, hover: { state: true }, width: { state: true }, page: { state: true },
|
||||
series: { state: true }, hiddenSeries: { state: true }, loading: { state: true }, errors: { state: true }, hover: { state: true }, width: { state: true }, plotHeight: { state: true }, page: { state: true },
|
||||
};
|
||||
declare hass: HomeAssistant;
|
||||
declare ids: string[];
|
||||
@@ -36,18 +36,20 @@ export class NfTrendDialog extends LitElement {
|
||||
private declare errors: string[];
|
||||
private declare hover: number | null;
|
||||
private declare width: number;
|
||||
private declare plotHeight: number;
|
||||
private declare page: number;
|
||||
private request = 0;
|
||||
private drag: number | null = null;
|
||||
private timer?: ReturnType<typeof setInterval>;
|
||||
private observer?: ResizeObserver;
|
||||
private resize = () => { this.plotHeight = Math.round(Math.min(600, Math.max(220, window.innerHeight * (window.innerWidth < 600 ? .52 : .65)))); };
|
||||
|
||||
constructor() {
|
||||
super(); this.ids = []; this.label = "";
|
||||
this.to = Math.floor(Date.now() / 1000); this.from = this.to - 86400;
|
||||
this.resolution = "auto"; this.chartStyle = "auto"; this.field = "v"; this.min = ""; this.max = "";
|
||||
this.zero = false; this.band = true; this.live = false; this.series = []; this.hiddenSeries = new Set();
|
||||
this.loading = false; this.errors = []; this.hover = null; this.width = 900; this.page = 0;
|
||||
this.loading = false; this.errors = []; this.hover = null; this.width = 900; this.plotHeight = 400; this.page = 0;
|
||||
}
|
||||
|
||||
async open() {
|
||||
@@ -55,11 +57,12 @@ export class NfTrendDialog extends LitElement {
|
||||
this.renderRoot.querySelector<HTMLDialogElement>("dialog")!.showModal();
|
||||
this.observer = new ResizeObserver(([e]) => { this.width = Math.max(280, Math.floor(e.contentRect.width)); });
|
||||
this.observer.observe(this.renderRoot.querySelector(".body")!);
|
||||
this.resize(); window.addEventListener("resize", this.resize);
|
||||
this.timer = setInterval(() => { if (this.live && !this.loading) { const span = this.to - this.from; this.to = Math.floor(Date.now() / 1000); this.from = this.to - span; void this.load(); } }, 30000);
|
||||
await this.load();
|
||||
}
|
||||
|
||||
disconnectedCallback() { super.disconnectedCallback(); ++this.request; clearInterval(this.timer); this.observer?.disconnect(); }
|
||||
disconnectedCallback() { super.disconnectedCallback(); ++this.request; clearInterval(this.timer); this.observer?.disconnect(); window.removeEventListener("resize", this.resize); }
|
||||
private async load() {
|
||||
const request = ++this.request, start = this.from, end = this.to;
|
||||
this.errors = []; this.series = []; this.hover = null; this.page = 0;
|
||||
@@ -97,7 +100,9 @@ export class NfTrendDialog extends LitElement {
|
||||
let low: number, high: number;
|
||||
try { [low, high] = trendBounds(numbers, this.min, this.max, this.zero || this.chartStyle === "bar" || series.some((s) => s.type === 0) || (this.chartStyle === "auto" && series.some((s) => s.counter && s.aggregation !== "raw"))); }
|
||||
catch (e) { return html`<p role="alert">${errorText(e)}</p>`; }
|
||||
const left = 64, right = this.width - 16, top = 14, bottom = 220;
|
||||
const groups = new Set(this.selected().filter((s) => s.type !== 3).map((s) => this.unit(s.entity_id))).size;
|
||||
const height = Math.max(200, Math.round(this.plotHeight / Math.max(1, Math.min(groups, 2))));
|
||||
const left = 64, right = this.width - 16, top = 14, bottom = height - 32;
|
||||
const x = (t: number) => left + (t - this.from) / (this.to - this.from) * (right - left);
|
||||
const y = (v: number) => bottom - (v - low) / (high - low) * (bottom - top);
|
||||
const point = (p: TrendPoint, field = this.field) => Number(field === "v" ? p.v : p[field] ?? p.v);
|
||||
@@ -107,13 +112,13 @@ export class NfTrendDialog extends LitElement {
|
||||
return ps.map((p, i) => `${i ? stepped ? `H${x(p.t).toFixed(1)}V` : "L" : "M"}${stepped && i ? y(point(p, field)).toFixed(1) : `${x(p.t).toFixed(1)},${y(point(p, field)).toFixed(1)}`}`).join("") + (ps.length ? stepped ? `H${right}` : s.aggregation === "raw" ? `L${right},${y(point(ps[ps.length - 1], field)).toFixed(1)}` : "" : "");
|
||||
};
|
||||
const ticks = this.width < 480 ? 2 : 5;
|
||||
return html`<section class="chart-group"><h3>${unit || "Wert"}</h3><svg class="plot" viewBox=${`0 0 ${this.width} 256`} role="img" aria-label=${`Trend ${unit}`} @wheel=${(e: WheelEvent) => { e.preventDefault(); this.zoom(e.deltaY > 0 ? 1.5 : 1 / 1.5, this.ratio(e)); }}
|
||||
return html`<section class="chart-group"><h3>${unit || "Wert"}</h3><svg class="plot" viewBox=${`0 0 ${this.width} ${height}`} role="img" aria-label=${`Trend ${unit}`} @wheel=${(e: WheelEvent) => { e.preventDefault(); this.zoom(e.deltaY > 0 ? 1.5 : 1 / 1.5, this.ratio(e)); }}
|
||||
@pointerdown=${(e: PointerEvent) => { this.drag = this.ratio(e); (e.currentTarget as Element).setPointerCapture(e.pointerId); }}
|
||||
@pointerup=${(e: PointerEvent) => { if (this.drag === null) return; const start = this.drag, end = this.ratio(e); this.drag = null; if (Math.abs(start - end) > .02) { const span = this.to - this.from; this.range(this.from + span * Math.min(start, end), this.from + span * Math.max(start, end)); } }}
|
||||
@pointercancel=${() => { this.drag = null; }} @pointermove=${(e: PointerEvent) => { this.hover = this.from + (this.to - this.from) * this.ratio(e); }}>
|
||||
<defs><clipPath id="plot-clip"><rect x=${left} y=${top} width=${right - left} height=${bottom - top}/></clipPath></defs>
|
||||
${[0, 1, 2, 3, 4].map((i) => { const v = low + (high - low) * i / 4; return svg`<line class="grid" x1=${left} x2=${right} y1=${y(v)} y2=${y(v)}/><text x=${left - 7} y=${y(v) + 4} text-anchor="end">${this.number(v)}</text>`; })}
|
||||
${Array.from({ length: ticks }, (_, i) => { const t = this.from + (this.to - this.from) * i / (ticks - 1); return svg`<text x=${x(t)} y="244" text-anchor=${i === 0 ? "start" : i === ticks - 1 ? "end" : "middle"}>${new Date(t * 1000).toLocaleString(this.hass.language, { month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" })}</text>`; })}
|
||||
${Array.from({ length: ticks }, (_, i) => { const t = this.from + (this.to - this.from) * i / (ticks - 1); return svg`<text x=${x(t)} y=${height - 8} text-anchor=${i === 0 ? "start" : i === ticks - 1 ? "end" : "middle"}>${new Date(t * 1000).toLocaleString(this.hass.language, { month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" })}</text>`; })}
|
||||
<g clip-path="url(#plot-clip)">${series.map((s) => {
|
||||
const bars = this.chartStyle === "bar" || (this.chartStyle === "auto" && s.counter && s.aggregation !== "raw");
|
||||
const color = this.color(s.entity_id);
|
||||
@@ -132,39 +137,112 @@ export class NfTrendDialog extends LitElement {
|
||||
render() {
|
||||
const selected = this.selected(), allString = selected.length > 0 && selected.every((s) => s.type === 3);
|
||||
const text = this.hover === null ? "Letzter Wert" : this.stamp(this.hover);
|
||||
return html`<dialog aria-label="Variablentrend" @close=${() => this.remove()} @keydown=${(e: KeyboardEvent) => e.stopPropagation()}>
|
||||
<header><div><h2>${this.label || "Variablentrend"}</h2><span>Symcon Archiv</span></div><button aria-label="Schließen" @click=${() => this.renderRoot.querySelector<HTMLDialogElement>("dialog")?.close()}>×</button></header>
|
||||
<div class="body"><div class="presets">${[["1 h", 3600], ["6 h", 21600], ["24 h", 86400], ["7 Tage", 604800], ["30 Tage", 2592000], ["1 Jahr", 31536000]].map(([label, seconds]) => html`<button @click=${() => { const end = Math.floor(Date.now() / 1000); this.range(end - Number(seconds), end); }}>${label}</button>`)}</div>
|
||||
<form @submit=${(e: Event) => { e.preventDefault(); void this.load(); }}><div class="fields">
|
||||
return html`<dialog aria-label="Variablentrend" @close=${() => this.remove()} @keydown=${(e: KeyboardEvent) => {
|
||||
e.stopPropagation();
|
||||
const settings = this.renderRoot.querySelector<HTMLDetailsElement>(".settings");
|
||||
if (e.key === "Escape" && settings?.open) { e.preventDefault(); settings.open = false; }
|
||||
}} @click=${(e: Event) => { const settings = this.renderRoot.querySelector<HTMLDetailsElement>(".settings"); if (settings?.open && !e.composedPath().includes(settings)) settings.open = false; }}>
|
||||
<header><div><h2>${this.label || "Variablentrend"}</h2><span class="range">${new Date(this.from * 1000).toLocaleString(this.hass.language, { dateStyle: "short", timeStyle: "short" })} – ${new Date(this.to * 1000).toLocaleString(this.hass.language, { dateStyle: "short", timeStyle: "short" })}</span></div><button aria-label="Schließen" @click=${() => this.renderRoot.querySelector<HTMLDialogElement>("dialog")?.close()}>×</button></header>
|
||||
<div class="body"><div class="toolbar"><div class="presets">${[["1 h", 3600], ["6 h", 21600], ["24 h", 86400], ["7 Tage", 604800], ["30 Tage", 2592000], ["1 Jahr", 31536000]].map(([label, seconds]) => html`<button aria-pressed=${this.to - this.from === seconds} @click=${() => { const end = Math.floor(Date.now() / 1000); this.range(end - Number(seconds), end); }}>${label}</button>`)}</div>
|
||||
<div class="navigation"><button aria-label="Vorheriger Zeitraum" title="Vorheriger Zeitraum" @click=${() => this.range(this.from - (this.to - this.from), this.from)}>←</button><button aria-label="Nächster Zeitraum" title="Nächster Zeitraum" @click=${() => this.range(this.to, this.to + (this.to - this.from))}>→</button><button aria-label="Hineinzoomen" title="Hineinzoomen" @click=${() => this.zoom(.5)}>+</button><button aria-label="Herauszoomen" title="Herauszoomen" @click=${() => this.zoom(2)}>−</button><button aria-label="Aktualisieren" title="Aktualisieren" aria-busy=${this.loading} @click=${() => void this.load()} ?disabled=${this.loading}>↻</button></div>
|
||||
<label class="live-toggle" title="Alle 30 Sekunden aktualisieren"><input type="checkbox" .checked=${this.live} @change=${(e: Event) => { this.live = (e.target as HTMLInputElement).checked; }}/> Live</label>
|
||||
<details class="settings"><summary aria-label="Trend-Einstellungen" title="Zeitraum, Auflösung und Darstellung">⚙︎</summary><div class="settings-panel">
|
||||
<form @submit=${(e: Event) => { e.preventDefault(); void this.load(); }}><div class="fields time-fields">
|
||||
<label>Von<input type="datetime-local" .value=${localDateTime(this.from)} @change=${(e: Event) => { this.from = Math.floor(new Date((e.target as HTMLInputElement).value).getTime() / 1000); this.live = false; void this.load(); }}/></label>
|
||||
<label>Bis<input type="datetime-local" .value=${localDateTime(this.to)} @change=${(e: Event) => { this.to = Math.floor(new Date((e.target as HTMLInputElement).value).getTime() / 1000); this.live = false; void this.load(); }}/></label>
|
||||
<label>Auflösung<select .value=${this.resolution} @change=${(e: Event) => { this.resolution = (e.target as HTMLSelectElement).value as TrendResolution; void this.load(); }}>${Object.entries(TREND_RESOLUTIONS).map(([id, label]) => html`<option value=${id}>${label}</option>`)}</select></label>
|
||||
<button type="submit" ?disabled=${this.loading}>${this.loading ? "Lädt …" : "Anzeigen"}</button>
|
||||
</div></form>
|
||||
<details class="settings"><summary>Darstellung und Wertebereich</summary><div class="fields">
|
||||
<div class="display-settings"><b class="group-title">Darstellung und Wertebereich</b><div class="fields display-fields">
|
||||
<label>Darstellung<select .value=${this.chartStyle} @change=${(e: Event) => { this.chartStyle = (e.target as HTMLSelectElement).value as typeof this.chartStyle; }}>${Object.entries({ auto: "Automatisch", line: "Linie", step: "Stufen", bar: "Balken", table: "Tabelle" }).map(([id, label]) => html`<option value=${id}>${label}</option>`)}</select></label>
|
||||
<label>Aggregierter Wert<select .value=${this.field} @change=${(e: Event) => { this.field = (e.target as HTMLSelectElement).value as typeof this.field; }}><option value="v">Mittelwert / Verbrauch</option><option value="min">Minimum</option><option value="max">Maximum</option></select></label>
|
||||
<label>Y-Minimum<input type="number" step="any" placeholder="Automatisch" .value=${this.min} @input=${(e: Event) => { this.min = (e.target as HTMLInputElement).value; }}/></label>
|
||||
<label>Y-Maximum<input type="number" step="any" placeholder="Automatisch" .value=${this.max} @input=${(e: Event) => { this.max = (e.target as HTMLInputElement).value; }}/></label>
|
||||
</div><div class="checks"><label><input type="checkbox" .checked=${this.zero} @change=${(e: Event) => { this.zero = (e.target as HTMLInputElement).checked; }}/> Nullpunkt einbeziehen</label><label><input type="checkbox" .checked=${this.band} @change=${(e: Event) => { this.band = (e.target as HTMLInputElement).checked; }}/> Min/Max anzeigen</label></div></details>
|
||||
<div class="actions"><button aria-label="Vorheriger Zeitraum" @click=${() => this.range(this.from - (this.to - this.from), this.from)}>←</button><button aria-label="Nächster Zeitraum" @click=${() => this.range(this.to, this.to + (this.to - this.from))}>→</button><button aria-label="Hineinzoomen" @click=${() => this.zoom(.5)}>+</button><button aria-label="Herauszoomen" @click=${() => this.zoom(2)}>−</button><button @click=${() => void this.load()} ?disabled=${this.loading}>Aktualisieren</button><label><input type="checkbox" .checked=${this.live} @change=${(e: Event) => { this.live = (e.target as HTMLInputElement).checked; }}/> Live (30 s)</label><button @click=${() => this.exportCsv()} ?disabled=${!selected.length}>CSV</button>
|
||||
</div><div class="checks"><label><input type="checkbox" .checked=${this.zero} @change=${(e: Event) => { this.zero = (e.target as HTMLInputElement).checked; }}/> Nullpunkt einbeziehen</label><label><input type="checkbox" .checked=${this.band} @change=${(e: Event) => { this.band = (e.target as HTMLInputElement).checked; }}/> Min/Max anzeigen</label></div></div>
|
||||
<div class="actions"><button @click=${() => this.exportCsv()} ?disabled=${!selected.length}>CSV</button>
|
||||
<nf-help-popup .text=${"Zeitraum und Auflösung lesen die originalen Symcon-Archivdaten. Rohdaten zeigen gespeicherte Änderungen; ein zuvor bekannter Wert wird zum Beginn fortgeführt. Bei Zählern sind aggregierte Werte der Verbrauch pro Intervall, bei Messwerten der Mittelwert. Mehrere Variablen werden einzeln dargestellt; unterschiedliche Einheiten erhalten eigene Diagramme. Zoomen: +/−, Mausrad oder im Diagramm einen Zeitraum ziehen. Eigene Y-Grenzen gelten für alle Diagramme. Begrenzte Rohdatenabfragen werden gekennzeichnet; wähle dann einen kürzeren Zeitraum oder eine Aggregation."}></nf-help-popup>
|
||||
</div>
|
||||
</div></div></details></div>
|
||||
<div class="legend">${this.ids.map((id) => html`<label title=${String(this.hass.states[id]?.attributes.symcon_path || entityName(this.hass, id))}><input type="checkbox" .checked=${!this.hiddenSeries.has(id)} @change=${(e: Event) => { const set = new Set(this.hiddenSeries); if ((e.target as HTMLInputElement).checked) set.delete(id); else set.add(id); this.hiddenSeries = set; this.requestUpdate(); }}/><i style=${`background:${this.color(id)}`}></i>${entityName(this.hass, id)}</label>`)}</div>
|
||||
${this.errors.map((e) => html`<p class="error" role="alert">${e}</p>`)}${this.loading ? html`<p class="note" role="status">Archivwerte werden geladen …</p>` : nothing}
|
||||
${selected.filter((s) => s.truncated).map((s) => html`<p class="error" role="status">${entityName(this.hass, s.entity_id)}: Die Abfrage ist auf ${(s.limit ?? 10000).toLocaleString(this.hass.language)} Einträge begrenzt. Bitte Zeitraum verkürzen oder Auflösung ändern.</p>`)}
|
||||
${selected.some((s) => s.counter && s.aggregation !== "raw") ? html`<p class="note">Zähler: Verbrauch pro Intervall</p>` : nothing}
|
||||
<div class="charts" style=${`min-height:${this.plotHeight}px`}>
|
||||
${this.chartStyle === "table" || allString ? this.table(selected) : [...new Set(selected.filter((s) => s.type !== 3).map((s) => this.unit(s.entity_id)))].map((unit) => this.plot(selected.filter((s) => s.type !== 3 && this.unit(s.entity_id) === unit), unit))}
|
||||
${selected.some((s) => s.type === 3) && !allString && this.chartStyle !== "table" ? this.table(selected.filter((s) => s.type === 3)) : nothing}
|
||||
${!this.loading && selected.length && selected.every((s) => !s.points.length) ? html`<p class="note">Keine Archivwerte in diesem Zeitraum.</p>` : nothing}
|
||||
</div>
|
||||
<div class="cursor"><b>${text}</b>${selected.map((s) => { let p = s.points.at(-1); if (this.hover !== null) { let lo = 0, hi = s.points.length; while (lo < hi) { const mid = (lo + hi) >>> 1; if (s.points[mid].t <= this.hover) lo = mid + 1; else hi = mid; } p = s.points[lo - 1]; } return html`<span style=${`color:${this.color(s.entity_id)}`}>${entityName(this.hass, s.entity_id)}: ${p ? typeof p.v === "number" ? `${this.number(this.value(p)!)} ${this.unit(s.entity_id)}` : p.v : "–"}</span>`; })}</div>
|
||||
</div>
|
||||
</dialog>`;
|
||||
}
|
||||
|
||||
static styles = [tokens, css`
|
||||
:host{font:14px/1.45 system-ui,sans-serif;color:var(--nf-text)}dialog{box-sizing:border-box;width:min(1080px,calc(100vw - 24px));max-height:92vh;max-height:92dvh;padding:0;border:1px solid var(--nf-line);border-radius:14px;background:var(--nf-chrome-solid,#1c1c1c);color:inherit;box-shadow:var(--nf-shadow);overflow:auto}dialog::backdrop{background:#050b16a8}header{display:flex;justify-content:space-between;align-items:center;gap:16px;padding:16px 20px;border-bottom:1px solid var(--nf-line)}h2{font-size:18px;margin:0}header span,.note{font-size:12px;color:var(--nf-muted)}header button{font-size:23px;width:36px;height:36px;padding:0}.body{padding:16px 20px}.presets,.actions,.checks,.legend,.cursor{display:flex;align-items:center;flex-wrap:wrap;gap:8px;margin:0 0 14px}.fields{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:10px;align-items:end;margin:12px 0}.fields label{display:grid;gap:5px;color:var(--nf-muted);font-size:12px}button,input,select{font:inherit;box-sizing:border-box;color:var(--nf-text)}button,select,input:not([type=checkbox]){border:1px solid var(--nf-line);border-radius:7px;padding:8px;background:var(--nf-fill,#292929);min-width:0}button{cursor:pointer}button:disabled{opacity:.45}button:focus-visible,input:focus-visible,select:focus-visible{outline:2px solid var(--nf-accent);outline-offset:2px}.settings{border:1px solid var(--nf-line);padding:10px 12px;border-radius:9px;margin:12px 0}summary{cursor:pointer}.checks label,.actions label,.legend label{display:flex;align-items:center;gap:6px;font-size:12px}.legend i{display:inline-block;width:10px;height:10px;border-radius:50%;flex-shrink:0}.legend label{max-width:100%;overflow-wrap:anywhere}.plot{display:block;width:100%;touch-action:none;user-select:none}.plot text{fill:var(--nf-muted);font:11px system-ui}.grid{stroke:var(--nf-line)}h3{font-size:12px;color:var(--nf-muted);margin:12px 0 0}.chart-group{margin-bottom:10px}.cursor{font-size:12px;align-items:flex-start}.cursor>b{width:100%;color:var(--nf-muted)}.cursor span{overflow-wrap:anywhere}.error{color:#ffa5a5}.table{overflow:auto;max-height:380px;margin:12px 0}table{width:100%;border-collapse:collapse;font-size:12px}td,th{text-align:left;padding:7px;border-bottom:1px solid var(--nf-line);overflow-wrap:anywhere}td:first-child{white-space:nowrap}th{position:sticky;top:0;background:var(--nf-chrome-solid,#1c1c1c)}@media(max-width:500px){header{padding:12px}.body{padding:10px}.fields{grid-template-columns:repeat(2,minmax(0,1fr))}input[type=datetime-local]{font-size:12px;padding:7px 3px}.actions{gap:6px}.actions button{padding:7px}header h2{font-size:16px}}
|
||||
header{position:sticky;top:0;z-index:2;background:var(--nf-chrome-solid,#1c1c1c)}
|
||||
:host { font:13px/1.4 system-ui,sans-serif; color:var(--nf-text); }
|
||||
dialog { box-sizing:border-box; width:min(1080px,calc(100vw - 24px)); max-height:92vh; max-height:92dvh; padding:0; border:1px solid var(--nf-line); border-radius:12px; background:var(--nf-chrome-solid,#1c1c1c); color:inherit; box-shadow:var(--nf-shadow); overflow:auto; }
|
||||
dialog::backdrop { background:#050b16a8; }
|
||||
header { display:flex; justify-content:space-between; align-items:center; gap:12px; padding:8px 12px; border-bottom:1px solid var(--nf-line); position:sticky; top:0; z-index:3; background:var(--nf-chrome-solid,#1c1c1c); }
|
||||
header>div { display:flex; align-items:baseline; flex-wrap:wrap; gap:3px 14px; min-width:0; }
|
||||
h2 { font-size:15px; margin:0; }
|
||||
.range { font-size:11px; color:var(--nf-muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
|
||||
header button { width:26px; height:26px; font-size:19px; padding:0; flex-shrink:0; }
|
||||
.body { padding:8px 12px; }
|
||||
.toolbar { position:relative; display:flex; align-items:center; flex-wrap:wrap; gap:5px 10px; margin-bottom:6px; }
|
||||
.presets,.navigation { display:flex; align-items:center; gap:3px; }
|
||||
button,input,select { box-sizing:border-box; color:var(--nf-text); font:inherit; }
|
||||
button,select,input:not([type=checkbox]),summary { border:1px solid var(--nf-line); border-radius:5px; padding:4px 7px; background:var(--nf-fill,#292929); min-width:0; }
|
||||
button { cursor:pointer; font-size:12px; }
|
||||
button:disabled { opacity:.45; }
|
||||
button:focus-visible,input:focus-visible,select:focus-visible,summary:focus-visible { outline:2px solid var(--nf-accent); outline-offset:2px; }
|
||||
.toolbar button,.toolbar summary { height:26px; }
|
||||
.navigation button { width:26px; padding:0; font-size:16px; }
|
||||
.presets button { padding:3px 6px; font-size:11px; }
|
||||
.presets button[aria-pressed=true],.settings[open]>summary { border-color:var(--nf-accent); background:color-mix(in srgb,var(--nf-accent) 16%,var(--nf-fill)); }
|
||||
.live-toggle { display:flex; align-items:center; gap:3px; font-size:11px; white-space:nowrap; }
|
||||
input[type=checkbox] { margin:0; }
|
||||
.settings { margin-left:auto; }
|
||||
.settings:not([open])>.settings-panel { display:none; }
|
||||
summary { display:flex; align-items:center; justify-content:center; width:28px; padding:0; list-style:none; font-size:17px; cursor:pointer; }
|
||||
summary::-webkit-details-marker { display:none; }
|
||||
.settings-panel { position:absolute; z-index:2; top:calc(100% + 5px); right:0; box-sizing:border-box; width:min(620px,100%); max-height:min(62vh,480px); overflow:auto; padding:10px 12px; border:1px solid var(--nf-line); border-radius:8px; background:var(--nf-chrome-solid,#1c1c1c); box-shadow:var(--nf-shadow); }
|
||||
.fields { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); align-items:end; gap:7px 10px; margin:0 0 10px; }
|
||||
.fields label { display:grid; gap:3px; color:var(--nf-muted); font-size:11px; }
|
||||
.fields input,.fields select { height:28px; width:100%; font-size:12px; }
|
||||
.time-fields button { justify-self:start; }
|
||||
.display-settings { padding-top:8px; border-top:1px solid var(--nf-line); }
|
||||
.group-title { display:block; margin-bottom:6px; font-size:12px; }
|
||||
.actions,.checks,.legend,.cursor { display:flex; align-items:center; flex-wrap:wrap; gap:6px 10px; }
|
||||
.checks { margin:0 0 6px; }
|
||||
.checks label,.legend label { display:flex; align-items:center; gap:4px; font-size:11px; }
|
||||
.legend { margin:4px 0 0; }
|
||||
.legend i { display:inline-block; width:8px; height:8px; border-radius:50%; flex-shrink:0; }
|
||||
.legend label { max-width:100%; overflow-wrap:anywhere; }
|
||||
.plot { display:block; width:100%; touch-action:none; user-select:none; }
|
||||
.plot text { fill:var(--nf-muted); font:11px system-ui; }
|
||||
.grid { stroke:var(--nf-line); }
|
||||
h3 { font-size:11px; color:var(--nf-muted); margin:3px 0 0; }
|
||||
.chart-group { margin-bottom:4px; }
|
||||
.cursor { font-size:11px; align-items:baseline; border-top:1px solid var(--nf-line); padding-top:6px; }
|
||||
.cursor>b { color:var(--nf-muted); font-weight:normal; }
|
||||
.cursor span { overflow-wrap:anywhere; }
|
||||
.note,.error { font-size:12px; margin:6px 0; }
|
||||
.note { color:var(--nf-muted); }
|
||||
.error { color:#ffa5a5; }
|
||||
.table { overflow:auto; max-height:60vh; margin:8px 0; }
|
||||
table { width:100%; border-collapse:collapse; font-size:12px; }
|
||||
td,th { text-align:left; padding:5px; border-bottom:1px solid var(--nf-line); overflow-wrap:anywhere; }
|
||||
td:first-child { white-space:nowrap; }
|
||||
th { position:sticky; top:0; background:var(--nf-chrome-solid,#1c1c1c); }
|
||||
@media(max-width:500px) {
|
||||
header { padding:7px 9px; }
|
||||
header>div { display:grid; gap:1px; }
|
||||
h2 { font-size:14px; }
|
||||
.body { padding:7px 9px; }
|
||||
.toolbar { gap:4px 6px; }
|
||||
.presets { gap:2px; }
|
||||
.presets button { padding:3px 5px; }
|
||||
.settings-panel { padding:9px; }
|
||||
input[type=datetime-local] { font-size:11px; padding:3px; }
|
||||
}
|
||||
`];
|
||||
}
|
||||
// Each lazy bundle has its own Lit copy; use an existing registration when another host loaded it first.
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
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 { trendButton } from "./trend-button.ts";
|
||||
|
||||
/** Building → floors, floor → rooms: the same native readings in the bar and the quiet side card. */
|
||||
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;
|
||||
declare floors: readonly Floor[];
|
||||
declare floorId: string | null;
|
||||
declare inline: boolean;
|
||||
declare compact: boolean;
|
||||
private declare folded: boolean | null;
|
||||
|
||||
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;
|
||||
}
|
||||
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 })); }
|
||||
|
||||
render() {
|
||||
if (!this.hass) return nothing;
|
||||
const rooms = this.floors.flatMap((f) => f.rooms), floor = this.floors.find((f) => f.id === this.floorId);
|
||||
if (this.inline) {
|
||||
const rows = floor ? floorUtilityReadings(this.hass, floor, rooms) : buildingUtilityReadings(this.hass, this.floors);
|
||||
return html`${UTILITY_KINDS.map((kind) => {
|
||||
const readings = rows.filter((r) => r.kind === kind);
|
||||
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 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>`);
|
||||
})}
|
||||
</section>`)}
|
||||
</div>`}
|
||||
</section>`;
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
:host { display:flex; width:100%; min-height:0; max-height:100%; color:var(--nf-text); font:12px/1.4 system-ui,sans-serif; pointer-events:auto; }
|
||||
:host([inline]) { display:flex; flex-wrap:wrap; align-items:stretch; gap:6px; width:auto; max-width:100%; }
|
||||
.meter { padding:5px 9px; border-radius:10px; background:var(--nf-chrome); border-left:2px solid var(--nf-line); backdrop-filter:blur(6px); }
|
||||
.medium { font-size:11px; color:var(--nf-muted); }
|
||||
.medium small { font-size:10px; }
|
||||
.values { display:flex; flex-wrap:wrap; gap:3px 10px; }
|
||||
.value { display:inline-flex; align-items:center; justify-content:flex-end; gap:3px; min-width:0; white-space:nowrap; font-variant-numeric:tabular-nums; }
|
||||
.value b { font-size:12px; font-weight:600; }
|
||||
.value small { color:var(--nf-muted); font-size:9px; }
|
||||
nf-trend-button { margin-left:0; }
|
||||
.panel { display:flex; flex-direction:column; box-sizing:border-box; width:100%; max-height:100%; border:1px solid var(--nf-line); border-radius:12px; background:var(--nf-chrome); backdrop-filter:blur(8px); overflow:hidden; }
|
||||
button { color:inherit; font:inherit; border:0; background:none; cursor:pointer; text-align:left; }
|
||||
button:focus-visible { outline:2px solid var(--nf-accent); outline-offset:-2px; }
|
||||
.heading { display:flex; flex-shrink:0; align-items:center; justify-content:space-between; gap:12px; width:100%; padding:8px 10px; font-weight:600; }
|
||||
.heading small { display:block; color:var(--nf-muted); font-size:10px; font-weight:normal; }
|
||||
.entries { min-height:0; max-height:min(50vh,480px); overflow:auto; padding:0 10px 8px; }
|
||||
.columns,.row { display:grid; grid-template-columns:54px minmax(0,1fr) minmax(0,1.2fr); align-items:center; gap:5px; }
|
||||
.columns { color:var(--nf-muted); font-size:9px; text-align:right; margin-bottom:2px; }
|
||||
.entry { border-top:1px solid var(--nf-line); padding:6px 0; }
|
||||
.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); }
|
||||
.row { min-height:20px; }
|
||||
.kind { color:var(--nf-muted); font-size:10px; white-space:nowrap; }
|
||||
.row .value b { font-size:11px; font-weight:normal; }
|
||||
@media(max-width:600px) { .entries { max-height:32vh; } }
|
||||
`;
|
||||
}
|
||||
if (!customElements.get("nf-utility-overview")) customElements.define("nf-utility-overview", NfUtilityOverview);
|
||||
@@ -54,6 +54,7 @@ import { isSymcon, isSymconVariable, nativeBool, nativeText } from "../entities/
|
||||
import { WEATHER_VARIABLE_LABELS } from "../symcon-weather.ts";
|
||||
import { floorUtilityReadings, utilityText } from "../utilities.ts";
|
||||
import "./utility-report.ts";
|
||||
import "./utility-overview.ts";
|
||||
import { trendButton } from "./trend-button.ts";
|
||||
import { deviceValuesText } from "../entities/device-values.ts";
|
||||
import { furnitureShown, hiddenFurniture, withoutHidden } from "../entities/visibility.ts";
|
||||
@@ -2527,15 +2528,15 @@ export class NfView3d extends LitElement {
|
||||
</section>`;
|
||||
}
|
||||
|
||||
private renderToday() {
|
||||
private renderToday(utilities: ReturnType<NfView3d["utilityOverview"]>) {
|
||||
const b = this.building;
|
||||
const hass = this.hass;
|
||||
// the room panel (a room, or Outside) takes the right side; the Today card would lie under it and catch its taps (#83)
|
||||
if (!b || !hass || this.clean || this.roomId || this.panelOpen) return nothing;
|
||||
const forecast = this.renderForecast("top_right");
|
||||
const today = this.today === false ? nothing : this.renderTodayCard(b, hass);
|
||||
if (today === nothing && forecast === nothing) return nothing;
|
||||
return html`<div class="nf-right-col" style=${this.clock === "top_right" ? "top: 78px" : ""}>${today}${forecast}</div>`;
|
||||
if (today === nothing && forecast === nothing && utilities === nothing) return nothing;
|
||||
return html`<div class="nf-right-col ${utilities !== nothing ? "nf-utility-right" : ""}" style=${this.clock === "top_right" ? "top: 78px" : ""}>${utilities}${today}${forecast}</div>`;
|
||||
}
|
||||
|
||||
private renderTodayCard(b: Building, hass: HomeAssistant) {
|
||||
@@ -2746,6 +2747,15 @@ export class NfView3d extends LitElement {
|
||||
}
|
||||
|
||||
/** The plan's own sensors at the top (outside temperature, the alarm…): their name and state; a tap opens their details. */
|
||||
private utilityOverview(inline: boolean) {
|
||||
const b = this.building;
|
||||
if (!b || !isSymcon(this.hass) || !this.showEnergy || this.clean || this.roomId || this.panelOpen) 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>`;
|
||||
}
|
||||
|
||||
private ownSensors() {
|
||||
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>`) : [];
|
||||
@@ -2756,7 +2766,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 [...people, weatherValues, utilities, ...ids
|
||||
return [this.utilityOverview(true), ...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)}>
|
||||
@@ -2819,17 +2829,18 @@ export class NfView3d extends LitElement {
|
||||
}
|
||||
|
||||
protected render() {
|
||||
const utilities = this.utilityOverview(false);
|
||||
const sky = this._sky;
|
||||
const mix = (a: number[], b: number[]) => `rgb(${a.map((v, i) => Math.round(v + (b[i] - v) * sky)).join(",")})`;
|
||||
const stage = STAGE[this.theme] ?? STAGE.neon;
|
||||
const style = `--nf-sky:${mix(stage.night[0], stage.day[0])};--nf-ground:${mix(stage.night[1], stage.day[1])}` + backdropStyle(this.building?.settings.backdrop);
|
||||
return html`<div
|
||||
class="nf-stage ${this.roomLabels ? "" : "nf-no-room-names"} ${this._low ? "nf-low" : ""} ${this.panelOpen ? "nf-panel-open" : ""} ${this._alerts.length ? "nf-has-alerts" : ""} ${this._narrowStage ? "nf-narrow" : ""}"
|
||||
class="nf-stage ${this.roomLabels ? "" : "nf-no-room-names"} ${this._low ? "nf-low" : ""} ${this.panelOpen ? "nf-panel-open" : ""} ${this._alerts.length ? "nf-has-alerts" : ""} ${this._narrowStage ? "nf-narrow" : ""} ${utilities !== nothing ? "nf-has-utility-overview" : ""}"
|
||||
style=${style}
|
||||
>
|
||||
${this._error ? html`<p class="nf-error">${this._error}</p>` : nothing} ${this.renderTopLeft()} ${renderLhCards(this.hass, this._liveCards, (domain, service, entity, data) => this.hass?.callService(domain, service, { entity_id: entity, ...data }), { folded: this._houseFolded, toggle: () => this.toggleHouseFold() }, !!this.roomId || this.panelOpen)} ${this.clean ? nothing : this.renderLegend()} ${this.renderMapCredit()}
|
||||
${this.renderAlerts()} ${this.renderAnnouncement()} ${this.clean ? nothing : html`${this.renderThumbs()} ${this.renderScenes()} ${this.renderFind()} ${this.renderCentral()}`} ${this.renderSwipe()}
|
||||
${this.renderMenu()} ${this.renderPlate()} ${this.renderEye()} ${this.renderLock()} ${this.renderWalk()} ${this.renderTravel()} ${this.renderClock()} ${this.renderToday()} ${this.renderLayers()} ${this.renderPluginWindow()}
|
||||
${this.renderMenu()} ${this.renderPlate()} ${this.renderEye()} ${this.renderLock()} ${this.renderWalk()} ${this.renderTravel()} ${this.renderClock()} ${this.renderToday(utilities)} ${this.renderLayers()} ${this.renderPluginWindow()}
|
||||
${this.showStats && this._stats
|
||||
? html`<span class="nf-stats"
|
||||
><b>${this._stats.fps ? translate(this.hass, "stats_fps", { fps: this._stats.fps, ms: this._stats.worstMs }) : translate(this.hass, "stats_idle")}</b>
|
||||
@@ -3411,6 +3422,24 @@ export class NfView3d extends LitElement {
|
||||
.nf-right-col > * {
|
||||
pointer-events: auto;
|
||||
}
|
||||
.nf-utility-right {
|
||||
height: calc(100% - 140px);
|
||||
}
|
||||
.nf-has-utility-overview:not(.nf-narrow) > .nf-energy,
|
||||
.nf-has-utility-overview:not(.nf-narrow) > .nf-topleft {
|
||||
max-width: calc(100% - 316px);
|
||||
}
|
||||
.nf-has-utility-overview .nf-energy {
|
||||
align-items: flex-start;
|
||||
}
|
||||
.nf-narrow .nf-utility-right {
|
||||
top: auto !important;
|
||||
bottom: 64px;
|
||||
height: 42%;
|
||||
max-height: 42%;
|
||||
justify-content: flex-end;
|
||||
width: min(280px, calc(100% - 24px));
|
||||
}
|
||||
.nf-has-alerts .nf-right-col {
|
||||
top: 58px;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { test } from "node:test";
|
||||
import { box, entity, floorWith, hassOf } from "./entities/fixtures.ts";
|
||||
import type { HomeAssistant, SymconObject } from "./types.ts";
|
||||
import { emptyBuilding, UTILITY_KINDS } from "./model.ts";
|
||||
import { floorMeter, floorUtilityReadings, roomUtilityReadings, utilityText, utilityWatched } from "./utilities.ts";
|
||||
import { buildingUtilityReadings, floorMeter, floorUtilityReadings, roomUtilityReadings, utilityText, utilityWatched } from "./utilities.ts";
|
||||
import { roomPower, roomPowerSensors } from "./heatmap.ts";
|
||||
import { floorCounts, floorInfoText } from "./presence.ts";
|
||||
import { watchedEntities } from "./components/view3d/watch-list.ts";
|
||||
@@ -165,3 +165,22 @@ test("the view watches automatic and all five manual floor meters even without h
|
||||
test("HA rooms do not gain guessed native utility readings", () => {
|
||||
assert.deepEqual(roomUtilityReadings(hassOf([]), box("r", 0, 0, 4, 3, "living")), []);
|
||||
});
|
||||
|
||||
test("building totals use effective floor meters, deduplicate shared sources and retain units and Err: partial sums", () => {
|
||||
const f = fixture(); f.node(10, 0, "A"); f.node(11, 10, "Strom");
|
||||
f.variable(12, 11, "Leistung", 100, "W"); f.variable(13, 11, "Verbrauch", 1, "kWh");
|
||||
f.node(20, 0, "B"); f.node(21, 20, "Strom");
|
||||
const bPower = f.variable(22, 21, "Leistung", 200, "W"); f.variable(23, 21, "Verbrauch", 2000, "Wh");
|
||||
f.node(24, 20, "Wasser"); f.variable(25, 24, "Verbrauch", 5, "m³");
|
||||
const manual = f.variable(90, 0, "Stockwerksleistung", 0.5, "kW");
|
||||
const a = floorWith([f.room()], { id: "a", utility_meters: { electricity: { power: manual } } }), b = floorWith([f.room(20)], { id: "b" });
|
||||
const h = f.hass();
|
||||
let rows = buildingUtilityReadings(h, [a, b]);
|
||||
assert.deepEqual(rows.map((r) => [r.kind, r.metric, r.unit, r.value]), [["electricity", "power", "W", 700], ["electricity", "energy", "kWh", 3], ["water", "energy", "m³", 5]]);
|
||||
const offline = { ...h, states: { ...h.states, [bPower]: { ...h.states[bPower], state: "unavailable" } } };
|
||||
assert.equal(utilityText(offline, buildingUtilityReadings(offline, [a, b])[0]), "Err: 500 W");
|
||||
b.utility_meters = { electricity: { power: manual } };
|
||||
rows = buildingUtilityReadings(h, [a, b]);
|
||||
assert.equal(rows[0].value, 500, "one shared native meter must not count twice in the building");
|
||||
assert.deepEqual(rows[0].sources, [manual]);
|
||||
});
|
||||
@@ -139,6 +139,13 @@ export function floorUtilityReadings(hass: HomeAssistant, floor: Floor, rooms: r
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Sum the effective floor meters; shared native sources count only once for the building. */
|
||||
export function buildingUtilityReadings(hass: HomeAssistant, floors: readonly Floor[]): UtilityReading[] {
|
||||
const rooms = floors.flatMap((f) => f.rooms);
|
||||
const sources = floors.flatMap((f) => floorUtilityReadings(hass, f, rooms).flatMap((r) => r.sources.map((id) => ({ kind: r.kind, metric: r.metric, period: r.period, id }))));
|
||||
return readings(hass, sources);
|
||||
}
|
||||
|
||||
export function utilityWatched(hass: HomeAssistant, floors: readonly Floor[]): string[] {
|
||||
const rooms = floors.flatMap((f) => f.rooms);
|
||||
return [...new Set(floors.flatMap((f) => [
|
||||
|
||||
Reference in new issue
Block a user