iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 5.24 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[33427],{67806:function(t,i,s){s.a(t,async function(t,o){try{s.r(i),s.d(i,{HuiGraphHeaderFooter:function(){return k}});s(16280),s(74423),s(18111),s(22489),s(3362),s(62953);var e=s(40445),n=s(5124),r=s(67576),h=s(36312),a=s(1087),c=s(71727),_=s(38962),d=s(25064),l=s(13632),u=s(18721),g=(s(21824),t([_,d]));[_,d]=g.then?(await g)():g;let f,y,b,p,v=t=>t;const m=6e4,w=60*m,C=["counter","input_number","number","sensor"];class k 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,l.B)(t,1,i,s,C,t=>!isNaN(Number(t.state))&&!!t.attributes.unit_of_measurement)[0]||""}}getCardSize(){return 3}setConfig(t){if(null==t||!t.entity||!C.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)(f||(f=v` <ha-alert alert-type="error"> ${0}: ${0} </ha-alert> `),this.hass.localize("ui.components.history_charts.error"),this._error.message||this._error.code):this._coordinates&&!this._coordinates.length?(0,n.qy)(y||(y=v` <div class="container"> <div class="info">No state history found.</div> </div> `)):(0,n.qy)(b||(b=v` <hui-graph-base ?loading="${0}" .coordinates="${0}"></hui-graph-base> `),this._loading,this._coordinates):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.config,"history")&&!this._subscribed&&this._config&&(this._setLoadingCoordinates(),this._subscribed=(0,d.IQ)(this.hass,t=>{var i;if(this._subscribed&&this._config){if(this._history=t,null===(i=this._history[this._config.entity])||void 0===i||!i.length){const t=this.hass.states[this._config.entity];t&&(this._history[this._config.entity]=(0,d.Lj)(t))}this._computeCoordinates()}},this._config.hours_to_show,[this._config.entity]).catch(t=>{this._subscribed=void 0,this._error=t}),this._setRedrawTimer())}_setLoadingCoordinates(){var t,i;if(!this._config||!this.hass)return;const s=this.hass.states[this._config.entity];if(!s)return;const o=this.clientWidth||this.offsetWidth,{points:e}=(0,u.a)((0,d.Lj)(s),o,o/5,10,{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});this._coordinates=e}_computeCoordinates(){var t,i;if(!this._history||!this._config)return;const s=this._history[this._config.entity];if(null==s||!s.length)return;const o=this.clientWidth||this.offsetWidth,e=Math.max(10,this._config.detail>1?Math.max(o/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,o,o/5,e,{minX:n-this._config.hours_to_show*w,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,this._loading=!1}_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 o=s.filter(i=>i.lu>=t);if(o.length!==s.length){if(!o.length||o[0].lu!==t){const i=Object.assign({},s[s.length-o.length-1]);i.lu=t,delete i.lc,o=[i,...o]}this._history=Object.assign(Object.assign({},this._history),{},{[i]:o})}}this._computeCoordinates()}_setRedrawTimer(){clearInterval(this._interval),this._interval=window.setInterval(()=>this._redrawGraph(),this._config.hours_to_show>24?w:m)}_unsubscribeHistory(){clearInterval(this._interval),this._subscribed&&(this._subscribed.then(t=>null==t?void 0:t()).catch(()=>{}),this._subscribed=void 0),this._history=void 0}updated(t){if(this._config&&this.hass)if(t.has("_config")){const i=t.get("_config");i&&this._subscribed&&i.entity===this._config.entity||(this._unsubscribeHistory(),this._subscribeHistory())}else this.isConnected&&!this._subscribed&&!this._error&&t.has("hass")&&this._subscribeHistory()}constructor(...t){super(...t),this._loading=!0}}k.styles=(0,n.AH)(p||(p=v`:host{display:block;cursor:pointer}.container{display:flex;justify-content:center;position:relative;padding-bottom:20%}.info{position:absolute;top:calc(50% - 16px);color:var(--secondary-text-color)}`)),(0,e.Cg)([(0,r.MZ)({attribute:!1})],k.prototype,"hass",void 0),(0,e.Cg)([(0,r.MZ)()],k.prototype,"type",void 0),(0,e.Cg)([(0,r.wk)()],k.prototype,"_config",void 0),(0,e.Cg)([(0,r.wk)()],k.prototype,"_coordinates",void 0),(0,e.Cg)([(0,r.wk)()],k.prototype,"_loading",void 0),(0,e.Cg)([(0,r.wk)()],k.prototype,"_error",void 0),k=(0,e.Cg)([(0,r.EM)("hui-graph-header-footer")],k),o()}catch(f){o(f)}})}}]);