iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 7.43 kB
JavaScript
export const __rspack_esm_id=58597;export const __rspack_esm_ids=[58597];export const __webpack_modules__={31396(e,t,a){a.a(e,async function(e,r){try{a.r(t);a(74423),a(44114),a(18111),a(7588);var o=a(62826),s=a(5124),i=a(22441),l=a(6412),n=(a(76776),a(67094),a(1087)),c=a(38114),u=a(23528),d=a(54706),h=a(3609),_=a(90433),g=a(20058),p=a(28455),y=a(48949),v=e([h,c,g]);[h,c,g]=v.then?(await v)():v;const m={group_by_floor:!0,group_by_area:!0};class f extends((0,d.E)((0,y.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{type:"energy-sankey",layout:"auto",...m}}setConfig(e){e.collection_key&&(0,c.s8)(e.collection_key),this._config={...m,...e}}hassSubscribe(){return[(0,c.tb)(this.hass,{key:this._config?.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 s.qy`${this.hass.localize("ui.panel.lovelace.cards.energy.loading")}`;const e=this._data.prefs,t=(0,c.E$)(e),{summedData:a,compareSummedData:r}=(0,c.gv)(this._data),{consumption:o,compareConsumption:i}=(0,c.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){const e=a.total.from_battery??0,t=a.total.to_battery??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){const e=a.total.from_grid??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){const e=a.total.solar??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){const e=a.total.to_grid??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 p=g.value;const y=[],v={};e.device_consumption.forEach((e,t)=>{const a=e.stat_consumption in this._data.stats&&(0,u.$j)(this._data.stats[e.stat_consumption])||0;if(a<.01)return;const r={id:e.stat_consumption,label:e.name||(0,u.$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,u.OQ)(e.stat_consumption)?void 0:e.stat_consumption};r.parent?(v[r.id]=r.parent,h.push({source:r.parent,target:r.id})):p-=a,y.push(r)});const m=y.filter(e=>!v[e.id]),{group_by_area:f,group_by_floor:b}=this._config;if(f||b){const{areas:e,floors:t}=this._groupByFloorAndArea(m);Object.keys(t).sort((e,t)=>(this.hass.floors[t]?.level??-1/0)-(this.hass.floors[e]?.level??-1/0)).forEach(a=>{let r=`floor_${a}`;"no_floor"!==a&&b?(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&&f){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 m.forEach(e=>{h.push({source:"home",target:e.id,value:e.value})});const x=this._getDeviceSections(v,y);x.forEach((e,t)=>{e.forEach(e=>{d.push({...e,index:4+t})})}),p>0&&(d.push({id:"untracked",label:this.hass.localize("ui.panel.lovelace.cards.energy.energy_devices_detail_graph.untracked_consumption"),value:p,color:n.getPropertyValue("--state-unavailable-color").trim(),index:3+x.length}),h.push({source:"home",target:"untracked",value:p}));const k=d.some(e=>e.value>0),$="vertical"===this._config.layout||"horizontal"!==this._config.layout&&this._isMobileSize;return s.qy` <ha-card .header="${this._config.title}" class="${(0,l.H)({"is-grid":"grid"===this.layout,"is-panel":"panel"===this.layout,"is-vertical":$})}"> <div class="card-content"> ${k?s.qy`<ha-sankey-chart .hass="${this.hass}" .data="${{nodes:d,links:h}}" .vertical="${$}" .valueFormatter="${this._valueFormatter}" -click="${this._handleNodeClick}"></ha-sankey-chart>`:s.qy`${this.hass.localize("ui.panel.lovelace.cards.energy.no_data_period")}`} </div> </ha-card> `}_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,p.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`}}f.styles=s.AH`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})],f.prototype,"hass",void 0),(0,o.Cg)([(0,i.MZ)({attribute:!1})],f.prototype,"layout",void 0),(0,o.Cg)([(0,i.wk)()],f.prototype,"_config",void 0),(0,o.Cg)([(0,i.wk)()],f.prototype,"_data",void 0),f=(0,o.Cg)([(0,i.EM)("hui-energy-sankey-card")],f),r()}catch(e){r(e)}})}};