fix: follow topology in utility summaries and breakdowns
This commit is contained in:
1 parent
16eddacebf
commit
96e5311baf
11 files changed
+571
-383
No files matched your search
@@ -3,22 +3,26 @@ import { UTILITY_KINDS, type Floor } from "../model.ts";
|
||||
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";
|
||||
import { topologyKey, type TopologySelection } from "../topology.ts";
|
||||
import type { UtilityScope } from "../utility-scope.ts";
|
||||
|
||||
/** Building → floors, floor → native areas → rooms → placed devices with a linked power value. */
|
||||
/** Logical groups → their children, floor → native areas → rooms → metered devices. */
|
||||
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 } };
|
||||
static properties = { hass: { attribute: false }, floors: { attribute: false }, floorId: { attribute: false }, scope: { 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;
|
||||
declare scope: UtilityScope | null;
|
||||
private declare folded: boolean | null;
|
||||
|
||||
constructor() { super(); this.floors = []; this.floorId = null; this.inline = false; this.compact = false; this.folded = null; }
|
||||
constructor() { super(); this.floors = []; this.floorId = null; this.scope=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 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 openTopology(selection:TopologySelection){this.dispatchEvent(new CustomEvent("utility-topology-open",{detail:selection,bubbles:true,composed:true}));}
|
||||
|
||||
private rows(readings: UtilityReading[]) {
|
||||
return UTILITY_KINDS.map((kind) => {
|
||||
@@ -30,23 +34,25 @@ class NfUtilityOverview extends LitElement {
|
||||
render() {
|
||||
if (!this.hass) return nothing;
|
||||
const rooms = this.floors.flatMap((f) => f.rooms), floor = this.floors.find((f) => f.id === this.floorId);
|
||||
const scope=this.scope,areaMode=scope?scope.floorId!==null:!!floor;
|
||||
const name=scope?.name||floor?.name||"Gesamtgebäude",path=scope?.path||name,heading=scope?.heading||(floor?"Bereiche":"Stockwerke");
|
||||
if (this.inline) {
|
||||
const rows = floor ? floorUtilityReadings(this.hass, floor, rooms) : buildingUtilityReadings(this.hass, this.floors);
|
||||
const rows = scope?.totals??(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;
|
||||
return readings.length ? html`<div class="meter" aria-label=${`${name} · ${UTILITY_LABELS[kind]}`}><span class="medium" title=${path}>${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, 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);
|
||||
const entries = scope?.entries??(floor ? floorUtilityAreas(this.hass, floor, rooms, true).map((area) => ({ ...area, hasDetails: area.rooms.length > 0,selection:null }))
|
||||
: [...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,selection:null })));
|
||||
const shown = scope?entries:entries.filter((e) => e.readings.length || ("hasDetails" in e&&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"}>
|
||||
<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>
|
||||
return html`<section class="panel" aria-label=${`${heading} · ${name}`}>
|
||||
<button class="heading" title=${path} aria-expanded=${!folded} @click=${() => { this.folded = !folded; }}><span>${heading}<small>${name}</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" 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>`}
|
||||
${shown.map((entry) => html`<section class="entry" data-area=${areaMode ? entry.id : nothing} data-topology-kind=${entry.selection?.kind??nothing} data-topology-key=${entry.selection?topologyKey(entry.selection):nothing}>
|
||||
${areaMode ? html`<div class="entry-name area-name" title=${entry.path || entry.name}>${entry.name}</div>` : html`<button class="entry-name" title=${entry.path||entry.name} @click=${() => entry.selection?this.openTopology(entry.selection):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)}
|
||||
${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>`)}
|
||||
@@ -71,7 +77,8 @@ class NfUtilityOverview extends LitElement {
|
||||
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; }
|
||||
.heading>span:first-child { min-width:0; overflow:hidden; }
|
||||
.heading small { display:block; color:var(--nf-muted); font-size:10px; font-weight:normal; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
|
||||
.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; }
|
||||
|
||||
@@ -59,9 +59,10 @@ 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 { floorUtilityAreas, floorUtilityReadings, utilityText } from "../utilities.ts";
|
||||
import { floorUtilityReadings, utilityText } from "../utilities.ts";
|
||||
import "./utility-report.ts";
|
||||
import "./utility-overview.ts";
|
||||
import { utilityScope } from "../utility-scope.ts";
|
||||
import { trendButton } from "./trend-button.ts";
|
||||
import { deviceValuesText } from "../entities/device-values.ts";
|
||||
import { furnitureShown, hiddenFurniture, withoutHidden } from "../entities/visibility.ts";
|
||||
@@ -2832,9 +2833,10 @@ export class NfView3d extends LitElement {
|
||||
private utilityOverview(inline: boolean) {
|
||||
const b = this.building?this.scopeBuilding():null;
|
||||
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 || 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}
|
||||
const scope=utilityScope(this.hass,this.building!,this.topologyFocus);
|
||||
if(!scope.totals.length&&!scope.entries.length)return nothing;
|
||||
return html`<nf-utility-overview ?inline=${inline} .hass=${this.hass} .floors=${b.floors} .floorId=${this.floorId} .scope=${scope} .compact=${this._narrowStage}
|
||||
@utility-topology-open=${(e:CustomEvent<TopologySelection>)=>{e.stopPropagation();this.fire("topology-tap",e.detail);}}
|
||||
@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>`;
|
||||
}
|
||||
|
||||
|
||||
@@ -190,8 +190,7 @@ export function floorUtilityReadings(hass: HomeAssistant, floor: Floor, rooms: r
|
||||
}
|
||||
|
||||
/** 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);
|
||||
export function buildingUtilityReadings(hass: HomeAssistant, floors: readonly Floor[], rooms: readonly Room[] = floors.flatMap((f) => f.rooms)): UtilityReading[] {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { emptyBuilding, newFloor, UTILITY_KINDS, type UtilityKind } from "./model.ts";
|
||||
import { box, entity, hassOf } from "./entities/fixtures.ts";
|
||||
import { addTopologyOutside, outsideSelection } from "./topology.ts";
|
||||
import { utilityScope } from "./utility-scope.ts";
|
||||
import type { HomeAssistant, SymconObject } from "./types.ts";
|
||||
|
||||
function project(){
|
||||
const b=emptyBuilding(),states:ReturnType<typeof entity>[]=[];
|
||||
b.topology={locations:[{id:"u",name:"Urbach"},{id:"x",name:"Ulm"}],branches:[{id:"hq",name:"Zentrale",location_id:"u"},{id:"other",name:"Andere Niederlassung",location_id:"u"},{id:"south",name:"Süd",location_id:"x"}],buildings:[{id:"a",name:"RAS19",branch_id:"hq"},{id:"b",name:"RAS21",branch_id:"hq"},{id:"foreign",name:"Fremd",branch_id:"other"},{id:"distant",name:"Fern",branch_id:"south"}]};
|
||||
b.floors=[...[["a-eg","a",1],["a-og","a",2],["b-eg","b",3],["foreign-eg","foreign",40],["distant-eg","distant",100]].map(([id,parent,n],i)=>{
|
||||
const f={...newFloor(String(id),i===1?"OG":"EG",i===1?3:0),building_id:String(parent)};
|
||||
for(const [k,kind]of UTILITY_KINDS.entries()){
|
||||
const power=`sensor.${1000+i*100+k*2}`,energy=`sensor.${1001+i*100+k*2}`;
|
||||
const st=(id:string,value:number,unit:string)=>entity(id,String(value),{symcon_id:Number(id.slice(7)),symcon_variable_type:2,symcon_value:value,unit_of_measurement:unit});
|
||||
states.push(st(power,Number(n)*(k+1),kind==="water"||kind==="gas"?"m³/h":"kW"),st(energy,Number(n)*10*(k+1),kind==="water"||kind==="gas"?"m³":"kWh"));
|
||||
f.utility_meters={...f.utility_meters,[kind]:{power,energy}};
|
||||
}return f;
|
||||
})];
|
||||
const hass=hassOf(states,{}, {symconObjects:[],language:"de"});return {b,hass};
|
||||
}
|
||||
const value=(scope:ReturnType<typeof utilityScope>,kind:UtilityKind,metric:"power"|"energy")=>scope.totals.find((r)=>r.kind===kind&&r.metric===metric)?.value;
|
||||
|
||||
test("a branch lists its buildings with both metrics for all media and sums only its own descendants",()=>{
|
||||
const {b,hass}=project(),scope=utilityScope(hass,b,{kind:"branch",id:"hq"});
|
||||
assert.equal(scope.heading,"Gebäude");assert.equal(scope.name,"Zentrale");assert.equal(scope.floorId,null);
|
||||
assert.deepEqual(scope.entries.map((e)=>[e.name,e.selection]),[["RAS19",{kind:"building",id:"a"}],["RAS21",{kind:"building",id:"b"}]]);
|
||||
for(const [i,kind]of UTILITY_KINDS.entries()){
|
||||
assert.equal(value(scope,kind,"power"),6*(i+1)*(kind==="water"||kind==="gas"?1:1000));
|
||||
assert.equal(value(scope,kind,"energy"),60*(i+1));
|
||||
assert.equal(scope.entries[0].readings.find((r)=>r.kind===kind&&r.metric==="energy")?.value,30*(i+1));
|
||||
}
|
||||
});
|
||||
test("building, location and root overviews show their immediate level and floors retain their area breakdown",()=>{
|
||||
const {b,hass}=project(),building=utilityScope(hass,b,{kind:"building",id:"a"});
|
||||
assert.equal(building.heading,"Stockwerke");assert.equal(building.name,"RAS19");
|
||||
assert.deepEqual(building.entries.map((e)=>e.selection),[{kind:"floor",id:"a-og"},{kind:"floor",id:"a-eg"}]);
|
||||
assert.ok(building.entries[0].readings.every((r)=>r.manual),"a storey's own meter keeps its override metadata in the building breakdown");
|
||||
assert.equal(value(building,"electricity","energy"),30);
|
||||
assert.equal(utilityScope(hass,b,{kind:"location",id:"u"}).heading,"Niederlassungen");
|
||||
assert.deepEqual(utilityScope(hass,b,{kind:"location",id:"u"}).entries.map((e)=>e.name),["Zentrale","Andere Niederlassung"]);
|
||||
assert.equal(utilityScope(hass,b,{kind:"all"}).heading,"Orte");
|
||||
const floor=utilityScope(hass,b,{kind:"floor",id:"a-eg"});assert.equal(floor.heading,"Bereiche");assert.equal(floor.floorId,"a-eg");assert.equal(value(floor,"electricity","energy"),10);
|
||||
});
|
||||
test("owned outdoor meters are separate children and do not leak into neighbouring building totals",()=>{
|
||||
const {b,hass}=project(),yard=addTopologyOutside(b,{kind:"branch",id:"hq"}),terrace=addTopologyOutside(b,{kind:"building",id:"a"});
|
||||
yard.utility_meters={electricity:{energy:"sensor.1001"}};terrace.utility_meters={electricity:{energy:"sensor.1201"}};
|
||||
const branch=utilityScope(hass,b,{kind:"branch",id:"hq"}),building=utilityScope(hass,b,{kind:"building",id:"a"});
|
||||
assert.deepEqual(branch.entries.at(-1)?.selection,outsideSelection({kind:"branch",id:"hq"}));
|
||||
assert.deepEqual(building.entries.at(-1)?.selection,outsideSelection({kind:"building",id:"a"}));
|
||||
assert.equal(value(branch,"electricity","energy"),60,"a shared native variable is counted once across indoor and outdoor floor aliases");
|
||||
assert.equal(value(building,"electricity","energy"),60);
|
||||
assert.equal(value(utilityScope(hass,b,outsideSelection({kind:"branch",id:"hq"})),"electricity","energy"),10);
|
||||
});
|
||||
test("live readings retain zero, error subtotals, periods, unit conversions and archive source identities",()=>{
|
||||
const {b,hass}=project();b.floors[0].utility_meters!.electricity!.power="sensor.1000";
|
||||
hass.states["sensor.1001"].attributes.friendly_name="Verbrauch heute";
|
||||
hass.states["sensor.1101"]={...hass.states["sensor.1101"],state:"unavailable"};
|
||||
hass.states["sensor.1000"]={...hass.states["sensor.1000"],state:"0",attributes:{...hass.states["sensor.1000"].attributes,symcon_value:0}};
|
||||
const first=utilityScope(hass,b,{kind:"branch",id:"hq"});
|
||||
assert.equal(first.entries[0].readings.find((r)=>r.kind==="electricity"&&r.metric==="power")?.value,2000);
|
||||
const energy=first.entries[0].readings.filter((r)=>r.kind==="electricity"&&r.metric==="energy");
|
||||
assert.deepEqual(energy.map((r)=>[r.period,r.value,r.incomplete]),[["day",10,false],["total",null,true]]);
|
||||
assert.ok(energy[0].sources.includes("sensor.1001"));
|
||||
const changed={...hass,states:{...hass.states,"sensor.1200":{...hass.states["sensor.1200"],state:"0",attributes:{...hass.states["sensor.1200"].attributes,symcon_value:0}}}} as HomeAssistant;
|
||||
assert.equal(value(utilityScope(changed,b,{kind:"branch",id:"hq"}),"electricity","power"),2000);
|
||||
});
|
||||
test("native categories in other buildings remain excluded from every child subtotal as well as the header",()=>{
|
||||
const {b,hass}=project();for(const f of b.floors)f.utility_meters=null;
|
||||
b.floors[0].rooms=[box("parent-room",0,0,4,4,"symcon-category-10")];b.floors[2].rooms=[box("child-room",0,0,4,4,"symcon-category-20")];
|
||||
const node=(id:number,parent:number,name:string,type=0,extra={})=>({object_id:id,parent_id:parent,name,path:name,object_type:type,hidden:false,position:0,icon:"",...extra}) as SymconObject;
|
||||
hass.symconObjects=[node(10,0,"Parent"),node(11,10,"Strom"),node(12,11,"Leistung",2,{entity_id:"sensor.1000"}),node(20,10,"Child"),node(21,20,"Strom"),node(22,21,"Leistung",2,{entity_id:"sensor.1200"})];
|
||||
const scope=utilityScope(hass,b,{kind:"branch",id:"hq"});
|
||||
assert.deepEqual(scope.entries.map((e)=>e.readings[0].value),[1000,3000]);assert.equal(value(scope,"electricity","power"),4000);
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
import type { Building } from "./model.ts";
|
||||
import type { HomeAssistant } from "./types.ts";
|
||||
import { floorSelection, outsideFloor, topologyPath, type TopologySelection } from "./topology.ts";
|
||||
import { buildingUtilityReadings, floorUtilityAreas, floorUtilityReadings, type UtilityArea, type UtilityReading } from "./utilities.ts";
|
||||
|
||||
export interface UtilityScopeEntry {
|
||||
id: string; name: string; path: string; readings: UtilityReading[];
|
||||
rooms: UtilityArea["rooms"]; selection: TopologySelection | null;
|
||||
}
|
||||
export interface UtilityScope {
|
||||
name: string; path: string; heading: string; floorId: string | null;
|
||||
totals: UtilityReading[]; entries: UtilityScopeEntry[];
|
||||
}
|
||||
|
||||
/** Use logical descendants for totals and immediate children for the right-hand breakdown. */
|
||||
export function utilityScope(hass: HomeAssistant, b: Building, selection: TopologySelection): UtilityScope {
|
||||
// A shared discovery context keeps nested native categories in other buildings out of every subtotal.
|
||||
const rooms=b.floors.flatMap((f)=>f.rooms);
|
||||
const floorId=selection.kind==="room"?selection.floorId:selection.kind==="floor"?selection.id:outsideFloor(b,selection)?.id;
|
||||
const floor=b.floors.find((f)=>f.id===floorId);
|
||||
if(floor){
|
||||
const path=b.topology?topologyPath(b,floorSelection(b,floor.id)).slice(1).map((n)=>n.name).join(" / "):floor.name;
|
||||
return {name:floor.name,path,heading:"Bereiche",floorId:floor.id,totals:floorUtilityReadings(hass,floor,rooms),
|
||||
entries:floorUtilityAreas(hass,floor,rooms,true).map((area)=>({...area,selection:null}))};
|
||||
}
|
||||
if(!b.topology){
|
||||
const entries=[...b.floors].sort((a,z)=>z.elevation-a.elevation).map((f)=>({id:f.id,name:f.name,path:f.name,readings:floorUtilityReadings(hass,f,rooms),rooms:[],selection:floorSelection(b,f.id)}));
|
||||
return {name:"Gesamtgebäude",path:"Gesamtgebäude",heading:"Stockwerke",floorId:null,totals:buildingUtilityReadings(hass,b.floors,rooms),
|
||||
entries:entries.filter((e)=>e.readings.length||floorUtilityAreas(hass,b.floors.find((f)=>f.id===e.id)!,rooms,true).length)};
|
||||
}
|
||||
const path=topologyPath(b,selection),node=path.at(-1)!;
|
||||
const floorsFor=(ids:readonly string[])=>{const selected=new Set(ids);return b.floors.filter((f)=>selected.has(f.id));};
|
||||
const entries=node.children.map((child)=>{
|
||||
const floors=floorsFor(child.floorIds);
|
||||
return {id:child.key,name:child.name,path:[...path.slice(1).map((n)=>n.name),child.name].join(" / "),
|
||||
readings:(child.selection.kind==="floor"||child.selection.kind==="outside")&&floors.length===1?floorUtilityReadings(hass,floors[0],rooms):buildingUtilityReadings(hass,floors,rooms),rooms:[],selection:child.selection,
|
||||
hasDetails:floors.some((f)=>floorUtilityAreas(hass,f,rooms,true).length)};
|
||||
}).filter((e)=>e.readings.length||e.hasDetails);
|
||||
const heading=({all:"Orte",location:"Niederlassungen",branch:"Gebäude",building:"Stockwerke"} as Record<string,string>)[node.selection.kind]??"Bereiche";
|
||||
return {name:node.name,path:path.slice(1).map((n)=>n.name).join(" / ")||node.name,heading,floorId:null,
|
||||
totals:buildingUtilityReadings(hass,floorsFor(node.floorIds),rooms),entries};
|
||||
}
|
||||
@@ -105,6 +105,53 @@ try{
|
||||
assert.deepEqual(await page.evaluate(()=>window.nfPanel.shadowRoot.querySelector("nf-room-panel").outside.slice().sort()),["sensor.903","sensor.906"]);
|
||||
await page.screenshot({path:join(out,"symcon-topology-building-outside.png")});
|
||||
|
||||
// Utility panels drill into immediate logical children; totals use exactly the selected descendants.
|
||||
await page.evaluate(async()=>{
|
||||
const p=window.nfPanel,b=structuredClone(window.topologyProject),states={...p.hass.states};
|
||||
b.topology.buildings.find((g)=>g.id==="ras21").branch_id="hq";
|
||||
for(const [i,[id,power,energy]]of[["eg",100,10],["og",200,20],["west-eg",500,50],["ulm-eg",9000,900],["outside-hq",150,15],["outside-ras19",50,5],["outside-a",1000,100]].entries()){
|
||||
const f=b.floors.find((f)=>f.id===id),powerId=`sensor.${9501+i*2}`,energyId=`sensor.${9502+i*2}`;
|
||||
f.utility_meters={electricity:{power:powerId,energy:energyId}};
|
||||
for(const [eid,value,unit]of[[powerId,power,"W"],[energyId,energy,"kWh"]])states[eid]={entity_id:eid,state:String(value),attributes:{symcon_id:Number(eid.slice(7)),symcon_variable_type:2,symcon_value:value,unit_of_measurement:unit,friendly_name:unit==="W"?"Leistung":"Verbrauch",symcon_archive:{id:999,counter:false}}};
|
||||
}
|
||||
window.topologyProject=structuredClone(b);p.hass={...p.hass,states};p.data.edit(b);p.openTopology({kind:"branch",id:"hq"});await p.updateComplete;
|
||||
window.utilityPanel=()=>window.topoView().shadowRoot.querySelector('.nf-utility-right nf-utility-overview');
|
||||
window.utilityBar=()=>window.topoView().shadowRoot.querySelector('nf-utility-overview[inline]');
|
||||
});
|
||||
const overview=async(heading,name,names,power,energy)=>{
|
||||
await page.waitForFunction((heading,name,names,power,energy)=>{
|
||||
const root=window.utilityPanel()?.shadowRoot,bar=window.utilityBar()?.shadowRoot;
|
||||
return root?.querySelector('.heading')?.textContent.includes(heading)&&root?.querySelector('.heading small')?.textContent===name
|
||||
&&JSON.stringify([...root.querySelectorAll('.entry>.entry-name')].map((el)=>el.textContent.trim()))===JSON.stringify(names)
|
||||
&&bar?.textContent.includes(power)&&bar?.textContent.includes(energy);
|
||||
},{},heading,name,names,power,energy);
|
||||
};
|
||||
const utilityClick=async(key)=>{await page.evaluate((key)=>window.utilityPanel().shadowRoot.querySelector(`[data-topology-key="${key}"]>.entry-name`).click(),key);};
|
||||
await overview("Gebäude","Zentrale",["RAS19","RAS21","Außen"],"1 kW","100 kWh");
|
||||
assert.deepEqual(await page.evaluate(()=>[...window.utilityPanel().shadowRoot.querySelector('[data-topology-key="building:ras19"]').querySelectorAll('.value b')].map((el)=>el.textContent)),["350 W","35 kWh"]);
|
||||
assert.ok(await page.evaluate(()=>window.utilityPanel().shadowRoot.querySelector('nf-trend-button')?.ids.length));
|
||||
await page.screenshot({path:join(out,"symcon-utilities-branch.png")});
|
||||
await utilityClick("building:ras19");await overview("Stockwerke","RAS19",["OG","EG","Außen"],"350 W","35 kWh");
|
||||
await page.screenshot({path:join(out,"symcon-utilities-building.png")});
|
||||
await utilityClick("floor:og");
|
||||
await page.waitForFunction(()=>window.topoView().floorId==="og"&&window.utilityBar()?.shadowRoot.textContent.includes("20 kWh"));
|
||||
assert.match(await page.evaluate(()=>window.utilityBar().shadowRoot.textContent),/200 W/);
|
||||
await page.evaluate(()=>window.nfPanel.openTopology({kind:"branch",id:"hq"}));
|
||||
await overview("Gebäude","Zentrale",["RAS19","RAS21","Außen"],"1 kW","100 kWh");
|
||||
await page.evaluate(async()=>{const p=window.nfPanel,states={...p.hass.states};for(const id of ["sensor.9501","sensor.9502"])states[id]={...states[id],state:"0",attributes:{...states[id].attributes,symcon_value:0}};p.hass={...p.hass,states};await p.updateComplete;});
|
||||
await overview("Gebäude","Zentrale",["RAS19","RAS21","Außen"],"900 W","90 kWh");
|
||||
await page.evaluate(async()=>{const p=window.nfPanel,states={...p.hass.states};for(const id of ["sensor.9505","sensor.9506"])states[id]={...states[id],state:"unavailable"};p.hass={...p.hass,states};await p.updateComplete;});
|
||||
await overview("Gebäude","Zentrale",["RAS19","RAS21","Außen"],"Err: 400 W","Err: 40 kWh");
|
||||
assert.match(await page.evaluate(()=>window.utilityPanel().shadowRoot.querySelector('[data-topology-key="building:ras21"]').textContent),/Err: –/);
|
||||
await page.evaluate(()=>window.topoView().shadowRoot.querySelector('.nf-utility-overview-toggle').click());
|
||||
await page.waitForFunction(()=>!window.utilityPanel()&&window.utilityBar().shadowRoot.textContent.includes("Err: 40 kWh"));
|
||||
await page.evaluate(async()=>{
|
||||
window.topoView().shadowRoot.querySelector('.nf-utility-overview-toggle').click();
|
||||
const p=window.nfPanel,states={...p.hass.states};for(const [id,value]of[["sensor.9501",100],["sensor.9502",10],["sensor.9505",500],["sensor.9506",50]])states[id]={...states[id],state:String(value),attributes:{...states[id].attributes,symcon_value:value}};p.hass={...p.hass,states};await p.updateComplete;
|
||||
p.openTopology({kind:"location",id:"urbach"});
|
||||
});
|
||||
await overview("Niederlassungen","Urbach",["Zentrale","Außen"],"2 kW","200 kWh");
|
||||
|
||||
// The HTML-SDK tile uses the same hierarchy and hides its own upper menu until a floor is selected.
|
||||
await page.evaluate(async()=>{const p=window.nfPanel,card=document.createElement("nextfloor-card");card.setConfig({type:"custom:nextfloor-card",fill:true,room_buttons:true,controls:true});card.hass=p.hass;card.style.cssText="display:block;height:850px";document.body.append(card);await card.updateComplete;card.data.edit(structuredClone(window.topologyProject));p.style.display="none";window.topoHost=card;window.topoCard=card;await card.updateComplete;});
|
||||
await page.waitForFunction(()=>window.topoView()?.viewer&&window.topoView().shadowRoot.querySelector('[data-topology-kind="location"]'));
|
||||
@@ -112,6 +159,9 @@ try{
|
||||
await page.waitForFunction(()=>window.topoCard.shadowRoot.querySelectorAll(".nf-card-rooms button").length===2);
|
||||
await page.evaluate(()=>window.topoView().shadowRoot.querySelector('.nf-topology-crumbs [data-topology-key="building:ras19"]').click());
|
||||
await select("outside","ras19","building");await noTopMenu();assert.deepEqual(await scene(),["outside-ras19"]);
|
||||
await page.evaluate(()=>window.topoView().shadowRoot.querySelector('.nf-topology-crumbs [data-topology-key="branch:hq"]').click());
|
||||
await overview("Gebäude","Zentrale",["RAS19","RAS21","Außen"],"1 kW","100 kWh");
|
||||
await utilityClick("building:ras19");await overview("Stockwerke","RAS19",["OG","EG","Außen"],"350 W","35 kWh");
|
||||
await page.evaluate(()=>window.topoView().shadowRoot.querySelector(".nf-thumb-house").click());await noTopMenu();
|
||||
await page.setViewport({width:390,height:844});
|
||||
await page.waitForFunction(()=>window.topoView().shadowRoot.querySelectorAll('[data-topology-kind="location"] img').length===2);
|
||||
|
||||
Reference in new issue
Block a user