iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
2 lines • 15.5 kB
JavaScript
export const __webpack_ids__=["51171"];export const __webpack_modules__={50875:function(t,e,r){r.d(e,{Eu:()=>i,hZ:()=>n,o9:()=>d});var a=r(27486),s=r(11259);const o=["#4269d0","#f4bd4a","#ff725c","#6cc5b0","#a463f2","#ff8ab7","#9c6b4e","#97bbf5","#01ab63","#9498a0","#094bad","#c99000","#d84f3e","#49a28f","#048732","#d96895","#8043ce","#7599d1","#7a4c31","#74787f","#6989f4","#ffd444","#ff957c","#8fe9d3","#62cc71","#ffadda","#c884ff","#badeff","#bf8b6d","#b6bac2","#927acc","#97ee3f","#bf3947","#9f5b00","#f48758","#8caed6","#f2b94f","#eff26e","#e43872","#d9b100","#9d7a00","#698cff","#d9d9d9","#00d27e","#d06800","#009f82","#c49200","#cbe8ff","#fecddf","#c27eb6","#8cd2ce","#c4b8d9","#f883b0","#a49100","#f48800","#27d0df","#a04a9b"];function i(t){return o[t%o.length]}function n(t,e){const r=e.getPropertyValue(`--graph-color-${t+1}`)||i(t);return(0,s.Rq)(r)}const d=(0,a.Z)((t=>o.map(((e,r)=>n(r,t)))),((t,e)=>t[0].getPropertyValue("--graph-color-1")===e[0].getPropertyValue("--graph-color-1")))},17705:function(t,e,r){r.d(e,{Cj:()=>f,F7:()=>s,Hs:()=>x,Kd:()=>k,Kj:()=>h,Nw:()=>y,PA:()=>o,Py:()=>d,Qm:()=>C,Z0:()=>p,_Y:()=>u,_m:()=>i,dL:()=>c,dO:()=>S,hN:()=>_,h_:()=>l,j2:()=>v,q6:()=>m,uR:()=>n});r(9359),r(52924);var a=r(47194);let s=function(t){return t[t.NONE=0]="NONE",t[t.ARITHMETIC=1]="ARITHMETIC",t[t.CIRCULAR=2]="CIRCULAR",t}({});const o=99387==r.j?["entity_not_recorded","entity_no_longer_recorded","state_class_removed","units_changed","mean_type_changed","no_state"]:null,i=t=>t.sendMessagePromise({type:"recorder/info"}),n=(t,e)=>t.callWS({type:"recorder/list_statistic_ids",statistic_type:e}),d=(t,e)=>t.callWS({type:"recorder/get_statistics_metadata",statistic_ids:e}),c=(t,e,r,a,s="hour",o,i)=>t.callWS({type:"recorder/statistics_during_period",start_time:e.toISOString(),end_time:r?.toISOString(),statistic_ids:a,period:s,units:o,types:i}),u=(t,e,r,a)=>t.callWS({type:"recorder/statistic_during_period",statistic_id:e,units:a,fixed_period:r.fixed_period?{start_time:r.fixed_period.start instanceof Date?r.fixed_period.start.toISOString():r.fixed_period.start,end_time:r.fixed_period.end instanceof Date?r.fixed_period.end.toISOString():r.fixed_period.end}:void 0,calendar:r.calendar,rolling_window:r.rolling_window}),l=t=>t.callWS({type:"recorder/validate_statistics"}),f=(t,e,r)=>t.callWS({type:"recorder/update_statistics_metadata",statistic_id:e,unit_of_measurement:r}),_=(t,e)=>t.callWS({type:"recorder/clear_statistics",statistic_ids:e}),h=t=>{let e=null;if(!t)return null;for(const r of t)null!==r.change&&void 0!==r.change&&(null===e?e=r.change:e+=r.change);return e},m=(t,e)=>{let r=null;for(const a of e){if(!(a in t))continue;const e=h(t[a]);null!==e&&(null===r?r=e:r+=e)}return r},y=(t,e)=>t.some((t=>void 0!==t[e]&&null!==t[e])),g=["mean","min","max"],b=["sum","state","change"],p=(t,e)=>!(!g.includes(e)||t.mean_type===s.NONE)||!(!b.includes(e)||!t.has_sum),v=(t,e,r,a,s)=>{const o=new Date(r).toISOString();return t.callWS({type:"recorder/adjust_sum_statistics",statistic_id:e,start_time:o,adjustment:a,adjustment_unit_of_measurement:s})},k=(t,e,r)=>{const s=t.states[e];return s?(0,a.C)(s):r?.name||e},S=(t,e,r)=>{let a;return e&&(a=t.states[e]?.attributes.unit_of_measurement),void 0===a?r?.statistics_unit_of_measurement:a},x=t=>t.includes(":"),C=t=>t.callWS({type:"recorder/update_statistics_issues"})},6736:function(t,e,r){r.d(e,{f:()=>i});var a=r(44249),s=r(72621),o=(r(9359),r(52924),r(15093));const i=t=>(0,a.Z)(null,(function(t,e){class r extends e{constructor(...e){super(...e),t(this)}}return{F:r,d:[{kind:"field",decorators:[(0,o.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",key:"hassSubscribeRequiredHostProps",value:void 0},{kind:"field",key:"__unsubs",value:void 0},{kind:"method",key:"connectedCallback",value:function(){(0,s.Z)(r,"connectedCallback",this,3)([]),this._checkSubscribed()}},{kind:"method",key:"disconnectedCallback",value:function(){if((0,s.Z)(r,"disconnectedCallback",this,3)([]),this.__unsubs){for(;this.__unsubs.length;){const t=this.__unsubs.pop();t instanceof Promise?t.then((t=>t())):t()}this.__unsubs=void 0}}},{kind:"method",key:"updated",value:function(t){if((0,s.Z)(r,"updated",this,3)([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()}},{kind:"method",key:"hassSubscribe",value:function(){return[]}},{kind:"method",key:"_checkSubscribed",value:function(){void 0===this.__unsubs&&this.isConnected&&void 0!==this.hass&&!this.hassSubscribeRequiredHostProps?.some((t=>void 0===this[t]))&&(this.__unsubs=this.hassSubscribe())}}]}}),t)},20548:function(t,e,r){r.d(e,{H:()=>o});var a=r(11259),s=r(4643);function o(t,e,r,o,i,n){const d=t.getPropertyValue(i+"-"+n).trim(),c=d.length>0?d:t.getPropertyValue(i).trim();let u=(0,a.Rq)(c);return 0===d.length&&n&&(u=(0,a.CO)((0,a.p3)(e?(0,s.C)((0,a.Rw)((0,a.wK)(u)),n):(0,s.W)((0,a.Rw)((0,a.wK)(u)),n)))),o?u+=r?"32":"7F":r&&(u+="7F"),u}},53259:function(t,e,r){r.a(t,(async function(t,a){try{r.d(e,{J:()=>v,MC:()=>b,Zx:()=>S,b4:()=>p,kT:()=>x});r(92745),r(9359),r(56475),r(31526),r(70104),r(92519),r(42179),r(89256),r(24931),r(88463),r(57449),r(19814);var s=r(21893),o=r(13809),i=r(38836),n=r(84775),d=r(80951),c=r(13730),u=r(6542),l=r(83204),f=r(23459),_=r(23711),h=r(50602),m=r(46467),y=r(33570),g=t([m,y,h]);function b(t,e){let r=new Date(e);return t>2&&0===r.getHours()&&(r=(0,s.b)(r,1)),r.setMinutes(0,0,0),t>35&&r.setDate(1),t>2&&r.setHours(0),r.getTime()}function p(t){return t>35?"month":t>2?"day":"hour"}function v(t,e,r,a,s,i,n,d){const c=(0,o.j)(e,t),u=void 0!==i&&void 0!==n;return{xAxis:{type:"time",min:t,max:b(c,e)},yAxis:{type:"value",name:s,nameGap:2,nameTextStyle:{align:"left"},axisLabel:{formatter:t=>(0,h.uf)(Math.abs(t),r)},splitLine:{show:!0}},grid:{top:15,bottom:0,left:1,right:1,containLabel:!0},tooltip:{trigger:"axis",formatter:t=>{if(Array.isArray(t)){const e=[],o=[];return t.forEach((t=>{t.seriesId?.startsWith("compare-")?o.push(t):e.push(t)})),[e,o].map((t=>k(t,r,a,c,u,s,d))).filter(Boolean).join("<br><br>")}return k([t],r,a,c,u,s,d)}}}}function k(t,e,r,a,s,o,n){if(!t[0]?.value)return"";const d=new Date(t[0].value?.[2]??t[0].value?.[0]);let c;c=a>89?`${(0,m.NC)(d,e,r)}`:a>0?`${(0,m.ud)(d,e,r)}`:`${s?`${(0,m.ud)(d,e,r)}: `:""}${(0,y.mr)(d,e,r)} – ${(0,y.mr)((0,i.T)(d,1),e,r)}`;const u=`<h4 style="text-align: center; margin: 0;">${c}</h4>`;let l=0,f=0,_=0,g=0;const b=t.map((t=>{const r=t.value?.[1],a=(0,h.uf)(r,e);return"0"!==a&&("bar"===t.componentSubType&&(r>0?(l+=r,f++):(_+=r,g++)),`${t.marker} ${t.seriesName}: ${a} ${o}`)})).filter(Boolean);let p="";return 0!==l&&f>1&&n&&(p+=`<br><b>${n(l)}</b>`),0!==_&&g>1&&n&&(p+=`<br><b>${n(_)}</b>`),b.length>0?`${u}${b.join("<br>")}${p}`:""}function S(t){Array.from(new Set(t.map((t=>t.data.map((t=>Number(t[0]))))).flat())).sort(((t,e)=>t-e)).forEach(((e,r)=>{const a={},s={};for(let o=t.length-1;o>=0;o--){const i=t[o].data[r],n=i&&"object"==typeof i&&"value"in i?i:{value:i},d=n.value?.[0],c=t[o].stack??"";void 0!==d&&(Number(d)!==e?t[o].data?.splice(r,0,{value:[e,0],itemStyle:{borderWidth:0}}):0===n.value?.[1]?t[o].data[r]={...n,itemStyle:{...n.itemStyle,borderWidth:0}}:!a[c]&&n.value?.[1]>0?(t[o].data[r]={...n,itemStyle:{...n.itemStyle,borderRadius:[4,4,0,0]}},a[c]=!0):!s[c]&&n.value?.[1]<0&&(t[o].data[r]={...n,itemStyle:{...n.itemStyle,borderRadius:[0,0,4,4]}},s[c]=!0))}}))}function x(t,e){if(!e)return t=>t;const r=(0,n.o)(t,e);if(0!==r&&t.getTime()===(0,d.e)(t).getTime())return t=>(0,c.B)(t,r);const a=(0,u.d)(t,e);if(0!==a&&t.getTime()===(0,l.N)(t).getTime())return t=>(0,f.z)(t,a);const s=t.getTime()-e.getTime();return t=>(0,_.n)(t,s)}[m,y,h]=g.then?(await g)():g,a()}catch(C){a(C)}}))},32672:function(t,e,r){r.a(t,(async function(t,a){try{r.r(e),r.d(e,{HuiEnergyUsageGraphCard:()=>S});var s=r(44249),o=(r(92745),r(9359),r(31526),r(52924),r(92519),r(42179),r(89256),r(24931),r(88463),r(57449),r(19814),r(42625)),i=r(83389),n=r(16444),d=r(57243),c=r(15093),u=r(35359),l=r(27486),f=r(20548),_=r(50602),h=r(25179),m=(r(54977),r(1118)),y=r(17705),g=r(6736),b=r(93331),p=r(53259),v=t([h,m,_,p]);[h,m,_,p]=v.then?(await v)():v;const k={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 S=(0,s.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:()=>[]},{kind:"field",decorators:[(0,c.SB)()],key:"_start",value:()=>(0,o.I)()},{kind:"field",decorators:[(0,c.SB)()],key:"_end",value:()=>(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:()=>["_config"]},{kind:"method",key:"hassSubscribe",value:function(){return[(0,m.UB)(this.hass,{key:this._config?.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,b.SN)(this,t)||t.size>1||!t.has("hass")}},{kind:"method",key:"render",value:function(){return this.hass&&this._config?d.dy` <ha-card> ${this._config.title?d.dy`<h1 class="card-header">${this._config.title}</h1>`:""} <div class="content ${(0,u.$)({"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)}" chart-type="bar"></ha-chart-base> ${this._chartData.some((t=>t.data.length))?"":d.dy`<div class="no-data"> ${(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")} </div>`} </div> </ha-card> `: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,l.Z)(((t,e,r,a,s,o)=>{const i=(0,p.J)(t,e,r,a,"kWh",s,o,this._formatTotal);return{...i,tooltip:{...i.tooltip,formatter:t=>Array.isArray(t)?(t.sort(((t,e)=>{const r=t.value?.[1],a=e.value?.[1];return r>0&&a<0?-1:a>0&&r<0?1:r>0?e.componentIndex-t.componentIndex:t.componentIndex-e.componentIndex})),i.tooltip?.formatter?.(t)):""}}}))}},{kind:"method",key:"_getStatistics",value:async function(t){const e=[],r={};for(const e of t.prefs.energy_sources)if("solar"!==e.type)if("battery"!==e.type){if("grid"===e.type){for(const t of e.flow_from)r.from_grid?r.from_grid.push(t.stat_energy_from):r.from_grid=[t.stat_energy_from];for(const t of e.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(e.stat_energy_to),r.from_battery.push(e.stat_energy_from)):(r.to_battery=[e.stat_energy_to],r.from_battery=[e.stat_energy_from]);else r.solar?r.solar.push(e.stat_energy_from):r.solar=[e.stat_energy_from];const a=getComputedStyle(this),s={};Object.keys(k).forEach((t=>{s[t]={},"used_grid"!==t&&"used_solar"!==t&&"used_battery"!==t&&r[t]&&Object.values(r[t]).forEach(((e,r)=>{s[t][e]=r}))}));const o={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,s,a,o,!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,s,a,o,!1)),e.sort(((t,e)=>t.order-e.order)),(0,p.Zx)(e),this._chartData=e}},{kind:"method",key:"_processDataSet",value:function(t,e,r,a,s,o,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),s=!["solar","from_battery"].includes(e),o={},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&&(o[t.start]=t.start in o?o[t.start]+e:e),s&&!(t.start in n)&&(n[t.start]=e)})),i[e]=n})),a&&(c[e]=o),s&&(d[e]=i)}));const u={},l={};if((c.to_grid||c.to_battery)&&c.solar){const t={};for(const e of Object.keys(c.solar))t[e]=(c.solar[e]||0)-(c.to_grid?.[e]||0)-(c.to_battery?.[e]||0),t[e]<0&&(c.to_battery&&(u[e]=-1*t[e],u[e]>(c.from_grid?.[e]||0)&&(l[e]=u[e]-(c.from_grid?.[e]||0),u[e]=c.from_grid?.[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)-(l[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(u)){let r,a=0;for(const[t,s]of Object.entries(d.from_grid))if(s[e]&&(r=t,a++),a>1)break;if(1===a)d.from_grid[r][e]-=u[e]||0;else{let r=0;Object.values(d.from_grid).forEach((t=>{r+=t[e]||0,delete t[e]})),t[e]=r-(u[e]||0)}}d.used_grid={used_grid:t}}let _=[];Object.values(d).forEach((t=>{Object.values(t).forEach((t=>{_=_.concat(Object.keys(t))}))}));const h=Array.from(new Set(_)).sort(((t,e)=>Number(t)-Number(e))),m=(0,p.kT)(this._start,this._compareStart);return Object.entries(d).forEach((([t,r],c)=>{Object.entries(r).forEach((([r,u])=>{const l=[];for(const e of h){const r=u[e]||0,a=[Number(e),r&&["to_grid","to_battery"].includes(t)?-1*r:r];i&&(a[2]=a[0],a[0]=m(a[0])),l.push(a)}n.push({id:i?"compare-"+r:r,type:"bar",cursor:"default",name:t in o?o[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,f.H)(s,this.hass.themes.darkMode,!1,i,k[t],a[t]?.[r])},color:(0,f.H)(s,this.hass.themes.darkMode,!0,i,k[t],a[t]?.[r]),stack:i?"compare":"usage",data:l})}))})),n}},{kind:"field",static:!0,key:"styles",value:()=>d.iv`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,g.f)(d.oi));a()}catch(t){a(t)}}))},41924:function(t,e,r){r.d(e,{y:()=>s});var a=r(53907);function s(t){return(0,a.L)(t,Date.now())}},97836:function(t,e,r){r.d(e,{K:()=>o});var a=r(18492),s=r(7591);function o(t,e,r){const[o,i]=(0,a.d)(r?.in,t,e);return+(0,s.b)(o)==+(0,s.b)(i)}},16444:function(t,e,r){r.d(e,{z:()=>i});var a=r(53907),s=r(41924),o=r(97836);function i(t,e){return(0,o.K)((0,a.L)(e?.in||t,t),(0,s.y)(e?.in||t))}}};
//# sourceMappingURL=51171.ebaba1d489e62731.js.map