UNPKG

iobroker.lovelace

Version:

With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI

1 lines 10.8 kB
export const __rspack_esm_id=21742;export const __rspack_esm_ids=[21742];export const __webpack_modules__={90433(t,i,e){e.d(i,{Vy:()=>r,fI:()=>n,ux:()=>a});var s=e(22786),o=e(79468);function r(t,i){const e=t%54+1;return i.getPropertyValue(`--color-${e}`)}function n(t,i){const e=i.getPropertyValue(`--graph-color-${t+1}`)||r(t,i);return(0,o.RQ)(e)}const a=(0,s.A)(t=>Array.from({length:54},(i,e)=>n(e,t)),(t,i)=>t[0].getPropertyValue("--graph-color-1")===i[0].getPropertyValue("--graph-color-1")&&t[0].getPropertyValue("--color-1")===i[0].getPropertyValue("--color-1"))},58548(t,i,e){e.d(i,{A:()=>o});const s=t=>{const i=parseFloat(t);if(isNaN(i))throw new Error(`${t} is not a number`);return i};function o(t){if(!t)return null;try{if(t.endsWith("%"))return{w:100,h:s(t.slice(0,-1))};const i=t.replace(":","x").split("x");return 0===i.length?null:1===i.length?{w:s(i[0]),h:1}:{w:s(i[0]),h:s(i[1])}}catch(t){}return null}},22845(t,i,e){e.a(t,async function(t,s){try{e.r(i),e.d(i,{DEFAULT_HOURS_TO_SHOW:()=>$,DEFAULT_ZOOM:()=>x});e(44114),e(18111),e(22489),e(20116),e(7588),e(61701),e(17642),e(58004),e(33853),e(45876),e(32475),e(15024),e(31698);var o=e(62826),r=e(5124),n=e(22441),a=e(22786),h=e(90433),c=e(78870),_=e(36312),l=e(71727),u=e(69093),d=e(28978),g=e(19459),f=e(58548),p=e(38962),m=(e(76776),e(26300)),b=e(22273),y=e(25064),E=e(13632),w=e(784),M=e(20939),A=e(14487),C=t([p,m,b,A,y]);[p,m,b,A,y]=C.then?(await C)():C;const k="M16 12C16 10.9 16.9 10 18 10S20 10.9 20 12 19.1 14 18 14 16 13.1 16 12M10 12C10 10.9 10.9 10 12 10S14 10.9 14 12 13.1 14 12 14 10 13.1 10 12M4 12C4 10.9 4.9 10 6 10S8 10.9 8 12 7.1 14 6 14 4 13.1 4 12M13 18C13 16.9 13.9 16 15 16S17 16.9 17 18 16.1 20 15 20 13 19.1 13 18M7 18C7 16.9 7.9 16 9 16S11 16.9 11 18 10.1 20 9 20 7 19.1 7 18M13 6C13 4.9 13.9 4 15 4S17 4.9 17 6 16.1 8 15 8 13 7.1 13 6M7 6C7 4.9 7.9 4 9 4S11 4.9 11 6 10.1 8 9 8 7 7.1 7 6",v="M15,12C13.89,12 13,12.89 13,14A2,2 0 0,0 15,16A2,2 0 0,0 17,14C17,12.89 16.1,12 15,12M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M14,9C14,7.89 13.1,7 12,7C10.89,7 10,7.89 10,9A2,2 0 0,0 12,11A2,2 0 0,0 14,9M9,12A2,2 0 0,0 7,14A2,2 0 0,0 9,16A2,2 0 0,0 11,14C11,12.89 10.1,12 9,12Z",H="M12,9A3,3 0 0,0 9,12A3,3 0 0,0 12,15A3,3 0 0,0 15,12A3,3 0 0,0 12,9M19,19H15V21H19A2,2 0 0,0 21,19V15H19M19,3H15V5H19V9H21V5A2,2 0 0,0 19,3M5,5H9V3H5A2,2 0 0,0 3,5V9H5M5,15H3V19A2,2 0 0,0 5,21H9V19H5V15Z",$=0,x=14;class V extends r.WF{_getAllEntities(){const t=this.hass,i=new Set,e=[];return Object.values(t.states).forEach(t=>{"latitude"in t.attributes&&"longitude"in t.attributes&&(e.push(t.entity_id),"person"===(0,u.t)(t)&&t.attributes.source&&i.add(t.attributes.source))}),e.filter(e=>!t.entities?.[e]?.hidden&&!i.has(e))}setConfig(t){if(!t)throw new Error("Error in card configuration.");if(!t.show_all&&!t.entities?.length&&!t.geo_location_sources)throw new Error("Either show_all, entities, or geo_location_sources must be specified");if(t.entities&&!Array.isArray(t.entities))throw new Error("Entities need to be an array");if(t.geo_location_sources&&!Array.isArray(t.geo_location_sources))throw new Error("Parameter geo_location_sources needs to be an array");if(t.show_all&&(t.entities||t.geo_location_sources))throw new Error("Cannot specify show_all and entities or geo_location_sources");this._config={...t},this.hass&&t.show_all&&(this._config.entities=this._getAllEntities()),this._configEntities=this._config.entities?(0,M.L)(this._config.entities):[],this._mapEntities=this._getMapEntities(),this._clusterMarkers=this._config.cluster??!0}getCardSize(){if(!this._config?.aspect_ratio)return 7;const t=(0,f.A)(this._config.aspect_ratio),i=t&&t.w>0&&t.h>0?`${(100*t.h/t.w).toFixed(2)}`:"100";return 1+Math.floor(Number(i)/25)||3}static async getConfigElement(){return await Promise.all([e.e(81034),e.e(99143),e.e(66990),e.e(38076),e.e(71609)]).then(e.bind(e,81846)),document.createElement("hui-map-card-editor")}static getStubConfig(t,i,e){return{type:"map",entities:(0,E.B)(t,2,i,e,["device_tracker"]),theme_mode:"auto"}}firstUpdated(){this._mapEntities=this._getMapEntities()}render(){if(!this._config)return r.s6;if(this._error)return r.qy`<ha-alert alert-type="error"> ${this.hass.localize("ui.components.map.error")}: ${this._error.message} (${this._error.code}) </ha-alert>`;const t=!(!this._config.dark_mode&&"dark"!==this._config.theme_mode)||"light"!==this._config.theme_mode&&this.hass.themes.darkMode,i=this._config.theme_mode||(this._config.dark_mode?"dark":"auto");return r.qy` <ha-card id="card" .header="${this._config.title}"> <div id="root"> <ha-map .hass="${this.hass}" .entities="${this._filteredMapEntities}" .zoom="${this._config.default_zoom??x}" .paths="${this._getHistoryPaths(this._config,this._stateHistory)}" .autoFit="${this._config.auto_fit||!1}" .fitZones="${this._config.fit_zones||!1}" .themeMode="${i}" .clusterMarkers="${this._clusterMarkers}" interactive-zones render-passive></ha-map> <div id="buttons"> ${this._filteredMapEntities.length>1?r.qy` <ha-icon-button .label="${this.hass.localize("ui.panel.lovelace.cards.map.toggle_grouping")}" .path="${this._clusterMarkers?v:k}" style="${t?"color:#ffffff":"color:#000000"}" @click="${this._toggleClusterMarkers}" tabindex="0"></ha-icon-button> `:r.s6} <ha-icon-button .label="${this.hass.localize("ui.panel.lovelace.cards.map.reset_focus")}" .path="${H}" style="${t?"color:#ffffff":"color:#000000"}" @click="${this._resetFocus}" tabindex="0"></ha-icon-button> </div> </div> </ha-card> `}shouldUpdate(t){if(!t.has("hass")||t.size>1)return!0;const i=t.get("hass");return!i||!this._configEntities||(i.themes.darkMode!==this.hass.themes.darkMode||(!(this._subscribed||this._error||!this._config||i.config.components===this.hass.config.components)||(!!t.has("_stateHistory")||(!(!this._config?.geo_location_sources||i.states===this.hass.states)||(this._config?.entities?(0,w.pY)(this,t):(0,w.xP)(this,t))))))}willUpdate(t){if(super.willUpdate(t),this._config?.show_all&&!this._config?.entities&&this.hass&&t.has("hass")&&(this._config.entities=this._getAllEntities(),this._configEntities=(0,M.L)(this._config.entities),this._mapEntities=this._getMapEntities()),t.has("hass")&&this._config?.geo_location_sources&&!(0,g.b)(this._getSourceEntities(t.get("hass")?.states),this._getSourceEntities(this.hass.states))&&(this._mapEntities=this._getMapEntities()),this._config?.conditions&&this._mapEntities){const t=this._config.conditions;this._filteredMapEntities=this._mapEntities.filter(i=>{const e=t.map(t=>(0,A.lB)(t,i.entity_id));return(0,A.XH)(e,this.hass,{})})}else this._filteredMapEntities=this._mapEntities}connectedCallback(){super.connectedCallback(),this.hasUpdated&&this._configEntities?.length&&this._subscribeHistory()}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribeHistory()}_subscribeHistory(){(0,_.x)(this.hass.config,"history")&&!this._subscribed&&(this._config?.hours_to_show??$)&&(this._subscribed=(0,y.IQ)(this.hass,t=>{this._subscribed&&(this._stateHistory=t)},this._config.hours_to_show??$,(this._configEntities||[]).map(t=>t.entity),!1,!1,!1).catch(t=>{this._subscribed=void 0,this._error=t}))}_unsubscribeHistory(){this._subscribed&&(this._subscribed.then(t=>t?.()).catch(()=>{}),this._subscribed=void 0)}updated(t){this._configEntities?.length?(this.isConnected&&!this._subscribed&&!this._error||t.has("_config"))&&(this._unsubscribeHistory(),this._subscribeHistory()):this._unsubscribeHistory(),t.has("_config")&&this._computePadding()}_computePadding(){const t=this.shadowRoot.getElementById("root"),i="panel"===this.layout||"grid"===this.layout;if(!this._config||i||!t)return;if(!this._config.aspect_ratio)return void(t.style.paddingBottom="100%");t.style.height="auto";const e=(0,f.A)(this._config.aspect_ratio);t.style.paddingBottom=e&&e.w>0&&e.h>0?`${(100*e.h/e.w).toFixed(2)}%`:t.style.paddingBottom="100%"}_resetFocus(){this._map?.fitMap({unpause_autofit:!0})}_toggleClusterMarkers(){this._clusterMarkers=!this._clusterMarkers}_getColor(t){let i=this._colorDict[t];if(i)return i;const e=getComputedStyle(this);return i=(0,h.Vy)(this._colorIndex,e),i&&(this._colorIndex++,this._colorDict[t]=i),i}_getSourceEntities(t){if(!t||!this._config?.geo_location_sources)return[];const i=this._config.geo_location_sources.map(t=>"string"==typeof t?{source:t}:t),e=[],s=i.find(t=>"all"===t.source);for(const o of Object.values(t)){const t=i.find(t=>t.source===o.attributes.source);"geo_location"===(0,l.m)(o.entity_id)&&(s||t)&&e.push({entity_id:o.entity_id,label_mode:t?.label_mode??s?.label_mode,attribute:t?.attribute??s?.attribute,unit:t?.unit??s?.unit,focus:t?t.focus??!0:s?.focus??!0})}return e}_getMapEntities(){return[...(this._configEntities||[]).map(t=>({entity_id:t.entity,color:t.color?(0,c.X0)(t.color):this._getColor(t.entity),label_mode:t.label_mode,attribute:t.attribute,unit:t.unit,focus:t.focus,name:t.name})),...this._getSourceEntities(this.hass?.states).map(t=>({...t,color:this._getColor(t.entity_id)}))]}getGridOptions(){return{columns:"full",rows:4,min_columns:6,min_rows:2}}constructor(...t){super(...t),this._mapEntities=[],this._filteredMapEntities=[],this._colorDict={},this._colorIndex=0,this._clusterMarkers=!0,this._getHistoryPaths=(0,a.A)((t,i)=>{if(!i||!(t.hours_to_show??$))return;const e=[];for(const s of Object.keys(i)){if("zone"===(0,l.m)(s))continue;const o=i[s];if(!o?.length)continue;const r=[];for(const t of o){const i=t.a.latitude,e=t.a.longitude;if(!i||!e)continue;const s={};s.point=[i,e],s.timestamp=new Date(1e3*t.lu),r.push(s)}const n=this._configEntities?.find(t=>t.entity===s),a=n?.name??(s in this.hass.states?(0,d.u)(this.hass.states[s]):s);e.push({points:r,name:a,fullDatetime:(t.hours_to_show??$)>144,color:n?.color?(0,c.X0)(n.color):this._getColor(s),gradualOpacity:.8})}return e})}}V.styles=r.AH`ha-card{overflow:hidden;width:100%;height:100%;display:flex;flex-direction:column}ha-map{z-index:0;border:none;position:absolute;top:0;left:0;width:100%;height:100%;background:inherit;border-radius:var(--ha-card-border-radius,var(--ha-border-radius-lg));overflow:hidden}#buttons{position:absolute;top:75px;left:3px;display:flex;flex-direction:column}#root{position:relative;height:100%}`,(0,o.Cg)([(0,n.MZ)({attribute:!1})],V.prototype,"hass",void 0),(0,o.Cg)([(0,n.MZ)({attribute:!1})],V.prototype,"layout",void 0),(0,o.Cg)([(0,n.wk)()],V.prototype,"_stateHistory",void 0),(0,o.Cg)([(0,n.wk)()],V.prototype,"_config",void 0),(0,o.Cg)([(0,n.P)("ha-map")],V.prototype,"_map",void 0),(0,o.Cg)([(0,n.wk)()],V.prototype,"_mapEntities",void 0),(0,o.Cg)([(0,n.wk)()],V.prototype,"_error",void 0),(0,o.Cg)([(0,n.wk)()],V.prototype,"_clusterMarkers",void 0),V=(0,o.Cg)([(0,n.EM)("hui-map-card")],V),s()}catch(t){s(t)}})}};