iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
2 lines • 9.23 kB
JavaScript
export const __webpack_ids__=["92692"];export const __webpack_modules__={17705:function(t,e,i){i.d(e,{Cj:()=>l,F7:()=>n,Hs:()=>w,Kd:()=>S,Kj:()=>f,Nw:()=>g,PA:()=>a,Py:()=>c,Qm:()=>E,Z0:()=>v,_Y:()=>h,_m:()=>r,dL:()=>d,dO:()=>b,hN:()=>u,h_:()=>_,j2:()=>k,q6:()=>y,uR:()=>o});i(9359),i(52924);var s=i(47194);let n=function(t){return t[t.NONE=0]="NONE",t[t.ARITHMETIC=1]="ARITHMETIC",t[t.CIRCULAR=2]="CIRCULAR",t}({});const a=99387==i.j?["entity_not_recorded","entity_no_longer_recorded","state_class_removed","units_changed","mean_type_changed","no_state"]:null,r=t=>t.sendMessagePromise({type:"recorder/info"}),o=(t,e)=>t.callWS({type:"recorder/list_statistic_ids",statistic_type:e}),c=(t,e)=>t.callWS({type:"recorder/get_statistics_metadata",statistic_ids:e}),d=(t,e,i,s,n="hour",a,r)=>t.callWS({type:"recorder/statistics_during_period",start_time:e.toISOString(),end_time:i?.toISOString(),statistic_ids:s,period:n,units:a,types:r}),h=(t,e,i,s)=>t.callWS({type:"recorder/statistic_during_period",statistic_id:e,units:s,fixed_period:i.fixed_period?{start_time:i.fixed_period.start instanceof Date?i.fixed_period.start.toISOString():i.fixed_period.start,end_time:i.fixed_period.end instanceof Date?i.fixed_period.end.toISOString():i.fixed_period.end}:void 0,calendar:i.calendar,rolling_window:i.rolling_window}),_=t=>t.callWS({type:"recorder/validate_statistics"}),l=(t,e,i)=>t.callWS({type:"recorder/update_statistics_metadata",statistic_id:e,unit_of_measurement:i}),u=(t,e)=>t.callWS({type:"recorder/clear_statistics",statistic_ids:e}),f=t=>{let e=null;if(!t)return null;for(const i of t)null!==i.change&&void 0!==i.change&&(null===e?e=i.change:e+=i.change);return e},y=(t,e)=>{let i=null;for(const s of e){if(!(s in t))continue;const e=f(t[s]);null!==e&&(null===i?i=e:i+=e)}return i},g=(t,e)=>t.some((t=>void 0!==t[e]&&null!==t[e])),m=["mean","min","max"],p=["sum","state","change"],v=(t,e)=>!(!m.includes(e)||t.mean_type===n.NONE)||!(!p.includes(e)||!t.has_sum),k=(t,e,i,s,n)=>{const a=new Date(i).toISOString();return t.callWS({type:"recorder/adjust_sum_statistics",statistic_id:e,start_time:a,adjustment:s,adjustment_unit_of_measurement:n})},S=(t,e,i)=>{const n=t.states[e];return n?(0,s.C)(n):i?.name||e},b=(t,e,i)=>{let s;return e&&(s=t.states[e]?.attributes.unit_of_measurement),void 0===s?i?.statistics_unit_of_measurement:s},w=t=>t.includes(":"),E=t=>t.callWS({type:"recorder/update_statistics_issues"})},98578:function(t,e,i){i.a(t,(async function(t,s){try{i.r(e),i.d(e,{HuiStatisticCard:()=>S,PERIOD_ENERGY:()=>k});var n=i(44249),a=i(72621),r=i(57243),o=i(15093),c=i(82393),d=i(36522),h=i(31064),_=i(50602),l=(i(99426),i(54977),i(51223)),u=i(1118),f=i(17705),y=i(81833),g=i(69223),m=i(93331),p=i(64830),v=t([l,u,_]);[l,u,_]=v.then?(await v)():v;const k="energy_date_selection";let S=(0,n.Z)([(0,o.Mo)("hui-statistic-card")],(function(t,e){class s extends e{constructor(...e){super(...e),t(this)}}return{F:s,d:[{kind:"method",static:!0,key:"getConfigElement",value:async function(){return await i.e("46748").then(i.bind(i,61471)),document.createElement("hui-statistic-card-editor")}},{kind:"method",static:!0,key:"getStubConfig",value:function(t,e,i){return{entity:(0,g.j)(t,1,e,i,["sensor"],(t=>"state_class"in t.attributes))[0]||"",period:{calendar:{period:"month"}}}}},{kind:"field",decorators:[(0,o.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,o.SB)()],key:"_config",value:void 0},{kind:"field",decorators:[(0,o.SB)()],key:"_value",value:void 0},{kind:"field",decorators:[(0,o.SB)()],key:"_metadata",value:void 0},{kind:"field",decorators:[(0,o.SB)()],key:"_error",value:void 0},{kind:"field",key:"_energySub",value:void 0},{kind:"field",decorators:[(0,o.SB)()],key:"_energyStart",value:void 0},{kind:"field",decorators:[(0,o.SB)()],key:"_energyEnd",value:void 0},{kind:"field",key:"_interval",value:void 0},{kind:"field",key:"_footerElement",value:void 0},{kind:"method",key:"disconnectedCallback",value:function(){(0,a.Z)(s,"disconnectedCallback",this,3)([]),this._unsubscribeEnergy(),clearInterval(this._interval)}},{kind:"method",key:"connectedCallback",value:function(){(0,a.Z)(s,"connectedCallback",this,3)([]),this._config?.period===k?this._subscribeEnergy():this._setFetchStatisticTimer()}},{kind:"method",key:"_subscribeEnergy",value:function(){this._energySub||(this._energySub=(0,u.UB)(this.hass,{key:this._config?.collection_key}).subscribe((t=>{this._energyStart=t.start,this._energyEnd=t.end,this._fetchStatistic()})))}},{kind:"method",key:"_unsubscribeEnergy",value:function(){this._energySub&&(this._energySub(),this._energySub=void 0),this._energyStart=void 0,this._energyEnd=void 0}},{kind:"method",key:"setConfig",value:function(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.Hs)(t.entity)&&!(0,h.T)(t.entity))throw new Error("Invalid entity");this._config=t,this._error=void 0,this._config.footer?this._footerElement=(0,p.t)(this._config.footer):this._footerElement&&(this._footerElement=void 0)}},{kind:"method",key:"getCardSize",value:async function(){let t=2;if(this._footerElement){const e=(0,y.N)(this._footerElement);t+=e instanceof Promise?await e:e}return t}},{kind:"method",key:"render",value:function(){if(!this._config||!this.hass)return r.Ld;if(this._error)return r.dy` <ha-alert alert-type="error">${this._error}</ha-alert> `;const t=this.hass.states[this._config.entity],e=this._config.name||(0,f.Kd)(this.hass,this._config.entity,this._metadata);return r.dy` <ha-card ="${this._handleClick}" tabindex="0"> <div class="header"> <div class="name" .title="${e}">${e}</div> <div class="icon"> <ha-state-icon .icon="${this._config.icon}" .stateObj="${t}" .hass="${this.hass}"></ha-state-icon> </div> </div> <div class="info"> <span class="value">${void 0===this._value?"":null===this._value?"?":(0,_.uf)(this._value,this.hass.locale)}</span> <span class="measurement">${this._config.unit||(0,f.dO)(this.hass,this._config.entity,this._metadata)}</span> </div> ${this._footerElement} </ha-card> `}},{kind:"method",key:"shouldUpdate",value:function(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,m.G2)(this,t))}},{kind:"method",key:"willUpdate",value:function(t){if((0,a.Z)(s,"willUpdate",this,3)([t]),!this._config||!t.has("_config"))return;const e=t.get("_config");if(this.hass){if(this._config.period===k&&!this._energySub)return void this._subscribeEnergy();if(this._config.period!==k&&this._energySub)return this._unsubscribeEnergy(),void this._setFetchStatisticTimer();this._config.period===k&&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()}))}},{kind:"method",key:"firstUpdated",value:function(){this._fetchStatistic(),this._fetchMetadata()}},{kind:"method",key:"updated",value:function(t){if((0,a.Z)(s,"updated",this,3)([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,c.R)(this,this.hass.themes,this._config.theme)}},{kind:"method",key:"_setFetchStatisticTimer",value:function(){this._fetchStatistic(),clearInterval(this._interval),this._config?.period!==k&&(this._interval=window.setInterval((()=>this._fetchStatistic()),3e5))}},{kind:"method",key:"_fetchStatistic",value:async function(){if(this.hass&&this._config)try{const t=await(0,f._Y)(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}}},{kind:"method",key:"_fetchMetadata",value:async function(){if(this.hass&&this._config)try{this._metadata=(await(0,f.Py)(this.hass,[this._config.entity]))?.[0]}catch(t){this._error=t.message}}},{kind:"method",key:"_handleClick",value:function(){(0,d.B)(this,"hass-more-info",{entityId:this._config.entity})}},{kind:"method",key:"getGridOptions",value:function(){return{columns:6,rows:2,min_columns:6,min_rows:2}}},{kind:"get",static:!0,key:"styles",value:function(){return[r.iv`ha-card{height:100%;display:flex;flex-direction:column;justify-content:space-between;cursor:pointer;outline:0}.header{display:flex;padding:8px 16px 0;justify-content:space-between}.name{color:var(--secondary-text-color);line-height:40px;font-weight:500;font-size:16px;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:28px}.value{font-size:28px;margin-right:4px;margin-inline-end:4px;margin-inline-start:initial}.measurement{font-size:18px;color:var(--secondary-text-color)}`]}}]}}),r.oi);s()}catch(t){s(t)}}))}};
//# sourceMappingURL=92692.c941fd3716103b0e.js.map