iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
2 lines • 6.29 kB
JavaScript
"use strict";(self.webpackChunkhome_assistant_frontend=self.webpackChunkhome_assistant_frontend||[]).push([["95469"],{63:function(t,e,a){a.a(t,(async function(t,s){try{a.r(e),a.d(e,{HuiEnergySolarGraphCard:()=>z});var r=a(61701),n=(a(71695),a(92745),a(9359),a(56475),a(31526),a(52924),a(40251),a(47021),a(42625)),o=a(83389),i=a(16444),c=a(13809),d=a(57243),h=a(50778),l=a(35359),u=a(27486),f=a(20548),_=a(50602),p=a(25179),y=(a(54977),a(1118)),g=a(17705),m=a(6736),k=a(93331),v=a(53259),b=t([p,_,y,v]);[p,_,y,v]=b.then?(await b)():b;let S,C,D,w,x=t=>t,z=(0,r.Z)([(0,h.Mo)("hui-energy-solar-graph-card")],(function(t,e){return{F:class extends e{constructor(...e){super(...e),t(this)}},d:[{kind:"field",decorators:[(0,h.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,h.SB)()],key:"_config",value:void 0},{kind:"field",decorators:[(0,h.SB)()],key:"_chartData",value(){return[]}},{kind:"field",decorators:[(0,h.SB)()],key:"_start",value(){return(0,n.I)()}},{kind:"field",decorators:[(0,h.SB)()],key:"_end",value(){return(0,o.p)()}},{kind:"field",decorators:[(0,h.SB)()],key:"_compareStart",value:void 0},{kind:"field",decorators:[(0,h.SB)()],key:"_compareEnd",value:void 0},{kind:"field",key:"hassSubscribeRequiredHostProps",value(){return["_config"]}},{kind:"method",key:"hassSubscribe",value:function(){var t;return[(0,y.UB)(this.hass,{key:null===(t=this._config)||void 0===t?void 0:t.collection_key}).subscribe((t=>this._getStatistics(t)))]}},{kind:"method",key:"getCardSize",value:function(){return 3}},{kind:"method",key:"setConfig",value:function(t){this._config=t}},{kind:"method",key:"shouldUpdate",value:function(t){return(0,k.SN)(this,t)||t.size>1||!t.has("hass")}},{kind:"method",key:"render",value:function(){return this.hass&&this._config?(0,d.dy)(S||(S=x` <ha-card> ${0} <div class="content ${0}"> <ha-chart-base .hass="${0}" .data="${0}" .options="${0}" chart-type="bar"></ha-chart-base> ${0} </div> </ha-card> `),this._config.title?(0,d.dy)(C||(C=x`<h1 class="card-header">${0}</h1>`),this._config.title):"",(0,l.$)({"has-header":!!this._config.title}),this.hass,this._chartData,this._createOptions(this._start,this._end,this.hass.locale,this.hass.config,this._compareStart,this._compareEnd),this._chartData.length?"":(0,d.dy)(D||(D=x`<div class="no-data"> ${0} </div>`),(0,i.z)(this._start)?this.hass.localize("ui.panel.lovelace.cards.energy.no_data"):this.hass.localize("ui.panel.lovelace.cards.energy.no_data_period"))):d.Ld}},{kind:"field",key:"_formatTotal",value(){return t=>this.hass.localize("ui.panel.lovelace.cards.energy.energy_solar_graph.total_produced",{num:(0,_.uf)(t,this.hass.locale)})}},{kind:"field",key:"_createOptions",value(){return(0,u.Z)(((t,e,a,s,r,n)=>(0,v.J)(t,e,a,s,"kWh",r,n,this._formatTotal)))}},{kind:"method",key:"_getStatistics",value:async function(t){this._start=t.start,this._end=t.end||(0,o.p)(),this._compareStart=t.startCompare,this._compareEnd=t.endCompare;const e=t.prefs.energy_sources.filter((t=>"solar"===t.type));let a;if(e.some((t=>{var e;return null===(e=t.config_entry_solar_forecast)||void 0===e?void 0:e.length})))try{a=await(0,y.jB)(this.hass)}catch(c){}const s=[],r=getComputedStyle(this);if(t.statsCompare)s.push(...this._processDataSet(t.statsCompare,t.statsMetadata,e,r,!0));else{var n,i;const t=null!==(n=null===(i=e[0])||void 0===i?void 0:i.stat_energy_from)&&void 0!==n?n:"placeholder";s.push({id:"compare-"+t,type:"bar",stack:"solar",data:[]})}s.push(...this._processDataSet(t.stats,t.statsMetadata,e,r)),(0,v.Zx)(s),a&&s.push(...this._processForecast(t.statsMetadata,a,e,r.getPropertyValue("--primary-text-color"),t.start,t.end)),this._chartData=s}},{kind:"method",key:"_processDataSet",value:function(t,e,a,s,r=!1){const n=[],o=(0,v.kT)(this._start,this._compareStart);return a.forEach(((a,i)=>{let c=null;const d=[];if(a.stat_energy_from in t){const e=t[a.stat_energy_from];for(const t of e){if(null===t.change||void 0===t.change||0===t.change)continue;if(c===t.start)continue;const e=[t.start,t.change];r&&(e[2]=e[0],e[0]=o(new Date(t.start))),d.push(e),c=t.start}}n.push({type:"bar",cursor:"default",id:r?"compare-"+a.stat_energy_from:a.stat_energy_from,name:this.hass.localize("ui.panel.lovelace.cards.energy.energy_solar_graph.production",{name:(0,g.Kd)(this.hass,a.stat_energy_from,e[a.stat_energy_from])}),barMaxWidth:50,itemStyle:{borderColor:(0,f.H)(s,this.hass.themes.darkMode,!1,r,"--energy-solar-color",i)},color:(0,f.H)(s,this.hass.themes.darkMode,!0,r,"--energy-solar-color",i),data:d,stack:r?"compare":"solar"})})),n}},{kind:"method",key:"_processForecast",value:function(t,e,a,s,r,n){const o=[],i=(0,c.j)(n||new Date,r);return a.forEach((a=>{if(a.config_entry_solar_forecast){const c={};if(a.config_entry_solar_forecast.forEach((t=>{e[t]&&Object.entries(e[t].wh_hours).forEach((([t,e])=>{const a=new Date(t);if(a<r||n&&a>n)return;i>35&&a.setDate(1),i>2?a.setHours(0,0,0,0):a.setMinutes(0,0,0);const s=a.getTime();s in c?c[s]+=e:c[s]=e}))})),c){const e=[];for(const[t,a]of Object.entries(c))e.push([Number(t),a/1e3]);e.length&&o.push({id:"forecast-"+a.stat_energy_from,type:"line",stack:"forecast",name:this.hass.localize("ui.panel.lovelace.cards.energy.energy_solar_graph.forecast",{name:(0,g.Kd)(this.hass,a.stat_energy_from,t[a.stat_energy_from])}),step:!1,color:s,lineStyle:{type:[7,5],width:1.5},symbol:"none",data:e})}}})),o}},{kind:"field",static:!0,key:"styles",value(){return(0,d.iv)(w||(w=x`ha-card{height:100%}.card-header{padding-bottom:0}.content{padding:16px}.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:32px;margin-inline-start:32px;margin-inline-end:initial;box-sizing:border-box}`))}}]}}),(0,m.f)(d.oi));s()}catch(S){s(S)}}))},41924:function(t,e,a){a.d(e,{y:()=>r});var s=a(53907);function r(t){return(0,s.L)(t,Date.now())}},97836:function(t,e,a){a.d(e,{K:()=>n});a(71695),a(47021);var s=a(18492),r=a(7591);function n(t,e,a){const[n,o]=(0,s.d)(null==a?void 0:a.in,t,e);return+(0,r.b)(n)==+(0,r.b)(o)}},16444:function(t,e,a){a.d(e,{z:()=>o});var s=a(53907),r=a(41924),n=a(97836);function o(t,e){return(0,n.K)((0,s.L)((null==e?void 0:e.in)||t,t),(0,r.y)((null==e?void 0:e.in)||t))}}}]);
//# sourceMappingURL=95469.3fa9aaff4d453c19.js.map