iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 6.8 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[85069],{41436:function(e,t,a){a.a(e,async function(e,s){try{a.r(t);a(74423),a(44114),a(72712),a(26910),a(13609),a(18111),a(22489),a(7588),a(18237),a(3362),a(42762),a(62953);var o=a(40445),r=a(5124),i=a(67576),n=a(6412),l=(a(76776),a(67094),a(1087)),c=a(38114),u=a(23528),h=a(54706),d=a(3609),_=a(90433),p=a(20058),f=a(28455),g=a(48949),v=e([d,c,u,p]);[d,c,u,p]=v.then?(await v)():v;let y,m,b,k,$,x=e=>e;const E={group_by_floor:!0,group_by_area:!0};class w extends((0,h.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 Object.assign({type:"water-sankey",layout:"auto"},E)}setConfig(e){e.collection_key&&(0,c.s8)(e.collection_key),this._config=Object.assign(Object.assign({},E),e)}hassSubscribe(){var e;return[(0,c.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 r.s6;if(!this._data)return(0,r.qy)(y||(y=x`${0}`),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,u.$j)(this._data.stats[t.stat_consumption])||0)},0),l=t.reduce((e,t)=>e+(t.stat_energy_from in this._data.stats&&(0,u.$j)(this._data.stats[t.stat_energy_from])||0),0),c=Math.max(i,l),h={id:"home",label:this.hass.config.location_name,value:Math.max(0,c),color:a.getPropertyValue("--primary-color").trim(),index:1};s.push(h);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,u.$j)(this._data.stats[e.stat_energy_from])||0;t<.01||(s.push({id:`source-${e.stat_energy_from}`,label:e.name||(0,u.$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=h.value;const f=[],g={};e.device_consumption_water.forEach((e,t)=>{const s=e.stat_consumption in this._data.stats&&(0,u.$j)(this._data.stats[e.stat_consumption])||0;if(s<.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:s,color:(0,_.fI)(t,a),index:4,parent:e.included_in_stat,entityId:(0,u.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:$,group_by_floor:E}=this._config;if($||E){const{areas:e,floors:t}=this._groupByFloorAndArea(v);Object.keys(t).sort((e,t)=>{var a,s,o,r;return(null!==(a=null===(s=this.hass.floors[t])||void 0===s?void 0:s.level)&&void 0!==a?a:-1/0)-(null!==(o=null===(r=this.hass.floors[e])||void 0===r?void 0:r.level)&&void 0!==o?o:-1/0)}).forEach(r=>{let i=`floor_${r}`;"no_floor"!==r&&E?(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&&$){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 w=this._getDeviceSections(g,f);w.forEach((e,t)=>{e.forEach(e=>{s.push(Object.assign(Object.assign({},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+w.length}),o.push({source:"home",target:"untracked",value:p}));const C=s.some(e=>e.value>0),j="vertical"===this._config.layout||"horizontal"!==this._config.layout&&this._isMobileSize;return(0,r.qy)(m||(m=x` <ha-card .header="${0}" class="${0}"> <div class="card-content"> ${0} </div> </ha-card> `),this._config.title,(0,n.H)({"is-grid":"grid"===this.layout,"is-panel":"panel"===this.layout,"is-vertical":j}),C?(0,r.qy)(b||(b=x`<ha-sankey-chart .hass="${0}" .data="${0}" .vertical="${0}" .valueFormatter="${0}" -click="${0}"></ha-sankey-chart>`),this.hass,{nodes:s,links:o},j,this._valueFormatter,this._handleNodeClick):(0,r.qy)(k||(k=x`${0}`),this.hass.localize("ui.panel.lovelace.cards.energy.no_data_period")))}_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}`}}w.styles=(0,r.AH)($||($=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})],w.prototype,"hass",void 0),(0,o.Cg)([(0,i.MZ)({attribute:!1})],w.prototype,"layout",void 0),(0,o.Cg)([(0,i.wk)()],w.prototype,"_config",void 0),(0,o.Cg)([(0,i.wk)()],w.prototype,"_data",void 0),w=(0,o.Cg)([(0,i.EM)("hui-water-sankey-card")],w),s()}catch(y){s(y)}})}}]);