+ `};customElements.get("nf-utility-overview")||customElements.define("nf-utility-overview",Po);var ff=new Set(["on","home","open","true","active","playing","heat","heating"]);function Zr(r,e){let t=e.show_when;if(!t?.entity||!r)return!0;let n=r.states[t.entity];if(!n||N(n))return!0;let i=String(n.state).toLowerCase(),o=(t.state??"").split(",").map(a=>a.trim().toLowerCase()).filter(Boolean),s=o.length?o.includes(i):ff.has(i)||Number.isFinite(Number(i))&&Number(i)>0;return t.invert?!s:s}function Io(r,e){let t=[];for(let n of e.floors)for(let i of n.furniture)Zr(r,i)||t.push(i.id);return t.sort()}function dc(r,e){if(!e.length)return r;let t=new Set(e);return{...r,floors:r.floors.map(n=>n.furniture.some(i=>t.has(i.id))?{...n,furniture:n.furniture.filter(i=>!t.has(i.id))}:n)}}var hc="image:";function No(r,e,t){let n=(e??"").trim();if(!n)return null;if(n.startsWith(hc))return t(n.slice(hc.length));if(/^(https?:\/\/|\/)/.test(n))return n;if(/^[a-z_]+\.[a-z0-9_]+$/.test(n)){let i=r?.states[n]?.attributes.entity_picture;return typeof i=="string"&&i?i:null}return null}var Hn=r=>Number(r);function In(r){if(Array.isArray(r)){let[o,s]=[Hn(r[0]),Hn(r[1])];return Number.isFinite(o)&&Number.isFinite(s)?[o,s]:null}if(!r||typeof r!="object")return null;let{x:e,y:t}=r,[n,i]=[Hn(e),Hn(t)];return Number.isFinite(n)&&Number.isFinite(i)?[n,i]:null}function mc(r){return r?In(r.charger)??In(r.charger_position):null}function pc(r){for(let[e,t]of Object.entries(r.states))if(e.startsWith("camera.")&&(In(t.attributes?.vacuum_position)??mc(t.attributes)))return e;return null}var gf=r=>Array.isArray(r)?typeof r[0]=="number":!!r&&typeof r=="object",Pn=(r,e)=>e?[r[0],-r[1]]:r;function _f(r){if(!r)return null;let e=r.mirror===!0,[t,n]=Pn(r.ga,e),[i,o]=Pn(r.gb,e),[s,a]=r.a,[l,u]=r.b,[c,d]=[i-t,o-n],[m,h]=[l-s,u-a],g=Math.hypot(c,d),_=Math.hypot(m,h);if(!(g>1e-6)||!(_>1e-6))return null;let b=_/g,v=Math.atan2(h,m)-Math.atan2(d,c),[S,k]=[Math.cos(v),Math.sin(v)];return M=>{let z=Pn(M,e),[R,F]=[z[0]-t,z[1]-n];return[s+b*(R*S-F*k),a+b*(R*k+F*S)]}}function bf(r){if(!r)return null;let e=r.mirror===!0,[t,n]=Pn(r.ga,e),[i,o]=Pn(r.gb,e),s=Math.atan2(r.b[1]-r.a[1],r.b[0]-r.a[0])-Math.atan2(o-n,i-t);return Number.isFinite(s)?s:null}function fc(r,e,t){if(!e)return null;let n=r.states[e]?.attributes;if(!n)return null;let i=_f(t)??(g=>g),o=bf(t)??0,s=t?.mirror===!0?-1:1,a=n.vacuum_position,l=In(a),u=l?(()=>{let[g,_]=i(l),b=Hn(a?.a)*s;if(!Number.isFinite(b))return{x:g,z:_,heading:0};let v=b*Math.PI/180+o;return{x:g,z:_,heading:Math.atan2(Math.cos(v),Math.sin(v))}})():null,c=mc(n),d=Array.isArray(n.path)?n.path:[],m=d.length>0&&gf(d[0])?[d]:d,h=[];for(let g of m){let _=[];for(let b of Array.isArray(g)?g:[]){let v=In(b);v&&_.push(i(v))}_.length>1&&h.push(_)}return!u&&!c&&!h.length?null:{pose:u,charger:c?i(c):null,path:h}}var gc="nextfloor.lock3d",_c=520,Wo=class extends Q{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;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(gc)==="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=Et(()=>{this.pluginsDirty=!0,this.requestUpdate()}),this.hasUpdated&&(this.observeStage(),this.viewer||this.start())}disconnectedCallback(){super.disconnectedCallback(),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 n=t[0]?.contentRect,i=(n?.width??1e3)<700||(n?.height??1e3)<_c,o=(n?.height??1e3)<_c;o!==this._shortStage&&(this._shortStage=o);let s=(n?.width??1e3)<520;s!==this._phoneStage&&(this._phoneStage=s),i!==this._narrowStage&&(this._narrowStage=i,this.scheduleThumbs())}),this.resizeObs.observe(e))}async start(){if(!(this.starting||this.viewer)){this.starting=!0;try{let e=await sc();if(!this.isConnected)return;let t=this.renderRoot.querySelector(".nf-stage");t.addEventListener("pointerdown",n=>{this._central&&!this.centralOpen&&!n.target?.closest?.(".nf-central, .nf-central-btn")&&(this._central=!1)}),this.viewer=e.createViewer(t,{quality:this.quality,explode:this.explode,onRoomTap:(n,i)=>this.fire("room-tap",{floorId:n,roomId:i}),onFloorTap:n=>this.fire("floor-tap",{floorId:n}),floorInfo:n=>n.rooms.length===1?$(this.hass,"floor_rooms_one"):$(this.hass,"floor_rooms",{n:n.rooms.length}),onBack:()=>this.fire("back",{}),onDeviceTap:(n,i,o)=>this.onDeviceTap(n,i,o),onDeviceHold:(n,i,o)=>this.onDeviceHold(n,i,o),onRoomDoubleTap:(n,i)=>this.onRoomDoubleTap(n,i),onDeviceSwipe:(n,i,o,s,a)=>this.onDeviceSwipe(n,i,o,s,a),onFurnitureSelect:n=>this.fire("furniture-select",{id:n}),onFurnitureMove:(n,i,o)=>this.fire("furniture-move",{id:n,x:i,z:o}),onDeviceSelect:n=>this.fire("device-select",{id:n}),onDeviceMove:(n,i,o)=>this.fire("device-move",{id:n,x:i,z:o}),onStats:n=>{this.showStats&&(this._stats=n)}}),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(n=>this.hass?No(this.hass,n,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(n=>this.hass?.fetchWithAuth?this.hass.fetchWithAuth(`/api/nextfloor/mesh/${encodeURIComponent(n)}`).then(i=>i.ok?i.arrayBuffer():null):Promise.resolve(null)),this.viewer.setPacks([...xi()]),this.shownPacks=Zn(),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 n=this.viewer;if(!n)return;if(this.shownPacks!==Zn()&&(this.shownPacks=Zn(),n.setPacks([...xi()]),this.hass&&this.building&&n.setParked(fo(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,n.setStartView(this.startViewOf()),n.setBuilding(this.shownBuilding(this.hass)),n.setMap(this.building?.settings.map,this.building?.settings.north??0),a&&this.floorId===null&&n.resetView()}e.has("startView")&&e.get("startView")!==void 0&&(n.setStartView(this.startViewOf()),this.floorId===null&&n.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")&&n.setAutoOrbit(this.autoOrbit?.06:0),(e.has("_thumbs")||e.has("_narrowStage")||e.has("_phoneStage"))&&n.setLabelInset(this._thumbs.length&&!this._phoneStage?this.narrowThumbs?136:184:0),e.has("floorId")&&n.setFloor(this.floorId),e.has("roomId")&&(this.roomId||e.get("roomId"))&&n.selectRoom(this.roomId),e.has("outsideOpen")&&e.get("outsideOpen")!==void 0){let s=this.building?.settings.outside_view;this.outsideOpen&&s?n.showView(s):!this.outsideOpen&&s&&this.floorId===null&&!this.roomId&&n.resetView()}e.has("tapInRoom")&&n.setTapInRoom(this.tapInRoom),e.has("wallMode")&&n.setWallMode(this.wallMode),e.has("solidWalls")&&n.setPaintedWalls(this.solidWalls),e.has("glassWalls")&&n.setGlassWalls((this.glassWalls??20)/100),e.has("explode")&&n.setExplode(this.explode),e.has("keepRoof")&&n.setKeepRoof(this.keepRoof),e.has("keepCamera")&&n.setKeepCamera(!!this.keepCamera),e.has("plain")&&n.setPlain(!!this.plain),e.has("rightBack")&&n.setRightBack(!!this.rightBack),e.has("zoom")&&n.setZoom(this.zoom??1),e.has("floorStack")&&n.setFloorStack(this.floorStack),e.has("theme")&&n.setTheme(this.theme),e.has("_locked")&&n.setNavigationLocked(this._locked),e.has("accent")&&n.setAccent(this.accent??null),e.has("furnitureColors")&&n.setFurnitureColors(this.furnitureColors??null),e.has("surfaceGrab")&&n.setSurfaceGrab(this.surfaceGrab??null),e.has("furnishTypes")&&n.setFurnishTypes(this.furnishTypes??null),e.has("furnish")&&(n.setFurnishMode(this.furnish),this.syncDevices(!0)),e.has("selectedFurniture")&&n.selectFurniture(this.selectedFurniture),e.has("selectedDevice")&&n.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&&(n.setQuality(this.quality),this._low=n.low),e.has("showStats")&&n.setStats(this.showStats),e.has("building")&&(this.findIndex=null)}shownFor=null;framePictureData=new Map;framePictures(e,t){let n=[];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||!Zr(e,o))continue;let s=No(e,o.picture,a=>this.storedPicture(e,a));s&&n.push({furnitureId:o.id,floorId:i.id,url:s,border:o.picture_border??0,fit:o.picture_fit==="contain"?"contain":"cover"})}return n}storedPicture(e,t){let n=this.framePictureData.get(t);return n!==void 0?n||null:(this.framePictureData.set(t,""),gs(e,t).then(i=>{this.framePictureData.set(t,i),this.syncDevices(!0)}).catch(()=>{}),null)}shownBuilding(e){let t=this.building,n=Io(e,t),i=t.floors.filter(a=>a.layer&&this.hiddenLayers.has(a.id)).map(a=>a.id),o=[...n,...i.map(a=>`layer:${a}`)].join(",");if(this.shownFor?.building===t&&this.shownFor.key===o)return this.shownFor.shown;let s=dc(t,n);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,n=this.building;if(!t||!n||!this.hass)return;let i=this._travel,o=i&&!i.loading?Ot(this.hass,i.history,i.t):this.hass;if((e||!this.openingLinks||this.linkedRegistry!==o.entities)&&(this.openingLinks=Ne(o,n.floors),this.furnitureLinks=gt(o,n.floors),this.linkedRegistry=o.entities,this.findIndex=null,this.alertSrc=this.alerts?iu(o,n,this.weatherEntityId,this.openingLinks):null,this.watched=du({hass:o,building:n,openingLinks:this.openingLinks,furnitureLinks:this.furnitureLinks,needsRoomSensors:this.heatMode!=="none"||this.roomLabels,alertSources:this.alertSrc,weatherEntityId:this.weatherEntityId}),e=!0),!(e||this.watched.some(y=>this.shownStates.get(y)!==o.states[y])))return;Io(o,n).join(",")!==this.shownFor?.key&&t.setBuilding(this.shownBuilding(o)),this.shownStates=new Map(this.watched.map(y=>[y,o.states[y]])),this.refreshToday(n),this.refreshForecast(n);let a=bn(o,n),l=Pa(o,n.floors.some(y=>y.layer&&this.hiddenLayers.has(y.id))?this.shownBuilding(o):n);this.placementInfo=new Map(l.map(y=>[y.id,{floorId:y.floorId,roomId:y.roomId,x:y.x,z:y.z,y:y.y,rotation:y.rotation??0}]));let u=this.furnitureMarkers(o,n,new Set(l.map(y=>y.id)),new Set(a.map(y=>y.powerEntity)));a.push(...u.consumers);let c=vn(o,n,a,Ve(n,y=>this.furnitureLinks?.get(y.id)?.power??null)),d=new Map(a.filter(y=>y.id!==y.powerEntity).map(y=>[y.id,y.power]));this.confirmSet=_t(o,n.floors);let m=new Set(this.liveCardsOn?this._liveCards.flatMap(y=>y.kind==="media"?[y.media.entity]:y.kind==="car"?[y.spot]:[]):[]);for(let y of n.floors)for(let w of y.outdoor??[]){if(!w.area_id&&!w.temp_entity&&!w.pump_entity)continue;let B=w.temp_entity?o.states[w.temp_entity]:void 0,D=w.pump_entity?o.states[w.pump_entity]:void 0,[O,pe]=Ae(w.points),at=B&&Number.isFinite(Number(B.state))?`${W(o,ae(o,ar(Number(B.state),B.attributes.unit_of_measurement)),1)} ${re(o)}`:"",kt=!!D&&te(D);l.push({id:w.area_id?`outdoor:${w.id}`:w.pump_entity??w.temp_entity,floorId:y.id,roomId:null,x:O,z:pe,y:tr(y,w,O,pe)+.7,icon:Ee(w.type==="pool"?"pool":w.type==="terrace"?"table-chair":"tree-outline"),name:w.area_id&&o.areas?.[w.area_id]?.name||$(o,`out_${w.type}`),text:[at,kt?$(o,"pool_pump_on"):""].filter(Boolean).join(" \xB7 "),active:kt,unavailable:!1,glow:null,show:"always"})}let h=new Map;for(let y of n.floors){for(let w of y.placements)w.pin_offset&&h.set(`${y.id}:${w.entity_id}`,w.pin_offset);for(let w of y.furniture)w.pin_offset&&h.set(`f:${w.id}`,w.pin_offset)}let g=y=>{let w=y.lamp?void 0:(y.furnitureId?h.get(`f:${y.furnitureId}`):void 0)??h.get(`${y.floorId}:${y.id}`);return w?{...y,x:y.x+(w.x??0),z:y.z+(w.z??0),y:y.y+(w.y??0)}:y};t.setDevices([...[...l,...u.markers].map(g).map(y=>{let w=y.show==="no_power"||"energyDevice"in y&&y.energyDevice?null:d.get(y.id)??null,B={...y,power:w,powerText:w===null?void 0:ce(o,w),effect:this.dimmed?void 0:y.effect,text:this.subMeterText(o,n,c,y.furnitureId)??y.text},D=y.ownName&&(y.showName||this.markerNames)?y.ownName:"",O=m.has(y.id)||!!y.furnitureId&&m.has(y.furnitureId);return{...B,pin:this.showPin(B)&&!O,full:y.show==="always",caption:D}})]),t.setPickTargets(u.targets,this.openingTargets(),this.secondBlinds()),t.setScreens(u.screens),t.setFridgeDoors(ga(o,n.floors)),t.setCovers(Aa(o,n)),t.setRobots(this.robotInfos(o,n));let _=new Map;for(let y of n.floors)for(let w of y.furniture)!X(w.type)?.pet||!w.room_sensor||w.room_sensor==="none"||_.set(w.id,Hi(o,y.rooms.filter(B=>B.points.length>=3),null,w.room_sensor)?.id??null);_.size&&t.setPetRooms(_),t.setRoofWindows(Xl(o,n)),t.setParked(fo(o,n)),t.setGateStates(_u(o,n));let b=new Map(n.floors.flatMap(y=>y.openings.map(w=>[w.id,w.type]))),v=new Map([...this.openingLinks].map(([y,w])=>[y,Ce(o,w,b.get(y))]));t.setOpeningStates(v),this.setAlerts(this.alertSrc?ho(o,n,this.alertSrc,this.openingLinks):[]),this.watchLostContacts(o);let S=[...l,...u.markers].map(y=>`${y.id}:${y.glow?`${y.glow.level.toFixed(1)}/${y.glow.color.map(w=>w.toFixed(1)).join("/")}`:0}`).join(";")+"|"+[...v].map(([y,w])=>`${y}:${w.open}:${w.cover===null?"-":w.cover.toFixed(1)}`).join(";");if(S!==this.thumbSig){let y=this.thumbSig==="";this.thumbSig=S,y||this.scheduleThumbs(1500)}let k=Tu(o,n,a,n.energy.advanced?y=>this.furnitureLinks?.get(y.id)?.power??null:void 0),M=this.liveCars(o,n);for(let y of M){if(!y.car.home||!y.car.charging&&!y.car.plugged)continue;let w=n.floors.flatMap(O=>O.furniture.filter(pe=>pe.type==="wallbox").map(pe=>({floorId:O.id,x:pe.x,z:pe.z,y:1}))).sort((O,pe)=>Math.hypot(O.x-y.at.x,O.z-y.at.z)-Math.hypot(pe.x-y.at.x,pe.z-y.at.z))[0],B=w&&w.floorId===y.at.floorId&&Math.hypot(w.x-y.at.x,w.z-y.at.z)<9,D=w??zn(n);!D||!y.car.charging&&!B||k.arcs.push({key:`car:${y.spot}`,from:D,to:{...y.at,y:.8},power:y.car.charging?y.car.chargingW??7e3:0,color:[80,175,255],...B?{via:[{...D,y:.35},{floorId:y.at.floorId,x:(D.x+y.at.x)/2,z:(D.z+y.at.z)/2,y:.08},{...y.at,y:.5}],cable:!0}:{}})}let z=zn(n);for(let y of this.liveHeatPumps(n)){let w=y.pump.heat??(y.pump.mode==="heating"||y.pump.mode==="water"?(y.pump.power??0)*(y.pump.cop??3):0);z&&w>100&&y.pump.mode!=="cooling"&&k.arcs.push({key:`heat:${y.id}`,from:{floorId:y.floorId,x:y.x,z:y.z,y:.8},to:z,power:w,color:[255,120,40]})}let R=(this.flows??this._flows)&&!this.dimmed;t.setLiveEnergy(R?k.arcs:[],R?k.sparks:[]),JSON.stringify(k)!==JSON.stringify(this._liveEnergy)&&(this._liveEnergy=k);let T=this.liveMedia(o,n).filter(y=>y.playing&&!this.dimmed);t.setLiveSound(T.filter(y=>y.rings>0).map(y=>({id:y.entity,at:y.at,color:y.color,level:y.volume??.5,size:y.rings})),Yl(T).map(([y,w])=>[y.at,w.at])),this.syncLhCards(t,n,k,M,T,o),t.setLiveScreens(this.dimmed?[]:eu(o,n,this.furnitureLinks)),t.setPictures(this.framePictures(o,n)),t.setLiveWater(this.dimmed?[]:Jl(o,n,this.furnitureLinks));let E=Cl(o,n);t.setPersons(E);let A=Wl(o,n,this.openingLinks,E);t.setFloorInfo(new Map([...A].map(([y,w])=>[y,Ll(o,w)])));let P=o.config,C=this.timeOfDay!=null&&P?.latitude!==void 0&&P.longitude!==void 0?mt(Mt(this.timeOfDay,P.time_zone),P.latitude,P.longitude):tu(o);t.setSun(C),t.setLocation(P?.latitude!==void 0&&P.longitude!==void 0?{latitude:P.latitude,longitude:P.longitude,zone:P.time_zone}:null);let V=this.weather&&!this.dimmed?bu(o,ot(o,this.weatherEntityId??n.settings.weather_entity)):null,j=V?vu(yu(V,n.settings.weather_effects),this.weatherDensity):null;this.cloud=j?.cloud??0,this._sky=nu(C?.elevation??null,this.cloud),t.setSky(this.weather&&!this.dimmed?{weather:j,sun:C,north:n.settings.north??0,sky:this.skyColor(),disc:(n.settings.weather_effects??["sky"]).includes("sky"),low:this._low}:null),this.applyTint();let ie=c.grid!==null||c.solar!==null||c.battery!==null||c.tariff!==null?c:null;JSON.stringify(ie)!==JSON.stringify(this._energy)&&(this._energy=ie)}watchLostContacts(e){let t=!!this.alertSrc&&!this._travel&&su(e,this.alertSrc);t&&!this.contactTimer&&(this.contactTimer=setInterval(()=>{let n=this.building;this.alertSrc&&n&&this.hass&&this.openingLinks&&!this._travel&&this.setAlerts(ho(this.hass,n,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}`),n=e.filter((o,s)=>!this.seenAlerts.has(t[s])&&!Hr.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=>!Hr.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),n.length&&this.alertJump&&this.jumpTo(n[0])}jumpTo(e){if(e.kind==="own"&&e.tap!=="room"){e.tap==="toggle"?this.hass.callService("homeassistant","toggle",{entity_id:e.entity}):ye(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 n=this.building,i=this.hass,o=n?.floors.find(c=>c.id===e),s=o?.rooms.find(c=>c.id===t);if(!n||!i||!o||!s)return;let a=hu(n.settings.room_double_tap,this.roomDoubleTap),l=mu(i,o,s,this.furnitureLinks,this.confirmSet,a);if(!l.length)return;let u=l.some(c=>i.states[c]?.state==="on");i.callService("homeassistant",u?"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){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,n=this.hass;if(!e||!t||!n)return;let i=null;if(this.heatMode!=="none"&&this.heatMode!=="values"&&this.heatMode!=="wifi"){let a=this.heatMode,l=El(n,t,a);!l.size!=!this.heatValues.size&&this.requestUpdate(),this.heatValues=l;let u=bt(new Date,n.config?.latitude??50);i=new Map([...l].map(([c,d])=>[c,Al(a,d,u)]))}let o=new Map;if(this.heatMode==="values")for(let a of t.floors)for(let l of a.rooms){let u=q(n,a,l,"temperature"),c=q(n,a,l,"humidity"),d=q(n,a,l,"co2"),m=Ar(d,c,Lt(u,c)),h=[u!==null?`${W(n,ae(n,u),1)} ${re(n)}`:null,c!==null?`${W(n,c,0)} %`:null,d!==null?`${W(n,d,0)} ppm`:null,m?`\u{1F4A8} ${$(n,`air_${m}`)}`:null].filter(g=>!!g);h.length&&o.set(l.id,h.join(" \xB7 "))}if(e.setRoomInfo(o),!i)for(let a of t.floors)for(let l of a.rooms){let u=l.floor_heating?n.states[l.floor_heating]:void 0;u&&(K(n)?se(u)===!0:u.entity_id.startsWith("climate.")?u.attributes.hvac_action==="heating":u.state==="on"||u.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(Hr.has(l.kind))continue;let u=au(l.kind).map(c=>c*a);if(l.roomId)i.set(l.roomId,u);else for(let c of t.floors)for(let d of c.rooms)i.set(d.id,u)}}this.roomFlash&&performance.now()
`${a}:${l.map(u=>u.toFixed(2)).join(",")}`).join(";"):"";s!==this.tintSig&&(this.tintSig=s,e.setRoomTint(i))}furnitureMarkers(e,t,n,i){let o=[],s=[],a=new Map,l=new Map,u=_n(t);for(let m of t.floors)if(!(m.layer&&this.hiddenLayers.has(m.id)))for(let h of m.furniture){if(!Zr(e,h))continue;let g=this.furnitureLinks.get(h.id),_=this.stateFaces(e,h);_.length&&a.set(h.id,{color:_[0].color,level:_[0].level,faces:_});let b=Jn(h.type);if(b&&h.care_entity){let w=this.careMarker(e,m,h,b,h.care_entity);w&&(o.push(w.marker),w.glow&&a.set(h.id,{color:w.glow,level:.9,faces:[{part:"all",color:w.glow,level:.9}]}),l.set(h.id,h.care_entity));continue}let v=X(h.type);if(h.cover_entity&&Yn(v)&&l.set(h.id,h.cover_entity),v?.gangs){for(let B of(h.gang_entities??[]).slice(0,v.gangs)){let D=B&&B!=="none"?Ke(e,B):null,O=D?J(e.states[D]):null;D&&O!==null&&!i.has(D)&&(i.add(D),s.push({id:B,powerEntity:D,floorId:m.id,x:h.x,z:h.z,power:Math.max(0,O)}))}let w=ka(e,(h.gang_entities??[]).slice(0,v.gangs),/socket/.test(h.type));w.length&&a.set(h.id,{color:w[0].color,level:w[0].level,gangs:w}),Ni(h.gang_entities,v.gangs).length&&l.set(h.id,`gang:${h.id}`);continue}if(rr(h.type)){let w=this.lampMarker(e,m,h,g?.entity??null),B=g?.power?J(e.states[g.power]):null;if(g?.power&&B!==null&&(B>=1&&(w.text=w.text?`${w.text} \xB7 ${vt(e,B)}`:vt(e,B)),i.has(g.power)||(i.add(g.power),s.push({id:w.id,powerEntity:g.power,floorId:m.id,x:h.x,z:h.z,power:Math.max(0,B)}))),o.push(w),h.type==="ceiling_fan"){let D=g?.fan?e.states[g.fan]:void 0;w.spin=ac(D),D&&!n.has(D.entity_id)&&(n.add(D.entity_id),o.push({...w,id:D.entity_id,y:Math.max(.5,w.y-.3),icon:h.icon?Ee(h.icon):Pt("fan"),name:h.name||L(e,D.entity_id),text:yf(e,D),active:te(D),unavailable:N(D),glow:null,lamp:null,spin:void 0,pickable:void 0,effect:void 0}))}continue}let S=Fi(h.type)?ma(e,h,w=>`${W(e,ae(e,w),1)} ${re(e)}`):null,k=Fi(h.type)?null:fa(e,h.temp_entity),M=k===null?"":`\u{1F321} ${W(e,ae(e,k),1)} ${re(e)}`,z=h.type==="home_battery"?h.soc:h.type==="wallbox"?h.status:S?h.temp_entity&&h.temp_entity!=="none"?h.temp_entity:h.temp_entity2:k!==null?h.temp_entity:null,R=z&&z!=="none"?z:(h.values??[]).find(w=>w.entity&&w.entity!=="none")?.entity??null,F=g??(R?{entity:null,power:null}:void 0);if(!F)continue;let T=h.type==="home_battery"?R??F.entity??F.power:F.entity??F.power??R;l.set(h.id,T);let E=F.entity?e.states[F.entity]:void 0,A=u.has(h.id),P=A?!!h.meter_invert:h.type==="meter"?t.energy.grid_invert&&!h.export:h.type==="home_battery"?t.energy.battery_invert&&!h.charge:!1,C=F.power?J(e.states[F.power],P):null,V=h.type==="home_battery"&&h.charge&&h.charge!=="none"?h.charge:h.type==="meter"&&!A&&h.export&&h.export!=="none"?h.export:null,j=V?J(e.states[V]):null;j!==null&&(C=Math.max(0,C??0)-Math.max(0,j)),F.power&&C!==null&&!i.has(F.power)&&(i.add(F.power),s.push({id:T,powerEntity:F.power,floorId:m.id,x:h.x,z:h.z,power:Math.max(0,C),wallbox:h.type==="wallbox"||void 0}));let Z=(C??0)>10||E?.state==="on"||E?.state==="running"||sr(E)&&te(E);if((h.type==="radiator"||v)&&E&&H(E.entity_id)==="climate"){let w=E.attributes;if(w.hvac_action==="heating"){let B=typeof w.temperature=="number"&&typeof w.current_temperature=="number"?w.temperature-w.current_temperature:1,D=!!v&&!v.parts.some(O=>O.screen);a.set(h.id,{color:[1,.42,.1],level:Math.min(1,.45+.25*Math.max(0,B)),heat:D||void 0})}}else(h.type==="washer"||h.type==="dryer"||h.type==="dishwasher")&&Z?a.set(h.id,{color:[.3,.85,1],level:.8}):v&&Z&&!v.light&&v.parts.some(w=>w.glow||w.screen)&&a.set(h.id,{color:[.3,.85,1],level:.8,leds:!0});if(Eo(h.type)){let w=Ao(e,F.entity??F.power);if(w&&w.progress!==null&&(w.printing||/pause/.test(w.status))){let B=w.filaments[0]??"#38bdf8",D=[1,3,5].map(O=>parseInt(B.slice(O,O+2),16)/255);a.set(h.id,{color:D,level:.9,print:Math.max(.02,w.progress/100)})}}if(h.type==="home_battery"&&R){let w=Number(e.states[R]?.state);Number.isFinite(w)&&a.set(h.id,{color:w>60?[.29,.87,.5]:w>25?[.98,.8,.08]:[.97,.44,.44],level:.95,fill:w/100})}if(E&&hr(h.type)){let w=H(E.entity_id)==="light"?Ie(E):null,B=H(E.entity_id)==="media"&&["playing","on","paused","idle"].includes(E.state),D=w?w.color:te(E)||B?[.22,.88,1]:null;D&&a.set(h.id,{color:D,level:E.state==="playing"?1:.6,halo:h.ambilight??1})}if(n.has(T))continue;n.add(T);let ie=F.entity?H(F.entity):null,y=m.rooms.find(w=>w.points.length>=3&&I([h.x,h.z],w.points));o.push({id:T,floorId:m.id,roomId:y?.id??null,x:h.x,z:h.z,y:Co(h)+he(m,h),icon:h.icon?Ee(h.icon):Pt(ie??"switch"),name:h.name||(F.entity?L(e,F.entity):_e(e,h.type)),ownName:h.name||void 0,showName:!!h.show_name,text:[S?S.text:h.type==="home_battery"?this.batteryText(e,R,C):h.type==="wallbox"?this.wallboxText(e,R,C):h.type==="meter"?A?C===null?"":ce(e,C):this.meterText(e,C):E&&(h.type==="washer"||h.type==="dryer"||h.type==="dishwasher")&&Z&&Wi(e,dn(e,F.entity??F.power))!==null?$(e,"care_time_left",{time:Ma(Wi(e,dn(e,F.entity??F.power)))}):E?[oe(e,E),C!==null&&C>5&&!sr(E)?ce(e,C):""].filter(Boolean).join(" \xB7 "):C!==null?ce(e,Math.max(0,C)):"",M,hn(e,h.values)].filter(Boolean).join(" \xB7 "),active:S?.warm||k!==null&&k>=pa||(E?te(E):(C??0)>5),unavailable:E?N(E):!1,glow:null,furnitureId:h.id,energyDevice:h.type==="inverter"||h.type==="home_battery"||h.type==="wallbox"||h.type==="meter",readout:!!S||!!h.values?.some(w=>w.entity&&w.entity!=="none")||void 0,show:h.marker??void 0,fromFurniture:!0})}let c=this.heatMode==="wifi";for(let m of o){let h=m.furnitureId?t.floors.flatMap(_=>_.furniture).find(_=>_.id===m.furnitureId):void 0;if(!h||!Ro(h.type))continue;let g=zo(e,this.furnitureLinks.get(h.id)?.entity??this.furnitureLinks.get(h.id)?.power??null);g&&(g.clients!==null&&(m.text=$(e,"wifi_clients",{n:g.clients})),c&&(m.wedge={angle:360,reach:9,near:0,color:Uu(g),opacity:.4,through:!0,walls:!1},m.show="always"))}let d=pu(t,o);this.tapPins=d.pins;for(let m of t.floors.flatMap(h=>h.furniture))m.tap?.action&&l.set(m.id,`tap:${m.id}`);for(let{floor:m,item:h}of d.bare){let g=m.rooms.find(b=>b.points.length>=3&&I([h.x,h.z],b.points)),_=h.name||_e(e,h.type);o.push({id:`tap:${h.id}`,floorId:m.id,roomId:g?.id??null,x:h.x,z:h.z,y:Co(h)+he(m,h),icon:Ee(h.icon||"gesture-tap-button"),name:_,ownName:h.name||void 0,showName:!!h.show_name,text:"",active:!1,unavailable:!1,glow:null,furnitureId:h.id,show:h.marker??void 0,fromFurniture:!0})}return{markers:o,consumers:s,screens:a,targets:l}}robotObstacles(e,t){let n=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(n.has(i.type)||i.type.startsWith("lamp_")&&i.type!=="lamp_floor"&&i.type!=="lamp_uplight"||i.h<.04||he(e,i)>.12)return!1;let o=X(i.type);return o&&(o.hole||/table|desk|chair|stool|bench|rug|carpet|mat$/.test(i.type))?!1:I([i.x,i.z],t)||ir(i).some(s=>I(s,t))}).map(i=>ir(i))}robotInfos(e,t){let n=[],i=pc(e),o=fc(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 u=this.furnitureLinks.get(l.id)?.entity??null,c=u?e.states[u]?.state:void 0,d=c==="cleaning"?"cleaning":c==="returning"?"returning":c==="error"?"error":c==="docked"||!c?"docked":"idle",m=l.rotation*Math.PI/180,h=l.d*.14,g=[l.x-Math.sin(m)*h,l.z+Math.cos(m)*h],_=a.rooms.filter(T=>T.points.length>=3),v=(d==="cleaning"?Hi(e,_,u,mr(e,u,l.room_sensor)):null)??_.find(T=>I(g,T.points)),S=d==="cleaning"&&v?this.robotObstacles(a,v.points):[],k=i?Date.parse(e.states[i]?.last_updated??""):Number.NaN,M=!Number.isFinite(k)||Date.now()-k<120*1e3,z=u?.startsWith("vacuum.")&&o&&!s&&(M||d!=="cleaning"&&d!=="returning")?o:null;z&&(s=!0);let R=u?Date.parse(e.states[u]?.last_changed??""):Number.NaN,F=d==="cleaning"||d==="returning"?null:Number.isFinite(R)?R:null;n.push({id:l.id,floorId:a.id,rest:g,restHeading:-m,mode:d,room:v?.points??null,roomId:v?.id??null,obstacles:S,track:z?.path??null,pose:z?.pose??null,settledAt:F})}for(let l of a.furniture){if(!/:(robot_mower|mower_dock)$/.test(l.type))continue;let u=this.furnitureLinks.get(l.id)?.entity??null;if(!u?.startsWith("lawn_mower."))continue;let c=e.states[u]?.state,d=c==="mowing"?"cleaning":c==="returning"?"returning":c==="error"?"error":c==="docked"||!c?"docked":"idle",m=[l.x,l.z],h=(a.outdoor??[]).filter(b=>b.type==="lawn"&&b.points.length>=3),g=h.find(b=>I(m,b.points))??[...h].sort((b,v)=>sn(v.points)-sn(b.points))[0],_=g?(a.outdoor??[]).filter(b=>b!==g&&b.type!=="lawn"&&b.points.some(v=>I(v,g.points))).map(b=>b.points):[];n.push({id:l.id,floorId:a.id,rest:m,restHeading:-l.rotation*Math.PI/180,mode:d,room:g?.points??null,roomId:g?.id??null,obstacles:_,y:g?tr(a,g,m[0],m[1]):nr(a),mower:!0})}}return n}batteryText(e,t,n){let i=t?Number(e.states[t]?.state):Number.NaN,o=[];return Number.isFinite(i)&&o.push(`${W(e,i,0)} %`),n!==null&&Math.abs(n)>=10&&o.push(`${n<0?"\u25B2":"\u25BC"} ${ce(e,Math.abs(n))}`),o.join(" \xB7 ")}subMeterText(e,t,n,i){let o=i?fl(t,n,i):null;return o?ce(e,o.use)+(o.unmetered===null?"":` \xB7 ${$(e,"meter_unmetered",{w:ce(e,o.unmetered)})}`):null}meterText(e,t){return t===null?"":Math.abs(t)<5?ce(e,0):`${$(e,t<0?"energy_grid_export":"energy_grid_import")} ${ce(e,Math.abs(t))}`}wallboxText(e,t,n){let i=t?e.states[t]:void 0,o=String(i?.state??"").toLowerCase(),s=(n??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?$(e,"wallbox_charging"):a?$(e,"wallbox_plugged"):i&&!N(i)&&!i.entity_id.startsWith("binary_sensor.")?oe(e,i):"",u=n!==null&&n>50?ce(e,n):"";return[l,u].filter(Boolean).join(" \xB7 ")}stateFaces(e,t){let n=[],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||N(a)||!(te(a)||a.state==="home"||a.state==="occupied"||a.state==="on"))continue;let u=H(o)==="light"?Ie(a):null;n.push({part:s,color:u?u.color:[1,.71,.28],level:u?u.level:.85})}return n}careMarker(e,t,n,i,o){let s=e.states[o];if(!s)return null;let a="",l=!1,u=null;if(i==="bin"){let m=pr(s);a=m===null?oe(e,s):m===0?$(e,"care_bin_today"):m===1?$(e,"care_bin_tomorrow"):$(e,"care_bin_days",{n:m}),l=m!==null&&m<=1,l&&(u=[1,.72,.28])}else if(i==="mail")l=Sa(s),a=$(e,l?"care_mail_yes":"care_mail_no"),l&&(u=[1,.85,.3]);else{let m=$a(s,n.thirsty_below??20);l=!!m?.thirsty,a=m?Number.isFinite(m.moisture)?`${$(e,l?"care_plant_thirsty":"care_plant_ok")} \xB7 ${Math.round(m.moisture)} %`:$(e,l?"care_plant_thirsty":"care_plant_ok"):oe(e,s),l&&(u=[1,.45,.3])}let c=t.rooms.find(m=>m.points.length>=3&&I([n.x,n.z],m.points)),d={bin:"mdi:trash-can-outline",mail:"mdi:mailbox-outline",plant:"mdi:sprout-outline"}[i];return{glow:u,marker:{id:o,floorId:t.id,roomId:c?.id??null,x:n.x,z:n.z,y:Co(n)+he(t,n),icon:n.icon?Ee(n.icon):Ee(d),name:n.name||_e(e,n.type),ownName:n.name||void 0,showName:!!n.show_name,text:a,active:l,unavailable:N(s),glow:null,furnitureId:n.id,show:n.marker??void 0,fromFurniture:!0,care:!0}}}lampMarker(e,t,n,i){let o=i?e.states[i]:void 0,s=(n.extra_lights??[]).map(b=>e.states[b]).filter(b=>!!b),a=s.find(b=>te(b)),l=X(n.type),u=Gs[n.type]??l?.light??"floor",c=t.rooms.some(b=>b.points.length>=3&&I([n.x,n.z],b.points)),d=u==="strip"&&!c?on(t,n.x,n.z)+(n.mount_y??0):n.mount_y!=null&&!l?n.mount_y:l||u==="wall"||u==="strip"?he(t,n):u==="table"?er(t,n.x,n.z):u==="bollard"||u==="garden"?on(t,n.x,n.z):0,m=t.rooms.find(b=>b.points.length>=3&&I([n.x,n.z],b.points)),h=Xn(t,n),g=l?l.mount==="ceiling"?Math.max(.5,d-.15):d+n.h+.2:{ceiling:h-.3,downlight:h-.25,spot:h-.35,panel:h-.25,pendant:Math.max(.6,h-n.h-.25),fan:Math.max(.6,h-n.h-.2),floor:d+n.h+.25,uplight:d+n.h+.25,table:d+n.h+.2,wall:d+n.h+.2,strip:n.upright?d+n.w+.15:Math.max(.3,d-.2),bollard:d+n.h+.25,garden:d+n.h+.25}[u],_={id:i??`lamp:${n.id}`,floorId:t.id,roomId:m?.id??null,x:n.x,z:n.z,y:g,icon:Pt("light"),name:n.name||(i?L(e,i):_e(e,n.type)),text:[o&&(te(o)||!a)?oe(e,o):a?L(e,a.entity_id):"",hn(e,n.values)].filter(Boolean).join(" \xB7 "),readout:!!n.values?.some(b=>b.entity&&b.entity!=="none"),active:(o?te(o):!1)||!!a,unavailable:o?N(o):!1,glow:o||s.length?Vi(Qs(o,s,n.color_entity&&n.color_entity!=="none"?e.states[n.color_entity]:void 0),n.glow_scale):null,lamp:u,rotation:n.rotation,mirror:!!n.mirror,roll:n.tilt??0,upright:!!n.upright,rise:n.rise??0,size:[n.w,n.d,n.h],base:d,pickable:!!i,furnitureId:n.id,pack:l?n.type:null,lightY:l?l.mount==="ceiling"?d:d+n.h*.85:void 0,ceiling:h,effect:o?.state==="on"?wr(n,Fa(e,n,i)):void 0,variant:n.variant,show:n.marker??void 0,fromFurniture:!0};return o&&i?Ki(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&&Ys(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(js(e.id,!!e.lamp));if(this.markerMode==="all")return!0;if(e.lamp)return!1;let t=H(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,n]of this.openingLinks??[]){let i=n.lock??n.cover??n.contact??n.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"})),n=document.createElement("a");n.href=t,n.download=`nextfloor-${new Date().toISOString().slice(0,10)}.stl`,n.click(),setTimeout(()=>URL.revokeObjectURL(t),5e3)}secondBlinds(){let e=new Map;for(let[t,n]of this.openingLinks??[])n.cover2&&!n.lock&&n.cover&&e.set(t,n.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 n=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)}},n)}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)),n=this._thumbsCompact,i=()=>{this._thumbsCompact=!n;try{localStorage.setItem("nextfloor.thumbs_compact",this._thumbsCompact?"1":"0")}catch{}};return p` `}syncDevices(e){let t=this.viewer,n=this.building;if(!t||!n||!this.hass)return;let i=this._travel,o=i&&!i.loading?Lt(this.hass,i.history,i.t):this.hass;if((e||!this.openingLinks||this.linkedRegistry!==o.entities)&&(this.openingLinks=Ne(o,n.floors),this.furnitureLinks=gt(o,n.floors),this.linkedRegistry=o.entities,this.findIndex=null,this.alertSrc=this.alerts?iu(o,n,this.weatherEntityId,this.openingLinks):null,this.watched=du({hass:o,building:n,openingLinks:this.openingLinks,furnitureLinks:this.furnitureLinks,needsRoomSensors:this.heatMode!=="none"||this.roomLabels,alertSources:this.alertSrc,weatherEntityId:this.weatherEntityId}),e=!0),!(e||this.watched.some(y=>this.shownStates.get(y)!==o.states[y])))return;Io(o,n).join(",")!==this.shownFor?.key&&t.setBuilding(this.shownBuilding(o)),this.shownStates=new Map(this.watched.map(y=>[y,o.states[y]])),this.refreshToday(n),this.refreshForecast(n);let a=bn(o,n),l=Pa(o,n.floors.some(y=>y.layer&&this.hiddenLayers.has(y.id))?this.shownBuilding(o):n);this.placementInfo=new Map(l.map(y=>[y.id,{floorId:y.floorId,roomId:y.roomId,x:y.x,z:y.z,y:y.y,rotation:y.rotation??0}]));let u=this.furnitureMarkers(o,n,new Set(l.map(y=>y.id)),new Set(a.map(y=>y.powerEntity)));a.push(...u.consumers);let c=vn(o,n,a,Ve(n,y=>this.furnitureLinks?.get(y.id)?.power??null)),d=new Map(a.filter(y=>y.id!==y.powerEntity).map(y=>[y.id,y.power]));this.confirmSet=_t(o,n.floors);let m=new Set(this.liveCardsOn?this._liveCards.flatMap(y=>y.kind==="media"?[y.media.entity]:y.kind==="car"?[y.spot]:[]):[]);for(let y of n.floors)for(let w of y.outdoor??[]){if(!w.area_id&&!w.temp_entity&&!w.pump_entity)continue;let B=w.temp_entity?o.states[w.temp_entity]:void 0,D=w.pump_entity?o.states[w.pump_entity]:void 0,[L,pe]=Ae(w.points),at=B&&Number.isFinite(Number(B.state))?`${W(o,ae(o,ar(Number(B.state),B.attributes.unit_of_measurement)),1)} ${re(o)}`:"",kt=!!D&&te(D);l.push({id:w.area_id?`outdoor:${w.id}`:w.pump_entity??w.temp_entity,floorId:y.id,roomId:null,x:L,z:pe,y:tr(y,w,L,pe)+.7,icon:Ee(w.type==="pool"?"pool":w.type==="terrace"?"table-chair":"tree-outline"),name:w.area_id&&o.areas?.[w.area_id]?.name||$(o,`out_${w.type}`),text:[at,kt?$(o,"pool_pump_on"):""].filter(Boolean).join(" \xB7 "),active:kt,unavailable:!1,glow:null,show:"always"})}let h=new Map;for(let y of n.floors){for(let w of y.placements)w.pin_offset&&h.set(`${y.id}:${w.entity_id}`,w.pin_offset);for(let w of y.furniture)w.pin_offset&&h.set(`f:${w.id}`,w.pin_offset)}let g=y=>{let w=y.lamp?void 0:(y.furnitureId?h.get(`f:${y.furnitureId}`):void 0)??h.get(`${y.floorId}:${y.id}`);return w?{...y,x:y.x+(w.x??0),z:y.z+(w.z??0),y:y.y+(w.y??0)}:y};t.setDevices([...[...l,...u.markers].map(g).map(y=>{let w=y.show==="no_power"||"energyDevice"in y&&y.energyDevice?null:d.get(y.id)??null,B={...y,power:w,powerText:w===null?void 0:ce(o,w),effect:this.dimmed?void 0:y.effect,text:this.subMeterText(o,n,c,y.furnitureId)??y.text},D=y.ownName&&(y.showName||this.markerNames)?y.ownName:"",L=m.has(y.id)||!!y.furnitureId&&m.has(y.furnitureId);return{...B,pin:this.showPin(B)&&!L,full:y.show==="always",caption:D}})]),t.setPickTargets(u.targets,this.openingTargets(),this.secondBlinds()),t.setScreens(u.screens),t.setFridgeDoors(ga(o,n.floors)),t.setCovers(Aa(o,n)),t.setRobots(this.robotInfos(o,n));let _=new Map;for(let y of n.floors)for(let w of y.furniture)!X(w.type)?.pet||!w.room_sensor||w.room_sensor==="none"||_.set(w.id,Hi(o,y.rooms.filter(B=>B.points.length>=3),null,w.room_sensor)?.id??null);_.size&&t.setPetRooms(_),t.setRoofWindows(Xl(o,n)),t.setParked(fo(o,n)),t.setGateStates(_u(o,n));let b=new Map(n.floors.flatMap(y=>y.openings.map(w=>[w.id,w.type]))),v=new Map([...this.openingLinks].map(([y,w])=>[y,Ce(o,w,b.get(y))]));t.setOpeningStates(v),this.setAlerts(this.alertSrc?ho(o,n,this.alertSrc,this.openingLinks):[]),this.watchLostContacts(o);let S=[...l,...u.markers].map(y=>`${y.id}:${y.glow?`${y.glow.level.toFixed(1)}/${y.glow.color.map(w=>w.toFixed(1)).join("/")}`:0}`).join(";")+"|"+[...v].map(([y,w])=>`${y}:${w.open}:${w.cover===null?"-":w.cover.toFixed(1)}`).join(";");if(S!==this.thumbSig){let y=this.thumbSig==="";this.thumbSig=S,y||this.scheduleThumbs(1500)}let k=Tu(o,n,a,n.energy.advanced?y=>this.furnitureLinks?.get(y.id)?.power??null:void 0),M=this.liveCars(o,n);for(let y of M){if(!y.car.home||!y.car.charging&&!y.car.plugged)continue;let w=n.floors.flatMap(L=>L.furniture.filter(pe=>pe.type==="wallbox").map(pe=>({floorId:L.id,x:pe.x,z:pe.z,y:1}))).sort((L,pe)=>Math.hypot(L.x-y.at.x,L.z-y.at.z)-Math.hypot(pe.x-y.at.x,pe.z-y.at.z))[0],B=w&&w.floorId===y.at.floorId&&Math.hypot(w.x-y.at.x,w.z-y.at.z)<9,D=w??zn(n);!D||!y.car.charging&&!B||k.arcs.push({key:`car:${y.spot}`,from:D,to:{...y.at,y:.8},power:y.car.charging?y.car.chargingW??7e3:0,color:[80,175,255],...B?{via:[{...D,y:.35},{floorId:y.at.floorId,x:(D.x+y.at.x)/2,z:(D.z+y.at.z)/2,y:.08},{...y.at,y:.5}],cable:!0}:{}})}let z=zn(n);for(let y of this.liveHeatPumps(n)){let w=y.pump.heat??(y.pump.mode==="heating"||y.pump.mode==="water"?(y.pump.power??0)*(y.pump.cop??3):0);z&&w>100&&y.pump.mode!=="cooling"&&k.arcs.push({key:`heat:${y.id}`,from:{floorId:y.floorId,x:y.x,z:y.z,y:.8},to:z,power:w,color:[255,120,40]})}let R=(this.flows??this._flows)&&!this.dimmed;t.setLiveEnergy(R?k.arcs:[],R?k.sparks:[]),JSON.stringify(k)!==JSON.stringify(this._liveEnergy)&&(this._liveEnergy=k);let T=this.liveMedia(o,n).filter(y=>y.playing&&!this.dimmed);t.setLiveSound(T.filter(y=>y.rings>0).map(y=>({id:y.entity,at:y.at,color:y.color,level:y.volume??.5,size:y.rings})),Yl(T).map(([y,w])=>[y.at,w.at])),this.syncLhCards(t,n,k,M,T,o),t.setLiveScreens(this.dimmed?[]:eu(o,n,this.furnitureLinks)),t.setPictures(this.framePictures(o,n)),t.setLiveWater(this.dimmed?[]:Jl(o,n,this.furnitureLinks));let E=Cl(o,n);t.setPersons(E);let A=Wl(o,n,this.openingLinks,E);t.setFloorInfo(new Map([...A].map(([y,w])=>[y,Ol(o,w)])));let P=o.config,C=this.timeOfDay!=null&&P?.latitude!==void 0&&P.longitude!==void 0?mt(Mt(this.timeOfDay,P.time_zone),P.latitude,P.longitude):tu(o);t.setSun(C),t.setLocation(P?.latitude!==void 0&&P.longitude!==void 0?{latitude:P.latitude,longitude:P.longitude,zone:P.time_zone}:null);let V=this.weather&&!this.dimmed?bu(o,ot(o,this.weatherEntityId??n.settings.weather_entity)):null,j=V?vu(yu(V,n.settings.weather_effects),this.weatherDensity):null;this.cloud=j?.cloud??0,this._sky=nu(C?.elevation??null,this.cloud),t.setSky(this.weather&&!this.dimmed?{weather:j,sun:C,north:n.settings.north??0,sky:this.skyColor(),disc:(n.settings.weather_effects??["sky"]).includes("sky"),low:this._low}:null),this.applyTint();let ie=c.grid!==null||c.solar!==null||c.battery!==null||c.tariff!==null?c:null;JSON.stringify(ie)!==JSON.stringify(this._energy)&&(this._energy=ie)}watchLostContacts(e){let t=!!this.alertSrc&&!this._travel&&su(e,this.alertSrc);t&&!this.contactTimer&&(this.contactTimer=setInterval(()=>{let n=this.building;this.alertSrc&&n&&this.hass&&this.openingLinks&&!this._travel&&this.setAlerts(ho(this.hass,n,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}`),n=e.filter((o,s)=>!this.seenAlerts.has(t[s])&&!Hr.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=>!Hr.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),n.length&&this.alertJump&&this.jumpTo(n[0])}jumpTo(e){if(e.kind==="own"&&e.tap!=="room"){e.tap==="toggle"?this.hass.callService("homeassistant","toggle",{entity_id:e.entity}):ye(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 n=this.building,i=this.hass,o=n?.floors.find(c=>c.id===e),s=o?.rooms.find(c=>c.id===t);if(!n||!i||!o||!s)return;let a=hu(n.settings.room_double_tap,this.roomDoubleTap),l=mu(i,o,s,this.furnitureLinks,this.confirmSet,a);if(!l.length)return;let u=l.some(c=>i.states[c]?.state==="on");i.callService("homeassistant",u?"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){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,n=this.hass;if(!e||!t||!n)return;let i=null;if(this.heatMode!=="none"&&this.heatMode!=="values"&&this.heatMode!=="wifi"){let a=this.heatMode,l=El(n,t,a);!l.size!=!this.heatValues.size&&this.requestUpdate(),this.heatValues=l;let u=bt(new Date,n.config?.latitude??50);i=new Map([...l].map(([c,d])=>[c,Al(a,d,u)]))}let o=new Map;if(this.heatMode==="values")for(let a of t.floors)for(let l of a.rooms){let u=q(n,a,l,"temperature"),c=q(n,a,l,"humidity"),d=q(n,a,l,"co2"),m=Ar(d,c,Ot(u,c)),h=[u!==null?`${W(n,ae(n,u),1)} ${re(n)}`:null,c!==null?`${W(n,c,0)} %`:null,d!==null?`${W(n,d,0)} ppm`:null,m?`\u{1F4A8} ${$(n,`air_${m}`)}`:null].filter(g=>!!g);h.length&&o.set(l.id,h.join(" \xB7 "))}if(e.setRoomInfo(o),!i)for(let a of t.floors)for(let l of a.rooms){let u=l.floor_heating?n.states[l.floor_heating]:void 0;u&&(K(n)?se(u)===!0:u.entity_id.startsWith("climate.")?u.attributes.hvac_action==="heating":u.state==="on"||u.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(Hr.has(l.kind))continue;let u=au(l.kind).map(c=>c*a);if(l.roomId)i.set(l.roomId,u);else for(let c of t.floors)for(let d of c.rooms)i.set(d.id,u)}}this.roomFlash&&performance.now()