@@ -1662,7 +1662,7 @@ ${t.sources.map(r=>this.hass.states[r]?.attributes.symcon_path||this.hass.states
@media(max-width:600px) { .entries { max-height:32vh; } }
`};customElements.get("nf-utility-overview")||customElements.define("nf-utility-overview",ss);var Uu="image:";function as(n,e,t){let r=(e??"").trim();if(!r)return null;if(r.startsWith(Uu))return t(r.slice(Uu.length));if(/^(https?:\/\/|\/)/.test(r))return r;if(/^[a-z_]+\.[a-z0-9_]+$/.test(r)){let i=n?.states[r]?.attributes.entity_picture;return typeof i=="string"&&i?i:null}return null}var Kn=n=>Number(n);function Un(n){if(Array.isArray(n)){let[o,s]=[Kn(n[0]),Kn(n[1])];return Number.isFinite(o)&&Number.isFinite(s)?[o,s]:null}if(!n||typeof n!="object")return null;let{x:e,y:t}=n,[r,i]=[Kn(e),Kn(t)];return Number.isFinite(r)&&Number.isFinite(i)?[r,i]:null}function ju(n){return n?Un(n.charger)??Un(n.charger_position):null}function qu(n){for(let[e,t]of Object.entries(n.states))if(e.startsWith("camera.")&&(Un(t.attributes?.vacuum_position)??ju(t.attributes)))return e;return null}var ig=n=>Array.isArray(n)?typeof n[0]=="number":!!n&&typeof n=="object",Gn=(n,e)=>e?[n[0],-n[1]]:n;function og(n){if(!n)return null;let e=n.mirror===!0,[t,r]=Gn(n.ga,e),[i,o]=Gn(n.gb,e),[s,a]=n.a,[l,c]=n.b,[u,h]=[i-t,o-r],[m,d]=[l-s,c-a],g=Math.hypot(u,h),_=Math.hypot(m,d);if(!(g>1e-6)||!(_>1e-6))return null;let b=_/g,y=Math.atan2(d,m)-Math.atan2(h,u),[$,S]=[Math.cos(y),Math.sin(y)];return A=>{let z=Gn(A,e),[x,D]=[z[0]-t,z[1]-r];return[s+b*(x*$-D*S),a+b*(x*S+D*$)]}}function sg(n){if(!n)return null;let e=n.mirror===!0,[t,r]=Gn(n.ga,e),[i,o]=Gn(n.gb,e),s=Math.atan2(n.b[1]-n.a[1],n.b[0]-n.a[0])-Math.atan2(o-r,i-t);return Number.isFinite(s)?s:null}function Zu(n,e,t){if(!e)return null;let r=n.states[e]?.attributes;if(!r)return null;let i=og(t)??(g=>g),o=sg(t)??0,s=t?.mirror===!0?-1:1,a=r.vacuum_position,l=Un(a),c=l?(()=>{let[g,_]=i(l),b=Kn(a?.a)*s;if(!Number.isFinite(b))return{x:g,z:_,heading:0};let y=b*Math.PI/180+o;return{x:g,z:_,heading:Math.atan2(Math.cos(y),Math.sin(y))}})():null,u=ju(r),h=Array.isArray(r.path)?r.path:[],m=h.length>0&&ig(h[0])?[h]:h,d=[];for(let g of m){let _=[];for(let b of Array.isArray(g)?g:[]){let y=Un(b);y&&_.push(i(y))}_.length>1&&d.push(_)}return!c&&!u&&!d.length?null:{pose:c,charger:u?i(u):null,path:d}}var Yu="nextfloor.lock3d",Ju=520,cs=class extends X{static properties={hass:{attribute:!1},building:{attribute:!1},floorId:{attribute:!1},roomId:{attribute:!1},wallMode:{attribute:!1},solidWalls:{attribute:!1},glassWalls:{attribute:!1},explode:{type:Boolean},keepRoof:{attribute:!1},markerMode:{attribute:!1},markerNames:{attribute:!1},markersOutside:{attribute:!1},tapInRoom:{type:Boolean},roomDoubleTap:{attribute:!1},heatMode:{attribute:!1},theme:{attribute:!1},accent:{attribute:!1},furnitureColors:{attribute:!1},packs:{attribute:!1},showEnergy:{attribute:!1},flows:{attribute:!1},holograms:{attribute:!1},furnish:{type:Boolean},surfaceGrab:{attribute:!1},furnishTypes:{attribute:!1},weather:{type:Boolean},weatherEntityId:{attribute:!1},weatherDensity:{attribute:!1},timeOfDay:{attribute:!1},selectedFurniture:{attribute:!1},selectedDevice:{attribute:!1},_sky:{state:!0},quality:{attribute:!1},showStats:{type:Boolean},_stats:{state:!0},_error:{state:!0},_energy:{state:!0},_flows:{state:!0},_liveEnergy:{state:!0},_liveCards:{state:!0},_liveCardOn:{state:!0},_houseFolded:{state:!0},_utilityOverviewVisible:{state:!0},_swipe:{state:!0},_menu:{state:!0},_pluginWindow:{state:!0},_plate:{state:!0},_blend:{state:!0},_wallBig:{state:!0},_find:{state:!0},_central:{state:!0},_thumbsCompact:{state:!0},_armed:{state:!0},central:{attribute:!1},centralOpen:{attribute:!1},keepCamera:{attribute:!1},plain:{attribute:!1},rightBack:{attribute:!1},templateName:{attribute:!1},readable:{type:Boolean,reflect:!0},today:{attribute:!1},_todayOpen:{state:!0},_todayItems:{state:!0},_forecast:{state:!0},zoom:{attribute:!1},buttons:{attribute:!1},_thumbs:{state:!0},floorThumbs:{attribute:!1},clean:{attribute:!1},cleanButton:{attribute:!1},clock:{attribute:!1},lockButton:{attribute:!1},walkButton:{attribute:!1},travelButton:{attribute:!1},_travel:{state:!0},_walking:{state:!0},_stick:{state:!0},_locked:{state:!0},_now:{state:!0},roomLabels:{attribute:!1},roomNamesButton:{attribute:!1},floorStack:{attribute:!1},panelOpen:{attribute:!1},alerts:{attribute:!1},alertJump:{attribute:!1},scenes:{attribute:!1},announcements:{attribute:!1},sensorBar:{attribute:!1},screenName:{attribute:!1},_announcement:{state:!0},dimmed:{attribute:!1},autoOrbit:{attribute:!1},startView:{attribute:!1},outsideOpen:{attribute:!1},_low:{state:!0},_narrowStage:{state:!0},_shortStage:{state:!0},_phoneStage:{state:!0},_alerts:{state:!0},_sceneFired:{state:!0}};stopAnnouncements=null;announceTimer;get liveCardsOn(){return this.holograms??this._liveCardOn}cloud=0;confirmSet=new Set;shownStartView;placementInfo=new Map;live=null;travelTimer;dayCurves=null;curvesAt=0;clockTimer;stopPlugins=null;pluginsDirty=!1;resizeObs=null;alertSrc=null;alertTimer;contactTimer;seenAlerts=new Set;roomFlash=null;findIndex=null;tintSig="";thumbTimer;thumbSig="";thumbsAt=0;armTimer;forecastAt=0;forecastKey="";todayAt=0;todayDay="";swipeSent=0;swipeTimer;viewer=null;hydronicModule=null;hydronicGeneration=0;starting=!1;shownStates=new Map;shownPacks=-1;openingLinks=null;linkedRegistry;furnitureLinks=new Map;tapPins=new Map;heatValues=new Map;watched=[];constructor(){super(),this.building=null,this.floorId=null,this.roomId=null,this.wallMode="auto",this.solidWalls=!1,this.glassWalls=null,this.explode=!0,this.keepRoof=!1,this.markerMode="important",this.markersOutside=null,this.tapInRoom=!1,this.roomDoubleTap="auto",this.heatMode="none",this.theme="neon",this.accent=null,this.furnitureColors=null,this.furnish=!1,this.weather=!0,this.weatherEntityId=null,this.weatherDensity=1,this.showEnergy=!0,this.flows=null,this._liveEnergy=null,this._liveCards=[],this._liveCardOn=localStorage.getItem("nextfloor.cards")!=="0",this._houseFolded=localStorage.getItem("nextfloor.house_card_folded")==="1";try{this._utilityOverviewVisible=localStorage.getItem("nextfloor.utility_overview")!=="0"}catch{this._utilityOverviewVisible=!0}this.selectedFurniture=null,this.selectedDevice=null,this._sky=0,this.quality="auto",this.showStats=!1,this._stats=null,this._error=null,this._energy=null,this._swipe=null,this._menu=null,this._pluginWindow=null,this._plate=null,this._wallBig=null,this._blend=.6,this._find=null,this._central=!1;try{this._thumbsCompact=localStorage.getItem("nextfloor.thumbs_compact")==="1"}catch{this._thumbsCompact=!1}this._armed=null,this.central=!0,this.buttons=null,this._thumbs=[],this.floorThumbs=!0,this.clean=!1,this.cleanButton=!1,this.clock=null,this.lockButton=!1,this.walkButton=!1,this.travelButton=!1,this._travel=null,this._walking=!1,this._stick=null,this._now=Date.now(),this._locked=(()=>{try{return localStorage.getItem(Yu)==="1"}catch{return!1}})(),this.roomLabels=!0,this.roomNamesButton=!1,this.floorStack="dim",this._low=!1,this.panelOpen=!1,this._narrowStage=!1,this._shortStage=!1,this._phoneStage=!1,this.alerts=!0,this.alertJump=!1,this.announcements=!1,this.sensorBar=!0,this.screenName=null,this._announcement=null,this._alerts=[],this.scenes=!0,this._sceneFired=null,this.dimmed=!1,this.autoOrbit=!1,this.startView=null,this.outsideOpen=!1,this.holograms=null;try{this._flows=localStorage.getItem("nextfloor.flows")==="1"}catch{this._flows=!1}}connectedCallback(){super.connectedCallback(),this.stopPlugins=Ft(()=>{this.pluginsDirty=!0,this.requestUpdate()}),this.hasUpdated&&(this.observeStage(),this.viewer||this.start())}disconnectedCallback(){super.disconnectedCallback(),this.hydronicGeneration++,this.hydronicModule?.closeHydronic(),this.stopPlugins?.(),this.stopPlugins=null,this.listenToAnnouncements(!1),this.resizeObs?.disconnect(),this.resizeObs=null,clearInterval(this.alertTimer),this.alertTimer=void 0,clearInterval(this.contactTimer),this.contactTimer=void 0,clearInterval(this.clockTimer),this.clockTimer=void 0,clearInterval(this.travelTimer),this.travelTimer=void 0,this.live=null,this.viewer?.dispose(),this.viewer=null}firstUpdated(){this.observeStage(),this.start()}observeStage(){let e=this.renderRoot.querySelector(".nf-stage");!e||this.resizeObs||typeof ResizeObserver!="function"||(this.resizeObs=new ResizeObserver(t=>{let r=t[0]?.contentRect,i=(r?.width??1e3)<700||(r?.height??1e3)
{this._central&&!this.centralOpen&&!r.target?.closest?.(".nf-central, .nf-central-btn")&&(this._central=!1)}),this.viewer=e.createViewer(t,{quality:this.quality,explode:this.explode,onRoomTap:(r,i)=>this.fire("room-tap",{floorId:r,roomId:i}),onFloorTap:r=>this.fire("floor-tap",{floorId:r}),floorInfo:r=>r.rooms.length===1?M(this.hass,"floor_rooms_one"):M(this.hass,"floor_rooms",{n:r.rooms.length}),onBack:()=>this.fire("back",{}),onDeviceTap:(r,i,o)=>this.onDeviceTap(r,i,o),onDeviceHold:(r,i,o)=>this.onDeviceHold(r,i,o),onRoomDoubleTap:(r,i)=>this.onRoomDoubleTap(r,i),onDeviceSwipe:(r,i,o,s,a)=>this.onDeviceSwipe(r,i,o,s,a),onFurnitureSelect:r=>this.fire("furniture-select",{id:r}),onFurnitureMove:(r,i,o)=>this.fire("furniture-move",{id:r,x:i,z:o}),onDeviceSelect:r=>this.fire("device-select",{id:r}),onDeviceMove:(r,i,o)=>this.fire("device-move",{id:r,x:i,z:o}),onStats:r=>{this.showStats&&(this._stats=r)}}),this.viewer.setWallMode(this.wallMode),this.viewer.setPaintedWalls(this.solidWalls),this.viewer.setGlassWalls((this.glassWalls??20)/100),this.viewer.setTheme(this.theme),this.viewer.setAccent(this.accent??null),this.viewer.setFurnitureColors(this.furnitureColors??null),this.viewer.setNotePhotos(r=>this.hass?as(this.hass,r,i=>this.storedPicture(this.hass,i)):null),this.viewer.setNavigationLocked(this._locked),this.viewer.setFurnishMode(this.furnish),this.viewer.setTapInRoom(this.tapInRoom),this.viewer.setSurfaceGrab(this.surfaceGrab??null),this.viewer.setFurnishTypes(this.furnishTypes??null),this.viewer.setFloorStack(this.floorStack),this.viewer.setStats(this.showStats),this.viewer.setAutoOrbit(this.autoOrbit?.06:0),this.viewer.setKeepRoof(this.keepRoof),this.viewer.setKeepCamera(!!this.keepCamera),this.viewer.setPlain(!!this.plain),this.viewer.setRightBack(!!this.rightBack),this.viewer.setZoom(this.zoom??1),this._low=this.viewer.low,this.viewer.setMeshSource(r=>this.hass?.fetchWithAuth?this.hass.fetchWithAuth(`/api/nextfloor/mesh/${encodeURIComponent(r)}`).then(i=>i.ok?i.arrayBuffer():null):Promise.resolve(null)),this.viewer.setPacks([...Wi()]),this.shownPacks=or(),this.building&&(this.shownStartView=JSON.stringify(this.startViewOf()),this.viewer.setStartView(this.startViewOf()),this.viewer.setBuilding(this.shownBuilding(this.hass)),this.viewer.setMap(this.building.settings.map,this.building.settings.north??0)),this.scheduleThumbs(),this.syncDevices(!0),this.viewer.setFloor(this.floorId,!1),this.roomId&&this.viewer.selectRoom(this.roomId)}catch(e){this._error=String(e)}finally{this.starting=!1}}}updated(e){(e.has("announcements")||e.has("hass")&&this.announcements&&!this.stopAnnouncements)&&this.listenToAnnouncements(this.announcements&&!!this.hass&&this.isConnected),e.has("hass")&&this.live?.el&&(this.live.el.hass=this.hass);let t=this._pluginWindow?.node;e.has("hass")&&t&&"hass"in t&&(t.hass=this.hass),this._central&&!this.centralOpen&&(e.has("roomId")&&e.get("roomId")!==void 0||e.has("floorId")&&e.get("floorId")!==void 0)&&(this._central=!1),e.has("centralOpen")&&this.centralOpen&&(this._central=!0),e.has("clock")&&(clearInterval(this.clockTimer),this.clockTimer=this.clock?setInterval(()=>this._now=Date.now(),1e4):void 0);let r=this.viewer;if(!r)return;if(this.shownPacks!==or()&&(this.shownPacks=or(),r.setPacks([...Wi()]),this.hass&&this.building&&r.setParked(No(this.hass,this.building)),this.syncDevices(!0)),e.has("building")&&this.building){let s=JSON.stringify(this.startViewOf()),a=this.shownStartView!==void 0&&this.shownStartView!==s;this.shownStartView=s,r.setStartView(this.startViewOf()),r.setBuilding(this.shownBuilding(this.hass)),r.setMap(this.building?.settings.map,this.building?.settings.north??0),a&&this.floorId===null&&r.resetView()}e.has("startView")&&e.get("startView")!==void 0&&(r.setStartView(this.startViewOf()),this.floorId===null&&r.resetView()),(e.has("building")||e.has("theme")||e.has("floorThumbs")||e.has("packs"))&&this.scheduleThumbs();let i=this.markersOutside?["markersOutside","floorId","roomId"]:["markersOutside"],o=this.pluginsDirty||["building","markerMode","heatMode","flows","alerts","dimmed","holograms","roomLabels","floorId","roomId",...i].some(s=>e.has(s));if(this.pluginsDirty=!1,(o||e.has("hass"))&&this.syncDevices(o),e.has("autoOrbit")&&r.setAutoOrbit(this.autoOrbit?.06:0),(e.has("_thumbs")||e.has("_narrowStage")||e.has("_phoneStage"))&&r.setLabelInset(this._thumbs.length&&!this._phoneStage?this.narrowThumbs?136:184:0),e.has("floorId")&&r.setFloor(this.floorId),e.has("roomId")&&(this.roomId||e.get("roomId"))&&r.selectRoom(this.roomId),e.has("outsideOpen")&&e.get("outsideOpen")!==void 0){let s=this.building?.settings.outside_view;this.outsideOpen&&s?r.showView(s):!this.outsideOpen&&s&&this.floorId===null&&!this.roomId&&r.resetView()}e.has("tapInRoom")&&r.setTapInRoom(this.tapInRoom),e.has("wallMode")&&r.setWallMode(this.wallMode),e.has("solidWalls")&&r.setPaintedWalls(this.solidWalls),e.has("glassWalls")&&r.setGlassWalls((this.glassWalls??20)/100),e.has("explode")&&r.setExplode(this.explode),e.has("keepRoof")&&r.setKeepRoof(this.keepRoof),e.has("keepCamera")&&r.setKeepCamera(!!this.keepCamera),e.has("plain")&&r.setPlain(!!this.plain),e.has("rightBack")&&r.setRightBack(!!this.rightBack),e.has("zoom")&&r.setZoom(this.zoom??1),e.has("floorStack")&&r.setFloorStack(this.floorStack),e.has("theme")&&r.setTheme(this.theme),e.has("_locked")&&r.setNavigationLocked(this._locked),e.has("accent")&&r.setAccent(this.accent??null),e.has("furnitureColors")&&r.setFurnitureColors(this.furnitureColors??null),e.has("surfaceGrab")&&r.setSurfaceGrab(this.surfaceGrab??null),e.has("furnishTypes")&&r.setFurnishTypes(this.furnishTypes??null),e.has("furnish")&&(r.setFurnishMode(this.furnish),this.syncDevices(!0)),e.has("selectedFurniture")&&r.selectFurniture(this.selectedFurniture),e.has("selectedDevice")&&r.setSelectedDevice(this.selectedDevice),(e.has("weather")||e.has("weatherEntityId")||e.has("weatherDensity")||e.has("timeOfDay"))&&this.syncDevices(!0),e.has("quality")&&e.get("quality")!==void 0&&(r.setQuality(this.quality),this._low=r.low),e.has("showStats")&&r.setStats(this.showStats),e.has("building")&&(this.findIndex=null)}shownFor=null;framePictureData=new Map;framePictures(e,t){let r=[];for(let i of t.floors)for(let o of i.notes??[])o.photo?.startsWith("image:")&&this.storedPicture(e,o.photo.slice(6));for(let i of t.floors)for(let o of i.furniture){if(!o.picture||!je(e,o))continue;let s=as(e,o.picture,a=>this.storedPicture(e,a));s&&r.push({furnitureId:o.id,floorId:i.id,url:s,border:o.picture_border??0,fit:o.picture_fit==="contain"?"contain":"cover"})}return r}storedPicture(e,t){let r=this.framePictureData.get(t);return r!==void 0?r||null:(this.framePictureData.set(t,""),Ws(e,t).then(i=>{this.framePictureData.set(t,i),this.syncDevices(!0)}).catch(()=>{}),null)}shownBuilding(e){let t=this.building,r=po(e,t),i=t.floors.filter(a=>a.layer&&this.hiddenLayers.has(a.id)).map(a=>a.id),o=[...r,...i.map(a=>`layer:${a}`)].join(",");if(this.shownFor?.building===t&&this.shownFor.key===o)return this.shownFor.shown;let s=wl(t,r);return this.shownFor={building:t,key:o,shown:i.length?{...s,floors:s.floors.filter(a=>!i.includes(a.id))}:s},this.shownFor.shown}hiddenLayers=(()=>{try{return new Set(JSON.parse(localStorage.getItem("nextfloor.hidden_layers")??"[]"))}catch{return new Set}})();toggleLayer(e){this.hiddenLayers.has(e)?this.hiddenLayers.delete(e):this.hiddenLayers.add(e);try{localStorage.setItem("nextfloor.hidden_layers",JSON.stringify([...this.hiddenLayers]))}catch{}this.viewer&&this.building&&this.viewer.setBuilding(this.shownBuilding(this.hass)),this.requestUpdate()}renderLayers(){let e=(this.building?.floors??[]).filter(t=>t.layer);return!e.length||this.clean?f:p`
${e.map(t=>p``)}
-
`}syncDevices(e){let t=this.viewer,r=this.building;if(!t||!r||!this.hass)return;let i=this._travel,o=i&&!i.loading?qt(this.hass,i.history,i.t):this.hass;if((e||!this.openingLinks||this.linkedRegistry!==o.entities)&&(this.openingLinks=Ve(o,r.floors),this.furnitureLinks=Ge(o,r.floors),this.linkedRegistry=o.entities,this.findIndex=null,this.alertSrc=this.alerts?Ic(o,r,this.weatherEntityId,this.openingLinks):null,this.watched=Vc({hass:o,building:r,openingLinks:this.openingLinks,furnitureLinks:this.furnitureLinks,needsRoomSensors:this.heatMode!=="none"||this.roomLabels,alertSources:this.alertSrc,weatherEntityId:this.weatherEntityId}),e=!0),!(e||this.watched.some(v=>this.shownStates.get(v)!==o.states[v])))return;po(o,r).join(",")!==this.shownFor?.key&&t.setBuilding(this.shownBuilding(o)),this.shownStates=new Map(this.watched.map(v=>[v,o.states[v]])),this.syncHydronics(t,r,o),this.refreshToday(r),this.refreshForecast(r);let a=Mn(o,r),l=al(o,r.floors.some(v=>v.layer&&this.hiddenLayers.has(v.id))?this.shownBuilding(o):r);this.placementInfo=new Map(l.map(v=>[v.id,{floorId:v.floorId,roomId:v.roomId,x:v.x,z:v.z,y:v.y,rotation:v.rotation??0}]));let c=this.furnitureMarkers(o,r,new Set(l.map(v=>v.id)),new Set(a.map(v=>v.powerEntity)));a.push(...c.consumers);let u=An(o,r,a,Ye(r,v=>this.furnitureLinks?.get(v.id)?.power??null)),h=new Map(a.filter(v=>v.id!==v.powerEntity).map(v=>[v.id,v.power]));this.confirmSet=yt(o,r.floors);let m=new Set(this.liveCardsOn?this._liveCards.flatMap(v=>v.kind==="media"?[v.media.entity]:v.kind==="car"?[v.spot]:[]):[]);for(let v of r.floors)for(let k of v.outdoor??[]){if(!k.area_id&&!k.temp_entity&&!k.pump_entity)continue;let K=k.temp_entity?o.states[k.temp_entity]:void 0,F=k.pump_entity?o.states[k.pump_entity]:void 0,[V,be]=Fe(k.points),ut=K&&Number.isFinite(Number(K.state))?`${L(o,ue(o,_r(Number(K.state),K.attributes.unit_of_measurement)),1)} ${ie(o)}`:"",At=!!F&&ne(F);l.push({id:k.area_id?`outdoor:${k.id}`:k.pump_entity??k.temp_entity,floorId:v.id,roomId:null,x:V,z:be,y:dr(v,k,V,be)+.7,icon:He(k.type==="pool"?"pool":k.type==="terrace"?"table-chair":"tree-outline"),name:k.area_id&&o.areas?.[k.area_id]?.name||M(o,`out_${k.type}`),text:[ut,At?M(o,"pool_pump_on"):""].filter(Boolean).join(" \xB7 "),active:At,unavailable:!1,glow:null,show:"always"})}let d=new Map;for(let v of r.floors){for(let k of v.placements)k.pin_offset&&d.set(`${v.id}:${k.entity_id}`,k.pin_offset);for(let k of v.furniture)k.pin_offset&&d.set(`f:${k.id}`,k.pin_offset)}let g=v=>{let k=v.lamp?void 0:(v.furnitureId?d.get(`f:${v.furnitureId}`):void 0)??d.get(`${v.floorId}:${v.id}`);return k?{...v,x:v.x+(k.x??0),z:v.z+(k.z??0),y:v.y+(k.y??0)}:v};t.setDevices([...[...l,...c.markers].map(g).map(v=>{let k=v.show==="no_power"||"energyDevice"in v&&v.energyDevice?null:h.get(v.id)??null,K={...v,power:k,powerText:k===null?void 0:me(o,k),effect:this.dimmed?void 0:v.effect,text:this.subMeterText(o,r,u,v.furnitureId)??v.text},F=v.ownName&&(v.showName||this.markerNames)?v.ownName:"",V=m.has(v.id)||!!v.furnitureId&&m.has(v.furnitureId);return{...K,pin:this.showPin(K)&&!V,full:v.show==="always",caption:F}})]),t.setPickTargets(c.targets,this.openingTargets(),this.secondBlinds()),t.setScreens(c.screens),t.setFridgeDoors(Ba(o,r.floors)),t.setCovers(Xa(o,r)),t.setRobots(this.robotInfos(o,r));let _=new Map;for(let v of r.floors)for(let k of v.furniture)!ee(k.type)?.pet||!k.room_sensor||k.room_sensor==="none"||_.set(k.id,eo(o,v.rooms.filter(K=>K.points.length>=3),null,k.room_sensor)?.id??null);_.size&&t.setPetRooms(_),t.setRoofWindows(Tc(o,r)),t.setParked(No(o,r)),t.setGateStates(Zc(o,r));let b=new Map(r.floors.flatMap(v=>v.openings.map(k=>[k.id,k.type]))),y=new Map([...this.openingLinks].map(([v,k])=>[v,Ke(o,k,b.get(v))]));t.setOpeningStates(y),this.setAlerts(this.alertSrc?Po(o,r,this.alertSrc,this.openingLinks):[]),this.watchLostContacts(o);let $=[...l,...c.markers].map(v=>`${v.id}:${v.glow?`${v.glow.level.toFixed(1)}/${v.glow.color.map(k=>k.toFixed(1)).join("/")}`:0}`).join(";")+"|"+[...y].map(([v,k])=>`${v}:${k.open}:${k.cover===null?"-":k.cover.toFixed(1)}`).join(";");if($!==this.thumbSig){let v=this.thumbSig==="";this.thumbSig=$,v||this.scheduleThumbs(1500)}let S=cu(o,r,a,r.energy.advanced?v=>this.furnitureLinks?.get(v.id)?.power??null:void 0),A=this.liveCars(o,r);for(let v of A){if(!v.car.home||!v.car.charging&&!v.car.plugged)continue;let k=r.floors.flatMap(V=>V.furniture.filter(be=>be.type==="wallbox").map(be=>({floorId:V.id,x:be.x,z:be.z,y:1}))).sort((V,be)=>Math.hypot(V.x-v.at.x,V.z-v.at.z)-Math.hypot(be.x-v.at.x,be.z-v.at.z))[0],K=k&&k.floorId===v.at.floorId&&Math.hypot(k.x-v.at.x,k.z-v.at.z)<9,F=k??On(r);!F||!v.car.charging&&!K||S.arcs.push({key:`car:${v.spot}`,from:F,to:{...v.at,y:.8},power:v.car.charging?v.car.chargingW??7e3:0,color:[80,175,255],...K?{via:[{...F,y:.35},{floorId:v.at.floorId,x:(F.x+v.at.x)/2,z:(F.z+v.at.z)/2,y:.08},{...v.at,y:.5}],cable:!0}:{}})}let z=On(r);for(let v of this.liveHeatPumps(r)){let k=v.pump.heat??(v.pump.mode==="heating"||v.pump.mode==="water"?(v.pump.power??0)*(v.pump.cop??3):0);z&&k>100&&v.pump.mode!=="cooling"&&S.arcs.push({key:`heat:${v.id}`,from:{floorId:v.floorId,x:v.x,z:v.z,y:.8},to:z,power:k,color:[255,120,40]})}let x=(this.flows??this._flows)&&!this.dimmed;t.setLiveEnergy(x?S.arcs:[],x?S.sparks:[]),JSON.stringify(S)!==JSON.stringify(this._liveEnergy)&&(this._liveEnergy=S);let T=this.liveMedia(o,r).filter(v=>v.playing&&!this.dimmed);t.setLiveSound(T.filter(v=>v.rings>0).map(v=>({id:v.entity,at:v.at,color:v.color,level:v.volume??.5,size:v.rings})),Ec(T).map(([v,k])=>[v.at,k.at])),this.syncLhCards(t,r,S,A,T,o),t.setLiveScreens(this.dimmed?[]:Fc(o,r,this.furnitureLinks)),t.setPictures(this.framePictures(o,r)),t.setLiveWater(this.dimmed?[]:Rc(o,r,this.furnitureLinks));let R=hc(o,r);t.setPersons(R);let E=mc(o,r,this.openingLinks,R);t.setFloorInfo(new Map([...E].map(([v,k])=>[v,pc(o,k)])));let I=o.config,N=this.timeOfDay!=null&&I?.latitude!==void 0&&I.longitude!==void 0?gt(zt(this.timeOfDay,I.time_zone),I.latitude,I.longitude):Dc(o);t.setSun(N),t.setLocation(I?.latitude!==void 0&&I.longitude!==void 0?{latitude:I.latitude,longitude:I.longitude,zone:I.time_zone}:null);let G=this.weather&&!this.dimmed?Yc(o,lt(o,this.weatherEntityId??r.settings.weather_entity)):null,q=G?Jc(Qc(G,r.settings.weather_effects),this.weatherDensity):null;this.cloud=q?.cloud??0,this._sky=Hc(N?.elevation??null,this.cloud),t.setSky(this.weather&&!this.dimmed?{weather:q,sun:N,north:r.settings.north??0,sky:this.skyColor(),disc:(r.settings.weather_effects??["sky"]).includes("sky"),low:this._low}:null),this.applyTint();let oe=u.grid!==null||u.solar!==null||u.battery!==null||u.tariff!==null?u:null;JSON.stringify(oe)!==JSON.stringify(this._energy)&&(this._energy=oe)}watchLostContacts(e){let t=!!this.alertSrc&&!this._travel&&Nc(e,this.alertSrc);t&&!this.contactTimer&&(this.contactTimer=setInterval(()=>{let r=this.building;this.alertSrc&&r&&this.hass&&this.openingLinks&&!this._travel&&this.setAlerts(Po(this.hass,r,this.alertSrc,this.openingLinks))},6e4)),!t&&this.contactTimer&&(clearInterval(this.contactTimer),this.contactTimer=void 0)}setAlerts(e){let t=e.map(o=>`${o.kind}:${o.entity}`),r=e.filter((o,s)=>!this.seenAlerts.has(t[s])&&!Qr.has(o.kind));this.seenAlerts=new Set(t),t.join()!==this._alerts.map(o=>`${o.kind}:${o.entity}`).join()&&(this._alerts=e);let i=e.some(o=>!Qr.has(o.kind));i&&!this.alertTimer&&(this.alertTimer=setInterval(()=>!document.hidden&&this.applyTint(),this._low?200:100)),!i&&this.alertTimer&&(clearInterval(this.alertTimer),this.alertTimer=void 0),r.length&&this.alertJump&&this.jumpTo(r[0])}jumpTo(e){if(e.kind==="own"&&e.tap!=="room"){e.tap==="toggle"&&W(this.hass,e.entity)?this.hass.callService("homeassistant","toggle",{entity_id:e.entity}):Se(this,e.entity);return}if(!e.floorId){this.fire("floor-tap",{floorId:null});return}this.floorId!==e.floorId&&this.fire("floor-tap",{floorId:e.floorId}),e.roomId&&setTimeout(()=>this.fire("room-tap",{floorId:e.floorId,roomId:e.roomId}),60)}onRoomDoubleTap(e,t){let r=this.building,i=this.hass,o=r?.floors.find(u=>u.id===e),s=o?.rooms.find(u=>u.id===t);if(!r||!i||!o||!s)return;let a=Kc(r.settings.room_double_tap,this.roomDoubleTap),l=Gc(i,o,s,this.furnitureLinks,this.confirmSet,a).filter(u=>W(i,u));if(!l.length)return;let c=l.some(u=>i.states[u]?.state==="on");i.callService("homeassistant",c?"turn_off":"turn_on",{entity_id:l}),this.roomFlash={roomId:t,until:performance.now()+350},this.applyTint(),setTimeout(()=>{this.roomFlash=null,this.applyTint()},380)}runScene(e){W(this.hass,e)&&(this.hass.callService(e.split(".")[0],"turn_on",{entity_id:e}),this._sceneFired=e,setTimeout(()=>this._sceneFired=null,600))}applyTint(){let e=this.viewer,t=this.building,r=this.hass;if(!e||!t||!r)return;let i=null;if(this.heatMode!=="none"&&this.heatMode!=="values"&&this.heatMode!=="wifi"){let a=this.heatMode,l=nc(r,t,a);!l.size!=!this.heatValues.size&&this.requestUpdate(),this.heatValues=l;let c=wt(new Date,r.config?.latitude??50);i=new Map([...l].map(([u,h])=>[u,tc(a,h,c)]))}let o=new Map;if(this.heatMode==="values")for(let a of t.floors)for(let l of a.rooms){let c=Y(r,a,l,"temperature"),u=Y(r,a,l,"humidity"),h=Y(r,a,l,"co2"),m=Kr(h,u,jt(c,u)),d=[c!==null?`${L(r,ue(r,c),1)} ${ie(r)}`:null,u!==null?`${L(r,u,0)} %`:null,h!==null?`${L(r,h,0)} ppm`:null,m?`\u{1F4A8} ${M(r,`air_${m}`)}`:null].filter(g=>!!g);d.length&&o.set(l.id,d.join(" \xB7 "))}if(e.setRoomInfo(o),!i)for(let a of t.floors)for(let l of a.rooms){let c=l.floor_heating?r.states[l.floor_heating]:void 0;c&&(B(r)?ce(c)===!0:c.entity_id.startsWith("climate.")?c.attributes.hvac_action==="heating":c.state==="on"||c.state==="open")&&(i??=new Map).set(l.id,[.55,.24,.08])}if(this._alerts.length){i??=new Map;let a=.55+.45*Math.sin(performance.now()/160);for(let l of this._alerts){if(Qr.has(l.kind))continue;let c=Lc(l.kind).map(u=>u*a);if(l.roomId)i.set(l.roomId,c);else for(let u of t.floors)for(let h of u.rooms)i.set(h.id,c)}}this.roomFlash&&performance.now()`${a}:${l.map(c=>c.toFixed(2)).join(",")}`).join(";"):"";s!==this.tintSig&&(this.tintSig=s,e.setRoomTint(i))}furnitureMarkers(e,t,r,i){let o=[],s=[],a=new Map,l=new Map,c=$n(t);for(let m of t.floors)if(!(m.layer&&this.hiddenLayers.has(m.id)))for(let d of m.furniture){if(!je(e,d))continue;let g=this.furnitureLinks.get(d.id),_=this.stateFaces(e,d);_.length&&a.set(d.id,{color:_[0].color,level:_[0].level,faces:_});let b=ar(d.type);if(b&&d.care_entity){let k=this.careMarker(e,m,d,b,d.care_entity);k&&(o.push(k.marker),k.glow&&a.set(d.id,{color:k.glow,level:.9,faces:[{part:"all",color:k.glow,level:.9}]}),l.set(d.id,d.care_entity));continue}let y=ee(d.type);if(d.cover_entity&&sr(y)&&l.set(d.id,d.cover_entity),y?.gangs){for(let K of(d.gang_entities??[]).slice(0,y.gangs)){let F=K&&K!=="none"?we(e,K):null,V=F?Z(e.states[F]):null;F&&V!==null&&!i.has(F)&&(i.add(F),s.push({id:K,powerEntity:F,floorId:m.id,x:d.x,z:d.z,power:Math.max(0,V)}))}let k=Za(e,(d.gang_entities??[]).slice(0,y.gangs),/socket/.test(d.type));k.length&&a.set(d.id,{color:k[0].color,level:k[0].level,gangs:k}),ro(d.gang_entities,y.gangs).length&&l.set(d.id,`gang:${d.id}`);continue}if(mr(d.type)){let k=this.lampMarker(e,m,d,g?.entity??null),K=g?.power?Z(e.states[g.power]):null;if(g?.power&&K!==null&&(K>=1&&(k.text=k.text?`${k.text} \xB7 ${xt(e,K)}`:xt(e,K)),i.has(g.power)||(i.add(g.power),s.push({id:k.id,powerEntity:g.power,floorId:m.id,x:d.x,z:d.z,power:Math.max(0,K)}))),o.push(k),d.type==="ceiling_fan"){let F=g?.fan?e.states[g.fan]:void 0;k.spin=Bu(F),F&&!r.has(F.entity_id)&&(r.add(F.entity_id),o.push({...k,id:F.entity_id,y:Math.max(.5,k.y-.3),icon:d.icon?He(d.icon):Lt("fan"),name:d.name||O(e,F.entity_id),text:lg(e,F),active:ne(F),unavailable:C(F),glow:null,lamp:null,spin:void 0,pickable:void 0,effect:void 0}))}continue}let $=Xi(d.type)?La(e,d,k=>`${L(e,ue(e,k),1)} ${ie(e)}`):null,S=Xi(d.type)?null:Wa(e,d.temp_entity),A=S===null?"":`\u{1F321} ${L(e,ue(e,S),1)} ${ie(e)}`,z=d.type==="home_battery"?d.soc:d.type==="wallbox"?d.status:$?d.temp_entity&&d.temp_entity!=="none"?d.temp_entity:d.temp_entity2:S!==null?d.temp_entity:null,x=z&&z!=="none"?z:(d.values??[]).find(k=>k.entity&&k.entity!=="none")?.entity??null,D=g??(x?{entity:null,power:null}:void 0);if(!D)continue;let T=d.type==="home_battery"?x??D.entity??D.power:D.entity??D.power??x;l.set(d.id,T);let R=D.entity?e.states[D.entity]:void 0,E=c.has(d.id),I=E?!!d.meter_invert:d.type==="meter"?t.energy.grid_invert&&!d.export:d.type==="home_battery"?t.energy.battery_invert&&!d.charge:!1,N=D.power?Z(e.states[D.power],I):null,G=d.type==="home_battery"&&d.charge&&d.charge!=="none"?d.charge:d.type==="meter"&&!E&&d.export&&d.export!=="none"?d.export:null,q=G?Z(e.states[G]):null;q!==null&&(N=Math.max(0,N??0)-Math.max(0,q)),D.power&&N!==null&&!i.has(D.power)&&(i.add(D.power),s.push({id:T,powerEntity:D.power,floorId:m.id,x:d.x,z:d.z,power:Math.max(0,N),wallbox:d.type==="wallbox"||void 0}));let J=(N??0)>10||R?.state==="on"||R?.state==="running"||gr(R)&&ne(R);if((d.type==="radiator"||y)&&R&&P(R.entity_id)==="climate"){let k=R.attributes;if(k.hvac_action==="heating"){let K=typeof k.temperature=="number"&&typeof k.current_temperature=="number"?k.temperature-k.current_temperature:1,F=!!y&&!y.parts.some(V=>V.screen);a.set(d.id,{color:[1,.42,.1],level:Math.min(1,.45+.25*Math.max(0,K)),heat:F||void 0})}}else(d.type==="washer"||d.type==="dryer"||d.type==="dishwasher")&&J?a.set(d.id,{color:[.3,.85,1],level:.8}):y&&J&&!y.light&&y.parts.some(k=>k.glow||k.screen)&&a.set(d.id,{color:[.3,.85,1],level:.8,leds:!0});if(Qo(d.type)){let k=Jo(e,D.entity??D.power);if(k&&k.progress!==null&&(k.printing||/pause/.test(k.status))){let K=k.filaments[0]??"#38bdf8",F=[1,3,5].map(V=>parseInt(K.slice(V,V+2),16)/255);a.set(d.id,{color:F,level:.9,print:Math.max(.02,k.progress/100)})}}if(d.type==="home_battery"&&x){let k=Number(e.states[x]?.state);Number.isFinite(k)&&a.set(d.id,{color:k>60?[.29,.87,.5]:k>25?[.98,.8,.08]:[.97,.44,.44],level:.95,fill:k/100})}if(R&&xr(d.type)){let k=P(R.entity_id)==="light"?Be(R):null,K=P(R.entity_id)==="media"&&["playing","on","paused","idle"].includes(R.state),F=k?k.color:ne(R)||K?[.22,.88,1]:null;F&&a.set(d.id,{color:F,level:R.state==="playing"?1:.6,halo:d.ambilight??1})}if(r.has(T))continue;r.add(T);let oe=D.entity?P(D.entity):null,v=m.rooms.find(k=>k.points.length>=3&&H([d.x,d.z],k.points));o.push({id:T,floorId:m.id,roomId:v?.id??null,x:d.x,z:d.z,y:ls(d)+se(m,d),icon:d.icon?He(d.icon):Lt(oe??"switch"),name:d.name||(D.entity?O(e,D.entity):le(e,d.type)),ownName:d.name||void 0,showName:!!d.show_name,text:[$?$.text:d.type==="home_battery"?this.batteryText(e,x,N):d.type==="wallbox"?this.wallboxText(e,x,N):d.type==="meter"?E?N===null?"":me(e,N):this.meterText(e,N):R&&(d.type==="washer"||d.type==="dryer"||d.type==="dishwasher")&&J&&oo(e,vn(e,D.entity??D.power))!==null?M(e,"care_time_left",{time:Qa(oo(e,vn(e,D.entity??D.power)))}):R?[ae(e,R),N!==null&&N>5&&!gr(R)?me(e,N):""].filter(Boolean).join(" \xB7 "):N!==null?me(e,Math.max(0,N)):"",A,wn(e,d.values)].filter(Boolean).join(" \xB7 "),active:$?.warm||S!==null&&S>=Oa||(R?ne(R):(N??0)>5),unavailable:R?C(R):!1,glow:null,furnitureId:d.id,energyDevice:d.type==="inverter"||d.type==="home_battery"||d.type==="wallbox"||d.type==="meter",readout:!!$||!!d.values?.some(k=>k.entity&&k.entity!=="none")||void 0,show:d.marker??void 0,fromFurniture:!0})}let u=this.heatMode==="wifi";for(let m of o){let d=m.furnitureId?t.floors.flatMap(_=>_.furniture).find(_=>_.id===m.furnitureId):void 0;if(!d||!Xo(d.type))continue;let g=es(e,this.furnitureLinks.get(d.id)?.entity??this.furnitureLinks.get(d.id)?.power??null);g&&(g.clients!==null&&(m.text=M(e,"wifi_clients",{n:g.clients})),u&&(m.wedge={angle:360,reach:9,near:0,color:Mu(g),opacity:.4,through:!0,walls:!1},m.show="always"))}let h=Uc(t,o);for(let m of t.floors.flatMap(d=>d.furniture))st(m.type)&&l.set(m.id,`hydronic:${m.id}`);this.tapPins=h.pins;for(let m of t.floors.flatMap(d=>d.furniture))m.tap?.action&&l.set(m.id,`tap:${m.id}`);for(let{floor:m,item:d}of h.bare){let g=m.rooms.find(b=>b.points.length>=3&&H([d.x,d.z],b.points)),_=d.name||le(e,d.type);o.push({id:`tap:${d.id}`,floorId:m.id,roomId:g?.id??null,x:d.x,z:d.z,y:ls(d)+se(m,d),icon:He(d.icon||"gesture-tap-button"),name:_,ownName:d.name||void 0,showName:!!d.show_name,text:"",active:!1,unavailable:!1,glow:null,furnitureId:d.id,show:d.marker??void 0,fromFurniture:!0})}return{markers:o,consumers:s,screens:a,targets:l}}robotObstacles(e,t){let r=new Set(["rug","worktop","table","table_round","coffee_table","chair","office_chair","stool","bar_stool","bench","desk","robot_vacuum","parking","stairwell","radiator","tv_wall","kitchen_wall","led_strip"]);return e.furniture.filter(i=>{if(r.has(i.type)||i.type.startsWith("lamp_")&&i.type!=="lamp_floor"&&i.type!=="lamp_uplight"||i.h<.04||se(e,i)>.12)return!1;let o=ee(i.type);return o&&(o.hole||/table|desk|chair|stool|bench|rug|carpet|mat$/.test(i.type))?!1:H([i.x,i.z],t)||pr(i).some(s=>H(s,t))}).map(i=>pr(i))}robotInfos(e,t){let r=[],i=qu(e),o=Zu(e,i,t.settings.vacuum_map??null),s=!1;for(let a of t.floors){for(let l of a.furniture){if(l.type!=="robot_vacuum")continue;let c=this.furnitureLinks.get(l.id)?.entity??null,u=c?e.states[c]?.state:void 0,h=u==="cleaning"?"cleaning":u==="returning"?"returning":u==="error"?"error":u==="docked"||!u?"docked":"idle",m=l.rotation*Math.PI/180,d=l.d*.14,g=[l.x-Math.sin(m)*d,l.z+Math.cos(m)*d],_=a.rooms.filter(T=>T.points.length>=3),y=(h==="cleaning"?eo(e,_,c,kr(e,c,l.room_sensor)):null)??_.find(T=>H(g,T.points)),$=h==="cleaning"&&y?this.robotObstacles(a,y.points):[],S=i?Date.parse(e.states[i]?.last_updated??""):Number.NaN,A=!Number.isFinite(S)||Date.now()-S<120*1e3,z=c?.startsWith("vacuum.")&&o&&!s&&(A||h!=="cleaning"&&h!=="returning")?o:null;z&&(s=!0);let x=c?Date.parse(e.states[c]?.last_changed??""):Number.NaN,D=h==="cleaning"||h==="returning"?null:Number.isFinite(x)?x:null;r.push({id:l.id,floorId:a.id,rest:g,restHeading:-m,mode:h,room:y?.points??null,roomId:y?.id??null,obstacles:$,track:z?.path??null,pose:z?.pose??null,settledAt:D})}for(let l of a.furniture){if(!/:(robot_mower|mower_dock)$/.test(l.type))continue;let c=this.furnitureLinks.get(l.id)?.entity??null;if(!c?.startsWith("lawn_mower."))continue;let u=e.states[c]?.state,h=u==="mowing"?"cleaning":u==="returning"?"returning":u==="error"?"error":u==="docked"||!u?"docked":"idle",m=[l.x,l.z],d=(a.outdoor??[]).filter(b=>b.type==="lawn"&&b.points.length>=3),g=d.find(b=>H(m,b.points))??[...d].sort((b,y)=>fn(y.points)-fn(b.points))[0],_=g?(a.outdoor??[]).filter(b=>b!==g&&b.type!=="lawn"&&b.points.some(y=>H(y,g.points))).map(b=>b.points):[];r.push({id:l.id,floorId:a.id,rest:m,restHeading:-l.rotation*Math.PI/180,mode:h,room:g?.points??null,roomId:g?.id??null,obstacles:_,y:g?dr(a,g,m[0],m[1]):hr(a),mower:!0})}}return r}batteryText(e,t,r){let i=t?Number(e.states[t]?.state):Number.NaN,o=[];return Number.isFinite(i)&&o.push(`${L(e,i,0)} %`),r!==null&&Math.abs(r)>=10&&o.push(`${r<0?"\u25B2":"\u25BC"} ${me(e,Math.abs(r))}`),o.join(" \xB7 ")}subMeterText(e,t,r,i){let o=i?Hl(t,r,i):null;return o?me(e,o.use)+(o.unmetered===null?"":` \xB7 ${M(e,"meter_unmetered",{w:me(e,o.unmetered)})}`):null}meterText(e,t){return t===null?"":Math.abs(t)<5?me(e,0):`${M(e,t<0?"energy_grid_export":"energy_grid_import")} ${me(e,Math.abs(t))}`}wallboxText(e,t,r){let i=t?e.states[t]:void 0,o=String(i?.state??"").toLowerCase(),s=(r??0)>50||/charg|laden|lädt/.test(o),a=i?.entity_id.startsWith("binary_sensor.")?o==="on":/connect|plug|ready|angesteckt|verbunden|wait|paused|suspend/.test(o),l=s?M(e,"wallbox_charging"):a?M(e,"wallbox_plugged"):i&&!C(i)&&!i.entity_id.startsWith("binary_sensor.")?ae(e,i):"",c=r!==null&&r>50?me(e,r):"";return[l,c].filter(Boolean).join(" \xB7 ")}stateFaces(e,t){let r=[],i=t.state_entity2&&t.state_entity2!=="none"?[[t.state_entity,t.state_split==="top_bottom"?"bottom":"left"],[t.state_entity2,t.state_split==="top_bottom"?"top":"right"]]:[[t.state_entity,"all"]];for(let[o,s]of i){if(!o||o==="none")continue;let a=e.states[o];if(!a||C(a)||!(ne(a)||a.state==="home"||a.state==="occupied"||a.state==="on"))continue;let c=P(o)==="light"?Be(a):null;r.push({part:s,color:c?c.color:[1,.71,.28],level:c?c.level:.85})}return r}careMarker(e,t,r,i,o){let s=e.states[o];if(!s)return null;let a="",l=!1,c=null;if(i==="bin"){let m=Sr(s);a=m===null?ae(e,s):m===0?M(e,"care_bin_today"):m===1?M(e,"care_bin_tomorrow"):M(e,"care_bin_days",{n:m}),l=m!==null&&m<=1,l&&(c=[1,.72,.28])}else if(i==="mail")l=Ya(s),a=M(e,l?"care_mail_yes":"care_mail_no"),l&&(c=[1,.85,.3]);else{let m=Ja(s,r.thirsty_below??20);l=!!m?.thirsty,a=m?Number.isFinite(m.moisture)?`${M(e,l?"care_plant_thirsty":"care_plant_ok")} \xB7 ${Math.round(m.moisture)} %`:M(e,l?"care_plant_thirsty":"care_plant_ok"):ae(e,s),l&&(c=[1,.45,.3])}let u=t.rooms.find(m=>m.points.length>=3&&H([r.x,r.z],m.points)),h={bin:"mdi:trash-can-outline",mail:"mdi:mailbox-outline",plant:"mdi:sprout-outline"}[i];return{glow:c,marker:{id:o,floorId:t.id,roomId:u?.id??null,x:r.x,z:r.z,y:ls(r)+se(t,r),icon:r.icon?He(r.icon):He(h),name:r.name||le(e,r.type),ownName:r.name||void 0,showName:!!r.show_name,text:a,active:l,unavailable:C(s),glow:null,furnitureId:r.id,show:r.marker??void 0,fromFurniture:!0,care:!0}}}lampMarker(e,t,r,i){let o=i?e.states[i]:void 0,s=(r.extra_lights??[]).map(b=>e.states[b]).filter(b=>!!b),a=s.find(b=>ne(b)),l=ee(r.type),c=ga[r.type]??l?.light??"floor",u=t.rooms.some(b=>b.points.length>=3&&H([r.x,r.z],b.points)),h=c==="strip"&&!u?pn(t,r.x,r.z)+(r.mount_y??0):r.mount_y!=null&&!l?r.mount_y:l||c==="wall"||c==="strip"?se(t,r):c==="table"?ur(t,r.x,r.z):c==="bollard"||c==="garden"?pn(t,r.x,r.z):0,m=t.rooms.find(b=>b.points.length>=3&&H([r.x,r.z],b.points)),d=cr(t,r),g=l?l.mount==="ceiling"?Math.max(.5,h-.15):h+r.h+.2:{ceiling:d-.3,downlight:d-.25,spot:d-.35,panel:d-.25,pendant:Math.max(.6,d-r.h-.25),fan:Math.max(.6,d-r.h-.2),floor:h+r.h+.25,uplight:h+r.h+.25,table:h+r.h+.2,wall:h+r.h+.2,strip:r.upright?h+r.w+.15:Math.max(.3,h-.2),bollard:h+r.h+.25,garden:h+r.h+.25}[c],_={id:i??`lamp:${r.id}`,floorId:t.id,roomId:m?.id??null,x:r.x,z:r.z,y:g,icon:Lt("light"),name:r.name||(i?O(e,i):le(e,r.type)),text:[o&&(ne(o)||!a)?ae(e,o):a?O(e,a.entity_id):"",wn(e,r.values)].filter(Boolean).join(" \xB7 "),readout:!!r.values?.some(b=>b.entity&&b.entity!=="none"),active:(o?ne(o):!1)||!!a,unavailable:o?C(o):!1,glow:o||s.length?co(Sa(o,s,r.color_entity&&r.color_entity!=="none"?e.states[r.color_entity]:void 0),r.glow_scale):null,lamp:c,rotation:r.rotation,mirror:!!r.mirror,roll:r.tilt??0,upright:!!r.upright,rise:r.rise??0,size:[r.w,r.d,r.h],base:h,pickable:!!i,furnitureId:r.id,pack:l?r.type:null,lightY:l?l.mount==="ceiling"?h:h+r.h*.85:void 0,ceiling:d,effect:o?.state==="on"?Tr(r,ol(e,r,i)):void 0,variant:r.variant,show:r.marker??void 0,fromFurniture:!0};return o&&i?uo(e,_,o,!1):_}showPin(e){if(this.furnish&&!e.fromFurniture)return!0;if(e.show==="never"||this.markerMode==="none")return!1;if(e.show==="always")return!0;if(e.show==="active"||this.building?.settings.motion_markers_active&&xa(this.hass,e.id)){if(!e.active)return!1;if(e.show==="active")return!0}if(this.markersOutside&&!(this.roomId&&e.roomId===this.roomId))return this.markersOutside.includes(ya(e.id,!!e.lamp));if(this.markerMode==="all")return!0;if(e.lamp)return!1;let t=P(e.id);return t==="light"?!1:e.fromFurniture&&t==="fan"?!0:e.care?e.active:e.id.startsWith("tap:")||e.readout?!0:e.fromFurniture?(e.power??0)>=1||t==="media"&&e.active||!!e.energyDevice&&!!e.text:!0}openingTargets(){let e=new Map;for(let[t,r]of this.openingLinks??[]){let i=r.lock??r.cover??r.contact??r.tilt;i&&e.set(t,i)}return e}downloadStl(){let e=this.viewer?.exportStl(10);if(!e)return;let t=URL.createObjectURL(new Blob([e],{type:"model/stl"})),r=document.createElement("a");r.href=t,r.download=`nextfloor-${new Date().toISOString().slice(0,10)}.stl`,r.click(),setTimeout(()=>URL.revokeObjectURL(t),5e3)}secondBlinds(){let e=new Map;for(let[t,r]of this.openingLinks??[])r.cover2&&!r.lock&&r.cover&&e.set(t,r.cover2);return e}scheduleThumbs(e=600){clearTimeout(this.thumbTimer);let t=this.building?.floors.filter(i=>i.rooms.length).length??0;if(!this.floorThumbs||t<2){this._thumbs=[];return}let r=Math.max(e,this.thumbsAt+(this._low?8e3:4e3)-Date.now());this.thumbTimer=setTimeout(()=>{if(!(!this.viewer||this.dimmed&&this._thumbs.length)){if(document.hidden){this.scheduleThumbs(3e3);return}this.thumbsAt=Date.now(),this._thumbs=this.viewer.floorThumbnails(this.narrowThumbs?104:150,this.narrowThumbs?78:112)}},r)}get narrowThumbs(){return this._narrowStage}renderThumbs(){if(!this._thumbs.length||!this.building||this._phoneStage)return f;let e=new Map(this.building.floors.map(o=>[o.id,o.name])),t=[...this._thumbs].sort((o,s)=>(this.building.floors.find(a=>a.id===s.floorId)?.elevation??0)-(this.building.floors.find(a=>a.id===o.floorId)?.elevation??0)),r=this._thumbsCompact,i=()=>{this._thumbsCompact=!r;try{localStorage.setItem("nextfloor.thumbs_compact",this._thumbsCompact?"1":"0")}catch{}};return p` `}syncDevices(e){let t=this.viewer,r=this.building;if(!t||!r||!this.hass)return;let i=this._travel,o=i&&!i.loading?qt(this.hass,i.history,i.t):this.hass;if((e||!this.openingLinks||this.linkedRegistry!==o.entities)&&(this.openingLinks=Ve(o,r.floors),this.furnitureLinks=Ge(o,r.floors),this.linkedRegistry=o.entities,this.findIndex=null,this.alertSrc=this.alerts?Ic(o,r,this.weatherEntityId,this.openingLinks):null,this.watched=Vc({hass:o,building:r,openingLinks:this.openingLinks,furnitureLinks:this.furnitureLinks,needsRoomSensors:this.heatMode!=="none"||this.roomLabels,alertSources:this.alertSrc,weatherEntityId:this.weatherEntityId}),e=!0),!(e||this.watched.some(v=>this.shownStates.get(v)!==o.states[v])))return;po(o,r).join(",")!==this.shownFor?.key&&t.setBuilding(this.shownBuilding(o)),this.shownStates=new Map(this.watched.map(v=>[v,o.states[v]])),this.syncHydronics(t,r,o),this.refreshToday(r),this.refreshForecast(r);let a=Mn(o,r),l=al(o,r.floors.some(v=>v.layer&&this.hiddenLayers.has(v.id))?this.shownBuilding(o):r);this.placementInfo=new Map(l.map(v=>[v.id,{floorId:v.floorId,roomId:v.roomId,x:v.x,z:v.z,y:v.y,rotation:v.rotation??0}]));let c=this.furnitureMarkers(o,r,new Set(l.map(v=>v.id)),new Set(a.map(v=>v.powerEntity)));a.push(...c.consumers);let u=An(o,r,a,Ye(r,v=>this.furnitureLinks?.get(v.id)?.power??null)),h=new Map(a.filter(v=>v.id!==v.powerEntity).map(v=>[v.id,v.power]));this.confirmSet=vt(o,r.floors);let m=new Set(this.liveCardsOn?this._liveCards.flatMap(v=>v.kind==="media"?[v.media.entity]:v.kind==="car"?[v.spot]:[]):[]);for(let v of r.floors)for(let k of v.outdoor??[]){if(!k.area_id&&!k.temp_entity&&!k.pump_entity)continue;let K=k.temp_entity?o.states[k.temp_entity]:void 0,F=k.pump_entity?o.states[k.pump_entity]:void 0,[V,be]=Fe(k.points),dt=K&&Number.isFinite(Number(K.state))?`${L(o,ue(o,_r(Number(K.state),K.attributes.unit_of_measurement)),1)} ${ie(o)}`:"",At=!!F&&ne(F);l.push({id:k.area_id?`outdoor:${k.id}`:k.pump_entity??k.temp_entity,floorId:v.id,roomId:null,x:V,z:be,y:dr(v,k,V,be)+.7,icon:He(k.type==="pool"?"pool":k.type==="terrace"?"table-chair":"tree-outline"),name:k.area_id&&o.areas?.[k.area_id]?.name||M(o,`out_${k.type}`),text:[dt,At?M(o,"pool_pump_on"):""].filter(Boolean).join(" \xB7 "),active:At,unavailable:!1,glow:null,show:"always"})}let d=new Map;for(let v of r.floors){for(let k of v.placements)k.pin_offset&&d.set(`${v.id}:${k.entity_id}`,k.pin_offset);for(let k of v.furniture)k.pin_offset&&d.set(`f:${k.id}`,k.pin_offset)}let g=v=>{let k=v.lamp?void 0:(v.furnitureId?d.get(`f:${v.furnitureId}`):void 0)??d.get(`${v.floorId}:${v.id}`);return k?{...v,x:v.x+(k.x??0),z:v.z+(k.z??0),y:v.y+(k.y??0)}:v};t.setDevices([...[...l,...c.markers].map(g).map(v=>{let k=v.show==="no_power"||"energyDevice"in v&&v.energyDevice?null:h.get(v.id)??null,K={...v,power:k,powerText:k===null?void 0:me(o,k),effect:this.dimmed?void 0:v.effect,text:this.subMeterText(o,r,u,v.furnitureId)??v.text},F=v.ownName&&(v.showName||this.markerNames)?v.ownName:"",V=m.has(v.id)||!!v.furnitureId&&m.has(v.furnitureId);return{...K,pin:this.showPin(K)&&!V,full:v.show==="always",caption:F}})]),t.setPickTargets(c.targets,this.openingTargets(),this.secondBlinds()),t.setScreens(c.screens),t.setFridgeDoors(Ba(o,r.floors)),t.setCovers(Xa(o,r)),t.setRobots(this.robotInfos(o,r));let _=new Map;for(let v of r.floors)for(let k of v.furniture)!ee(k.type)?.pet||!k.room_sensor||k.room_sensor==="none"||_.set(k.id,eo(o,v.rooms.filter(K=>K.points.length>=3),null,k.room_sensor)?.id??null);_.size&&t.setPetRooms(_),t.setRoofWindows(Tc(o,r)),t.setParked(No(o,r)),t.setGateStates(Zc(o,r));let b=new Map(r.floors.flatMap(v=>v.openings.map(k=>[k.id,k.type]))),y=new Map([...this.openingLinks].map(([v,k])=>[v,Ke(o,k,b.get(v))]));t.setOpeningStates(y),this.setAlerts(this.alertSrc?Po(o,r,this.alertSrc,this.openingLinks):[]),this.watchLostContacts(o);let $=[...l,...c.markers].map(v=>`${v.id}:${v.glow?`${v.glow.level.toFixed(1)}/${v.glow.color.map(k=>k.toFixed(1)).join("/")}`:0}`).join(";")+"|"+[...y].map(([v,k])=>`${v}:${k.open}:${k.cover===null?"-":k.cover.toFixed(1)}`).join(";");if($!==this.thumbSig){let v=this.thumbSig==="";this.thumbSig=$,v||this.scheduleThumbs(1500)}let S=cu(o,r,a,r.energy.advanced?v=>this.furnitureLinks?.get(v.id)?.power??null:void 0),A=this.liveCars(o,r);for(let v of A){if(!v.car.home||!v.car.charging&&!v.car.plugged)continue;let k=r.floors.flatMap(V=>V.furniture.filter(be=>be.type==="wallbox").map(be=>({floorId:V.id,x:be.x,z:be.z,y:1}))).sort((V,be)=>Math.hypot(V.x-v.at.x,V.z-v.at.z)-Math.hypot(be.x-v.at.x,be.z-v.at.z))[0],K=k&&k.floorId===v.at.floorId&&Math.hypot(k.x-v.at.x,k.z-v.at.z)<9,F=k??On(r);!F||!v.car.charging&&!K||S.arcs.push({key:`car:${v.spot}`,from:F,to:{...v.at,y:.8},power:v.car.charging?v.car.chargingW??7e3:0,color:[80,175,255],...K?{via:[{...F,y:.35},{floorId:v.at.floorId,x:(F.x+v.at.x)/2,z:(F.z+v.at.z)/2,y:.08},{...v.at,y:.5}],cable:!0}:{}})}let z=On(r);for(let v of this.liveHeatPumps(r)){let k=v.pump.heat??(v.pump.mode==="heating"||v.pump.mode==="water"?(v.pump.power??0)*(v.pump.cop??3):0);z&&k>100&&v.pump.mode!=="cooling"&&S.arcs.push({key:`heat:${v.id}`,from:{floorId:v.floorId,x:v.x,z:v.z,y:.8},to:z,power:k,color:[255,120,40]})}let x=(this.flows??this._flows)&&!this.dimmed;t.setLiveEnergy(x?S.arcs:[],x?S.sparks:[]),JSON.stringify(S)!==JSON.stringify(this._liveEnergy)&&(this._liveEnergy=S);let T=this.liveMedia(o,r).filter(v=>v.playing&&!this.dimmed);t.setLiveSound(T.filter(v=>v.rings>0).map(v=>({id:v.entity,at:v.at,color:v.color,level:v.volume??.5,size:v.rings})),Ec(T).map(([v,k])=>[v.at,k.at])),this.syncLhCards(t,r,S,A,T,o),t.setLiveScreens(this.dimmed?[]:Fc(o,r,this.furnitureLinks)),t.setPictures(this.framePictures(o,r)),t.setLiveWater(this.dimmed?[]:Rc(o,r,this.furnitureLinks));let R=hc(o,r);t.setPersons(R);let E=mc(o,r,this.openingLinks,R);t.setFloorInfo(new Map([...E].map(([v,k])=>[v,pc(o,k)])));let I=o.config,N=this.timeOfDay!=null&&I?.latitude!==void 0&&I.longitude!==void 0?_t(zt(this.timeOfDay,I.time_zone),I.latitude,I.longitude):Dc(o);t.setSun(N),t.setLocation(I?.latitude!==void 0&&I.longitude!==void 0?{latitude:I.latitude,longitude:I.longitude,zone:I.time_zone}:null);let G=this.weather&&!this.dimmed?Yc(o,lt(o,this.weatherEntityId??r.settings.weather_entity)):null,q=G?Jc(Qc(G,r.settings.weather_effects),this.weatherDensity):null;this.cloud=q?.cloud??0,this._sky=Hc(N?.elevation??null,this.cloud),t.setSky(this.weather&&!this.dimmed?{weather:q,sun:N,north:r.settings.north??0,sky:this.skyColor(),disc:(r.settings.weather_effects??["sky"]).includes("sky"),low:this._low}:null),this.applyTint();let oe=u.grid!==null||u.solar!==null||u.battery!==null||u.tariff!==null?u:null;JSON.stringify(oe)!==JSON.stringify(this._energy)&&(this._energy=oe)}watchLostContacts(e){let t=!!this.alertSrc&&!this._travel&&Nc(e,this.alertSrc);t&&!this.contactTimer&&(this.contactTimer=setInterval(()=>{let r=this.building;this.alertSrc&&r&&this.hass&&this.openingLinks&&!this._travel&&this.setAlerts(Po(this.hass,r,this.alertSrc,this.openingLinks))},6e4)),!t&&this.contactTimer&&(clearInterval(this.contactTimer),this.contactTimer=void 0)}setAlerts(e){let t=e.map(o=>`${o.kind}:${o.entity}`),r=e.filter((o,s)=>!this.seenAlerts.has(t[s])&&!Qr.has(o.kind));this.seenAlerts=new Set(t),t.join()!==this._alerts.map(o=>`${o.kind}:${o.entity}`).join()&&(this._alerts=e);let i=e.some(o=>!Qr.has(o.kind));i&&!this.alertTimer&&(this.alertTimer=setInterval(()=>!document.hidden&&this.applyTint(),this._low?200:100)),!i&&this.alertTimer&&(clearInterval(this.alertTimer),this.alertTimer=void 0),r.length&&this.alertJump&&this.jumpTo(r[0])}jumpTo(e){if(e.kind==="own"&&e.tap!=="room"){e.tap==="toggle"&&W(this.hass,e.entity)?this.hass.callService("homeassistant","toggle",{entity_id:e.entity}):Se(this,e.entity);return}if(!e.floorId){this.fire("floor-tap",{floorId:null});return}this.floorId!==e.floorId&&this.fire("floor-tap",{floorId:e.floorId}),e.roomId&&setTimeout(()=>this.fire("room-tap",{floorId:e.floorId,roomId:e.roomId}),60)}onRoomDoubleTap(e,t){let r=this.building,i=this.hass,o=r?.floors.find(u=>u.id===e),s=o?.rooms.find(u=>u.id===t);if(!r||!i||!o||!s)return;let a=Kc(r.settings.room_double_tap,this.roomDoubleTap),l=Gc(i,o,s,this.furnitureLinks,this.confirmSet,a).filter(u=>W(i,u));if(!l.length)return;let c=l.some(u=>i.states[u]?.state==="on");i.callService("homeassistant",c?"turn_off":"turn_on",{entity_id:l}),this.roomFlash={roomId:t,until:performance.now()+350},this.applyTint(),setTimeout(()=>{this.roomFlash=null,this.applyTint()},380)}runScene(e){W(this.hass,e)&&(this.hass.callService(e.split(".")[0],"turn_on",{entity_id:e}),this._sceneFired=e,setTimeout(()=>this._sceneFired=null,600))}applyTint(){let e=this.viewer,t=this.building,r=this.hass;if(!e||!t||!r)return;let i=null;if(this.heatMode!=="none"&&this.heatMode!=="values"&&this.heatMode!=="wifi"){let a=this.heatMode,l=nc(r,t,a);!l.size!=!this.heatValues.size&&this.requestUpdate(),this.heatValues=l;let c=xt(new Date,r.config?.latitude??50);i=new Map([...l].map(([u,h])=>[u,tc(a,h,c)]))}let o=new Map;if(this.heatMode==="values")for(let a of t.floors)for(let l of a.rooms){let c=Y(r,a,l,"temperature"),u=Y(r,a,l,"humidity"),h=Y(r,a,l,"co2"),m=Kr(h,u,jt(c,u)),d=[c!==null?`${L(r,ue(r,c),1)} ${ie(r)}`:null,u!==null?`${L(r,u,0)} %`:null,h!==null?`${L(r,h,0)} ppm`:null,m?`\u{1F4A8} ${M(r,`air_${m}`)}`:null].filter(g=>!!g);d.length&&o.set(l.id,d.join(" \xB7 "))}if(e.setRoomInfo(o),!i)for(let a of t.floors)for(let l of a.rooms){let c=l.floor_heating?r.states[l.floor_heating]:void 0;c&&(B(r)?ce(c)===!0:c.entity_id.startsWith("climate.")?c.attributes.hvac_action==="heating":c.state==="on"||c.state==="open")&&(i??=new Map).set(l.id,[.55,.24,.08])}if(this._alerts.length){i??=new Map;let a=.55+.45*Math.sin(performance.now()/160);for(let l of this._alerts){if(Qr.has(l.kind))continue;let c=Lc(l.kind).map(u=>u*a);if(l.roomId)i.set(l.roomId,c);else for(let u of t.floors)for(let h of u.rooms)i.set(h.id,c)}}this.roomFlash&&performance.now()