iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 12.2 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[21742],{90433:function(t,i,e){e.d(i,{Vy:function(){return r},fI:function(){return a},ux:function(){return l}});var s=e(22786),o=e(79468);const n=54;function r(t,i){const e=t%n+1;return i.getPropertyValue(`--color-${e}`)}function a(t,i){const e=i.getPropertyValue(`--graph-color-${t+1}`)||r(t,i);return(0,o.RQ)(e)}const l=(0,s.A)(t=>Array.from({length:n},(i,e)=>a(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:function(t,i,e){e.d(i,{A:function(){return o}});e(16280),e(27495),e(25440);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(i){}return null}},22845:function(t,i,e){e.a(t,async function(t,s){try{e.r(i),e.d(i,{DEFAULT_HOURS_TO_SHOW:function(){return O},DEFAULT_ZOOM:function(){return z}});e(16280),e(44114),e(18111),e(22489),e(20116),e(7588),e(61701),e(3362),e(17642),e(58004),e(33853),e(45876),e(32475),e(15024),e(31698),e(62953);var o=e(40445),n=e(5124),r=e(67576),a=e(22786),l=e(90433),c=e(78870),h=e(36312),u=e(71727),d=e(69093),_=e(28978),f=e(19459),g=e(58548),p=e(38962),v=(e(76776),e(26300)),b=e(22273),m=e(25064),y=e(13632),E=e(784),w=e(20939),M=e(14487),C=t([p,v,b,M,m]);[p,v,b,M,m]=C.then?(await C)():C;let A,k,H,$,x=t=>t;const V="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",S="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",P="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",O=0,z=14;class F extends n.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,d.t)(t)&&t.attributes.source&&i.add(t.attributes.source))}),e.filter(e=>{var s;return!(null!==(s=t.entities)&&void 0!==s&&null!==(s=s[e])&&void 0!==s&&s.hidden||i.has(e))})}setConfig(t){var i,e;if(!t)throw new Error("Error in card configuration.");if(!(t.show_all||null!==(i=t.entities)&&void 0!==i&&i.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=Object.assign({},t),this.hass&&t.show_all&&(this._config.entities=this._getAllEntities()),this._configEntities=this._config.entities?(0,w.L)(this._config.entities):[],this._mapEntities=this._getMapEntities(),this._clusterMarkers=null===(e=this._config.cluster)||void 0===e||e}getCardSize(){var t;if(null===(t=this._config)||void 0===t||!t.aspect_ratio)return 7;const i=(0,g.A)(this._config.aspect_ratio),e=i&&i.w>0&&i.h>0?`${(100*i.h/i.w).toFixed(2)}`:"100";return 1+Math.floor(Number(e)/25)||3}static async getConfigElement(){return await Promise.all([e.e(81034),e.e(99143),e.e(66990),e.e(81804),e.e(38076),e.e(35873),e.e(62231)]).then(e.bind(e,81846)),document.createElement("hui-map-card-editor")}static getStubConfig(t,i,e){return{type:"map",entities:(0,y.B)(t,2,i,e,["device_tracker"]),theme_mode:"auto"}}firstUpdated(){this._mapEntities=this._getMapEntities()}render(){var t;if(!this._config)return n.s6;if(this._error)return(0,n.qy)(A||(A=x`<ha-alert alert-type="error"> ${0}: ${0} (${0}) </ha-alert>`),this.hass.localize("ui.components.map.error"),this._error.message,this._error.code);const i=!(!this._config.dark_mode&&"dark"!==this._config.theme_mode)||"light"!==this._config.theme_mode&&this.hass.themes.darkMode,e=this._config.theme_mode||(this._config.dark_mode?"dark":"auto");return(0,n.qy)(k||(k=x` <ha-card id="card" .header="${0}"> <div id="root"> <ha-map .hass="${0}" .entities="${0}" .zoom="${0}" .paths="${0}" .autoFit="${0}" .fitZones="${0}" .themeMode="${0}" .clusterMarkers="${0}" interactive-zones render-passive></ha-map> <div id="buttons"> ${0} <ha-icon-button .label="${0}" .path="${0}" style="${0}" ="${0}" tabindex="0"></ha-icon-button> </div> </div> </ha-card> `),this._config.title,this.hass,this._filteredMapEntities,null!==(t=this._config.default_zoom)&&void 0!==t?t:z,this._getHistoryPaths(this._config,this._stateHistory),this._config.auto_fit||!1,this._config.fit_zones||!1,e,this._clusterMarkers,this._filteredMapEntities.length>1?(0,n.qy)(H||(H=x` <ha-icon-button .label="${0}" .path="${0}" style="${0}" ="${0}" tabindex="0"></ha-icon-button> `),this.hass.localize("ui.panel.lovelace.cards.map.toggle_grouping"),this._clusterMarkers?S:V,i?"color:#ffffff":"color:#000000",this._toggleClusterMarkers):n.s6,this.hass.localize("ui.panel.lovelace.cards.map.reset_focus"),P,i?"color:#ffffff":"color:#000000",this._resetFocus)}shouldUpdate(t){var i,e;if(!t.has("hass")||t.size>1)return!0;const s=t.get("hass");return!s||!this._configEntities||(s.themes.darkMode!==this.hass.themes.darkMode||(!(this._subscribed||this._error||!this._config||s.config.components===this.hass.config.components)||(!!t.has("_stateHistory")||(!(null===(i=this._config)||void 0===i||!i.geo_location_sources||s.states===this.hass.states)||(null!==(e=this._config)&&void 0!==e&&e.entities?(0,E.pY)(this,t):(0,E.xP)(this,t))))))}willUpdate(t){var i,e,s,o,n;if(super.willUpdate(t),null!==(i=this._config)&&void 0!==i&&i.show_all&&(null===(e=this._config)||void 0===e||!e.entities)&&this.hass&&t.has("hass")&&(this._config.entities=this._getAllEntities(),this._configEntities=(0,w.L)(this._config.entities),this._mapEntities=this._getMapEntities()),t.has("hass")&&null!==(s=this._config)&&void 0!==s&&s.geo_location_sources&&!(0,f.b)(this._getSourceEntities(null===(o=t.get("hass"))||void 0===o?void 0:o.states),this._getSourceEntities(this.hass.states))&&(this._mapEntities=this._getMapEntities()),null!==(n=this._config)&&void 0!==n&&n.conditions&&this._mapEntities){const t=this._config.conditions;this._filteredMapEntities=this._mapEntities.filter(i=>{const e=t.map(t=>(0,M.lB)(t,i.entity_id));return(0,M.XH)(e,this.hass,{})})}else this._filteredMapEntities=this._mapEntities}connectedCallback(){var t;super.connectedCallback(),this.hasUpdated&&null!==(t=this._configEntities)&&void 0!==t&&t.length&&this._subscribeHistory()}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribeHistory()}_subscribeHistory(){var t,i,e;(0,h.x)(this.hass.config,"history")&&!this._subscribed&&(null!==(t=null===(i=this._config)||void 0===i?void 0:i.hours_to_show)&&void 0!==t?t:O)&&(this._subscribed=(0,m.IQ)(this.hass,t=>{this._subscribed&&(this._stateHistory=t)},null!==(e=this._config.hours_to_show)&&void 0!==e?e:O,(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=>null==t?void 0:t()).catch(()=>{}),this._subscribed=void 0)}updated(t){var i;null!==(i=this._configEntities)&&void 0!==i&&i.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,g.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(){var t;null===(t=this._map)||void 0===t||t.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,l.Vy)(this._colorIndex,e),i&&(this._colorIndex++,this._colorDict[t]=i),i}_getSourceEntities(t){var i;if(!t||null===(i=this._config)||void 0===i||!i.geo_location_sources)return[];const e=this._config.geo_location_sources.map(t=>"string"==typeof t?{source:t}:t),s=[],o=e.find(t=>"all"===t.source);for(const h of Object.values(t)){const t=e.find(t=>t.source===h.attributes.source);var n,r,a,l,c;if("geo_location"===(0,u.m)(h.entity_id)&&(o||t))s.push({entity_id:h.entity_id,label_mode:null!==(n=null==t?void 0:t.label_mode)&&void 0!==n?n:null==o?void 0:o.label_mode,attribute:null!==(r=null==t?void 0:t.attribute)&&void 0!==r?r:null==o?void 0:o.attribute,unit:null!==(a=null==t?void 0:t.unit)&&void 0!==a?a:null==o?void 0:o.unit,focus:t?null===(l=t.focus)||void 0===l||l:null===(c=null==o?void 0:o.focus)||void 0===c||c})}return s}_getMapEntities(){var t;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(null===(t=this.hass)||void 0===t?void 0:t.states).map(t=>Object.assign(Object.assign({},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)=>{var e;if(!i||!(null!==(e=t.hours_to_show)&&void 0!==e?e:O))return;const s=[];for(const a of Object.keys(i)){var o,n,r;if("zone"===(0,u.m)(a))continue;const e=i[a];if(null==e||!e.length)continue;const l=[];for(const t of e){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),l.push(s)}const h=null===(o=this._configEntities)||void 0===o?void 0:o.find(t=>t.entity===a),d=null!==(n=null==h?void 0:h.name)&&void 0!==n?n:a in this.hass.states?(0,_.u)(this.hass.states[a]):a;s.push({points:l,name:d,fullDatetime:(null!==(r=t.hours_to_show)&&void 0!==r?r:O)>144,color:null!=h&&h.color?(0,c.X0)(h.color):this._getColor(a),gradualOpacity:.8})}return s})}}F.styles=(0,n.AH)($||($=x`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,r.MZ)({attribute:!1})],F.prototype,"hass",void 0),(0,o.Cg)([(0,r.MZ)({attribute:!1})],F.prototype,"layout",void 0),(0,o.Cg)([(0,r.wk)()],F.prototype,"_stateHistory",void 0),(0,o.Cg)([(0,r.wk)()],F.prototype,"_config",void 0),(0,o.Cg)([(0,r.P)("ha-map")],F.prototype,"_map",void 0),(0,o.Cg)([(0,r.wk)()],F.prototype,"_mapEntities",void 0),(0,o.Cg)([(0,r.wk)()],F.prototype,"_error",void 0),(0,o.Cg)([(0,r.wk)()],F.prototype,"_clusterMarkers",void 0),F=(0,o.Cg)([(0,r.EM)("hui-map-card")],F),s()}catch(A){s(A)}})}}]);