iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
2 lines • 14.4 kB
JavaScript
export const __webpack_ids__=["49554"];export const __webpack_modules__={91480:function(t,e,i){i.d(e,{F:()=>a});i(9359),i(70104);const a=async t=>{if(!t.parentNode)throw new Error("Cannot setup Leaflet map on disconnected element");const e=(await Promise.resolve().then(i.t.bind(i,94010,23))).default;e.Icon.Default.imagePath="/static/images/leaflet/images/",await i.e("56834").then(i.t.bind(i,69376,23));const a=e.map(t),o=document.createElement("link");o.setAttribute("href","/static/images/leaflet/leaflet.css"),o.setAttribute("rel","stylesheet"),t.parentNode.appendChild(o);const r=document.createElement("link");r.setAttribute("href","/static/images/leaflet/MarkerCluster.css"),r.setAttribute("rel","stylesheet"),t.parentNode.appendChild(r),a.setView([52.3731339,4.8903147],13);return[a,e,s(e).addTo(a)]},s=t=>t.tileLayer("https://basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}"+(t.Browser.retina?"@2x.png":".png"),{attribution:'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>, © <a href="https://carto.com/attributions">CARTO</a>',subdomains:"abcd",minZoom:0,maxZoom:20})},44435:function(t,e,i){i.d(e,{k:()=>s});var a=i(94010);class s extends a.Marker{constructor(t,e,i){super(t,i),this.decorationLayer=void 0,this.decorationLayer=e}onAdd(t){return super.onAdd(t),this.decorationLayer?.addTo(t),this}onRemove(t){return this.decorationLayer?.remove(),super.onRemove(t)}}},14502:function(t,e,i){i.a(t,(async function(t,e){try{var a=i(44249),s=i(57243),o=i(15093),r=i(69634),n=i(36522),l=i(51223),d=t([l]);l=(d.then?(await d)():d)[0];let c=(0,a.Z)(null,(function(t,e){return{F:class extends e{constructor(...e){super(...e),t(this)}},d:[{kind:"field",decorators:[(0,o.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,o.Cb)({attribute:"entity-id",reflect:!0})],key:"entityId",value:void 0},{kind:"field",decorators:[(0,o.Cb)({attribute:"entity-name"})],key:"entityName",value:void 0},{kind:"field",decorators:[(0,o.Cb)({attribute:"entity-picture"})],key:"entityPicture",value:void 0},{kind:"field",decorators:[(0,o.Cb)({attribute:"entity-color"})],key:"entityColor",value:void 0},{kind:"field",decorators:[(0,o.Cb)({attribute:"show-icon",type:Boolean})],key:"showIcon",value:()=>!1},{kind:"method",key:"render",value:function(){return s.dy` <div class="marker ${this.entityPicture?"picture":""}" style="${(0,r.V)({"border-color":this.entityColor})}" ="${this._badgeTap}"> ${this.entityPicture?s.dy`<div class="entity-picture" style="${(0,r.V)({"background-image":`url(${this.entityPicture})`})}"></div>`:this.showIcon&&this.entityId?s.dy`<ha-state-icon .hass="${this.hass}" .stateObj="${this.hass?.states[this.entityId]}"></ha-state-icon>`:this.entityName} </div> `}},{kind:"method",key:"_badgeTap",value:function(t){t.stopPropagation(),this.entityId&&(0,n.B)(this,"hass-more-info",{entityId:this.entityId})}},{kind:"field",static:!0,key:"styles",value:()=>s.iv`.marker{display:flex;justify-content:center;text-align:center;align-items:center;box-sizing:border-box;width:48px;height:48px;font-size:var(--ha-marker-font-size, 1.5em);border-radius:var(--ha-marker-border-radius,50%);border:1px solid var(--ha-marker-color,var(--primary-color));color:var(--primary-text-color);background-color:var(--card-background-color)}.marker.picture{overflow:hidden}.entity-picture{background-size:cover;height:100%;width:100%}`}]}}),s.oi);customElements.define("ha-entity-marker",c),e()}catch(t){e(t)}}))},65986:function(t,e,i){i.a(t,(async function(t,e){try{var a=i(44249),s=i(72621),o=(i(92745),i(9359),i(31526),i(70104),i(16444)),r=i(57243),n=i(15093),l=i(36522),d=i(64214),c=i(33570),h=i(91480),u=i(59847),p=i(47194),m=i(79291),f=(i(23334),i(14502)),y=i(44435),k=t([f,d,c]);[f,d,c]=k.then?(await k)():k;const v=t=>"string"==typeof t?t:t.entity_id;(0,a.Z)([(0,n.Mo)("ha-map")],(function(t,e){class i extends e{constructor(...e){super(...e),t(this)}}return{F:i,d:[{kind:"field",decorators:[(0,n.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,n.Cb)({attribute:!1})],key:"entities",value:void 0},{kind:"field",decorators:[(0,n.Cb)({attribute:!1})],key:"paths",value:void 0},{kind:"field",decorators:[(0,n.Cb)({attribute:!1})],key:"layers",value:void 0},{kind:"field",decorators:[(0,n.Cb)({type:Boolean})],key:"clickable",value:()=>!1},{kind:"field",decorators:[(0,n.Cb)({attribute:"auto-fit",type:Boolean})],key:"autoFit",value:()=>!1},{kind:"field",decorators:[(0,n.Cb)({attribute:"render-passive",type:Boolean})],key:"renderPassive",value:()=>!1},{kind:"field",decorators:[(0,n.Cb)({attribute:"interactive-zones",type:Boolean})],key:"interactiveZones",value:()=>!1},{kind:"field",decorators:[(0,n.Cb)({attribute:"fit-zones",type:Boolean})],key:"fitZones",value:()=>!1},{kind:"field",decorators:[(0,n.Cb)({attribute:"theme-mode",type:String})],key:"themeMode",value:()=>"auto"},{kind:"field",decorators:[(0,n.Cb)({type:Number})],key:"zoom",value:()=>14},{kind:"field",decorators:[(0,n.Cb)({attribute:"cluster-markers",type:Boolean})],key:"clusterMarkers",value:()=>!0},{kind:"field",decorators:[(0,n.SB)()],key:"_loaded",value:()=>!1},{kind:"field",key:"leafletMap",value:void 0},{kind:"field",key:"Leaflet",value:void 0},{kind:"field",key:"_resizeObserver",value:void 0},{kind:"field",key:"_mapItems",value:()=>[]},{kind:"field",key:"_mapFocusItems",value:()=>[]},{kind:"field",key:"_mapZones",value:()=>[]},{kind:"field",key:"_mapFocusZones",value:()=>[]},{kind:"field",key:"_mapCluster",value:void 0},{kind:"field",key:"_mapPaths",value:()=>[]},{kind:"field",key:"_clickCount",value:()=>0},{kind:"method",key:"connectedCallback",value:function(){(0,s.Z)(i,"connectedCallback",this,3)([]),this._loadMap(),this._attachObserver()}},{kind:"method",key:"disconnectedCallback",value:function(){(0,s.Z)(i,"disconnectedCallback",this,3)([]),this.leafletMap&&(this.leafletMap.remove(),this.leafletMap=void 0,this.Leaflet=void 0),this._loaded=!1,this._resizeObserver&&this._resizeObserver.unobserve(this)}},{kind:"method",key:"update",value:function(t){if((0,s.Z)(i,"update",this,3)([t]),!this._loaded)return;let e=!1;const a=t.get("hass");if(t.has("_loaded")||t.has("entities"))this._drawEntities(),e=!0;else if(this._loaded&&a&&this.entities)for(const t of this.entities)if(a.states[v(t)]!==this.hass.states[v(t)]){this._drawEntities(),e=!0;break}t.has("clusterMarkers")&&this._drawEntities(),(t.has("_loaded")||t.has("paths"))&&this._drawPaths(),(t.has("_loaded")||t.has("layers"))&&(this._drawLayers(t.get("layers")),e=!0),(t.has("_loaded")||this.autoFit&&e)&&this.fitMap(),t.has("zoom")&&this.leafletMap.setZoom(this.zoom),(t.has("themeMode")||t.has("hass")&&(!a||a.themes?.darkMode!==this.hass.themes?.darkMode))&&this._updateMapStyle()}},{kind:"get",key:"_darkMode",value:function(){return"dark"===this.themeMode||"auto"===this.themeMode&&Boolean(this.hass.themes.darkMode)}},{kind:"method",key:"_updateMapStyle",value:function(){const t=this.renderRoot.querySelector("#map");t.classList.toggle("clickable",this.clickable),t.classList.toggle("dark",this._darkMode),t.classList.toggle("forced-dark","dark"===this.themeMode),t.classList.toggle("forced-light","light"===this.themeMode)}},{kind:"field",key:"_loading",value:()=>!1},{kind:"method",key:"_loadMap",value:async function(){if(this._loading)return;let t=this.shadowRoot.getElementById("map");t||(t=document.createElement("div"),t.id="map",this.shadowRoot.append(t)),this._loading=!0;try{[this.leafletMap,this.Leaflet]=await(0,h.F)(t),this._updateMapStyle(),this.leafletMap.on("click",(t=>{0===this._clickCount&&setTimeout((()=>{1===this._clickCount&&(0,l.B)(this,"map-clicked",{location:[t.latlng.lat,t.latlng.lng]}),this._clickCount=0}),250),this._clickCount++})),this._loaded=!0}finally{this._loading=!1}}},{kind:"method",key:"fitMap",value:function(t){if(!this.leafletMap||!this.Leaflet||!this.hass)return;if(!this._mapFocusItems.length&&!this._mapFocusZones.length&&!this.layers?.length)return void this.leafletMap.setView(new this.Leaflet.LatLng(this.hass.config.latitude,this.hass.config.longitude),t?.zoom||this.zoom);let e=this.Leaflet.latLngBounds(this._mapFocusItems?this._mapFocusItems.map((t=>t.getLatLng())):[]);this._mapFocusZones?.forEach((t=>{e.extend("getBounds"in t?t.getBounds():t.getLatLng())})),this.layers?.forEach((t=>{e.extend("getBounds"in t?t.getBounds():t.getLatLng())})),e=e.pad(t?.pad??.5),this.leafletMap.fitBounds(e,{maxZoom:t?.zoom||this.zoom})}},{kind:"method",key:"fitBounds",value:function(t,e){if(!this.leafletMap||!this.Leaflet||!this.hass)return;const i=this.Leaflet.latLngBounds(t).pad(e?.pad??.5);this.leafletMap.fitBounds(i,{maxZoom:e?.zoom||this.zoom})}},{kind:"method",key:"_drawLayers",value:function(t){if(t&&t.forEach((t=>t.remove())),!this.layers)return;const e=this.leafletMap;this.layers.forEach((t=>{e.addLayer(t)}))}},{kind:"method",key:"_computePathTooltip",value:function(t,e){let i;return i=t.fullDatetime?(0,d.o0)(e.timestamp,this.hass.locale,this.hass.config):(0,o.z)(e.timestamp)?(0,c.Vu)(e.timestamp,this.hass.locale,this.hass.config):(0,c.xO)(e.timestamp,this.hass.locale,this.hass.config),`${t.name}<br>${i}`}},{kind:"method",key:"_drawPaths",value:function(){const t=this.hass,e=this.leafletMap,i=this.Leaflet;if(!t||!e||!i)return;if(this._mapPaths.length&&(this._mapPaths.forEach((t=>t.remove())),this._mapPaths=[]),!this.paths)return;const a=getComputedStyle(this).getPropertyValue("--dark-primary-color");this.paths.forEach((t=>{let s,o;t.gradualOpacity&&(s=t.gradualOpacity/(t.points.length-2),o=1-t.gradualOpacity);for(let e=0;e<t.points.length-1;e++){const r=t.gradualOpacity?o+e*s:void 0;this._mapPaths.push(i.circleMarker(t.points[e].point,{radius:m.T?8:3,color:t.color||a,opacity:r,fillOpacity:r,interactive:!0}).bindTooltip(this._computePathTooltip(t,t.points[e]),{direction:"top"})),this._mapPaths.push(i.polyline([t.points[e].point,t.points[e+1].point],{color:t.color||a,opacity:r,interactive:!1}))}const r=t.points.length-1;if(r>=0){const e=t.gradualOpacity?o+r*s:void 0;this._mapPaths.push(i.circleMarker(t.points[r].point,{radius:m.T?8:3,color:t.color||a,opacity:e,fillOpacity:e,interactive:!0}).bindTooltip(this._computePathTooltip(t,t.points[r]),{direction:"top"}))}this._mapPaths.forEach((t=>e.addLayer(t)))}))}},{kind:"method",key:"_drawEntities",value:function(){const t=this.hass,e=this.leafletMap,i=this.Leaflet;if(!t||!e||!i)return;if(this._mapItems.length&&(this._mapItems.forEach((t=>t.remove())),this._mapItems=[],this._mapFocusItems=[]),this._mapZones.length&&(this._mapZones.forEach((t=>t.remove())),this._mapZones=[],this._mapFocusZones=[]),this._mapCluster&&(this._mapCluster.remove(),this._mapCluster=void 0),!this.entities)return;const a=getComputedStyle(this),s=a.getPropertyValue("--accent-color"),o=a.getPropertyValue("--secondary-text-color"),r=a.getPropertyValue("--dark-primary-color"),n=this._darkMode?"dark":"light";for(const e of this.entities){const a=t.states[v(e)];if(!a)continue;const l="string"!=typeof e?e.name:void 0,d=l??(0,p.C)(a),{latitude:c,longitude:h,passive:m,icon:f,radius:k,entity_picture:b,gps_accuracy:g}=a.attributes;if(!c||!h)continue;if("zone"===(0,u.N)(a)){if(m&&!this.renderPassive)continue;let t="";if(f){const e=document.createElement("ha-icon");e.setAttribute("icon",f),t=e.outerHTML}else{const e=document.createElement("span");e.innerHTML=d,t=e.outerHTML}const a=i.circle([c,h],{interactive:!1,color:m?o:s,radius:k}),r=new y.k([c,h],a,{icon:i.divIcon({html:t,iconSize:[24,24],className:n}),interactive:this.interactiveZones,title:d});this._mapZones.push(r),!this.fitZones||"string"!=typeof e&&!1===e.focus||this._mapFocusZones.push(a);continue}const _="string"!=typeof e&&"state"===e.label_mode?this.hass.formatEntityState(a):"string"!=typeof e&&"attribute"===e.label_mode&&void 0!==e.attribute?this.hass.formatEntityAttributeValue(a,e.attribute):l??d.split(" ").map((t=>t[0])).join("").substr(0,3),C=document.createElement("ha-entity-marker");C.hass=this.hass,C.showIcon="string"!=typeof e&&"icon"===e.label_mode,C.entityId=v(e),C.entityName=_,C.entityPicture=!b||"string"!=typeof e&&e.label_mode?"":this.hass.hassUrl(b),"string"!=typeof e&&(C.entityColor=e.color);const M=new y.k([c,h],void 0,{icon:i.divIcon({html:C,iconSize:[48,48],className:""}),title:d});"string"!=typeof e&&!1===e.focus||this._mapFocusItems.push(M),g&&(M.decorationLayer=i.circle([c,h],{interactive:!1,color:r,radius:g})),this._mapItems.push(M)}this.clusterMarkers?(this._mapCluster=i.markerClusterGroup({showCoverageOnHover:!1,removeOutsideVisibleBounds:!1,maxClusterRadius:40}),this._mapCluster.addLayers(this._mapItems),e.addLayer(this._mapCluster)):this._mapItems.forEach((t=>e.addLayer(t))),this._mapZones.forEach((t=>e.addLayer(t)))}},{kind:"method",key:"_attachObserver",value:async function(){this._resizeObserver||(this._resizeObserver=new ResizeObserver((()=>{this.leafletMap?.invalidateSize({debounceMoveend:!0})}))),this._resizeObserver.observe(this)}},{kind:"field",static:!0,key:"styles",value:()=>r.iv`:host{display:block;height:300px}#map{height:100%}#map.clickable{cursor:pointer}#map.dark{background:#090909}#map.forced-dark{color:#fff;--map-filter:invert(0.9) hue-rotate(170deg) brightness(1.5) contrast(1.2) saturate(0.3)}#map.forced-light{background:#fff;color:#000;--map-filter:invert(0)}#map.clickable:active,#map:active{cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.leaflet-tile-pane{filter:var(--map-filter)}.dark .leaflet-bar a{background-color:#1c1c1c;color:#fff}.dark .leaflet-bar a:hover{background-color:#313131}.leaflet-marker-draggable{cursor:move!important}.leaflet-edit-resize{border-radius:50%;cursor:nesw-resize!important}.named-icon{display:flex;align-items:center;justify-content:center;flex-direction:column;text-align:center;color:var(--primary-text-color)}.leaflet-pane{z-index:0!important}.leaflet-bottom,.leaflet-control,.leaflet-top{z-index:1!important}.leaflet-tooltip{padding:8px;font-size:90%;background:rgba(80,80,80,.9)!important;color:#fff!important;border-radius:4px;box-shadow:none!important;text-align:center}.marker-cluster div{background-clip:padding-box;background-color:var(--primary-color);border:3px solid rgba(var(--rgb-primary-color),.2);width:32px;height:32px;border-radius:20px;text-align:center;color:var(--text-primary-color);font-size:14px}.marker-cluster span{line-height:30px}`}]}}),r.fl);e()}catch(t){e(t)}}))}};
//# sourceMappingURL=49554.051250e782eba219.js.map