iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
10 lines • 9.77 kB
JavaScript
;(self.webpackChunkhome_assistant_frontend=self.webpackChunkhome_assistant_frontend||[]).push([["40389"],{82062:function(e,t,i){i.a(e,(async function(e,t){try{var n=i(61701),s=i(72621),a=(i(71695),i(61893),i(9359),i(70104),i(47021),i(57243)),l=i(50778),o=i(69634),r=i(50602),h=i(45061),d=i(76320),u=i(10916),c=e([r]);r=(c.then?(await c)():c)[0];let f,v,g,m,y,_,k,p=e=>e;const b=(e,t,i)=>180*(0,u.Ff)((0,u.Fv)(e,t,i),t,i)/100;(0,n.Z)([(0,l.Mo)("ha-gauge")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[(0,l.Cb)({type:Number})],key:"min",value(){return 0}},{kind:"field",decorators:[(0,l.Cb)({type:Number})],key:"max",value(){return 100}},{kind:"field",decorators:[(0,l.Cb)({type:Number})],key:"value",value(){return 0}},{kind:"field",decorators:[(0,l.Cb)({attribute:!1})],key:"formatOptions",value:void 0},{kind:"field",decorators:[(0,l.Cb)({attribute:!1,type:String})],key:"valueText",value:void 0},{kind:"field",decorators:[(0,l.Cb)({attribute:!1})],key:"locale",value:void 0},{kind:"field",decorators:[(0,l.Cb)({type:Boolean})],key:"needle",value(){return!1}},{kind:"field",decorators:[(0,l.Cb)({type:Array})],key:"levels",value:void 0},{kind:"field",decorators:[(0,l.Cb)()],key:"label",value(){return""}},{kind:"field",decorators:[(0,l.SB)()],key:"_angle",value(){return 0}},{kind:"field",decorators:[(0,l.SB)()],key:"_updated",value(){return!1}},{kind:"field",decorators:[(0,l.SB)()],key:"_segment_label",value(){return""}},{kind:"method",key:"firstUpdated",value:function(e){(0,s.Z)(i,"firstUpdated",this,3)([e]),(0,d.T)((()=>{this._updated=!0,this._angle=b(this.value,this.min,this.max),this._segment_label=this._getSegmentLabel(),this._rescaleSvg()}))}},{kind:"method",key:"updated",value:function(e){(0,s.Z)(i,"updated",this,3)([e]),this._updated&&(e.has("value")||e.has("valueText")||e.has("label")||e.has("_segment_label"))&&(this._angle=b(this.value,this.min,this.max),this._segment_label=this._getSegmentLabel(),this._rescaleSvg())}},{kind:"method",key:"render",value:function(){return(0,a.YP)(f||(f=p` <svg viewBox="-50 -50 100 50" class="gauge"> ${0} ${0} ${0} </svg> <svg class="text"> <text class="value-text"> ${0}${0} </text> </svg>`),this.needle&&this.levels?"":(0,a.YP)(v||(v=p`<path class="dial" d="M -40 0 A 40 40 0 0 1 40 0"></path>`)),this.levels?this.levels.sort(((e,t)=>e.level-t.level)).map(((e,t)=>{let i;if(0===t&&e.level!==this.min){const e=b(this.min,this.min,this.max);i=(0,a.YP)(g||(g=p`<path stroke="var(--info-color)" class="level" d="M
${0}
${0}
A 40 40 0 0 1 40 0
"></path>`),0-40*Math.cos(e*Math.PI/180),0-40*Math.sin(e*Math.PI/180))}const n=b(e.level,this.min,this.max);return(0,a.YP)(m||(m=p`${0}<path stroke="${0}" class="level" d="M
${0}
${0}
A 40 40 0 0 1 40 0
"></path>`),i,e.stroke,0-40*Math.cos(n*Math.PI/180),0-40*Math.sin(n*Math.PI/180))})):"",this.needle?(0,a.YP)(y||(y=p`<path class="needle" d="M -25 -2.5 L -47.5 0 L -25 2.5 z" style="${0}"> </path>`),(0,o.V)({transform:`rotate(${this._angle}deg)`})):(0,a.YP)(_||(_=p`<path class="value" d="M -40 0 A 40 40 0 1 0 40 0" style="${0}"></path>`),(0,o.V)({transform:`rotate(${this._angle}deg)`})),this._segment_label?this._segment_label:this.valueText||(0,r.uf)(this.value,this.locale,this.formatOptions),this._segment_label?"":"%"===this.label?(0,h.K)(this.locale)+"%":` ${this.label}`)}},{kind:"method",key:"_rescaleSvg",value:function(){const e=this.shadowRoot.querySelector(".text"),t=e.querySelector("text").getBBox();e.setAttribute("viewBox",`${t.x} ${t.y} ${t.width} ${t.height}`)}},{kind:"method",key:"_getSegmentLabel",value:function(){if(this.levels){this.levels.sort(((e,t)=>e.level-t.level));for(let e=this.levels.length-1;e>=0;e--)if(this.value>=this.levels[e].level)return this.levels[e].label}return""}},{kind:"field",static:!0,key:"styles",value(){return(0,a.iv)(k||(k=p`:host{position:relative}.dial{fill:none;stroke:var(--primary-background-color);stroke-width:15}.value{fill:none;stroke-width:15;stroke:var(--gauge-color);transition:all 1s ease 0s}.needle{fill:var(--primary-text-color);transition:all 1s ease 0s}.level{fill:none;stroke-width:15}.gauge{display:block}.text{position:absolute;max-height:40%;max-width:55%;left:50%;bottom:-6%;transform:translate(-50%,0%)}.value-text{font-size:50px;fill:var(--primary-text-color);text-anchor:middle;direction:ltr}`))}}]}}),a.oi);t()}catch(f){t(f)}}))},10188:function(e,t,i){i.a(e,(async function(e,n){try{i.r(t),i.d(t,{DEFAULT_MAX:()=>P,DEFAULT_MIN:()=>L,severityMap:()=>B});var s=i(61701),a=i(72621),l=(i(52247),i(71695),i(61893),i(9359),i(70104),i(19423),i(40251),i(47021),i(57243)),o=i(50778),r=i(20552),h=i(35359),d=i(69634),u=i(82393),c=i(47194),f=i(31064),v=i(50602),g=(i(54977),i(82062)),m=i(96194),y=i(3967),_=i(69223),k=i(1617),p=i(5684),b=i(93331),x=i(62577),$=e([g,v]);[g,v]=$.then?(await $)():$;let w,M,C,N,S,A=e=>e;const L=0,P=100,B={red:"var(--error-color)",green:"var(--success-color)",yellow:"var(--warning-color)",normal:"var(--info-color)"};(0,s.Z)([(0,o.Mo)("hui-gauge-card")],(function(e,t){class n extends t{constructor(...t){super(...t),e(this)}}return{F:n,d:[{kind:"method",static:!0,key:"getConfigElement",value:async function(){return await i.e("96212").then(i.bind(i,32137)),document.createElement("hui-gauge-card-editor")}},{kind:"method",static:!0,key:"getStubConfig",value:function(e,t,i){return{type:"gauge",entity:(0,_.j)(e,1,t,i,["counter","input_number","number","sensor"],(e=>!isNaN(Number(e.state))))[0]||""}}},{kind:"field",decorators:[(0,o.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,o.SB)()],key:"_config",value:void 0},{kind:"method",key:"getCardSize",value:function(){return 4}},{kind:"method",key:"setConfig",value:function(e){if(!e.entity)throw new Error("Entity must be specified");if(!(0,f.T)(e.entity))throw new Error("Invalid entity");this._config=Object.assign({min:L,max:P},e)}},{kind:"method",key:"render",value:function(){var e,t;if(!this._config||!this.hass)return l.Ld;const i=this.hass.states[this._config.entity];if(!i)return(0,l.dy)(w||(w=A` <hui-warning> ${0} </hui-warning> `),(0,x.i)(this.hass,this._config.entity));const n=Number(i.state);if(i.state===m.nZ)return(0,l.dy)(M||(M=A` <hui-warning>${0}</hui-warning> `),this.hass.localize("ui.panel.lovelace.warning.entity_unavailable",{entity:this._config.entity}));if(isNaN(n))return(0,l.dy)(C||(C=A` <hui-warning>${0}</hui-warning> `),this.hass.localize("ui.panel.lovelace.warning.entity_non_numeric",{entity:this._config.entity}));const s=null!==(e=this._config.name)&&void 0!==e?e:(0,c.C)(i);return(0,l.dy)(N||(N=A` <ha-card class="${0}" @action="${0}" .actionHandler="${0}" tabindex="${0}"> <ha-gauge .min="${0}" .max="${0}" .value="${0}" .formatOptions="${0}" .locale="${0}" .label="${0}" style="${0}" .needle="${0}" .levels="${0}"></ha-gauge> <div class="name" .title="${0}">${0}</div> </ha-card> `),(0,h.$)({action:(0,p.q)(this._config)}),this._handleAction,(0,y.K)({hasHold:(0,p._)(this._config.hold_action),hasDoubleClick:(0,p._)(this._config.double_tap_action)}),(0,r.o)(!this._config.tap_action||(0,p._)(this._config.tap_action)?"0":void 0),this._config.min,this._config.max,i.state,(0,v.l4)(i,this.hass.entities[i.entity_id]),this.hass.locale,this._config.unit||(null===(t=this.hass)||void 0===t?void 0:t.states[this._config.entity].attributes.unit_of_measurement)||"",(0,d.V)({"--gauge-color":this._computeSeverity(n)}),this._config.needle,this._config.needle?this._severityLevels():void 0,s,s)}},{kind:"method",key:"shouldUpdate",value:function(e){return(0,b.G2)(this,e)}},{kind:"method",key:"updated",value:function(e){if((0,a.Z)(n,"updated",this,3)([e]),!this._config||!this.hass)return;const t=e.get("hass"),i=e.get("_config");t&&i&&t.themes===this.hass.themes&&i.theme===this._config.theme||(0,u.R)(this,this.hass.themes,this._config.theme)}},{kind:"method",key:"_computeSeverity",value:function(e){if(this._config.needle)return;let t=this._config.segments;if(t){t=[...t].sort(((e,t)=>e.from-t.from));for(let n=0;n<t.length;n++){var i;const s=t[n];if(s&&e>=s.from&&(n+1===t.length||e<(null===(i=t[n+1])||void 0===i?void 0:i.from)))return s.color}return B.normal}const n=this._config.severity;if(!n)return B.normal;const s=Object.keys(n).map((e=>[e,n[e]]));for(const a of s)if(null==B[a[0]]||isNaN(a[1]))return B.normal;return s.sort(((e,t)=>e[1]-t[1])),e>=s[0][1]&&e<s[1][1]?B[s[0][0]]:e>=s[1][1]&&e<s[2][1]?B[s[1][0]]:e>=s[2][1]?B[s[2][0]]:B.normal}},{kind:"method",key:"_severityLevels",value:function(){const e=this._config.segments;if(e)return e.map((e=>({level:null==e?void 0:e.from,stroke:null==e?void 0:e.color,label:null==e?void 0:e.label})));const t=this._config.severity;if(!t)return[{level:0,stroke:B.normal}];return Object.keys(t).map((e=>({level:t[e],stroke:B[e]})))}},{kind:"method",key:"_handleAction",value:function(e){(0,k.G)(this,this.hass,this._config,e.detail.action)}},{kind:"field",static:!0,key:"styles",value(){return(0,l.iv)(S||(S=A`ha-card{height:100%;overflow:hidden;padding:16px;display:flex;align-items:center;justify-content:center;flex-direction:column;box-sizing:border-box}ha-card.action{cursor:pointer}ha-card:focus{outline:0}ha-gauge{width:100%;max-width:250px}.name{text-align:center;line-height:initial;color:var(--primary-text-color);width:100%;font-size:15px;margin-top:8px}`))}}]}}),l.oi);n()}catch(w){n(w)}}))},10916:function(e,t,i){i.d(t,{Ff:()=>s,Fv:()=>n,IU:()=>a});const n=(e,t,i)=>isNaN(e)||isNaN(t)||isNaN(i)?0:e>i?i:e<t?t:e,s=(e,t,i)=>100*(e-t)/(i-t),a=e=>Math.round(10*e)/10}}]);
//# sourceMappingURL=40389.779c5c73020df8ff.js.map