UNPKG

iobroker.lovelace

Version:

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

2 lines 9.77 kB
"use strict";(self.webpackChunkhome_assistant_frontend=self.webpackChunkhome_assistant_frontend||[]).push([["92692"],{17705:function(t,e,i){i.d(e,{Cj:()=>_,F7:()=>s,Hs:()=>w,Kd:()=>S,Kj:()=>f,Nw:()=>v,PA:()=>a,Py:()=>d,Qm:()=>E,Z0:()=>p,_Y:()=>h,_m:()=>o,dL:()=>c,dO:()=>b,hN:()=>u,h_:()=>l,j2:()=>k,q6:()=>y,uR:()=>r});i(19083),i(71695),i(9359),i(52924),i(61006),i(47021);var n=i(47194);let s=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,o=t=>t.sendMessagePromise({type:"recorder/info"}),r=(t,e)=>t.callWS({type:"recorder/list_statistic_ids",statistic_type:e}),d=(t,e)=>t.callWS({type:"recorder/get_statistics_metadata",statistic_ids:e}),c=(t,e,i,n,s="hour",a,o)=>t.callWS({type:"recorder/statistics_during_period",start_time:e.toISOString(),end_time:null==i?void 0:i.toISOString(),statistic_ids:n,period:s,units:a,types:o}),h=(t,e,i,n)=>t.callWS({type:"recorder/statistic_during_period",statistic_id:e,units:n,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}),l=t=>t.callWS({type:"recorder/validate_statistics"}),_=(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 n of e){if(!(n in t))continue;const e=f(t[n]);null!==e&&(null===i?i=e:i+=e)}return i},v=(t,e)=>t.some((t=>void 0!==t[e]&&null!==t[e])),g=["mean","min","max"],m=["sum","state","change"],p=(t,e)=>!(!g.includes(e)||t.mean_type===s.NONE)||!(!m.includes(e)||!t.has_sum),k=(t,e,i,n,s)=>{const a=new Date(i).toISOString();return t.callWS({type:"recorder/adjust_sum_statistics",statistic_id:e,start_time:a,adjustment:n,adjustment_unit_of_measurement:s})},S=(t,e,i)=>{const s=t.states[e];return s?(0,n.C)(s):(null==i?void 0:i.name)||e},b=(t,e,i)=>{let n;var s;e&&(n=null===(s=t.states[e])||void 0===s?void 0:s.attributes.unit_of_measurement);return void 0===n?null==i?void 0:i.statistics_unit_of_measurement:n},w=t=>t.includes(":"),E=t=>t.callWS({type:"recorder/update_statistics_issues"})},98578:function(t,e,i){i.a(t,(async function(t,n){try{i.r(e),i.d(e,{HuiStatisticCard:()=>x,PERIOD_ENERGY:()=>E});var s=i(61701),a=i(72621),o=(i(52247),i(71695),i(40251),i(47021),i(57243)),r=i(50778),d=i(82393),c=i(36522),h=i(31064),l=i(50602),_=(i(99426),i(54977),i(51223)),u=i(1118),f=i(17705),y=i(81833),v=i(69223),g=i(93331),m=i(64830),p=t([_,u,l]);[_,u,l]=p.then?(await p)():p;let k,S,b,w=t=>t;const E="energy_date_selection";let x=(0,s.Z)([(0,r.Mo)("hui-statistic-card")],(function(t,e){class n extends e{constructor(...e){super(...e),t(this)}}return{F:n,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,v.j)(t,1,e,i,["sensor"],(t=>"state_class"in t.attributes))[0]||"",period:{calendar:{period:"month"}}}}},{kind:"field",decorators:[(0,r.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,r.SB)()],key:"_config",value:void 0},{kind:"field",decorators:[(0,r.SB)()],key:"_value",value:void 0},{kind:"field",decorators:[(0,r.SB)()],key:"_metadata",value:void 0},{kind:"field",decorators:[(0,r.SB)()],key:"_error",value:void 0},{kind:"field",key:"_energySub",value:void 0},{kind:"field",decorators:[(0,r.SB)()],key:"_energyStart",value:void 0},{kind:"field",decorators:[(0,r.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)(n,"disconnectedCallback",this,3)([]),this._unsubscribeEnergy(),clearInterval(this._interval)}},{kind:"method",key:"connectedCallback",value:function(){var t;(0,a.Z)(n,"connectedCallback",this,3)([]),(null===(t=this._config)||void 0===t?void 0:t.period)===E?this._subscribeEnergy():this._setFetchStatisticTimer()}},{kind:"method",key:"_subscribeEnergy",value:function(){var t;this._energySub||(this._energySub=(0,u.UB)(this.hass,{key:null===(t=this._config)||void 0===t?void 0:t.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,m.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 o.Ld;if(this._error)return(0,o.dy)(k||(k=w` <ha-alert alert-type="error">${0}</ha-alert> `),this._error);const t=this.hass.states[this._config.entity],e=this._config.name||(0,f.Kd)(this.hass,this._config.entity,this._metadata);return(0,o.dy)(S||(S=w` <ha-card @click="${0}" tabindex="0"> <div class="header"> <div class="name" .title="${0}">${0}</div> <div class="icon"> <ha-state-icon .icon="${0}" .stateObj="${0}" .hass="${0}"></ha-state-icon> </div> </div> <div class="info"> <span class="value">${0}</span> <span class="measurement">${0}</span> </div> ${0} </ha-card> `),this._handleClick,e,e,this._config.icon,t,this.hass,void 0===this._value?"":null===this._value?"?":(0,l.uf)(this._value,this.hass.locale),this._config.unit||(0,f.dO)(this.hass,this._config.entity,this._metadata),this._footerElement)}},{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,g.G2)(this,t))}},{kind:"method",key:"willUpdate",value:function(t){if((0,a.Z)(n,"willUpdate",this,3)([t]),!this._config||!t.has("_config"))return;const e=t.get("_config");if(this.hass){if(this._config.period===E&&!this._energySub)return void this._subscribeEnergy();if(this._config.period!==E&&this._energySub)return this._unsubscribeEnergy(),void this._setFetchStatisticTimer();this._config.period===E&&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()}))}},{kind:"method",key:"firstUpdated",value:function(){this._fetchStatistic(),this._fetchMetadata()}},{kind:"method",key:"updated",value:function(t){if((0,a.Z)(n,"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,d.R)(this,this.hass.themes,this._config.theme)}},{kind:"method",key:"_setFetchStatisticTimer",value:function(){var t;this._fetchStatistic(),clearInterval(this._interval),(null===(t=this._config)||void 0===t?void 0:t.period)!==E&&(this._interval=window.setInterval((()=>this._fetchStatistic()),3e5))}},{kind:"method",key:"_fetchStatistic",value:async function(){if(this.hass&&this._config)try{var t,e;const i=await(0,f._Y)(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}}},{kind:"method",key:"_fetchMetadata",value:async function(){if(this.hass&&this._config)try{var t;this._metadata=null===(t=await(0,f.Py)(this.hass,[this._config.entity]))||void 0===t?void 0:t[0]}catch(e){this._error=e.message}}},{kind:"method",key:"_handleClick",value:function(){(0,c.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[(0,o.iv)(b||(b=w`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)}`))]}}]}}),o.oi);n()}catch(k){n(k)}}))}}]); //# sourceMappingURL=92692.549d8b55f8ef1320.js.map