UNPKG

iobroker.lovelace

Version:

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

1 lines 9.55 kB
export const __rspack_esm_id=21727;export const __rspack_esm_ids=[21727];export const __webpack_modules__={5127(t,e,s){s.a(t,async function(t,e){try{s(18111),s(61701);var i=s(62826),a=s(5124),o=s(22441),n=s(89784),r=s(20058),l=s(67258),h=s(12587),c=s(36240),d=t([r]);r=(d.then?(await d)():d)[0];const u=(t,e,s)=>180*(0,c.NN)((0,c.S8)(t,e,s),e,s)/100;class g 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=u(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=u(this.value,this.min,this.max),this._segment_label=this._getSegmentLabel(),this._rescaleSvg())}render(){const t=40,e=Math.PI*t,s=u(this.value,this.min,this.max),i=this._updated?e*(1-s/180):e;return a.JW` <svg viewBox="-50 -50 100 55" class="gauge"> <path class="levels-base" d="M -40 0 A 40 40 0 0 1 40 0"/> ${this._sortedLevels?.map((e,s,i)=>{const o=e.level,n=s+1<i.length?i[s+1].level:this.max,r=u(o,this.min,this.max),l=u(n,this.min,this.max),h=l-r>180?1:0,c=-40*Math.cos(r*Math.PI/180),d=-40*Math.sin(r*Math.PI/180),g=0===s,v=s===i.length-1;if(g)return a.JW` <path class="level" stroke="${e.stroke}" style="stroke-linecap:butt" d="M ${c} ${d} A ${t} ${t} 0 ${h} 1 40 0"/> `;if(v){const s=l-.5,i=-40*Math.cos(s*Math.PI/180),o=-40*Math.sin(s*Math.PI/180);return a.JW` <path class="level" stroke="${e.stroke}" style="stroke-linecap:butt" d="M ${c} ${d} A ${t} ${t} 0 ${h} 1 40 0"/> <path class="level" stroke="${e.stroke}" style="stroke-linecap:butt" d="M ${i} ${o} A ${t} ${t} 0 0 1 40 0"/> `}return a.JW` <path class="level" stroke="${e.stroke}" style="stroke-linecap:butt" d="M ${c} ${d} A ${t} ${t} 0 ${h} 1 40 0"></path> `})} ${this.needle?a.JW` <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,n.W)({transform:`rotate(${this._angle}deg)`})}"/> `:a.JW` <path class="value" d="M -40 0 A 40 40 0 0 1 40 0" stroke-dasharray="${e}" style="${(0,n.W)({strokeDashoffset:`${i}`})}"/> `} </svg> <svg class="text"> <text class="value-text" x="0" y="-5" dominant-baseline="middle" text-anchor="middle"> ${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}`} </text> </svg> `}_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}}g.styles=a.AH`: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,i.Cg)([(0,o.MZ)({type:Number})],g.prototype,"min",void 0),(0,i.Cg)([(0,o.MZ)({type:Number})],g.prototype,"max",void 0),(0,i.Cg)([(0,o.MZ)({type:Number})],g.prototype,"value",void 0),(0,i.Cg)([(0,o.MZ)({attribute:!1})],g.prototype,"formatOptions",void 0),(0,i.Cg)([(0,o.MZ)({attribute:!1})],g.prototype,"valueText",void 0),(0,i.Cg)([(0,o.MZ)({attribute:!1})],g.prototype,"locale",void 0),(0,i.Cg)([(0,o.MZ)({type:Boolean})],g.prototype,"needle",void 0),(0,i.Cg)([(0,o.MZ)({type:Array})],g.prototype,"levels",void 0),(0,i.Cg)([(0,o.MZ)()],g.prototype,"label",void 0),(0,i.Cg)([(0,o.wk)()],g.prototype,"_angle",void 0),(0,i.Cg)([(0,o.wk)()],g.prototype,"_updated",void 0),(0,i.Cg)([(0,o.wk)()],g.prototype,"_segment_label",void 0),g=(0,i.Cg)([(0,o.EM)("ha-gauge")],g),e()}catch(t){e(t)}})},91874(t,e,s){s.a(t,async function(t,i){try{s.r(e),s.d(e,{DEFAULT_MAX:()=>k,DEFAULT_MIN:()=>x,severityMap:()=>w});s(18111),s(20116),s(61701);var a=s(62826),o=s(5124),n=s(22441),r=s(6412),l=s(63672),h=s(89784),c=s(42372),d=s(78536),u=s(78649),g=(s(76776),s(5127)),v=s(22675),_=s(19037),p=s(13632),f=s(22064),m=s(97176),y=s(784),b=s(85979),$=t([g,b]);[g,b]=$.then?(await $)():$;const x=0,k=100,w={red:"var(--error-color)",green:"var(--success-color)",yellow:"var(--warning-color)",normal:"var(--info-color)"};class M extends o.WF{static async getConfigElement(){return await s.e(88292).then(s.bind(s,89647)),document.createElement("hui-gauge-card-editor")}static getStubConfig(t,e,s){return{type:"gauge",entity:(0,p.B)(t,1,e,s,["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,u.n)(t.entity))throw new Error("Invalid entity");this._config={min:x,max:k,...t}}render(){if(!this._config||!this.hass)return o.s6;const t=this.hass.states[this._config.entity];if(!t)return o.qy` <hui-warning .hass="${this.hass}"> ${(0,b.j)(this.hass,this._config.entity)} </hui-warning> `;if(t.state===v.Hh)return o.qy` <hui-warning>${this.hass.localize("ui.panel.lovelace.warning.entity_unavailable",{entity:this._config.entity})}</hui-warning> `;let e;e=this._config.attribute?this.hass.formatEntityAttributeValueToParts(t,this._config.attribute):this.hass.formatEntityStateToParts(t);const s=e.find(t=>"value"===t.type)?.value,i=this._config.attribute?t.attributes[this._config.attribute]:t.state;if(isNaN(i))return o.qy` <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})}</hui-warning> `;const a=this.hass.formatEntityName(t,this._config.name),n=(0,d.h)(this.hass,t,this._config)??"";return o.qy` <ha-card class="${(0,r.H)({action:(0,m.A)(this._config)})}" @action="${this._handleAction}" .actionHandler="${(0,_.T)({hasHold:(0,m.h)(this._config.hold_action),hasDoubleClick:(0,m.h)(this._config.double_tap_action)})}" tabindex="${(0,l.J)(!this._config.tap_action||(0,m.h)(this._config.tap_action)?"0":void 0)}"> <ha-gauge .min="${this._config.min}" .max="${this._config.max}" .value="${i}" .valueText="${s}" .locale="${this.hass.locale}" .label="${n}" style="${(0,h.W)({"--gauge-color":this._computeSeverity(Number(i))})}" .needle="${this._config.needle}" .levels="${this._config.needle?this._severityLevels():void 0}"></ha-gauge> <p class="title" .title="${a}">${a}</p> </ha-card> `}shouldUpdate(t){return(0,y.LX)(this,t)}updated(t){if(super.updated(t),!this._config||!this.hass)return;const e=t.get("hass"),s=t.get("_config");e&&s&&e.themes===this.hass.themes&&s.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++){const i=e[s];if(i&&t>=i.from&&(s+1===e.length||t<e[s+1]?.from))return i.color}return w.normal}const s=this._config.severity;if(!s)return w.normal;const i=Object.keys(s).map(t=>[t,s[t]]);for(const t of i)if(null==w[t[0]]||isNaN(t[1]))return w.normal;return i.sort((t,e)=>t[1]-e[1]),t>=i[0][1]&&t<i[1][1]?w[i[0][0]]:t>=i[1][1]&&t<i[2][1]?w[i[1][0]]:t>=i[2][1]?w[i[2][0]]:w.normal}_severityLevels(){const t=this._config.segments;if(t)return t.map(t=>({level:t?.from,stroke:t?.color,label:t?.label}));const e=this._config.severity;if(!e)return[{level:0,stroke:w.normal}];return Object.keys(e).map(t=>({level:e[t],stroke:w[t]}))}_handleAction(t){(0,f.$)(this,this.hass,this._config,t.detail.action)}}M.styles=o.AH`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,n.MZ)({attribute:!1})],M.prototype,"hass",void 0),(0,a.Cg)([(0,n.wk)()],M.prototype,"_config",void 0),M=(0,a.Cg)([(0,n.EM)("hui-gauge-card")],M),i()}catch(t){i(t)}})},36240(t,e,s){s.d(e,{NN:()=>a,S8:()=>i,gN:()=>o});const i=(t,e,s)=>isNaN(t)||isNaN(e)||isNaN(s)?0:t>s?s:t<e?e:t,a=(t,e,s)=>100*(t-e)/(s-e),o=t=>Math.round(10*t)/10}};