UNPKG

iobroker.lovelace

Version:

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

2 lines 33.6 kB
(self.webpackChunkhome_assistant_frontend=self.webpackChunkhome_assistant_frontend||[]).push([[5540],{92390:function(t,e,n){"use strict";n(31206);var i=n(50856),r=n(28426),a=n(1265),o=n(78956),s=n(44583),c=n(72986),l=n(33367),u=n(21683),h=n(49684);n(10983);function f(t){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function d(){var t=function(t,e){e||(e=t.slice(0));return Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}(['\n <style>\n :host {\n display: block;\n }\n .chartHeader {\n padding: 6px 0 0 0;\n width: 100%;\n display: flex;\n flex-direction: row;\n }\n .chartHeader > div {\n vertical-align: top;\n padding: 0 8px;\n }\n .chartHeader > div.chartTitle {\n padding-top: 8px;\n flex: 0 0 0;\n max-width: 30%;\n }\n .chartHeader > div.chartLegend {\n flex: 1 1;\n min-width: 70%;\n }\n :root {\n user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n -ms-user-select: none;\n }\n .chartTooltip {\n font-size: 90%;\n opacity: 1;\n position: absolute;\n background: rgba(80, 80, 80, 0.9);\n color: white;\n border-radius: 3px;\n pointer-events: none;\n transform: translate(-50%, 12px);\n z-index: 1000;\n width: 200px;\n transition: opacity 0.15s ease-in-out;\n }\n :host([rtl]) .chartTooltip {\n direction: rtl;\n }\n .chartLegend ul,\n .chartTooltip ul {\n display: inline-block;\n padding: 0 0px;\n margin: 5px 0 0 0;\n width: 100%;\n }\n .chartTooltip ul {\n margin: 0 3px;\n }\n .chartTooltip li {\n display: block;\n white-space: pre-line;\n }\n .chartTooltip li::first-line {\n line-height: 0;\n }\n .chartTooltip .title {\n text-align: center;\n font-weight: 500;\n }\n .chartTooltip .beforeBody {\n text-align: center;\n font-weight: 300;\n }\n .chartLegend li {\n display: inline-block;\n padding: 0 6px;\n max-width: 49%;\n text-overflow: ellipsis;\n white-space: nowrap;\n overflow: hidden;\n box-sizing: border-box;\n }\n .chartLegend li:nth-child(odd):last-of-type {\n /* Make last item take full width if it is odd-numbered. */\n max-width: 100%;\n }\n .chartLegend li[data-hidden] {\n text-decoration: line-through;\n }\n .chartLegend em,\n .chartTooltip em {\n border-radius: 5px;\n display: inline-block;\n height: 10px;\n margin-right: 4px;\n width: 10px;\n }\n :host([rtl]) .chartTooltip em {\n margin-right: inherit;\n margin-left: 4px;\n }\n ha-icon-button {\n color: var(--secondary-text-color);\n }\n </style>\n <template is="dom-if" if="[[unit]]">\n <div class="chartHeader">\n <div class="chartTitle">[[unit]]</div>\n <div class="chartLegend">\n <ul>\n <template is="dom-repeat" items="[[metas]]">\n <li on-click="_legendClick" data-hidden$="[[item.hidden]]">\n <em style$="background-color:[[item.bgColor]]"></em>\n [[item.label]]\n </li>\n </template>\n </ul>\n </div>\n </div>\n </template>\n <div id="chartTarget" style="height:40px; width:100%">\n <canvas id="chartCanvas"></canvas>\n <div\n class$="chartTooltip [[tooltip.yAlign]]"\n style$="opacity:[[tooltip.opacity]]; top:[[tooltip.top]]; left:[[tooltip.left]]; padding:[[tooltip.yPadding]]px [[tooltip.xPadding]]px"\n >\n <div class="title">[[tooltip.title]]</div>\n <template is="dom-if" if="[[tooltip.beforeBody]]">\n <div class="beforeBody">[[tooltip.beforeBody]]</div>\n </template>\n <div>\n <ul>\n <template is="dom-repeat" items="[[tooltip.lines]]">\n <li>\n <em style$="background-color:[[item.bgColor]]"></em\n >[[item.text]]\n </li>\n </template>\n </ul>\n </div>\n </div>\n </div>\n ']);return d=function(){return t},t}function p(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function y(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function m(t,e,n){return(m="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=_(t)););return t}(t,e);if(i){var r=Object.getOwnPropertyDescriptor(i,e);return r.get?r.get.call(n):r.value}})(t,e,n||t)}function b(t,e){return(b=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function g(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,i=_(t);if(e){var r=_(this).constructor;n=Reflect.construct(i,arguments,r)}else n=i.apply(this,arguments);return v(this,n)}}function v(t,e){return!e||"object"!==f(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function _(t){return(_=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var w=null,O=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&b(t,e)}(c,t);var e,r,a,s=g(c);function c(){return p(this,c),s.apply(this,arguments)}return e=c,a=[{key:"getColorList",value:function(t){var e=!1;t>10&&(e=!0,t=Math.ceil(t/2));for(var n=360/t,i=[],r=0;r<t;r++)i[r]=Color().hsl(n*r,80,38),e&&(i[r+t]=Color().hsl(n*r,80,62));return i}},{key:"getColorGenerator",value:function(t,e){var n=["ff0029","66a61e","377eb8","984ea3","00d2d5","ff7f00","af8d00","7f80cd","b3e900","c42e60","a65628","f781bf","8dd3c7","bebada","fb8072","80b1d3","fdb462","fccde5","bc80bd","ffed6f","c4eaff","cf8c00","1b9e77","d95f02","e7298a","e6ab02","a6761d","0097ff","00d067","f43600","4ba93b","5779bb","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 i(t){return Color("#"+n[t%n.length])}var r={},a=0;return e>0&&(a=e),t&&Object.keys(t).forEach((function(e){var n=t[e];isFinite(n)?r[e.toLowerCase()]=i(n):r[e.toLowerCase()]=Color(t[e])})),function(t,e){var n,o=e[3];if(null===o)return Color().hsl(0,40,38);if(void 0===o)return Color().hsl(120,40,38);var s=o.toLowerCase();return void 0===n&&(n=r[s]),void 0===n&&(n=i(a),a++,r[s]=n),n}}},{key:"template",get:function(){return(0,i.d)(d())}},{key:"properties",get:function(){return{data:Object,identifier:String,rendered:{type:Boolean,notify:!0,value:!1,readOnly:!0},metas:{type:Array,value:function(){return[]}},tooltip:{type:Object,value:function(){return{opacity:"0",left:"0",top:"0",xPadding:"5",yPadding:"3"}}},unit:Object,rtl:{type:Boolean,reflectToAttribute:!0}}}},{key:"observers",get:function(){return["onPropsChange(data)"]}}],(r=[{key:"connectedCallback",value:function(){var t=this;m(_(c.prototype),"connectedCallback",this).call(this),this._isAttached=!0,this.onPropsChange(),this._resizeListener=function(){t._debouncer=o.d.debounce(t._debouncer,u.Wc.after(10),(function(){t._isAttached&&t.resizeChart()}))},"function"==typeof ResizeObserver?(this.resizeObserver=new ResizeObserver((function(e){e.forEach((function(){t._resizeListener()}))})),this.resizeObserver.observe(this.$.chartTarget)):this.addEventListener("iron-resize",this._resizeListener),null===w&&(w=Promise.all([n.e(3296),n.e(7770)]).then(n.bind(n,79109))),w.then((function(e){t.ChartClass=e.default,t.onPropsChange()}))}},{key:"disconnectedCallback",value:function(){m(_(c.prototype),"disconnectedCallback",this).call(this),this._isAttached=!1,this.resizeObserver&&this.resizeObserver.unobserve(this.$.chartTarget),this.removeEventListener("iron-resize",this._resizeListener),void 0!==this._resizeTimer&&(clearInterval(this._resizeTimer),this._resizeTimer=void 0)}},{key:"onPropsChange",value:function(){this._isAttached&&this.ChartClass&&this.data&&this.drawChart()}},{key:"_customTooltips",value:function(t){if(0!==t.opacity){t.yAlign?this.set(["tooltip","yAlign"],t.yAlign):this.set(["tooltip","yAlign"],"no-transform");var e=t.title&&t.title[0]||"";this.set(["tooltip","title"],e),t.beforeBody&&this.set(["tooltip","beforeBody"],t.beforeBody.join("\n"));var n=t.body.map((function(t){return t.lines}));t.body&&this.set(["tooltip","lines"],n.map((function(e,n){var i=t.labelColors[n];return{color:i.borderColor,bgColor:i.backgroundColor,text:e.join("\n")}})));var i=this.$.chartTarget.clientWidth,r=t.caretX,a=this._chart.canvas.offsetTop+t.caretY;t.caretX+100>i?r=i-100:t.caretX<100&&(r=100),r+=this._chart.canvas.offsetLeft,this.tooltip=Object.assign({},this.tooltip,{opacity:1,left:"".concat(r,"px"),top:"".concat(a,"px")})}else this.set(["tooltip","opacity"],0)}},{key:"_legendClick",value:function(t){(t=t||window.event).stopPropagation();for(var e=t.target||t.srcElement;"LI"!==e.nodeName;)e=e.parentElement;var n=t.model.itemsIndex,i=this._chart.getDatasetMeta(n);i.hidden=null===i.hidden?!this._chart.data.datasets[n].hidden:null,this.set(["metas",n,"hidden"],this._chart.isDatasetVisible(n)?null:"hidden"),this._chart.update()}},{key:"_drawLegend",value:function(){var t=this,e=this._chart,n=this._oldIdentifier&&this.identifier===this._oldIdentifier;this._oldIdentifier=this.identifier,this.set("metas",this._chart.data.datasets.map((function(i,r){return{label:i.label,color:i.color,bgColor:i.backgroundColor,hidden:n&&r<t.metas.length?t.metas[r].hidden:!e.isDatasetVisible(r)}})));var i=!1;if(n)for(var r=0;r<this.metas.length;r++){var a=e.getDatasetMeta(r);!!a.hidden!=!!this.metas[r].hidden&&(i=!0),a.hidden=!!this.metas[r].hidden||null}i&&e.update(),this.unit=this.data.unit}},{key:"_formatTickValue",value:function(t,e,n){if(0===n.length)return t;var i=new Date(n[e].value);return(0,h.m)(i,this.hass.language)}},{key:"drawChart",value:function(){var t=this,e=this.data.data,n=this.$.chartCanvas;if(e.datasets&&e.datasets.length||this._chart){if("timeline"!==this.data.type&&e.datasets.length>0)for(var i=e.datasets.length,r=this.constructor.getColorList(i),a=0;a<i;a++)e.datasets[a].borderColor=r[a].rgbString(),e.datasets[a].backgroundColor=r[a].alpha(.6).rgbaString();if(this._chart)this._customTooltips({opacity:0}),this._chart.data=e,this._chart.update({duration:0}),this.isTimeline?this._chart.options.scales.yAxes[0].gridLines.display=e.length>1:!0===this.data.legend&&this._drawLegend(),this.resizeChart();else{if(!e.datasets)return;this._customTooltips({opacity:0});var o=[{afterRender:function(){return t._setRendered(!0)}}],s={responsive:!0,maintainAspectRatio:!1,animation:{duration:0},hover:{animationDuration:0},responsiveAnimationDuration:0,tooltips:{enabled:!1,custom:this._customTooltips.bind(this)},legend:{display:!1},line:{spanGaps:!0},elements:{font:"12px 'Roboto', 'sans-serif'"},ticks:{fontFamily:"'Roboto', 'sans-serif'"}};(s=Chart.helpers.merge(s,this.data.options)).scales.xAxes[0].ticks.callback=this._formatTickValue.bind(this),"timeline"===this.data.type?(this.set("isTimeline",!0),void 0!==this.data.colors&&(this._colorFunc=this.constructor.getColorGenerator(this.data.colors.staticColors,this.data.colors.staticColorIndex)),void 0!==this._colorFunc&&(s.elements.colorFunction=this._colorFunc),1===e.datasets.length&&(s.scales.yAxes[0].ticks?s.scales.yAxes[0].ticks.display=!1:s.scales.yAxes[0].ticks={display:!1},s.scales.yAxes[0].gridLines?s.scales.yAxes[0].gridLines.display=!1:s.scales.yAxes[0].gridLines={display:!1}),this.$.chartTarget.style.height="50px"):this.$.chartTarget.style.height="160px";var c={type:this.data.type,data:this.data.data,options:s,plugins:o};this._chart=new this.ChartClass(n,c),!0!==this.isTimeline&&!0===this.data.legend&&this._drawLegend(),this.resizeChart()}}}},{key:"resizeChart",value:function(){this._chart&&(void 0!==this._resizeTimer?(clearInterval(this._resizeTimer),this._resizeTimer=void 0,this._resizeChart()):this._resizeTimer=setInterval(this.resizeChart.bind(this),10))}},{key:"_resizeChart",value:function(){var t=this.$.chartTarget,e=this.data.data;if(0!==e.datasets.length)if(this.isTimeline){var n=this._chart.chartArea.top,i=this._chart.chartArea.bottom,r=this._chart.canvas.clientHeight;if(i>0&&(this._axisHeight=r-i+n),!this._axisHeight)return t.style.height="50px",this._chart.resize(),void this.resizeChart();if(this._axisHeight){var a=30*e.datasets.length+this._axisHeight+"px";t.style.height!==a&&(t.style.height=a),this._chart.resize()}}else this._chart.resize()}},{key:"chart",get:function(){return this._chart}}])&&y(e.prototype,r),a&&y(e,a),c}((0,l.P)([c.z],r.H3));function x(t){return(x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function k(){var t=function(t,e){e||(e=t.slice(0));return Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}(['\n <style>\n :host {\n display: block;\n overflow: hidden;\n height: 0;\n transition: height 0.3s ease-in-out;\n }\n </style>\n <ha-chart-base\n id="chart"\n hass="[[hass]]"\n data="[[chartData]]"\n identifier="[[identifier]]"\n rendered="{{rendered}}"\n ></ha-chart-base>\n ']);return k=function(){return t},t}function C(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function T(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function j(t,e,n){return(j="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=R(t)););return t}(t,e);if(i){var r=Object.getOwnPropertyDescriptor(i,e);return r.get?r.get.call(n):r.value}})(t,e,n||t)}function D(t,e){return(D=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function z(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,i=R(t);if(e){var r=R(this).constructor;n=Reflect.construct(i,arguments,r)}else n=i.apply(this,arguments);return S(this,n)}}function S(t,e){return!e||"object"!==x(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function R(t){return(R=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}customElements.define("ha-chart-base",O);var A=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&D(t,e)}(o,t);var e,n,r,a=z(o);function o(){return C(this,o),a.apply(this,arguments)}return e=o,r=[{key:"template",get:function(){return(0,i.d)(k())}},{key:"properties",get:function(){return{hass:{type:Object},chartData:Object,data:Object,names:Object,unit:String,identifier:String,isSingleDevice:{type:Boolean,value:!1},endTime:Object,rendered:{type:Boolean,value:!1,observer:"_onRenderedChanged"}}}},{key:"observers",get:function(){return["dataChanged(data, endTime, isSingleDevice)"]}}],(n=[{key:"connectedCallback",value:function(){j(R(o.prototype),"connectedCallback",this).call(this),this._isAttached=!0,this.drawChart()}},{key:"ready",value:function(){var t=this;j(R(o.prototype),"ready",this).call(this),this.addEventListener("transitionend",(function(){t.style.overflow="auto"}))}},{key:"dataChanged",value:function(){this.drawChart()}},{key:"_onRenderedChanged",value:function(t){t&&this.animateHeight()}},{key:"animateHeight",value:function(){var t=this;requestAnimationFrame((function(){return requestAnimationFrame((function(){t.style.height=t.$.chart.scrollHeight+"px"}))}))}},{key:"drawChart",value:function(){var t=this;if(this._isAttached){var e,n=this.unit,i=this.data,r=[];if(0!==i.length){(e=this.endTime||new Date(Math.max.apply(null,i.map((function(t){return new Date(t.states[t.states.length-1].last_changed)})))))>new Date&&(e=new Date);var a=this.names||{};i.forEach((function(i){var o,s=i.domain,l=a[i.entity_id]||i.name,u=[];function h(t,n){n&&(t>e||(u.forEach((function(e,i){e.data.push({x:t,y:n[i]})})),o=n))}function f(t,e,i){var r=!1,a=!1;i&&(r="origin"),e&&(a="before"),u.push({label:t,fill:r,steppedLine:a,pointRadius:0,data:[],unitText:n})}if("thermostat"===s||"climate"===s||"water_heater"===s){var d=i.states.some((function(t){return t.attributes&&t.attributes.hvac_action})),p="climate"===s&&d?function(t){return"heating"===t.attributes.hvac_action}:function(t){return"heat"===t.state},y="climate"===s&&d?function(t){return"cooling"===t.attributes.hvac_action}:function(t){return"cool"===t.state},m=i.states.some(p),b=i.states.some(y),g=i.states.some((function(t){return t.attributes&&t.attributes.target_temp_high!==t.attributes.target_temp_low}));f("".concat(t.hass.localize("ui.card.climate.current_temperature","name",l)),!0),m&&f("".concat(t.hass.localize("ui.card.climate.heating","name",l)),!0,!0),b&&f("".concat(t.hass.localize("ui.card.climate.cooling","name",l)),!0,!0),g?(f("".concat(t.hass.localize("ui.card.climate.target_temperature_mode","name",l,"mode",t.hass.localize("ui.card.climate.high"))),!0),f("".concat(t.hass.localize("ui.card.climate.target_temperature_mode","name",l,"mode",t.hass.localize("ui.card.climate.low"))),!0)):f("".concat(t.hass.localize("ui.card.climate.target_temperature_entity","name",l)),!0),i.states.forEach((function(t){if(t.attributes){var e=c(t.attributes.current_temperature),n=[e];if(m&&n.push(p(t)?e:null),b&&n.push(y(t)?e:null),g){var i=c(t.attributes.target_temp_high),r=c(t.attributes.target_temp_low);n.push(i,r),h(new Date(t.last_changed),n)}else{var a=c(t.attributes.temperature);n.push(a),h(new Date(t.last_changed),n)}}}))}else if("humidifier"===s)f("".concat(t.hass.localize("ui.card.humidifier.target_humidity_entity","name",l)),!0),f("".concat(t.hass.localize("ui.card.humidifier.on_entity","name",l)),!0,!0),i.states.forEach((function(t){if(t.attributes){var e=c(t.attributes.humidity),n=[e];n.push("on"===t.state?e:null),h(new Date(t.last_changed),n)}}));else{f(l,"sensor"===s);var v=null,_=null,w=null;i.states.forEach((function(t){var e=c(t.state),n=new Date(t.last_changed);if(null!==e&&null!==w){var i=n.getTime(),r=w.getTime(),a=_.getTime();h(w,[(r-a)/(i-a)*(e-v)+v]),h(new Date(r+1),[null]),h(n,[e]),_=n,v=e,w=null}else null!==e&&null===w?(h(n,[e]),_=n,v=e):null===e&&null===w&&null!==v&&(w=n)}))}h(e,o),Array.prototype.push.apply(r,u)}));var o={type:"line",unit:n,legend:!this.isSingleDevice,options:{scales:{xAxes:[{type:"time",ticks:{major:{fontStyle:"bold"}}}],yAxes:[{ticks:{maxTicksLimit:7}}]},tooltips:{mode:"neareach",callbacks:{title:function(e,n){var i=e[0],r=n.datasets[i.datasetIndex].data[i.index].x;return(0,s.E)(r,t.hass.language)}}},hover:{mode:"neareach"},layout:{padding:{top:5}},elements:{line:{tension:.1,pointRadius:0,borderWidth:1.5},point:{hitRadius:5}},plugins:{filler:{propagate:!0}}},data:{labels:[],datasets:r}};this.chartData=o}}function c(t){var e=parseFloat(t);return isFinite(e)?e:null}}}])&&T(e.prototype,n),r&&T(e,r),o}((0,a.Z)(r.H3));customElements.define("state-history-chart-line",A);var P=n(87744);function E(t){return(E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function L(){var t=function(t,e){e||(e=t.slice(0));return Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}(['\n <style>\n :host {\n display: block;\n opacity: 0;\n transition: opacity 0.3s ease-in-out;\n }\n :host([rendered]) {\n opacity: 1;\n }\n\n ha-chart-base {\n direction: ltr;\n }\n </style>\n <ha-chart-base\n hass="[[hass]]"\n data="[[chartData]]"\n rendered="{{rendered}}"\n rtl="{{rtl}}"\n ></ha-chart-base>\n ']);return L=function(){return t},t}function I(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function H(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function B(t,e,n){return(B="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=M(t)););return t}(t,e);if(i){var r=Object.getOwnPropertyDescriptor(i,e);return r.get?r.get.call(n):r.value}})(t,e,n||t)}function $(t,e){return($=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function F(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,i=M(t);if(e){var r=M(this).constructor;n=Reflect.construct(i,arguments,r)}else n=i.apply(this,arguments);return N(this,n)}}function N(t,e){return!e||"object"!==E(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function M(t){return(M=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var G=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&$(t,e)}(o,t);var e,n,r,a=F(o);function o(){return I(this,o),a.apply(this,arguments)}return e=o,r=[{key:"template",get:function(){return(0,i.d)(L())}},{key:"properties",get:function(){return{hass:{type:Object},chartData:Object,data:{type:Object,observer:"dataChanged"},names:Object,noSingle:Boolean,endTime:Date,rendered:{type:Boolean,value:!1,reflectToAttribute:!0},rtl:{reflectToAttribute:!0,computed:"_computeRTL(hass)"}}}},{key:"observers",get:function(){return["dataChanged(data, endTime, localize, language)"]}}],(n=[{key:"connectedCallback",value:function(){B(M(o.prototype),"connectedCallback",this).call(this),this._isAttached=!0,this.drawChart()}},{key:"dataChanged",value:function(){this.drawChart()}},{key:"drawChart",value:function(){var t=this,e=this.data;if(this._isAttached){e||(e=[]);var n=new Date(e.reduce((function(t,e){return Math.min(t,new Date(e.data[0].last_changed))}),new Date)),i=this.endTime||new Date(e.reduce((function(t,e){return Math.max(t,new Date(e.data[e.data.length-1].last_changed))}),n));i>new Date&&(i=new Date);var r=[],a=[],o=this.names||{};e.forEach((function(t){var e,s=null,c=null,l=n,u=o[t.entity_id]||t.name,h=[];t.data.forEach((function(t){var n=t.state;void 0!==n&&""!==n||(n=null),new Date(t.last_changed)>i||(null!==s&&n!==s?(e=new Date(t.last_changed),h.push([l,e,c,s]),s=n,c=t.state_localize,l=e):null===s&&(s=n,c=t.state_localize,l=new Date(t.last_changed)))})),null!==s&&h.push([l,i,c,s]),a.push({data:h,entity_id:t.entity_id}),r.push(u)}));var c={type:"timeline",options:{tooltips:{callbacks:{label:function(e,n){var i=n.datasets[e.datasetIndex].data[e.index],r=(0,s.E)(i[0],t.hass.language),a=(0,s.E)(i[1],t.hass.language);return[i[2],r,a]},beforeBody:function(e,n){return t.hass.userData&&t.hass.userData.showAdvanced&&e[0]&&n.datasets[e[0].datasetIndex].entity_id||""}}},scales:{xAxes:[{ticks:{major:{fontStyle:"bold"}}}],yAxes:[{afterSetDimensions:function(t){t.maxWidth=.18*t.chart.width},position:this._computeRTL?"right":"left"}]}},data:{labels:r,datasets:a},colors:{staticColors:{on:1,off:0,home:1,not_home:0,unavailable:"#a0a0a0",unknown:"#606060",idle:2},staticColorIndex:3}};this.chartData=c}}},{key:"_computeRTL",value:function(t){return(0,P.HE)(t)}}])&&H(e.prototype,n),r&&H(e,r),o}((0,a.Z)(r.H3));function V(t){return(V="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function W(){var t=function(t,e){e||(e=t.slice(0));return Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}(['\n <style>\n :host {\n display: block;\n /* height of single timeline chart = 58px */\n min-height: 58px;\n }\n .info {\n text-align: center;\n line-height: 58px;\n color: var(--secondary-text-color);\n }\n </style>\n <template\n is="dom-if"\n class="info"\n if="[[_computeIsLoading(isLoadingData)]]"\n >\n <div class="info">\n [[localize(\'ui.components.history_charts.loading_history\')]]\n </div>\n </template>\n\n <template\n is="dom-if"\n class="info"\n if="[[_computeIsEmpty(isLoadingData, historyData)]]"\n >\n <div class="info">\n [[localize(\'ui.components.history_charts.no_history_found\')]]\n </div>\n </template>\n\n <template is="dom-if" if="[[historyData.timeline.length]]">\n <state-history-chart-timeline\n hass="[[hass]]"\n data="[[historyData.timeline]]"\n end-time="[[_computeEndTime(endTime, upToNow, historyData)]]"\n no-single="[[noSingle]]"\n names="[[names]]"\n ></state-history-chart-timeline>\n </template>\n\n <template is="dom-repeat" items="[[historyData.line]]">\n <state-history-chart-line\n hass="[[hass]]"\n unit="[[item.unit]]"\n data="[[item.data]]"\n identifier="[[item.identifier]]"\n is-single-device="[[_computeIsSingleLineChart(item.data, noSingle)]]"\n end-time="[[_computeEndTime(endTime, upToNow, historyData)]]"\n names="[[names]]"\n ></state-history-chart-line>\n </template>\n ']);return W=function(){return t},t}function q(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function X(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function Z(t,e){return(Z=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function J(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,i=Y(t);if(e){var r=Y(this).constructor;n=Reflect.construct(i,arguments,r)}else n=i.apply(this,arguments);return U(this,n)}}function U(t,e){return!e||"object"!==V(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function Y(t){return(Y=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}customElements.define("state-history-chart-timeline",G);var K=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&Z(t,e)}(o,t);var e,n,r,a=J(o);function o(){return q(this,o),a.apply(this,arguments)}return e=o,r=[{key:"template",get:function(){return(0,i.d)(W())}},{key:"properties",get:function(){return{hass:Object,historyData:{type:Object,value:null},names:Object,isLoadingData:Boolean,endTime:{type:Object},upToNow:Boolean,noSingle:Boolean}}}],(n=[{key:"_computeIsSingleLineChart",value:function(t,e){return!e&&t&&1===t.length}},{key:"_computeIsEmpty",value:function(t,e){var n=!e||!e.timeline||!e.line||0===e.timeline.length&&0===e.line.length;return!t&&n}},{key:"_computeIsLoading",value:function(t){return t&&!this.historyData}},{key:"_computeEndTime",value:function(t,e){return e?new Date:t}}])&&X(e.prototype,n),r&&X(e,r),o}((0,a.Z)(r.H3));customElements.define("state-history-charts",K)},58763:function(t,e,n){"use strict";n.d(e,{vq:function(){return u},_J:function(){return h},Nu:function(){return d}});var i=n(29171),r=n(22311),a=n(91741);function o(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return s(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0,r=function(){};return{s:r,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,c=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return o=t.done,t},e:function(t){c=!0,a=t},f:function(){try{o||null==n.return||n.return()}finally{if(c)throw a}}}}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}var c=["climate","humidifier","water_heater"],l=["temperature","current_temperature","target_temp_low","target_temp_high","hvac_action","humidity","mode"],u=function(t,e,n,i){var r=arguments.length>4&&void 0!==arguments[4]&&arguments[4],a=arguments.length>5?arguments[5]:void 0,o=!(arguments.length>6&&void 0!==arguments[6])||arguments[6],s="history/period";return n&&(s+="/"+n.toISOString()),s+="?filter_entity_id="+e,i&&(s+="&end_time="+i.toISOString()),r&&(s+="&skip_initial_state"),void 0!==a&&(s+="&significant_changes_only=".concat(Number(a))),o&&(s+="&minimal_response"),t.callApi("GET",s)},h=function(t,e,n,i){return t.callApi("GET","history/period/".concat(e.toISOString(),"?end_time=").concat(n.toISOString(),"&minimal_response").concat(i?"&filter_entity_id=".concat(i):""))},f=function(t,e){return t.state===e.state&&(!t.attributes||!e.attributes||l.every((function(n){return t.attributes[n]===e.attributes[n]})))},d=function(t,e,n,s){var u={},h=[];return e?(e.forEach((function(e){if(0!==e.length){var c,l=e.find((function(t){return t.attributes&&"unit_of_measurement"in t.attributes}));l?c=l.attributes.unit_of_measurement:"climate"===(0,r.N)(e[0])||"water_heater"===(0,r.N)(e[0])?c=t.config.unit_system.temperature:"humidifier"===(0,r.N)(e[0])&&(c="%"),c?c in u?u[c].push(e):u[c]=[e]:h.push(function(t,e,n){var r,s=[],c=n.length-1,l=o(n);try{for(l.s();!(r=l.n()).done;){var u=r.value;s.length>0&&u.state===s[s.length-1].state||(u.entity_id||(u.attributes=n[c].attributes,u.entity_id=n[c].entity_id),s.push({state_localize:(0,i.D)(t,u,e),state:u.state,last_changed:u.last_changed}))}}catch(h){l.e(h)}finally{l.f()}return{name:(0,a.C)(n[0]),entity_id:n[0].entity_id,data:s}}(n,s,e))}})),{line:Object.keys(u).map((function(t){return function(t,e){var n,i=[],s=o(e);try{for(s.s();!(n=s.n()).done;){var u,h=n.value,d=h[h.length-1],p=(0,r.N)(d),y=[],m=o(h);try{for(m.s();!(u=m.n()).done;){var b=u.value,g=void 0;if(c.includes(p)){g={state:b.state,last_changed:b.last_updated,attributes:{}};var v,_=o(l);try{for(_.s();!(v=_.n()).done;){var w=v.value;w in b.attributes&&(g.attributes[w]=b.attributes[w])}}catch(O){_.e(O)}finally{_.f()}}else g=b;y.length>1&&f(g,y[y.length-1])&&f(g,y[y.length-2])||y.push(g)}}catch(O){m.e(O)}finally{m.f()}i.push({domain:p,name:(0,a.C)(d),entity_id:d.entity_id,states:y})}}catch(O){s.e(O)}finally{s.f()}return{unit:t,identifier:e.map((function(t){return t[0].entity_id})).join(""),data:i}}(t,u[t])})),timeline:h}):{line:[],timeline:[]}}}}]); //# sourceMappingURL=chunk.536c2fa17e5097fe817d.js.map