iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 6.86 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[69315],{89029:function(t,e,i){i.a(t,async function(t,s){try{i.r(e),i.d(e,{HuiStatisticCard:function(){return C},PERIOD_ENERGY:function(){return k},STATISTIC_CARD_DEFAULT_PERIOD:function(){return x}});i(16280),i(3362),i(62953);var n=i(40445),r=i(5124),a=i(67576),o=i(42372),h=i(1087),c=i(78649),_=i(20058),l=i(38962),d=(i(76776),i(93367)),f=i(38114),g=i(23528),u=i(33121),y=i(13632),p=i(784),v=i(83938),m=t([l,d,f,_,g]);[l,d,f,_,g]=m.then?(await m)():m;let b,E,w,S=t=>t;const k="energy_date_selection",x={calendar:{period:"month"}};class C extends r.WF{static async getConfigElement(){return await i.e(90303).then(i.bind(i,46754)),document.createElement("hui-statistic-card-editor")}static getStubConfig(t,e,i){return{entity:(0,y.B)(t,1,e,i,["sensor"],t=>"state_class"in t.attributes)[0]||"",period:x}}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribeEnergy(),clearInterval(this._interval)}connectedCallback(){super.connectedCallback(),this._useEnergyDateSelect()?this._subscribeEnergy():this._setFetchStatisticTimer()}_subscribeEnergy(){var t;this._energySub||(this._energySub=(0,f.tb)(this.hass,{key:null===(t=this._config)||void 0===t?void 0:t.collection_key}).subscribe(t=>{this._energyStart=t.start;let e=t.end;e&&999===e.getMilliseconds()&&(e=new Date(e),e.setMilliseconds(1e3)),this._energyEnd=e,this._fetchStatistic()}))}_unsubscribeEnergy(){this._energySub&&(this._energySub(),this._energySub=void 0),this._energyStart=void 0,this._energyEnd=void 0}setConfig(t){if(!t.entity)throw new Error("Entity must be specified");if(!t.stat_type)throw new Error("Statistic type must be specified");if(!t.period)throw new Error("Period must be specified");if(t.entity&&!(0,g.OQ)(t.entity)&&!(0,c.n)(t.entity))throw new Error("Invalid entity");t.collection_key&&(0,f.s8)(t.collection_key),t.period===k&&(t=Object.assign(Object.assign({energy_date_selection:!0},t),{},{period:x})),this._config=t,this._error=void 0,this._config.footer?this._footerElement=(0,v.x)(this._config.footer):this._footerElement&&(this._footerElement=void 0)}async getCardSize(){let t=2;if(this._footerElement){const e=(0,u.Z)(this._footerElement);t+=e instanceof Promise?await e:e}return t}render(){if(!this._config||!this.hass)return r.s6;if(this._error)return(0,r.qy)(b||(b=S` <ha-alert alert-type="error">${0}</ha-alert> `),this._error);const t=this.hass.states[this._config.entity],e=(this._config.name?this.hass.formatEntityName(t,this._config.name):"")||(0,g.$O)(this.hass,this._config.entity,this._metadata),i=!(0,g.OQ)(this._config.entity);return(0,r.qy)(E||(E=S` <ha-card ="${0}" .tabIndex="${0}" ?interactive="${0}"> <div class="header"> <div class="name" .title="${0}">${0}</div> <div class="icon"> <ha-state-icon .icon="${0}" .stateObj="${0}"></ha-state-icon> </div> </div> <div class="info"> <span class="value">${0}</span> <span class="measurement">${0}</span> </div> ${0} </ha-card> `),i?this._handleClick:r.s6,i?0:-1,i,e,e,this._config.icon,t,void 0===this._value?"":null===this._value?"?":(0,_.ZV)(this._value,this.hass.locale,(0,_.ZQ)(void 0,this.hass.entities[this._config.entity])),this._config.unit||(0,g.JE)(this.hass,this._config.entity,this._metadata),this._footerElement)}shouldUpdate(t){return this._footerElement&&(this._footerElement.hass=this.hass),!!(t.has("_value")||t.has("_metadata")||t.has("_error")||t.has("_energyStart")||t.has("_energyEnd"))||(!this._config||(0,p.LX)(this,t))}willUpdate(t){if(super.willUpdate(t),!this._config||!t.has("_config"))return;const e=t.get("_config");if(this.hass){const i=this._useEnergyDateSelect();if(i&&!this._energySub)return void this._subscribeEnergy();if(!i&&this._energySub)return this._unsubscribeEnergy(),void this._setFetchStatisticTimer();i&&this._energySub&&t.has("_config")&&(null==e?void 0:e.collection_key)!==this._config.collection_key&&(this._unsubscribeEnergy(),this._subscribeEnergy())}t.has("_config")&&(null==e?void 0:e.entity)!==this._config.entity&&this._fetchMetadata().then(()=>{this._setFetchStatisticTimer()})}firstUpdated(){this._fetchStatistic(),this._fetchMetadata()}updated(t){if(super.updated(t),!this._config||!this.hass)return;const e=t.get("hass"),i=t.get("_config");e&&i&&e.themes===this.hass.themes&&i.theme===this._config.theme||(0,o.Q)(this,this.hass.themes,this._config.theme)}_useEnergyDateSelect(){return!!this._config&&(!!this._config.energy_date_selection||this._config.period===k)}_setFetchStatisticTimer(){this._fetchStatistic(),clearInterval(this._interval),this._useEnergyDateSelect()||(this._interval=window.setInterval(()=>this._fetchStatistic(),3e5))}async _fetchStatistic(){if(this.hass&&this._config)try{var t,e;const i=await(0,g.pJ)(this.hass,this._config.entity,this._energyStart&&this._energyEnd?{fixed_period:{start:this._energyStart,end:this._energyEnd}}:"object"==typeof(null===(t=this._config)||void 0===t?void 0:t.period)?null===(e=this._config)||void 0===e?void 0:e.period:{});this._value=i[this._config.stat_type],this._error=void 0}catch(i){this._error=i.message}}async _fetchMetadata(){if(this.hass&&this._config)try{var t;this._metadata=null===(t=await(0,g.Wr)(this.hass,[this._config.entity]))||void 0===t?void 0:t[0]}catch(e){this._error=e.message}}_handleClick(){(0,h.r)(this,"hass-more-info",{entityId:this._config.entity})}getGridOptions(){return{columns:6,rows:2,min_columns:6,min_rows:2}}static get styles(){return[(0,r.AH)(w||(w=S`ha-card{height:100%;display:flex;flex-direction:column;justify-content:space-between;outline:0}ha-card[interactive]{cursor:pointer}.header{display:flex;padding:8px 16px 0;justify-content:space-between}.name{color:var(--secondary-text-color);line-height:var(--ha-line-height-expanded);font-size:var(--ha-font-size-l);font-weight:var(--ha-font-weight-medium);overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.icon{color:var(--state-icon-color,#44739e);line-height:40px}.info{padding:0px 16px 16px;margin-top:-4px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;line-height:var(--ha-line-height-expanded)}.value{font-size:var(--ha-font-size-3xl);margin-right:4px;margin-inline-end:4px;margin-inline-start:initial}.measurement{font-size:var(--ha-font-size-l);color:var(--secondary-text-color)}`))]}}(0,n.Cg)([(0,a.MZ)({attribute:!1})],C.prototype,"hass",void 0),(0,n.Cg)([(0,a.wk)()],C.prototype,"_config",void 0),(0,n.Cg)([(0,a.wk)()],C.prototype,"_value",void 0),(0,n.Cg)([(0,a.wk)()],C.prototype,"_metadata",void 0),(0,n.Cg)([(0,a.wk)()],C.prototype,"_error",void 0),(0,n.Cg)([(0,a.wk)()],C.prototype,"_energyStart",void 0),(0,n.Cg)([(0,a.wk)()],C.prototype,"_energyEnd",void 0),C=(0,n.Cg)([(0,a.EM)("hui-statistic-card")],C),s()}catch(b){s(b)}})},56434:function(t,e,i){i.d(e,{e:function(){return n}});var s=i(81977);function n(t,e,i){return(0,s.P)(t,12*e,i)}}}]);