UNPKG

iobroker.lovelace

Version:

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

1 lines 13.5 kB
export const __rspack_esm_id=35546;export const __rspack_esm_ids=[35546];export const __webpack_modules__={5127(e,t,s){s.a(e,async function(e,t){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),u=e([r]);r=(u.then?(await u)():u)[0];const d=(e,t,s)=>180*(0,c.NN)((0,c.S8)(e,t,s),t,s)/100;class g extends a.WF{connectedCallback(){super.connectedCallback(),this._rescaleOnConnect&&(this._rescaleSvg(),this._rescaleOnConnect=!1)}firstUpdated(e){super.firstUpdated(e),(0,h.m)(()=>{this._updated=!0,this.needle&&(this._angle=d(this.value,this.min,this.max)),this._segment_label=this._getSegmentLabel(),this._rescaleSvg()})}willUpdate(e){(e.has("levels")||e.has("min"))&&(this.levels?(this._sortedLevels=[...this.levels].sort((e,t)=>e.level-t.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(e){super.updated(e),this._updated&&(e.has("value")||e.has("valueText")||e.has("label")||e.has("_segment_label"))&&(this._angle=d(this.value,this.min,this.max),this._segment_label=this._getSegmentLabel(),this._rescaleSvg())}render(){const e=40,t=Math.PI*e,s=d(this.value,this.min,this.max),i=this._updated?t*(1-s/180):t;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((t,s,i)=>{const o=t.level,n=s+1<i.length?i[s+1].level:this.max,r=d(o,this.min,this.max),l=d(n,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),g=0===s,p=s===i.length-1;if(g)return a.JW` <path class="level" stroke="${t.stroke}" style="stroke-linecap:butt" d="M ${c} ${u} A ${e} ${e} 0 ${h} 1 40 0"/> `;if(p){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="${t.stroke}" style="stroke-linecap:butt" d="M ${c} ${u} A ${e} ${e} 0 ${h} 1 40 0"/> <path class="level" stroke="${t.stroke}" style="stroke-linecap:butt" d="M ${i} ${o} A ${e} ${e} 0 0 1 40 0"/> `}return a.JW` <path class="level" stroke="${t.stroke}" style="stroke-linecap:butt" d="M ${c} ${u} A ${e} ${e} 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="${t}" 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 e=this.shadowRoot.querySelector(".text"),t=e.querySelector("text").getBBox();e.setAttribute("viewBox",`${t.x} ${t.y} ${t.width} ${t.height}`)}_getSegmentLabel(){if(this._sortedLevels)for(let e=this._sortedLevels.length-1;e>=0;e--)if(this.value>=this._sortedLevels[e].level)return this._sortedLevels[e].label;return""}constructor(...e){super(...e),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),t()}catch(e){t(e)}})},54706(e,t,s){s.d(t,{E:()=>o});s(74423),s(18111),s(13579);var i=s(62826),a=s(22441);const o=e=>{class t extends e{connectedCallback(){super.connectedCallback(),this._checkSubscribed()}disconnectedCallback(){if(super.disconnectedCallback(),this.__unsubs){for(;this.__unsubs.length;){const e=this.__unsubs.pop();e instanceof Promise?e.then(e=>e()):e()}this.__unsubs=void 0}}updated(e){if(super.updated(e),e.has("hass"))this._checkSubscribed();else if(this.hassSubscribeRequiredHostProps)for(const t of e.keys())if(this.hassSubscribeRequiredHostProps.includes(t))return void this._checkSubscribed()}hassSubscribe(){return[]}_checkSubscribed(){void 0===this.__unsubs&&this.isConnected&&void 0!==this.hass&&!this.hassSubscribeRequiredHostProps?.some(e=>void 0===this[e])&&(this.__unsubs=this.hassSubscribe())}}return(0,i.Cg)([(0,a.MZ)({attribute:!1})],t.prototype,"hass",void 0),t}},48196(e,t,s){s.a(e,async function(e,i){try{s.r(t);var a=s(62826),o=s(5124),n=s(22441),r=s(89784),l=(s(76776),s(5127)),h=(s(67094),s(34127)),c=s(38114),u=s(54706),d=s(91874),g=s(784),p=e([l,h,c,d]);[l,h,c,d]=p.then?(await p)():p;const _="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z",f={maximumFractionDigits:0};class v extends((0,u.E)(o.WF)){static async getConfigElement(){return await s.e(79062).then(s.bind(s,54197)),document.createElement("hui-energy-graph-card-editor")}static getStubConfig(e,t,s){return{type:"energy-self-sufficiency-gauge"}}hassSubscribe(){return[(0,c.tb)(this.hass,{key:this._config?.collection_key}).subscribe(e=>{this._data=e})]}getCardSize(){return 4}setConfig(e){e.collection_key&&(0,c.s8)(e.collection_key),this._config=e}shouldUpdate(e){return(0,g.xP)(this,e)||e.size>1||!e.has("hass")}render(){if(!this._config||!this.hass)return o.s6;if(!this._data)return o.qy`${this.hass.localize("ui.panel.lovelace.cards.energy.loading")}`;const{summedData:e,compareSummedData:t}=(0,c.gv)(this._data),{consumption:s,compareConsumption:i}=(0,c.DR)(e,void 0),a=e.total.from_grid??0,n=Math.max(0,s.total.used_total);let l;return null!==a&&null!==n&&n>0&&(l=100*(1-Math.min(1,a/n))),o.qy` <ha-card> ${void 0!==l?o.qy` <ha-gauge min="0" max="100" .value="${l}" label="%" .formatOptions="${f}" .locale="${this.hass.locale}" style="${(0,r.W)({"--gauge-color":this._computeSeverity(l)})}"></ha-gauge> <ha-svg-icon id="info" .path="${_}"></ha-svg-icon> <ha-tooltip for="info" placement="left"> ${this.hass.localize("ui.panel.lovelace.cards.energy.self_sufficiency_gauge.card_indicates_self_sufficiency_quota")} </ha-tooltip> <div class="name"> ${this.hass.localize("ui.panel.lovelace.cards.energy.self_sufficiency_gauge.self_sufficiency_quota")} </div> `:this.hass.localize("ui.panel.lovelace.cards.energy.self_sufficiency_gauge.self_sufficiency_could_not_calc")} </ha-card> `}_computeSeverity(e){return e>75?d.severityMap.green:e<50?d.severityMap.yellow:d.severityMap.normal}constructor(...e){super(...e),this.hassSubscribeRequiredHostProps=["_config"]}}v.styles=o.AH`ha-card{height:100%;overflow:hidden;padding:16px;display:flex;align-items:center;justify-content:center;flex-direction:column;box-sizing:border-box}ha-gauge{width:100%;max-width:250px;direction:ltr}.name{text-align:center;line-height:initial;color:var(--primary-text-color);width:100%;font-size:var(--ha-font-size-m);margin-top:8px}ha-svg-icon{position:absolute;right:4px;inset-inline-end:4px;inset-inline-start:initial;top:4px;color:var(--secondary-text-color)}ha-tooltip::part(base__popup){margin-top:4px}`,(0,a.Cg)([(0,n.MZ)({attribute:!1})],v.prototype,"hass",void 0),(0,a.Cg)([(0,n.wk)()],v.prototype,"_config",void 0),(0,a.Cg)([(0,n.wk)()],v.prototype,"_data",void 0),v=(0,a.Cg)([(0,n.EM)("hui-energy-self-sufficiency-gauge-card")],v),i()}catch(e){i(e)}})},91874(e,t,s){s.a(e,async function(e,i){try{s.r(t),s.d(t,{DEFAULT_MAX:()=>k,DEFAULT_MIN:()=>$,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),u=s(78536),d=s(78649),g=(s(76776),s(5127)),p=s(22675),_=s(19037),f=s(13632),v=s(22064),m=s(97176),y=s(784),b=s(85979),x=e([g,b]);[g,b]=x.then?(await x)():x;const $=0,k=100,w={red:"var(--error-color)",green:"var(--success-color)",yellow:"var(--warning-color)",normal:"var(--info-color)"};class C extends o.WF{static async getConfigElement(){return await s.e(88292).then(s.bind(s,89647)),document.createElement("hui-gauge-card-editor")}static getStubConfig(e,t,s){return{type:"gauge",entity:(0,f.B)(e,1,t,s,["counter","input_number","number","sensor"],e=>!isNaN(Number(e.state)))[0]||""}}getCardSize(){return 4}setConfig(e){if(!e.entity)throw new Error("Entity must be specified");if(!(0,d.n)(e.entity))throw new Error("Invalid entity");this._config={min:$,max:k,...e}}render(){if(!this._config||!this.hass)return o.s6;const e=this.hass.states[this._config.entity];if(!e)return o.qy` <hui-warning .hass="${this.hass}"> ${(0,b.j)(this.hass,this._config.entity)} </hui-warning> `;if(e.state===p.Hh)return o.qy` <hui-warning>${this.hass.localize("ui.panel.lovelace.warning.entity_unavailable",{entity:this._config.entity})}</hui-warning> `;let t;t=this._config.attribute?this.hass.formatEntityAttributeValueToParts(e,this._config.attribute):this.hass.formatEntityStateToParts(e);const s=t.find(e=>"value"===e.type)?.value,i=this._config.attribute?e.attributes[this._config.attribute]:e.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(e,this._config.name),n=(0,u.h)(this.hass,e,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(e){return(0,y.LX)(this,e)}updated(e){if(super.updated(e),!this._config||!this.hass)return;const t=e.get("hass"),s=e.get("_config");t&&s&&t.themes===this.hass.themes&&s.theme===this._config.theme||(0,c.Q)(this,this.hass.themes,this._config.theme)}_computeSeverity(e){if(this._config.needle)return;let t=this._config.segments;if(t){t=[...t].sort((e,t)=>e.from-t.from);for(let s=0;s<t.length;s++){const i=t[s];if(i&&e>=i.from&&(s+1===t.length||e<t[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(e=>[e,s[e]]);for(const e of i)if(null==w[e[0]]||isNaN(e[1]))return w.normal;return i.sort((e,t)=>e[1]-t[1]),e>=i[0][1]&&e<i[1][1]?w[i[0][0]]:e>=i[1][1]&&e<i[2][1]?w[i[1][0]]:e>=i[2][1]?w[i[2][0]]:w.normal}_severityLevels(){const e=this._config.segments;if(e)return e.map(e=>({level:e?.from,stroke:e?.color,label:e?.label}));const t=this._config.severity;if(!t)return[{level:0,stroke:w.normal}];return Object.keys(t).map(e=>({level:t[e],stroke:w[e]}))}_handleAction(e){(0,v.$)(this,this.hass,this._config,e.detail.action)}}C.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})],C.prototype,"hass",void 0),(0,a.Cg)([(0,n.wk)()],C.prototype,"_config",void 0),C=(0,a.Cg)([(0,n.EM)("hui-gauge-card")],C),i()}catch(e){i(e)}})},36240(e,t,s){s.d(t,{NN:()=>a,S8:()=>i,gN:()=>o});const i=(e,t,s)=>isNaN(e)||isNaN(t)||isNaN(s)?0:e>s?s:e<t?t:e,a=(e,t,s)=>100*(e-t)/(s-t),o=e=>Math.round(10*e)/10},56434(e,t,s){s.d(t,{e:()=>a});var i=s(81977);function a(e,t,s){return(0,i.P)(e,12*t,s)}}};