UNPKG

iobroker.lovelace

Version:

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

1 lines 10.1 kB
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[76285],{90433:function(t,e,s){s.d(e,{Vy:function(){return n},fI:function(){return i},ux:function(){return c}});var r=s(22786),a=s(79468);const o=54;function n(t,e){const s=t%o+1;return e.getPropertyValue(`--color-${s}`)}function i(t,e){const s=e.getPropertyValue(`--graph-color-${t+1}`)||n(t,e);return(0,a.RQ)(s)}const c=(0,r.A)(t=>Array.from({length:o},(e,s)=>i(s,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,s){function r(t,e){const s=e-t;return!Number.isFinite(s)||s<=0?1:Math.max(0,Math.ceil(-Math.log10(s/10)))}s.d(e,{G:function(){return r}})},54706:function(t,e,s){s.d(e,{E:function(){return o}});s(74423),s(18111),s(13579),s(3362),s(62953);var r=s(40445),a=s(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,r.Cg)([(0,a.MZ)({attribute:!1})],e.prototype,"hass",void 0),e}},18427:function(t,e,s){s.d(e,{g:function(){return o}});s(42762);var r=s(79468),a=s(39274);function o(t,e,s,o,n,i){const c=t.getPropertyValue(n+"-"+i).trim(),h=c.length>0?c:t.getPropertyValue(n).trim();let u=(0,r.RQ)(h);return 0===c.length&&i&&(u=(0,r.v2)((0,r.BE)(e?(0,a.T)((0,r.Nc)((0,r.xp)(u)),i):(0,a.d)((0,r.Nc)((0,r.xp)(u)),i)))),o?u+=s?"32":"7F":s&&(u+="7F"),u}},40345:function(t,e,s){s.a(t,async function(t,e){try{var r=s(40445),a=s(5124),o=s(67576),n=s(34127),i=t([n]);n=(i.then?(await i)():i)[0];let c,h,u=t=>t;class l extends a.WF{render(){const t=`energy-graph-chip-${Date.now()}`;return(0,a.qy)(c||(c=u` <div class="chip" id="${0}"> <slot></slot> </div> <ha-tooltip for="${0}" placement="top">${0}</ha-tooltip> `),t,t,this.tooltip)}}l.styles=(0,a.AH)(h||(h=u`.chip{font-size:var(--ha-font-size-m);font-weight:var(--ha-font-weight-medium);padding:var(--ha-space-1) var(--ha-space-2);border-radius:var(--ha-border-radius-md);border:1px solid var(--divider-color)}`)),(0,r.Cg)([(0,o.MZ)({type:String})],l.prototype,"tooltip",void 0),l=(0,r.Cg)([(0,o.EM)("hui-energy-graph-chip")],l),e()}catch(c){e(c)}})},32185:function(t,e,s){s.a(t,async function(t,r){try{s.r(e),s.d(e,{HuiEnergySolarGraphCard:function(){return P}});s(44114),s(72712),s(26910),s(18111),s(22489),s(7588),s(61701),s(18237),s(13579),s(3362),s(62953);var a=s(40445),o=s(73684),n=s(40600),i=s(81859),c=s(5124),h=s(67576),u=s(6412),l=s(22786),d=s(18427),p=s(20058),g=s(44439),_=s(89938),f=(s(76776),s(38114)),y=s(23528),m=s(54706),v=s(784),b=s(97372),k=s(40345),C=s(34127),S=t([g,k,C,f,y,p,b]);[g,k,C,f,y,p,b]=S.then?(await S)():S;let w,x,D,$,M,E=t=>t;class P extends((0,m.E)(c.WF)){static async getConfigElement(){return await s.e(79062).then(s.bind(s,54197)),document.createElement("hui-energy-graph-card-editor")}static getStubConfig(t,e,s){return{type:"energy-solar-graph"}}hassSubscribe(){var t;return[(0,f.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,f.s8)(t.collection_key),this._config=t}shouldUpdate(t){return(0,v.xP)(this,t)||t.size>1||!t.has("hass")}render(){return this.hass&&this._config?(0,c.qy)(w||(w=E` <ha-card> ${0} <div class="content ${0}"> <ha-chart-base .hass="${0}" .data="${0}" .options="${0}" chart-type="bar"></ha-chart-base> ${0} </div> </ha-card> `),this._config.title?(0,c.qy)(x||(x=E` <div class="card-header"> <span>${0}</span> ${0} </div>`),this._config.title,this._total?(0,c.qy)(D||(D=E`<hui-energy-graph-chip .tooltip="${0}"> ${0} kWh </hui-energy-graph-chip>`),this._formatTotal(this._total),(0,p.ZV)(this._total,this.hass.locale)):c.s6):c.s6,(0,u.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._yAxisFractionDigits),this._chartData.length?"":(0,c.qy)($||($=E`<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"))):c.s6}async _getStatistics(t){this._start=t.start,this._end=t.end||(0,n.o)(),this._compareStart=t.startCompare,this._compareEnd=t.endCompare;const e=t.prefs.energy_sources.filter(t=>"solar"===t.type);let s;if(e.some(t=>{var e;return null===(e=t.config_entry_solar_forecast)||void 0===e?void 0:e.length}))try{s=await(0,f.al)(this.hass)}catch(l){}const r=[],a=getComputedStyle(this);let o=1/0,i=-1/0;const c=t=>{t<o&&(o=t),t>i&&(i=t)};if(t.statsCompare)r.push(...this._processDataSet(t.statsCompare,t.statsMetadata,e,a,c,!0));else{var h,u;const t=null!==(h=null===(u=e[0])||void 0===u?void 0:u.stat_energy_from)&&void 0!==h?h:"placeholder";r.push({id:"compare-"+t,type:"bar",stack:"solar",data:[]})}r.push(...this._processDataSet(t.stats,t.statsMetadata,e,a,c)),(0,b.RR)(r),s&&r.push(...this._processForecast(t.statsMetadata,s,e,a.getPropertyValue("--primary-text-color"),t.start,t.end,c)),this._yAxisFractionDigits=(0,_.G)(o,i),this._chartData=r,this._total=this._processTotal(t.stats,e)}_processTotal(t,e){return e.reduce((e,s)=>e+(s.stat_energy_from in t?t[s.stat_energy_from].reduce((t,e)=>t+(e.change||0),0):0),0)}_processDataSet(t,e,s,r,a,o=!1){const n=[],i=(0,b.ok)(this._start,this._compareStart),c=(0,f.TI)(this._start,this._end);return s.forEach((s,h)=>{let u=null;const l=[];if(s.stat_energy_from in t){const e=t[s.stat_energy_from];for(const t of e){if(null===t.change||void 0===t.change||0===t.change)continue;if(u===t.start)continue;const e=[(0,b.IJ)(t.start,t.end,c,o?i:void 0),t.change,t.start];l.push(e),a(t.change),u=t.start}}n.push({type:"bar",cursor:"default",id:o?"compare-"+s.stat_energy_from:s.stat_energy_from,name:this.hass.localize("ui.panel.lovelace.cards.energy.energy_solar_graph.production",{name:s.name||(0,y.$O)(this.hass,s.stat_energy_from,e[s.stat_energy_from])}),barMaxWidth:50,itemStyle:{borderColor:(0,d.g)(r,this.hass.themes.darkMode,!1,o,"--energy-solar-color",h)},color:(0,d.g)(r,this.hass.themes.darkMode,!0,o,"--energy-solar-color",h),data:l,stack:o?"compare":"solar"})}),n}_processForecast(t,e,s,r,a,o,n){const i=[],c=(0,f.TI)(a,o);return s.forEach(s=>{if(s.config_entry_solar_forecast){const h={};if(s.config_entry_solar_forecast.forEach(t=>{e[t]&&Object.entries(e[t].wh_hours).forEach(([t,e])=>{const s=new Date(t);if(s<a||o&&s>o)return;"month"===c&&s.setDate(1),"month"===c||"day"===c?s.setHours(0,0,0,0):s.setMinutes(0,0,0);const r=s.getTime();r in h?h[r]+=e:h[r]=e})}),h){const e=[];let a=0;if("hour"===c||"5minute"===c){const t=Object.keys(h).map(Number).sort((t,e)=>t-e);a=t.length>=2?(t[1]-t[0])/2:0}for(const[t,s]of Object.entries(h)){const r=s/1e3;e.push([Number(t)+a,r]),n(r)}e.length&&i.push({id:"forecast-"+s.stat_energy_from,type:"line",stack:"forecast",name:this.hass.localize("ui.panel.lovelace.cards.energy.energy_solar_graph.forecast",{name:s.name||(0,y.$O)(this.hass,s.stat_energy_from,t[s.stat_energy_from])}),step:!1,color:r,lineStyle:{type:[7,5],width:1.5},symbol:"none",data:e})}}}),i}constructor(...t){super(...t),this._chartData=[],this._yAxisFractionDigits=1,this._start=(0,i.R)(),this._end=(0,n.o)(),this.hassSubscribeRequiredHostProps=["_config"],this._formatTotal=t=>this.hass.localize("ui.panel.lovelace.cards.energy.energy_solar_graph.total_produced",{num:(0,p.ZV)(t,this.hass.locale)}),this._createOptions=(0,l.A)((t,e,s,r,a,o,n)=>(0,b.od)(t,e,s,r,"kWh",a,o,this._formatTotal,!1,n))}}P.styles=(0,c.AH)(M||(M=E`ha-card{height:100%}.card-header{display:flex;justify-content:space-between;align-items:center;padding-bottom:0}.content{padding:16px}.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:32px;margin-inline-start:32px;margin-inline-end:initial;box-sizing:border-box}`)),(0,a.Cg)([(0,h.MZ)({attribute:!1})],P.prototype,"hass",void 0),(0,a.Cg)([(0,h.wk)()],P.prototype,"_config",void 0),(0,a.Cg)([(0,h.wk)()],P.prototype,"_chartData",void 0),(0,a.Cg)([(0,h.wk)()],P.prototype,"_yAxisFractionDigits",void 0),(0,a.Cg)([(0,h.wk)()],P.prototype,"_start",void 0),(0,a.Cg)([(0,h.wk)()],P.prototype,"_end",void 0),(0,a.Cg)([(0,h.wk)()],P.prototype,"_compareStart",void 0),(0,a.Cg)([(0,h.wk)()],P.prototype,"_compareEnd",void 0),(0,a.Cg)([(0,h.wk)()],P.prototype,"_total",void 0),P=(0,a.Cg)([(0,h.EM)("hui-energy-solar-graph-card")],P),r()}catch(w){r(w)}})},43382:function(t,e,s){s.d(e,{A:function(){return a}});var r=s(73420);function a(t){return(0,r.w)(t,Date.now())}},6116:function(t,e,s){s.d(e,{o:function(){return o}});var r=s(6439),a=s(83339);function o(t,e,s){const o=(0,a.b)(t,e)/6e4;return(0,r.u)(null==s?void 0:s.roundingMethod)(o)}},40600:function(t,e,s){s.d(e,{o:function(){return a}});var r=s(73983);function a(t){return(0,r.D)(Date.now(),t)}},83309:function(t,e,s){s.d(e,{r:function(){return o}});s(62953);var r=s(74816),a=s(35932);function o(t,e,s){const[o,n]=(0,r.x)(null==s?void 0:s.in,t,e);return+(0,a.o)(o)===+(0,a.o)(n)}},73684:function(t,e,s){s.d(e,{c:function(){return n}});var r=s(73420),a=s(43382),o=s(83309);function n(t,e){return(0,o.r)((0,r.w)((null==e?void 0:e.in)||t,t),(0,a.A)((null==e?void 0:e.in)||t))}},81859:function(t,e,s){s.d(e,{R:function(){return a}});var r=s(35932);function a(t){return(0,r.o)(Date.now(),t)}}}]);