iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 11.2 kB
JavaScript
export const __rspack_esm_id=93507;export const __rspack_esm_ids=[93507];export const __webpack_modules__={90433(t,e,r){r.d(e,{Vy:()=>o,fI:()=>i,ux:()=>n});var s=r(22786),a=r(79468);function o(t,e){const r=t%54+1;return e.getPropertyValue(`--color-${r}`)}function i(t,e){const r=e.getPropertyValue(`--graph-color-${t+1}`)||o(t,e);return(0,a.RQ)(r)}const n=(0,s.A)(t=>Array.from({length:54},(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(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:()=>s})},54706(t,e,r){r.d(e,{E:()=>o});r(74423),r(18111),r(13579);var s=r(62826),a=r(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,a.MZ)({attribute:!1})],e.prototype,"hass",void 0),e}},18427(t,e,r){r.d(e,{g:()=>o});var s=r(79468),a=r(39274);function o(t,e,r,o,i,n){const c=t.getPropertyValue(i+"-"+n).trim(),d=c.length>0?c:t.getPropertyValue(i).trim();let h=(0,s.RQ)(d);return 0===c.length&&n&&(h=(0,s.v2)((0,s.BE)(e?(0,a.T)((0,s.Nc)((0,s.xp)(h)),n):(0,a.d)((0,s.Nc)((0,s.xp)(h)),n)))),o?h+=r?"32":"7F":r&&(h+="7F"),h}},40345(t,e,r){r.a(t,async function(t,e){try{var s=r(62826),a=r(5124),o=r(22441),i=r(34127),n=t([i]);i=(n.then?(await n)():n)[0];class c extends a.WF{render(){const t=`energy-graph-chip-${Date.now()}`;return a.qy` <div class="chip" id="${t}"> <slot></slot> </div> <ha-tooltip for="${t}" placement="top">${this.tooltip}</ha-tooltip> `}}c.styles=a.AH`.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,o.MZ)({type:String})],c.prototype,"tooltip",void 0),c=(0,s.Cg)([(0,o.EM)("hui-energy-graph-chip")],c),e()}catch(t){e(t)}})},14207(t,e,r){r.a(t,async function(t,s){try{r.r(e),r.d(e,{HuiEnergyUsageGraphCard:()=>S});r(74423),r(44114),r(18111),r(7588),r(13579);var a=r(62826),o=r(73684),i=r(40600),n=r(81859),c=r(5124),d=r(22441),h=r(6412),_=r(22786),l=r(18427),u=r(20058),g=r(44439),p=r(89938),y=(r(76776),r(40345)),m=r(38114),f=r(23528),b=r(54706),v=r(784),k=r(97372),C=t([g,y,m,u,k]);[g,y,m,u,k]=C.then?(await C)():C;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"};class S 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(){return[(0,m.tb)(this.hass,{key:this._config?.collection_key}).subscribe(t=>this._getStatistics(t))]}getCardSize(){return 3}setConfig(t){t.collection_key&&(0,m.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?c.qy` <ha-card> ${this._config.title?c.qy` <div class="card-header"> <span>${this._config.title}</span> ${this._total?c.qy`<hui-energy-graph-chip .tooltip="${this._formatTotal(this._total)}"> ${this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.total_usage",{num:(0,u.ZV)(this._total,this.hass.locale)})} </hui-energy-graph-chip>`:c.s6} </div>`:c.s6} <div class="content ${(0,h.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._yAxisFractionDigits)}" chart-type="bar"></ha-chart-base> ${this._chartData.some(t=>t.data.length)?"":c.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> `:c.s6}async _getStatistics(t){const e=[];let r=1/0,s=-1/0;const a=t=>{t<r&&(r=t),t>s&&(s=t)},o={},n={to_grid:{},from_grid:{},to_battery:{}};for(const e of t.prefs.energy_sources){if("solar"===e.type){o.solar?o.solar.push(e.stat_energy_from):o.solar=[e.stat_energy_from];continue}if("battery"===e.type){o.to_battery?(o.to_battery.push(e.stat_energy_to),o.from_battery.push(e.stat_energy_from)):(o.to_battery=[e.stat_energy_to],o.from_battery=[e.stat_energy_from]),e.name&&(n.to_battery[e.stat_energy_to]=this.hass.localize("ui.panel.lovelace.cards.energy.energy_sources_table.named_battery_charged",{name:e.name}));continue}if("grid"!==e.type)continue;const t=e;t.stat_energy_from&&(o.from_grid?o.from_grid.push(t.stat_energy_from):o.from_grid=[t.stat_energy_from],t.name&&(n.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&&(o.to_grid?o.to_grid.push(t.stat_energy_to):o.to_grid=[t.stat_energy_to],t.name&&(n.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(x).forEach(t=>{d[t]={},"used_grid"!==t&&"used_solar"!==t&&"used_battery"!==t&&o[t]&&Object.values(o[t]).forEach((e,r)=>{d[t][e]=r})});const h={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.o)(),this._compareStart=t.startCompare,this._compareEnd=t.endCompare;const{summedData:_,compareSummedData:l}=(0,m.gv)(t),{consumption:u,compareConsumption:g}=(0,m.DR)(_,l);t.statsCompare&&e.push(...this._processDataSet(t.statsCompare,t.statsMetadata,l,g,o,d,c,h,n,a,!0)),e.push({id:"compare-placeholder",type:"bar",stack:t.statsCompare?"compare":"usage",data:[],order:0}),e.push(...this._processDataSet(t.stats,t.statsMetadata,_,u,o,d,c,h,n,a,!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(u)}_processTotal(t){return t.total.used_total>0?t.total.used_total:void 0}_processDataSet(t,e,r,s,a,o,i,n,c,d,h=!1){const _=[],u={};if(Object.entries(a).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 a={};r.forEach(t=>{if(null===t.change||void 0===t.change)return;const e=t.change;t.start in a||(a[t.start]=e)}),s[e]=a}),u[e]=s}),u.used_solar={used_solar:s.used_solar},u.used_battery={used_battery:s.used_battery},u.from_grid&&r.to_battery){const t={};for(const[e,r]of Object.entries(s.grid_to_battery)){if(!r)continue;let a,o=0;for(const[t,r]of Object.entries(u.from_grid))if(r[e]&&(a=t,o++),o>1)break;1===o?u.from_grid[a][e]=s.used_grid[e]:(Object.values(u.from_grid).forEach(t=>{delete t[e]}),t[e]=s.used_grid[e])}u.used_grid={used_grid:t}}const g=r.timestamps,p=(0,m.TI)(this._start,this._end),y=("hour"===p||"5minute"===p)&&g.length>=2?(g[1]-g[0])/2:0,b=(0,k.ok)(this._start,this._compareStart);return Object.entries(u).forEach(([t,r],s)=>{Object.entries(r).forEach(([r,a])=>{const p=[];for(const e of g){const r=a[e]||0,s=r&&["to_grid","to_battery"].includes(t)?-1*r:r,o=[e+y,s,e];h&&(o[0]=b(new Date(e)).getTime()+y),p.push(o),d(s)}_.push({id:`${h?"compare-":""}${r}-${t}`,type:"bar",cursor:"default",name:t in n?n[t]:c[t]?.[r]||(0,f.$O)(this.hass,r,e[r]),order:"used_solar"===t?1:"to_battery"===t?Object.keys(u).length:s+2,barMaxWidth:50,itemStyle:{borderColor:(0,l.g)(i,this.hass.themes.darkMode,!1,h,x[t],o[t]?.[r])},color:(0,l.g)(i,this.hass.themes.darkMode,!0,h,x[t],o[t]?.[r]),stack:h?"compare":"usage",data:p})})}),_}constructor(...t){super(...t),this._chartData=[],this._yAxisFractionDigits=1,this._start=(0,n.R)(),this._end=(0,i.o)(),this.hassSubscribeRequiredHostProps=["_config"],this._formatTotal=t=>t>0?this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.total_consumed",{num:(0,u.ZV)(t,this.hass.locale)}):this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.total_returned",{num:(0,u.ZV)(-t,this.hass.locale)}),this._createOptions=(0,_.A)((t,e,r,s,a,o,i)=>{const n=(0,k.od)(t,e,r,s,"kWh",a,o,this._formatTotal,!1,i),d=n.tooltip,h=d&&!Array.isArray(d)&&"function"==typeof d.formatter?d.formatter:void 0;return{...n,tooltip:{...n.tooltip,formatter:t=>{if(!Array.isArray(t))return c.s6;const e=[...t].sort((t,e)=>{const r=t.value?.[1],s=e.value?.[1];return r>0&&s<0?-1:s>0&&r<0?1:r>0?e.componentIndex-t.componentIndex:t.componentIndex-e.componentIndex});return h?h(e):c.s6}}}})}}S.styles=c.AH`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,a.Cg)([(0,d.MZ)({attribute:!1})],S.prototype,"hass",void 0),(0,a.Cg)([(0,d.wk)()],S.prototype,"_config",void 0),(0,a.Cg)([(0,d.wk)()],S.prototype,"_chartData",void 0),(0,a.Cg)([(0,d.wk)()],S.prototype,"_yAxisFractionDigits",void 0),(0,a.Cg)([(0,d.wk)()],S.prototype,"_start",void 0),(0,a.Cg)([(0,d.wk)()],S.prototype,"_end",void 0),(0,a.Cg)([(0,d.wk)()],S.prototype,"_compareStart",void 0),(0,a.Cg)([(0,d.wk)()],S.prototype,"_compareEnd",void 0),(0,a.Cg)([(0,d.wk)()],S.prototype,"_total",void 0),S=(0,a.Cg)([(0,d.EM)("hui-energy-usage-graph-card")],S),s()}catch(t){s(t)}})},43382(t,e,r){r.d(e,{A:()=>a});var s=r(73420);function a(t){return(0,s.w)(t,Date.now())}},6116(t,e,r){r.d(e,{o:()=>o});var s=r(6439),a=r(83339);function o(t,e,r){const o=(0,a.b)(t,e)/6e4;return(0,s.u)(r?.roundingMethod)(o)}},40600(t,e,r){r.d(e,{o:()=>a});var s=r(73983);function a(t){return(0,s.D)(Date.now(),t)}},83309(t,e,r){r.d(e,{r:()=>o});var s=r(74816),a=r(35932);function o(t,e,r){const[o,i]=(0,s.x)(r?.in,t,e);return+(0,a.o)(o)===+(0,a.o)(i)}},73684(t,e,r){r.d(e,{c:()=>i});var s=r(73420),a=r(43382),o=r(83309);function i(t,e){return(0,o.r)((0,s.w)(e?.in||t,t),(0,a.A)(e?.in||t))}},81859(t,e,r){r.d(e,{R:()=>a});var s=r(35932);function a(t){return(0,s.o)(Date.now(),t)}}};