UNPKG

iobroker.lovelace

Version:

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

1 lines 8 kB
export const __rspack_esm_id=37248;export const __rspack_esm_ids=[37248];export const __webpack_modules__={34499(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),a(45367),a(92731),a(17642),a(58004),a(33853),a(45876),a(32475),a(15024),a(31698);var r=a(62826),i=a(5124),o=a(22441),n=a(6412),l=(a(76776),a(1087)),c=a(38114),h=a(54706),u=a(3609),_=a(90433),d=a(28455),p=a(48949),f=e([u,c]);[u,c]=f.then?(await f)():f;const g={group_by_floor:!0,group_by_area:!0},v=.001;class y extends((0,h.E)((0,p.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{type:"water-flow-sankey",layout:"auto",...g}}setConfig(e){e.collection_key&&(0,c.s8)(e.collection_key),this._config={...g,...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){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 i.qy`${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*v,c=[],h=[],u=t.getPropertyValue("--energy-water-color").trim(),d=t.getPropertyValue("--primary-color").trim();let p;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:u,index:0,entityId:e.stat_rate}),h.push({source:a,target:"home"})});const e={id:"home",label:this.hass.config.location_name,value:Math.max(0,o),color:d,index:1};c.push(e),p="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:u,index:0,entityId:e.stat_rate}),p=e.stat_rate}else p="home"}const f=new Map;e.device_consumption_water.forEach(e=>{f.set(e.stat_consumption,{stat_rate:e.stat_rate,included_in_stat:e.included_in_stat})});const g=new Set;e.device_consumption_water.forEach(e=>{if(e.stat_rate){this._getCurrentFlowRate(e.stat_rate)>=l&&g.add(e.stat_rate)}});let y=o;const m=[],b={},w=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=f.get(t);if(!e)return;if(e.stat_rate&&g.has(e.stat_rate))return e.stat_rate;t=e.included_in_stat}})(e.included_in_stat);if(s<l){const t=r??p;return w.has(t)||w.set(t,[]),void w.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,_.fI)(a,t),index:4,parent:r,entityId:e.stat_rate};i.parent?(b[i.id]=i.parent,h.push({source:i.parent,target:i.id})):y-=s,m.push(i)}),w.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,_.fI)(a.idx,t),index:4,parent:a.effectiveParent,entityId:a.statRate};s.parent?(b[s.id]=s.parent,h.push({source:s.parent,target:s.id})):y-=a.value,m.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!==p?(b[e]=a,h.push({source:a,target:e})):y-=s,m.push(r)}});const E=m.filter(e=>!b[e.id]),{group_by_area:x,group_by_floor:k,layout:C,title:F}=this._config;if(x||k){const{areas:e,floors:t}=this._groupByFloorAndArea(E);Object.keys(t).sort((e,t)=>(this.hass.floors[t]?.level??-1/0)-(this.hass.floors[e]?.level??-1/0)).forEach(a=>{let s=`floor_${a}`;"no_floor"!==a&&k?(c.push({id:s,label:this.hass.floors[a].name,value:t[a].value,index:2,color:d}),h.push({source:p,target:s})):s=p,t[a].areas.forEach(t=>{let a;if("no_area"!==t&&x){const r=`area_${t}`;c.push({id:r,label:this.hass.areas[t]?.name||t,value:e[t].value,index:3,color:d}),h.push({source:s,target:r,value:e[t].value}),a=r}else a=s;e[t].devices.forEach(e=>{h.push({source:a,target:e.id,value:e.value})})})})}else E.forEach(e=>{h.push({source:p,target:e.id,value:e.value})});const S=this._getDeviceSections(b,m);S.forEach((e,t)=>{e.forEach(e=>{c.push({...e,index:4+t})})}),y>1&&(c.push({id:"untracked",label:this.hass.localize("ui.panel.lovelace.cards.energy.energy_devices_detail_graph.untracked_consumption"),value:y,color:t.getPropertyValue("--state-unavailable-color").trim(),index:3+S.length}),h.push({source:p,target:"untracked",value:y}));const $=c.some(e=>e.value>0),R="vertical"===C||"horizontal"!==C&&this._isMobileSize;return i.qy` <ha-card .header="${F}" class="${(0,n.H)({"is-grid":"grid"===this.layout,"is-panel":"panel"===this.layout,"is-vertical":R})}"> <div class="card-content"> ${$?i.qy`<ha-sankey-chart .data="${{nodes:c,links:h}}" .vertical="${R}" .valueFormatter="${this._valueFormatter}" @node-click="${this._handleNodeClick}"></ha-sankey-chart>`:i.qy`${this.hass.localize("ui.panel.lovelace.cards.energy.no_data")}`} </div> </ha-card> `}_handleNodeClick(e){const{node:t}=e.detail;t.entityId&&(0,l.r)(this,"hass-more-info",{entityId:t.entityId})}_getCurrentFlowRate(e){return this._entities.add(e),(0,c.Sp)(this.hass.states[e])??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,d.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)}}y.styles=i.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,r.Cg)([(0,o.MZ)({attribute:!1})],y.prototype,"hass",void 0),(0,r.Cg)([(0,o.MZ)({attribute:!1})],y.prototype,"layout",void 0),(0,r.Cg)([(0,o.wk)()],y.prototype,"_config",void 0),(0,r.Cg)([(0,o.wk)()],y.prototype,"_data",void 0),y=(0,r.Cg)([(0,o.EM)("hui-water-flow-sankey-card")],y),s()}catch(e){s(e)}})}};