UNPKG

iobroker.lovelace

Version:

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

2 lines 12.9 kB
export const __webpack_ids__=["51062"];export const __webpack_modules__={17705:function(t,e,i){i.d(e,{Cj:()=>u,F7:()=>n,Hs:()=>$,Kd:()=>S,Kj:()=>g,Nw:()=>f,PA:()=>a,Py:()=>c,Qm:()=>E,Z0:()=>v,_Y:()=>_,_m:()=>r,dL:()=>d,dO:()=>b,hN:()=>l,h_:()=>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}),_=(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}),h=t=>t.callWS({type:"recorder/validate_statistics"}),u=(t,e,i)=>t.callWS({type:"recorder/update_statistics_metadata",statistic_id:e,unit_of_measurement:i}),l=(t,e)=>t.callWS({type:"recorder/clear_statistics",statistic_ids:e}),g=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=g(t[s]);null!==e&&(null===i?i=e:i+=e)}return i},f=(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},$=t=>t.includes(":"),E=t=>t.callWS({type:"recorder/update_statistics_issues"})},53259:function(t,e,i){i.a(t,(async function(t,s){try{i.d(e,{J:()=>k,MC:()=>p,Zx:()=>b,b4:()=>v,kT:()=>$});i(92745),i(9359),i(56475),i(31526),i(70104),i(92519),i(42179),i(89256),i(24931),i(88463),i(57449),i(19814);var n=i(21893),a=i(13809),r=i(38836),o=i(84775),c=i(80951),d=i(13730),_=i(6542),h=i(83204),u=i(23459),l=i(23711),g=i(50602),y=i(46467),f=i(33570),m=t([y,f,g]);function p(t,e){let i=new Date(e);return t>2&&0===i.getHours()&&(i=(0,n.b)(i,1)),i.setMinutes(0,0,0),t>35&&i.setDate(1),t>2&&i.setHours(0),i.getTime()}function v(t){return t>35?"month":t>2?"day":"hour"}function k(t,e,i,s,n,r,o,c){const d=(0,a.j)(e,t),_=void 0!==r&&void 0!==o;return{xAxis:{type:"time",min:t,max:p(d,e)},yAxis:{type:"value",name:n,nameGap:2,nameTextStyle:{align:"left"},axisLabel:{formatter:t=>(0,g.uf)(Math.abs(t),i)},splitLine:{show:!0}},grid:{top:15,bottom:0,left:1,right:1,containLabel:!0},tooltip:{trigger:"axis",formatter:t=>{if(Array.isArray(t)){const e=[],a=[];return t.forEach((t=>{t.seriesId?.startsWith("compare-")?a.push(t):e.push(t)})),[e,a].map((t=>S(t,i,s,d,_,n,c))).filter(Boolean).join("<br><br>")}return S([t],i,s,d,_,n,c)}}}}function S(t,e,i,s,n,a,o){if(!t[0]?.value)return"";const c=new Date(t[0].value?.[2]??t[0].value?.[0]);let d;d=s>89?`${(0,y.NC)(c,e,i)}`:s>0?`${(0,y.ud)(c,e,i)}`:`${n?`${(0,y.ud)(c,e,i)}: `:""}${(0,f.mr)(c,e,i)} – ${(0,f.mr)((0,r.T)(c,1),e,i)}`;const _=`<h4 style="text-align: center; margin: 0;">${d}</h4>`;let h=0,u=0,l=0,m=0;const p=t.map((t=>{const i=t.value?.[1],s=(0,g.uf)(i,e);return"0"!==s&&("bar"===t.componentSubType&&(i>0?(h+=i,u++):(l+=i,m++)),`${t.marker} ${t.seriesName}: ${s} ${a}`)})).filter(Boolean);let v="";return 0!==h&&u>1&&o&&(v+=`<br><b>${o(h)}</b>`),0!==l&&m>1&&o&&(v+=`<br><b>${o(l)}</b>`),p.length>0?`${_}${p.join("<br>")}${v}`:""}function b(t){Array.from(new Set(t.map((t=>t.data.map((t=>Number(t[0]))))).flat())).sort(((t,e)=>t-e)).forEach(((e,i)=>{const s={},n={};for(let a=t.length-1;a>=0;a--){const r=t[a].data[i],o=r&&"object"==typeof r&&"value"in r?r:{value:r},c=o.value?.[0],d=t[a].stack??"";void 0!==c&&(Number(c)!==e?t[a].data?.splice(i,0,{value:[e,0],itemStyle:{borderWidth:0}}):0===o.value?.[1]?t[a].data[i]={...o,itemStyle:{...o.itemStyle,borderWidth:0}}:!s[d]&&o.value?.[1]>0?(t[a].data[i]={...o,itemStyle:{...o.itemStyle,borderRadius:[4,4,0,0]}},s[d]=!0):!n[d]&&o.value?.[1]<0&&(t[a].data[i]={...o,itemStyle:{...o.itemStyle,borderRadius:[0,0,4,4]}},n[d]=!0))}}))}function $(t,e){if(!e)return t=>t;const i=(0,o.o)(t,e);if(0!==i&&t.getTime()===(0,c.e)(t).getTime())return t=>(0,d.B)(t,i);const s=(0,_.d)(t,e);if(0!==s&&t.getTime()===(0,h.N)(t).getTime())return t=>(0,u.z)(t,s);const n=t.getTime()-e.getTime();return t=>(0,l.n)(t,n)}[y,f,g]=m.then?(await m)():m,s()}catch(E){s(E)}}))},56615:function(t,e,i){i.a(t,(async function(t,s){try{i.r(e),i.d(e,{DEFAULT_DAYS_TO_SHOW:()=>p,HuiStatisticsGraphCard:()=>v});var n=i(44249),a=i(72621),r=(i(92745),i(9359),i(1331),i(31526),i(13809)),o=i(21893),c=i(57243),d=i(15093),_=i(35359),h=(i(54977),i(1118)),u=i(53259),l=i(17705),g=i(69223),y=i(93331),f=i(29401),m=t([h,u]);[h,u]=m.then?(await m)():m;const p=30;let v=(0,n.Z)([(0,d.Mo)("hui-statistics-graph-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 Promise.all([i.e("46379"),i.e("24199"),i.e("27506"),i.e("27090"),i.e("87593"),i.e("19551"),i.e("47457")]).then(i.bind(i,23656)),document.createElement("hui-statistics-graph-card-editor")}},{kind:"method",static:!0,key:"getStubConfig",value:function(t,e,i){const s=(0,g.j)(t,1,e,i,["sensor"],(t=>"state_class"in t.attributes));return{type:"statistics-graph",entities:s.length?[s[0]]:[]}}},{kind:"field",decorators:[(0,d.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,d.SB)()],key:"_config",value:void 0},{kind:"field",decorators:[(0,d.SB)()],key:"_statistics",value:void 0},{kind:"field",decorators:[(0,d.SB)()],key:"_metadata",value:void 0},{kind:"field",decorators:[(0,d.SB)()],key:"_unit",value:void 0},{kind:"field",key:"_entities",value:()=>[]},{kind:"field",key:"_names",value:()=>({})},{kind:"field",key:"_interval",value:void 0},{kind:"field",key:"_statTypes",value:void 0},{kind:"field",key:"_energySub",value:void 0},{kind:"field",decorators:[(0,d.SB)()],key:"_energyStart",value:void 0},{kind:"field",decorators:[(0,d.SB)()],key:"_energyEnd",value:void 0},{kind:"method",key:"disconnectedCallback",value:function(){(0,a.Z)(s,"disconnectedCallback",this,3)([]),this._unsubscribeEnergy(),this._interval&&(clearInterval(this._interval),this._interval=void 0)}},{kind:"method",key:"connectedCallback",value:function(){(0,a.Z)(s,"connectedCallback",this,3)([]),this.hasUpdated&&(this._config?.energy_date_selection?this._subscribeEnergy():this._setFetchStatisticsTimer())}},{kind:"method",key:"_subscribeEnergy",value:function(){this._energySub||(this._energySub=(0,h.UB)(this.hass,{key:this._config?.collection_key}).subscribe((t=>{this._energyStart=t.start,this._energyEnd=t.end,this._getStatistics()})))}},{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:"getCardSize",value:function(){return 5+(this._config?.title?2:0)+(this._config?.hide_legend?0:this._entities?.length||0)}},{kind:"method",key:"getGridOptions",value:function(){return{columns:12,min_columns:6,min_rows:3}}},{kind:"method",key:"setConfig",value:function(t){if(!t.entities||!Array.isArray(t.entities))throw new Error("Entities need to be an array");if(!t.entities.length)throw new Error("You must include at least one entity");const e=t.entities?(0,f.A)(t.entities,!1):[];this._entities=[],e.forEach((t=>{this._entities.push(t.entity),t.name&&(this._names[t.entity]=t.name)})),"string"==typeof t.stat_types?this._statTypes=[t.stat_types]:t.stat_types?this._statTypes=t.stat_types:this._statTypes=["change","state","sum","min","max","mean"],this._config=t}},{kind:"method",key:"shouldUpdate",value:function(t){return(0,y.Wh)(this,t)||t.size>1||!t.has("hass")}},{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.energy_date_selection&&!this._energySub)return void this._subscribeEnergy();if(!this._config.energy_date_selection&&this._energySub)return this._unsubscribeEnergy(),void this._setFetchStatisticsTimer();this._config.energy_date_selection&&this._energySub&&t.has("_config")&&e?.collection_key!==this._config.collection_key&&(this._unsubscribeEnergy(),this._subscribeEnergy())}t.has("_config")&&e?.entities!==this._config.entities?this._getStatisticsMetaData(this._entities).then((()=>{this._setFetchStatisticsTimer()})):!t.has("_config")||e?.stat_types===this._config.stat_types&&e?.days_to_show===this._config.days_to_show&&e?.period===this._config.period&&e?.unit===this._config.unit||this._setFetchStatisticsTimer()}},{kind:"method",key:"_setFetchStatisticsTimer",value:function(){this._getStatistics(),clearInterval(this._interval),this._config?.energy_date_selection||(this._interval=window.setInterval((()=>this._getStatistics()),this._intervalTimeout))}},{kind:"get",key:"_period",value:function(){return this._config?.period??(this._energyStart&&this._energyEnd?(0,u.b4)((0,r.j)(this._energyEnd,this._energyStart)):void 0)}},{kind:"method",key:"render",value:function(){if(!this.hass||!this._config)return c.Ld;const t="number"==typeof this._config.grid_options?.rows;return c.dy` <ha-card> ${this._config.title?c.dy`<h1 class="card-header">${this._config.title}</h1>`:c.Ld} <div class="content ${(0,_.$)({"has-header":!!this._config.title})}"> <statistics-chart .hass="${this.hass}" .isLoadingData="${!this._statistics}" .statisticsData="${this._statistics}" .metadata="${this._metadata}" .period="${this._period}" .chartType="${this._config.chart_type||"line"}" .statTypes="${this._statTypes}" .names="${this._names}" .unit="${this._unit}" .minYAxis="${this._config.min_y_axis}" .maxYAxis="${this._config.max_y_axis}" .startTime="${this._energyStart}" .endTime="${this._energyEnd&&this._energyStart?(0,u.MC)((0,r.j)(this._energyEnd,this._energyStart),this._energyEnd):void 0}" .fitYData="${this._config.fit_y_data||!1}" .hideLegend="${this._config.hide_legend||!1}" .logarithmicScale="${this._config.logarithmic_scale||!1}" .daysToShow="${this._energyStart&&this._energyEnd?(0,r.j)(this._energyEnd,this._energyStart):this._config.days_to_show||p}" .height="${t?"100%":void 0}" .expandLegend="${this._config.expand_legend}"></statistics-chart> </div> </ha-card> `}},{kind:"get",key:"_intervalTimeout",value:function(){return 1e3*("5minute"===this._config?.period?5:60)*60}},{kind:"method",key:"_getStatisticsMetaData",value:async function(t){const e=await(0,l.Py)(this.hass,t),i={};e.forEach((t=>{i[t.statistic_id]=t})),this._metadata=i}},{kind:"method",key:"_getStatistics",value:async function(){const t=this._energyStart??(0,o.b)(new Date,24*(this._config.days_to_show||p)+1),e=this._energyEnd;try{let i;if(this._config.unit&&this._metadata){const t=Object.values(this._metadata).find((t=>(0,l.dO)(this.hass,t?.statistic_id,t)===this._config.unit));t&&(i=t.unit_class,this._unit=this._config.unit)}if(!i&&this._metadata){const t=this._metadata[this._entities[0]];i=t?.unit_class,this._unit=i&&(0,l.dO)(this.hass,t.statistic_id,t)||void 0}const s=i?{[i]:this._unit}:void 0,n=await(0,l.dL)(this.hass,t,e,this._entities,this._period,s,this._statTypes);this._statistics={},this._entities.forEach((t=>{t in n&&(this._statistics[t]=n[t])}))}catch(t){this._statistics=void 0}}},{kind:"field",static:!0,key:"styles",value:()=>c.iv`ha-card{display:flex;flex-direction:column;height:100%}.card-header{padding-bottom:0}.content{padding:16px;flex:1}.has-header{padding-top:0}statistics-chart{height:100%}`}]}}),c.oi);s()}catch(t){s(t)}}))},13730:function(t,e,i){i.d(e,{B:()=>n});var s=i(23459);function n(t,e,i){return(0,s.z)(t,12*e,i)}},84775:function(t,e,i){i.d(e,{o:()=>r});var s=i(18492),n=i(2425);function a(t,e,i){const[n,a]=(0,s.d)(i?.in,t,e);return n.getFullYear()-a.getFullYear()}function r(t,e,i){const[r,o]=(0,s.d)(i?.in,t,e),c=(0,n.U)(r,o),d=Math.abs(a(r,o));r.setFullYear(1584),o.setFullYear(1584);const _=c*(d-+((0,n.U)(r,o)===-c));return 0===_?0:_}}}; //# sourceMappingURL=51062.b95437fce688c4b6.js.map