UNPKG

iobroker.lovelace

Version:

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

2 lines 17 kB
export const __webpack_ids__=["63697"];export const __webpack_modules__={50875:function(t,e,s){s.d(e,{Eu:()=>o,hZ:()=>r,o9:()=>c});var i=s(27486),a=s(11259);const n=["#4269d0","#f4bd4a","#ff725c","#6cc5b0","#a463f2","#ff8ab7","#9c6b4e","#97bbf5","#01ab63","#9498a0","#094bad","#c99000","#d84f3e","#49a28f","#048732","#d96895","#8043ce","#7599d1","#7a4c31","#74787f","#6989f4","#ffd444","#ff957c","#8fe9d3","#62cc71","#ffadda","#c884ff","#badeff","#bf8b6d","#b6bac2","#927acc","#97ee3f","#bf3947","#9f5b00","#f48758","#8caed6","#f2b94f","#eff26e","#e43872","#d9b100","#9d7a00","#698cff","#d9d9d9","#00d27e","#d06800","#009f82","#c49200","#cbe8ff","#fecddf","#c27eb6","#8cd2ce","#c4b8d9","#f883b0","#a49100","#f48800","#27d0df","#a04a9b"];function o(t){return n[t%n.length]}function r(t,e){const s=e.getPropertyValue(`--graph-color-${t+1}`)||o(t);return(0,a.Rq)(s)}const c=(0,i.Z)((t=>n.map(((e,s)=>r(s,t)))),((t,e)=>t[0].getPropertyValue("--graph-color-1")===e[0].getPropertyValue("--graph-color-1")))},68958:function(t,e,s){s.d(e,{t:()=>n});s(92745),s(9359),s(31526),s(88972);class i{constructor(t=window.localStorage){this.storage=void 0,this._storage={},this._listeners={},this.storage=t,t===window.localStorage&&window.addEventListener("storage",(t=>{t.key&&this.hasKey(t.key)&&(this._storage[t.key]=t.newValue?JSON.parse(t.newValue):t.newValue,this._listeners[t.key]&&this._listeners[t.key].forEach((e=>e(t.oldValue?JSON.parse(t.oldValue):t.oldValue,this._storage[t.key]))))}))}addFromStorage(t){if(!this._storage[t]){const e=this.storage.getItem(t);e&&(this._storage[t]=JSON.parse(e))}}subscribeChanges(t,e){return this._listeners[t]?this._listeners[t].push(e):this._listeners[t]=[e],()=>{this.unsubscribeChanges(t,e)}}unsubscribeChanges(t,e){if(!(t in this._listeners))return;const s=this._listeners[t].indexOf(e);-1!==s&&this._listeners[t].splice(s,1)}hasKey(t){return t in this._storage}getValue(t){return this._storage[t]}setValue(t,e){const s=this._storage[t];this._storage[t]=e;try{void 0===e?this.storage.removeItem(t):this.storage.setItem(t,JSON.stringify(e))}catch(t){}finally{this._listeners[t]&&this._listeners[t].forEach((t=>t(s,e)))}}}const a={},n=t=>e=>{const s=t.storage||"localStorage";let n;s&&s in a?n=a[s]:(n=new i(window[s]),a[s]=n);const o=String(e.key),r=t.key||String(e.key),c=e.initializer?e.initializer():void 0;n.addFromStorage(r);const d=!1!==t.subscribe?t=>n.subscribeChanges(r,((s,i)=>{t.requestUpdate(e.key,s)})):void 0,u=()=>n.hasKey(r)?t.deserializer?t.deserializer(n.getValue(r)):n.getValue(r):c;return{kind:"method",placement:"prototype",key:e.key,descriptor:{set(s){((s,i)=>{let a;t.state&&(a=u()),n.setValue(r,t.serializer?t.serializer(i):i),t.state&&s.requestUpdate(e.key,a)})(this,s)},get:()=>u(),enumerable:!0,configurable:!0},finisher(s){if(t.state&&t.subscribe){const t=s.prototype.connectedCallback,e=s.prototype.disconnectedCallback;s.prototype.connectedCallback=function(){t.call(this),this[`__unbsubLocalStorage${o}`]=d?.(this)},s.prototype.disconnectedCallback=function(){e.call(this),this[`__unbsubLocalStorage${o}`]?.(),this[`__unbsubLocalStorage${o}`]=void 0}}t.state&&s.createProperty(e.key,{noAccessor:!0,...t.stateOptions})}}}},17705:function(t,e,s){s.d(e,{Cj:()=>h,F7:()=>a,Hs:()=>C,Kd:()=>v,Kj:()=>f,Nw:()=>m,PA:()=>n,Py:()=>c,Qm:()=>$,Z0:()=>y,_Y:()=>u,_m:()=>o,dL:()=>d,dO:()=>S,hN:()=>_,h_:()=>l,j2:()=>k,q6:()=>p,uR:()=>r});s(9359),s(52924);var i=s(47194);let a=function(t){return t[t.NONE=0]="NONE",t[t.ARITHMETIC=1]="ARITHMETIC",t[t.CIRCULAR=2]="CIRCULAR",t}({});const n=99387==s.j?["entity_not_recorded","entity_no_longer_recorded","state_class_removed","units_changed","mean_type_changed","no_state"]:null,o=t=>t.sendMessagePromise({type:"recorder/info"}),r=(t,e)=>t.callWS({type:"recorder/list_statistic_ids",statistic_type:e}),c=(t,e)=>t.callWS({type:"recorder/get_statistics_metadata",statistic_ids:e}),d=(t,e,s,i,a="hour",n,o)=>t.callWS({type:"recorder/statistics_during_period",start_time:e.toISOString(),end_time:s?.toISOString(),statistic_ids:i,period:a,units:n,types:o}),u=(t,e,s,i)=>t.callWS({type:"recorder/statistic_during_period",statistic_id:e,units:i,fixed_period:s.fixed_period?{start_time:s.fixed_period.start instanceof Date?s.fixed_period.start.toISOString():s.fixed_period.start,end_time:s.fixed_period.end instanceof Date?s.fixed_period.end.toISOString():s.fixed_period.end}:void 0,calendar:s.calendar,rolling_window:s.rolling_window}),l=t=>t.callWS({type:"recorder/validate_statistics"}),h=(t,e,s)=>t.callWS({type:"recorder/update_statistics_metadata",statistic_id:e,unit_of_measurement:s}),_=(t,e)=>t.callWS({type:"recorder/clear_statistics",statistic_ids:e}),f=t=>{let e=null;if(!t)return null;for(const s of t)null!==s.change&&void 0!==s.change&&(null===e?e=s.change:e+=s.change);return e},p=(t,e)=>{let s=null;for(const i of e){if(!(i in t))continue;const e=f(t[i]);null!==e&&(null===s?s=e:s+=e)}return s},m=(t,e)=>t.some((t=>void 0!==t[e]&&null!==t[e])),b=["mean","min","max"],g=["sum","state","change"],y=(t,e)=>!(!b.includes(e)||t.mean_type===a.NONE)||!(!g.includes(e)||!t.has_sum),k=(t,e,s,i,a)=>{const n=new Date(s).toISOString();return t.callWS({type:"recorder/adjust_sum_statistics",statistic_id:e,start_time:n,adjustment:i,adjustment_unit_of_measurement:a})},v=(t,e,s)=>{const a=t.states[e];return a?(0,i.C)(a):s?.name||e},S=(t,e,s)=>{let i;return e&&(i=t.states[e]?.attributes.unit_of_measurement),void 0===i?s?.statistics_unit_of_measurement:i},C=t=>t.includes(":"),$=t=>t.callWS({type:"recorder/update_statistics_issues"})},6736:function(t,e,s){s.d(e,{f:()=>o});var i=s(44249),a=s(72621),n=(s(9359),s(52924),s(15093));const o=t=>(0,i.Z)(null,(function(t,e){class s extends e{constructor(...e){super(...e),t(this)}}return{F:s,d:[{kind:"field",decorators:[(0,n.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",key:"hassSubscribeRequiredHostProps",value:void 0},{kind:"field",key:"__unsubs",value:void 0},{kind:"method",key:"connectedCallback",value:function(){(0,a.Z)(s,"connectedCallback",this,3)([]),this._checkSubscribed()}},{kind:"method",key:"disconnectedCallback",value:function(){if((0,a.Z)(s,"disconnectedCallback",this,3)([]),this.__unsubs){for(;this.__unsubs.length;){const t=this.__unsubs.pop();t instanceof Promise?t.then((t=>t())):t()}this.__unsubs=void 0}}},{kind:"method",key:"updated",value:function(t){if((0,a.Z)(s,"updated",this,3)([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()}},{kind:"method",key:"hassSubscribe",value:function(){return[]}},{kind:"method",key:"_checkSubscribed",value:function(){void 0===this.__unsubs&&this.isConnected&&void 0!==this.hass&&!this.hassSubscribeRequiredHostProps?.some((t=>void 0===this[t]))&&(this.__unsubs=this.hassSubscribe())}}]}}),t)},20548:function(t,e,s){s.d(e,{H:()=>n});var i=s(11259),a=s(4643);function n(t,e,s,n,o,r){const c=t.getPropertyValue(o+"-"+r).trim(),d=c.length>0?c:t.getPropertyValue(o).trim();let u=(0,i.Rq)(d);return 0===c.length&&r&&(u=(0,i.CO)((0,i.p3)(e?(0,a.C)((0,i.Rw)((0,i.wK)(u)),r):(0,a.W)((0,i.Rw)((0,i.wK)(u)),r)))),n?u+=s?"32":"7F":s&&(u+="7F"),u}},53259:function(t,e,s){s.a(t,(async function(t,i){try{s.d(e,{J:()=>k,MC:()=>g,Zx:()=>S,b4:()=>y,kT:()=>C});s(92745),s(9359),s(56475),s(31526),s(70104),s(92519),s(42179),s(89256),s(24931),s(88463),s(57449),s(19814);var a=s(21893),n=s(13809),o=s(38836),r=s(84775),c=s(80951),d=s(13730),u=s(6542),l=s(83204),h=s(23459),_=s(23711),f=s(50602),p=s(46467),m=s(33570),b=t([p,m,f]);function g(t,e){let s=new Date(e);return t>2&&0===s.getHours()&&(s=(0,a.b)(s,1)),s.setMinutes(0,0,0),t>35&&s.setDate(1),t>2&&s.setHours(0),s.getTime()}function y(t){return t>35?"month":t>2?"day":"hour"}function k(t,e,s,i,a,o,r,c){const d=(0,n.j)(e,t),u=void 0!==o&&void 0!==r;return{xAxis:{type:"time",min:t,max:g(d,e)},yAxis:{type:"value",name:a,nameGap:2,nameTextStyle:{align:"left"},axisLabel:{formatter:t=>(0,f.uf)(Math.abs(t),s)},splitLine:{show:!0}},grid:{top:15,bottom:0,left:1,right:1,containLabel:!0},tooltip:{trigger:"axis",formatter:t=>{if(Array.isArray(t)){const e=[],n=[];return t.forEach((t=>{t.seriesId?.startsWith("compare-")?n.push(t):e.push(t)})),[e,n].map((t=>v(t,s,i,d,u,a,c))).filter(Boolean).join("<br><br>")}return v([t],s,i,d,u,a,c)}}}}function v(t,e,s,i,a,n,r){if(!t[0]?.value)return"";const c=new Date(t[0].value?.[2]??t[0].value?.[0]);let d;d=i>89?`${(0,p.NC)(c,e,s)}`:i>0?`${(0,p.ud)(c,e,s)}`:`${a?`${(0,p.ud)(c,e,s)}: `:""}${(0,m.mr)(c,e,s)}${(0,m.mr)((0,o.T)(c,1),e,s)}`;const u=`<h4 style="text-align: center; margin: 0;">${d}</h4>`;let l=0,h=0,_=0,b=0;const g=t.map((t=>{const s=t.value?.[1],i=(0,f.uf)(s,e);return"0"!==i&&("bar"===t.componentSubType&&(s>0?(l+=s,h++):(_+=s,b++)),`${t.marker} ${t.seriesName}: ${i} ${n}`)})).filter(Boolean);let y="";return 0!==l&&h>1&&r&&(y+=`<br><b>${r(l)}</b>`),0!==_&&b>1&&r&&(y+=`<br><b>${r(_)}</b>`),g.length>0?`${u}${g.join("<br>")}${y}`:""}function S(t){Array.from(new Set(t.map((t=>t.data.map((t=>Number(t[0]))))).flat())).sort(((t,e)=>t-e)).forEach(((e,s)=>{const i={},a={};for(let n=t.length-1;n>=0;n--){const o=t[n].data[s],r=o&&"object"==typeof o&&"value"in o?o:{value:o},c=r.value?.[0],d=t[n].stack??"";void 0!==c&&(Number(c)!==e?t[n].data?.splice(s,0,{value:[e,0],itemStyle:{borderWidth:0}}):0===r.value?.[1]?t[n].data[s]={...r,itemStyle:{...r.itemStyle,borderWidth:0}}:!i[d]&&r.value?.[1]>0?(t[n].data[s]={...r,itemStyle:{...r.itemStyle,borderRadius:[4,4,0,0]}},i[d]=!0):!a[d]&&r.value?.[1]<0&&(t[n].data[s]={...r,itemStyle:{...r.itemStyle,borderRadius:[0,0,4,4]}},a[d]=!0))}}))}function C(t,e){if(!e)return t=>t;const s=(0,r.o)(t,e);if(0!==s&&t.getTime()===(0,c.e)(t).getTime())return t=>(0,d.B)(t,s);const i=(0,u.d)(t,e);if(0!==i&&t.getTime()===(0,l.N)(t).getTime())return t=>(0,h.z)(t,i);const a=t.getTime()-e.getTime();return t=>(0,_.n)(t,a)}[p,m,f]=b.then?(await b)():b,i()}catch($){i($)}}))},36681:function(t,e,s){s.a(t,(async function(t,i){try{s.r(e),s.d(e,{HuiEnergyDevicesDetailGraphCard:()=>C});var a=s(44249),n=(s(92745),s(9359),s(56475),s(1331),s(31526),s(70104),s(48136),s(42625)),o=s(83389),r=s(57243),c=s(15093),d=s(35359),u=s(27486),l=s(50875),h=s(20548),_=(s(54977),s(25179)),f=s(1118),p=s(17705),m=s(6736),b=s(93331),g=s(53259),y=s(68958),k=s(50602),v=t([_,k,f,g]);[_,k,f,g]=v.then?(await v)():v;const S="kWh";let C=(0,a.Z)([(0,c.Mo)("hui-energy-devices-detail-graph-card")],(function(t,e){return{F:class extends e{constructor(...e){super(...e),t(this)}},d:[{kind:"field",decorators:[(0,c.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,c.SB)()],key:"_config",value:void 0},{kind:"field",decorators:[(0,c.SB)()],key:"_chartData",value:()=>[]},{kind:"field",decorators:[(0,c.SB)()],key:"_data",value:void 0},{kind:"field",decorators:[(0,c.SB)()],key:"_start",value:()=>(0,n.I)()},{kind:"field",decorators:[(0,c.SB)()],key:"_end",value:()=>(0,o.p)()},{kind:"field",decorators:[(0,c.SB)()],key:"_compareStart",value:void 0},{kind:"field",decorators:[(0,c.SB)()],key:"_compareEnd",value:void 0},{kind:"field",decorators:[(0,y.t)({key:"energy-devices-hidden-stats",state:!0,subscribe:!1})],key:"_hiddenStats",value:()=>[]},{kind:"field",key:"hassSubscribeRequiredHostProps",value:()=>["_config"]},{kind:"method",key:"hassSubscribe",value:function(){return[(0,f.UB)(this.hass,{key:this._config?.collection_key}).subscribe((t=>{this._data=t,this._processStatistics()}))]}},{kind:"method",key:"getCardSize",value:function(){return 3}},{kind:"method",key:"setConfig",value:function(t){this._config=t}},{kind:"method",key:"shouldUpdate",value:function(t){return(0,b.SN)(this,t)||t.size>1||!t.has("hass")}},{kind:"method",key:"willUpdate",value:function(t){(t.has("_hiddenStats")||t.has("_config"))&&this._data&&this._processStatistics()}},{kind:"method",key:"render",value:function(){return this.hass&&this._config?r.dy` <ha-card> ${this._config.title?r.dy`<h1 class="card-header">${this._config.title}</h1>`:""} <div class="content ${(0,d.$)({"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,S,this._compareStart,this._compareEnd)}" @dataset-hidden="${this._datasetHidden}" @dataset-unhidden="${this._datasetUnhidden}"></ha-chart-base> </div> </ha-card> `:r.Ld}},{kind:"field",key:"_formatTotal",value(){return t=>this.hass.localize("ui.panel.lovelace.cards.energy.energy_usage_graph.total_consumed",{num:(0,k.uf)(t,this.hass.locale),unit:S})}},{kind:"method",key:"_datasetHidden",value:function(t){this._hiddenStats=[...this._hiddenStats,t.detail.name]}},{kind:"method",key:"_datasetUnhidden",value:function(t){this._hiddenStats=this._hiddenStats.filter((e=>e!==t.detail.name))}},{kind:"field",key:"_createOptions",value(){return(0,u.Z)(((t,e,s,i,a,n,o)=>({...(0,g.J)(t,e,s,i,a,n,o,this._formatTotal),legend:{show:!0,type:"scroll",animationDurationUpdate:400,selected:this._hiddenStats.reduce(((t,e)=>(t[e]=!1,t)),{}),icon:"circle"},grid:{top:15,bottom:0,left:1,right:1,containLabel:!0}})))}},{kind:"method",key:"_processStatistics",value:function(){const t=this._data;this._start=t.start,this._end=t.end||(0,o.p)(),this._compareStart=t.startCompare,this._compareEnd=t.endCompare;const e=t.stats,s=t.statsCompare,i=getComputedStyle(this),a=t.prefs.device_consumption,n={};a.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,p.Kj)(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 u=[],{summedData:l,compareSummedData:h}=(0,f.EH)(t),_="from_grid"in l||"solar"in l||"from_battery"in l,{consumption:m,compareConsumption:b}=_?(0,f.E4)(l,h):{consumption:void 0,compareConsumption:void 0};if(s){const e=this._processDataSet(i,s,t.statsMetadata,t.prefs.device_consumption,d,n,!0);if(u.push(...e),_){const t=this._processUntracked(i,e,b,!0);u.push(t)}}u.push({id:"compare-placeholder",type:"bar",stack:t.statsCompare?"devicesCompare":"devices",data:[]});const y=this._processDataSet(i,e,t.statsMetadata,t.prefs.device_consumption,d,n);if(u.push(...y),_){const t=this._processUntracked(i,y,m,!1);u.push(t)}(0,g.Zx)(u),this._chartData=u}},{kind:"method",key:"_processUntracked",value:function(t,e,s,i){const a={};e.forEach((t=>{t.data.forEach((t=>{a[t[i?2:0]]=(a[t[i?2:0]]||0)+t[1]}))}));const n=(0,g.kT)(this._start,this._compareStart),o=[];Object.keys(s.total).sort(((t,e)=>Number(t)-Number(e))).forEach((t=>{const e=Number(t),r=[e,s.total[t]-(a[t]||0)];i&&(r[2]=r[0],r[0]=n(new Date(e)).getTime()),o.push(r)}));const r=Date.now();return{type:"bar",cursor:"default",id:i?`compare-untracked-${r}`:`untracked-${r}`,name:this.hass.localize("ui.panel.lovelace.cards.energy.energy_devices_detail_graph.untracked_consumption"),itemStyle:{borderColor:(0,h.H)(t,this.hass.themes.darkMode,!1,i,"--state-unavailable-color")},barMaxWidth:50,color:(0,h.H)(t,this.hass.themes.darkMode,!0,i,"--state-unavailable-color"),data:o,stack:i?"devicesCompare":"devices"}}},{kind:"method",key:"_processDataSet",value:function(t,e,s,i,a,n,o=!1){const r=[],c=(0,g.kT)(this._start,this._compareStart);return i.forEach(((i,d)=>{const u=a.indexOf(i.stat_consumption);if(this._config?.max_devices&&u>=this._config.max_devices)return void console.warn(`Max devices exceeded for ${i.name} (${u} >= ${this._config.max_devices})`);const h=(0,l.hZ)(d,t);let _=null;const f=[];if(i.stat_consumption in e){const t=e[i.stat_consumption];for(const s of t){if(null===s.change||void 0===s.change||0===s.change)continue;if(_===s.start)continue;let t=0;(n[i.stat_consumption]||[]).forEach((i=>{const a=e[i];t+=a?.find((t=>t.start===s.start))?.change||0}));const a=[s.start,s.change-t];o&&(a[2]=a[0],a[0]=c(new Date(s.start)).getTime()),f.push(a),_=s.start}}const m=(i.name||(0,p.Kd)(this.hass,i.stat_consumption,s[i.stat_consumption]))+(i.stat_consumption in n?` (${this.hass.localize("ui.panel.lovelace.cards.energy.energy_devices_detail_graph.untracked")})`:"");r.push({type:"bar",cursor:"default",id:o?`compare-${i.stat_consumption}-${u}`:`${i.stat_consumption}-${u}`,name:m,itemStyle:{borderColor:o?h+"7F":h},barMaxWidth:50,color:o?h+"32":h+"7F",data:f,stack:o?"devicesCompare":"devices"})})),a.map((t=>r.find((e=>this._getStatIdFromId(e.id)===t)))).filter(Boolean)}},{kind:"method",key:"_getStatIdFromId",value:function(t){return t.replace(/^compare-/,"").replace(/-\d+$/,"")}},{kind:"field",static:!0,key:"styles",value:()=>r.iv`.card-header{padding-bottom:0}.content{padding:16px}.has-header{padding-top:0}`}]}}),(0,m.f)(r.oi));i()}catch(t){i(t)}}))}}; //# sourceMappingURL=63697.972fc98a47185a83.js.map