iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 9.2 kB
JavaScript
export const __rspack_esm_id=32527;export const __rspack_esm_ids=[32527];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),r=s(22441),o=s(89784),l=s(20058),n=s(67258),h=s(12587),c=s(36240),d=e([l]);l=(d.then?(await d)():d)[0];const u=(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=u(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=u(this.value,this.min,this.max),this._segment_label=this._getSegmentLabel(),this._rescaleSvg())}render(){const e=40,t=Math.PI*e,s=u(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 r=t.level,o=s+1<i.length?i[s+1].level:this.max,l=u(r,this.min,this.max),n=u(o,this.min,this.max),h=n-l>180?1:0,c=-40*Math.cos(l*Math.PI/180),d=-40*Math.sin(l*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} ${d} A ${e} ${e} 0 ${h} 1 40 0"/> `;if(p){const s=n-.5,i=-40*Math.cos(s*Math.PI/180),r=-40*Math.sin(s*Math.PI/180);return a.JW` <path class="level" stroke="${t.stroke}" style="stroke-linecap:butt" d="M ${c} ${d} A ${e} ${e} 0 ${h} 1 40 0"/> <path class="level" stroke="${t.stroke}" style="stroke-linecap:butt" d="M ${i} ${r} A ${e} ${e} 0 0 1 40 0"/> `}return a.JW` <path class="level" stroke="${t.stroke}" style="stroke-linecap:butt" d="M ${c} ${d} 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,o.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,o.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,l.ZV)(this.value,this.locale,this.formatOptions)}${this._segment_label?"":"%"===this.label?(0,n.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,r.MZ)({type:Number})],g.prototype,"min",void 0),(0,i.Cg)([(0,r.MZ)({type:Number})],g.prototype,"max",void 0),(0,i.Cg)([(0,r.MZ)({type:Number})],g.prototype,"value",void 0),(0,i.Cg)([(0,r.MZ)({attribute:!1})],g.prototype,"formatOptions",void 0),(0,i.Cg)([(0,r.MZ)({attribute:!1})],g.prototype,"valueText",void 0),(0,i.Cg)([(0,r.MZ)({attribute:!1})],g.prototype,"locale",void 0),(0,i.Cg)([(0,r.MZ)({type:Boolean})],g.prototype,"needle",void 0),(0,i.Cg)([(0,r.MZ)({type:Array})],g.prototype,"levels",void 0),(0,i.Cg)([(0,r.MZ)()],g.prototype,"label",void 0),(0,i.Cg)([(0,r.wk)()],g.prototype,"_angle",void 0),(0,i.Cg)([(0,r.wk)()],g.prototype,"_updated",void 0),(0,i.Cg)([(0,r.wk)()],g.prototype,"_segment_label",void 0),g=(0,i.Cg)([(0,r.EM)("ha-gauge")],g),t()}catch(e){t(e)}})},54706(e,t,s){s.d(t,{E:()=>r});s(74423),s(18111),s(13579);var i=s(62826),a=s(22441);const r=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}},80449(e,t,s){s.a(e,async function(e,i){try{s.r(t);var a=s(62826),r=s(5124),o=s(22441),l=s(20058),n=(s(76776),s(5127)),h=(s(67094),s(34127)),c=s(38114),d=s(54706),u=s(784),g=e([n,h,c,l]);[n,h,c,l]=g.then?(await g)():g;const p="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",v=[{level:-1,stroke:"var(--energy-grid-consumption-color)"},{level:0,stroke:"var(--energy-grid-return-color)"}];class _ extends((0,d.E)(r.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-grid-neutrality-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,u.xP)(this,e)||e.size>1||!e.has("hass")}render(){if(!this._config||!this.hass)return r.s6;if(!this._data)return r.qy`${this.hass.localize("ui.panel.lovelace.cards.energy.loading")}`;const{summedData:e,compareSummedData:t}=(0,c.gv)(this._data);let s;if(!("from_grid"in e.total))return r.s6;const i=e.total.from_grid??0,a=e.total.to_grid??0;return null!==i&&null!==a&&(s=a>i?1-i/a:a<i?-1*(1-a/i):0),r.qy` <ha-card> ${void 0!==s?r.qy` <ha-gauge min="-1" max="1" .value="${s}" .valueText="${(0,l.ZV)(Math.abs(a-i),this.hass.locale,{maximumFractionDigits:2})}" .locale="${this.hass.locale}" .levels="${v}" label="kWh" needle></ha-gauge> <ha-svg-icon id="info" .path="${p}"></ha-svg-icon> <ha-tooltip for="info" placement="left"> ${this.hass.localize("ui.panel.lovelace.cards.energy.grid_neutrality_gauge.energy_dependency")} <br><br> ${this.hass.localize("ui.panel.lovelace.cards.energy.grid_neutrality_gauge.color_explain")} </ha-tooltip> <div class="name"> ${a>=i?this.hass.localize("ui.panel.lovelace.cards.energy.grid_neutrality_gauge.net_returned_grid"):this.hass.localize("ui.panel.lovelace.cards.energy.grid_neutrality_gauge.net_consumed_grid")} </div> `:this.hass.localize("ui.panel.lovelace.cards.energy.grid_neutrality_gauge.grid_neutrality_not_calculated")} </ha-card> `}constructor(...e){super(...e),this.hassSubscribeRequiredHostProps=["_config"]}}_.styles=r.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,o.MZ)({attribute:!1})],_.prototype,"hass",void 0),(0,a.Cg)([(0,o.wk)()],_.prototype,"_config",void 0),(0,a.Cg)([(0,o.wk)()],_.prototype,"_data",void 0),_=(0,a.Cg)([(0,o.EM)("hui-energy-grid-neutrality-gauge-card")],_),i()}catch(e){i(e)}})},36240(e,t,s){s.d(t,{NN:()=>a,S8:()=>i,gN:()=>r});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),r=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)}}};