UNPKG

iobroker.lovelace

Version:

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

1 lines 7.99 kB
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[58597],{31396:function(e,t,a){a.a(e,async function(e,r){try{a.r(t);a(74423),a(44114),a(26910),a(13609),a(18111),a(7588),a(3362),a(42762),a(62953);var o=a(40445),s=a(5124),i=a(67576),l=a(6412),n=(a(76776),a(67094),a(1087)),u=a(38114),c=a(23528),d=a(54706),h=a(3609),_=a(90433),g=a(20058),v=a(28455),p=a(48949),y=e([h,u,c,g]);[h,u,c,g]=y.then?(await y)():y;let f,m,b,k,x,$=e=>e;const C={group_by_floor:!0,group_by_area:!0};class E extends((0,d.E)((0,p.Q)(s.WF))){static async getConfigElement(){return await a.e(92923).then(a.bind(a,46358)),document.createElement("hui-energy-sankey-card-editor")}static getStubConfig(e,t,a){return Object.assign({type:"energy-sankey",layout:"auto"},C)}setConfig(e){e.collection_key&&(0,u.s8)(e.collection_key),this._config=Object.assign(Object.assign({},C),e)}hassSubscribe(){var e;return[(0,u.tb)(this.hass,{key:null===(e=this._config)||void 0===e?void 0:e.collection_key}).subscribe(e=>{this._data=e})]}getCardSize(){return 5}getGridOptions(){return{columns:12,min_columns:6,rows:6,min_rows:2}}shouldUpdate(e){return e.has("_config")||e.has("_data")||e.has("_isMobileSize")}render(){if(!this._config)return s.s6;if(!this._data)return(0,s.qy)(f||(f=$`${0}`),this.hass.localize("ui.panel.lovelace.cards.energy.loading"));const e=this._data.prefs,t=(0,u.E$)(e),{summedData:a,compareSummedData:r}=(0,u.gv)(this._data),{consumption:o,compareConsumption:i}=(0,u.DR)(a,void 0),n=getComputedStyle(this),d=[],h=[],g={id:"home",label:this.hass.config.location_name,value:Math.max(0,o.total.used_total),color:n.getPropertyValue("--primary-color").trim(),index:1};if(d.push(g),t.battery){var v,p;const e=null!==(v=a.total.from_battery)&&void 0!==v?v:0,t=null!==(p=a.total.to_battery)&&void 0!==p?p:0;d.push({id:"battery",label:this.hass.localize("ui.panel.lovelace.cards.energy.energy_distribution.battery"),value:e,color:n.getPropertyValue("--energy-battery-out-color").trim(),index:0}),h.push({source:"battery",target:"home",value:o.total.used_battery}),d.push({id:"battery_in",label:this.hass.localize("ui.panel.lovelace.cards.energy.energy_distribution.battery"),value:t,color:n.getPropertyValue("--energy-battery-in-color").trim(),index:1}),o.total.grid_to_battery>0&&h.push({source:"grid",target:"battery_in",value:o.total.grid_to_battery}),o.total.solar_to_battery>0&&h.push({source:"solar",target:"battery_in",value:o.total.solar_to_battery})}if(t.grid){var y;const e=null!==(y=a.total.from_grid)&&void 0!==y?y:0;d.push({id:"grid",label:this.hass.localize("ui.panel.lovelace.cards.energy.energy_distribution.grid"),value:e,color:n.getPropertyValue("--energy-grid-consumption-color").trim(),index:0}),h.push({source:"grid",target:"home",value:o.total.used_grid})}if(t.solar){var x;const e=null!==(x=a.total.solar)&&void 0!==x?x:0;d.push({id:"solar",label:this.hass.localize("ui.panel.lovelace.cards.energy.energy_distribution.solar"),value:e,color:n.getPropertyValue("--energy-solar-color").trim(),index:0}),h.push({source:"solar",target:"home",value:o.total.used_solar})}if(t.grid&&t.grid[0].stat_energy_to){var C;const e=null!==(C=a.total.to_grid)&&void 0!==C?C:0;d.push({id:"grid_return",label:this.hass.localize("ui.panel.lovelace.cards.energy.energy_distribution.grid"),value:e,color:n.getPropertyValue("--energy-grid-return-color").trim(),index:1}),o.total.battery_to_grid>0&&h.push({source:"battery",target:"grid_return",value:o.total.battery_to_grid}),o.total.solar_to_grid>0&&h.push({source:"solar",target:"grid_return",value:o.total.solar_to_grid})}let E=g.value;const z=[],O={};e.device_consumption.forEach((e,t)=>{const a=e.stat_consumption in this._data.stats&&(0,c.$j)(this._data.stats[e.stat_consumption])||0;if(a<.01)return;const r={id:e.stat_consumption,label:e.name||(0,c.$O)(this.hass,e.stat_consumption,this._data.statsMetadata[e.stat_consumption]),value:a,color:(0,_.fI)(t,n),index:4,parent:e.included_in_stat,entityId:(0,c.OQ)(e.stat_consumption)?void 0:e.stat_consumption};r.parent?(O[r.id]=r.parent,h.push({source:r.parent,target:r.id})):E-=a,z.push(r)});const S=z.filter(e=>!O[e.id]),{group_by_area:P,group_by_floor:V}=this._config;if(P||V){const{areas:e,floors:t}=this._groupByFloorAndArea(S);Object.keys(t).sort((e,t)=>{var a,r,o,s;return(null!==(a=null===(r=this.hass.floors[t])||void 0===r?void 0:r.level)&&void 0!==a?a:-1/0)-(null!==(o=null===(s=this.hass.floors[e])||void 0===s?void 0:s.level)&&void 0!==o?o:-1/0)}).forEach(a=>{let r=`floor_${a}`;"no_floor"!==a&&V?(d.push({id:r,label:this.hass.floors[a].name,value:t[a].value,index:2,color:n.getPropertyValue("--primary-color").trim()}),h.push({source:"home",target:r})):r="home",t[a].areas.forEach(t=>{let a;if("no_area"!==t&&P){const o=`area_${t}`;d.push({id:o,label:this.hass.areas[t].name,value:e[t].value,index:3,color:n.getPropertyValue("--primary-color").trim()}),h.push({source:r,target:o,value:e[t].value}),a=o}else a=r;e[t].devices.forEach(e=>{h.push({source:a,target:e.id,value:e.value})})})})}else S.forEach(e=>{h.push({source:"home",target:e.id,value:e.value})});const j=this._getDeviceSections(O,z);j.forEach((e,t)=>{e.forEach(e=>{d.push(Object.assign(Object.assign({},e),{},{index:4+t}))})}),E>0&&(d.push({id:"untracked",label:this.hass.localize("ui.panel.lovelace.cards.energy.energy_devices_detail_graph.untracked_consumption"),value:E,color:n.getPropertyValue("--state-unavailable-color").trim(),index:3+j.length}),h.push({source:"home",target:"untracked",value:E}));const D=d.some(e=>e.value>0),F="vertical"===this._config.layout||"horizontal"!==this._config.layout&&this._isMobileSize;return(0,s.qy)(m||(m=$` <ha-card .header="${0}" class="${0}"> <div class="card-content"> ${0} </div> </ha-card> `),this._config.title,(0,l.H)({"is-grid":"grid"===this.layout,"is-panel":"panel"===this.layout,"is-vertical":F}),D?(0,s.qy)(b||(b=$`<ha-sankey-chart .hass="${0}" .data="${0}" .vertical="${0}" .valueFormatter="${0}" @node-click="${0}"></ha-sankey-chart>`),this.hass,{nodes:d,links:h},F,this._valueFormatter,this._handleNodeClick):(0,s.qy)(k||(k=$`${0}`),this.hass.localize("ui.panel.lovelace.cards.energy.no_data_period")))}_handleNodeClick(e){const{node:t}=e.detail;t.entityId&&(0,n.r)(this,"hass-more-info",{entityId:t.entityId})}_groupByFloorAndArea(e){const t={no_area:{value:0,devices:[]}},a={no_floor:{value:0,areas:["no_area"]}};return e.forEach(e=>{const r=this.hass.states[e.id],{area:o,floor:s}=r?(0,v.ln)(r,this.hass.entities,this.hass.devices,this.hass.areas,this.hass.floors):{area:null,floor:null};o?(o.area_id in t?(t[o.area_id].value+=e.value,t[o.area_id].devices.push(e)):t[o.area_id]={value:e.value,devices:[e]},s?s.floor_id in a?(a[s.floor_id].value+=e.value,a[s.floor_id].areas.includes(o.area_id)||a[s.floor_id].areas.push(o.area_id)):a[s.floor_id]={value:e.value,areas:[o.area_id]}:(a.no_floor.value+=e.value,a.no_floor.areas.includes(o.area_id)||a.no_floor.areas.unshift(o.area_id))):(t.no_area.value+=e.value,t.no_area.devices.push(e))}),{areas:t,floors:a}}_getDeviceSections(e,t){const a=[],r=[],o=Object.values(e),s={};return t.forEach(t=>{const s=t.id in e;o.includes(t.id)&&!s?a.push(t):r.push(t)}),Object.entries(e).forEach(([e,t])=>{a.some(e=>e.id===t)||(s[e]=t)}),a.length>0?[a,...this._getDeviceSections(s,r)]:[t]}constructor(...e){super(...e),this.hassSubscribeRequiredHostProps=["_config"],this._valueFormatter=e=>`${(0,g.ZV)(e,this.hass.locale,e<.1?{maximumFractionDigits:3}:void 0)} kWh`}}E.styles=(0,s.AH)(x||(x=$`ha-card{height:400px;display:flex;flex-direction:column;--chart-max-height:none}ha-card.is-vertical{height:500px}ha-card.is-grid,ha-card.is-panel{height:100%}.card-content{flex:1;display:flex}`)),(0,o.Cg)([(0,i.MZ)({attribute:!1})],E.prototype,"hass",void 0),(0,o.Cg)([(0,i.MZ)({attribute:!1})],E.prototype,"layout",void 0),(0,o.Cg)([(0,i.wk)()],E.prototype,"_config",void 0),(0,o.Cg)([(0,i.wk)()],E.prototype,"_data",void 0),E=(0,o.Cg)([(0,i.EM)("hui-energy-sankey-card")],E),r()}catch(f){r(f)}})}}]);