"use strict";(self.webpackChunkhome_assistant_frontend=self.webpackChunkhome_assistant_frontend||[]).push([["28696"],{12150:function(t,e,s){s.a(t,async function(t,a){try{s.r(e),s.d(e,{HuiPowerTotalBadge:function(){return g}});s(18111),s(7588),s(17642),s(58004),s(33853),s(45876),s(32475),s(15024),s(31698),s(62953);var i=s(40445),r=s(96196),o=s(77845),n=s(20058),h=(s(24671),s(67094),s(38114)),c=s(54706),u=t([h,n]);[h,n]=u.then?(await u)():u;let l,_,d=t=>t;const f="M12 3L2 12H5V20H19V12H22L12 3M11.5 18V14H9L12.5 7V11H15L11.5 18Z";class g extends((0,c.E)(r.WF)){setConfig(t){this._config=t}hassSubscribe(){var t;return[(0,h.tb)(this.hass,{key:null===(t=this._config)||void 0===t?void 0:t.collection_key}).subscribe(t=>{this._data=t})]}shouldUpdate(t){if(t.has("_config")||t.has("_data"))return!0;if(t.has("hass")){const s=t.get("hass");if(!s||!this._entities.size)return!0;for(const t of this._entities){var e;if(s.states[t]!==(null===(e=this.hass)||void 0===e?void 0:e.states[t]))return!0}}return!1}_getCurrentPower(t){var e;return this._entities.add(t),null!==(e=(0,h.h4)(this.hass.states[t]))&&void 0!==e?e:0}_computeTotalPower(t){this._entities.clear();let e=0,s=0,a=0,i=0,r=0;t.energy_sources.forEach(t=>{if("solar"===t.type&&t.stat_rate){const s=this._getCurrentPower(t.stat_rate);s>0&&(e+=s)}else if("grid"===t.type&&t.stat_rate){const e=this._getCurrentPower(t.stat_rate);e>0?s+=e:e<0&&(a+=Math.abs(e))}else if("battery"===t.type&&t.stat_rate){const e=this._getCurrentPower(t.stat_rate);e>0?i+=e:e<0&&(r+=Math.abs(e))}});const o=s+e+i-a-r;return Math.max(0,o)}render(){if(!this._config||!this._data)return r.s6;const t=this._computeTotalPower(this._data.prefs);let e="";e=t>=1e3?`${(0,n.ZV)(t/1e3,this.hass.locale,{maximumFractionDigits:2})} kW`:`${(0,n.ZV)(t,this.hass.locale,{maximumFractionDigits:0})} W`;const s=this._config.title||this.hass.localize("ui.panel.lovelace.cards.energy.power_total_title");return(0,r.qy)(l||(l=d` <ha-badge .label="${0}"> <ha-svg-icon slot="icon" .path="${0}"></ha-svg-icon> ${0} </ha-badge> `),s,f,e)}constructor(...t){super(...t),this._entities=new Set,this.hassSubscribeRequiredHostProps=["_config"]}}g.styles=(0,r.AH)(_||(_=d`ha-badge{--badge-color:var(--primary-color)}`)),(0,i.Cg)([(0,o.MZ)({attribute:!1})],g.prototype,"hass",void 0),(0,i.Cg)([(0,o.wk)()],g.prototype,"_config",void 0),(0,i.Cg)([(0,o.wk)()],g.prototype,"_data",void 0),g=(0,i.Cg)([(0,o.EM)("hui-power-total-badge")],g),a()}catch(l){a(l)}})},56434:function(t,e,s){s.d(e,{e:function(){return i}});var a=s(81977);function i(t,e,s){return(0,a.P)(t,12*e,s)}}}]);
//# sourceMappingURL=28696.b9d09b42bab8fdef.js.map