UNPKG

iobroker.lovelace

Version:

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

177 lines (162 loc) 16.1 kB
(self.webpackChunkhome_assistant_frontend=self.webpackChunkhome_assistant_frontend||[]).push([[8558],{68558:(e,t,i)=>{"use strict";i.r(t),i.d(t,{HuiHumidifierCard:()=>_});i(32333);var r=i(50424),n=i(55358),o=i(62877),s=i(47181),a=i(91741),d=i(87744),l=(i(22098),i(10983),i(56007)),c=i(15688),u=i(53658),h=i(75502);function f(){f=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 n=t.placement;if(t.kind===r&&("static"===n||"prototype"===n)){var o="static"===n?e:i;this.defineClassElement(o,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=[],n={static:[],prototype:[],own:[]};if(e.forEach((function(e){this.addElementPlacement(e,n)}),this),e.forEach((function(e){if(!y(e))return i.push(e);var t=this.decorateElement(e,n);i.push(t.element),i.push.apply(i,t.extras),r.push.apply(r,t.finishers)}),this),!t)return{elements:i,finishers:r};var o=this.decorateConstructor(i,t);return r.push.apply(r,o.finishers),o.finishers=r,o},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=[],n=e.decorators,o=n.length-1;o>=0;o--){var s=t[e.placement];s.splice(s.indexOf(e.key),1);var a=this.fromElementDescriptor(e),d=this.toElementFinisherExtras((0,n[o])(a)||a);e=d.element,this.addElementPlacement(e,t),d.finisher&&r.push(d.finisher);var l=d.extras;if(l){for(var c=0;c<l.length;c++)this.addElementPlacement(l[c],t);i.push.apply(i,l)}}return{element:e,finishers:r,extras:i}},decorateConstructor:function(e,t){for(var i=[],r=t.length-1;r>=0;r--){var n=this.fromClassDescriptor(e),o=this.toClassDescriptor((0,t[r])(n)||n);if(void 0!==o.finisher&&i.push(o.finisher),void 0!==o.elements){e=o.elements;for(var s=0;s<e.length-1;s++)for(var a=s+1;a<e.length;a++)if(e[s].key===e[a].key&&e[s].placement===e[a].placement)throw new TypeError("Duplicated element ("+e[s].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&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||function(e,t){if(e){if("string"==typeof e)return k(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)?k(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=b(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 n=e.descriptor;this.disallowProperty(e,"elements","An element descriptor");var o={kind:t,key:i,placement:r,descriptor:Object.assign({},n)};return"field"!==t?this.disallowProperty(e,"initializer","A method descriptor"):(this.disallowProperty(n,"get","The property descriptor of a field descriptor"),this.disallowProperty(n,"set","The property descriptor of a field descriptor"),this.disallowProperty(n,"value","The property descriptor of a field descriptor"),o.initializer=e.initializer),o},toElementFinisherExtras:function(e){return{element:this.toElementDescriptor(e),finisher:g(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=g(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 p(e){var t,i=b(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 m(e,t){void 0!==e.descriptor.get?t.descriptor.get=e.descriptor.get:t.descriptor.set=e.descriptor.set}function y(e){return e.decorators&&e.decorators.length}function v(e){return void 0!==e&&!(void 0===e.value&&void 0===e.writable)}function g(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 b(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 k(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 w(e,t,i){return(w="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=x(e)););return e}(e,t);if(r){var n=Object.getOwnPropertyDescriptor(r,t);return n.get?n.get.call(i):n.value}})(e,t,i||e)}function x(e){return(x=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}let _=function(e,t,i,r){var n=f();if(r)for(var o=0;o<r.length;o++)n=r[o](n);var s=t((function(e){n.initializeInstanceElements(e,a.elements)}),i),a=n.decorateClass(function(e){for(var t=[],i=function(e){return"method"===e.kind&&e.key===o.key&&e.placement===o.placement},r=0;r<e.length;r++){var n,o=e[r];if("method"===o.kind&&(n=t.find(i)))if(v(o.descriptor)||v(n.descriptor)){if(y(o)||y(n))throw new ReferenceError("Duplicated methods ("+o.key+") can't be decorated.");n.descriptor=o.descriptor}else{if(y(o)){if(y(n))throw new ReferenceError("Decorators can't be placed on different accessors with for the same property ("+o.key+").");n.decorators=o.decorators}m(o,n)}else t.push(o)}return t}(s.d.map(p)),e);return n.initializeClassElements(s.F,a.elements),n.runClassFinishers(s.F,a.finishers)}([(0,n.Mo)("hui-humidifier-card")],(function(e,t){class f extends t{constructor(...t){super(...t),e(this)}}return{F:f,d:[{kind:"method",static:!0,key:"getConfigElement",value:async function(){return await Promise.all([i.e(5009),i.e(2955),i.e(8161),i.e(1041),i.e(1657),i.e(4268),i.e(3098),i.e(129),i.e(4535),i.e(7210)]).then(i.bind(i,57210)),document.createElement("hui-humidifier-card-editor")}},{kind:"method",static:!0,key:"getStubConfig",value:function(e,t,i){return{type:"humidifier",entity:(0,c.j)(e,1,t,i,["humidifier"])[0]||""}}},{kind:"field",decorators:[(0,n.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,n.SB)()],key:"_config",value:void 0},{kind:"field",decorators:[(0,n.SB)()],key:"_setHum",value:void 0},{kind:"method",key:"getCardSize",value:function(){return 6}},{kind:"method",key:"setConfig",value:function(e){if(!e.entity||"humidifier"!==e.entity.split(".")[0])throw new Error("Specify an entity from within the humidifier domain");this._config=e}},{kind:"method",key:"render",value:function(){if(!this.hass||!this._config)return r.dy``;const e=this.hass.states[this._config.entity];if(!e)return r.dy` <hui-warning> ${(0,h.i)(this.hass,this._config.entity)} </hui-warning> `;const t=this._config.name||(0,a.C)(this.hass.states[this._config.entity]),i=null!==e.attributes.humidity&&Number.isFinite(Number(e.attributes.humidity))?e.attributes.humidity:e.attributes.min_humidity,n=(0,d.Zu)(this.hass),o=l.V_.includes(e.state)?r.dy` <round-slider disabled="true"></round-slider> `:r.dy` <round-slider .value=${i} .min=${e.attributes.min_humidity} .max=${e.attributes.max_humidity} .rtl=${"rtl"===n} step="1" @value-changing=${this._dragEvent} @value-changed=${this._setHumidity} ></round-slider> `,s=r.YP` <svg viewBox="0 0 40 20"> <text x="50%" dx="1" y="60%" text-anchor="middle" style="font-size: 13px;" class="set-value" > ${l.V_.includes(e.state)||void 0===this._setHum||null===this._setHum?"":r.YP` ${this._setHum.toFixed()} <tspan dx="-3" dy="-6.5" style="font-size: 4px;"> % </tspan> `} </text> </svg> <svg id="set-values"> <g> <text dy="22" text-anchor="middle" id="set-mode" > ${this.hass.localize(`state.default.${e.state}`)} ${e.attributes.mode&&!l.V_.includes(e.state)?r.dy` - ${this.hass.localize(`state_attributes.humidifier.mode.${e.attributes.mode}`)||e.attributes.mode} `:""} </text> </g> </svg> `;return r.dy` <ha-card> <ha-icon-button icon="hass:dots-vertical" class="more-info" @click=${this._handleMoreInfo} tabindex="0" ></ha-icon-button> <div class="content"> <div id="controls"> <div id="slider"> ${o} <div id="slider-center"> <div id="humidity">${s}</div> </div> </div> </div> <div id="info">${t}</div> </div> </ha-card> `}},{kind:"method",key:"shouldUpdate",value:function(e){return(0,u.G)(this,e)}},{kind:"method",key:"updated",value:function(e){if(w(x(f.prototype),"updated",this).call(this,e),!this._config||!this.hass||!e.has("hass")&&!e.has("_config"))return;const t=e.get("hass"),i=e.get("_config");t&&i&&t.themes===this.hass.themes&&i.theme===this._config.theme||(0,o.R)(this,this.hass.themes,this._config.theme);const r=this.hass.states[this._config.entity];r&&(t&&t.states[this._config.entity]===r||this._rescale_svg())}},{kind:"method",key:"willUpdate",value:function(e){if(!this.hass||!this._config||!e.has("hass"))return;const t=this.hass.states[this._config.entity];if(!t)return;const i=e.get("hass");i&&i.states[this._config.entity]===t||(this._setHum=this._getSetHum(t))}},{kind:"method",key:"_rescale_svg",value:function(){this.shadowRoot&&this.shadowRoot.querySelector("ha-card")&&this.shadowRoot.querySelector("ha-card").updateComplete.then((()=>{const e=this.shadowRoot.querySelector("#set-values"),t=e.querySelector("g").getBBox();e.setAttribute("viewBox",`${t.x} ${t.y} ${t.width} ${t.height}`),e.setAttribute("width",`${t.width}`),e.setAttribute("height",`${t.height}`)}))}},{kind:"method",key:"_getSetHum",value:function(e){if(!l.V_.includes(e.state))return e.attributes.humidity}},{kind:"method",key:"_dragEvent",value:function(e){this._setHum=e.detail.value}},{kind:"method",key:"_setHumidity",value:function(e){this.hass.callService("humidifier","set_humidity",{entity_id:this._config.entity,humidity:e.detail.value})}},{kind:"method",key:"_handleMoreInfo",value:function(){(0,s.B)(this,"hass-more-info",{entityId:this._config.entity})}},{kind:"get",static:!0,key:"styles",value:function(){return r.iv` :host { display: block; } ha-card { height: 100%; position: relative; overflow: hidden; --name-font-size: 1.2rem; --brightness-font-size: 1.2rem; --rail-border-color: transparent; } .more-info { position: absolute; cursor: pointer; top: 0; right: 0; border-radius: 100%; color: var(--secondary-text-color); z-index: 25; } .content { height: 100%; display: flex; flex-direction: column; justify-content: center; } #controls { display: flex; justify-content: center; padding: 16px; position: relative; } #slider { height: 100%; width: 100%; position: relative; max-width: 250px; min-width: 100px; } round-slider { --round-slider-path-color: var(--disabled-text-color); --round-slider-bar-color: var(--mode-color); padding-bottom: 10%; } #slider-center { position: absolute; width: calc(100% - 40px); height: calc(100% - 40px); box-sizing: border-box; border-radius: 100%; left: 20px; top: 20px; text-align: center; overflow-wrap: break-word; pointer-events: none; } #humidity { position: absolute; transform: translate(-50%, -50%); width: 100%; height: 50%; top: 45%; left: 50%; } #set-values { max-width: 80%; transform: translate(0, -50%); font-size: 20px; } #set-mode { fill: var(--secondary-text-color); font-size: 16px; } #info { display: flex-vertical; justify-content: center; text-align: center; padding: 16px; margin-top: -60px; font-size: var(--name-font-size); } #modes > * { color: var(--disabled-text-color); cursor: pointer; display: inline-block; } #modes .selected-icon { color: var(--mode-color); } text { fill: var(--primary-text-color); } `}}]}}),r.oi)}}]); //# sourceMappingURL=chunk.56f0fb203086151c658c.js.map