UNPKG

iobroker.lovelace

Version:

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

1 lines 13.7 kB
export const __rspack_esm_id=58945;export const __rspack_esm_ids=[58945];export const __webpack_modules__={36525(t,e,i){i.a(t,async function(t,s){try{i.d(e,{n:()=>$});i(74423),i(44114),i(18111),i(81148),i(7588),i(61701),i(17642),i(58004),i(33853),i(45876),i(32475),i(15024),i(31698);var a=i(62826),o=i(5124),h=i(22441),n=i(89784),r=i(22786),l=i(90433),d=i(36312),c=i(1087),p=i(72487),m=i(95747),u=i(30162),g=i(20058),y=i(8549),_=i(15638),f=i(23528),b=i(29961),x=i(44439),v=i(1253),D=(i(33062),i(47245)),M=i(89938),C=t([x,b,p,u,m,g]);[x,b,p,u,m,g]=C.then?(await C)():C;const $={mean:"mean",min:"min",max:"max",sum:"sum",state:"sum",change:"sum"},S=Object.keys($).map(t=>`-${t}`);class L extends o.WF{shouldUpdate(t){return t.size>1||!t.has("hass")}willUpdate(t){(t.has("statisticsData")||t.has("statTypes")||t.has("chartType")||t.has("hideLegend")||t.has("_hiddenStats")||t.has("names"))&&this._generateData(),(!this.hasUpdated||t.has("unit")||t.has("period")||t.has("chartType")||t.has("minYAxis")||t.has("maxYAxis")||t.has("fitYData")||t.has("logarithmicScale")||t.has("hideLegend")||t.has("startTime")||t.has("endTime")||t.has("_legendData")||t.has("_chartData"))&&this._createOptions()}firstUpdated(){this._computedStyle=getComputedStyle(this)}render(){return(0,d.x)(this.hass.config,"history")?this.isLoadingData&&!this.statisticsData?o.qy`<div class="info"> ${this.hass.localize("ui.components.statistics_charts.loading_statistics")} </div>`:this.statisticsData&&Object.keys(this.statisticsData).length?o.qy` <ha-chart-base .hass="${this.hass}" .data="${this._chartData}" .options="${this._chartOptions}" .height="${this.height}" style="${(0,n.W)({height:this.height})}" @dataset-hidden="${this._datasetHidden}" @dataset-unhidden="${this._datasetUnhidden}" .expandLegend="${this.expandLegend}" .clickLabelForMoreInfo="${this.clickForMoreInfo&&!this._statisticIds.every(f.OQ)}" @legend-label-click="${this._handleLegendLabelClick}"></ha-chart-base> `:o.qy`<div class="info"> ${this.hass.localize("ui.components.statistics_charts.no_statistics_found")} </div>`:o.qy`<div class="info"> ${this.hass.localize("ui.components.history_charts.history_disabled")} </div>`}_datasetHidden(t){this._hiddenStats.add(t.detail.id),this.requestUpdate("_hiddenStats")}_datasetUnhidden(t){this._hiddenStats.delete(t.detail.id),this.requestUpdate("_hiddenStats")}_handleLegendLabelClick(t){const e=t.detail.id;if((0,f.OQ)(e))return;let i=e;if(!this.hass.states[i])for(const t of S)if(e.endsWith(t)){i=e.slice(0,-t.length);break}this.hass.states[i]&&(0,c.r)(this,"hass-more-info",{entityId:i})}_createOptions(){const t=this.daysToShow??1;let e=this.minYAxis,i=this.maxYAxis;"number"==typeof e?this.fitYData&&(e=({min:t})=>Math.min(this._roundYAxis(t,Math.floor),this.minYAxis)):this.logarithmicScale&&(e=({min:t})=>{const e=t>0?.95*t:1.05*t;return this._roundYAxis(e,Math.floor)}),"number"==typeof i?this.fitYData&&(i=({max:t})=>Math.max(this._roundYAxis(t,Math.ceil),this.maxYAxis)):this.logarithmicScale&&(i=({max:t})=>{const e=t>0?1.05*t:.95*t;return this._roundYAxis(e,Math.ceil)});const s=this.endTime??new Date;let a=this.startTime;a||(this._chartData.forEach(t=>{if(!Array.isArray(t.data)||!t.data[0])return;const e=t.data[0],i=Array.isArray(e)?e[0]:e.value?.[0];i&&(!a||new Date(i)<a)&&(a=new Date(i))}),a||(a=new Date(s.getTime()-24*t*3600*1e3))),this._chartOptions={xAxis:[{id:"xAxis",type:"time",min:a,max:this.endTime,..."month"===this.period&&{minInterval:24192e5,axisLabel:(0,b.d)("month",this.hass.locale,this.hass.config)},..."year"===this.period&&{minInterval:31536e6,axisLabel:(0,b.d)("year",this.hass.locale,this.hass.config)}},{id:"hiddenAxis",type:"time",show:!1}],yAxis:{type:this.logarithmicScale?"log":"value",name:this.unit,nameGap:2,nameTextStyle:{align:"left"},position:(0,_.qC)(this.hass.language,this.hass.translationMetadata.translations)?"right":"left",scale:this.chartType.startsWith("line")||this.logarithmicScale||void 0!==e||void 0!==i,min:this._clampYAxis(e),max:this._clampYAxis(i),splitLine:{show:!0},axisLabel:{formatter:this._formatYAxisLabel}},legend:{type:"custom",show:!this.hideLegend,data:this._legendData},grid:{top:15,left:1,right:1,bottom:0,containLabel:!0},tooltip:{trigger:"axis",renderMode:"html",position:v.mJ,confine:!0,formatter:this._renderTooltip}}}async _generateData(){if(!this.statisticsData)return;const t=this.metadata||await this._getStatisticsMetaData(Object.keys(this.statisticsData));let e=0;const i=this.chartType.startsWith("line")?"line":"bar",s=this.chartType.endsWith("stack"),a=Object.entries(this.statisticsData),o=[];let h=1/0,n=-1/0;const r=t=>{"number"==typeof t&&Number.isFinite(t)&&(t<h&&(h=t),t>n&&(n=t))},d=[],c=[];let p;if(0===a.length)return;p=this.endTime||new Date(Math.max(...a.map(([t,e])=>new Date(e[e.length-1].start).getTime()))),p>new Date&&(p=new Date);const m=new Date,u=m.getTime()-p.getTime()<=6e5;if(!this.unit){let e;a.forEach(([i,s])=>{const a=t?.[i],o=(0,f.JE)(this.hass,i,a);void 0===e?e=o:null!==e&&e!==o&&(e=null)}),e&&(this.unit=e)}const g=this.names||{},y=this.colors||{};a.forEach(([a,h])=>{const n=t?.[a];let _=g[a];void 0===_&&(_=(0,f.$O)(this.hass,a,n));let b,x=null;const v=[],D=[],M="bar"===i&&("5minute"===this.period||"hour"===this.period);let C=y[a];void 0===C&&(C=(0,l.fI)(e,this._computedStyle||getComputedStyle(this)),e++);const $=[],S=this.statTypes.includes("mean")&&(0,f.iY)(h,"mean"),L=this.statTypes.includes("max")&&(0,f.iY)(h,"max"),T=this.statTypes.includes("min")&&(0,f.iY)(h,"min"),w=!s&&[S,L,T].filter(Boolean).length>1,k=this.statTypes.includes("state"),A=L?"max":"mean",Z=T?"min":"mean",Y=w?[...this.statTypes].sort((t,e)=>"min"===t||"max"===e?-1:"max"===t||"min"===e?1:0):this.statTypes;let I=!1;Y.forEach(t=>{if((0,f.iY)(h,t)){const e=w&&(t===A||t===Z);$.push(t);const o=e&&T&&L&&S||k&&["change","sum"].includes(t)?C+(this.hideLegend?"00":"7F"):C,h=e?C+"3F":C+"7F",n={id:`${a}-${t}`,type:i,smooth:"line"===i&&.4,cursor:"default",data:[],name:_?`${_} (${this.hass.localize(`ui.components.statistics_charts.statistic_types.${t}`)})`:this.hass.localize(`ui.components.statistics_charts.statistic_types.${t}`),symbol:"none",sampling:e&&w?"lttb":"minmax",animationDurationUpdate:0,lineStyle:{width:1.5},itemStyle:"bar"===i?{borderColor:o,borderWidth:1.5}:void 0,color:"bar"===i?h:o};if(s?(n.stack="band-stacked",n.stackStrategy="samesign","line"===i&&(n.areaStyle={color:C+"3F"})):e&&"line"===i&&(n.stack=`band-${a}`,n.stackStrategy="all",this._hiddenStats.has(`${a}-${Z}`)?(n.stackOrder="seriesDesc",n.areaStyle=void 0):(n.stackOrder="seriesAsc",t===A&&(n.areaStyle={color:C+"3F"}))),!this.hideLegend){const e=S?"mean"===t:!1===I;e&&D.push({id:a,name:_,color:n.color,borderColor:n.itemStyle?.borderColor,noLabelClick:(0,f.OQ)(a)}),I=I||e}v.push(n),c.push(a)}});let F=null,O=null;h.forEach(t=>{const e=new Date(t.start),s=new Date(t.end);if(F===e)return;F=e;const o=[];$.forEach(e=>{const s=[];if("sum"===e)null==O?(s.push(0),O=t.sum):s.push((t.sum||0)-O);else if(e===A&&"line"===i&&w&&!this._hiddenStats.has(`${a}-${Z}`)){const e=t[A]||0;s.push(Math.abs(e-(t[Z]||0))),s.push(e)}else s.push(t[e]??null);o.push(s)}),this._hiddenStats.has(a)||((t,e,s,a)=>{a.length&&(s=e.getTime()<s.getTime()?e:s,t.getTime()>s.getTime()||(v.forEach((s,o)=>{if("line"===i)b&&x&&b.getTime()!==t.getTime()&&(s.data.push([b,...x[o]]),s.data.push([b,null])),s.data.push([t,...a[o]]),r(a[o][a[o].length-1]);else{let i=t;M&&(i=new Date((t.getTime()+e.getTime())/2)),s.data.push([i,a[o][0],t,e]),r(a[o][0])}}),x=a,b=s))})(e,s,p,o)});const E=b,q=x;"line"===i&&E&&q&&v.forEach((t,e)=>{t.data.push([E,...q[e]])});const B=(0,f.JE)(this.hass,a,n);if(u&&!s&&(!this.unit||!B||this.unit===B)&&!(0,f.OQ)(a)){const t=this.hass.states[a];if(t){const e=parseFloat(t.state);isFinite(e)&&!this._hiddenStats.has(a)&&$.forEach((t,s)=>{if("sum"===t||"change"===t)return;const o=[];t===A&&"line"===i&&w&&!this._hiddenStats.has(`${a}-${Z}`)?(o.push(0),o.push(e)):o.push(e),v[s].data.push([m,...o]),r(o[o.length-1])})}}Array.prototype.push.apply(o,v),Array.prototype.push.apply(d,D)}),"bar"===i&&(0,D.R)(o,s),d.forEach(({id:t,name:e,color:s,borderColor:a})=>{o.push({id:t,name:e,color:s,itemStyle:{borderColor:a},type:i,data:[],xAxisIndex:1})}),this._yAxisFractionDigits=(0,M.G)(h,n),this._chartData=o,d.length!==this._legendData?.length&&(this._legendData=d.length>1?d.map(({id:t,name:e,noLabelClick:i})=>({id:t,name:e,noLabelClick:i})):void 0),this._statisticIds=c}_clampYAxis(t){if(this.logarithmicScale){if("number"==typeof t)return Math.max(t,Number.EPSILON);if("function"==typeof t)return e=>Math.max(t(e),Number.EPSILON)}return t}_roundYAxis(t,e){return Math.abs(t)<1?t:e(t)}constructor(...t){super(...t),this.statTypes=["sum","min","mean","max"],this.chartType="line",this.fitYData=!1,this.hideLegend=!1,this.logarithmicScale=!1,this.isLoadingData=!1,this.clickForMoreInfo=!0,this._chartData=[],this._statisticIds=[],this._hiddenStats=new Set,this._yAxisFractionDigits=1,this._renderTooltip=t=>{const e={},i=this.chartType.startsWith("bar"),s=this.period,a=this.unit?`${(0,y.A)(this.unit,this.hass.locale)}${this.unit}`:"",h=[];for(const o of t){if(e[o.seriesIndex])continue;e[o.seriesIndex]=!0;const t=this._statisticIds[o.seriesIndex],n=this.hass.states[t],r=this.hass.entities[t];let l,d;if(i){let t,e;l=String(o.value[1]),o.value[2]?(t=new Date(o.value[2]),o.value[3]&&(e=new Date(o.value[3]))):t=new Date(o.value[0]),d="year"===s||"month"===s||"week"===s||"day"===s?(0,p.Yq)(t,this.hass.locale,this.hass.config)+(e&&"day"!==s?` – ${(0,p.Yq)(e,this.hass.locale,this.hass.config)}`:""):(0,m.yg)(t,this.hass.locale,this.hass.config)+(e?` – ${(0,u.ie)(e,this.hass.locale,this.hass.config)}`:"")}else l=String(o.value[2]??o.value[1]),d=(0,m.yg)(new Date(o.value[0]),this.hass.locale,this.hass.config);const c=(0,g.ZQ)(n,r)??{maximumFractionDigits:2},y=`${(0,g.ZV)(l,this.hass.locale,c)}${a}`;h.push({time:0===h.length?d:void 0,color:String(o.color??""),seriesName:o.seriesName,value:y})}return 0===h.length?o.s6:o.qy`${h.map((t,e)=>o.qy`${t.time?o.qy`${t.time}<br>`:o.s6}<ha-chart-tooltip-marker .color="${t.color}"></ha-chart-tooltip-marker> ${t.seriesName}: ${t.value}${e<h.length-1?o.qy`<br>`:o.s6}`)}`},this._getStatisticsMetaData=(0,r.A)(async t=>{const e=await(0,f.Wr)(this.hass,t),i={};return e.forEach(t=>{i[t.statistic_id]=t}),i}),this._formatYAxisLabel=t=>(0,g.ZV)(t,this.hass.locale,{maximumFractionDigits:this._yAxisFractionDigits})}}L.styles=o.AH`:host{display:block;min-height:60px}.info{text-align:center;line-height:60px;color:var(--secondary-text-color)}`,(0,a.Cg)([(0,h.MZ)({attribute:!1})],L.prototype,"hass",void 0),(0,a.Cg)([(0,h.MZ)({attribute:!1})],L.prototype,"statisticsData",void 0),(0,a.Cg)([(0,h.MZ)({attribute:!1})],L.prototype,"metadata",void 0),(0,a.Cg)([(0,h.MZ)({attribute:!1})],L.prototype,"names",void 0),(0,a.Cg)([(0,h.MZ)({attribute:!1})],L.prototype,"colors",void 0),(0,a.Cg)([(0,h.MZ)()],L.prototype,"unit",void 0),(0,a.Cg)([(0,h.MZ)({attribute:!1})],L.prototype,"startTime",void 0),(0,a.Cg)([(0,h.MZ)({attribute:!1})],L.prototype,"endTime",void 0),(0,a.Cg)([(0,h.MZ)({attribute:!1})],L.prototype,"statTypes",void 0),(0,a.Cg)([(0,h.MZ)({attribute:!1})],L.prototype,"chartType",void 0),(0,a.Cg)([(0,h.MZ)({attribute:!1})],L.prototype,"minYAxis",void 0),(0,a.Cg)([(0,h.MZ)({attribute:!1})],L.prototype,"maxYAxis",void 0),(0,a.Cg)([(0,h.MZ)({attribute:"fit-y-data",type:Boolean})],L.prototype,"fitYData",void 0),(0,a.Cg)([(0,h.MZ)({attribute:"hide-legend",type:Boolean})],L.prototype,"hideLegend",void 0),(0,a.Cg)([(0,h.MZ)({attribute:"logarithmic-scale",type:Boolean})],L.prototype,"logarithmicScale",void 0),(0,a.Cg)([(0,h.MZ)({attribute:"is-loading-data",type:Boolean})],L.prototype,"isLoadingData",void 0),(0,a.Cg)([(0,h.MZ)({attribute:"click-for-more-info",type:Boolean})],L.prototype,"clickForMoreInfo",void 0),(0,a.Cg)([(0,h.MZ)()],L.prototype,"period",void 0),(0,a.Cg)([(0,h.MZ)({attribute:"days-to-show",type:Number})],L.prototype,"daysToShow",void 0),(0,a.Cg)([(0,h.MZ)({type:String})],L.prototype,"height",void 0),(0,a.Cg)([(0,h.MZ)({attribute:"expand-legend",type:Boolean})],L.prototype,"expandLegend",void 0),(0,a.Cg)([(0,h.wk)()],L.prototype,"_chartData",void 0),(0,a.Cg)([(0,h.wk)()],L.prototype,"_legendData",void 0),(0,a.Cg)([(0,h.wk)()],L.prototype,"_statisticIds",void 0),(0,a.Cg)([(0,h.wk)()],L.prototype,"_chartOptions",void 0),(0,a.Cg)([(0,h.wk)()],L.prototype,"_hiddenStats",void 0),L=(0,a.Cg)([(0,h.EM)("statistics-chart")],L),s()}catch(t){s(t)}})},45100(t,e,i){i.a(t,async function(t,s){try{i.r(e),i.d(e,{HaIconButtonPrev:()=>p});var a=i(62826),o=i(5124),h=i(22441),n=i(63091),r=i(26300),l=t([r]);r=(l.then?(await l)():l)[0];const d="M15.41,16.58L10.83,12L15.41,7.41L14,6L8,12L14,18L15.41,16.58Z",c="M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z";class p extends o.WF{render(){return o.qy` <ha-icon-button .disabled="${this.disabled}" .label="${this.label||this.hass?.localize("ui.common.back")||"Back"}" .path="${this._icon}" .href="${this.href}" .target="${this.target}" .rel="${this.rel}" .download="${this.download}"></ha-icon-button> `}constructor(...t){super(...t),this.disabled=!1,this._icon="rtl"===n.G.document.dir?c:d}}(0,a.Cg)([(0,h.MZ)({attribute:!1})],p.prototype,"hass",void 0),(0,a.Cg)([(0,h.MZ)({type:Boolean})],p.prototype,"disabled",void 0),(0,a.Cg)([(0,h.MZ)()],p.prototype,"label",void 0),(0,a.Cg)([(0,h.MZ)()],p.prototype,"href",void 0),(0,a.Cg)([(0,h.MZ)()],p.prototype,"target",void 0),(0,a.Cg)([(0,h.MZ)()],p.prototype,"rel",void 0),(0,a.Cg)([(0,h.MZ)()],p.prototype,"download",void 0),(0,a.Cg)([(0,h.wk)()],p.prototype,"_icon",void 0),p=(0,a.Cg)([(0,h.EM)("ha-icon-button-prev")],p),s()}catch(t){s(t)}})}};