iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
19 lines • 13.7 kB
JavaScript
(self.webpackChunkhome_assistant_frontend=self.webpackChunkhome_assistant_frontend||[]).push([[1482],{51482:(e,t,i)=>{"use strict";var r=i(15652),o=i(47181),n=i(52003),a=i(96151),s=i(45841);function l(){l=function(){return e};var e={elementsDefinitionOrder:[["method"],["field"]],initializeInstanceElements:function(e,t){["method","field"].forEach((function(i){t.forEach((function(t){t.kind===i&&"own"===t.placement&&this.defineClassElement(e,t)}),this)}),this)},initializeClassElements:function(e,t){var i=e.prototype;["method","field"].forEach((function(r){t.forEach((function(t){var o=t.placement;if(t.kind===r&&("static"===o||"prototype"===o)){var n="static"===o?e:i;this.defineClassElement(n,t)}}),this)}),this)},defineClassElement:function(e,t){var i=t.descriptor;if("field"===t.kind){var r=t.initializer;i={enumerable:i.enumerable,writable:i.writable,configurable:i.configurable,value:void 0===r?void 0:r.call(e)}}Object.defineProperty(e,t.key,i)},decorateClass:function(e,t){var i=[],r=[],o={static:[],prototype:[],own:[]};if(e.forEach((function(e){this.addElementPlacement(e,o)}),this),e.forEach((function(e){if(!h(e))return i.push(e);var t=this.decorateElement(e,o);i.push(t.element),i.push.apply(i,t.extras),r.push.apply(r,t.finishers)}),this),!t)return{elements:i,finishers:r};var n=this.decorateConstructor(i,t);return r.push.apply(r,n.finishers),n.finishers=r,n},addElementPlacement:function(e,t,i){var r=t[e.placement];if(!i&&-1!==r.indexOf(e.key))throw new TypeError("Duplicated element ("+e.key+")");r.push(e.key)},decorateElement:function(e,t){for(var i=[],r=[],o=e.decorators,n=o.length-1;n>=0;n--){var a=t[e.placement];a.splice(a.indexOf(e.key),1);var s=this.fromElementDescriptor(e),l=this.toElementFinisherExtras((0,o[n])(s)||s);e=l.element,this.addElementPlacement(e,t),l.finisher&&r.push(l.finisher);var d=l.extras;if(d){for(var c=0;c<d.length;c++)this.addElementPlacement(d[c],t);i.push.apply(i,d)}}return{element:e,finishers:r,extras:i}},decorateConstructor:function(e,t){for(var i=[],r=t.length-1;r>=0;r--){var o=this.fromClassDescriptor(e),n=this.toClassDescriptor((0,t[r])(o)||o);if(void 0!==n.finisher&&i.push(n.finisher),void 0!==n.elements){e=n.elements;for(var a=0;a<e.length-1;a++)for(var s=a+1;s<e.length;s++)if(e[a].key===e[s].key&&e[a].placement===e[s].placement)throw new TypeError("Duplicated element ("+e[a].key+")")}}return{elements:e,finishers:i}},fromElementDescriptor:function(e){var t={kind:e.kind,key:e.key,placement:e.placement,descriptor:e.descriptor};return Object.defineProperty(t,Symbol.toStringTag,{value:"Descriptor",configurable:!0}),"field"===e.kind&&(t.initializer=e.initializer),t},toElementDescriptors:function(e){var t;if(void 0!==e)return(t=e,function(e){if(Array.isArray(e))return e}(t)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(t)||function(e,t){if(e){if("string"==typeof e)return m(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?m(e,t):void 0}}(t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).map((function(e){var t=this.toElementDescriptor(e);return this.disallowProperty(e,"finisher","An element descriptor"),this.disallowProperty(e,"extras","An element descriptor"),t}),this)},toElementDescriptor:function(e){var t=String(e.kind);if("method"!==t&&"field"!==t)throw new TypeError('An element descriptor\'s .kind property must be either "method" or "field", but a decorator created an element descriptor with .kind "'+t+'"');var i=p(e.key),r=String(e.placement);if("static"!==r&&"prototype"!==r&&"own"!==r)throw new TypeError('An element descriptor\'s .placement property must be one of "static", "prototype" or "own", but a decorator created an element descriptor with .placement "'+r+'"');var o=e.descriptor;this.disallowProperty(e,"elements","An element descriptor");var n={kind:t,key:i,placement:r,descriptor:Object.assign({},o)};return"field"!==t?this.disallowProperty(e,"initializer","A method descriptor"):(this.disallowProperty(o,"get","The property descriptor of a field descriptor"),this.disallowProperty(o,"set","The property descriptor of a field descriptor"),this.disallowProperty(o,"value","The property descriptor of a field descriptor"),n.initializer=e.initializer),n},toElementFinisherExtras:function(e){return{element:this.toElementDescriptor(e),finisher:f(e,"finisher"),extras:this.toElementDescriptors(e.extras)}},fromClassDescriptor:function(e){var t={kind:"class",elements:e.map(this.fromElementDescriptor,this)};return Object.defineProperty(t,Symbol.toStringTag,{value:"Descriptor",configurable:!0}),t},toClassDescriptor:function(e){var t=String(e.kind);if("class"!==t)throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator created a class descriptor with .kind "'+t+'"');this.disallowProperty(e,"key","A class descriptor"),this.disallowProperty(e,"placement","A class descriptor"),this.disallowProperty(e,"descriptor","A class descriptor"),this.disallowProperty(e,"initializer","A class descriptor"),this.disallowProperty(e,"extras","A class descriptor");var i=f(e,"finisher");return{elements:this.toElementDescriptors(e.elements),finisher:i}},runClassFinishers:function(e,t){for(var i=0;i<t.length;i++){var r=(0,t[i])(e);if(void 0!==r){if("function"!=typeof r)throw new TypeError("Finishers must return a constructor.");e=r}}return e},disallowProperty:function(e,t,i){if(void 0!==e[t])throw new TypeError(i+" can't have a ."+t+" property.")}};return e}function d(e){var t,i=p(e.key);"method"===e.kind?t={value:e.value,writable:!0,configurable:!0,enumerable:!1}:"get"===e.kind?t={get:e.value,configurable:!0,enumerable:!1}:"set"===e.kind?t={set:e.value,configurable:!0,enumerable:!1}:"field"===e.kind&&(t={configurable:!0,writable:!0,enumerable:!0});var r={kind:"field"===e.kind?"field":"method",key:i,placement:e.static?"static":"field"===e.kind?"own":"prototype",descriptor:t};return e.decorators&&(r.decorators=e.decorators),"field"===e.kind&&(r.initializer=e.value),r}function c(e,t){void 0!==e.descriptor.get?t.descriptor.get=e.descriptor.get:t.descriptor.set=e.descriptor.set}function h(e){return e.decorators&&e.decorators.length}function u(e){return void 0!==e&&!(void 0===e.value&&void 0===e.writable)}function f(e,t){var i=e[t];if(void 0!==i&&"function"!=typeof i)throw new TypeError("Expected '"+t+"' to be a function");return i}function p(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}function m(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,r=new Array(t);i<t;i++)r[i]=e[i];return r}function v(e,t,i){return(v="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=k(e)););return e}(e,t);if(r){var o=Object.getOwnPropertyDescriptor(r,t);return o.get?o.get.call(i):o.value}})(e,t,i||e)}function k(e){return(k=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}!function(e,t,i,r){var o=l();if(r)for(var n=0;n<r.length;n++)o=r[n](o);var a=t((function(e){o.initializeInstanceElements(e,s.elements)}),i),s=o.decorateClass(function(e){for(var t=[],i=function(e){return"method"===e.kind&&e.key===n.key&&e.placement===n.placement},r=0;r<e.length;r++){var o,n=e[r];if("method"===n.kind&&(o=t.find(i)))if(u(n.descriptor)||u(o.descriptor)){if(h(n)||h(o))throw new ReferenceError("Duplicated methods ("+n.key+") can't be decorated.");o.descriptor=n.descriptor}else{if(h(n)){if(h(o))throw new ReferenceError("Decorators can't be placed on different accessors with for the same property ("+n.key+").");o.decorators=n.decorators}c(n,o)}else t.push(n)}return t}(a.d.map(d)),e);o.initializeClassElements(a.F,s.elements),o.runClassFinishers(a.F,s.finishers)}([(0,r.Mo)("ha-location-editor")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[(0,r.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,r.Cb)({type:Array})],key:"location",value:void 0},{kind:"field",decorators:[(0,r.Cb)({type:Number})],key:"radius",value:void 0},{kind:"field",decorators:[(0,r.Cb)()],key:"radiusColor",value:void 0},{kind:"field",decorators:[(0,r.Cb)()],key:"icon",value:void 0},{kind:"field",decorators:[(0,r.Cb)({type:Boolean})],key:"darkMode",value:void 0},{kind:"field",key:"fitZoom",value:()=>16},{kind:"field",key:"_iconEl",value:void 0},{kind:"field",key:"_ignoreFitToMap",value:void 0},{kind:"field",key:"Leaflet",value:void 0},{kind:"field",key:"_leafletMap",value:void 0},{kind:"field",key:"_tileLayer",value:void 0},{kind:"field",key:"_locationMarker",value:void 0},{kind:"method",key:"fitMap",value:function(){this._leafletMap&&this.location&&(this._locationMarker&&"getBounds"in this._locationMarker?this._leafletMap.fitBounds(this._locationMarker.getBounds()):this._leafletMap.setView(this.location,this.fitZoom),this._ignoreFitToMap=this.location)}},{kind:"method",key:"render",value:function(){return r.dy` <div id="map"></div> `}},{kind:"method",key:"firstUpdated",value:function(e){v(k(i.prototype),"firstUpdated",this).call(this,e),this._initMap()}},{kind:"method",key:"updated",value:function(e){if(v(k(i.prototype),"updated",this).call(this,e),this.Leaflet&&(e.has("location")&&(this._updateMarker(),!this.location||this._ignoreFitToMap&&this._ignoreFitToMap[0]===this.location[0]&&this._ignoreFitToMap[1]===this.location[1]||this.fitMap()),e.has("radius")&&this._updateRadius(),e.has("radiusColor")&&this._updateRadiusColor(),e.has("icon")&&this._updateIcon(),e.has("hass"))){var t,r,o;const i=e.get("hass");if(!i||(null===(t=i.themes)||void 0===t?void 0:t.darkMode)===(null===(r=this.hass.themes)||void 0===r?void 0:r.darkMode))return;if(!this._leafletMap||!this._tileLayer)return;this._tileLayer=(0,n.C)(this.Leaflet,this._leafletMap,this._tileLayer,null===(o=this.hass.themes)||void 0===o?void 0:o.darkMode)}}},{kind:"get",key:"_mapEl",value:function(){return this.shadowRoot.querySelector("div")}},{kind:"method",key:"_initMap",value:async function(){var e,t;[this._leafletMap,this.Leaflet,this._tileLayer]=await(0,n.F)(this._mapEl,null!==(e=this.darkMode)&&void 0!==e?e:null===(t=this.hass.themes)||void 0===t?void 0:t.darkMode,Boolean(this.radius)),this._leafletMap.addEventListener("click",(e=>this._locationUpdated(e.latlng))),this._updateIcon(),this._updateMarker(),this.fitMap(),this._leafletMap.invalidateSize()}},{kind:"method",key:"_locationUpdated",value:function(e){let t=e.lng;Math.abs(t)>180&&(t=(t%360+540)%360-180),this.location=this._ignoreFitToMap=[e.lat,t],(0,o.B)(this,"change",void 0,{bubbles:!1})}},{kind:"method",key:"_radiusUpdated",value:function(){this._ignoreFitToMap=this.location,this.radius=this._locationMarker.getRadius(),(0,o.B)(this,"change",void 0,{bubbles:!1})}},{kind:"method",key:"_updateIcon",value:function(){if(!this.icon)return void(this._iconEl=void 0);let e="";const t=document.createElement("ha-icon");t.setAttribute("icon",this.icon),e=t.outerHTML,this._iconEl=this.Leaflet.divIcon({html:e,iconSize:[24,24],className:"light leaflet-edit-move"}),this._setIcon()}},{kind:"method",key:"_setIcon",value:function(){if(!this._locationMarker||!this._iconEl)return;if(!this.radius)return void this._locationMarker.setIcon(this._iconEl);this._locationMarker.editing._moveMarker.setIcon(this._iconEl)}},{kind:"method",key:"_setupEdit",value:function(){this._locationMarker.editing.enable();const e=this._locationMarker.editing._moveMarker,t=this._locationMarker.editing._resizeMarkers[0];this._setIcon(),e.addEventListener("dragend",(e=>this._locationUpdated(e.target.getLatLng()))),t.addEventListener("dragend",(e=>this._radiusUpdated(e)))}},{kind:"method",key:"_updateMarker",value:async function(){if(this.location)return this._locationMarker?(this._locationMarker.setLatLng(this.location),void(this.radius&&(this._locationMarker.editing.disable(),await(0,a.y)(),this._setupEdit()))):void(this.radius?(this._locationMarker=this.Leaflet.circle(this.location,{color:this.radiusColor||s.V3,radius:this.radius}),this._leafletMap.addLayer(this._locationMarker),this._setupEdit()):(this._locationMarker=this.Leaflet.marker(this.location,{draggable:!0}),this._setIcon(),this._locationMarker.addEventListener("dragend",(e=>this._locationUpdated(e.target.getLatLng()))),this._leafletMap.addLayer(this._locationMarker)));this._locationMarker&&(this._locationMarker.remove(),this._locationMarker=void 0)}},{kind:"method",key:"_updateRadius",value:function(){this._locationMarker&&this.radius&&this._locationMarker.setRadius(this.radius)}},{kind:"method",key:"_updateRadiusColor",value:function(){this._locationMarker&&this.radius&&this._locationMarker.setStyle({color:this.radiusColor})}},{kind:"get",static:!0,key:"styles",value:function(){return r.iv`
:host {
display: block;
height: 300px;
}
#map {
height: 100%;
background: inherit;
}
.leaflet-edit-move {
border-radius: 50%;
cursor: move !important;
}
.leaflet-edit-resize {
border-radius: 50%;
cursor: nesw-resize !important;
}
`}}]}}),r.oi)}}]);
//# sourceMappingURL=chunk.8352c00101db136c69ea.js.map