feat: add location and branch topology with scoped navigation

This commit is contained in:
jhartworks committed 2026-11-17 14:46:48 +01:00
1 parent 4a8da8ad0c
commit bffc4d0acc
30 files changed
+3172 -2491

No files matched your search

+39 -14
View File
@@ -1,3 +1,5 @@
import { ALL_TOPOLOGY, floorSelection, topologyFloors, topologyItems, type TopologySelection } from "../topology.ts";
import { topologyNavigation } from "./view3d/topology-navigation.ts";
// Lit wrapper around the lazily loaded 3D viewer.
import { changeMoments, hassAt, loadHistory, replayable, type History } from "../live/time-travel.ts";
@@ -157,6 +159,7 @@ export class NfView3d extends LitElement {
buttons: { attribute: false },
_thumbs: { state: true },
floorThumbs: { attribute: false },
topologySelection: { attribute: false },
clean: { attribute: false },
cleanButton: { attribute: false },
clock: { attribute: false },
@@ -289,6 +292,9 @@ export class NfView3d extends LitElement {
private declare _blend: number;
/** Floor switcher with small pictures of the floors (panel and card; off with a fixed floor). */
declare floorThumbs: boolean;
declare topologySelection: TopologySelection | null;
private topologyImages = new Map<string,string>();
private scopedFor: {source:Building;key:string;plan:Building}|null=null;
/** Clean view: only the stage – no energy values, thumbnails, legend, scene chips or search (the host hides its own bars). */
declare clean: boolean;
/** Show the eye button that toggles the clean view (the host listens for "clean-toggle"). */
@@ -493,6 +499,7 @@ export class NfView3d extends LitElement {
this.buttons = null;
this._thumbs = [];
this.floorThumbs = true;
this.topologySelection=null;
this.clean = false;
this.cleanButton = false;
this.clock = null;
@@ -698,13 +705,13 @@ export class NfView3d extends LitElement {
// a feature pack may have arrived with them (Energiefluss): the cables and modules follow
this.syncDevices(true);
}
if (changed.has("building") && this.building) {
if (["building","topologySelection","floorId"].some((k)=>changed.has(k)) && this.building) {
// a new start view (just remembered in the editor) shows right away in the house view
const start = JSON.stringify(this.startViewOf());
const startChanged = this.shownStartView !== undefined && this.shownStartView !== start;
this.shownStartView = start;
v.setStartView(this.startViewOf());
v.setBuilding(this.shownBuilding(this.hass));
v.setStartView(this.building.topology&&this.topologyFocus.kind!=="all"?null:this.startViewOf());
const previous=this.shownFor?.shown,shown=this.shownBuilding(this.hass);if(shown!==previous)v.setBuilding(shown);
v.setMap(this.building?.settings.map, this.building?.settings.north ?? 0);
if (startChanged && this.floorId === null) v.resetView();
}
@@ -712,14 +719,14 @@ export class NfView3d extends LitElement {
v.setStartView(this.startViewOf());
if (this.floorId === null) v.resetView();
}
if (changed.has("building") || changed.has("theme") || changed.has("floorThumbs") || changed.has("packs")) this.scheduleThumbs();
if (changed.has("building") || changed.has("theme") || changed.has("floorThumbs") || changed.has("packs") || changed.has("topologySelection") || changed.has("floorId") || changed.has("roomId")) this.scheduleThumbs();
// markers shown by kind outside the opened room change with the room
const byRoom = this.markersOutside ? ["markersOutside", "floorId", "roomId"] : ["markersOutside"];
const forced = this.pluginsDirty || ["building", "markerMode", "heatMode", "flows", "alerts", "dimmed", "holograms", "roomLabels", "floorId", "roomId", ...byRoom].some((k) => changed.has(k));
const forced = this.pluginsDirty || ["building", "topologySelection", "markerMode", "heatMode", "flows", "alerts", "dimmed", "holograms", "roomLabels", "floorId", "roomId", ...byRoom].some((k) => changed.has(k));
this.pluginsDirty = false;
if (forced || changed.has("hass")) this.syncDevices(forced);
if (changed.has("autoOrbit")) v.setAutoOrbit(this.autoOrbit ? 0.06 : 0);
if (changed.has("_thumbs") || changed.has("_narrowStage") || changed.has("_phoneStage")) v.setLabelInset(this._thumbs.length && !this._phoneStage ? (this.narrowThumbs ? 136 : 184) : 0);
if (changed.has("_thumbs") || changed.has("_narrowStage") || changed.has("_phoneStage") || changed.has("building")) v.setLabelInset(this.building?.topology||(this._thumbs.length&&!this._phoneStage) ? (this.narrowThumbs ? 136 : 184) : 0);
if (changed.has("floorId")) v.setFloor(this.floorId);
if (changed.has("roomId") && (this.roomId || changed.get("roomId"))) v.selectRoom(this.roomId);
if (changed.has("outsideOpen") && changed.get("outsideOpen") !== undefined) {
@@ -796,8 +803,19 @@ export class NfView3d extends LitElement {
}
/** The building as the 3D view draws it: without the pieces whose visibility condition is not met. */
private get topologyFocus(): TopologySelection {
return this.building&&this.floorId?floorSelection(this.building,this.floorId,this.roomId):this.topologySelection??ALL_TOPOLOGY;
}
private scopeBuilding(): Building {
const b=this.building!;if(!b.topology)return b;
const floors=topologyFloors(b,this.topologyFocus,true),key=floors.map((f)=>f.id).join("|");
if(this.scopedFor?.source!==b||this.scopedFor.key!==key)this.scopedFor={source:b,key,plan:{...b,floors}};
return this.scopedFor.plan;
}
private shownBuilding(hass: HomeAssistant | undefined): Building {
const b = this.building!;
const b = this.scopeBuilding();
const hidden = hiddenFurniture(hass, b);
const layers = b.floors.filter((f) => f.layer && this.hiddenLayers.has(f.id)).map((f) => f.id);
const key = [...hidden, ...layers.map((id) => `layer:${id}`)].join(",");
@@ -839,7 +857,7 @@ export class NfView3d extends LitElement {
private syncDevices(force: boolean): void {
const v = this.viewer;
const b = this.building;
const b = this.building?this.scopeBuilding():null;
if (!v || !b || !this.hass) return;
// time travel: the same view, fed with the states of the moment shown
const travel = this._travel;
@@ -864,7 +882,7 @@ export class NfView3d extends LitElement {
const changed = force || this.watched.some((id) => this.shownStates.get(id) !== hass.states[id]);
if (!changed) return;
// a piece shown only while a helper is on (seasonal decoration) comes and goes with it
if (hiddenFurniture(hass, b).join(",") !== this.shownFor?.key) v.setBuilding(this.shownBuilding(hass));
const previous=this.shownFor?.shown,shown=this.shownBuilding(hass);if(shown!==previous)v.setBuilding(shown);
this.shownStates = new Map(this.watched.map((id) => [id, hass.states[id]]));
this.syncHydronics(v, b, hass);
this.refreshToday(b);
@@ -1738,12 +1756,12 @@ export class NfView3d extends LitElement {
private scheduleThumbs(delay = 600): void {
clearTimeout(this.thumbTimer);
const floors = this.building?.floors.filter((f) => f.rooms.length).length ?? 0;
if (!this.floorThumbs || floors < 2) {
if (!this.floorThumbs || (!this.building?.topology && floors < 2)) {
this._thumbs = [];
return;
}
// at most every few seconds, however often lamps change (the tablet level waits longer)
const wait = Math.max(delay, this.thumbsAt + (this._low ? 8000 : 4000) - Date.now());
const wait = this.building?.topology ? delay : Math.max(delay, this.thumbsAt + (this._low ? 8000 : 4000) - Date.now());
this.thumbTimer = setTimeout(() => {
// at night (kiosk) the pictures are drawn once and then rest
if (!this.viewer || (this.dimmed && this._thumbs.length)) return;
@@ -1753,7 +1771,11 @@ export class NfView3d extends LitElement {
return;
}
this.thumbsAt = Date.now();
this._thumbs = this.viewer.floorThumbnails(this.narrowThumbs ? 104 : 150, this.narrowThumbs ? 78 : 112);
if(this.building?.topology){
const nodes=topologyItems(this.building,this.topologyFocus);
for(const t of this.viewer.scopeThumbnails(nodes,this.narrowThumbs?104:150,this.narrowThumbs?78:112))this.topologyImages.set(t.key,t.url);
this.requestUpdate();
}else this._thumbs = this.viewer.floorThumbnails(this.narrowThumbs ? 104 : 150, this.narrowThumbs ? 78 : 112);
}, wait);
}
@@ -1762,6 +1784,9 @@ export class NfView3d extends LitElement {
}
private renderThumbs() {
if(this.floorThumbs&&this.building?.topology){
return topologyNavigation(this.building,this.topologyFocus,this.topologyImages,(s)=>this.fire("topology-tap",s),this._thumbsCompact,()=>{this._thumbsCompact=!this._thumbsCompact;try{localStorage.setItem("nextfloor.thumbs_compact",this._thumbsCompact?"1":"0");}catch{}},this.narrowThumbs,this._shortStage);
}
if (!this._thumbs.length || !this.building || this._phoneStage) return nothing;
const names = new Map(this.building.floors.map((f) => [f.id, f.name]));
// the highest floor on top
@@ -2805,7 +2830,7 @@ export class NfView3d extends LitElement {
/** Native utility readings for the current building/floor scope. */
private utilityOverview(inline: boolean) {
const b = this.building;
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;
@@ -2826,7 +2851,7 @@ export class NfView3d extends LitElement {
if (isSymcon(this.hass) && this.building?.settings.rain_sensor && this.building.settings.rain_sensor !== "none") weather.push(["Regensensor", this.building.settings.rain_sensor]);
const weatherValues = weather.length ? html`<button class="nf-energy-item nf-flow-toggle nf-weather-values" aria-label="Wetterwerte anzeigen" title="Wetterwerte anzeigen" aria-haspopup="dialog" @click=${() => this.renderRoot.querySelector<HTMLDialogElement>(".nf-weather-dialog")?.showModal()}><span>Wetter</span><b aria-hidden="true">⛅</b></button>
<dialog class="nf-weather-dialog" aria-label="Wetterwerte" @keydown=${(event: KeyboardEvent) => event.stopPropagation()}><header><b>Wetter</b><button type="button" class="nf-chip" aria-label="Schließen" @click=${() => this.renderRoot.querySelector<HTMLDialogElement>(".nf-weather-dialog")?.close()}>×</button></header>${weather.map(([label, id]) => html`<p><span>${label}</span><b>${nativeText(this.hass.states[id])}${trendButton(this.hass, [id], label)}</b></p>`)}</dialog>` : nothing;
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 floors = isSymcon(this.hass) ? (this.building?this.scopeBuilding().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 [overviewToggle, summary, ...people, weatherValues, utilities, ...ids