iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 21.9 kB
JavaScript
export const __rspack_esm_id=77183;export const __rspack_esm_ids=[77183];export const __webpack_modules__={91069(t,e,r){r.a(t,async function(t,o){try{r.d(e,{EO:()=>v,Yq:()=>W,_U:()=>E,eE:()=>S,fU:()=>D,ol:()=>b,xo:()=>w});var s=r(78016),n=r(31810),a=r(87950),i=r(81977),c=r(36307),_=r(35932),l=r(73983),u=r(6946),d=r(92913),g=r(83339),m=r(77972),y=r(31886),f=r(46927),p=t([y]);y=(p.then?(await p)():p)[0];const h=(t,e,r,o)=>{const s=r(new y.BB(t,e),o);return s instanceof Date?new Date(s.getTime()):s},b=(t,e,r,o,s)=>r.time_zone===f.Wj.server?h(t,o.time_zone,e,s):e(t,s),w=(t,e,r,o,s)=>r.time_zone===f.Wj.server?h(t,o.time_zone,e,s):e(t,s),v=(t,e,r,o,s)=>w(t,r,o,s,o.time_zone===f.Wj.server?new y.BB(e,s.time_zone):e),S=(t,e,r,o,y)=>{let f,p;if(w(t,s.e,o,y)&&w(e,n.c,o,y)){const s=(v(e,t,a.W,o,y)+1)*(r?1:-1);f=b(t,i.P,o,y,s),p=b(b(e,i.P,o,y,s),c.p,o,y)}else if(w(t,t=>(0,_.o)(t).getMilliseconds()===t.getMilliseconds(),o,y)&&w(e,t=>(0,l.D)(t).getMilliseconds()===t.getMilliseconds(),o,y)){const s=(v(e,t,u.c,o,y)+1)*(r?1:-1);f=b(t,d.f,o,y,s),p=b(e,d.f,o,y,s)}else{const s=v(e,t,g.b,o,y)*(r?1:-1);f=b(t,m.A,o,y,s),p=b(e,m.A,o,y,s)}return{start:f,end:p}},E=(t,e)=>{const r=new y.BB(t,e);return new Date(r.getTime())},W=(t,e)=>new y.BB(t,e).toISOString().split("T")[0],D=(t,e)=>new y.BB(t,e).toISOString().split("T")[1].split(".")[0];o()}catch(t){o(t)}})},46223(t,e,r){r.a(t,async function(t,o){try{r.d(e,{b:()=>v});var s=r(35932),n=r(73983),a=r(92913),i=r(52640),c=r(69137),_=r(35660),l=r(36307),u=r(11650),d=r(15797),g=r(33977),m=r(69748),y=r(55144),f=r(21828),p=r(66708),h=r(91069),b=r(380),w=t([h]);h=(w.then?(await w)():w)[0];const v=(t,e,r)=>{const o=new Date,w=(0,b.P)(t);switch(r){case"today":return[(0,h.ol)(o,s.o,t,e,{weekStartsOn:w}),(0,h.ol)(o,n.D,t,e,{weekStartsOn:w})];case"yesterday":return[(0,h.ol)((0,a.f)(o,-1),s.o,t,e,{weekStartsOn:w}),(0,h.ol)((0,a.f)(o,-1),n.D,t,e,{weekStartsOn:w})];case"this_week":return[(0,h.ol)(o,i.k,t,e,{weekStartsOn:w}),(0,h.ol)(o,c.$,t,e,{weekStartsOn:w})];case"this_month":return[(0,h.ol)(o,_.w,t,e),(0,h.ol)(o,l.p,t,e)];case"this_quarter":return[(0,h.ol)(o,u.a,t,e),(0,h.ol)(o,d.j,t,e)];case"this_year":return[(0,h.ol)(o,g.D,t,e),(0,h.ol)(o,m.Q,t,e)];case"now-7d":return[(0,h.ol)(o,y.e,t,e,7),(0,h.ol)(o,y.e,t,e,0)];case"now-30d":return[(0,h.ol)(o,y.e,t,e,30),(0,h.ol)(o,y.e,t,e,0)];case"now-12m":return[(0,h.ol)(o,t=>(0,f.a)((0,_.w)(t),11),t,e),(0,h.ol)(o,l.p,t,e)];case"now-365d":return[(0,h.ol)(o,y.e,t,e,365),(0,h.ol)(o,y.e,t,e,0)];case"now-1h":return[(0,h.ol)(o,p.O,t,e,1),(0,h.ol)(o,p.O,t,e,0)];case"now-12h":return[(0,h.ol)(o,p.O,t,e,12),(0,h.ol)(o,p.O,t,e,0)];case"now-24h":return[(0,h.ol)(o,p.O,t,e,24),(0,h.ol)(o,p.O,t,e,0)]}return[o,o]};o()}catch(t){o(t)}})},9658(t,e,r){r.d(e,{m:()=>s});const o={T:1e12,G:1e9,M:1e6,k:1e3,m:.001,µ:1e-6,μ:1e-6},s=(t,e)=>{if(!e||e.length<=1)return t;const r=e[0];return r in o?t*o[r]:t}},38114(t,e,r){r.a(t,async function(t,o){try{r.d(e,{AN:()=>z,B2:()=>N,BV:()=>A,DR:()=>ot,E$:()=>R,E_:()=>dt,GW:()=>I,Q4:()=>C,Sp:()=>lt,TI:()=>yt,WN:()=>L,X4:()=>tt,_d:()=>Q,al:()=>Y,bs:()=>B,c:()=>j,gv:()=>et,h4:()=>gt,h_:()=>ft,lh:()=>O,mn:()=>ut,n3:()=>at,oU:()=>U,pe:()=>it,s8:()=>k,t5:()=>mt,tb:()=>J,uh:()=>T});r(74423),r(44114),r(18111),r(81148),r(22489),r(7588),r(61701),r(17642),r(58004),r(33853),r(45876),r(32475),r(15024),r(31698),r(14603),r(47566),r(98721);var s=r(6946),n=r(78016),a=r(31810),i=r(81977),c=r(87950),_=r(92913),l=r(77972),u=r(56434),d=r(35932),g=r(73983),m=r(57279),y=r(35518),f=r(22786),p=r(91069),h=r(46223),b=r(30162),w=r(20058),v=r(9658),S=r(5911),E=r(30039),W=r(23528),D=t([b,h,p,w]);[b,h,p,w]=D.then?(await D)():D;const x="energy_",M=new Set;function k(t){if(!t?.startsWith(x))throw new Error(`Collection keys must start with ${x}.`)}const T=()=>({type:"grid",stat_energy_from:null,stat_energy_to:null,stat_cost:null,stat_compensation:null,entity_energy_price:null,number_energy_price:null,entity_energy_price_export:null,number_energy_price_export:null,cost_adjustment_day:0}),C=()=>({type:"solar",stat_energy_from:"",config_entry_solar_forecast:null}),U=()=>({type:"battery",stat_energy_from:"",stat_energy_to:""}),j=()=>({type:"gas",stat_energy_from:"",stat_cost:null,entity_energy_price:null,number_energy_price:null}),I=()=>({type:"water",stat_energy_from:"",stat_cost:null,entity_energy_price:null,number_energy_price:null}),A=t=>t.callWS({type:"energy/info"}),N=async t=>(await t.loadBackendTranslation("issues","energy"),t.callWS({type:"energy/validate"})),B=t=>t.callWS({type:"energy/get_prefs"}),L=async(t,e)=>{const r=t.callWS({type:"energy/save_prefs",...e});return V(t),r},P=async(t,e,r,o,s,n="hour")=>t.callWS({type:"energy/fossil_energy_consumption",start_time:e.toISOString(),end_time:s?.toISOString(),energy_statistic_ids:r,co2_statistic_id:o,period:n}),R=t=>(0,S.$)(t.energy_sources,t=>t.type),z=(t,e,r)=>{const o=[];for(const s of t.energy_sources)if(!r||r.includes(s.type))if("solar"!==s.type){if("gas"===s.type||"water"===s.type){o.push(s.stat_energy_from),s.stat_cost&&o.push(s.stat_cost);const t=e.cost_sensors[s.stat_energy_from];t&&o.push(t);continue}if("battery"!==s.type){if(s.stat_energy_from){o.push(s.stat_energy_from),s.stat_cost&&o.push(s.stat_cost);const t=e.cost_sensors[s.stat_energy_from];t&&o.push(t)}if(s.stat_energy_to){o.push(s.stat_energy_to),s.stat_compensation&&o.push(s.stat_compensation);const t=e.cost_sensors[s.stat_energy_to];t&&o.push(t)}}else o.push(s.stat_energy_from),o.push(s.stat_energy_to)}else o.push(s.stat_energy_from);return r&&!r.includes("device")||o.push(...t.device_consumption.map(t=>t.stat_consumption)),r&&!r.includes("water")||o.push(...t.device_consumption_water.map(t=>t.stat_consumption)),o},$=t=>{const e=[];for(const r of t.energy_sources)"gas"!==r.type&&"water"!==r.type?"solar"!==r.type?(r.type,r.stat_rate&&e.push(r.stat_rate)):e.push(r.stat_rate):r.stat_rate&&e.push(r.stat_rate);return e.push(...t.device_consumption.map(t=>t.stat_rate)),e.push(...t.device_consumption_water.map(t=>t.stat_rate)),e.filter(Boolean)};var O=function(t){return t.NONE="",t.PREVIOUS="previous",t.YOY="yoy",t}({});const F=async(t,e,r,o,d)=>{const g=await A(t);let m;for(const e of Object.values(t.entities)){if("co2signal"!==e.platform)continue;const r=t.states[e.entity_id];if(r&&"%"===r.attributes.unit_of_measurement){m=r.entity_id;break}}const y=[];for(const t of e.energy_sources)"grid"===t.type&&t.stat_energy_from&&y.push(t.stat_energy_from);const f=z(e,g,["grid","solar","battery","gas","device"]),h=$(e),b=z(e,g,["water"]),w=[...f,...b,...h],v=(0,s.c)(o||new Date,r),S=yt(r,o),E=yt(r,o,!0),D={},O=w.length?await(0,W.Wr)(t,w):[];w.length&&O.forEach(t=>{D[t.statistic_id]=t});const x=X(t,e,D),M={energy:"kWh",volume:W.r_.includes(x)?x:void 0},k={power:"kW"},T=K(t,e,D),C={volume:T},U=f.length?(0,W.sz)(t,r,o,f,S,M,["change"]):{},j=h.length?(0,W.sz)(t,r,o,h,E,k,["mean"]):{},I=h.length&&"5minute"===E?(0,W.sz)(t,r,o,h,"hour",k,["mean"]):{},N=b.length?(0,W.sz)(t,r,o,b,S,C,["change"]):{};let B,L,R,F,V,H={},Z={};d&&("previous"===d?(L=(0,p.xo)(r,n.e,t.locale,t.config)&&(0,p.xo)(o||new Date,a.c,t.locale,t.config)?(0,p.ol)(r,i.P,t.locale,t.config,-(0,p.EO)(o||new Date,r,c.W,t.locale,t.config)-1):(0,p.ol)(r,_.f,t.locale,t.config,-1*(v+1)),R=(0,l.A)(r,-1)):"yoy"===d&&(L=(0,p.ol)(r,u.e,t.locale,t.config,-1),R=(0,p.ol)(o,u.e,t.locale,t.config,-1)),f.length&&(H=(0,W.sz)(t,L,R,f,S,M,["change"])),b.length&&(Z=(0,W.sz)(t,L,R,b,S,C,["change"]))),void 0!==m&&(F=P(t,r,y,m,o,S),d&&(V=P(t,L,y,m,R,S)));const[G,J,Y,q,Q,tt,et,rt]=await Promise.all([U,j,I,N,H,Z,F,V]);Object.keys(Y).length&&h.forEach(t=>{if(t in Y)if(t in J&&J[t].length){const e=J[t][0],r=Y[t];let o=0;for(const t of r){if(t.end>e.start)break;o++}J[t]=[...r.slice(0,o),...J[t]]}else J[t]=Y[t]});d&&(B={...Q,...tt});return{start:r,end:o,startCompare:L,endCompare:R,compareMode:d,info:g,prefs:e,stats:{...G,...q,...J},statsMetadata:D,statsCompare:B,co2SignalEntity:m,fossilEnergyConsumption:et,fossilEnergyConsumptionCompare:rt,waterUnit:T,gasUnit:x}},V=t=>{M.forEach(e=>{const r=G(t,e);r&&(r.clearPrefs(),r.isActive()&&r.refresh())})},H=t=>{if(t._refreshTimeout&&clearTimeout(t._refreshTimeout),t._active&&(!t.end||t.end>new Date)){const e=new Date;e.getMinutes()>=20&&e.setHours(e.getHours()+1),e.setMinutes(20,0,0),t._refreshTimeout=window.setTimeout(()=>t.refresh(),e.getTime()-Date.now())}},Z=(t,e)=>{let r="_energy";if(e)k(e),r=`_${e}`;else if(t.panelUrl){const o=x+t.panelUrl;r=`_${o}`,e=o}return[r,e]},G=(t,e)=>{const[r,o]=Z(t,e);return t.connection[r]},J=(t,e={})=>{const[r,o]=Z(t,e.key);if(t.connection[r])return t.connection[r];M.add(o);const s=(0,y.X)(t.connection,r,async()=>(s.prefs||(s.prefs=await B(t)),H(s),F(t,s.prefs,s.start,s.end,s.compare))),n=s.subscribe;s.subscribe=t=>{const e=n(t);return s._active++,void 0===s._refreshTimeout&&H(s),()=>{s._active--,s._active<1&&(clearTimeout(s._refreshTimeout),s._refreshTimeout=void 0),e()}},s._active=0,s.prefs=e.prefs;const a=new Date,i=(0,b.LW)(a,t.locale,t.config).split(":")[0],c=localStorage.getItem(`energy-default-period-${r}`)||"today",_="today"===c&&"0"===i?"yesterday":c,[l,u]=(0,h.b)(t.locale,t.config,_);s.start=(0,p.ol)(l,d.o,t.locale,t.config),s.end=(0,p.ol)(u,g.D,t.locale,t.config);const f=()=>{s._updatePeriodTimeout=window.setTimeout(()=>{s.start=(0,p.ol)(new Date,d.o,t.locale,t.config),s.end=(0,p.ol)(new Date,g.D,t.locale,t.config),s.refresh(),f()},(0,m.L)((0,p.ol)(new Date,g.D,t.locale,t.config),1).getTime()-Date.now())};return f(),s.isActive=()=>!!s._active,s.clearPrefs=()=>{s.prefs=void 0},s.setPeriod=(e,r)=>{s._updatePeriodTimeout&&(clearTimeout(s._updatePeriodTimeout),s._updatePeriodTimeout=void 0),s.start=e,s.end=r,s.start.getTime()===(0,p.ol)(new Date,d.o,t.locale,t.config).getTime()&&s.end?.getTime()===(0,p.ol)(new Date,g.D,t.locale,t.config).getTime()&&f()},s.setCompare=t=>{s.compare=t},s},Y=t=>t.callWS({type:"energy/solar_forecast"}),q=["volume","energy"],Q=(t,e,r={})=>{for(const o of t.energy_sources){if("gas"!==o.type)continue;if(e&&e===o.stat_energy_from)continue;const t=r[o.stat_energy_from];if(q.includes(t?.unit_class))return t.unit_class}},X=(t,e,r={})=>{if("energy"===Q(e,void 0,r))return"kWh";const o=e.energy_sources.filter(t=>"gas"===t.type).map(e=>(0,W.JE)(t,e.stat_energy_from,r[e.stat_energy_from]));if(o.length){const t=o[0];if(W.r_.includes(t)&&o.every(e=>e===t))return t}return"km"===t.config.unit_system.length?"m³":"ft³"},K=(t,e,r)=>{const o=e.energy_sources.filter(t=>"water"===t.type).map(e=>(0,W.JE)(t,e.stat_energy_from,r[e.stat_energy_from]));if(o.length){const t=o[0];if(W.r_.includes(t)&&o.every(e=>e===t))return t}return"km"===t.config.unit_system.length?"L":"gal"},tt="/docs/energy/faq/#troubleshooting-missing-entities",et=(0,f.A)(t=>({summedData:rt(t),compareSummedData:t.statsCompare?rt(t,!0):void 0})),rt=(t,e)=>{const r={};for(const e of t.prefs.energy_sources)"solar"!==e.type?"battery"!==e.type?"grid"===e.type&&(e.stat_energy_from&&(r.from_grid?r.from_grid.push(e.stat_energy_from):r.from_grid=[e.stat_energy_from]),e.stat_energy_to&&(r.to_grid?r.to_grid.push(e.stat_energy_to):r.to_grid=[e.stat_energy_to])):r.to_battery?(r.to_battery.push(e.stat_energy_to),r.from_battery.push(e.stat_energy_from)):(r.to_battery=[e.stat_energy_to],r.from_battery=[e.stat_energy_from]):r.solar?r.solar.push(e.stat_energy_from):r.solar=[e.stat_energy_from];const o={total:{},timestamps:[]},s=new Set;return Object.entries(r).forEach(([r,n])=>{const a={},i={};let c=0;n.forEach(r=>{const o=e?t.statsCompare[r]:t.stats[r];if(!o)return;o.forEach(t=>{if(null===t.change||void 0===t.change)return;const e=t.change;c+=e,a[t.start]=t.start in a?a[t.start]+e:e,s.add(t.start)}),i[r]={}}),o[r]=a,o.total[r]=c}),o.timestamps=Array.from(s).sort(),o},ot=(0,f.A)((t,e)=>({consumption:st(t),compareConsumption:e?st(e):void 0})),st=t=>{const e={used_total:{},grid_to_battery:{},battery_to_grid:{},solar_to_battery:{},solar_to_grid:{},used_solar:{},used_grid:{},used_battery:{},total:{used_total:0,grid_to_battery:0,battery_to_grid:0,solar_to_battery:0,solar_to_grid:0,used_solar:0,used_grid:0,used_battery:0}};return t.timestamps.forEach(r=>{const{grid_to_battery:o,battery_to_grid:s,used_solar:n,used_grid:a,used_battery:i,used_total:c,solar_to_battery:_,solar_to_grid:l}=nt({from_grid:t.from_grid&&(t.from_grid[r]??0),to_grid:t.to_grid&&(t.to_grid[r]??0),solar:t.solar&&(t.solar[r]??0),to_battery:t.to_battery&&(t.to_battery[r]??0),from_battery:t.from_battery&&(t.from_battery[r]??0)});e.used_total[r]=c,e.total.used_total+=c,e.grid_to_battery[r]=o,e.total.grid_to_battery+=o,e.battery_to_grid[r]=s,e.total.battery_to_grid+=s,e.used_battery[r]=i,e.total.used_battery+=i,e.used_grid[r]=a,e.total.used_grid+=a,e.used_solar[r]=n,e.total.used_solar+=n,e.solar_to_battery[r]=_,e.total.solar_to_battery+=_,e.solar_to_grid[r]=l,e.total.solar_to_grid+=l}),e},nt=t=>{let e=Math.max(t.to_grid||0,0),r=Math.max(t.to_battery||0,0),o=Math.max(t.solar||0,0),s=Math.max(t.from_grid||0,0),n=Math.max(t.from_battery||0,0);const a=(s||0)+(o||0)+(n||0)-(e||0)-(r||0);let i=0,c=Math.max(a,0);const _=Math.max(0,Math.min(r,s-c));i+=_,r-=_,s-=_;const l=Math.min(o,r);r-=l,o-=l;const u=Math.min(o,e);e-=u,o-=u;const d=Math.min(n,e);n-=d;const g=Math.min(s,r);i+=g,s-=g;const m=Math.min(c,o);c-=m;const y=Math.min(n,c);c-=y;return{used_solar:m,used_grid:Math.min(c,s),used_battery:y,used_total:a,grid_to_battery:i,battery_to_grid:d,solar_to_battery:l,solar_to_grid:u}},at=(t,e,r,o)=>{const s=["Wh","kWh","MWh","GWh","TWh"];let n=r,a=e||0,i=-1;o&&(i=s.findIndex(t=>t===o));let c=s.findIndex(t=>t===r);if(c>=0){for(;i>-1?i<c:Math.abs(a)<1&&c>0;)a*=1e3,c--;for(;i>-1?i>c:Math.abs(a)>=1e3&&c<s.length-1;)a/=1e3,c++;n=s[c]}return(0,w.ZV)(a,t.locale,{maximumFractionDigits:Math.abs(a)<10?2:Math.abs(a)<100?1:0})+" "+n},it=(t,e)=>{if(!e.total.solar)return;const{consumption:r,compareConsumption:o}=ot(e,void 0);if(!t){const t=e.total.solar;return r.total.used_solar/t*100}let s=0,n=0;const a=[];e.timestamps.forEach(t=>{s+=r.used_solar[t]??0,n+=r.solar_to_grid[t]??0,r.grid_to_battery[t]&&a.push({type:"grid",value:r.grid_to_battery[t]}),r.solar_to_battery[t]&&a.push({type:"solar",value:r.solar_to_battery[t]});let e=r.battery_to_grid[t]??0,o=r.used_battery[t]??0;const i=function(t){const e=a[a.length-1],r=e.type;if(t>=e.value){const t=e.value;return a.pop(),{energy:t,type:r}}return e.value-=t,{energy:t,type:r}};for(;o>0&&a.length;){const{energy:t,type:e}=i(o);"solar"===e&&(s+=t),o-=t}for(;e>0&&a.length;){const{energy:t,type:r}=i(e);"solar"===r&&(n+=t),e-=t}});const i=s+n;return!!i?s/i*100:void 0},ct=3.785411784,_t={"m³/h":1e3/60,"m³/min":1e3,"m³/s":6e4,"ft³/min":28.316846592,"L/h":1/60,"L/min":1,"L/s":60,"gal/h":ct/60,"gal/min":ct,"gal/d":ct/1440,"mL/s":.06},lt=t=>{if(!t)return;const e=parseFloat(t.state);if(isNaN(e))return;const r=t.attributes.unit_of_measurement,o=r?_t[r]:void 0;return void 0===o?e:e*o},ut=(t,e,r,o)=>{let s;o.clear();let n=0;return e.energy_sources.forEach(e=>{if(e.type!==t||!e.stat_rate)return;const a=e.stat_rate;o.add(a);const i=r[a];if(!i)return;let c=parseFloat(i.state);if(isNaN(c))return;c<0&&(c=0);const _=i.attributes.unit_of_measurement;if(!_)return;if(void 0===s)return s=_,void(n+=c);if(_===s)return void(n+=c);const l=_t[_],u=_t[s];n+=void 0!==l&&void 0!==u?c*l/u:c}),{value:Math.max(0,n),unit:s??""}},dt=(t,e,r)=>{if("km"===e)return`${(0,w.ZV)(r,t,{maximumFractionDigits:1})} L/min`;const o=r/ct;return`${(0,w.ZV)(o,t,{maximumFractionDigits:1})} gal/min`},gt=t=>{if(!t)return;const e=parseFloat(t.state);return isNaN(e)?void 0:(0,v.m)(e,t.attributes.unit_of_measurement)},mt=(t,e)=>{const r=["W","kW","MW","GW","TW"];let o=0,s=e;for(;Math.abs(s)>=1e3&&o<r.length-1;)s/=1e3,o++;return(0,w.ZV)(s,t.locale,{maximumFractionDigits:"W"===r[o]?0:3})+" "+r[o]};function yt(t,e,r=!1){const o=(0,s.c)(e||new Date,t);return r?o>64?"day":o>8?"hour":"5minute":(0,n.e)(t)&&(!e||(0,a.c)(e))&&o>35?"month":o>2?"day":"hour"}const ft=(t,e)=>{const r=J(t,{key:e});if(!r.prefs||!r.state.stats)return;const o=r.state.gasUnit,s="kWh",n=r.prefs.energy_sources,a=r.prefs.device_consumption,i=r.prefs.device_consumption_water,c=r.state.stats,_=new Set;Object.values(c).forEach(t=>{t.forEach(t=>{_.add(t.start)})});const l=Array.from(_).sort(),u="entity_id,type,unit,"+l.map(t=>new Date(t).toISOString()).join(",")+"\n",d=[];d[0]=u;const g=function(t,e,r,o){let s=0;const n=[];n.push(t),n.push(e),n.push(r.normalize("NFKD")),l.forEach(t=>{s<o.length&&o[s].start===t?(n.push((o[s].change??"").toString()),s++):n.push("")}),d.push(n.join(",")+"\n")},m=function(t,e,r){c[t]&&g(t,e,r,c[t])},y=t.config.currency,f=function(t,e,r,o,s){e.length&&(e.forEach(e=>m(e,t,r)),o&&s&&s.forEach(t=>m(t,o,y)))},p=[],h=[],b=[],w=[];n.filter(t=>"grid"===t.type).forEach(t=>{const e=t;if(e.stat_energy_from){p.push(e.stat_energy_from);const t=e.stat_cost||r.state.info.cost_sensors[e.stat_energy_from];t&&b.push(t)}if(e.stat_energy_to){h.push(e.stat_energy_to);const t=e.stat_compensation||r.state.info.cost_sensors[e.stat_energy_to];t&&w.push(t)}}),f("grid_consumption",p,s,"grid_consumption_cost",b),f("grid_return",h,s,"grid_return_compensation",w);const v=[],S=[];n.filter(t=>"battery"===t.type).forEach(t=>{v.push(t.stat_energy_to),S.push(t.stat_energy_from)}),f("battery_in",v,s),f("battery_out",S,s);const W=[];n.filter(t=>"solar"===t.type).forEach(t=>{W.push(t.stat_energy_from)}),f("solar_production",W,s);const D=[],O=[];n.filter(t=>"gas"===t.type).forEach(t=>{const e=t.stat_energy_from;D.push(e);const o=t.stat_cost||r.state.info.cost_sensors[e];o&&O.push(o)}),f("gas_consumption",D,o,"gas_consumption_cost",O);const x=[],M=[];n.filter(t=>"water"===t.type).forEach(t=>{const e=t.stat_energy_from;x.push(e);const o=t.stat_cost||r.state.info.cost_sensors[e];o&&M.push(o)}),f("water_consumption",x,r.state.waterUnit,"water_consumption_cost",M);const k=[];if(a.forEach(t=>{k.push(t.stat_consumption)}),f("device_consumption",k,s),i){const t=[];i.forEach(e=>{t.push(e.stat_consumption)}),f("device_consumption_water",t,r.state.waterUnit)}const{summedData:T}=et(r.state),{consumption:C}=ot(T,void 0),U=function(t,e,r){const o=[];Object.entries(r).forEach(([t,e])=>{o.push({start:Number(t),end:NaN,change:e})}),g("",t,e,o)},j=!!W.length,I=!!v.length,A=!!h.length,N=!!p.length;N&&(U("calculated_consumed_grid",s,C.used_grid),I&&U("calculated_grid_to_battery",s,C.grid_to_battery)),A&&I&&U("calculated_battery_to_grid",s,C.battery_to_grid),I&&U("calculated_consumed_battery",s,C.used_battery),j&&(U("calculated_consumed_solar",s,C.used_solar),I&&U("calculated_solar_to_battery",s,C.solar_to_battery),A&&U("calculated_solar_to_grid",s,C.solar_to_grid)),(N?1:0)+(j?1:0)+(I?1:0)>1&&U("calculated_total_consumption",s,C.used_total);const B=new Blob(d,{type:"text/csv"}),L=window.URL.createObjectURL(B);(0,E.R)(L,"energy.csv")};o()}catch(pt){o(pt)}})},16869(t,e,r){r.d(e,{B:()=>s,g:()=>o});r(74423);const o=window.externalAppV2||window.externalApp||window.webkit?.messageHandlers?.getExternalAuth||location.search.includes("external_auth=1"),s=window.externalApp||window.externalAppV2},23528(t,e,r){r.d(e,{$3:()=>y,$O:()=>E,$j:()=>f,ED:()=>n,JE:()=>W,OQ:()=>D,PU:()=>O,Ph:()=>g,Uf:()=>S,W1:()=>m,Wr:()=>l,Z:()=>c,gF:()=>p,iY:()=>h,jU:()=>a,nN:()=>v,p3:()=>_,pJ:()=>d,r_:()=>i,sz:()=>u});r(74423),r(18111),r(13579);var o=r(28978),s=r(380),n=function(t){return t[t.NONE=0]="NONE",t[t.ARITHMETIC=1]="ARITHMETIC",t[t.CIRCULAR=2]="CIRCULAR",t}({});const a=66649!=r.j?["entity_not_recorded","entity_no_longer_recorded","state_class_removed","units_changed","mean_type_changed","no_state"]:null,i=["L","gal","ft³","m³","CCF","MCF"],c=t=>t.sendMessagePromise({type:"recorder/info"}),_=(t,e)=>t.callWS({type:"recorder/list_statistic_ids",statistic_type:e}),l=(t,e)=>t.callWS({type:"recorder/get_statistics_metadata",statistic_ids:e}),u=(t,e,r,o,s="hour",n,a)=>t.callWS({type:"recorder/statistics_during_period",start_time:e.toISOString(),end_time:r?.toISOString(),statistic_ids:o,period:s,units:n,types:a}),d=(t,e,r,o)=>t.callWS({type:"recorder/statistic_during_period",statistic_id:e,units:o,fixed_period:r.fixed_period?{start_time:r.fixed_period.start instanceof Date?r.fixed_period.start.toISOString():r.fixed_period.start,end_time:r.fixed_period.end instanceof Date?r.fixed_period.end.toISOString():r.fixed_period.end}:void 0,calendar:r.calendar?{..."week"===r.calendar.period?{first_weekday:(0,s.D)(t.locale).substring(0,3)}:{},...r.calendar}:void 0,rolling_window:r.rolling_window}),g=t=>t.callWS({type:"recorder/validate_statistics"}),m=(t,e,r,o)=>t.callWS({type:"recorder/update_statistics_metadata",statistic_id:e,unit_of_measurement:r,unit_class:o}),y=(t,e)=>t.callWS({type:"recorder/clear_statistics",statistic_ids:e}),f=t=>{let e=null;if(!t)return null;for(const r of t)null!==r.change&&void 0!==r.change&&(null===e?e=r.change:e+=r.change);return e},p=(t,e)=>{let r=null;for(const o of e){if(!(o in t))continue;const e=f(t[o]);null!==e&&(null===r?r=e:r+=e)}return r},h=(t,e)=>t.some(t=>void 0!==t[e]&&null!==t[e]),b=["mean","min","max"],w=["sum","state","change"],v=(t,e)=>!(!b.includes(e)||0===t.mean_type)||!(!w.includes(e)||!t.has_sum),S=(t,e,r,o,s)=>{const n=new Date(r).toISOString();return t.callWS({type:"recorder/adjust_sum_statistics",statistic_id:e,start_time:n,adjustment:o,adjustment_unit_of_measurement:s})},E=(t,e,r)=>{const s=t.states[e];return s?(0,o.u)(s):r?.name||e},W=(t,e,r)=>{let o;return e&&(o=t.states[e]?.attributes.unit_of_measurement),void 0===o?r?.statistics_unit_of_measurement:o},D=t=>t.includes(":"),O=t=>t.callWS({type:"recorder/update_statistics_issues"})},30039(t,e,r){r.d(e,{R:()=>s});r(14603),r(47566),r(98721);var o=r(16869);const s=(t,e="")=>{const r=document.createElement("a");r.target="_blank",r.href=t,r.download=e,r.style.display="none",document.body.appendChild(r),r.dispatchEvent(new MouseEvent("click")),document.body.removeChild(r),t.startsWith("blob:")&&(o.B?setTimeout(()=>URL.revokeObjectURL(t),1e4):URL.revokeObjectURL(t))}}};