iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 6.38 kB
JavaScript
export const __rspack_esm_id=85069;export const __rspack_esm_ids=[85069];export const __webpack_modules__={41436(e,t,a){a.a(e,async function(e,s){try{a.r(t);a(74423),a(44114),a(18111),a(22489),a(7588),a(18237);var o=a(62826),r=a(5124),i=a(22441),n=a(6412),l=(a(76776),a(67094),a(1087)),c=a(38114),h=a(23528),u=a(54706),d=a(3609),_=a(90433),p=a(20058),f=a(28455),g=a(48949),v=e([d,c,p]);[d,c,p]=v.then?(await v)():v;const y={group_by_floor:!0,group_by_area:!0};class m extends((0,u.E)((0,g.Q)(r.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:"water-sankey",layout:"auto",...y}}setConfig(e){e.collection_key&&(0,c.s8)(e.collection_key),this._config={...y,...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 r.s6;if(!this._data)return r.qy`${this.hass.localize("ui.panel.lovelace.cards.energy.loading")}`;const e=this._data.prefs,t=e.energy_sources.filter(e=>"water"===e.type),a=getComputedStyle(this),s=[],o=[],i=e.device_consumption_water.reduce((e,t)=>{if(t.included_in_stat)return e;return e+(t.stat_consumption in this._data.stats&&(0,h.$j)(this._data.stats[t.stat_consumption])||0)},0),l=t.reduce((e,t)=>e+(t.stat_energy_from in this._data.stats&&(0,h.$j)(this._data.stats[t.stat_energy_from])||0),0),c=Math.max(i,l),u={id:"home",label:this.hass.config.location_name,value:Math.max(0,c),color:a.getPropertyValue("--primary-color").trim(),index:1};s.push(u);const d=a.getPropertyValue("--energy-water-color").trim();t.forEach(e=>{if("water"!==e.type)return;const t=e.stat_energy_from in this._data.stats&&(0,h.$j)(this._data.stats[e.stat_energy_from])||0;t<.01||(s.push({id:`source-${e.stat_energy_from}`,label:e.name||(0,h.$O)(this.hass,e.stat_energy_from,this._data.statsMetadata[e.stat_energy_from]),value:t,color:d,index:0}),o.push({source:`source-${e.stat_energy_from}`,target:"home",value:t}))});let p=u.value;const f=[],g={};e.device_consumption_water.forEach((e,t)=>{const s=e.stat_consumption in this._data.stats&&(0,h.$j)(this._data.stats[e.stat_consumption])||0;if(s<.01)return;const r={id:e.stat_consumption,label:e.name||(0,h.$O)(this.hass,e.stat_consumption,this._data.statsMetadata[e.stat_consumption]),value:s,color:(0,_.fI)(t,a),index:4,parent:e.included_in_stat,entityId:(0,h.OQ)(e.stat_consumption)?void 0:e.stat_consumption};r.parent?(g[r.id]=r.parent,o.push({source:r.parent,target:r.id})):p-=s,f.push(r)});const v=f.filter(e=>!g[e.id]),{group_by_area:y,group_by_floor:m}=this._config;if(y||m){const{areas:e,floors:t}=this._groupByFloorAndArea(v);Object.keys(t).sort((e,t)=>(this.hass.floors[t]?.level??-1/0)-(this.hass.floors[e]?.level??-1/0)).forEach(r=>{let i=`floor_${r}`;"no_floor"!==r&&m?(s.push({id:i,label:this.hass.floors[r].name,value:t[r].value,index:2,color:a.getPropertyValue("--primary-color").trim()}),o.push({source:"home",target:i})):i="home",t[r].areas.forEach(t=>{let r;if("no_area"!==t&&y){const n=`area_${t}`;s.push({id:n,label:this.hass.areas[t].name,value:e[t].value,index:3,color:a.getPropertyValue("--primary-color").trim()}),o.push({source:i,target:n,value:e[t].value}),r=n}else r=i;e[t].devices.forEach(e=>{o.push({source:r,target:e.id,value:e.value})})})})}else v.forEach(e=>{o.push({source:"home",target:e.id,value:e.value})});const b=this._getDeviceSections(g,f);b.forEach((e,t)=>{e.forEach(e=>{s.push({...e,index:4+t})})}),p>0&&(s.push({id:"untracked",label:this.hass.localize("ui.panel.lovelace.cards.energy.energy_devices_detail_graph.untracked_consumption"),value:p,color:a.getPropertyValue("--state-unavailable-color").trim(),index:3+b.length}),o.push({source:"home",target:"untracked",value:p}));const k=s.some(e=>e.value>0),$="vertical"===this._config.layout||"horizontal"!==this._config.layout&&this._isMobileSize;return r.qy` <ha-card .header="${this._config.title}" class="${(0,n.H)({"is-grid":"grid"===this.layout,"is-panel":"panel"===this.layout,"is-vertical":$})}"> <div class="card-content"> ${k?r.qy`<ha-sankey-chart .hass="${this.hass}" .data="${{nodes:s,links:o}}" .vertical="${$}" .valueFormatter="${this._valueFormatter}" -click="${this._handleNodeClick}"></ha-sankey-chart>`:r.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,l.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 s=this.hass.states[e.id],{area:o,floor:r}=s?(0,f.ln)(s,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]},r?r.floor_id in a?(a[r.floor_id].value+=e.value,a[r.floor_id].areas.includes(o.area_id)||a[r.floor_id].areas.push(o.area_id)):a[r.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=[],s=[],o=Object.values(e),r={};return t.forEach(t=>{const r=t.id in e;o.includes(t.id)&&!r?a.push(t):s.push(t)}),Object.entries(e).forEach(([e,t])=>{a.some(e=>e.id===t)||(r[e]=t)}),a.length>0?[a,...this._getDeviceSections(r,s)]:[t]}constructor(...e){super(...e),this.hassSubscribeRequiredHostProps=["_config"],this._valueFormatter=e=>`${(0,p.ZV)(e,this.hass.locale,e<.1?{maximumFractionDigits:3}:void 0)} ${this._data.waterUnit}`}}m.styles=r.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})],m.prototype,"hass",void 0),(0,o.Cg)([(0,i.MZ)({attribute:!1})],m.prototype,"layout",void 0),(0,o.Cg)([(0,i.wk)()],m.prototype,"_config",void 0),(0,o.Cg)([(0,i.wk)()],m.prototype,"_data",void 0),m=(0,o.Cg)([(0,i.EM)("hui-water-sankey-card")],m),s()}catch(e){s(e)}})}};