UNPKG

iobroker.lovelace

Version:

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

1 lines 9.86 kB
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[66471],{90433:function(t,e,a){a.d(e,{Vy:function(){return n},fI:function(){return i},ux:function(){return c}});var s=a(22786),r=a(79468);const o=54;function n(t,e){const a=t%o+1;return e.getPropertyValue(`--color-${a}`)}function i(t,e){const a=e.getPropertyValue(`--graph-color-${t+1}`)||n(t,e);return(0,r.RQ)(a)}const c=(0,s.A)(t=>Array.from({length:o},(e,a)=>i(a,t)),(t,e)=>t[0].getPropertyValue("--graph-color-1")===e[0].getPropertyValue("--graph-color-1")&&t[0].getPropertyValue("--color-1")===e[0].getPropertyValue("--color-1"))},89938:function(t,e,a){function s(t,e){const a=e-t;return!Number.isFinite(a)||a<=0?1:Math.max(0,Math.ceil(-Math.log10(a/10)))}a.d(e,{G:function(){return s}})},54706:function(t,e,a){a.d(e,{E:function(){return o}});a(74423),a(18111),a(13579),a(3362),a(62953);var s=a(40445),r=a(67576);const o=t=>{class e extends t{connectedCallback(){super.connectedCallback(),this._checkSubscribed()}disconnectedCallback(){if(super.disconnectedCallback(),this.__unsubs){for(;this.__unsubs.length;){const t=this.__unsubs.pop();t instanceof Promise?t.then(t=>t()):t()}this.__unsubs=void 0}}updated(t){if(super.updated(t),t.has("hass"))this._checkSubscribed();else if(this.hassSubscribeRequiredHostProps)for(const e of t.keys())if(this.hassSubscribeRequiredHostProps.includes(e))return void this._checkSubscribed()}hassSubscribe(){return[]}_checkSubscribed(){var t;void 0!==this.__unsubs||!this.isConnected||void 0===this.hass||null!==(t=this.hassSubscribeRequiredHostProps)&&void 0!==t&&t.some(t=>void 0===this[t])||(this.__unsubs=this.hassSubscribe())}}return(0,s.Cg)([(0,r.MZ)({attribute:!1})],e.prototype,"hass",void 0),e}},40235:function(t,e,a){a.a(t,async function(t,s){try{a.r(e),a.d(e,{HuiPowerSourcesGraphCard:function(){return x}});a(44114),a(72712),a(18111),a(7588),a(61701),a(18237),a(13579),a(3362),a(62953);var r=a(40445),o=a(73684),n=a(83309),i=a(40600),c=a(81859),h=a(5124),u=a(67576),l=a(6412),d=a(22786),p=a(79144),g=a(44439),f=a(89938),_=(a(76776),a(38114)),y=a(54706),b=a(784),v=a(97372),m=a(79468),w=t([g,_,v]);[g,_,v]=w.then?(await w)():w;let k,D,S,$,C=t=>t;class x extends((0,y.E)(h.WF)){static async getConfigElement(){return await a.e(79062).then(a.bind(a,54197)),document.createElement("hui-energy-graph-card-editor")}static getStubConfig(t,e,a){return{type:"power-sources-graph"}}hassSubscribe(){var t;return[(0,_.tb)(this.hass,{key:null===(t=this._config)||void 0===t?void 0:t.collection_key}).subscribe(t=>this._getStatistics(t))]}getCardSize(){return 3}setConfig(t){t.collection_key&&(0,_.s8)(t.collection_key),this._config=t}shouldUpdate(t){return(0,b.xP)(this,t)||t.size>1||!t.has("hass")}render(){return this.hass&&this._config?(0,h.qy)(k||(k=C` <ha-card> ${0} <div class="content ${0}"> <ha-chart-base .hass="${0}" .data="${0}" .options="${0}"></ha-chart-base> ${0} </div> </ha-card> `),this._config.title?(0,h.qy)(D||(D=C`<h1 class="card-header">${0}</h1>`),this._config.title):"",(0,l.H)({"has-header":!!this._config.title}),this.hass,this._chartData,this._createOptions(this._start,this._end,this.hass.locale,this.hass.config,this._compareStart,this._compareEnd,this._legendData,this._yAxisFractionDigits),this._chartData.some(t=>t.data.length)?h.s6:(0,h.qy)(S||(S=C`<div class="no-data"> ${0} </div>`),(0,o.c)(this._start)?this.hass.localize("ui.panel.lovelace.cards.energy.no_data"):this.hass.localize("ui.panel.lovelace.cards.energy.no_data_period"))):h.s6}async _getStatistics(t){var e;const a=[];this._legendData=[];const s={solar:{stats:[],color:"--energy-solar-color",name:this.hass.localize("ui.panel.lovelace.cards.energy.power_graph.solar")},grid:{stats:[],color:"--energy-grid-consumption-color",name:this.hass.localize("ui.panel.lovelace.cards.energy.power_graph.grid")},battery:{stats:[],color:"--energy-battery-out-color",name:this.hass.localize("ui.panel.lovelace.cards.energy.power_graph.battery")}},r=getComputedStyle(this);let o=1/0,c=-1/0;const h=t=>{t<o&&(o=t),t>c&&(c=t)};for(const n of t.prefs.energy_sources)"solar"!==n.type?"battery"!==n.type?"grid"===n.type&&n.stat_rate&&s.grid.stats.push(n.stat_rate):n.stat_rate&&s.battery.stats.push(n.stat_rate):n.stat_rate&&s.solar.stats.push(n.stat_rate);const u={type:"line",smooth:.4,lineStyle:{width:1}},l=Date.now();Object.keys(s).forEach((e,o)=>{if(s[e].stats.length){const i=r.getPropertyValue(s[e].color),c=(0,m.xp)(i),{positive:d,negative:g}=this._processData(s[e].stats.map(e=>{var a;const s=null!==(a=t.stats[e])&&void 0!==a?a:[];if((0,n.r)(l,this._start)&&(0,n.r)(l,this._end)){const t=(0,_.h4)(this.hass.states[e]);void 0!==t&&s.push({start:l,end:l,mean:t/1e3})}return s}),h);a.push(Object.assign(Object.assign({},u),{},{id:e,name:s[e].name,color:i,stack:"positive",areaStyle:{color:new p.W(0,0,0,1,[{offset:0,color:`rgba(${c[0]}, ${c[1]}, ${c[2]}, 0.75)`},{offset:1,color:`rgba(${c[0]}, ${c[1]}, ${c[2]}, 0.25)`}])},data:d,z:3-o})),"solar"!==e&&a.push(Object.assign(Object.assign({},u),{},{id:`${e}-negative`,name:s[e].name,color:i,stack:"negative",areaStyle:{color:new p.W(0,1,0,0,[{offset:0,color:`rgba(${c[0]}, ${c[1]}, ${c[2]}, 0.75)`},{offset:1,color:`rgba(${c[0]}, ${c[1]}, ${c[2]}, 0.25)`}])},data:g,z:4-o})),this._legendData.push({id:e,secondaryIds:"solar"!==e?[`${e}-negative`]:[],name:s[e].name,itemStyle:{color:`rgba(${c[0]}, ${c[1]}, ${c[2]}, 0.75)`,borderColor:i}})}}),this._start=t.start,this._end=t.end||(0,i.o)(),this._chartData=(0,v.JR)(a),this._yAxisFractionDigits=(0,f.G)(o,c);const d=[];null===(e=this._chartData[0])||void 0===e||e.data.forEach((t,e)=>{const a="object"==typeof t&&"value"in t?t.value[0]:t[0];let s=0;this._chartData.forEach(t=>{const a="object"==typeof t.data[e]&&"value"in t.data[e]?t.data[e].value[1]:t.data[e][1];s+=a}),d[e]=[a,Math.max(0,s)]}),this._chartData.push(Object.assign(Object.assign({},u),{},{id:"usage",name:this.hass.localize("ui.panel.lovelace.cards.energy.power_graph.usage"),color:r.getPropertyValue("--primary-text-color"),lineStyle:{type:[7,2],width:1.5},data:d,z:5})),this._legendData.push({id:"usage",name:this.hass.localize("ui.panel.lovelace.cards.energy.power_graph.usage"),itemStyle:{color:r.getPropertyValue("--primary-text-color")}})}_processData(t,e){const a={};t.forEach(t=>{t.forEach(t=>{var e;if(null==t.mean)return;const s=(t.start+t.end)/2;a[s]=[...null!==(e=a[s])&&void 0!==e?e:[],t.mean]})});const s=[],r=[];return Object.entries(a).forEach(([t,a])=>{const o=Number(t),n=a.reduce((t,e)=>t+e,0),i=Math.max(0,n),c=Math.min(0,n);s.push([o,i]),r.push([o,c]),e(i),e(c)}),{positive:s,negative:r}}constructor(...t){super(...t),this._chartData=[],this._yAxisFractionDigits=1,this._start=(0,c.R)(),this._end=(0,i.o)(),this.hassSubscribeRequiredHostProps=["_config"],this._createOptions=(0,d.A)((t,e,a,s,r,o,n,i)=>{var c;return Object.assign(Object.assign({},(0,v.od)(t,e,a,s,"kW",r,o,void 0,!0,i)),{},{legend:{show:!1!==(null===(c=this._config)||void 0===c?void 0:c.show_legend),type:"custom",data:n}})})}}x.styles=(0,h.AH)($||($=C`ha-card{height:100%}.card-header{padding-bottom:0}.content{padding:var(--ha-space-4)}.has-header{padding-top:0}.no-data{position:absolute;height:100%;top:0;left:0;right:0;display:flex;justify-content:center;align-items:center;padding:20%;margin-left:var(--ha-space-8);margin-inline-start:var(--ha-space-8);margin-inline-end:initial;box-sizing:border-box}`)),(0,r.Cg)([(0,u.MZ)({attribute:!1})],x.prototype,"hass",void 0),(0,r.Cg)([(0,u.wk)()],x.prototype,"_config",void 0),(0,r.Cg)([(0,u.wk)()],x.prototype,"_chartData",void 0),(0,r.Cg)([(0,u.wk)()],x.prototype,"_yAxisFractionDigits",void 0),(0,r.Cg)([(0,u.wk)()],x.prototype,"_legendData",void 0),(0,r.Cg)([(0,u.wk)()],x.prototype,"_start",void 0),(0,r.Cg)([(0,u.wk)()],x.prototype,"_end",void 0),(0,r.Cg)([(0,u.wk)()],x.prototype,"_compareStart",void 0),(0,r.Cg)([(0,u.wk)()],x.prototype,"_compareEnd",void 0),x=(0,r.Cg)([(0,u.EM)("hui-power-sources-graph-card")],x),s()}catch(k){s(k)}})},79144:function(t,e,a){a.d(e,{W:function(){return v.A},default:function(){return r}});var s=a(88648),r=a(79501),o=a(33156),n=a(93275),i=a(73836),c=a(93084),h=a(69913),u=a(85136),l=a(19795),d=a(89516),p=a(11826),g=a(17966),f=a(70255),_=a(83276),y=a(67797),b=a(39378),v=a(67665),m=(a(62953),a(33810));const w=m.A.prototype.filterData;m.A.prototype.filterData=function(t,e){if("boundaryFilter"!==t.get("filterMode"))return void w.call(this,t,e);if(!this.hostedBy(t))return;const a=this._dimName,s=this._window.value,r=this.getTargetSeriesModels();for(const o of r){const t=o.getData(),e=t.mapDimensionsAll(a);if(!e.length)continue;const r=t.getStore(),n=t.getDimensionIndex(e[0]),i=t.count();let c=-1,h=-1;for(let a=0;a<i;a++){const t=r.get(n,a);isNaN(t)||(t<s[0]?c=a:t>s[1]&&-1===h&&(h=a))}t.filterSelf(t=>{if(t===c||t===h)return!0;const e=r.get(n,t);return!isNaN(e)&&e>=s[0]&&e<=s[1]});for(const a of e)t.setApproximateExtent(s,a)}},s.Y([o.a,n.a,i.a,c.a,h.a,u.a,l.a,d.a,p.a,g.a,_._,y.i,b.a,f.a])},43382:function(t,e,a){a.d(e,{A:function(){return r}});var s=a(73420);function r(t){return(0,s.w)(t,Date.now())}},6116:function(t,e,a){a.d(e,{o:function(){return o}});var s=a(6439),r=a(83339);function o(t,e,a){const o=(0,r.b)(t,e)/6e4;return(0,s.u)(null==a?void 0:a.roundingMethod)(o)}},40600:function(t,e,a){a.d(e,{o:function(){return r}});var s=a(73983);function r(t){return(0,s.D)(Date.now(),t)}},83309:function(t,e,a){a.d(e,{r:function(){return o}});a(62953);var s=a(74816),r=a(35932);function o(t,e,a){const[o,n]=(0,s.x)(null==a?void 0:a.in,t,e);return+(0,r.o)(o)===+(0,r.o)(n)}},73684:function(t,e,a){a.d(e,{c:function(){return n}});var s=a(73420),r=a(43382),o=a(83309);function n(t,e){return(0,o.r)((0,s.w)((null==e?void 0:e.in)||t,t),(0,r.A)((null==e?void 0:e.in)||t))}},81859:function(t,e,a){a.d(e,{R:function(){return r}});var s=a(35932);function r(t){return(0,s.o)(Date.now(),t)}}}]);