UNPKG

iobroker.lovelace

Version:

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

1 lines 6.45 kB
export const __rspack_esm_id=69315;export const __rspack_esm_ids=[69315];export const __webpack_modules__={89029(t,e,i){i.a(t,async function(t,s){try{i.r(e),i.d(e,{HuiStatisticCard:()=>w,PERIOD_ENERGY:()=>b,STATISTIC_CARD_DEFAULT_PERIOD:()=>E});var n=i(62826),r=i(5124),a=i(22441),o=i(42372),h=i(1087),c=i(78649),_=i(20058),d=i(38962),l=(i(76776),i(93367)),g=i(38114),f=i(23528),y=i(33121),u=i(13632),p=i(784),m=i(83938),v=t([d,l,g,_]);[d,l,g,_]=v.then?(await v)():v;const b="energy_date_selection",E={calendar:{period:"month"}};class w 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,u.B)(t,1,e,i,["sensor"],t=>"state_class"in t.attributes)[0]||"",period:E}}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribeEnergy(),clearInterval(this._interval)}connectedCallback(){super.connectedCallback(),this._useEnergyDateSelect()?this._subscribeEnergy():this._setFetchStatisticTimer()}_subscribeEnergy(){this._energySub||(this._energySub=(0,g.tb)(this.hass,{key:this._config?.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,f.OQ)(t.entity)&&!(0,c.n)(t.entity))throw new Error("Invalid entity");t.collection_key&&(0,g.s8)(t.collection_key),t.period===b&&(t={energy_date_selection:!0,...t,period:E}),this._config=t,this._error=void 0,this._config.footer?this._footerElement=(0,m.x)(this._config.footer):this._footerElement&&(this._footerElement=void 0)}async getCardSize(){let t=2;if(this._footerElement){const e=(0,y.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 r.qy` <ha-alert alert-type="error">${this._error}</ha-alert> `;const t=this.hass.states[this._config.entity],e=(this._config.name?this.hass.formatEntityName(t,this._config.name):"")||(0,f.$O)(this.hass,this._config.entity,this._metadata),i=!(0,f.OQ)(this._config.entity);return r.qy` <ha-card @click="${i?this._handleClick:r.s6}" .tabIndex="${i?0:-1}" ?interactive="${i}"> <div class="header"> <div class="name" .title="${e}">${e}</div> <div class="icon"> <ha-state-icon .icon="${this._config.icon}" .stateObj="${t}"></ha-state-icon> </div> </div> <div class="info"> <span class="value">${void 0===this._value?"":null===this._value?"?":(0,_.ZV)(this._value,this.hass.locale,(0,_.ZQ)(void 0,this.hass.entities[this._config.entity]))}</span> <span class="measurement">${this._config.unit||(0,f.JE)(this.hass,this._config.entity,this._metadata)}</span> </div> ${this._footerElement} </ha-card> `}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")&&e?.collection_key!==this._config.collection_key&&(this._unsubscribeEnergy(),this._subscribeEnergy())}t.has("_config")&&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===b)}_setFetchStatisticTimer(){this._fetchStatistic(),clearInterval(this._interval),this._useEnergyDateSelect()||(this._interval=window.setInterval(()=>this._fetchStatistic(),3e5))}async _fetchStatistic(){if(this.hass&&this._config)try{const t=await(0,f.pJ)(this.hass,this._config.entity,this._energyStart&&this._energyEnd?{fixed_period:{start:this._energyStart,end:this._energyEnd}}:"object"==typeof this._config?.period?this._config?.period:{});this._value=t[this._config.stat_type],this._error=void 0}catch(t){this._error=t.message}}async _fetchMetadata(){if(this.hass&&this._config)try{this._metadata=(await(0,f.Wr)(this.hass,[this._config.entity]))?.[0]}catch(t){this._error=t.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[r.AH`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})],w.prototype,"hass",void 0),(0,n.Cg)([(0,a.wk)()],w.prototype,"_config",void 0),(0,n.Cg)([(0,a.wk)()],w.prototype,"_value",void 0),(0,n.Cg)([(0,a.wk)()],w.prototype,"_metadata",void 0),(0,n.Cg)([(0,a.wk)()],w.prototype,"_error",void 0),(0,n.Cg)([(0,a.wk)()],w.prototype,"_energyStart",void 0),(0,n.Cg)([(0,a.wk)()],w.prototype,"_energyEnd",void 0),w=(0,n.Cg)([(0,a.EM)("hui-statistic-card")],w),s()}catch(t){s(t)}})},56434(t,e,i){i.d(e,{e:()=>n});var s=i(81977);function n(t,e,i){return(0,s.P)(t,12*e,i)}}};