iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 8.98 kB
JavaScript
export const __rspack_esm_id=66471;export const __rspack_esm_ids=[66471];export const __webpack_modules__={90433(t,e,a){a.d(e,{Vy:()=>o,fI:()=>i,ux:()=>n});var s=a(22786),r=a(79468);function o(t,e){const a=t%54+1;return e.getPropertyValue(`--color-${a}`)}function i(t,e){const a=e.getPropertyValue(`--graph-color-${t+1}`)||o(t,e);return(0,r.RQ)(a)}const n=(0,s.A)(t=>Array.from({length:54},(e,a)=>i(a,t)),(t,e)=>t[0].getPropertyValue("--graph-color-1")===e[0].getPropertyValue("--graph-color-1")&&t[0].getPropertyValue("--color-1")===e[0].getPropertyValue("--color-1"))},89938(t,e,a){function s(t,e){const a=e-t;return!Number.isFinite(a)||a<=0?1:Math.max(0,Math.ceil(-Math.log10(a/10)))}a.d(e,{G:()=>s})},54706(t,e,a){a.d(e,{E:()=>o});a(74423),a(18111),a(13579);var s=a(62826),r=a(22441);const o=t=>{class e extends t{connectedCallback(){super.connectedCallback(),this._checkSubscribed()}disconnectedCallback(){if(super.disconnectedCallback(),this.__unsubs){for(;this.__unsubs.length;){const t=this.__unsubs.pop();t instanceof Promise?t.then(t=>t()):t()}this.__unsubs=void 0}}updated(t){if(super.updated(t),t.has("hass"))this._checkSubscribed();else if(this.hassSubscribeRequiredHostProps)for(const e of t.keys())if(this.hassSubscribeRequiredHostProps.includes(e))return void this._checkSubscribed()}hassSubscribe(){return[]}_checkSubscribed(){void 0===this.__unsubs&&this.isConnected&&void 0!==this.hass&&!this.hassSubscribeRequiredHostProps?.some(t=>void 0===this[t])&&(this.__unsubs=this.hassSubscribe())}}return(0,s.Cg)([(0,r.MZ)({attribute:!1})],e.prototype,"hass",void 0),e}},40235(t,e,a){a.a(t,async function(t,s){try{a.r(e),a.d(e,{HuiPowerSourcesGraphCard:()=>D});a(44114),a(18111),a(7588),a(61701),a(18237),a(13579);var r=a(62826),o=a(73684),i=a(83309),n=a(40600),c=a(81859),h=a(5124),l=a(22441),d=a(6412),u=a(22786),p=a(79144),g=a(44439),_=a(89938),y=(a(76776),a(38114)),f=a(54706),b=a(784),v=a(97372),m=a(79468),w=t([g,y,v]);[g,y,v]=w.then?(await w)():w;class D extends((0,f.E)(h.WF)){static async getConfigElement(){return await a.e(79062).then(a.bind(a,54197)),document.createElement("hui-energy-graph-card-editor")}static getStubConfig(t,e,a){return{type:"power-sources-graph"}}hassSubscribe(){return[(0,y.tb)(this.hass,{key:this._config?.collection_key}).subscribe(t=>this._getStatistics(t))]}getCardSize(){return 3}setConfig(t){t.collection_key&&(0,y.s8)(t.collection_key),this._config=t}shouldUpdate(t){return(0,b.xP)(this,t)||t.size>1||!t.has("hass")}render(){return this.hass&&this._config?h.qy` <ha-card> ${this._config.title?h.qy`<h1 class="card-header">${this._config.title}</h1>`:""} <div class="content ${(0,d.H)({"has-header":!!this._config.title})}"> <ha-chart-base .hass="${this.hass}" .data="${this._chartData}" .options="${this._createOptions(this._start,this._end,this.hass.locale,this.hass.config,this._compareStart,this._compareEnd,this._legendData,this._yAxisFractionDigits)}"></ha-chart-base> ${this._chartData.some(t=>t.data.length)?h.s6:h.qy`<div class="no-data"> ${(0,o.c)(this._start)?this.hass.localize("ui.panel.lovelace.cards.energy.no_data"):this.hass.localize("ui.panel.lovelace.cards.energy.no_data_period")} </div>`} </div> </ha-card> `:h.s6}async _getStatistics(t){const e=[];this._legendData=[];const a={solar:{stats:[],color:"--energy-solar-color",name:this.hass.localize("ui.panel.lovelace.cards.energy.power_graph.solar")},grid:{stats:[],color:"--energy-grid-consumption-color",name:this.hass.localize("ui.panel.lovelace.cards.energy.power_graph.grid")},battery:{stats:[],color:"--energy-battery-out-color",name:this.hass.localize("ui.panel.lovelace.cards.energy.power_graph.battery")}},s=getComputedStyle(this);let r=1/0,o=-1/0;const c=t=>{t<r&&(r=t),t>o&&(o=t)};for(const e of t.prefs.energy_sources)"solar"!==e.type?"battery"!==e.type?"grid"===e.type&&e.stat_rate&&a.grid.stats.push(e.stat_rate):e.stat_rate&&a.battery.stats.push(e.stat_rate):e.stat_rate&&a.solar.stats.push(e.stat_rate);const h={type:"line",smooth:.4,lineStyle:{width:1}},l=Date.now();Object.keys(a).forEach((r,o)=>{if(a[r].stats.length){const n=s.getPropertyValue(a[r].color),d=(0,m.xp)(n),{positive:u,negative:g}=this._processData(a[r].stats.map(e=>{const a=t.stats[e]??[];if((0,i.r)(l,this._start)&&(0,i.r)(l,this._end)){const t=(0,y.h4)(this.hass.states[e]);void 0!==t&&a.push({start:l,end:l,mean:t/1e3})}return a}),c);e.push({...h,id:r,name:a[r].name,color:n,stack:"positive",areaStyle:{color:new p.W(0,0,0,1,[{offset:0,color:`rgba(${d[0]}, ${d[1]}, ${d[2]}, 0.75)`},{offset:1,color:`rgba(${d[0]}, ${d[1]}, ${d[2]}, 0.25)`}])},data:u,z:3-o}),"solar"!==r&&e.push({...h,id:`${r}-negative`,name:a[r].name,color:n,stack:"negative",areaStyle:{color:new p.W(0,1,0,0,[{offset:0,color:`rgba(${d[0]}, ${d[1]}, ${d[2]}, 0.75)`},{offset:1,color:`rgba(${d[0]}, ${d[1]}, ${d[2]}, 0.25)`}])},data:g,z:4-o}),this._legendData.push({id:r,secondaryIds:"solar"!==r?[`${r}-negative`]:[],name:a[r].name,itemStyle:{color:`rgba(${d[0]}, ${d[1]}, ${d[2]}, 0.75)`,borderColor:n}})}}),this._start=t.start,this._end=t.end||(0,n.o)(),this._chartData=(0,v.JR)(e),this._yAxisFractionDigits=(0,_.G)(r,o);const d=[];this._chartData[0]?.data.forEach((t,e)=>{const a="object"==typeof t&&"value"in t?t.value[0]:t[0];let s=0;this._chartData.forEach(t=>{const a="object"==typeof t.data[e]&&"value"in t.data[e]?t.data[e].value[1]:t.data[e][1];s+=a}),d[e]=[a,Math.max(0,s)]}),this._chartData.push({...h,id:"usage",name:this.hass.localize("ui.panel.lovelace.cards.energy.power_graph.usage"),color:s.getPropertyValue("--primary-text-color"),lineStyle:{type:[7,2],width:1.5},data:d,z:5}),this._legendData.push({id:"usage",name:this.hass.localize("ui.panel.lovelace.cards.energy.power_graph.usage"),itemStyle:{color:s.getPropertyValue("--primary-text-color")}})}_processData(t,e){const a={};t.forEach(t=>{t.forEach(t=>{if(null==t.mean)return;const e=(t.start+t.end)/2;a[e]=[...a[e]??[],t.mean]})});const s=[],r=[];return Object.entries(a).forEach(([t,a])=>{const o=Number(t),i=a.reduce((t,e)=>t+e,0),n=Math.max(0,i),c=Math.min(0,i);s.push([o,n]),r.push([o,c]),e(n),e(c)}),{positive:s,negative:r}}constructor(...t){super(...t),this._chartData=[],this._yAxisFractionDigits=1,this._start=(0,c.R)(),this._end=(0,n.o)(),this.hassSubscribeRequiredHostProps=["_config"],this._createOptions=(0,u.A)((t,e,a,s,r,o,i,n)=>({...(0,v.od)(t,e,a,s,"kW",r,o,void 0,!0,n),legend:{show:!1!==this._config?.show_legend,type:"custom",data:i}}))}}D.styles=h.AH`ha-card{height:100%}.card-header{padding-bottom:0}.content{padding:var(--ha-space-4)}.has-header{padding-top:0}.no-data{position:absolute;height:100%;top:0;left:0;right:0;display:flex;justify-content:center;align-items:center;padding:20%;margin-left:var(--ha-space-8);margin-inline-start:var(--ha-space-8);margin-inline-end:initial;box-sizing:border-box}`,(0,r.Cg)([(0,l.MZ)({attribute:!1})],D.prototype,"hass",void 0),(0,r.Cg)([(0,l.wk)()],D.prototype,"_config",void 0),(0,r.Cg)([(0,l.wk)()],D.prototype,"_chartData",void 0),(0,r.Cg)([(0,l.wk)()],D.prototype,"_yAxisFractionDigits",void 0),(0,r.Cg)([(0,l.wk)()],D.prototype,"_legendData",void 0),(0,r.Cg)([(0,l.wk)()],D.prototype,"_start",void 0),(0,r.Cg)([(0,l.wk)()],D.prototype,"_end",void 0),(0,r.Cg)([(0,l.wk)()],D.prototype,"_compareStart",void 0),(0,r.Cg)([(0,l.wk)()],D.prototype,"_compareEnd",void 0),D=(0,r.Cg)([(0,l.EM)("hui-power-sources-graph-card")],D),s()}catch(t){s(t)}})},79144(t,e,a){a.d(e,{W:()=>v.A,default:()=>r});var s=a(88648),r=a(79501),o=a(33156),i=a(93275),n=a(73836),c=a(93084),h=a(69913),l=a(85136),d=a(19795),u=a(89516),p=a(11826),g=a(17966),_=a(70255),y=a(83276),f=a(67797),b=a(39378),v=a(67665),m=a(33810);const w=m.A.prototype.filterData;m.A.prototype.filterData=function(t,e){if("boundaryFilter"!==t.get("filterMode"))return void w.call(this,t,e);if(!this.hostedBy(t))return;const a=this._dimName,s=this._window.value,r=this.getTargetSeriesModels();for(const t of r){const e=t.getData(),r=e.mapDimensionsAll(a);if(!r.length)continue;const o=e.getStore(),i=e.getDimensionIndex(r[0]),n=e.count();let c=-1,h=-1;for(let t=0;t<n;t++){const e=o.get(i,t);isNaN(e)||(e<s[0]?c=t:e>s[1]&&-1===h&&(h=t))}e.filterSelf(t=>{if(t===c||t===h)return!0;const e=o.get(i,t);return!isNaN(e)&&e>=s[0]&&e<=s[1]});for(const t of r)e.setApproximateExtent(s,t)}},s.Y([o.a,i.a,n.a,c.a,h.a,l.a,d.a,u.a,p.a,g.a,y._,f.i,b.a,_.a])},43382(t,e,a){a.d(e,{A:()=>r});var s=a(73420);function r(t){return(0,s.w)(t,Date.now())}},6116(t,e,a){a.d(e,{o:()=>o});var s=a(6439),r=a(83339);function o(t,e,a){const o=(0,r.b)(t,e)/6e4;return(0,s.u)(a?.roundingMethod)(o)}},40600(t,e,a){a.d(e,{o:()=>r});var s=a(73983);function r(t){return(0,s.D)(Date.now(),t)}},83309(t,e,a){a.d(e,{r:()=>o});var s=a(74816),r=a(35932);function o(t,e,a){const[o,i]=(0,s.x)(a?.in,t,e);return+(0,r.o)(o)===+(0,r.o)(i)}},73684(t,e,a){a.d(e,{c:()=>i});var s=a(73420),r=a(43382),o=a(83309);function i(t,e){return(0,o.r)((0,s.w)(e?.in||t,t),(0,r.A)(e?.in||t))}},81859(t,e,a){a.d(e,{R:()=>r});var s=a(35932);function r(t){return(0,s.o)(Date.now(),t)}}};