UNPKG

iobroker.lovelace

Version:

With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI

1 lines 12.1 kB
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[93507],{90433:function(t,e,r){r.d(e,{Vy:function(){return n},fI:function(){return i},ux:function(){return c}});var s=r(22786),o=r(79468);const a=54;function n(t,e){const r=t%a+1;return e.getPropertyValue(`--color-${r}`)}function i(t,e){const r=e.getPropertyValue(`--graph-color-${t+1}`)||n(t,e);return(0,o.RQ)(r)}const c=(0,s.A)(t=>Array.from({length:a},(e,r)=>i(r,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:function(t,e,r){function s(t,e){const r=e-t;return!Number.isFinite(r)||r<=0?1:Math.max(0,Math.ceil(-Math.log10(r/10)))}r.d(e,{G:function(){return s}})},54706:function(t,e,r){r.d(e,{E:function(){return a}});r(74423),r(18111),r(13579),r(3362),r(62953);var s=r(40445),o=r(67576);const a=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(){var t;void 0!==this.__unsubs||!this.isConnected||void 0===this.hass||null!==(t=this.hassSubscribeRequiredHostProps)&&void 0!==t&&t.some(t=>void 0===this[t])||(this.__unsubs=this.hassSubscribe())}}return(0,s.Cg)([(0,o.MZ)({attribute:!1})],e.prototype,"hass",void 0),e}},18427:function(t,e,r){r.d(e,{g:function(){return a}});r(42762);var s=r(79468),o=r(39274);function a(t,e,r,a,n,i){const c=t.getPropertyValue(n+"-"+i).trim(),d=c.length>0?c:t.getPropertyValue(n).trim();let u=(0,s.RQ)(d);return 0===c.length&&i&&(u=(0,s.v2)((0,s.BE)(e?(0,o.T)((0,s.Nc)((0,s.xp)(u)),i):(0,o.d)((0,s.Nc)((0,s.xp)(u)),i)))),a?u+=r?"32":"7F":r&&(u+="7F"),u}},40345:function(t,e,r){r.a(t,async function(t,e){try{var s=r(40445),o=r(5124),a=r(67576),n=r(34127),i=t([n]);n=(i.then?(await i)():i)[0];let c,d,u=t=>t;class h extends o.WF{render(){const t=`energy-graph-chip-${Date.now()}`;return(0,o.qy)(c||(c=u` <div class="chip" id="${0}"> <slot></slot> </div> <ha-tooltip for="${0}" placement="top">${0}</ha-tooltip> `),t,t,this.tooltip)}}h.styles=(0,o.AH)(d||(d=u`.chip{font-size:var(--ha-font-size-m);font-weight:var(--ha-font-weight-medium);padding:var(--ha-space-1) var(--ha-space-2);border-radius:var(--ha-border-radius-md);border:1px solid var(--divider-color)}`)),(0,s.Cg)([(0,a.MZ)({type:String})],h.prototype,"tooltip",void 0),h=(0,s.Cg)([(0,a.EM)("hui-energy-graph-chip")],h),e()}catch(c){e(c)}})},14207:function(t,e,r){r.a(t,async function(t,s){try{r.r(e),r.d(e,{HuiEnergyUsageGraphCard:function(){return O}});r(74423),r(44114),r(26910),r(18111),r(7588),r(13579),r(3362),r(62953);var o=r(40445),a=r(73684),n=r(40600),i=r(81859),c=r(5124),d=r(67576),u=r(6412),h=r(22786),l=r(18427),g=r(20058),_=r(44439),p=r(89938),y=(r(76776),r(40345)),f=r(38114),m=r(23528),b=r(54706),v=r(784),k=r(97372),C=t([_,y,f,m,g,k]);[_,y,f,m,g,k]=C.then?(await C)():C;let x,S,w,D,$,E=t=>t;const z={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"};class O extends((0,b.E)(c.WF)){static async getConfigElement(){return await r.e(79062).then(r.bind(r,54197)),document.createElement("hui-energy-graph-card-editor")}static getStubConfig(t,e,r){return{type:"energy-usage-graph"}}hassSubscribe(){var t;return[(0,f.tb)(this.hass,{key:null===(t=this._config)||void 0===t?void 0:t.collection_key}).subscribe(t=>this._getStatistics(t))]}getCardSize(){return 3}setConfig(t){t.collection_key&&(0,f.s8)(t.collection_key),this._config=t}shouldUpdate(t){return(0,v.xP)(this,t)||t.size>1||!t.has("hass")}render(){return this.hass&&this._config?(0,c.qy)(x||(x=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,c.qy)(S||(S=E` <div class="card-header"> <span>${0}</span> ${0} </div>`),this._config.title,this._total?(0,c.qy)(w||(w=E`<hui-energy-graph-chip .tooltip="${0}"> ${0} </hui-energy-graph-chip>`),this._formatTotal(this._total),this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.total_usage",{num:(0,g.ZV)(this._total,this.hass.locale)})):c.s6):c.s6,(0,u.H)({"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._yAxisFractionDigits),this._chartData.some(t=>t.data.length)?"":(0,c.qy)(D||(D=E`<div class="no-data"> ${0} </div>`),(0,a.c)(this._start)?this.hass.localize("ui.panel.lovelace.cards.energy.no_data"):this.hass.localize("ui.panel.lovelace.cards.energy.no_data_period"))):c.s6}async _getStatistics(t){const e=[];let r=1/0,s=-1/0;const o=t=>{t<r&&(r=t),t>s&&(s=t)},a={},i={to_grid:{},from_grid:{},to_battery:{}};for(const n of t.prefs.energy_sources){if("solar"===n.type){a.solar?a.solar.push(n.stat_energy_from):a.solar=[n.stat_energy_from];continue}if("battery"===n.type){a.to_battery?(a.to_battery.push(n.stat_energy_to),a.from_battery.push(n.stat_energy_from)):(a.to_battery=[n.stat_energy_to],a.from_battery=[n.stat_energy_from]),n.name&&(i.to_battery[n.stat_energy_to]=this.hass.localize("ui.panel.lovelace.cards.energy.energy_sources_table.named_battery_charged",{name:n.name}));continue}if("grid"!==n.type)continue;const t=n;t.stat_energy_from&&(a.from_grid?a.from_grid.push(t.stat_energy_from):a.from_grid=[t.stat_energy_from],t.name&&(i.from_grid[t.stat_energy_from]=t.stat_energy_to?this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.named_grid_consumed",{name:t.name}):t.name)),t.stat_energy_to&&(a.to_grid?a.to_grid.push(t.stat_energy_to):a.to_grid=[t.stat_energy_to],t.name&&(i.to_grid[t.stat_energy_to]=t.stat_energy_from?this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.named_grid_exported",{name:t.name}):t.name))}const c=getComputedStyle(this),d={};Object.keys(z).forEach(t=>{d[t]={},"used_grid"!==t&&"used_solar"!==t&&"used_battery"!==t&&a[t]&&Object.values(a[t]).forEach((e,r)=>{d[t][e]=r})});const u={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,n.o)(),this._compareStart=t.startCompare,this._compareEnd=t.endCompare;const{summedData:h,compareSummedData:l}=(0,f.gv)(t),{consumption:g,compareConsumption:_}=(0,f.DR)(h,l);t.statsCompare&&e.push(...this._processDataSet(t.statsCompare,t.statsMetadata,l,_,a,d,c,u,i,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,h,g,a,d,c,u,i,o,!1)),e.sort((t,e)=>t.order-e.order),(0,k.RR)(e),this._yAxisFractionDigits=(0,p.G)(r,s),this._chartData=e,this._total=this._processTotal(g)}_processTotal(t){return t.total.used_total>0?t.total.used_total:void 0}_processDataSet(t,e,r,s,o,a,n,i,c,d,u=!1){const h=[],g={};if(Object.entries(o).forEach(([e,r])=>{if(!["to_grid","from_grid","to_battery"].includes(e))return;const s={};r.forEach(e=>{const r=t[e];if(!r)return;const o={};r.forEach(t=>{if(null===t.change||void 0===t.change)return;const e=t.change;t.start in o||(o[t.start]=e)}),s[e]=o}),g[e]=s}),g.used_solar={used_solar:s.used_solar},g.used_battery={used_battery:s.used_battery},g.from_grid&&r.to_battery){const t={};for(const[e,r]of Object.entries(s.grid_to_battery)){if(!r)continue;let o,a=0;for(const[t,r]of Object.entries(g.from_grid))if(r[e]&&(o=t,a++),a>1)break;1===a?g.from_grid[o][e]=s.used_grid[e]:(Object.values(g.from_grid).forEach(t=>{delete t[e]}),t[e]=s.used_grid[e])}g.used_grid={used_grid:t}}const _=r.timestamps,p=(0,f.TI)(this._start,this._end),y=("hour"===p||"5minute"===p)&&_.length>=2?(_[1]-_[0])/2:0,b=(0,k.ok)(this._start,this._compareStart);return Object.entries(g).forEach(([t,r],s)=>{Object.entries(r).forEach(([r,o])=>{var p,f,v;const k=[];for(const e of _){const r=o[e]||0,s=r&&["to_grid","to_battery"].includes(t)?-1*r:r,a=[e+y,s,e];u&&(a[0]=b(new Date(e)).getTime()+y),k.push(a),d(s)}h.push({id:`${u?"compare-":""}${r}-${t}`,type:"bar",cursor:"default",name:t in i?i[t]:(null===(p=c[t])||void 0===p?void 0:p[r])||(0,m.$O)(this.hass,r,e[r]),order:"used_solar"===t?1:"to_battery"===t?Object.keys(g).length:s+2,barMaxWidth:50,itemStyle:{borderColor:(0,l.g)(n,this.hass.themes.darkMode,!1,u,z[t],null===(f=a[t])||void 0===f?void 0:f[r])},color:(0,l.g)(n,this.hass.themes.darkMode,!0,u,z[t],null===(v=a[t])||void 0===v?void 0:v[r]),stack:u?"compare":"usage",data:k})})}),h}constructor(...t){super(...t),this._chartData=[],this._yAxisFractionDigits=1,this._start=(0,i.R)(),this._end=(0,n.o)(),this.hassSubscribeRequiredHostProps=["_config"],this._formatTotal=t=>t>0?this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.total_consumed",{num:(0,g.ZV)(t,this.hass.locale)}):this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.total_returned",{num:(0,g.ZV)(-t,this.hass.locale)}),this._createOptions=(0,h.A)((t,e,r,s,o,a,n)=>{const i=(0,k.od)(t,e,r,s,"kWh",o,a,this._formatTotal,!1,n),d=i.tooltip,u=d&&!Array.isArray(d)&&"function"==typeof d.formatter?d.formatter:void 0;return Object.assign(Object.assign({},i),{},{tooltip:Object.assign(Object.assign({},i.tooltip),{},{formatter:t=>{if(!Array.isArray(t))return c.s6;const e=[...t].sort((t,e)=>{var r,s;const o=null===(r=t.value)||void 0===r?void 0:r[1],a=null===(s=e.value)||void 0===s?void 0:s[1];return o>0&&a<0?-1:a>0&&o<0?1:o>0?e.componentIndex-t.componentIndex:t.componentIndex-e.componentIndex});return u?u(e):c.s6}})})})}}O.styles=(0,c.AH)($||($=E`ha-card{height:100%}.card-header{display:flex;justify-content:space-between;align-items:center;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,o.Cg)([(0,d.MZ)({attribute:!1})],O.prototype,"hass",void 0),(0,o.Cg)([(0,d.wk)()],O.prototype,"_config",void 0),(0,o.Cg)([(0,d.wk)()],O.prototype,"_chartData",void 0),(0,o.Cg)([(0,d.wk)()],O.prototype,"_yAxisFractionDigits",void 0),(0,o.Cg)([(0,d.wk)()],O.prototype,"_start",void 0),(0,o.Cg)([(0,d.wk)()],O.prototype,"_end",void 0),(0,o.Cg)([(0,d.wk)()],O.prototype,"_compareStart",void 0),(0,o.Cg)([(0,d.wk)()],O.prototype,"_compareEnd",void 0),(0,o.Cg)([(0,d.wk)()],O.prototype,"_total",void 0),O=(0,o.Cg)([(0,d.EM)("hui-energy-usage-graph-card")],O),s()}catch(x){s(x)}})},43382:function(t,e,r){r.d(e,{A:function(){return o}});var s=r(73420);function o(t){return(0,s.w)(t,Date.now())}},6116:function(t,e,r){r.d(e,{o:function(){return a}});var s=r(6439),o=r(83339);function a(t,e,r){const a=(0,o.b)(t,e)/6e4;return(0,s.u)(null==r?void 0:r.roundingMethod)(a)}},40600:function(t,e,r){r.d(e,{o:function(){return o}});var s=r(73983);function o(t){return(0,s.D)(Date.now(),t)}},83309:function(t,e,r){r.d(e,{r:function(){return a}});r(62953);var s=r(74816),o=r(35932);function a(t,e,r){const[a,n]=(0,s.x)(null==r?void 0:r.in,t,e);return+(0,o.o)(a)===+(0,o.o)(n)}},73684:function(t,e,r){r.d(e,{c:function(){return n}});var s=r(73420),o=r(43382),a=r(83309);function n(t,e){return(0,a.r)((0,s.w)((null==e?void 0:e.in)||t,t),(0,o.A)((null==e?void 0:e.in)||t))}},81859:function(t,e,r){r.d(e,{R:function(){return o}});var s=r(35932);function o(t){return(0,s.o)(Date.now(),t)}}}]);