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