feat: add location and branch topology with scoped navigation
This commit is contained in:
1 parent
4a8da8ad0c
commit
bffc4d0acc
30 files changed
+3172
-2491
No files matched your search
+41
-4
@@ -24,6 +24,7 @@ import type { HomeAssistant } from "./types.ts";
|
||||
import { withCoverControls } from "./entities/cover-controls.ts";
|
||||
import { withSymconWeather } from "./symcon-weather.ts";
|
||||
import { isSymcon } from "./entities/symcon-values.ts";
|
||||
import { ALL_TOPOLOGY, floorSelection, topologyOutsideFloors, topologyParent, topologyPath, type TopologySelection } from "./topology.ts";
|
||||
import { allOffPlan, floorSwitchables, type ServiceCall } from "./live/all-off.ts";
|
||||
import type { FloorStack, Quality, WallMode } from "./viewer/viewer3d.ts";
|
||||
|
||||
@@ -38,6 +39,7 @@ export class NextFloorPanel extends LitElement {
|
||||
panel: { attribute: false },
|
||||
_mode: { state: true },
|
||||
_editorReady: { state: true },
|
||||
_topologyGroup: { state: true },
|
||||
_floorId: { state: true },
|
||||
_roomId: { state: true },
|
||||
_wallMode: { state: true },
|
||||
@@ -63,6 +65,7 @@ export class NextFloorPanel extends LitElement {
|
||||
private declare _mode: Mode;
|
||||
/** The editor bundle has been loaded (it is fetched when the editor or the extensions page opens first). */
|
||||
private declare _editorReady: boolean;
|
||||
private declare _topologyGroup: TopologySelection;
|
||||
private declare _floorId: string | null;
|
||||
private declare _roomId: string | null;
|
||||
private declare _wallMode: WallMode;
|
||||
@@ -98,6 +101,7 @@ export class NextFloorPanel extends LitElement {
|
||||
this._mode = "view";
|
||||
this._editorReady = !!customElements.get("nf-editor");
|
||||
this._floorId = null;
|
||||
this._topologyGroup=ALL_TOPOLOGY;
|
||||
this._roomId = null;
|
||||
this._wallMode = "auto";
|
||||
this._prefs = this.store.load(location.search);
|
||||
@@ -165,6 +169,7 @@ export class NextFloorPanel extends LitElement {
|
||||
const building = this.data.building;
|
||||
if (building && this._floorId && !building.floors.some((f) => f.id === this._floorId)) {
|
||||
this._floorId = null;
|
||||
this._topologyGroup=ALL_TOPOLOGY;
|
||||
this._roomId = null;
|
||||
}
|
||||
}
|
||||
@@ -180,7 +185,19 @@ export class NextFloorPanel extends LitElement {
|
||||
this._mode = mode;
|
||||
}
|
||||
|
||||
private topologySelection(building: Building): TopologySelection {
|
||||
return this._floorId ? floorSelection(building,this._floorId,this._roomId) : this._topologyGroup;
|
||||
}
|
||||
|
||||
private openTopology(selection: TopologySelection): void {
|
||||
const b=this.data.building;if(!b)return;
|
||||
this._roomId=selection.kind==="room"?selection.id??null:null;
|
||||
this._floorId=selection.kind==="room"?selection.floorId??null:selection.kind==="floor"?selection.id??null:selection.kind==="outside"?b.floors.find((f)=>f.outdoor_location_id===selection.id)?.id??null:null;
|
||||
this._topologyGroup=selection;this._outside=false;
|
||||
}
|
||||
|
||||
private openFloor(floorId: string | null): void {
|
||||
this._topologyGroup=ALL_TOPOLOGY;
|
||||
this._floorId = floorId;
|
||||
this._roomId = null;
|
||||
this._outside = false;
|
||||
@@ -188,6 +205,7 @@ export class NextFloorPanel extends LitElement {
|
||||
|
||||
/** The devices of Outside, worked out again only when the plan or the registry changes. */
|
||||
private outsideIds(building: Building): string[] {
|
||||
if(building.topology)return outsideEntities(this.hass,topologyOutsideFloors(building,this.topologySelection(building)),building.settings.outside_hidden);
|
||||
const m = this.outsideMemo;
|
||||
if (m && m.building === building && m.entities === this.hass.entities) return m.ids;
|
||||
const ids = outsideEntities(this.hass, building.floors, building.settings.outside_hidden);
|
||||
@@ -196,7 +214,15 @@ export class NextFloorPanel extends LitElement {
|
||||
}
|
||||
|
||||
/** Opens Outside over the house view (or closes it again). */
|
||||
private openOutside(): void {
|
||||
private openOutside(floorId?: string): void {
|
||||
const b=this.data.building;
|
||||
if(b?.topology){
|
||||
const location=topologyPath(b,floorId?floorSelection(b,floorId):this.topologySelection(b)).find((n)=>n.selection.kind==="location");
|
||||
if(!location)return;
|
||||
const f=b.floors.find((f)=>f.outdoor_location_id===location?.selection.id);
|
||||
if(f){const open=!this._outside;this.openTopology({kind:"outside",id:f.outdoor_location_id!});this._outside=open;return;}
|
||||
const open=!this._outside;this.openTopology(location.selection);this._outside=open;return;
|
||||
}
|
||||
const open = !this._outside;
|
||||
this.openFloor(null);
|
||||
this._outside = open;
|
||||
@@ -205,7 +231,7 @@ export class NextFloorPanel extends LitElement {
|
||||
private onRoomTap(e: CustomEvent<{ floorId: string; roomId: string | null }>): void {
|
||||
const { floorId, roomId } = e.detail;
|
||||
// an outdoor area's pin opens Outside
|
||||
if (roomId === "nf-outside") return this.openOutside();
|
||||
if (roomId === "nf-outside") return this.openOutside(floorId);
|
||||
// in the house view, or on another floor, a tap opens the whole floor first and the rooms come next
|
||||
if ((this.data.building?.floors.length ?? 0) > 1 && floorId && this._floorId !== floorId) return this.openFloor(floorId);
|
||||
if (roomId) {
|
||||
@@ -257,6 +283,7 @@ export class NextFloorPanel extends LitElement {
|
||||
private back(): void {
|
||||
if (this._outside) this._outside = false;
|
||||
else if (this._roomId) this._roomId = null;
|
||||
else if(this.data.building?.topology && this.topologySelection(this.data.building).kind!=="all")this.openTopology(topologyParent(this.data.building,this.topologySelection(this.data.building)));
|
||||
else if (this._floorId && (this.data.building?.floors.length ?? 0) > 1) this._floorId = null;
|
||||
else this.view3d()?.resetView();
|
||||
}
|
||||
@@ -487,6 +514,14 @@ export class NextFloorPanel extends LitElement {
|
||||
|
||||
/** The bar of floors and rooms above the stage. */
|
||||
private renderNav(building: Building) {
|
||||
if(building.topology){
|
||||
const floor=building.floors.find((f)=>f.id===this._floorId);
|
||||
if(!floor||floor.outdoor_location_id)return nothing;
|
||||
return html`<nav class="nf-nav nf-topology-floor-nav" aria-label=${floor.name}>
|
||||
${floor.rooms.map((room)=>html`<button class="nf-chip nf-room-chip" aria-pressed=${room.id===this._roomId} @click=${()=>{this._roomId=this._roomId===room.id?null:room.id;this._outside=false;}}>${room.name}</button>`)}
|
||||
${this.allOffChip(building)}
|
||||
</nav>`;
|
||||
}
|
||||
const shown: Floor[] = building.floors.filter((f) => !this._floorId || f.id === this._floorId);
|
||||
const several = building.floors.length > 1;
|
||||
const wrap = this._prefs.navWrap;
|
||||
@@ -573,7 +608,7 @@ export class NextFloorPanel extends LitElement {
|
||||
}
|
||||
|
||||
private renderView(building: Building) {
|
||||
if (!building.floors.some((f) => f.rooms.length)) {
|
||||
if (!building.floors.some((f) => f.rooms.length || f.outdoor.length || f.furniture.length)) {
|
||||
return html`<div class="nf-empty">
|
||||
<p>${this.t(this.isAdmin ? (building.floors.length ? "no_rooms_admin" : "no_building_admin") : "no_building")}</p>
|
||||
${this.isAdmin ? html`<button class="nf-btn nf-primary" @click=${() => this.setMode("editor")}>${this.t("open_editor")}</button>` : nothing}
|
||||
@@ -590,6 +625,7 @@ export class NextFloorPanel extends LitElement {
|
||||
class="nf-body"
|
||||
.hass=${withSymconWeather(withCoverControls(this.hass, building.floors), building.settings)}
|
||||
.building=${building}
|
||||
.topologySelection=${this.topologySelection(building)}
|
||||
.packs=${this.data.packs}
|
||||
.floorStack=${p.floorStack}
|
||||
.roomLabels=${p.roomNames}
|
||||
@@ -598,7 +634,7 @@ export class NextFloorPanel extends LitElement {
|
||||
@clean-toggle=${() => this.setPref("clean", !p.clean)}
|
||||
?weather=${p.weather}
|
||||
.panelOpen=${!!this._roomId || this._outside}
|
||||
.floorId=${building.floors.length > 1 ? this._floorId : (building.floors[0]?.id ?? null)}
|
||||
.floorId=${building.topology || building.floors.length > 1 ? this._floorId : (building.floors[0]?.id ?? null)}
|
||||
.roomId=${this._roomId}
|
||||
.outsideOpen=${this._outside}
|
||||
.wallMode=${this._wallMode}
|
||||
@@ -632,6 +668,7 @@ export class NextFloorPanel extends LitElement {
|
||||
.quality=${p.quality}
|
||||
?showStats=${p.stats}
|
||||
@room-tap=${this.onRoomTap}
|
||||
@topology-tap=${(e: CustomEvent<TopologySelection>) => this.openTopology(e.detail)}
|
||||
@floor-tap=${(e: CustomEvent<{ floorId: string | null }>) => this.openFloor(e.detail.floorId)}
|
||||
@back=${() => this.back()}
|
||||
></nf-view3d>
|
||||
|
||||
Reference in new issue
Block a user