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
+25
-4
@@ -21,6 +21,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, type TopologySelection } from "./topology.ts";
|
||||
import type { WallMode } from "./viewer/viewer3d.ts";
|
||||
import { lookNow } from "./themes.ts";
|
||||
|
||||
@@ -44,6 +45,7 @@ export class NextFloorCard extends LitElement {
|
||||
hass: { attribute: false },
|
||||
_config: { state: true },
|
||||
_roomId: { state: true },
|
||||
_topologyGroup: { state: true },
|
||||
_floorId: { state: true },
|
||||
_walls: { state: true },
|
||||
_heat: { state: true },
|
||||
@@ -64,6 +66,7 @@ export class NextFloorCard extends LitElement {
|
||||
/** The configured start room has been opened once the building arrived. */
|
||||
private roomApplied = false;
|
||||
/** The floor chosen in the card: null is the house, undefined means none was chosen so the configured floor applies. */
|
||||
private declare _topologyGroup: TopologySelection;
|
||||
private declare _floorId: string | null | undefined;
|
||||
/** Choices made with the card's own switches; null means as configured. */
|
||||
private declare _walls: WallMode | null;
|
||||
@@ -93,6 +96,7 @@ export class NextFloorCard extends LitElement {
|
||||
super();
|
||||
this._roomId = null;
|
||||
this._floorId = undefined;
|
||||
this._topologyGroup=ALL_TOPOLOGY;
|
||||
this._walls = null;
|
||||
this._heat = null;
|
||||
this._explode = null;
|
||||
@@ -111,6 +115,7 @@ export class NextFloorCard extends LitElement {
|
||||
private returnHome(): void {
|
||||
this._roomId = this._config?.room ?? null;
|
||||
this._floorId = undefined;
|
||||
this._topologyGroup=ALL_TOPOLOGY;
|
||||
this.view3d()?.resetView();
|
||||
if (this._config?.idle_orbit) this._orbit = true;
|
||||
}
|
||||
@@ -156,6 +161,7 @@ export class NextFloorCard extends LitElement {
|
||||
this._own = config;
|
||||
this._config = withTemplate(config, this.data.building?.settings.card_templates as CardTemplates | undefined);
|
||||
this._floorId = undefined;
|
||||
this._topologyGroup=ALL_TOPOLOGY;
|
||||
this._walls = null;
|
||||
this._heat = null;
|
||||
this._explode = null;
|
||||
@@ -199,8 +205,20 @@ export class NextFloorCard extends LitElement {
|
||||
}
|
||||
|
||||
/** One level up: room, then floor, then the house. */
|
||||
private topologySelection(): TopologySelection {
|
||||
const b=this.plan(),id=this.stage().floorId;
|
||||
return b&&id?floorSelection(b,id,this._roomId===OUTSIDE?null:this._roomId):this._topologyGroup;
|
||||
}
|
||||
|
||||
private openTopology(s:TopologySelection):void {
|
||||
const b=this.plan();if(!b)return;
|
||||
this._floorId=s.kind==="room"?s.floorId??null:s.kind==="floor"?s.id??null:s.kind==="outside"?b.floors.find((f)=>f.outdoor_location_id===s.id)?.id??null:null;
|
||||
this._roomId=s.kind==="room"?s.id??null:null;this._topologyGroup=s;
|
||||
}
|
||||
|
||||
private back(): void {
|
||||
if (this._roomId) this._roomId = null;
|
||||
else if(this.plan()?.topology)this.openTopology(topologyParent(this.plan()!,this.topologySelection()));
|
||||
else if (this.canSwitch) this._floorId = null;
|
||||
}
|
||||
|
||||
@@ -224,7 +242,7 @@ export class NextFloorCard extends LitElement {
|
||||
const c = this._config;
|
||||
// the configured floor is where the card starts; with floor pictures the user can switch
|
||||
const chosen = this._floorId === undefined ? (c?.floor ?? null) : this._floorId;
|
||||
const floorId = b && b.floors.length === 1 ? b.floors[0].id : b?.floors.some((f) => f.id === chosen) ? chosen : null;
|
||||
const floorId = b && !b.topology && b.floors.length === 1 ? b.floors[0].id : b?.floors.some((f) => f.id === chosen) ? chosen : null;
|
||||
// the floor pictures have a house button of their own; a room with its panel has a close button
|
||||
const panelOpen = !!this._roomId && c?.room_panel !== false;
|
||||
const canGoBack = (!!this._roomId && c?.room_panel === false) || (!this.thumbs && this.canSwitch && !this._roomId && !!floorId && (b?.floors.length ?? 0) > 1);
|
||||
@@ -270,6 +288,7 @@ export class NextFloorCard extends LitElement {
|
||||
private renderRoomButtons(s: Stage): TemplateResult | typeof nothing {
|
||||
const b = this.plan();
|
||||
if (!this._config?.room_buttons || !b || this._clean) return nothing;
|
||||
if(b.topology&&(!s.floorId||b.floors.find((f)=>f.id===s.floorId)?.outdoor_location_id))return nothing;
|
||||
const groups = roomButtons(b, s.floorId);
|
||||
if (!groups.length) return nothing;
|
||||
const several = groups.length > 1;
|
||||
@@ -278,7 +297,7 @@ export class NextFloorCard extends LitElement {
|
||||
this._roomId = roomId === this._roomId ? null : roomId;
|
||||
};
|
||||
// Outside: the house view with the garden's and the roof's devices in the panel
|
||||
const outside = outsideEntities(this.hass, b.floors).length > 0;
|
||||
const outside = !b.topology&&outsideEntities(this.hass, b.floors).length > 0;
|
||||
const openOutside = () => {
|
||||
if (this.canSwitch) this._floorId = null;
|
||||
this._roomId = this._roomId === OUTSIDE ? null : OUTSIDE;
|
||||
@@ -322,6 +341,7 @@ export class NextFloorCard extends LitElement {
|
||||
return html`<nf-view3d
|
||||
.hass=${withSymconWeather(withCoverControls(this.hass, b.floors), b.settings)}
|
||||
.building=${b}
|
||||
.topologySelection=${this.topologySelection()}
|
||||
.packs=${this.data.packs}
|
||||
.floorId=${s.floorId}
|
||||
.roomId=${this._roomId === OUTSIDE ? null : this._roomId}
|
||||
@@ -388,9 +408,10 @@ export class NextFloorCard extends LitElement {
|
||||
this._roomId = null;
|
||||
} else if (e.detail.roomId) this._roomId = e.detail.roomId === this._roomId ? null : e.detail.roomId;
|
||||
}}
|
||||
@topology-tap=${(e: CustomEvent<TopologySelection>)=>{if(this.canSwitch)this.openTopology(e.detail);}}
|
||||
@floor-tap=${(e: CustomEvent<{ floorId: string | null }>) => {
|
||||
this._floorId = e.detail.floorId;
|
||||
this._roomId = null;
|
||||
this._roomId = null;this._topologyGroup=ALL_TOPOLOGY;
|
||||
}}
|
||||
@back=${() => this.back()}
|
||||
></nf-view3d>`;
|
||||
@@ -404,7 +425,7 @@ export class NextFloorCard extends LitElement {
|
||||
.hass=${withCoverControls(this.hass, b.floors)}
|
||||
.room=${b.floors.flatMap((f) => f.rooms).find((r) => r.id === this._roomId) ?? null}
|
||||
.floor=${b.floors.find((f) => f.rooms.some((r) => r.id === this._roomId)) ?? null}
|
||||
.outside=${this._roomId === OUTSIDE ? outsideEntities(this.hass, b.floors) : null}
|
||||
.outside=${this._roomId === OUTSIDE ? outsideEntities(this.hass, topologyOutsideFloors(b,this.topologySelection())) : null}
|
||||
.confirmEntities=${confirmEntities(this.hass, b.floors)}
|
||||
.phrases=${b.settings.announce_phrases ?? null}
|
||||
@close=${() => (this._roomId = null)}
|
||||
|
||||
Reference in new issue
Block a user