iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 9.31 kB
JavaScript
export const __rspack_esm_id=76285;export const __rspack_esm_ids=[76285];export const __webpack_modules__={90433(t,e,s){s.d(e,{Vy:()=>o,fI:()=>i,ux:()=>n});var a=s(22786),r=s(79468);function o(t,e){const s=t%54+1;return e.getPropertyValue(`--color-${s}`)}function i(t,e){const s=e.getPropertyValue(`--graph-color-${t+1}`)||o(t,e);return(0,r.RQ)(s)}const n=(0,a.A)(t=>Array.from({length:54},(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(t,e,s){function a(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:()=>a})},54706(t,e,s){s.d(e,{E:()=>o});s(74423),s(18111),s(13579);var a=s(62826),r=s(22441);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(){void 0===this.__unsubs&&this.isConnected&&void 0!==this.hass&&!this.hassSubscribeRequiredHostProps?.some(t=>void 0===this[t])&&(this.__unsubs=this.hassSubscribe())}}return(0,a.Cg)([(0,r.MZ)({attribute:!1})],e.prototype,"hass",void 0),e}},18427(t,e,s){s.d(e,{g:()=>o});var a=s(79468),r=s(39274);function o(t,e,s,o,i,n){const c=t.getPropertyValue(i+"-"+n).trim(),h=c.length>0?c:t.getPropertyValue(i).trim();let l=(0,a.RQ)(h);return 0===c.length&&n&&(l=(0,a.v2)((0,a.BE)(e?(0,r.T)((0,a.Nc)((0,a.xp)(l)),n):(0,r.d)((0,a.Nc)((0,a.xp)(l)),n)))),o?l+=s?"32":"7F":s&&(l+="7F"),l}},40345(t,e,s){s.a(t,async function(t,e){try{var a=s(62826),r=s(5124),o=s(22441),i=s(34127),n=t([i]);i=(n.then?(await n)():n)[0];class c extends r.WF{render(){const t=`energy-graph-chip-${Date.now()}`;return r.qy` <div class="chip" id="${t}"> <slot></slot> </div> <ha-tooltip for="${t}" placement="top">${this.tooltip}</ha-tooltip> `}}c.styles=r.AH`.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,a.Cg)([(0,o.MZ)({type:String})],c.prototype,"tooltip",void 0),c=(0,a.Cg)([(0,o.EM)("hui-energy-graph-chip")],c),e()}catch(t){e(t)}})},32185(t,e,s){s.a(t,async function(t,a){try{s.r(e),s.d(e,{HuiEnergySolarGraphCard:()=>x});s(44114),s(18111),s(22489),s(7588),s(61701),s(18237),s(13579);var r=s(62826),o=s(73684),i=s(40600),n=s(81859),c=s(5124),h=s(22441),l=s(6412),d=s(22786),p=s(18427),u=s(20058),_=s(44439),g=s(89938),y=(s(76776),s(38114)),f=s(23528),m=s(54706),b=s(784),v=s(97372),k=s(40345),C=s(34127),S=t([_,k,C,y,u,v]);[_,k,C,y,u,v]=S.then?(await S)():S;class x 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(){return[(0,y.tb)(this.hass,{key:this._config?.collection_key}).subscribe(t=>this._getStatistics(t))]}getCardSize(){return 3}setConfig(t){t.collection_key&&(0,y.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?c.qy` <ha-card> ${this._config.title?c.qy` <div class="card-header"> <span>${this._config.title}</span> ${this._total?c.qy`<hui-energy-graph-chip .tooltip="${this._formatTotal(this._total)}"> ${(0,u.ZV)(this._total,this.hass.locale)} kWh </hui-energy-graph-chip>`:c.s6} </div>`:c.s6} <div class="content ${(0,l.H)({"has-header":!!this._config.title})}"> <ha-chart-base .hass="${this.hass}" .data="${this._chartData}" .options="${this._createOptions(this._start,this._end,this.hass.locale,this.hass.config,this._compareStart,this._compareEnd,this._yAxisFractionDigits)}" chart-type="bar"></ha-chart-base> ${this._chartData.length?"":c.qy`<div class="no-data"> ${(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")} </div>`} </div> </ha-card> `:c.s6}async _getStatistics(t){this._start=t.start,this._end=t.end||(0,i.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=>t.config_entry_solar_forecast?.length))try{s=await(0,y.al)(this.hass)}catch(t){}const a=[],r=getComputedStyle(this);let o=1/0,n=-1/0;const c=t=>{t<o&&(o=t),t>n&&(n=t)};if(t.statsCompare)a.push(...this._processDataSet(t.statsCompare,t.statsMetadata,e,r,c,!0));else{const t=e[0]?.stat_energy_from??"placeholder";a.push({id:"compare-"+t,type:"bar",stack:"solar",data:[]})}a.push(...this._processDataSet(t.stats,t.statsMetadata,e,r,c)),(0,v.RR)(a),s&&a.push(...this._processForecast(t.statsMetadata,s,e,r.getPropertyValue("--primary-text-color"),t.start,t.end,c)),this._yAxisFractionDigits=(0,g.G)(o,n),this._chartData=a,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,a,r,o=!1){const i=[],n=(0,v.ok)(this._start,this._compareStart),c=(0,y.TI)(this._start,this._end);return s.forEach((s,h)=>{let l=null;const d=[];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(l===t.start)continue;const e=[(0,v.IJ)(t.start,t.end,c,o?n:void 0),t.change,t.start];d.push(e),r(t.change),l=t.start}}i.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,f.$O)(this.hass,s.stat_energy_from,e[s.stat_energy_from])}),barMaxWidth:50,itemStyle:{borderColor:(0,p.g)(a,this.hass.themes.darkMode,!1,o,"--energy-solar-color",h)},color:(0,p.g)(a,this.hass.themes.darkMode,!0,o,"--energy-solar-color",h),data:d,stack:o?"compare":"solar"})}),i}_processForecast(t,e,s,a,r,o,i){const n=[],c=(0,y.TI)(r,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<r||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 a=s.getTime();a in h?h[a]+=e:h[a]=e})}),h){const e=[];let r=0;if("hour"===c||"5minute"===c){const t=Object.keys(h).map(Number).sort((t,e)=>t-e);r=t.length>=2?(t[1]-t[0])/2:0}for(const[t,s]of Object.entries(h)){const a=s/1e3;e.push([Number(t)+r,a]),i(a)}e.length&&n.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,f.$O)(this.hass,s.stat_energy_from,t[s.stat_energy_from])}),step:!1,color:a,lineStyle:{type:[7,5],width:1.5},symbol:"none",data:e})}}}),n}constructor(...t){super(...t),this._chartData=[],this._yAxisFractionDigits=1,this._start=(0,n.R)(),this._end=(0,i.o)(),this.hassSubscribeRequiredHostProps=["_config"],this._formatTotal=t=>this.hass.localize("ui.panel.lovelace.cards.energy.energy_solar_graph.total_produced",{num:(0,u.ZV)(t,this.hass.locale)}),this._createOptions=(0,d.A)((t,e,s,a,r,o,i)=>(0,v.od)(t,e,s,a,"kWh",r,o,this._formatTotal,!1,i))}}x.styles=c.AH`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,r.Cg)([(0,h.MZ)({attribute:!1})],x.prototype,"hass",void 0),(0,r.Cg)([(0,h.wk)()],x.prototype,"_config",void 0),(0,r.Cg)([(0,h.wk)()],x.prototype,"_chartData",void 0),(0,r.Cg)([(0,h.wk)()],x.prototype,"_yAxisFractionDigits",void 0),(0,r.Cg)([(0,h.wk)()],x.prototype,"_start",void 0),(0,r.Cg)([(0,h.wk)()],x.prototype,"_end",void 0),(0,r.Cg)([(0,h.wk)()],x.prototype,"_compareStart",void 0),(0,r.Cg)([(0,h.wk)()],x.prototype,"_compareEnd",void 0),(0,r.Cg)([(0,h.wk)()],x.prototype,"_total",void 0),x=(0,r.Cg)([(0,h.EM)("hui-energy-solar-graph-card")],x),a()}catch(t){a(t)}})},43382(t,e,s){s.d(e,{A:()=>r});var a=s(73420);function r(t){return(0,a.w)(t,Date.now())}},6116(t,e,s){s.d(e,{o:()=>o});var a=s(6439),r=s(83339);function o(t,e,s){const o=(0,r.b)(t,e)/6e4;return(0,a.u)(s?.roundingMethod)(o)}},40600(t,e,s){s.d(e,{o:()=>r});var a=s(73983);function r(t){return(0,a.D)(Date.now(),t)}},83309(t,e,s){s.d(e,{r:()=>o});var a=s(74816),r=s(35932);function o(t,e,s){const[o,i]=(0,a.x)(s?.in,t,e);return+(0,r.o)(o)===+(0,r.o)(i)}},73684(t,e,s){s.d(e,{c:()=>i});var a=s(73420),r=s(43382),o=s(83309);function i(t,e){return(0,o.r)((0,a.w)(e?.in||t,t),(0,r.A)(e?.in||t))}},81859(t,e,s){s.d(e,{R:()=>r});var a=s(35932);function r(t){return(0,a.o)(Date.now(),t)}}};