"use strict";(self.webpackChunkhome_assistant_frontend=self.webpackChunkhome_assistant_frontend||[]).push([["33427"],{67806:function(t,i,s){s.a(t,async function(t,e){try{s.r(i),s.d(i,{HuiGraphHeaderFooter:function(){return x}});s(16280),s(74423),s(18111),s(22489),s(3362),s(62953);var o=s(40445),n=s(96196),r=s(77845),h=s(36312),a=s(1087),c=s(71727),_=s(65829),l=s(25064),d=s(13632),u=s(18721),f=(s(24672),t([_,l]));[_,l]=f.then?(await f)():f;let g,b,y,p,v,m=t=>t;const w=6e4,C=60*w,k=["counter","input_number","number","sensor"];class x extends n.WF{static async getConfigElement(){return await s.e("11868").then(s.bind(s,87031)),document.createElement("hui-graph-footer-editor")}static getStubConfig(t,i,s){return{type:"graph",entity:(0,d.B)(t,1,i,s,k,t=>!isNaN(Number(t.state))&&!!t.attributes.unit_of_measurement)[0]||""}}getCardSize(){return 3}setConfig(t){if(null==t||!t.entity||!k.includes((0,c.m)(t.entity)))throw new Error("Specify an entity from within the sensor domain");const i=Object.assign({detail:1,hours_to_show:24},t);i.hours_to_show=Number(i.hours_to_show),i.detail=1===i.detail||2===i.detail?i.detail:1,this._config=i}render(){return this._config&&this.hass?this._error?(0,n.qy)(g||(g=m`<div class="errors">${0}</div>`),this._error):this._coordinates?this._coordinates.length?(0,n.qy)(p||(p=m` <hui-graph-base .coordinates="${0}"></hui-graph-base> `),this._coordinates):(0,n.qy)(y||(y=m` <div class="container"> <div class="info">No state history found.</div> </div> `)):(0,n.qy)(b||(b=m` <div class="container"> <ha-spinner size="small"></ha-spinner> </div> `)):n.s6}_handleClick(){var t,i;(0,a.r)(this,"hass-more-info",{entityId:null!==(t=null===(i=this._config)||void 0===i?void 0:i.entity)&&void 0!==t?t:null})}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this._handleClick),this.hasUpdated&&this._config&&this._subscribeHistory()}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribeHistory()}_subscribeHistory(){(0,h.x)(this.hass,"history")&&!this._subscribed&&this._config&&(this._subscribed=(0,l.IQ)(this.hass,t=>{this._subscribed&&this._config&&(this._history=t,this._computeCoordinates())},this._config.hours_to_show,[this._config.entity]).catch(t=>{this._subscribed=void 0,this._error=t}),this._setRedrawTimer())}_computeCoordinates(){var t,i;if(!this._history||!this._config)return;const s=this._history[this._config.entity];if(null==s||!s.length)return;const e=this.clientWidth||this.offsetWidth,o=Math.max(10,this._config.detail>1?Math.max(e/5,this._config.hours_to_show):this._config.hours_to_show),n=Date.now(),r=2!==this._config.detail,{points:h}=(0,u.a)(s,e,e/5,o,{minX:n-this._config.hours_to_show*C,maxX:n,minY:null===(t=this._config.limits)||void 0===t?void 0:t.min,maxY:null===(i=this._config.limits)||void 0===i?void 0:i.max},r);this._coordinates=h}_redrawGraph(){var t;if(!this._history||null===(t=this._config)||void 0===t||!t.hours_to_show)return;const i=this._config.entity,s=this._history[i];if(null!=s&&s.length){const t=(Date.now()-60*this._config.hours_to_show*60*1e3)/1e3;let e=s.filter(i=>i.lu>=t);if(e.length!==s.length){if(!e.length||e[0].lu!==t){const i=Object.assign({},s[s.length-e.length-1]);i.lu=t,delete i.lc,e=[i,...e]}this._history=Object.assign(Object.assign({},this._history),{},{[i]:e})}}this._computeCoordinates()}_setRedrawTimer(){clearInterval(this._interval),this._interval=window.setInterval(()=>this._redrawGraph(),this._config.hours_to_show>24?C:w)}_unsubscribeHistory(){clearInterval(this._interval),this._subscribed&&(this._subscribed.then(t=>null==t?void 0:t()),this._subscribed=void 0),this._history=void 0}updated(t){if(!this._config||!this.hass||!t.has("_config"))return;const i=t.get("_config");i&&this._subscribed&&i.entity===this._config.entity||(this._unsubscribeHistory(),this._subscribeHistory())}}x.styles=(0,n.AH)(v||(v=m`:host{display:block;cursor:pointer}ha-spinner{position:absolute;top:calc(50% - 14px)}.container{display:flex;justify-content:center;position:relative;padding-bottom:20%}.info{position:absolute;top:calc(50% - 16px);color:var(--secondary-text-color)}`)),(0,o.Cg)([(0,r.MZ)({attribute:!1})],x.prototype,"hass",void 0),(0,o.Cg)([(0,r.MZ)()],x.prototype,"type",void 0),(0,o.Cg)([(0,r.wk)()],x.prototype,"_config",void 0),(0,o.Cg)([(0,r.wk)()],x.prototype,"_coordinates",void 0),x=(0,o.Cg)([(0,r.EM)("hui-graph-header-footer")],x),e()}catch(g){e(g)}})}}]);
//# sourceMappingURL=33427.2eb1753ce24e4122.js.map