iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 3.22 kB
JavaScript
export const __rspack_esm_id=28696;export const __rspack_esm_ids=[28696];export const __webpack_modules__={54706(s,t,e){e.d(t,{E:()=>r});e(74423),e(18111),e(13579);var i=e(62826),a=e(22441);const r=s=>{class t extends s{connectedCallback(){super.connectedCallback(),this._checkSubscribed()}disconnectedCallback(){if(super.disconnectedCallback(),this.__unsubs){for(;this.__unsubs.length;){const s=this.__unsubs.pop();s instanceof Promise?s.then(s=>s()):s()}this.__unsubs=void 0}}updated(s){if(super.updated(s),s.has("hass"))this._checkSubscribed();else if(this.hassSubscribeRequiredHostProps)for(const t of s.keys())if(this.hassSubscribeRequiredHostProps.includes(t))return void this._checkSubscribed()}hassSubscribe(){return[]}_checkSubscribed(){void 0===this.__unsubs&&this.isConnected&&void 0!==this.hass&&!this.hassSubscribeRequiredHostProps?.some(s=>void 0===this[s])&&(this.__unsubs=this.hassSubscribe())}}return(0,i.Cg)([(0,a.MZ)({attribute:!1})],t.prototype,"hass",void 0),t}},12150(s,t,e){e.a(s,async function(s,i){try{e.r(t),e.d(t,{HuiPowerTotalBadge:()=>d});e(18111),e(7588),e(17642),e(58004),e(33853),e(45876),e(32475),e(15024),e(31698);var a=e(62826),r=e(5124),o=e(22441),c=e(20058),n=(e(24671),e(67094),e(38114)),h=e(54706),u=s([n,c]);[n,c]=u.then?(await u)():u;const _="M12 3L2 12H5V20H19V12H22L12 3M11.5 18V14H9L12.5 7V11H15L11.5 18Z";class d extends((0,h.E)(r.WF)){setConfig(s){this._config=s}hassSubscribe(){return[(0,n.tb)(this.hass,{key:this._config?.collection_key}).subscribe(s=>{this._data=s})]}shouldUpdate(s){if(s.has("_config")||s.has("_data"))return!0;if(s.has("hass")){const t=s.get("hass");if(!t||!this._entities.size)return!0;for(const s of this._entities)if(t.states[s]!==this.hass?.states[s])return!0}return!1}_getCurrentPower(s){return this._entities.add(s),(0,n.h4)(this.hass.states[s])??0}_computeTotalPower(s){this._entities.clear();let t=0,e=0,i=0,a=0,r=0;s.energy_sources.forEach(s=>{if("solar"===s.type&&s.stat_rate){const e=this._getCurrentPower(s.stat_rate);e>0&&(t+=e)}else if("grid"===s.type&&s.stat_rate){const t=this._getCurrentPower(s.stat_rate);t>0?e+=t:t<0&&(i+=Math.abs(t))}else if("battery"===s.type&&s.stat_rate){const t=this._getCurrentPower(s.stat_rate);t>0?a+=t:t<0&&(r+=Math.abs(t))}});const o=e+t+a-i-r;return Math.max(0,o)}render(){if(!this._config||!this._data)return r.s6;const s=this._computeTotalPower(this._data.prefs);let t;t=s>=1e3?`${(0,c.ZV)(s/1e3,this.hass.locale,{maximumFractionDigits:2})} kW`:`${(0,c.ZV)(s,this.hass.locale,{maximumFractionDigits:0})} W`;const e=this._config.title||this.hass.localize("ui.panel.lovelace.cards.energy.power_total_title");return r.qy` <ha-badge .label="${e}"> <ha-svg-icon slot="icon" .path="${_}"></ha-svg-icon> ${t} </ha-badge> `}constructor(...s){super(...s),this._entities=new Set,this.hassSubscribeRequiredHostProps=["_config"]}}d.styles=r.AH`ha-badge{--badge-color:var(--primary-color)}`,(0,a.Cg)([(0,o.MZ)({attribute:!1})],d.prototype,"hass",void 0),(0,a.Cg)([(0,o.wk)()],d.prototype,"_config",void 0),(0,a.Cg)([(0,o.wk)()],d.prototype,"_data",void 0),d=(0,a.Cg)([(0,o.EM)("hui-power-total-badge")],d),i()}catch(s){i(s)}})},56434(s,t,e){e.d(t,{e:()=>a});var i=e(81977);function a(s,t,e){return(0,i.P)(s,12*t,e)}}};