UNPKG

iobroker.lovelace

Version:

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

1 lines 8.49 kB
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[37248],{34499: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(45367),a(92731),a(3362),a(17642),a(58004),a(33853),a(45876),a(32475),a(15024),a(31698),a(42762),a(62953);var r=a(40445),i=a(5124),o=a(67576),n=a(6412),l=(a(76776),a(1087)),c=a(38114),u=a(54706),h=a(3609),d=a(90433),_=a(28455),f=a(48949),v=e([h,c]);[h,c]=v.then?(await v)():v;let g,p,y,b,m,w=e=>e;const E={group_by_floor:!0,group_by_area:!0},k=.001;class x extends((0,u.E)((0,f.Q)(i.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-flow-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){if(e.has("_config")||e.has("_data")||e.has("_isMobileSize"))return!0;if(e.has("hass")){const t=e.get("hass");if(!t||!this._entities.size)return!0;for(const e of this._entities)if(t.states[e]!==this.hass.states[e])return!0}return!1}render(){if(!this._config)return i.s6;if(!this._data)return(0,i.qy)(g||(g=w`${0}`),this.hass.localize("ui.panel.lovelace.cards.energy.loading"));const e=this._data.prefs,t=getComputedStyle(this);this._entities.clear();const a=e.energy_sources.filter(e=>"water"===e.type&&e.stat_rate);let s=0;a.forEach(e=>{if("water"===e.type&&e.stat_rate){const t=this._getCurrentFlowRate(e.stat_rate);t>0&&(s+=t)}});let r=0;0===a.length&&e.device_consumption_water.forEach(e=>{e.included_in_stat||e.stat_rate&&(r+=this._getCurrentFlowRate(e.stat_rate))});const o=0===a.length?r:s,l=o*k,c=[],u=[],h=t.getPropertyValue("--energy-water-color").trim(),_=t.getPropertyValue("--primary-color").trim();let f;if(1!==a.length){a.forEach(e=>{if("water"!==e.type||!e.stat_rate)return;const t=this._getCurrentFlowRate(e.stat_rate);if(t<=0)return;const a=`water_source_${e.stat_rate}`;c.push({id:a,label:this._getEntityLabel(e.stat_rate)||this.hass.localize("ui.panel.lovelace.cards.energy.energy_distribution.water"),value:t,color:h,index:0,entityId:e.stat_rate}),u.push({source:a,target:"home"})});const e={id:"home",label:this.hass.config.location_name,value:Math.max(0,o),color:_,index:1};c.push(e),f="home"}else{const e=a[0];if("water"===e.type&&e.stat_rate){const t=this._getCurrentFlowRate(e.stat_rate);c.push({id:e.stat_rate,label:this._getEntityLabel(e.stat_rate)||this.hass.localize("ui.panel.lovelace.cards.energy.energy_distribution.water"),value:Math.max(0,t),color:h,index:0,entityId:e.stat_rate}),f=e.stat_rate}else f="home"}const v=new Map;e.device_consumption_water.forEach(e=>{v.set(e.stat_consumption,{stat_rate:e.stat_rate,included_in_stat:e.included_in_stat})});const m=new Set;e.device_consumption_water.forEach(e=>{if(e.stat_rate){this._getCurrentFlowRate(e.stat_rate)>=l&&m.add(e.stat_rate)}});let E=o;const x=[],C={},F=new Map;e.device_consumption_water.forEach((e,a)=>{if(!e.stat_rate)return;const s=this._getCurrentFlowRate(e.stat_rate),r=(e=>{let t=e;for(;t;){const e=v.get(t);if(!e)return;if(e.stat_rate&&m.has(e.stat_rate))return e.stat_rate;t=e.included_in_stat}})(e.included_in_stat);if(s<l){const t=null!=r?r:f;return F.has(t)||F.set(t,[]),void F.get(t).push({statRate:e.stat_rate,name:e.name,value:s,effectiveParent:r,idx:a})}const i={id:e.stat_rate,label:e.name||this._getEntityLabel(e.stat_rate),value:s,color:(0,d.fI)(a,t),index:4,parent:r,entityId:e.stat_rate};i.parent?(C[i.id]=i.parent,u.push({source:i.parent,target:i.id})):E-=s,x.push(i)}),F.forEach((e,a)=>{const s=e.reduce((e,t)=>e+t.value,0);if(!(s<=0))if(1===e.length){const a=e[0],s={id:a.statRate,label:a.name||this._getEntityLabel(a.statRate),value:a.value,color:(0,d.fI)(a.idx,t),index:4,parent:a.effectiveParent,entityId:a.statRate};s.parent?(C[s.id]=s.parent,u.push({source:s.parent,target:s.id})):E-=a.value,x.push(s)}else{const e=`other_${a}`,r={id:e,label:this.hass.localize("ui.panel.lovelace.cards.energy.energy_devices_detail_graph.other"),value:Math.ceil(s),color:t.getPropertyValue("--state-unavailable-color").trim(),index:4};a!==f?(C[e]=a,u.push({source:a,target:e})):E-=s,x.push(r)}});const S=x.filter(e=>!C[e.id]),{group_by_area:$,group_by_floor:R,layout:z,title:M}=this._config;if($||R){const{areas:e,floors:t}=this._groupByFloorAndArea(S);Object.keys(t).sort((e,t)=>{var a,s,r,i;return(null!==(a=null===(s=this.hass.floors[t])||void 0===s?void 0:s.level)&&void 0!==a?a:-1/0)-(null!==(r=null===(i=this.hass.floors[e])||void 0===i?void 0:i.level)&&void 0!==r?r:-1/0)}).forEach(a=>{let s=`floor_${a}`;"no_floor"!==a&&R?(c.push({id:s,label:this.hass.floors[a].name,value:t[a].value,index:2,color:_}),u.push({source:f,target:s})):s=f,t[a].areas.forEach(t=>{let a;if("no_area"!==t&&$){var r;const i=`area_${t}`;c.push({id:i,label:(null===(r=this.hass.areas[t])||void 0===r?void 0:r.name)||t,value:e[t].value,index:3,color:_}),u.push({source:s,target:i,value:e[t].value}),a=i}else a=s;e[t].devices.forEach(e=>{u.push({source:a,target:e.id,value:e.value})})})})}else S.forEach(e=>{u.push({source:f,target:e.id,value:e.value})});const I=this._getDeviceSections(C,x);I.forEach((e,t)=>{e.forEach(e=>{c.push(Object.assign(Object.assign({},e),{},{index:4+t}))})}),E>1&&(c.push({id:"untracked",label:this.hass.localize("ui.panel.lovelace.cards.energy.energy_devices_detail_graph.untracked_consumption"),value:E,color:t.getPropertyValue("--state-unavailable-color").trim(),index:3+I.length}),u.push({source:f,target:"untracked",value:E}));const O=c.some(e=>e.value>0),j="vertical"===z||"horizontal"!==z&&this._isMobileSize;return(0,i.qy)(p||(p=w` <ha-card .header="${0}" class="${0}"> <div class="card-content"> ${0} </div> </ha-card> `),M,(0,n.H)({"is-grid":"grid"===this.layout,"is-panel":"panel"===this.layout,"is-vertical":j}),O?(0,i.qy)(y||(y=w`<ha-sankey-chart .data="${0}" .vertical="${0}" .valueFormatter="${0}" @node-click="${0}"></ha-sankey-chart>`),{nodes:c,links:u},j,this._valueFormatter,this._handleNodeClick):(0,i.qy)(b||(b=w`${0}`),this.hass.localize("ui.panel.lovelace.cards.energy.no_data")))}_handleNodeClick(e){const{node:t}=e.detail;t.entityId&&(0,l.r)(this,"hass-more-info",{entityId:t.entityId})}_getCurrentFlowRate(e){var t;return this._entities.add(e),null!==(t=(0,c.Sp)(this.hass.states[e]))&&void 0!==t?t:0}_getEntityLabel(e){const t=this.hass.states[e];return t&&t.attributes.friendly_name||e}_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:r,floor:i}=s?(0,_.ln)(s,this.hass.entities,this.hass.devices,this.hass.areas,this.hass.floors):{area:null,floor:null};r?(r.area_id in t?(t[r.area_id].value+=e.value,t[r.area_id].devices.push(e)):t[r.area_id]={value:e.value,devices:[e]},i?i.floor_id in a?(a[i.floor_id].value+=e.value,a[i.floor_id].areas.includes(r.area_id)||a[i.floor_id].areas.push(r.area_id)):a[i.floor_id]={value:e.value,areas:[r.area_id]}:(a.no_floor.value+=e.value,a.no_floor.areas.includes(r.area_id)||a.no_floor.areas.unshift(r.area_id))):(t.no_area.value+=e.value,t.no_area.devices.push(e))}),{areas:t,floors:a}}_getDeviceSections(e,t){const a=[],s=[],r=Object.values(e),i={};return t.forEach(t=>{const i=t.id in e;r.includes(t.id)&&!i?a.push(t):s.push(t)}),Object.entries(e).forEach(([e,t])=>{a.some(e=>e.id===t)||(i[e]=t)}),a.length>0?[a,...this._getDeviceSections(i,s)]:[t]}constructor(...e){super(...e),this._entities=new Set,this.hassSubscribeRequiredHostProps=["_config"],this._valueFormatter=e=>(0,c.E_)(this.hass.locale,this.hass.config.unit_system.length,e)}}x.styles=(0,i.AH)(m||(m=w`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,r.Cg)([(0,o.MZ)({attribute:!1})],x.prototype,"hass",void 0),(0,r.Cg)([(0,o.MZ)({attribute:!1})],x.prototype,"layout",void 0),(0,r.Cg)([(0,o.wk)()],x.prototype,"_config",void 0),(0,r.Cg)([(0,o.wk)()],x.prototype,"_data",void 0),x=(0,r.Cg)([(0,o.EM)("hui-water-flow-sankey-card")],x),s()}catch(g){s(g)}})}}]);