iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
2 lines • 8.62 kB
JavaScript
"use strict";(self.webpackChunkhome_assistant_frontend=self.webpackChunkhome_assistant_frontend||[]).push([["78786"],{32672:function(t,e,r){r.a(t,(async function(t,a){try{r.r(e),r.d(e,{HuiEnergyUsageGraphCard:()=>C});var o=r(61701),s=(r(19083),r(71695),r(92745),r(61893),r(9359),r(31526),r(52924),r(19423),r(40251),r(92519),r(42179),r(89256),r(24931),r(88463),r(57449),r(19814),r(47021),r(42625)),i=r(83389),n=r(16444),d=r(57243),c=r(50778),l=r(35359),u=r(27486),h=r(20548),_=r(50602),f=r(25179),g=(r(54977),r(1118)),y=r(17705),m=r(6736),p=r(93331),b=r(53259),v=t([f,g,_,b]);[f,g,_,b]=v.then?(await v)():v;let k,S,O,j,E=t=>t;const x={to_grid:"--energy-grid-return-color",to_battery:"--energy-battery-in-color",from_grid:"--energy-grid-consumption-color",used_grid:"--energy-grid-consumption-color",used_solar:"--energy-solar-color",used_battery:"--energy-battery-out-color"};let C=(0,o.Z)([(0,c.Mo)("hui-energy-usage-graph-card")],(function(t,e){return{F:class extends e{constructor(...e){super(...e),t(this)}},d:[{kind:"field",decorators:[(0,c.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,c.SB)()],key:"_config",value:void 0},{kind:"field",decorators:[(0,c.SB)()],key:"_chartData",value(){return[]}},{kind:"field",decorators:[(0,c.SB)()],key:"_start",value(){return(0,s.I)()}},{kind:"field",decorators:[(0,c.SB)()],key:"_end",value(){return(0,i.p)()}},{kind:"field",decorators:[(0,c.SB)()],key:"_compareStart",value:void 0},{kind:"field",decorators:[(0,c.SB)()],key:"_compareEnd",value:void 0},{kind:"field",key:"hassSubscribeRequiredHostProps",value(){return["_config"]}},{kind:"method",key:"hassSubscribe",value:function(){var t;return[(0,g.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,p.SN)(this,t)||t.size>1||!t.has("hass")}},{kind:"method",key:"render",value:function(){return this.hass&&this._config?(0,d.dy)(k||(k=E` <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)(S||(S=E`<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.some((t=>t.data.length))?"":(0,d.dy)(O||(O=E`<div class="no-data"> ${0} </div>`),(0,n.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=>t>0?this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.total_consumed",{num:(0,_.uf)(t,this.hass.locale)}):this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.total_returned",{num:(0,_.uf)(-t,this.hass.locale)})}},{kind:"field",key:"_createOptions",value(){return(0,u.Z)(((t,e,r,a,o,s)=>{const i=(0,b.J)(t,e,r,a,"kWh",o,s,this._formatTotal);return Object.assign(Object.assign({},i),{},{tooltip:Object.assign(Object.assign({},i.tooltip),{},{formatter:t=>{var e,r;return Array.isArray(t)?(t.sort(((t,e)=>{var r,a;const o=null===(r=t.value)||void 0===r?void 0:r[1],s=null===(a=e.value)||void 0===a?void 0:a[1];return o>0&&s<0?-1:s>0&&o<0?1:o>0?e.componentIndex-t.componentIndex:t.componentIndex-e.componentIndex})),null===(e=i.tooltip)||void 0===e||null===(r=e.formatter)||void 0===r?void 0:r.call(e,t)):""}})})}))}},{kind:"method",key:"_getStatistics",value:async function(t){const e=[],r={};for(const i of t.prefs.energy_sources)if("solar"!==i.type)if("battery"!==i.type){if("grid"===i.type){for(const t of i.flow_from)r.from_grid?r.from_grid.push(t.stat_energy_from):r.from_grid=[t.stat_energy_from];for(const t of i.flow_to)r.to_grid?r.to_grid.push(t.stat_energy_to):r.to_grid=[t.stat_energy_to]}}else r.to_battery?(r.to_battery.push(i.stat_energy_to),r.from_battery.push(i.stat_energy_from)):(r.to_battery=[i.stat_energy_to],r.from_battery=[i.stat_energy_from]);else r.solar?r.solar.push(i.stat_energy_from):r.solar=[i.stat_energy_from];const a=getComputedStyle(this),o={};Object.keys(x).forEach((t=>{o[t]={},"used_grid"!==t&&"used_solar"!==t&&"used_battery"!==t&&r[t]&&Object.values(r[t]).forEach(((e,r)=>{o[t][e]=r}))}));const s={used_grid:this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.combined_from_grid"),used_solar:this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.consumed_solar"),used_battery:this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.consumed_battery")};this._start=t.start,this._end=t.end||(0,i.p)(),this._compareStart=t.startCompare,this._compareEnd=t.endCompare,t.statsCompare&&e.push(...this._processDataSet(t.statsCompare,t.statsMetadata,r,o,a,s,!0)),e.push({id:"compare-placeholder",type:"bar",stack:t.statsCompare?"compare":"usage",data:[],order:0}),e.push(...this._processDataSet(t.stats,t.statsMetadata,r,o,a,s,!1)),e.sort(((t,e)=>t.order-e.order)),(0,b.Zx)(e),this._chartData=e}},{kind:"method",key:"_processDataSet",value:function(t,e,r,a,o,s,i=!1){const n=[],d={},c={};Object.entries(r).forEach((([e,r])=>{const a=["solar","to_grid","from_grid","to_battery","from_battery"].includes(e),o=!["solar","from_battery"].includes(e),s={},i={};r.forEach((e=>{const r=t[e];if(!r)return;const n={};r.forEach((t=>{if(null===t.change||void 0===t.change)return;const e=t.change;a&&(s[t.start]=t.start in s?s[t.start]+e:e),o&&!(t.start in n)&&(n[t.start]=e)})),i[e]=n})),a&&(c[e]=s),o&&(d[e]=i)}));const l={},u={};if((c.to_grid||c.to_battery)&&c.solar){const t={};for(const e of Object.keys(c.solar)){var _,f;if(t[e]=(c.solar[e]||0)-((null===(_=c.to_grid)||void 0===_?void 0:_[e])||0)-((null===(f=c.to_battery)||void 0===f?void 0:f[e])||0),t[e]<0){var g,m,p;if(c.to_battery)if(l[e]=-1*t[e],l[e]>((null===(g=c.from_grid)||void 0===g?void 0:g[e])||0))u[e]=l[e]-((null===(m=c.from_grid)||void 0===m?void 0:m[e])||0),l[e]=null===(p=c.from_grid)||void 0===p?void 0:p[e];t[e]=0}}d.used_solar={used_solar:t}}if(c.from_battery)if(c.to_grid){const t={};for(const e of Object.keys(c.from_battery))t[e]=(c.from_battery[e]||0)-(u[e]||0);d.used_battery={used_battery:t}}else d.used_battery={used_battery:c.from_battery};if(d.from_grid&&c.to_battery){const t={};for(const e of Object.keys(l)){let r,a=0;for(const[t,o]of Object.entries(d.from_grid))if(o[e]&&(r=t,a++),a>1)break;if(1===a)d.from_grid[r][e]-=l[e]||0;else{let r=0;Object.values(d.from_grid).forEach((t=>{r+=t[e]||0,delete t[e]})),t[e]=r-(l[e]||0)}}d.used_grid={used_grid:t}}let v=[];Object.values(d).forEach((t=>{Object.values(t).forEach((t=>{v=v.concat(Object.keys(t))}))}));const k=Array.from(new Set(v)).sort(((t,e)=>Number(t)-Number(e))),S=(0,b.kT)(this._start,this._compareStart);return Object.entries(d).forEach((([t,r],c)=>{Object.entries(r).forEach((([r,l])=>{var u,_;const f=[];for(const e of k){const r=l[e]||0,a=[Number(e),r&&["to_grid","to_battery"].includes(t)?-1*r:r];i&&(a[2]=a[0],a[0]=S(a[0])),f.push(a)}n.push({id:i?"compare-"+r:r,type:"bar",cursor:"default",name:t in s?s[t]:(0,y.Kd)(this.hass,r,e[r]),order:"used_solar"===t?1:"to_battery"===t?Object.keys(d).length:c+2,barMaxWidth:50,itemStyle:{borderColor:(0,h.H)(o,this.hass.themes.darkMode,!1,i,x[t],null===(u=a[t])||void 0===u?void 0:u[r])},color:(0,h.H)(o,this.hass.themes.darkMode,!0,i,x[t],null===(_=a[t])||void 0===_?void 0:_[r]),stack:i?"compare":"usage",data:f})}))})),n}},{kind:"field",static:!0,key:"styles",value(){return(0,d.iv)(j||(j=E`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));a()}catch(k){a(k)}}))},41924:function(t,e,r){r.d(e,{y:()=>o});var a=r(53907);function o(t){return(0,a.L)(t,Date.now())}},97836:function(t,e,r){r.d(e,{K:()=>s});r(71695),r(47021);var a=r(18492),o=r(7591);function s(t,e,r){const[s,i]=(0,a.d)(null==r?void 0:r.in,t,e);return+(0,o.b)(s)==+(0,o.b)(i)}},16444:function(t,e,r){r.d(e,{z:()=>i});var a=r(53907),o=r(41924),s=r(97836);function i(t,e){return(0,s.K)((0,a.L)((null==e?void 0:e.in)||t,t),(0,o.y)((null==e?void 0:e.in)||t))}}}]);
//# sourceMappingURL=78786.f19bbe5200b75ade.js.map