iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 10.2 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[21727],{5127:function(t,e,i){i.a(t,async function(t,e){try{i(26910),i(13609),i(18111),i(61701),i(62953);var s=i(40445),a=i(5124),n=i(67576),o=i(89784),r=i(20058),l=i(67258),h=i(12587),c=i(36240),u=t([r]);r=(u.then?(await u)():u)[0];let d,g,v,f,p,_,m,y=t=>t;const b=(t,e,i)=>180*(0,c.NN)((0,c.S8)(t,e,i),e,i)/100;class $ extends a.WF{connectedCallback(){super.connectedCallback(),this._rescaleOnConnect&&(this._rescaleSvg(),this._rescaleOnConnect=!1)}firstUpdated(t){super.firstUpdated(t),(0,h.m)(()=>{this._updated=!0,this.needle&&(this._angle=b(this.value,this.min,this.max)),this._segment_label=this._getSegmentLabel(),this._rescaleSvg()})}willUpdate(t){(t.has("levels")||t.has("min"))&&(this.levels?(this._sortedLevels=[...this.levels].sort((t,e)=>t.level-e.level),this._sortedLevels.length>0&&this._sortedLevels[0].level!==this.min&&this._sortedLevels.unshift({level:this.min,stroke:"var(--info-color)"})):this._sortedLevels=void 0)}updated(t){super.updated(t),this._updated&&(t.has("value")||t.has("valueText")||t.has("label")||t.has("_segment_label"))&&(this._angle=b(this.value,this.min,this.max),this._segment_label=this._getSegmentLabel(),this._rescaleSvg())}render(){var t;const e=40,i=Math.PI*e,s=b(this.value,this.min,this.max),n=this._updated?i*(1-s/180):i;return(0,a.JW)(d||(d=y` <svg viewBox="-50 -50 100 55" class="gauge"> <path class="levels-base" d="M -40 0 A 40 40 0 0 1 40 0"/> ${0} ${0} </svg> <svg class="text"> <text class="value-text" x="0" y="-5" dominant-baseline="middle" text-anchor="middle"> ${0}${0} </text> </svg> `),null===(t=this._sortedLevels)||void 0===t?void 0:t.map((t,i,s)=>{const n=t.level,o=i+1<s.length?s[i+1].level:this.max,r=b(n,this.min,this.max),l=b(o,this.min,this.max),h=l-r>180?1:0,c=-40*Math.cos(r*Math.PI/180),u=-40*Math.sin(r*Math.PI/180),d=0===i,p=i===s.length-1;if(d)return(0,a.JW)(g||(g=y` <path class="level" stroke="${0}" style="stroke-linecap:butt" d="M ${0} ${0} A ${0} ${0} 0 ${0} 1 40 0"/> `),t.stroke,c,u,e,e,h);if(p){const i=l-.5,s=-40*Math.cos(i*Math.PI/180),n=-40*Math.sin(i*Math.PI/180);return(0,a.JW)(v||(v=y` <path class="level" stroke="${0}" style="stroke-linecap:butt" d="M ${0} ${0} A ${0} ${0} 0 ${0} 1 40 0"/> <path class="level" stroke="${0}" style="stroke-linecap:butt" d="M ${0} ${0} A ${0} ${0} 0 0 1 40 0"/> `),t.stroke,c,u,e,e,h,t.stroke,s,n,e,e)}return(0,a.JW)(f||(f=y` <path class="level" stroke="${0}" style="stroke-linecap:butt" d="M ${0} ${0} A ${0} ${0} 0 ${0} 1 40 0"></path> `),t.stroke,c,u,e,e,h)}),this.needle?(0,a.JW)(p||(p=y` <path class="needle" d="M -34,-3 L -40,-1 A 1,1,0,0,0,-40,1 L -34,3 A 2,2,0,0,0,-34,-3 Z" style="${0}"/> `),(0,o.W)({transform:`rotate(${this._angle}deg)`})):(0,a.JW)(_||(_=y` <path class="value" d="M -40 0 A 40 40 0 0 1 40 0" stroke-dasharray="${0}" style="${0}"/> `),i,(0,o.W)({strokeDashoffset:`${n}`})),this._segment_label?this._segment_label:this.valueText||(0,r.ZV)(this.value,this.locale,this.formatOptions),this._segment_label?"":"%"===this.label?(0,l.d)(this.locale)+"%":` ${this.label}`)}_rescaleSvg(){if(!this.isConnected)return void(this._rescaleOnConnect=!0);const t=this.shadowRoot.querySelector(".text"),e=t.querySelector("text").getBBox();t.setAttribute("viewBox",`${e.x} ${e.y} ${e.width} ${e.height}`)}_getSegmentLabel(){if(this._sortedLevels)for(let t=this._sortedLevels.length-1;t>=0;t--)if(this.value>=this._sortedLevels[t].level)return this._sortedLevels[t].label;return""}constructor(...t){super(...t),this.min=0,this.max=100,this.value=0,this.needle=!1,this.label="",this._angle=0,this._updated=!1,this._segment_label="",this._rescaleOnConnect=!1}}$.styles=(0,a.AH)(m||(m=y`:host{position:relative}.levels-base{fill:none;stroke:var(--primary-background-color);stroke-width:12;stroke-linecap:butt}.level{fill:none;stroke-width:12;stroke-linecap:butt}.value{fill:none;stroke-width:12;stroke:var(--gauge-color);stroke-linecap:butt;transition:stroke-dashoffset 1s ease 0s}.needle{fill:var(--primary-text-color);stroke:var(--card-background-color);color:var(--primary-text-color);stroke-width:1;stroke-linecap:round;transform-origin:0 0;transition:all 1s ease 0s}.text{position:absolute;max-height:40%;max-width:55%;left:50%;bottom:10%;transform:translate(-50%,0%)}.value-text{font-size:var(--ha-font-size-l);fill:var(--primary-text-color);direction:ltr}`)),(0,s.Cg)([(0,n.MZ)({type:Number})],$.prototype,"min",void 0),(0,s.Cg)([(0,n.MZ)({type:Number})],$.prototype,"max",void 0),(0,s.Cg)([(0,n.MZ)({type:Number})],$.prototype,"value",void 0),(0,s.Cg)([(0,n.MZ)({attribute:!1})],$.prototype,"formatOptions",void 0),(0,s.Cg)([(0,n.MZ)({attribute:!1})],$.prototype,"valueText",void 0),(0,s.Cg)([(0,n.MZ)({attribute:!1})],$.prototype,"locale",void 0),(0,s.Cg)([(0,n.MZ)({type:Boolean})],$.prototype,"needle",void 0),(0,s.Cg)([(0,n.MZ)({type:Array})],$.prototype,"levels",void 0),(0,s.Cg)([(0,n.MZ)()],$.prototype,"label",void 0),(0,s.Cg)([(0,n.wk)()],$.prototype,"_angle",void 0),(0,s.Cg)([(0,n.wk)()],$.prototype,"_updated",void 0),(0,s.Cg)([(0,n.wk)()],$.prototype,"_segment_label",void 0),$=(0,s.Cg)([(0,n.EM)("ha-gauge")],$),e()}catch(d){e(d)}})},91874:function(t,e,i){i.a(t,async function(t,s){try{i.r(e),i.d(e,{DEFAULT_MAX:function(){return A},DEFAULT_MIN:function(){return L},severityMap:function(){return S}});i(16280),i(26910),i(18111),i(20116),i(61701),i(3362),i(62953);var a=i(40445),n=i(5124),o=i(67576),r=i(6412),l=i(63672),h=i(89784),c=i(42372),u=i(78536),d=i(78649),g=(i(76776),i(5127)),v=i(22675),f=i(19037),p=i(13632),_=i(22064),m=i(97176),y=i(784),b=i(85979),$=t([g,b]);[g,b]=$.then?(await $)():$;let x,k,w,M,C,N=t=>t;const L=0,A=100,S={red:"var(--error-color)",green:"var(--success-color)",yellow:"var(--warning-color)",normal:"var(--info-color)"};class E extends n.WF{static async getConfigElement(){return await i.e(88292).then(i.bind(i,89647)),document.createElement("hui-gauge-card-editor")}static getStubConfig(t,e,i){return{type:"gauge",entity:(0,p.B)(t,1,e,i,["counter","input_number","number","sensor"],t=>!isNaN(Number(t.state)))[0]||""}}getCardSize(){return 4}setConfig(t){if(!t.entity)throw new Error("Entity must be specified");if(!(0,d.n)(t.entity))throw new Error("Invalid entity");this._config=Object.assign({min:L,max:A},t)}render(){var t,e;if(!this._config||!this.hass)return n.s6;const i=this.hass.states[this._config.entity];if(!i)return(0,n.qy)(x||(x=N` <hui-warning .hass="${0}"> ${0} </hui-warning> `),this.hass,(0,b.j)(this.hass,this._config.entity));if(i.state===v.Hh)return(0,n.qy)(k||(k=N` <hui-warning>${0}</hui-warning> `),this.hass.localize("ui.panel.lovelace.warning.entity_unavailable",{entity:this._config.entity}));let s;s=this._config.attribute?this.hass.formatEntityAttributeValueToParts(i,this._config.attribute):this.hass.formatEntityStateToParts(i);const a=null===(t=s.find(t=>"value"===t.type))||void 0===t?void 0:t.value,o=this._config.attribute?i.attributes[this._config.attribute]:i.state;if(isNaN(o))return(0,n.qy)(w||(w=N` <hui-warning>${0}</hui-warning> `),this.hass.localize(this._config.attribute?"ui.panel.lovelace.warning.attribute_not_numeric":"ui.panel.lovelace.warning.entity_non_numeric",{entity:this._config.entity,attribute:this._config.attribute}));const c=this.hass.formatEntityName(i,this._config.name),d=null!==(e=(0,u.h)(this.hass,i,this._config))&&void 0!==e?e:"";return(0,n.qy)(M||(M=N` <ha-card class="${0}" ="${0}" .actionHandler="${0}" tabindex="${0}"> <ha-gauge .min="${0}" .max="${0}" .value="${0}" .valueText="${0}" .locale="${0}" .label="${0}" style="${0}" .needle="${0}" .levels="${0}"></ha-gauge> <p class="title" .title="${0}">${0}</p> </ha-card> `),(0,r.H)({action:(0,m.A)(this._config)}),this._handleAction,(0,f.T)({hasHold:(0,m.h)(this._config.hold_action),hasDoubleClick:(0,m.h)(this._config.double_tap_action)}),(0,l.J)(!this._config.tap_action||(0,m.h)(this._config.tap_action)?"0":void 0),this._config.min,this._config.max,o,a,this.hass.locale,d,(0,h.W)({"--gauge-color":this._computeSeverity(Number(o))}),this._config.needle,this._config.needle?this._severityLevels():void 0,c,c)}shouldUpdate(t){return(0,y.LX)(this,t)}updated(t){if(super.updated(t),!this._config||!this.hass)return;const e=t.get("hass"),i=t.get("_config");e&&i&&e.themes===this.hass.themes&&i.theme===this._config.theme||(0,c.Q)(this,this.hass.themes,this._config.theme)}_computeSeverity(t){if(this._config.needle)return;let e=this._config.segments;if(e){e=[...e].sort((t,e)=>t.from-e.from);for(let s=0;s<e.length;s++){var i;const a=e[s];if(a&&t>=a.from&&(s+1===e.length||t<(null===(i=e[s+1])||void 0===i?void 0:i.from)))return a.color}return S.normal}const s=this._config.severity;if(!s)return S.normal;const a=Object.keys(s).map(t=>[t,s[t]]);for(const n of a)if(null==S[n[0]]||isNaN(n[1]))return S.normal;return a.sort((t,e)=>t[1]-e[1]),t>=a[0][1]&&t<a[1][1]?S[a[0][0]]:t>=a[1][1]&&t<a[2][1]?S[a[1][0]]:t>=a[2][1]?S[a[2][0]]:S.normal}_severityLevels(){const t=this._config.segments;if(t)return t.map(t=>({level:null==t?void 0:t.from,stroke:null==t?void 0:t.color,label:null==t?void 0:t.label}));const e=this._config.severity;if(!e)return[{level:0,stroke:S.normal}];return Object.keys(e).map(t=>({level:e[t],stroke:S[t]}))}_handleAction(t){(0,_.$)(this,this.hass,this._config,t.detail.action)}}E.styles=(0,n.AH)(C||(C=N`ha-card{height:100%;overflow:hidden;padding:var(--ha-space-3);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}.title{width:100%;font-size:var(--ha-font-size-m);line-height:var(--ha-line-height-expanded);margin:0;text-align:center;box-sizing:border-box;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:none;color:var(--primary-text-color)}ha-gauge{width:100%;max-width:250px}`)),(0,a.Cg)([(0,o.MZ)({attribute:!1})],E.prototype,"hass",void 0),(0,a.Cg)([(0,o.wk)()],E.prototype,"_config",void 0),E=(0,a.Cg)([(0,o.EM)("hui-gauge-card")],E),s()}catch(x){s(x)}})},36240:function(t,e,i){i.d(e,{NN:function(){return a},S8:function(){return s},gN:function(){return n}});const s=(t,e,i)=>isNaN(t)||isNaN(e)||isNaN(i)?0:t>i?i:t<e?e:t,a=(t,e,i)=>100*(t-e)/(i-e),n=t=>Math.round(10*t)/10}}]);