iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 9.94 kB
JavaScript
export const __rspack_esm_id=39565;export const __rspack_esm_ids=[39565];export const __webpack_modules__={90433(t,e,s){s.d(e,{Vy:()=>i,fI:()=>r,ux:()=>n});var a=s(22786),o=s(79468);function i(t,e){const s=t%54+1;return e.getPropertyValue(`--color-${s}`)}function r(t,e){const s=e.getPropertyValue(`--graph-color-${t+1}`)||i(t,e);return(0,o.RQ)(s)}const n=(0,a.A)(t=>Array.from({length:54},(e,s)=>r(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:()=>i});s(74423),s(18111),s(13579);var a=s(62826),o=s(22441);const i=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,o.MZ)({attribute:!1})],e.prototype,"hass",void 0),e}},18427(t,e,s){s.d(e,{g:()=>i});var a=s(79468),o=s(39274);function i(t,e,s,i,r,n){const c=t.getPropertyValue(r+"-"+n).trim(),d=c.length>0?c:t.getPropertyValue(r).trim();let h=(0,a.RQ)(d);return 0===c.length&&n&&(h=(0,a.v2)((0,a.BE)(e?(0,o.T)((0,a.Nc)((0,a.xp)(h)),n):(0,o.d)((0,a.Nc)((0,a.xp)(h)),n)))),i?h+=s?"32":"7F":s&&(h+="7F"),h}},71209(t,e,s){s.a(t,async function(t,a){try{s.r(e),s.d(e,{HuiEnergyDevicesDetailGraphCard:()=>D});s(74423),s(44114),s(18111),s(22489),s(20116),s(7588),s(61701),s(18237);var o=s(62826),i=s(40600),r=s(81859),n=s(5124),c=s(22441),d=s(6412),h=s(22786),u=s(90433),p=s(18427),_=(s(76776),s(44439)),l=s(89938),m=s(38114),g=s(23528),f=s(1087),b=s(54706),y=s(784),v=s(97372),k=s(93905),S=s(20058),C=t([_,m,S,v]);[_,m,S,v]=C.then?(await C)():C;const $="kWh";class D extends((0,b.E)(n.WF)){static async getConfigElement(){return await s.e(88899).then(s.bind(s,2670)),document.createElement("hui-energy-devices-card-editor")}static getStubConfig(t,e,s){return{type:"energy-devices-detail-graph"}}hassSubscribe(){return[(0,m.tb)(this.hass,{key:this._config?.collection_key}).subscribe(t=>{this._data=t})]}getCardSize(){return 3}setConfig(t){t.collection_key&&(0,m.s8)(t.collection_key),this._config=t}shouldUpdate(t){return(0,y.xP)(this,t)||t.size>1||!t.has("hass")}willUpdate(t){(t.has("_config")||t.has("_data"))&&this._processStatistics()}render(){return this.hass&&this._config?n.qy` <ha-card> ${this._config.title?n.qy`<h1 class="card-header">${this._config.title}</h1>`:""} <div class="content ${(0,d.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,this._legendData)}" click-label-for-more-info -hidden="${this._datasetHidden}" -unhidden="${this._datasetUnhidden}" -label-click="${this._handleLegendLabelClick}"></ha-chart-base> </div> </ha-card> `:n.s6}_datasetHidden(t){this._hiddenStats=[...this._hiddenStats,this._getStatIdFromId(t.detail.id)]}_datasetUnhidden(t){this._hiddenStats=this._hiddenStats.filter(e=>e!==this._getStatIdFromId(t.detail.id))}_handleLegendLabelClick(t){const e=this._getStatIdFromId(t.detail.id);(0,g.OQ)(e)||this.hass.states[e]&&(0,f.r)(this,"hass-more-info",{entityId:e})}_processStatistics(){if(!this._data)return;const t=this._data;this._start=t.start,this._end=t.end||(0,i.o)(),this._compareStart=t.startCompare,this._compareEnd=t.endCompare;const e=t.stats,s=t.statsCompare,a=getComputedStyle(this),o=t.prefs.device_consumption,r={};o.forEach(t=>{t.included_in_stat&&(r[t.included_in_stat]=r[t.included_in_stat]||[],r[t.included_in_stat].push(t.stat_consumption))});const n={};t.prefs.device_consumption.forEach(t=>{const s=t.stat_consumption in e&&(0,g.$j)(e[t.stat_consumption])||0;n[t.stat_consumption]=s});const c={};t.prefs.device_consumption.forEach(t=>{c[t.stat_consumption]=(r[t.stat_consumption]||[]).reduce((t,e)=>t-n[e],n[t.stat_consumption])});const d=t.prefs.device_consumption.map(t=>t.stat_consumption);d.sort((t,e)=>c[e]-c[t]);const h=[];let u=1/0,p=-1/0;const _=t=>{t<u&&(u=t),t>p&&(p=t)},{summedData:f,compareSummedData:b}=(0,m.gv)(t),y="from_grid"in f||"solar"in f||"from_battery"in f,{consumption:k,compareConsumption:S}=y?(0,m.DR)(f,b):{consumption:void 0,compareConsumption:void 0};if(s){const e=this._processDataSet(a,s,t.statsMetadata,t.prefs.device_consumption,d,r,_,!0);if(h.push(...e),y){const t=this._processUntracked(a,e,S,_,!0);h.push(t)}}h.push({id:"compare-placeholder",type:"bar",stack:t.statsCompare?"devicesCompare":"devices",data:[]});const C=this._processDataSet(a,e,t.statsMetadata,t.prefs.device_consumption,d,r,_);if(h.push(...C),this._legendData=C.map(t=>{const e=this._getStatIdFromId(t.id);return{id:t.id,secondaryIds:[`compare-${t.id}`],name:t.name,itemStyle:{color:t.color,borderColor:t.itemStyle?.borderColor},noLabelClick:(0,g.OQ)(e)||!this.hass.states[e]}}),y){const t=this._processUntracked(a,C,k,_,!1);h.push(t),this._legendData.push({id:t.id,secondaryIds:[`compare-${t.id}`],name:t.name,itemStyle:{color:t.color,borderColor:t.itemStyle?.borderColor},noLabelClick:!0})}(0,v.RR)(h),this._yAxisFractionDigits=(0,l.G)(u,p),this._chartData=h}_processUntracked(t,e,s,a,o){const i={};e.forEach(t=>{t.data.forEach(t=>{i[t[2]]=(i[t[2]]||0)+t[1]})});const r=(0,v.ok)(this._start,this._compareStart),n=(0,m.TI)(this._start,this._end),c=[],d=Object.keys(s.used_total).sort((t,e)=>Number(t)-Number(e)),h=("hour"===n||"5minute"===n)&&d.length>=2?(Number(d[1])-Number(d[0]))/2:0;d.forEach(t=>{const e=Number(t),n=s.used_total[t]-(i[t]||0),d=[e+h,n,e];o&&(d[0]=r(new Date(e)).getTime()+h),c.push(d),a(n)});const u=Date.now();return{type:"bar",cursor:"default",id:o?`compare-untracked-${u}`:`untracked-${u}`,name:this.hass.localize("ui.panel.lovelace.cards.energy.energy_devices_detail_graph.untracked_consumption"),itemStyle:{borderColor:(0,p.g)(t,this.hass.themes.darkMode,!1,o,"--history-unknown-color")},barMaxWidth:50,color:(0,p.g)(t,this.hass.themes.darkMode,!0,o,"--history-unknown-color"),data:c,stack:o?"devicesCompare":"devices"}}_processDataSet(t,e,s,a,o,i,r,n=!1){const c=[],d=(0,v.ok)(this._start,this._compareStart),h=(0,m.TI)(this._start,this._end);return a.forEach((a,p)=>{const _=o.indexOf(a.stat_consumption);if(this._config?.max_devices&&_>=this._config.max_devices)return void console.warn(`Max devices exceeded for ${a.name} (${_} >= ${this._config.max_devices})`);const l=(0,u.fI)(p,t);let m=null;const f=[];if(a.stat_consumption in e){const t=e[a.stat_consumption];for(const s of t){if(null===s.change||void 0===s.change||0===s.change)continue;if(m===s.start)continue;let t=0;(i[a.stat_consumption]||[]).forEach(a=>{const o=e[a];t+=o?.find(t=>t.start===s.start)?.change||0});const o=s.change-t,c=[(0,v.IJ)(s.start,s.end,h,n?d:void 0),o,s.start];f.push(c),r(o),m=s.start}}const b=(a.name||(0,g.$O)(this.hass,a.stat_consumption,s[a.stat_consumption]))+(a.stat_consumption in i?` (${this.hass.localize("ui.panel.lovelace.cards.energy.energy_devices_detail_graph.untracked")})`:"");c.push({type:"bar",cursor:"default",id:n?`compare-${a.stat_consumption}-${_}`:`${a.stat_consumption}-${_}`,name:b,itemStyle:{borderColor:n?l+"7F":l},barMaxWidth:50,color:n?l+"32":l+"7F",data:f,stack:n?"devicesCompare":"devices"})}),o.map(t=>c.find(e=>this._getStatIdFromId(e.id)===t)).filter(Boolean)}_getStatIdFromId(t){return t.replace(/^compare-/,"").replace(/-\d+$/,"")}constructor(...t){super(...t),this._chartData=[],this._yAxisFractionDigits=1,this._start=(0,r.R)(),this._end=(0,i.o)(),this._hiddenStats=[],this.hassSubscribeRequiredHostProps=["_config"],this._formatTotal=t=>this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.total_consumed",{num:(0,S.ZV)(t,this.hass.locale),unit:$}),this._createOptions=(0,h.A)((t,e,s,a,o,i,r,n,c)=>{const d=(0,v.od)(t,e,s,a,o,i,r,this._formatTotal,!1,n),h=c?c.filter(t=>t.id&&this._hiddenStats.includes(this._getStatIdFromId(t.id))).reduce((t,e)=>(t[e.id]=!1,t),{}):{};return{...d,legend:{show:!0,type:"custom",data:c,selected:h},grid:{top:15,bottom:0,left:1,right:1,containLabel:!0}}})}}D.styles=n.AH`.card-header{padding-bottom:0}.content{padding:16px}.has-header{padding-top:0}`,(0,o.Cg)([(0,c.MZ)({attribute:!1})],D.prototype,"hass",void 0),(0,o.Cg)([(0,c.wk)()],D.prototype,"_config",void 0),(0,o.Cg)([(0,c.wk)()],D.prototype,"_chartData",void 0),(0,o.Cg)([(0,c.wk)()],D.prototype,"_yAxisFractionDigits",void 0),(0,o.Cg)([(0,c.wk)()],D.prototype,"_data",void 0),(0,o.Cg)([(0,c.wk)()],D.prototype,"_legendData",void 0),(0,o.Cg)([(0,c.wk)()],D.prototype,"_start",void 0),(0,o.Cg)([(0,c.wk)()],D.prototype,"_end",void 0),(0,o.Cg)([(0,c.wk)()],D.prototype,"_compareStart",void 0),(0,o.Cg)([(0,c.wk)()],D.prototype,"_compareEnd",void 0),(0,o.Cg)([(0,c.wk)(),(0,k.I)({key:"energy-devices-hidden-stats",state:!0,subscribe:!1})],D.prototype,"_hiddenStats",void 0),D=(0,o.Cg)([(0,c.EM)("hui-energy-devices-detail-graph-card")],D),a()}catch(t){a(t)}})},6116(t,e,s){s.d(e,{o:()=>i});var a=s(6439),o=s(83339);function i(t,e,s){const i=(0,o.b)(t,e)/6e4;return(0,a.u)(s?.roundingMethod)(i)}},40600(t,e,s){s.d(e,{o:()=>o});var a=s(73983);function o(t){return(0,a.D)(Date.now(),t)}},81859(t,e,s){s.d(e,{R:()=>o});var a=s(35932);function o(t){return(0,a.o)(Date.now(),t)}}};