(function(){"use strict";function a(){const b=E(["\n
\n ","\n \n "," ","\n \n \n ","\n \n
\n "]);return a=function(){return b},b}function b(){const a=E(["\n \n ","\n
\n "]);return b=function(){return a},a}function c(){const a=E(["\n \n ","\n ","\n
\n "]);return c=function(){return a},a}function d(){const a=E(["\n "]);return d=function(){return a},a}function e(){const a=E(["",""]);return e=function(){return a},a}function f(){const a=E(["\n \n ","\n "]);return f=function(){return a},a}function g(){const a=E(["\n \n "]);return g=function(){return a},a}function h(){const a=E(["\n "]);return h=function(){return a},a}function i(){const a=E(["",""]);return i=function(){return a},a}function j(){const a=E(["\n \n "]);return j=function(){return a},a}function k(){const a=E(["\n \n ","\n "]);return k=function(){return a},a}function l(){const a=E(["\n \n ","\n "]);return l=function(){return a},a}function m(){const a=E(["\n \n "]);return m=function(){return a},a}function n(){const a=E(["\n \n ","\n \n "]);return n=function(){return a},a}function o(){const a=E(["\n "]);return o=function(){return a},a}function p(){const a=E(["\n \n \n \n \n \n \n "]);return p=function(){return a},a}function q(){const a=E(["\n \n "]);return q=function(){return a},a}function r(){const a=E(["\n \n ","\n ","\n
\n "]);return r=function(){return a},a}function s(){const a=E(["\n \n ","\n
\n "]);return s=function(){return a},a}function t(){const a=E(["\n "]);return t=function(){return a},a}function u(){const a=E(["\n "," -\n ","\n "]);return u=function(){return a},a}function v(){const a=E(["\n ","\n "]);return v=function(){return a},a}function w(){const a=E(["\n \n ","\n
\n "]);return w=function(){return a},a}function x(){const a=E(["\n \n ","\n \n ","\n \n \n ","\n \n
\n "]);return x=function(){return a},a}function y(){const a=E(["\n \n
\n \n ","\n \n \n ","\n \n ","\n
\n
","
\n ","\n
\n "]);return y=function(){return a},a}function z(){const a=E(["\n \n ","\n
\n "]);return z=function(){return a},a}function A(){const a=E(["\n \n \n
\n "]);return A=function(){return a},a}function B(){const a=E(["\n \n "]);return B=function(){return a},a}function C(){const a=E(["\n \n "," "," "," ","\n \n "]);return C=function(){return a},a}function D(){const a=E(["\n :host {\n display: flex;\n flex-direction: column;\n }\n ha-card {\n flex-direction: column;\n flex: 1;\n padding: 16px 0;\n position: relative;\n overflow: hidden;\n }\n ha-card > div {\n padding: 0px 16px 16px 16px;\n }\n ha-card > div:last-child {\n padding-bottom: 0;\n }\n ha-card[points] .line--points,\n ha-card[labels] .graph__labels {\n opacity: 0;\n transition: opacity .25s;\n animation: none;\n }\n ha-card[points]:hover .line--points,\n ha-card:hover .graph__labels {\n opacity: 1;\n }\n ha-card[fill] {\n padding-bottom: 0;\n }\n ha-card[fill] .graph {\n padding: 0;\n order: 10;\n }\n ha-card[fill] path {\n stroke-linecap: initial;\n stroke-linejoin: initial;\n }\n ha-card[fill] .graph__legend {\n order: -1;\n padding: 0 16px 8px 16px;\n }\n ha-card[fill] .info {\n padding-bottom: 16px;\n }\n ha-card[group] {\n box-shadow: none;\n padding: 0;\n }\n ha-card[group] > div {\n padding-left: 0;\n padding-right: 0;\n }\n ha-card[group] .graph__legend {\n padding-left: 0;\n padding-right: 0;\n }\n ha-card[more-info] {\n cursor: pointer;\n }\n .flex {\n display: flex;\n display: -webkit-flex;\n min-width: 0;\n }\n .header {\n justify-content: space-between;\n }\n .header[loc=\"center\"] {\n justify-content: space-around;\n }\n .header[loc=\"left\"] {\n align-self: flex-start;\n }\n .header[loc=\"right\"] {\n align-self: flex-end;\n }\n .name {\n align-items: center;\n min-width: 0;\n opacity: .8;\n letter-spacing: .05em;\n }\n .name > span {\n font-size: 1.2em;\n font-weight: 400;\n max-height: 1.4em;\n min-height: 1.4em;\n opacity: .75;\n }\n .icon {\n color: var(--paper-item-icon-color, #44739e);\n display: inline-block;\n flex: 0 0 1.7em;\n text-align: center;\n }\n .icon > ha-icon {\n height: 1.7em;\n width: 1.7em;\n }\n .icon[loc=\"left\"] {\n order: -1;\n margin-right: .6em;\n margin-left: 0;\n }\n .icon[loc=\"state\"] {\n align-self: center;\n }\n .states {\n align-items: flex-start;\n font-weight: 300;\n justify-content: space-between;\n flex-wrap: nowrap;\n }\n .states .icon {\n align-self: center;\n margin-left: 0;\n }\n .states[loc=\"center\"] {\n justify-content: space-evenly;\n }\n .states[loc=\"right\"] > .state {\n margin-left: auto;\n order: 2;\n }\n .states[loc=\"center\"] .states--secondary,\n .states[loc=\"right\"] .states--secondary {\n margin-left: 0;\n }\n .states[loc=\"center\"] .states--secondary {\n align-items: center;\n }\n .states[loc=\"right\"] .states--secondary {\n align-items: flex-start;\n }\n .states[loc=\"center\"] .state__time {\n left: 50%;\n transform: translateX(-50%);\n }\n .states > .icon > ha-icon {\n height: 2em !important;\n width: 2em !important;\n }\n .states--secondary {\n display: flex;\n flex-flow: column;\n flex-wrap: wrap;\n align-items: flex-end;\n margin-left: 1rem;\n min-width: 0;\n margin-left: 1.4em;\n }\n .states--secondary:empty {\n display: none;\n }\n .state {\n position: relative;\n display: flex;\n flex-wrap: wrap;\n max-width: 100%;\n min-width: 0;\n }\n .state--small {\n font-size: .6em;\n margin-bottom: .6rem;\n flex-wrap: nowrap;\n }\n .state--small > svg {\n position: absolute;\n left: -1.6em;\n align-self: center;\n height: 1em;\n width: 1em;\n border-radius: 100%;\n margin-right: 1em;\n }\n .state--small:last-child {\n margin-bottom: 0;\n }\n .states--secondary > :only-child {\n font-size: 1em;\n margin-bottom: 0;\n }\n .states--secondary > :only-child svg {\n display: none;\n }\n .state__value {\n display: inline-block;\n font-size: 2.4em;\n line-height: 1em;\n margin-right: .25rem;\n }\n .state__uom {\n align-self: flex-end;\n display: inline-block;\n font-size: 1.4em;\n font-weight: 400;\n line-height: 1.2em;\n margin-top: .1em;\n opacity: .6;\n vertical-align: bottom;\n }\n .state--small .state__uom {\n flex: 1;\n }\n .state__time {\n font-size: .95rem;\n font-weight: 500;\n bottom: -1.1rem;\n left: 0;\n opacity: .75;\n position: absolute;\n white-space: nowrap;\n }\n .states[loc=\"right\"] .state__time {\n left: initial;\n right: 0;\n }\n .graph {\n align-self: flex-end;\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n margin-top: auto;\n width: 100%;\n }\n .graph__container {\n display: flex;\n flex-direction: row;\n position: relative;\n }\n .graph__container__svg {\n cursor: default;\n flex: 1;\n }\n svg {\n overflow: hidden;\n }\n path {\n stroke-linecap: round;\n stroke-linejoin: round;\n }\n .line--fill[anim=\"false\"] {\n animation: reveal .25s cubic-bezier(0.215, 0.61, 0.355, 1) forwards;\n }\n .line--fill[anim=\"false\"][type=\"fade\"] {\n animation: reveal-2 .25s cubic-bezier(0.215, 0.61, 0.355, 1) forwards;\n }\n .line--points[anim=\"false\"],\n .line[anim=\"false\"] {\n animation: pop .25s cubic-bezier(0.215, 0.61, 0.355, 1) forwards;\n }\n .line--points[inactive],\n .line--rect[inactive],\n .line--fill[inactive] {\n opacity: 0 !important;\n animation: none !important;\n transition: all .15s !important;\n }\n .line--points[inactive] {\n }\n .line--points[tooltip] .line--point[inactive] {\n opacity: 0;\n }\n .line--point {\n cursor: pointer;\n fill: var(--paper-card-background-color, white);\n stroke-width: inherit;\n }\n .line--point:hover {\n fill: var(--mcg-hover, inherit) !important;\n }\n .bars {\n animation: pop .25s cubic-bezier(0.215, 0.61, 0.355, 1);\n }\n .bars[anim] {\n animation: bars .5s cubic-bezier(0.215, 0.61, 0.355, 1);\n }\n .bar {\n transition: opacity .25s cubic-bezier(0.215, 0.61, 0.355, 1);\n }\n .bar:hover {\n opacity: .5;\n cursor: pointer;\n }\n ha-card[gradient] .line--point:hover {\n fill: var(--primary-text-color, white);\n }\n path,\n .line--points,\n .line--fill {\n opacity: 0;\n }\n .line--points[anim=\"true\"][init] {\n animation: pop .5s cubic-bezier(0.215, 0.61, 0.355, 1) forwards;\n }\n .line--fill[anim=\"true\"][init] {\n animation: reveal .5s cubic-bezier(0.215, 0.61, 0.355, 1) forwards;\n }\n .line--fill[anim=\"true\"][init][type=\"fade\"] {\n animation: reveal-2 .5s cubic-bezier(0.215, 0.61, 0.355, 1) forwards;\n }\n .line[anim=\"true\"][init] {\n animation: dash 1s cubic-bezier(0.215, 0.61, 0.355, 1) forwards;\n }\n .graph__labels {\n align-items: flex-start;\n flex-direction: column;\n font-size: calc(.15em + 8.5px);\n font-weight: 400;\n justify-content: space-between;\n margin-right: 10px;\n padding: .6em;\n position: absolute;\n pointer-events: none;\n top: 0; bottom: 0;\n opacity: .75;\n }\n .graph__labels > span {\n cursor: pointer;\n background: var(--primary-background-color, white);\n border-radius: 1em;\n padding: .2em .6em;\n box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.24);\n }\n .graph__legend {\n display: flex;\n flex-direction: row;\n justify-content: space-evenly;\n padding-top: 16px;\n flex-wrap: wrap;\n }\n .graph__legend__item {\n cursor: pointer;\n display: flex;\n min-width: 0;\n margin: .4em;\n align-items: center\n }\n .graph__legend__item span {\n opacity: .75;\n margin-left: .4em;\n }\n .graph__legend__item svg {\n border-radius: 100%;\n }\n .info {\n justify-content: space-between;\n align-items: middle;\n }\n .info__item {\n display: flex;\n flex-flow: column;\n align-items: flex-end;\n text-align: right;\n }\n .info__item:first-child {\n align-items: flex-start;\n text-align: left;\n }\n .info__item__type {\n text-transform: capitalize;\n font-weight: 500;\n opacity: .9;\n }\n .info__item__time,\n .info__item__value {\n opacity: .75;\n }\n .ellipsis {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n @keyframes reveal {\n 0% { opacity: 0; }\n 100% { opacity: .15; }\n }\n @keyframes reveal-2 {\n 0% { opacity: 0; }\n 100% { opacity: .4; }\n }\n @keyframes pop {\n 0% { opacity: 0; }\n 100% { opacity: 1; }\n }\n @keyframes bars {\n 0% { opacity: 0; }\n 50% { opacity: 0; }\n 100% { opacity: 1; }\n }\n @keyframes dash {\n 0% {\n opacity: 0;\n }\n 25% {\n opacity: 1;\n }\n 100% {\n opacity: 1;\n stroke-dashoffset: 0;\n }\n }"]);return D=function(){return a},a}function E(a,b){return b||(b=a.slice(0)),Object.freeze(Object.defineProperties(a,{raw:{value:Object.freeze(b)}}))}function F(a){for(var b=1;ba.parentNode.removeChild(a))}function I(a,b,c=null){const{element:{content:e},parts:d}=a;if(null===c||void 0===c)return void e.appendChild(b);const f=document.createTreeWalker(e,eb,null,!1);let g=gb(d),h=0,i=-1;for(;f.nextNode();){i++;const a=f.currentNode;for(a===c&&(h=fb(b),c.parentNode.insertBefore(b,c));-1!==g&&d[g].index===i;){if(0=b.oldVersion&&c.createObjectStore(Gb)}catch(c){if("ConstraintError"===c.name)console.warn("The database \""+a.name+"\" has been upgraded from version "+b.oldVersion+" to version "+b.newVersion+", but the storage \""+a.storeName+"\" already exists.");else throw c}}),f.onerror=function(a){a.preventDefault(),d(f.error)},f.onsuccess=function(){c(f.result),T(a)}})}function Z(a){return W(a,!1)}function $(a){return W(a,!0)}function _(a,b){if(!a.db)return!0;var c=!a.db.objectStoreNames.contains(a.storeName),d=a.versiona.db.version;if(d&&(a.version!==b&&console.warn("The database \""+a.name+"\" can't be downgraded from version "+a.db.version+" to version "+a.version+"."),a.version=a.db.version),e||c){if(c){var f=a.db.version+1;f>a.version&&(a.version=f)}return!0}return!1}function aa(a){return new Promise(function(b,c){var d=new FileReader;d.onerror=c,d.onloadend=function(c){var d=btoa(c.target.result||"");b({__local_forage_encoded_blob:!0,data:d,type:a.type})},d.readAsBinaryString(a)})}function ba(a){var b=P(atob(a.data));return K([b],{type:a.type})}function ca(a){return a&&a.__local_forage_encoded_blob}function da(a){var b=this,c=b._initReady().then(function(){var a=Ib[b._dbInfo.name];if(a&&a.dbReady)return a.dbReady});return M(c,a,a),c}function ea(a){S(a);for(var b=Ib[a.name],c=b.forages,d=0;d(a.db=b,_(a)?$(a):b)).then(d=>{a.db=b.db=d;for(var e=0;e{throw U(a,b),b})}function fa(a,b,c,d){d===void 0&&(d=1);try{var e=a.db.transaction(a.storeName,b);c(null,e)}catch(e){if(0{if(!a.db||"NotFoundError"===e.name&&!a.db.objectStoreNames.contains(a.storeName)&&a.version<=a.db.version)return a.db&&(a.version=a.db.version+1),$(a)}).then(()=>ea(a).then(function(){fa(a,b,c,d-1)})).catch(c);c(e)}}function ga(){return{forages:[],db:null,dbReady:null,deferredOperations:[]}}function ha(a){var b,c,d,e,f,g=.75*a.length,h=a.length,j=0;"="===a[a.length-1]&&(g--,"="===a[a.length-2]&&g--);var k=new ArrayBuffer(g),l=new Uint8Array(k);for(b=0;b>4,l[j++]=(15&d)<<4|e>>2,l[j++]=(3&e)<<6|63&f;return k}function ia(a){var b,c=new Uint8Array(a),d="";for(b=0;b>2],d+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(3&c[b])<<4|c[b+1]>>4],d+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(15&c[b+1])<<2|c[b+2]>>6],d+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[63&c[b+2]];return 2==c.length%3?d=d.substring(0,d.length-1)+"=":1==c.length%3&&(d=d.substring(0,d.length-2)+"=="),d}function ja(a,b,c,d){a.executeSql("CREATE TABLE IF NOT EXISTS ".concat(b.storeName," ")+"(id INTEGER PRIMARY KEY, key unique, value)",[],c,d)}function ka(a,b,c,d,e,f){a.executeSql(c,d,e,function(a,g){g.code===g.SYNTAX_ERR?a.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name = ?",[b.storeName],function(a,h){h.rows.length?f(a,g):ja(a,b,function(){a.executeSql(c,d,e,f)},f)},f):f(a,g)},f)}function la(a,b,c,d){var e=this;a=N(a);var f=new Promise(function(f,g){e.ready().then(function(){void 0===b&&(b=null);var h=b,i=e._dbInfo;i.serializer.serialize(b,function(b,j){j?g(j):i.db.transaction(function(c){ka(c,i,"INSERT OR REPLACE INTO ".concat(i.storeName," ")+"(key, value) VALUES (?, ?)",[a,b],function(){f(h)},function(a,b){g(b)})},function(b){if(b.code===b.QUOTA_ERR){if(0 '__WebKitDatabaseInfoTable__'",[],function(c,d){for(var e=[],f=0;f"function"==typeof a&&ya.has(a),Aa=window.customElements!==void 0&&window.customElements.polyfillWrapFlushCallback!==void 0,Ba=(a,b,c=null,d=null)=>{for(let e=b;e!==c;){const b=e.nextSibling;a.insertBefore(e,d),e=b}},Ca=(a,b,c=null)=>{for(let d=b;d!==c;){const b=d.nextSibling;a.removeChild(d),d=b}},Da={},Ea={},Fa="{{lit-".concat((Math.random()+"").slice(2),"}}"),Ga=""),Ha=new RegExp("".concat(Fa,"|").concat(Ga)),Ia="$lit$";class Ja{constructor(a,b){this.parts=[],this.element=b;let c=-1,d=0;const e=[],f=b=>{const g=b.content,h=document.createTreeWalker(g,133,null,!1);for(let g=0;h.nextNode();){c++;const b=h.currentNode;if(1===b.nodeType){if(b.hasAttributes()){const e=b.attributes;let f=0;for(let a=0;a-1!==a.index,La=()=>document.createComment(""),Ma=/([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F \x09\x0a\x0c\x0d"'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;class Na{constructor(a,b,c){this._parts=[],this.template=a,this.processor=b,this.options=c}update(a){let b=0;for(const c of this._parts)void 0!==c&&c.setValue(a[b]),b++;for(const b of this._parts)void 0!==b&&b.commit()}_clone(){const a=Aa?this.template.element.content.cloneNode(!0):document.importNode(this.template.element.content,!0),b=this.template.parts;let c=0,d=0;const e=a=>{const f=document.createTreeWalker(a,133,null,!1);for(let h=f.nextNode();c".concat(super.getHTML(),"")}getTemplateElement(){const a=super.getTemplateElement(),b=a.content,c=b.firstChild;return b.removeChild(c),Ba(b,c.firstChild),a}}const Qa=a=>null===a||"object"!=typeof a&&"function"!=typeof a;class Ra{constructor(a,b,c){this.dirty=!0,this.element=a,this.name=b,this.strings=c,this.parts=[];for(let d=0;dthis.handleEvent(a)}setValue(a){this._pendingValue=a}commit(){for(;za(this._pendingValue);){const a=this._pendingValue;this._pendingValue=Da,a(this)}if(this._pendingValue===Da)return;const a=this._pendingValue,b=this.value,c=null==a||null!=b&&(a.capture!==b.capture||a.once!==b.once||a.passive!==b.passive);c&&this.element.removeEventListener(this.eventName,this._boundHandleEvent,this._options),null!=a&&(null==b||c)&&(this._options=Za(a),this.element.addEventListener(this.eventName,this._boundHandleEvent,this._options)),this.value=a,this._pendingValue=Da}handleEvent(a){"function"==typeof this.value?this.value.call(this.eventContext||this.element,a):this.value.handleEvent(a)}}const Za=a=>a&&(Xa?{capture:a.capture,passive:a.passive,once:a.once}:a.capture);const $a=new class{handleAttributeExpressions(a,b,c,d){const e=b[0];if("."===e){const d=new Va(a,b.slice(1),c);return d.parts}if("@"===e)return[new Ya(a,b.slice(1),d.eventContext)];if("?"===e)return[new Ua(a,b.slice(1),c)];const f=new Ra(a,b,c);return f.parts}handleTextExpression(a){return new Ta(a)}},_a=new Map,ab=new WeakMap,bb=(a,b,c)=>{let d=ab.get(b);d===void 0&&(Ca(b,b.firstChild),ab.set(b,d=new Ta(Object.assign({templateFactory:E},c))),d.appendInto(b)),d.setValue(a),d.commit()};(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.0.0");const cb=(a,...b)=>new Oa(a,b,"html",$a),db=(a,...b)=>new Pa(a,b,"svg",$a),eb=133,fb=a=>{let b=11===a.nodeType?0:1;for(const c=document.createTreeWalker(a,eb,null,!1);c.nextNode();)b++;return b},gb=(a,b=-1)=>{for(let c=b+1;c"".concat(a,"--").concat(b);let ib=!0;"undefined"==typeof window.ShadyCSS?ib=!1:"undefined"==typeof window.ShadyCSS.prepareTemplateDom&&(console.warn("Incompatible ShadyCSS version detected.Please update to at least @webcomponents/webcomponentsjs@2.0.2 and@webcomponents/shadycss@1.3.1."),ib=!1);const jb=a=>b=>{const c=hb(b.type,a);let d=_a.get(c);void 0===d&&(d={stringsArray:new WeakMap,keyString:new Map},_a.set(c,d));let e=d.stringsArray.get(b.strings);if(void 0!==e)return e;const f=b.strings.join(Fa);if(e=d.keyString.get(f),void 0===e){const c=b.getTemplateElement();ib&&window.ShadyCSS.prepareTemplateDom(c,a),e=new Ja(b,c),d.keyString.set(f,e)}return d.stringsArray.set(b.strings,e),e},kb=["html","svg"],lb=a=>{kb.forEach(b=>{const c=_a.get(hb(b,a));c!==void 0&&c.keyString.forEach(a=>{const{element:{content:b}}=a,c=new Set;Array.from(b.querySelectorAll("style")).forEach(a=>{c.add(a)}),G(a,c)})})},mb=new Set,nb=(a,b,c)=>{mb.add(c);const d=a.querySelectorAll("style");if(0===d.length)return void window.ShadyCSS.prepareTemplateStyles(b.element,c);const e=document.createElement("style");for(let f=0;f{const d=c.scopeName,e=ab.has(b),f=b instanceof ShadowRoot&&ib&&a instanceof Oa,g=f&&!mb.has(d),h=g?document.createDocumentFragment():b;if(bb(a,h,Object.assign({templateFactory:jb(d)},c)),g){const a=ab.get(h);ab.delete(h),a.value instanceof Na&&nb(h,a.value.template,d),Ca(b,b.firstChild),b.appendChild(h),ab.set(b,a)}!e&&f&&window.ShadyCSS.styleElement(b.host)};window.JSCompiler_renameProperty=a=>a;const pb={toAttribute(a,b){return b===Boolean?a?"":null:b===Object||b===Array?null==a?a:JSON.stringify(a):a},fromAttribute(a,b){return b===Boolean?null!==a:b===Number?null===a?null:+a:b===Object||b===Array?JSON.parse(a):a}},qb=(a,b)=>b!==a&&(b===b||a===a),rb={attribute:!0,type:String,converter:pb,reflect:!1,hasChanged:qb},sb=Promise.resolve(!0),tb=1,ub=4,vb=8,wb=16,xb=32;class yb extends HTMLElement{constructor(){super(),this._updateState=0,this._instanceProperties=void 0,this._updatePromise=sb,this._hasConnectedResolver=void 0,this._changedProperties=new Map,this._reflectingProperties=void 0,this.initialize()}static get observedAttributes(){this.finalize();const a=[];return this._classProperties.forEach((b,c)=>{const d=this._attributeNameForProperty(c,b);void 0!==d&&(this._attributeToPropertyMap.set(d,c),a.push(d))}),a}static _ensureClassProperties(){if(!this.hasOwnProperty(JSCompiler_renameProperty("_classProperties",this))){this._classProperties=new Map;const a=Object.getPrototypeOf(this)._classProperties;a!==void 0&&a.forEach((a,b)=>this._classProperties.set(b,a))}}static createProperty(a,b=rb){if(this._ensureClassProperties(),this._classProperties.set(a,b),b.noAccessor||this.prototype.hasOwnProperty(a))return;const c="symbol"==typeof a?Symbol():"__".concat(a);Object.defineProperty(this.prototype,a,{get(){return this[c]},set(b){const d=this[a];this[c]=b,this._requestUpdate(a,d)},configurable:!0,enumerable:!0})}static finalize(){if(!(this.hasOwnProperty(JSCompiler_renameProperty("finalized",this))&&this.finalized)){const a=Object.getPrototypeOf(this);if("function"==typeof a.finalize&&a.finalize(),this.finalized=!0,this._ensureClassProperties(),this._attributeToPropertyMap=new Map,this.hasOwnProperty(JSCompiler_renameProperty("properties",this))){const a=this.properties,b=[].concat(H(Object.getOwnPropertyNames(a)),H("function"==typeof Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(a):[]));for(const c of b)this.createProperty(c,a[c])}}}static _attributeNameForProperty(a,b){const c=b.attribute;return!1===c?void 0:"string"==typeof c?c:"string"==typeof a?a.toLowerCase():void 0}static _valueHasChanged(a,b,c=qb){return c(a,b)}static _propertyValueFromAttribute(a,b){const c=b.type,d=b.converter||pb,e="function"==typeof d?d:d.fromAttribute;return e?e(a,c):a}static _propertyValueToAttribute(a,b){if(void 0===b.reflect)return;const c=b.type,d=b.converter,e=d&&d.toAttribute||pb.toAttribute;return e(a,c)}initialize(){this._saveInstanceProperties(),this._requestUpdate()}_saveInstanceProperties(){this.constructor._classProperties.forEach((a,b)=>{if(this.hasOwnProperty(b)){const a=this[b];delete this[b],this._instanceProperties||(this._instanceProperties=new Map),this._instanceProperties.set(b,a)}})}_applyInstanceProperties(){this._instanceProperties.forEach((a,b)=>this[b]=a),this._instanceProperties=void 0}connectedCallback(){this._updateState|=xb,this._hasConnectedResolver&&(this._hasConnectedResolver(),this._hasConnectedResolver=void 0)}disconnectedCallback(){}attributeChangedCallback(a,b,c){b!==c&&this._attributeToProperty(a,c)}_propertyToAttribute(a,b,c=rb){const d=this.constructor,e=d._attributeNameForProperty(a,c);if(e!==void 0){const a=d._propertyValueToAttribute(b,c);if(a===void 0)return;this._updateState|=vb,null==a?this.removeAttribute(e):this.setAttribute(e,a),this._updateState&=~vb}}_attributeToProperty(a,b){if(this._updateState&vb)return;const c=this.constructor,d=c._attributeToPropertyMap.get(a);if(d!==void 0){const a=c._classProperties.get(d)||rb;this._updateState|=wb,this[d]=c._propertyValueFromAttribute(b,a),this._updateState&=~wb}}_requestUpdate(a,b){let c=!0;if(a!==void 0){const d=this.constructor,e=d._classProperties.get(a)||rb;d._valueHasChanged(this[a],b,e.hasChanged)?(!this._changedProperties.has(a)&&this._changedProperties.set(a,b),!0===e.reflect&&!(this._updateState&wb)&&(this._reflectingProperties===void 0&&(this._reflectingProperties=new Map),this._reflectingProperties.set(a,e))):c=!1}!this._hasRequestedUpdate&&c&&this._enqueueUpdate()}requestUpdate(a,b){return this._requestUpdate(a,b),this.updateComplete}async _enqueueUpdate(){this._updateState|=ub;let a,b;const c=this._updatePromise;this._updatePromise=new Promise((c,d)=>{a=c,b=d});try{await c}catch(a){}this._hasConnected||(await new Promise(a=>this._hasConnectedResolver=a));try{const a=this.performUpdate();null!=a&&(await a)}catch(a){b(a)}a(!this._hasRequestedUpdate)}get _hasConnected(){return this._updateState&xb}get _hasRequestedUpdate(){return this._updateState&ub}get hasUpdated(){return this._updateState&tb}performUpdate(){this._instanceProperties&&this._applyInstanceProperties();let a=!1;const b=this._changedProperties;try{a=this.shouldUpdate(b),a&&this.update(b)}catch(b){throw a=!1,b}finally{this._markUpdated()}a&&(!(this._updateState&tb)&&(this._updateState|=tb,this.firstUpdated(b)),this.updated(b))}_markUpdated(){this._changedProperties=new Map,this._updateState&=~ub}get updateComplete(){return this._updatePromise}shouldUpdate(a){return!0}update(a){this._reflectingProperties!==void 0&&0this._propertyToAttribute(b,this[b],a)),this._reflectingProperties=void 0)}updated(a){}firstUpdated(a){}}yb.finalized=!0;const zb="adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,Ab=Symbol();class Bb{constructor(a,b){if(b!==Ab)throw new Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=a}get styleSheet(){return void 0===this._styleSheet&&(zb?(this._styleSheet=new CSSStyleSheet,this._styleSheet.replaceSync(this.cssText)):this._styleSheet=null),this._styleSheet}toString(){return this.cssText}}const Cb=a=>{if(a instanceof Bb)return a.cssText;throw new Error("Value passed to 'css' function must be a 'css' function result: ".concat(a,". Use 'unsafeCSS' to pass non-literal values, but\n take care to ensure page security."))};(window.litElementVersions||(window.litElementVersions=[])).push("2.0.1");const Db=a=>a.flat?a.flat(1/0):J(a);class Eb extends yb{static finalize(){super.finalize(),this._styles=this.hasOwnProperty(JSCompiler_renameProperty("styles",this))?this._getUniqueStyles():this._styles||[]}static _getUniqueStyles(){const a=this.styles,b=[];if(Array.isArray(a)){const c=Db(a),d=c.reduceRight((a,b)=>(a.add(b),a),new Set);d.forEach(a=>b.unshift(a))}else a&&b.push(a);return b}initialize(){super.initialize(),this.renderRoot=this.createRenderRoot(),window.ShadowRoot&&this.renderRoot instanceof window.ShadowRoot&&this.adoptStyles()}createRenderRoot(){return this.attachShadow({mode:"open"})}adoptStyles(){const a=this.constructor._styles;0===a.length||(window.ShadyCSS===void 0||window.ShadyCSS.nativeShadow?zb?this.renderRoot.adoptedStyleSheets=a.map(a=>a.styleSheet):this._needsShimAdoptedStyleSheets=!0:window.ShadyCSS.ScopingShim.prepareAdoptedCssText(a.map(a=>a.cssText),this.localName))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&window.ShadyCSS!==void 0&&window.ShadyCSS.styleElement(this)}update(a){super.update(a);const b=this.render();b instanceof Oa&&this.constructor.render(b,this.renderRoot,{scopeName:this.localName,eventContext:this}),this._needsShimAdoptedStyleSheets&&(this._needsShimAdoptedStyleSheets=!1,this.constructor._styles.forEach(a=>{const b=document.createElement("style");b.textContent=a.cssText,this.renderRoot.appendChild(b)}))}render(){}}Eb.finalized=!0,Eb.render=ob;var Fb=function(){try{if("undefined"!=typeof indexedDB)return indexedDB;if("undefined"!=typeof webkitIndexedDB)return webkitIndexedDB;if("undefined"!=typeof mozIndexedDB)return mozIndexedDB;if("undefined"!=typeof OIndexedDB)return OIndexedDB;if("undefined"!=typeof msIndexedDB)return msIndexedDB}catch(a){}}();"undefined"==typeof Promise&&require("lie/polyfill");const Gb="local-forage-detect-blob-support";let Hb;const Ib={},Jb=Object.prototype.toString,Kb="readonly",Lb="readwrite";var Mb={_driver:"asyncStorage",_initStorage:function(a){function b(){return Promise.resolve()}var c=this,d={db:null};if(a)for(var e in a)d[e]=a[e];var f=Ib[d.name];f||(f=ga(),Ib[d.name]=f),f.forages.push(c),c._initReady||(c._initReady=c.ready,c.ready=da);for(var g,h=[],i=0;ia?void b(null):void c.ready().then(function(){fa(c._dbInfo,Kb,function(e,f){if(e)return d(e);try{var g=f.objectStore(c._dbInfo.storeName),h=!1,i=g.openCursor();i.onsuccess=function(){var c=i.result;return c?void(0===a?b(c.key):h?b(c.key):(h=!0,c.advance(a))):void b(null)},i.onerror=function(){d(i.error)}}catch(a){d(a)}})}).catch(d)});return L(d,b),d},keys:function(a){var b=this,c=new Promise(function(a,c){b.ready().then(function(){fa(b._dbInfo,Kb,function(d,e){if(d)return c(d);try{var f=e.objectStore(b._dbInfo.storeName),g=f.openCursor(),h=[];g.onsuccess=function(){var b=g.result;return b?void(h.push(b.key),b.continue()):void a(h)},g.onerror=function(){c(g.error)}}catch(a){c(a)}})}).catch(c)});return L(c,a),c},dropInstance:function(a,b){b=O.apply(this,arguments);var c=this.config();a="function"!=typeof a&&a||{},a.name||(a.name=a.name||c.name,a.storeName=a.storeName||c.storeName);var d,e=this;if(!a.name)d=Promise.reject("Invalid arguments");else{const b=a.name===c.name&&e._dbInfo.db,f=b?Promise.resolve(e._dbInfo.db):Z(a).then(b=>{const c=Ib[a.name],d=c.forages;c.db=b;for(var e=0;e{if(!b.objectStoreNames.contains(a.storeName))return;const c=b.version+1;S(a);const d=Ib[a.name],e=d.forages;b.close();for(let a=0;a{const e=Fb.open(a.name,c);e.onerror=a=>{const b=e.result;b.close(),d(a)},e.onupgradeneeded=()=>{var b=e.result;b.deleteObjectStore(a.storeName)},e.onsuccess=()=>{const a=e.result;a.close(),b(a)}});return f.then(a=>{d.db=a;for(let b=0;b{throw(U(a,b)||Promise.resolve()).catch(()=>{}),b})}):f.then(b=>{S(a);const c=Ib[a.name],d=c.forages;b.close();for(var e=0;e{var d=Fb.deleteDatabase(a.name);d.onerror=d.onblocked=a=>{const b=d.result;b&&b.close(),c(a)},d.onsuccess=()=>{const a=d.result;a&&a.close(),b(a)}});return f.then(a=>{c.db=a;for(var b=0;b{throw(U(a,b)||Promise.resolve()).catch(()=>{}),b})})}return L(d,b),d}},Nb=/^~~local_forage_type~([^~]+)~/,Ob="__lfsc__:".length,Pb=Ob+"arbf".length,Qb=Object.prototype.toString,Rb={serialize:function(a,b){var c="";if(a&&(c=Qb.call(a)),a&&("[object ArrayBuffer]"===c||a.buffer&&"[object ArrayBuffer]"===Qb.call(a.buffer))){var d,e="__lfsc__:";a instanceof ArrayBuffer?(d=a,e+="arbf"):(d=a.buffer,"[object Int8Array]"===c?e+="si08":"[object Uint8Array]"===c?e+="ui08":"[object Uint8ClampedArray]"===c?e+="uic8":"[object Int16Array]"===c?e+="si16":"[object Uint16Array]"===c?e+="ur16":"[object Int32Array]"===c?e+="si32":"[object Uint32Array]"===c?e+="ui32":"[object Float32Array]"===c?e+="fl32":"[object Float64Array]"===c?e+="fl64":b(new Error("Failed to get type for BinaryArray"))),b(e+ia(d))}else if("[object Blob]"===c){var f=new FileReader;f.onload=function(){var c="~~local_forage_type~"+a.type+"~"+ia(this.result);b("__lfsc__:blob"+c)},f.readAsArrayBuffer(a)}else try{b(JSON.stringify(a))}catch(c){console.error("Couldn't convert value into a JSON string: ",a),b(null,c)}},deserialize:function(a){if(a.substring(0,Ob)!=="__lfsc__:")return JSON.parse(a);var b,c=a.substring(Pb),d=a.substring(Ob,Pb);if(d==="blob"&&Nb.test(c)){var e=c.match(Nb);b=e[1],c=c.substring(e[0].length)}var f=ha(c);switch(d){case"arbf":return f;case"blob":return K([f],{type:b});case"si08":return new Int8Array(f);case"ui08":return new Uint8Array(f);case"uic8":return new Uint8ClampedArray(f);case"si16":return new Int16Array(f);case"ur16":return new Uint16Array(f);case"si32":return new Int32Array(f);case"ui32":return new Uint32Array(f);case"fl32":return new Float32Array(f);case"fl64":return new Float64Array(f);default:throw new Error("Unkown type: "+d);}},stringToBuffer:ha,bufferToString:ia},Sb={_driver:"webSQLStorage",_initStorage:function(a){var b=this,c={db:null};if(a)for(var d in a)c[d]="string"==typeof a[d]?a[d]:a[d].toString();var e=new Promise(function(a,d){try{c.db=openDatabase(c.name,c.version+"",c.description,c.size)}catch(a){return d(a)}c.db.transaction(function(e){ja(e,c,function(){b._dbInfo=c,a()},function(a,b){d(b)})},d)});return c.serializer=Rb,e},_support:function(){return"function"==typeof openDatabase}(),iterate:function(a,b){var c=this,d=new Promise(function(b,d){c.ready().then(function(){var e=c._dbInfo;e.db.transaction(function(c){ka(c,e,"SELECT * FROM ".concat(e.storeName),[],function(c,d){for(var f=d.rows,g=f.length,h=0;ha===b||"number"==typeof a&&"number"==typeof b&&isNaN(a)&&isNaN(b),Vb=(a,b)=>{const c=a.length;for(let d=0;d{})}config(a){if("object"==typeof a){if(this._ready)return new Error("Can't call config() after localforage has been used.");for(let b in a){if("storeName"==b&&(a[b]=a[b].replace(/\W/g,"_")),"version"==b&&"number"!=typeof a[b])return new Error("Database version must be a number.");this._config[b]=a[b]}return!("driver"in a&&a.driver)||this.setDriver(this._config.driver)}return"string"==typeof a?this._config[a]:this._config}defineDriver(a,b,c){const d=new Promise(function(b,c){try{const d=a._driver,e=new Error("Custom driver not compliant; see https://mozilla.github.io/localForage/#definedriver");if(!a._driver)return void c(e);const f=ac.concat("_initStorage");for(let b=0,d=f.length;b(null===b._ready&&(b._ready=b._initDriver()),b._ready));return M(c,a,a),c}setDriver(a,b,c){function d(){g._config.driver=g.driver()}function e(a){return g._extend(a),d(),g._ready=g._initStorage(g._config),g._ready}function f(a){return function(){function b(){for(;cPromise.resolve());return this._driverSet=i.then(()=>{const a=h[0];return g._dbInfo=null,g._ready=null,g.getDriver(a).then(a=>{g._driver=a._driver,d(),g._wrapLibraryMethodsWithReady(),g._initDriver=f(h)})}).catch(()=>{d();const a=new Error("No available storage method found.");return g._driverSet=Promise.reject(a),g._driverSet}),M(this._driverSet,b,c),this._driverSet}supports(a){return!!Yb[a]}_extend(a){sa(this,a)}_getSupportedDrivers(a){const b=[];for(let c=0,d=a.length;ca.reduce((a,c)=>+c[b]<+a[b]?c:a,a[0]),mc=(a,b)=>a.reduce((a,c)=>+c[b]>+a[b]?c:a,a[0]),nc=(a,b,c="en-US")=>a.toLocaleString(c,F({hour:"numeric",minute:"numeric"},b)),oc=a=>a*3600*1000,pc=(c,a,b)=>{const d=+c.replace("#","0x"),e=d>>16,f=255&d>>8,g=255&d,h=+a.replace("#","0x");return"#".concat((0|16777216+(e+b*((h>>16)-e)<<16)+(f+b*((255&h>>8)-f)<<8)+(g+b*((255&h)-g))).toString(16).slice(1))};class qc{constructor(a,b,c,d=24,e=1){this.coords=[],this.width=a-2*c[lc],this.height=b-2*c[X],this.margin=c,this._max=0,this._min=0,this.points=e,this.hours=d}get max(){return this._max}set max(a){this._max=a}get min(){return this._min}set min(a){this._min=a}update(a){const b=new Date().getTime(),c=(a,c)=>{var d=Math.floor;const e=b-new Date(c.last_changed).getTime(),f=e/3600000*this.points-this.hours*this.points,g=d(xa(f));return a[g]||(a[g]=[]),a[g].push(c),a},d=a.reduce((a,b)=>c(a,b),[]);d.length=wa(this.hours*this.points),this.coords=this._calcPoints(d),this.min=va.apply(Math,H(this.coords.map(a=>+a[Y]))),this.max=ua.apply(Math,H(this.coords.map(a=>+a[Y])))}_calcPoints(a){var b=Number.isFinite;const c=[];let d=this.width/(this.hours*this.points-1);d=b(d)?d:this.width;const e=a.filter(Boolean)[0];let f=[this._average(e),this._last(e)];const g=(a,b)=>{const e=d*b+this.margin[lc];return a&&(f=[this._average(a),this._last(a)]),c.push([e,0,a?f[0]:f[1]])};for(let b=0;b[a[lc],this.height-(a[Y]-this.min)/b+1*this.margin[X],a[Y]])}getPoints(){const a=this._calcY(this.coords);let b,c,d=a[0];a.shift();const e=a.map((a,e)=>{b=a,c=this._midPoint(d[lc],d[X],b[lc],b[X]);const f=(b[Y]+d[Y])/2;return d=b,[c[lc],c[X],f,e+1]});return e}getPath(){const a=this._calcY(this.coords);let b,c,d="",e=a[0];return d+="M".concat(e[lc],",").concat(e[X]),a.forEach(a=>{b=a,c=this._midPoint(e[lc],e[X],b[lc],b[X]),d+=" ".concat(c[lc],",").concat(c[X]),d+=" Q ".concat(b[lc],",").concat(b[X]),e=b}),d+=" ".concat(b[lc],",").concat(b[X]),d}computeGradient(a){const b=this._max-this._min;return a.map((a,c,d)=>{let e;if(a.value>this._max&&d[c+1]){const b=(this._max-d[c+1].value)/(a.value-d[c+1].value);e=pc(d[c+1].color,a.color,b)}else if(a.value({x:e*f*b+e*a+d,y:c[X],height:this.height-c[X]+3*this.margin[X],width:e-d,value:c[Y]}))}_midPoint(a,b,c,d){return[(a-c)/2+c,(b-d)/2+d]}_average(a){return a.reduce((a,b)=>a+parseFloat(b.state),0)/a.length}_last(a){return parseFloat(a[a.length-1].state)||0}}const rc=((a,...b)=>{const c=b.reduce((b,c,d)=>b+Cb(c)+a[d+1],a[0]);return new Bb(c,Ab)})(D());dc.config({name:"mini-graph-card",version:1,storeName:"entity_history_cache",description:"Mini graph card uses caching for the entity history"});class sc extends Eb{constructor(){super(),this.id=Math.random().toString(36).substr(2,9),this.bound=[0,0],this.abs=[],this.length=[],this.entity=[],this.line=[],this.bar=[],this.fill=[],this.points=[],this.gradient=[],this.tooltip={},this.updateQueue=[],this.updating=!1,this.stateChanged=!1}static get styles(){return rc}set hass(a){this._hass=a;let b=!1;this.config.entities.forEach((c,d)=>{const e=a.states[c.entity];e&&this.entity[d]!==e&&(this.entity[d]=e,this.updateQueue.push(e.entity_id),b=!0)}),b&&(this.entity=H(this.entity),this.config.update_interval||this.updating?this.stateChanged=!0:this.updateData())}static get properties(){return{id:String,_hass:{},config:{},entity:[],Graph:[],line:[],shadow:[],length:Number,bound:[],abs:[],tooltip:{},updateQueue:[],color:String}}setConfig(a){if(a.entity)throw new Error("The \"entity\" option was removed, please use \"entities\".\n See ".concat(ec));if(!Array.isArray(a.entities))throw new Error("Please provide the \"entities\" option as a list.\n See ".concat(ec));if(a.line_color_above||a.line_color_below)throw new Error("\"line_color_above/line_color_below\" was removed, please use \"color_thresholds\".\n See ".concat(ec));const b=F({animate:!1,hour24:!1,font_size:fc,font_size_header:14,height:100,hours_to_show:24,points_per_hour:.5,line_color:[].concat(ic),color_thresholds:[],color_thresholds_transition:"smooth",line_width:5,more_info:!0},a,{show:F({},kc,a.show)});b.entities.forEach((a,c)=>{"string"==typeof a&&(b.entities[c]={entity:a})}),"string"==typeof a.line_color&&(b.line_color=[a.line_color].concat(ic)),b.font_size=a.font_size/100*fc||fc,b.color_thresholds=this.computeThresholds(b.color_thresholds,b.color_thresholds_transition);const c=24gc&&(b.points_per_hour=gc/(b.hours_to_show*a),console.warn("mini-graph-card: Not enough space, adjusting points_per_hour to ",b.points_per_hour))}this.Graph||(this.Graph=b.entities.map(()=>new qc(500,b.height,[b.show.fill?0:b.line_width,b.line_width],b.hours_to_show,b.points_per_hour))),this.config=b}connectedCallback(){super.connectedCallback(),this.config.update_interval&&(this.updateOnInterval(),this.interval=setInterval(()=>this.updateOnInterval(),1e3*this.config.update_interval))}disconnectedCallback(){this.interval&&clearInterval(this.interval),super.disconnectedCallback()}shouldUpdate(a){return!!this.entity[0]&&(jc.some(b=>a.has(b))?(this.color=this.intColor(this.tooltip.value||this.entity[0].state,this.tooltip.entity||0),!0):void 0)}updated(a){this.config.animate&&a.has("line")&&(this.length.length{this.length[a.id]=a.getTotalLength()}),this.length=H(this.length)):this.length=Array(this.entity.length).fill("none"))}render({config:a}=this){return cb(C(),a.group,a.show.graph&&a.show.fill,"hover"===a.show.points,"hover"===a.show.labels,0this.handlePopup(a,this.entity[0]),this.renderHeader(),this.renderStates(),this.renderGraph(),this.renderInfo())}renderHeader(){const{show:a,align_icon:b,align_header:c,font_size_header:d}=this.config;return a.name||a.icon&&"state"!==b?cb(B(),c,d,this.renderName(),"state"===b?"":this.renderIcon()):""}renderIcon(){const{icon:a,icon_adaptive_color:b}=this.config.show;return a?cb(A(),this.config.align_icon,b?"color: ".concat(this.color,";"):"",this.computeIcon(this.entity[0])):""}renderName(){if(!this.config.show.name)return;const a=this.tooltip.entity===void 0?this.config.name||this.computeName(0):this.computeName(this.tooltip.entity),b=this.config.show.name_adaptive_color?"opacity: 1; color: ".concat(this.color,";"):"";return cb(z(),b,a)}renderStates(){const{entity:a,value:b}=this.tooltip,c=b===void 0?this.entity[0].state:b,d=this.config.entities[0].state_adaptive_color?"color: ".concat(this.color,";"):"";if(this.config.show.state)return cb(y(),this.config.align_state,d,this.computeState(c),d,this.computeUom(a||0),this.renderStateTime(),this.config.entities.map((a,b)=>this.renderState(a,b)),"state"===this.config.align_icon?this.renderIcon():"")}renderState(a,b){if(a.show_state&&0!==b){const{state:c}=this.entity[b];return cb(x(),a.state_adaptive_color?"color: ".concat(this.computeColor(c,b),";"):"",a.show_indicator?this.renderIndicator(c,b):"",this.computeState(c),this.computeUom(b))}}renderStateTime(){return void 0===this.tooltip.value?void 0:cb(w(),this.tooltip.label?cb(v(),this.tooltip.label):cb(u(),this.tooltip.time[0],this.tooltip.time[1]))}renderGraph(){return this.config.show.graph?cb(t(),this.renderLabels(),this.renderSvg(),this.renderLegend()):""}renderLegend(){return 1>=this.config.entities.length||!this.config.show.legend?void 0:cb(s(),this.entity.map((a,b)=>cb(r(),b=>this.handlePopup(b,a),()=>this.setTooltip(b,-1,this.entity[b].state,"Current"),()=>this.tooltip={},this.renderIndicator(a.state,b),this.computeName(b))))}renderIndicator(a,b){return db(q(),this.computeColor(a,b))}renderSvgFill(a,b){if(!a)return;const c=this.intColor(this.entity[b].state,b),d="fade"===this.config.show.fill,e=d?"url(#fill-grad-".concat(this.id,"-").concat(b,")"):c;return db(p(),"fill-grad-".concat(this.id,"-").concat(b),c,c,this.tooltip.entity!==void 0&&this.tooltip.entity!==b,this.config.show.fill,b,this.config.animate,this.length[b],this.config.animate?"".concat(.5*b,"s"):"0s",e,e,this.config.line_width,this.fill[b])}renderSvgLine(a,b){if(a){const a=db(o(),b,this.config.animate,this.length[b],this.config.animate?"".concat(.5*b,"s"):"0s",this.length[b]||"none",this.length[b]||"none","white",this.config.line_width,this.line[b]);return db(n(),"line-".concat(this.id,"-").concat(b),a)}}renderSvgPoint(a,b){const c=this.gradient[b]?this.computeColor(a[Y],b):"inherit";return db(m(),this.tooltip.index!==a[3],"--mcg-hover: ".concat(c,";"),c,c,a[lc],a[X],this.config.line_width,()=>this.setTooltip(b,a[3],a[Y]),()=>this.tooltip={})}renderSvgPoints(a,b){if(a){const c=this.computeColor(this.entity[b].state,b);return db(l(),this.tooltip.entity===b,void 0!==this.tooltip.entity&&this.tooltip.entity!==b,this.length[b],this.config.animate&&"hover"!==this.config.show.points,this.config.animate?"".concat(.5*b+.5,"s"):"0s",c,c,this.config.line_width/2,a.map(a=>this.renderSvgPoint(a,b)))}}renderSvgGradient(a){if(a){const b=a.map((a,b)=>a?db(k(),"grad-".concat(this.id,"-").concat(b),a.map(a=>db(j(),a.color,"".concat(a.offset,"%")))):void 0);return db(i(),b)}}renderSvgRect(a,b){if(a){const a=this.gradient[b]?"url(#grad-".concat(this.id,"-").concat(b,")"):this.computeColor(this.entity[b].state,b);return db(h(),void 0!==this.tooltip.entity&&this.tooltip.entity!==b,"rect-".concat(this.id,"-").concat(b),a,"url(#line-".concat(this.id,"-").concat(b,")"))}}renderSvgBars(a,b){if(a){const c=a.map((a,c)=>{const d=this.config.animate?db(g(),this.config.height,a.y):"",e=this.computeColor(a.value,b);return db(f(),a.x,a.y,a.height,a.width,e,()=>this.setTooltip(b,c,a.value),()=>this.tooltip={},d)});return db(e(),this.config.animate,c)}}renderSvg(){const{height:a}=this.config;return db(d(),0===a?0:"100%",a,a=>a.stopPropagation(),this.renderSvgGradient(this.gradient),this.line.map((a,b)=>this.renderSvgLine(a,b)),this.fill.map((a,b)=>this.renderSvgFill(a,b)),this.line.map((a,b)=>this.renderSvgRect(a,b)),this.bar.map((a,b)=>this.renderSvgBars(a,b)),this.points.map((a,b)=>this.renderSvgPoints(a,b)))}setTooltip(a,b,c,d=null){const{points_per_hour:e,hours_to_show:f,format:g}=this.config,h=1>f&&1>e?e*f:1/e,i=xa(b+1-wa(f*e)),j=new Date;j.setMilliseconds(j.getMilliseconds()-oc(h*i));const k=nc(j,{hour12:!this.config.hour24},this._hass.language);j.setMilliseconds(j.getMilliseconds()-oc(h));const l=nc(j,g,this._hass.language);this.tooltip={value:c,id:i,entity:a,time:[l,k],index:b,label:d}}renderLabels(){return this.config.show.labels?cb(c(),this.computeState(this.bound[1]),this.computeState(this.bound[0])):void 0}renderInfo(){return this.config.show.extrema?cb(b(),this.abs.map(b=>cb(a(),b.type,this.computeState(b.state),this.computeUom(0),nc(new Date(b.last_changed),this.config.format,this._hass.language)))):void 0}handlePopup(a,b){a.stopPropagation(),this.config.more_info&&this.fire("hass-more-info",{entityId:b.entity_id})}fire(a,b,c){const d=c||{},f=null===b||void 0===b?{}:b,g=new Event(a,{bubbles:void 0===d.bubbles||d.bubbles,cancelable:!!d.cancelable,composed:void 0===d.composed||d.composed});return g.detail=f,this.dispatchEvent(g),g}computeThresholds(a,b){if(a.sort((c,a)=>a.value-c.value),"smooth"===b)return a;else{var c;const b=(c=[]).concat.apply(c,H(a.map((b,c)=>[b,{value:b.value-1e-4,color:a[c+1]?a[c+1].color:b.color}])));return b}}computeColor(a,b){const{color_thresholds:c,line_color:d}=this.config,e=F({color:d[b]||d[0]},c.slice(-1)[0],c.find(b=>b.value<(+a||0)));return this.config.entities[b].color||e.color}intColor(a,b){const{color_thresholds:c,line_color:d}=this.config,e=+a||0;let f;if(0a.valuea.valuethis.updateEntity(a,d,c,b));await Promise.all(a)}finally{this.updating=!1}this.updateQueue=[],this.bound=[a.lower_bound===void 0?va.apply(Math,H(this.Graph.map(a=>a.min)))||this.bound[0]:a.lower_bound,a.upper_bound===void 0?ua.apply(Math,H(this.Graph.map(a=>a.max)))||this.bound[1]:a.upper_bound],a.show.graph&&(this.entity.forEach((b,c)=>{b&&0!==this.Graph[c].coords.length&&([this.Graph[c].min,this.Graph[c].max]=[this.bound[0],this.bound[1]],"bar"===a.show.graph?this.bar[c]=this.Graph[c].getBars(c,a.entities.length):(this.line[c]=this.Graph[c].getPath(),a.show.fill&&(this.fill[c]=this.Graph[c].getFill(this.line[c])),a.show.points&&(this.points[c]=this.Graph[c].getPoints()),0new Date(a.last_updated)>c),0f&&(f=new Date(a-1))}let i=await this.fetchRecent(a.entity_id,f,d,g);i[0]&&0!ta(parseFloat(a.state))),e=[].concat(H(e),H(i)),dc.setItem(a.entity_id,{hours_to_show:this.config.hours_to_show,last_fetched:d,data:e}).catch(a=>{console.warn("mini-graph-card: Failed to cache: ",a),dc.clear()}));0===e.length||(a.entity_id===this.entity[0].entity_id&&(this.abs=[F({type:"min"},V(e,"state")),F({type:"max"},mc(e,"state"))]),this.Graph[b].update(e))}async fetchRecent(a,b,c,d){let e="history/period";return b&&(e+="/".concat(b.toISOString())),e+="?filter_entity_id=".concat(a),c&&(e+="&end_time=".concat(c.toISOString())),d&&(e+="&skip_initial_state"),this._hass.callApi("GET",e)}getCardSize(){return 3}}customElements.define("mini-graph-card",sc)})})();