Files
homeassistant/config/www/community/battery-state-card/battery-state-card.js
T
2026-08-24 21:55:33 +08:00

113 lines
51 KiB
JavaScript

!function(){"use strict";function t(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o}"function"==typeof SuppressedError&&SuppressedError;
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const e=globalThis,i=e.ShadowRoot&&(void 0===e.ShadyCSS||e.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s=Symbol(),r=new WeakMap;let n=class{constructor(t,e,i){if(this._$cssResult$=!0,i!==s)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(i&&void 0===t){const i=void 0!==e&&1===e.length;i&&(t=r.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&r.set(e,t))}return t}toString(){return this.cssText}};const o=(t,...e)=>{const i=1===t.length?t[0]:e.reduce((e,i,s)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+t[s+1],t[0]);return new n(i,t,s)},a=i?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return(t=>new n("string"==typeof t?t:t+"",void 0,s))(e)})(t):t,{is:l,defineProperty:c,getOwnPropertyDescriptor:d,getOwnPropertyNames:h,getOwnPropertySymbols:u,getPrototypeOf:p}=Object,f=globalThis,g=f.trustedTypes,v=g?g.emptyScript:"",y=f.reactiveElementPolyfillSupport,m=(t,e)=>t,b={toAttribute(t,e){switch(e){case Boolean:t=t?v:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(t){i=null}}return i}},_=(t,e)=>!l(t,e),$={attribute:!0,type:String,converter:b,reflect:!1,useDefault:!1,hasChanged:_};
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/Symbol.metadata??=Symbol("metadata"),f.litPropertyMetadata??=new WeakMap;let w=class extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,e=$){if(e.state&&(e.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((e=Object.create(e)).wrapped=!0),this.elementProperties.set(t,e),!e.noAccessor){const i=Symbol(),s=this.getPropertyDescriptor(t,i,e);void 0!==s&&c(this.prototype,t,s)}}static getPropertyDescriptor(t,e,i){const{get:s,set:r}=d(this.prototype,t)??{get(){return this[e]},set(t){this[e]=t}};return{get:s,set(e){const n=s?.call(this);r?.call(this,e),this.requestUpdate(t,n,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??$}static _$Ei(){if(this.hasOwnProperty(m("elementProperties")))return;const t=p(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(m("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(m("properties"))){const t=this.properties,e=[...h(t),...u(t)];for(const i of e)this.createProperty(i,t[i])}const t=this[Symbol.metadata];if(null!==t){const e=litPropertyMetadata.get(t);if(void 0!==e)for(const[t,i]of e)this.elementProperties.set(t,i)}this._$Eh=new Map;for(const[t,e]of this.elementProperties){const i=this._$Eu(t,e);void 0!==i&&this._$Eh.set(i,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(a(t))}else void 0!==t&&e.push(a(t));return e}static _$Eu(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(t=>this.enableUpdating=t),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(t=>t(this))}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.()}removeController(t){this._$EO?.delete(t)}_$E_(){const t=new Map,e=this.constructor.elementProperties;for(const i of e.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return((t,s)=>{if(i)t.adoptedStyleSheets=s.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const i of s){const s=document.createElement("style"),r=e.litNonce;void 0!==r&&s.setAttribute("nonce",r),s.textContent=i.cssText,t.appendChild(s)}})(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(t=>t.hostConnected?.())}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach(t=>t.hostDisconnected?.())}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$ET(t,e){const i=this.constructor.elementProperties.get(t),s=this.constructor._$Eu(t,i);if(void 0!==s&&!0===i.reflect){const r=(void 0!==i.converter?.toAttribute?i.converter:b).toAttribute(e,i.type);this._$Em=t,null==r?this.removeAttribute(s):this.setAttribute(s,r),this._$Em=null}}_$AK(t,e){const i=this.constructor,s=i._$Eh.get(t);if(void 0!==s&&this._$Em!==s){const t=i.getPropertyOptions(s),r="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:b;this._$Em=s;const n=r.fromAttribute(e,t.type);this[s]=n??this._$Ej?.get(s)??n,this._$Em=null}}requestUpdate(t,e,i,s=!1,r){if(void 0!==t){const n=this.constructor;if(!1===s&&(r=this[t]),i??=n.getPropertyOptions(t),!((i.hasChanged??_)(r,e)||i.useDefault&&i.reflect&&r===this._$Ej?.get(t)&&!this.hasAttribute(n._$Eu(t,i))))return;this.C(t,e,i)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(t,e,{useDefault:i,reflect:s,wrapped:r},n){i&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,n??e??this[t]),!0!==r||void 0!==n)||(this._$AL.has(t)||(this.hasUpdated||i||(e=void 0),this._$AL.set(t,e)),!0===s&&this._$Em!==t&&(this._$Eq??=new Set).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,e]of this._$Ep)this[t]=e;this._$Ep=void 0}const t=this.constructor.elementProperties;if(t.size>0)for(const[e,i]of t){const{wrapped:t}=i,s=this[e];!0!==t||this._$AL.has(e)||void 0===s||this.C(e,void 0,i,s)}}let t=!1;const e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),this._$EO?.forEach(t=>t.hostUpdate?.()),this.update(e)):this._$EM()}catch(e){throw t=!1,this._$EM(),e}t&&this._$AE(e)}willUpdate(t){}_$AE(t){this._$EO?.forEach(t=>t.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&=this._$Eq.forEach(t=>this._$ET(t,this[t])),this._$EM()}updated(t){}firstUpdated(t){}};w.elementStyles=[],w.shadowRootOptions={mode:"open"},w[m("elementProperties")]=new Map,w[m("finalized")]=new Map,y?.({ReactiveElement:w}),(f.reactiveElementVersions??=[]).push("2.1.2");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const A=globalThis,E=t=>t,S=A.trustedTypes,x=S?S.createPolicy("lit-html",{createHTML:t=>t}):void 0,N="$lit$",C=`lit$${Math.random().toFixed(9).slice(2)}$`,k="?"+C,O=`<${k}>`,U=document,P=()=>U.createComment(""),T=t=>null===t||"object"!=typeof t&&"function"!=typeof t,I=Array.isArray,M="[ \t\n\f\r]",R=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,j=/-->/g,H=/>/g,D=RegExp(`>|${M}(?:([^\\s"'>=/]+)(${M}*=${M}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),z=/'/g,W=/"/g,B=/^(?:script|style|textarea|title)$/i,L=(t=>(e,...i)=>({_$litType$:t,strings:e,values:i}))(1),V=Symbol.for("lit-noChange"),q=Symbol.for("lit-nothing"),J=new WeakMap,F=U.createTreeWalker(U,129);function K(t,e){if(!I(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==x?x.createHTML(e):e}const X=(t,e)=>{const i=t.length-1,s=[];let r,n=2===e?"<svg>":3===e?"<math>":"",o=R;for(let e=0;e<i;e++){const i=t[e];let a,l,c=-1,d=0;for(;d<i.length&&(o.lastIndex=d,l=o.exec(i),null!==l);)d=o.lastIndex,o===R?"!--"===l[1]?o=j:void 0!==l[1]?o=H:void 0!==l[2]?(B.test(l[2])&&(r=RegExp("</"+l[2],"g")),o=D):void 0!==l[3]&&(o=D):o===D?">"===l[0]?(o=r??R,c=-1):void 0===l[1]?c=-2:(c=o.lastIndex-l[2].length,a=l[1],o=void 0===l[3]?D:'"'===l[3]?W:z):o===W||o===z?o=D:o===j||o===H?o=R:(o=D,r=void 0);const h=o===D&&t[e+1].startsWith("/>")?" ":"";n+=o===R?i+O:c>=0?(s.push(a),i.slice(0,c)+N+i.slice(c)+C+h):i+C+(-2===c?e:h)}return[K(t,n+(t[i]||"<?>")+(2===e?"</svg>":3===e?"</math>":"")),s]};class G{constructor({strings:t,_$litType$:e},i){let s;this.parts=[];let r=0,n=0;const o=t.length-1,a=this.parts,[l,c]=X(t,e);if(this.el=G.createElement(l,i),F.currentNode=this.el.content,2===e||3===e){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes)}for(;null!==(s=F.nextNode())&&a.length<o;){if(1===s.nodeType){if(s.hasAttributes())for(const t of s.getAttributeNames())if(t.endsWith(N)){const e=c[n++],i=s.getAttribute(t).split(C),o=/([.?@])?(.*)/.exec(e);a.push({type:1,index:r,name:o[2],strings:i,ctor:"."===o[1]?et:"?"===o[1]?it:"@"===o[1]?st:tt}),s.removeAttribute(t)}else t.startsWith(C)&&(a.push({type:6,index:r}),s.removeAttribute(t));if(B.test(s.tagName)){const t=s.textContent.split(C),e=t.length-1;if(e>0){s.textContent=S?S.emptyScript:"";for(let i=0;i<e;i++)s.append(t[i],P()),F.nextNode(),a.push({type:2,index:++r});s.append(t[e],P())}}}else if(8===s.nodeType)if(s.data===k)a.push({type:2,index:r});else{let t=-1;for(;-1!==(t=s.data.indexOf(C,t+1));)a.push({type:7,index:r}),t+=C.length-1}r++}}static createElement(t,e){const i=U.createElement("template");return i.innerHTML=t,i}}function Q(t,e,i=t,s){if(e===V)return e;let r=void 0!==s?i._$Co?.[s]:i._$Cl;const n=T(e)?void 0:e._$litDirective$;return r?.constructor!==n&&(r?._$AO?.(!1),void 0===n?r=void 0:(r=new n(t),r._$AT(t,i,s)),void 0!==s?(i._$Co??=[])[s]=r:i._$Cl=r),void 0!==r&&(e=Q(t,r._$AS(t,e.values),r,s)),e}class Z{constructor(t,e){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:e},parts:i}=this._$AD,s=(t?.creationScope??U).importNode(e,!0);F.currentNode=s;let r=F.nextNode(),n=0,o=0,a=i[0];for(;void 0!==a;){if(n===a.index){let e;2===a.type?e=new Y(r,r.nextSibling,this,t):1===a.type?e=new a.ctor(r,a.name,a.strings,this,t):6===a.type&&(e=new rt(r,this,t)),this._$AV.push(e),a=i[++o]}n!==a?.index&&(r=F.nextNode(),n++)}return F.currentNode=U,s}p(t){let e=0;for(const i of this._$AV)void 0!==i&&(void 0!==i.strings?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class Y{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,e,i,s){this.type=2,this._$AH=q,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=s,this._$Cv=s?.isConnected??!0}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t?.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=Q(this,t,e),T(t)?t===q||null==t||""===t?(this._$AH!==q&&this._$AR(),this._$AH=q):t!==this._$AH&&t!==V&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):(t=>I(t)||"function"==typeof t?.[Symbol.iterator])(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==q&&T(this._$AH)?this._$AA.nextSibling.data=t:this.T(U.createTextNode(t)),this._$AH=t}$(t){const{values:e,_$litType$:i}=t,s="number"==typeof i?this._$AC(t):(void 0===i.el&&(i.el=G.createElement(K(i.h,i.h[0]),this.options)),i);if(this._$AH?._$AD===s)this._$AH.p(e);else{const t=new Z(s,this),i=t.u(this.options);t.p(e),this.T(i),this._$AH=t}}_$AC(t){let e=J.get(t.strings);return void 0===e&&J.set(t.strings,e=new G(t)),e}k(t){I(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,s=0;for(const r of t)s===e.length?e.push(i=new Y(this.O(P()),this.O(P()),this,this.options)):i=e[s],i._$AI(r),s++;s<e.length&&(this._$AR(i&&i._$AB.nextSibling,s),e.length=s)}_$AR(t=this._$AA.nextSibling,e){for(this._$AP?.(!1,!0,e);t!==this._$AB;){const e=E(t).nextSibling;E(t).remove(),t=e}}setConnected(t){void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t))}}class tt{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,i,s,r){this.type=1,this._$AH=q,this._$AN=void 0,this.element=t,this.name=e,this._$AM=s,this.options=r,i.length>2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=q}_$AI(t,e=this,i,s){const r=this.strings;let n=!1;if(void 0===r)t=Q(this,t,e,0),n=!T(t)||t!==this._$AH&&t!==V,n&&(this._$AH=t);else{const s=t;let o,a;for(t=r[0],o=0;o<r.length-1;o++)a=Q(this,s[i+o],e,o),a===V&&(a=this._$AH[o]),n||=!T(a)||a!==this._$AH[o],a===q?t=q:t!==q&&(t+=(a??"")+r[o+1]),this._$AH[o]=a}n&&!s&&this.j(t)}j(t){t===q?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class et extends tt{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===q?void 0:t}}class it extends tt{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==q)}}class st extends tt{constructor(t,e,i,s,r){super(t,e,i,s,r),this.type=5}_$AI(t,e=this){if((t=Q(this,t,e,0)??q)===V)return;const i=this._$AH,s=t===q&&i!==q||t.capture!==i.capture||t.once!==i.once||t.passive!==i.passive,r=t!==q&&(i===q||s);s&&this.element.removeEventListener(this.name,this,i),r&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t)}}class rt{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){Q(this,t)}}const nt=A.litHtmlPolyfillSupport;nt?.(G,Y),(A.litHtmlVersions??=[]).push("3.3.2");const ot=globalThis;
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/class at extends w{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=((t,e,i)=>{const s=i?.renderBefore??e;let r=s._$litPart$;if(void 0===r){const t=i?.renderBefore??null;s._$litPart$=r=new Y(e.insertBefore(P(),t),t,void 0,i??{})}return r._$AI(t),r})(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return V}}at._$litElement$=!0,at.finalized=!0,ot.litElementHydrateSupport?.({LitElement:at});const lt=ot.litElementPolyfillSupport;lt?.({LitElement:at}),(ot.litElementVersions??=[]).push("4.2.2");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const ct={attribute:!0,type:String,converter:b,reflect:!1,hasChanged:_},dt=(t=ct,e,i)=>{const{kind:s,metadata:r}=i;let n=globalThis.litPropertyMetadata.get(r);if(void 0===n&&globalThis.litPropertyMetadata.set(r,n=new Map),"setter"===s&&((t=Object.create(t)).wrapped=!0),n.set(i.name,t),"accessor"===s){const{name:s}=i;return{set(i){const r=e.get.call(this);e.set.call(this,i),this.requestUpdate(s,r,t,!0,i)},init(e){return void 0!==e&&this.C(s,void 0,t,e),e}}}if("setter"===s){const{name:s}=i;return function(i){const r=this[s];e.call(this,i),this.requestUpdate(s,r,t,!0,i)}}throw Error("Unsupported decorator location: "+s)};function ht(t){return(e,i)=>"object"==typeof i?dt(t,e,i):((t,e,i)=>{const s=e.hasOwnProperty(i);return e.constructor.createProperty(i,t),s?Object.getOwnPropertyDescriptor(e,i):void 0})(t,e,i)}const ut=new Set,pt=(t,e="warn")=>{const i=`${e}:${t}`;ut.has(i)||(ut.add(i),console[e]("[battery-state-card] "+t))},ft=t=>null!=t&&"boolean"!=typeof t&&("string"==typeof t&&(t=t.replace(",",".")),""!==t&&!isNaN(Number(t))),gt=t=>("string"==typeof t&&(t=t.replace(",",".")),Number(t)),vt={m:6e4,h:36e5,d:864e5,w:6048e5},yt=t=>{const e=t.match(/^(\d+(?:\.\d+)?)\s*([mhdw])$/);if(e)return parseFloat(e[1])*vt[e[2]]},mt=t=>Array.isArray(t)?t:void 0!==t?[t]:[],bt=(t,e)=>mt(t).map(t=>_t(t,e)),_t=(t,e)=>{switch(typeof t){case"string":const i={};return i[e]=t,i;case"object":return{...t}}return t},$t=/\/(.*?)\/([igm]{1,3})/,wt=t=>{try{if("/"==t[0]&&"/"==t[t.length-1])return new RegExp(t.substr(1,t.length-2));{let e=t.match($t);if(e&&3==e.length)return new RegExp(e[1],e[2])}}catch(e){pt(`Invalid regex pattern: ${t}`)}return null},At=(t,e)=>{const i=e.split(".");for(let e=0;e<i.length&&void 0!==(t=t[i[e]]);e++);return null!==t&&"object"==typeof t&&(t=JSON.stringify(t)),t};class Et{constructor(t){this.accessor=t}process(t){return t?t.replace(/\{([^\}]+)\}/g,(t,e)=>this.replaceKeyword(e,"")):""}replaceKeyword(t,e){const i=t.split("|"),s=i.shift(),r=this.getValue(s);if(void 0===r)return e;if(0===i.length)return r;const n=Nt(r,i);return void 0===n?e:n}getValue(t){if(void 0===t)return t;if(this.accessor){let e=this.accessor.resolve(t);return"object"==typeof e&&(e=JSON.stringify(e)),void 0===e?void 0:e.toString()}}}const St=/(?<func>[a-z]+)\((?<params>[^\)]*)\)/,xt={replace:t=>{const e=t.indexOf(",");if(-1==e)return void pt("'replace' function requires two params");const i=[t.substring(0,e),t.substring(e+1)];return t=>t.replace(i[0],i[1])},round:t=>{let e=parseInt(t);return isNaN(e)&&(e=0),t=>parseFloat(t).toFixed(e)},multiply:t=>{if(""===t)return pt("[KString]multiply function is missing parameter"),t=>t;const e=Number(t);return t=>isNaN(e)?t:(Number(t)*e).toString()},greaterthan:t=>{const e=t.split(",");if(2!=e.length)return pt("[KString]greaterthan function requires two parameters"),t=>t;const i=Number(e[0]);return t=>Number(t)>i?e[1]:t},lessthan:t=>{const e=t.split(",");if(2!=e.length)return pt("[KString]lessthan function requires two parameters"),t=>t;const i=Number(e[0]);return t=>Number(t)<i?e[1]:t},between:t=>{const e=t.split(",");if(3!=e.length)return pt("[KString]between function requires three parameters"),t=>t;const i=Number(e[0]),s=Number(e[1]);return t=>{const r=Number(t);return i<=r&&s>=r?e[2]:t}},thresholds:t=>{const e=t.split(",").map(t=>Number(t));return t=>{const i=Number(t),s=e.findIndex(t=>i<t);return-1==s?"100":Math.round(100/e.length*s).toString()}},abs:()=>t=>Math.abs(Number(t)).toString(),equals:t=>{const e=t.split(",");return 2!=e.length?(pt("[KString]equals function requires two parameters"),t=>t):t=>t==e[0]?e[1]:t},add:t=>{if(""===t)return pt("[KString]add function is missing parameter"),t=>t;const e=Number(t);return t=>isNaN(e)?t:(Number(t)+e).toString()},reltime:()=>t=>{const e=Date.parse(t);return isNaN(e)?(pt("[KString]value isn't a valid date: "+t),t):`<rt>${t}</rt>`}},Nt=(t,e)=>{const i=e.map(t=>{const e=St.exec(t);if(e&&e.groups&&xt[e.groups.func])return xt[e.groups.func](e.groups.params)}).filter(t=>void 0!==t).reduce((t,e)=>e(t),t);return void 0===i?"":i},Ct="mdi:battery-unknown",kt="<default_icon>",Ot=new RegExp("<rt>([^<]+)</rt>","g"),Ut=(t,e)=>{if(!t)return[];const i=[];let s,r=0;for(;s=Ot.exec(t);){const n=s.index;n!==r&&i.push(L`${t.substring(r,n)}`),i.push(L`<ha-relative-time .hass="${e}" .datetime="${new Date(s[1])}"></ha-relative-time>`),r=n+s[0].length}return r<t.length&&i.push(L`${t.substring(r)}`),i},Pt=(t,e)=>t&&L`
<div class="icon">
<ha-icon
style="color: ${e}"
icon="${t}"
></ha-icon>
</div>
`,Tt=t=>{return L`
${t.dynamicStyles?L`<style>${t.dynamicStyles}</style>`:""}
${(t=>{var e;return t.icon===kt?L`
<div class="icon">
<ha-state-icon
style="color: ${t.iconColor}"
.hass="${t.hass}"
.stateObj="${null===(e=t.accessor)||void 0===e?void 0:e.state}"
></ha-state-icon>
</div>
`:Pt(t.icon,t.iconColor)})(t)}
<div class="name truncate">
${t.name}
${e=t.secondaryInfo,i=t.hass,e&&L`
<div class="secondary">${Ut(e,i)}</div>
`}
</div>
<div class="state">
${Ut(t.state,t.hass)}${It(t.unit)}
</div>
`;var e,i},It=t=>t&&L`&nbsp;${t}`,Mt=t=>{const e=[{text:"Show / hide",action:t=>{var e,i,s;const r=null===(s=null===(i=null===(e=t.currentTarget)||void 0===e?void 0:e.parentElement)||void 0===i?void 0:i.parentElement)||void 0===s?void 0:s.querySelector(".debug_expand");r&&(r.style.display="none"===r.style.display?"block":"none")}}];return navigator.clipboard&&e.push({text:"Copy to clipboard",action:()=>navigator.clipboard.writeText(t)}),L`<div>${e.length&&L`${e.map(t=>L`[<a href="javascript:void(0);" @click="${e=>t.action(e)}">${t.text}</a>] `)}`}</div>
<div class="debug_expand" style="display: none;">
<p>Version: 4.2.0</p>
<pre style="user-select: all">${t}</pre>
</div>`};class Rt extends at{constructor(){super(...arguments),this.updateNotifyQueue=[],this.configUpdated=!1,this.hassUpdated=!1,this.triggerUpdate=function(t,e){let i;return(...s)=>{i&&(clearTimeout(i),i=null),i=setTimeout(()=>t.apply(null,s),e)}}(async()=>{this.alert=void 0;try{await this.internalUpdate(this.configUpdated,this.hassUpdated),this.error=void 0}catch(t){"string"==typeof t?this.error={message:t,name:""}:t instanceof Error&&(this.error=t)}this.configUpdated&&this.requestUpdate(),this.configUpdated=!1,this.hassUpdated=!1,this.updateNotifyQueue.forEach(t=>t()),this.updateNotifyQueue=[]},100)}set hass(t){this._hass=t,this.hassUpdated=!0,this.triggerUpdate()}get hass(){return this._hass}get cardUpdated(){return new Promise(t=>this.updateNotifyQueue.push(t))}setConfig(t){this.config=JSON.parse(JSON.stringify(t)),this.configUpdated=!0,this.triggerUpdate()}render(){return this.error?(this.onError(),jt(this.tagName,"Exception: "+this.error.message,this.error.stack)):this.alert?L`<ha-alert alert-type="${this.alert.type||"warning"}" title="${this.alert.title||this.tagName}">${this.alert.content}</ha-alert>`:this.internalRender()}}t([ht({attribute:!1})],Rt.prototype,"error",void 0),t([ht({attribute:!1})],Rt.prototype,"alert",void 0);const jt=(t,e,i)=>L`
<ha-alert alert-type="error" title="${t}">
<p>
<strong>${e}</strong>
<p>
<ol>
<li>
Please check if the problem was reported already<br />
Click <a target="_blank" href="https://github.com/maxwroc/battery-state-card/issues?q=is%3Aissue+${encodeURIComponent(e)}">here</a> to search
</li>
<li>
If it wasn't please consider creating one<br />
Click <a target="_blank" href="https://github.com/maxwroc/battery-state-card/issues/new?assignees=&labels=bug&projects=&template=bug_report.md&title=${encodeURIComponent(e)}">here</a> to create<br />
Please copy-paste the below stack trace.
</li>
</ol>
<pre>${i}</pre>
</ha-alert>
`;var Ht="\n:host(.clickable),\n.clickable {\n cursor: pointer;\n}\n\n\n\n.truncate {\n white-space: nowrap;\n text-overflow: ellipsis;\n overflow: hidden;\n}\n\n.name {\n flex: 1;\n margin: 0 6px;\n}\n\n.secondary {\n color: var(--secondary-text-color);\n}\n\n.icon {\n flex: 0 0 40px;\n border-radius: 50%;\n text-align: center;\n line-height: 40px;\n margin-right: 10px;\n color: var(--paper-item-icon-color)\n}";const Dt=(t,e)=>{const i=new Et(e),s={...t};for(const t of["tap_action","hold_action","double_tap_action"]){const e=s[t];e&&"object"==typeof e&&(s[t]=zt(e,i))}return s},zt=(t,e)=>{const i={...t},s=["navigation_path","url_path","service"];for(const t of s)i[t]&&"string"==typeof i[t]&&(i[t]=e.process(i[t]));const r=["service_data","data","target"];for(const t of r)i[t]&&(i[t]=Wt(i[t],e));return i},Wt=(t,e)=>{if("string"==typeof t)return e.process(t);if(Array.isArray(t))return t.map(t=>Wt(t,e));if(t&&"object"==typeof t){const i={};for(const s in t)t.hasOwnProperty(s)&&(i[s]=Wt(t[s],e));return i}return t},Bt=(t,e,i,s)=>{const r=new Event(e,{bubbles:!0,cancelable:!0,composed:!0});r.detail=i,t.dispatchEvent(r)},Lt=(t,e,i)=>{let s=t.map(t=>t.color);if(!Xt(s))return pt("For gradient colors you need to use hex HTML colors. E.g. '#FF00FF'","error"),Vt;if(s.length<2)return pt("For gradient colors you need to specify at least two steps/colors","error"),Vt;if(t.every(t=>null!=t.value)){const r=t[0];if(e<=r.value)return r.color;const n=Qt(t);if(e>=n.value)return n.color;const o=t.findIndex(t=>e<=t.value);-1!=o?(s=[t[o-1].color,t[o].color],e=100*(e-t[o-1].value)/(t[o].value-t[o-1].value)):(null==i&&t.some(t=>t.value<0||t.value>100)||!0===i)&&(e=Gt(t,e))}else if(e<0||e>100)return pt("Entity state value seems to be outside of 0-100 range and color step values are not defined"),Vt;return Kt(s,e)},Vt="inherit",qt=[{value:20,color:"var(--label-badge-red)"},{value:55,color:"var(--label-badge-yellow)"},{value:100,color:"var(--label-badge-green)"}],Jt=/^#[A-Fa-f0-9]{6}$/,Ft=t=>(t=t.replace("#",""),{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16)}),Kt=function(t,e){e/=100;const i=t.map((e,i)=>({pct:1/(t.length-1)*i,color:Ft(e)}));let s=1;for(s=1;s<i.length-1&&!(e<i[s].pct);s++);const r=i[s-1],n=i[s],o=n.pct-r.pct,a=(e-r.pct)/o,l=1-a,c=a,d={r:Math.floor(r.color.r*l+n.color.r*c),g:Math.floor(r.color.g*l+n.color.g*c),b:Math.floor(r.color.b*l+n.color.b*c)};return"#"+[d.r,d.g,d.b].map(t=>t.toString(16).padStart(2,"0")).join("")},Xt=t=>{if(t.length<2)return pt("Value for 'color_gradient' should be an array with at least 2 colors."),!1;for(const e of t)if(!Jt.test(e))return pt(`Color '${e}' is not valid. Please provide valid HTML hex color in #XXXXXX format.`),!1;return!0},Gt=(t,e)=>{const i=t.map((t,e)=>void 0===t.value?e:t.value).sort((t,e)=>t-e),s=i[i.length-1]-i[0],r=e-i[0];return Math.round(r/s*100)},Qt=t=>t&&t.length>0?t[t.length-1]:{},Zt=(t,e)=>{var i,s;if(!t||!e||0===e.length)return!1;for(const r of e){if("enum"===r.device_class)return["charging","full"].includes(null===(i=t.states[r.entity_id])||void 0===i?void 0:i.state);if(r.entity_id.startsWith("binary_sensor.")&&"plug"===r.device_class)return"on"===(null===(s=t.states[r.entity_id])||void 0===s?void 0:s.state)}return!1},Yt=(t,e)=>(void 0===t||e.split(".").forEach(e=>{t=t?t[e]:void 0}),t),te=/\b([0-9]{1,3})\s?%/,ee=/(-?[0-9,.]+)\s?(.*)/,ie=(t,e,i,s,r)=>{var n;return i=s.unit?s.unit:i||(null===(n=null==r?void 0:r.states[s.entity])||void 0===n?void 0:n.attributes.unit_of_measurement)||"%",(!ft(t)||e&&!ft(e))&&(i=void 0),i},se=(t,e)=>mt(e).reduce((t,e)=>{const i=wt(e.from);return t=i?t.replace(i,e.to||""):t.replace(e.from,e.to||"")},t),re=["automation","binary_sensor","button","calendar","camera","climate","device_tracker","group","input_boolean","input_datetime","input_number","input_select","input_text","light","media_player","number","person","remote","scene","script","select","sensor","switch","update","weather","zone"];class ne{constructor(t,e){this.hass=t,this.entityId=e,this._computed={}}get state(){return this.hass.states[this.entityId]}get attributes(){var t;return null===(t=this.state)||void 0===t?void 0:t.attributes}get entity(){var t;return null===(t=this.hass.entities)||void 0===t?void 0:t[this.entityId]}get device(){var t,e;return(null===(t=this.entity)||void 0===t?void 0:t.device_id)?null===(e=this.hass.devices)||void 0===e?void 0:e[this.entity.device_id]:void 0}get area(){var t,e,i;const s=(null===(t=this.entity)||void 0===t?void 0:t.area_id)||(null===(e=this.device)||void 0===e?void 0:e.area_id);return s?null===(i=this.hass.areas)||void 0===i?void 0:i[s]:void 0}get computed(){return this._computed}setComputed(t,e){this._computed[t]=e}resolve(t){const e=t.split(".");if(re.includes(e[0])){const t=e[0]+"."+e[1],i=this.hass.states[t];if(!i)return;const s=e.slice(2).join(".");return s?At(i,s):i.state}if(t.startsWith("entity."))return this.entity?At(this.entity,t.substring(7)):void 0;if(t.startsWith("device."))return this.device?At(this.device,t.substring(7)):void 0;if(t.startsWith("area."))return this.area?At(this.area,t.substring(5)):void 0;if(t.startsWith("computed."))return At(this._computed,t.substring(9));if(this.state){const e=At(this.state,t);if(void 0!==e)return e}return At(this._computed,t)}toDebugJSON(){return JSON.stringify({...this.state,entity:this.entity,device:this.device,area:this.area,computed:this._computed},null,2)}}class oe extends Rt{constructor(){super(...arguments),this.dynamicStyles=""}static get styles(){return o([Ht+":host {\n display: flex;\n align-items: center;\n}\n:host > ha-alert {\n flex: 1 0 auto;\n}\n"])}async internalUpdate(){var t,e,i;if(this.accessor=new ne(this.hass,this.config.entity),!this.accessor.state)return void(this.alert={type:"warning",title:(null===(t=this.hass)||void 0===t?void 0:t.localize("ui.panel.lovelace.warning.entity_not_found","entity",this.config.entity))||`Entity not available: ${this.config.entity}`});let s=[];var r,n,o;!1!==this.config.extend_entity_data&&(r=this.hass,n=this.config.entity,s=(o=null===(e=this.accessor.entity)||void 0===e?void 0:e.device_id)&&r.entities?Object.values(r.entities).filter(t=>t.device_id===o&&t.entity_id!==n).map(t=>{var e,i;const s=r.states[t.entity_id];return{entity_id:t.entity_id,device_class:null===(e=null==s?void 0:s.attributes)||void 0===e?void 0:e.device_class,state_class:null===(i=null==s?void 0:s.attributes)||void 0===i?void 0:i.state_class}}):[],this.accessor.setComputed("siblings",s),this.showEntity());var{state:a,level:l,unit:c}=((t,e,i)=>{var s,r,n,o,a,l;const c=(null==e?void 0:e.localize("state.default.unknown"))||"Unknown";let d,h;const u=new Et(i);if(void 0!==t.value_override){const i=u.process(t.value_override.toString());return{state:i,level:ft(i)?gt(i):void 0,unit:ie(i,void 0,void 0,t,e)}}if(!(null==i?void 0:i.state))return{state:c};const p=i.state,f=p.state;if(t.attribute)d=null===(r=null===(s=i.attributes)||void 0===s?void 0:s[t.attribute])||void 0===r?void 0:r.toString(),null==d&&(pt(`Attribute "${t.attribute}" doesn't exist on "${t.entity}" entity`),d=c);else{const e=[t.non_battery_entity?null:null===(n=i.attributes)||void 0===n?void 0:n.battery_level,t.non_battery_entity?null:null===(o=i.attributes)||void 0===o?void 0:o.battery,f];d=(null===(a=e.find(t=>ft(t)))||void 0===a?void 0:a.toString())||(null===(l=e.find(t=>null!=t))||void 0===l?void 0:l.toString())||c}let g;if(t.state_map){const e=t.state_map.find(t=>t.from===d);void 0===e?ft(d)||pt(`Missing option for '${d}' in 'state_map.'`):(d=e.to.toString(),void 0!==e.display&&(g=u.process(e.display)))}if(!ft(d)){const t=te.exec(d);null!=t&&(d=t[1])}if(ft(d)?(t.multiplier&&(d=(t.multiplier*gt(d)).toString()),"number"==typeof t.round&&(d=parseFloat(d).toFixed(t.round).toString())):d=d.charAt(0).toUpperCase()+d.slice(1),!1!==t.default_state_formatting&&!g&&d===f&&e){const t=e.formatEntityState(p).match(ee);null!=t&&(d=t[1],h=t[2]||h)}return{state:g||d,level:ft(d)?gt(d):void 0,unit:ie(d,g,h,t,e)}})(this.config,this.hass,this.accessor);this.state=a,this.unit=c,this.stateNumeric=l;const d=((t,e,i,s)=>{const r=t.charging_state;if(!r)return Zt(i,s);let n=i.states[t.entity];if(!n)return pt(`Entity (${t.entity}) not found.`,"error"),!1;if(r.entity_id){if(n=i.states[r.entity_id],!n)return pt(`'charging_state' entity id (${r.entity_id}) not found.`,"error"),!1;e=n.state}const o=mt(r.attribute);if(0!=o.length){const t=o.find(t=>void 0!==Yt(n.attributes,t.name));return!!t&&(void 0===t.value||Yt(n.attributes,t.name)==t.value)}const a=mt(r.state);return 0==a.length?!!e:a.some(t=>t==e)})(this.config,this.state,this.hass,s),h=(null===(i=this.config.charging_state)||void 0===i?void 0:i.secondary_info_text)||"Charging",u=new Et(this.accessor);this.accessor.setComputed("charging",{text:d?u.process(h):"",is_active:d}),this.accessor.setComputed("state",this.state),!0!==this.config.debug&&this.config.debug!==this.config.entity||(this.alert={title:`Debug: ${this.config.entity}`,content:Mt(this.accessor.toDebugJSON())}),this.name=((t,e)=>{var i,s;if(t.name)return new Et(e).process(t.name);let r=null===(i=e.attributes)||void 0===i?void 0:i.friendly_name;if(!r)return t.entity;let n=t.bulk_rename,o=!0;if(t.bulk_rename&&!Array.isArray(t.bulk_rename)&&void 0===(null===(s=t.bulk_rename)||void 0===s?void 0:s.from)){const e=t.bulk_rename;n=e.rules,o=!1!==e.capitalize_first}return r=se(r,n),o&&""!==r&&(r=r[0].toLocaleUpperCase()+r.substring(1)),r})(this.config,this.accessor),this.secondaryInfo=((t,e)=>{if(t.secondary_info){let i=new Et(e).process(t.secondary_info);if(ft(i))return i;if(/\d{4}-\d{2}-\d{2}|\d{1,2}:\d{2}(:\d{2})?|\d{1,2}\/\d{1,2}\/\d{2,4}/.test(i)){const t=Date.parse(i);if(!isNaN(t))return`<rt>${i}</rt>`}return i}return null})(this.config,this.accessor),this.icon=((t,e,i,s)=>{var r,n;if(i&&(null===(r=t.charging_state)||void 0===r?void 0:r.icon))return t.charging_state.icon;if(null===t.icon)return kt;if(t.icon){if(!s.state)return pt(`Entity '${t.entity}' not found`,"error"),Ct;const e="attribute.";if(t.icon.startsWith(e)){const i=t.icon.substr(e.length);return(null===(n=s.attributes)||void 0===n?void 0:n[i])||(pt(`Icon attribute missing in '${t.entity}' entity`,"error"),Ct)}return new Et(s).process(t.icon)}if(void 0===e||isNaN(e)||e>100||e<0)return Ct;const o=10*Math.round(e/10);switch(o){case 100:return i?"mdi:battery-charging-100":"mdi:battery";case 0:return i?"mdi:battery-charging-outline":"mdi:battery-outline";default:return(i?"mdi:battery-charging-":"mdi:battery-")+o}})(this.config,l,d,this.accessor),this.iconColor=((t,e,i)=>{var s,r,n,o,a,l;if(i&&(null===(s=t.charging_state)||void 0===s?void 0:s.color))return t.charging_state.color;if(void 0===e||isNaN(e))return Vt;const c=bt(null===(r=t.colors)||void 0===r?void 0:r.steps,"color");if(null===(n=t.colors)||void 0===n?void 0:n.gradient)return Lt(c,e,null===(o=t.colors)||void 0===o?void 0:o.non_percent_values);let d=qt;return(null===(a=t.colors)||void 0===a?void 0:a.steps)&&(d=c.map(t=>(t.value=void 0===t.value?100:t.value,t))),(null===(l=d.find(t=>e<=t.value))||void 0===l?void 0:l.color)||Qt(d).color||Vt})(this.config,l,d),this.dynamicStyles=this.config.style||""}connectedCallback(){super.connectedCallback(),this.setupAction(!0)}disconnectedCallback(){super.disconnectedCallback(),this.setupAction(!1)}internalRender(){return Tt(this)}onError(){}hideEntity(){this.isHidden=!0}showEntity(){var t,e;!1!==this.config.respect_visibility_setting&&(null===(e=null===(t=this.accessor)||void 0===t?void 0:t.entity)||void 0===e?void 0:e.hidden)?this.isHidden=!0:this.isHidden=!1}setupAction(t=!0){if(!t||this.error||this.alert)this.action&&(this.classList.remove("clickable"),this.removeEventListener("click",this.action),this.action=void 0);else{let t=this.config.tap_action||"more-info";"none"==t||this.action||(this.action=e=>{e.stopPropagation(),(async(t,e,i,s)=>{s&&(e=Dt(e,s)),Bt(t,"hass-action",{config:e,action:i})})(this,{entity:this.config.entity,tap_action:_t(t,"action")},"tap",this.accessor)},this.addEventListener("click",this.action),this.classList.add("clickable"))}}}t([ht({attribute:!1})],oe.prototype,"name",void 0),t([ht({attribute:!1})],oe.prototype,"secondaryInfo",void 0),t([ht({attribute:!1})],oe.prototype,"state",void 0),t([ht({attribute:!1})],oe.prototype,"unit",void 0),t([ht({attribute:!1})],oe.prototype,"icon",void 0),t([ht({attribute:!1})],oe.prototype,"iconColor",void 0),t([ht({attribute:!1})],oe.prototype,"dynamicStyles",void 0),t([ht({attribute:!1})],oe.prototype,"action",void 0);const ae=t=>{return L`
${t.dynamicStyles?L`<style>${t.dynamicStyles}</style>`:""}
<ha-card>
${e=t.header,e&&L`
<div class="card-header">
<div class="truncate">
${e}
</div>
</div>
`}
<div class="card-content">
${t.list.map(e=>le(t.batteries[e]))}
${t.groups.map(e=>((t,e)=>(Math.random().toString().substr(2),L`
<div class="expandWrapper entity-spacing">
<div class="toggler" @click=${t=>t.currentTarget.classList.toggle("expanded")}>
${Pt(t.icon,t.iconColor)}
<div class="name truncate">
${t.title}
${t.secondaryInfo?L`<div class="secondary">${t.secondaryInfo}</div>`:null}
</div>
<div class="chevron">&lsaquo;</div>
</div>
<div style="max-height: ${50*Object.keys(e).length}px" class="groupItems">
${t.batteryIds.map(t=>le(e[t]))}
</div>
</div>
`))(e,t.batteries))}
</div>
</ha-card>
`;var e},le=t=>L`
<div class="entity-spacing">
${t}
</div>
`,ce=(t,e,i)=>{if(Array.isArray(t)||Array.isArray(e))throw new Error(`The '${i}' operator does not support array values.`)},de={exists:t=>void 0!==t,not_exists:t=>void 0===t,contains:(t,e)=>{if(null==t||null==e)return!1;const i=e.toString();return Array.isArray(t)?t.some(t=>null!=t&&t.toString().includes(i)):t.toString().includes(i)},"=":(t,e)=>(ce(t,e,"="),ft(t)||ft(e)?gt(t)==gt(e):t==e),">":(t,e)=>{ce(t,e,">");const i=yt(String(e));if(void 0!==i){const e=new Date(String(t)).getTime();return!isNaN(e)&&Date.now()-e>i}return gt(t)>gt(e)},"<":(t,e)=>{ce(t,e,"<");const i=yt(String(e));if(void 0!==i){const e=new Date(String(t)).getTime();return!isNaN(e)&&Date.now()-e<i}return gt(t)<gt(e)},">=":(t,e)=>{ce(t,e,">=");const i=yt(String(e));if(void 0!==i){const e=new Date(String(t)).getTime();return!isNaN(e)&&Date.now()-e>=i}return gt(t)>=gt(e)},"<=":(t,e)=>{ce(t,e,"<=");const i=yt(String(e));if(void 0!==i){const e=new Date(String(t)).getTime();return!isNaN(e)&&Date.now()-e<=i}return gt(t)<=gt(e)},matches:(t,e)=>{if(null==t)return!1;e=e.toString();let i=wt(e);return!i&&e.includes("*")&&(i=new RegExp("^"+e.replace(/\*/g,".*")+"$")),i?i.test(t.toString()):t===e}};class he{}class ue extends he{constructor(t){super(),this.filters=t}get is_permanent(){return this.filters.every(t=>t.is_permanent)}}class pe extends ue{isValid(t){return!this.filters.every(e=>e.isValid(t))}}class fe extends ue{isValid(t){return this.filters.every(e=>e.isValid(t))}}class ge extends ue{isValid(t){return this.filters.some(e=>e.isValid(t))}}class ve extends he{get is_permanent(){return"state"!=this.config.name&&!this.config.name.startsWith("computed.")}constructor(t){super(),this.config=t}isValid(t){const e=this.getValue(t);return this.meetsExpectations(e,t)}getValue(t){if(this.config.name)return t.resolve(this.config.name);pt("Missing filter 'name' property")}meetsExpectations(t,e){let i=this.config.value;if("string"==typeof i&&i.includes("{")){const t=new Et(e).process(i);i=ft(t)?gt(t):t}let s=this.config.operator;if(!s)if(void 0===i)s="exists";else if(null===i)s="=";else{const t=i.toString(),e=wt(t);s=t.includes("*")||e?"matches":"="}const r=de[s];return r?r(t,i):(pt(`Operator '${s}' not supported. Supported operators: ${Object.keys(de).join(", ")}`),!1)}}function ye(t){if(!t||"object"!=typeof t)throw new Error("Invalid filter specification: expected a non-null object.");const e=(e,i)=>{if(!(e in t))return null;const s=mt(t[e]);if(0===s.length)throw new Error(`Invalid '${e}' filter specification: expected a non-empty array.`);return new i(s.map(ye))};return e("not",pe)||e("and",fe)||e("or",ge)||new ve(t)}const me=["bulk_rename","charging_state","colors","debug","default_state_formatting","extend_entity_data","icon","non_battery_entity","respect_visibility_setting","round","secondary_info","state_map","tap_action","value_override","unit","style","battery_notes_dedup"];class be{constructor(t){var e,i;this.config=t,this.batteries={},this.groupsToResolve=[],this.groupsData={},this.explicitEntities=new Set,this.initialized=!1;const s=t.filter||t.filters;this.include=null===(e=null==s?void 0:s.include)||void 0===e?void 0:e.map(ye),this.exclude=null===(i=null==s?void 0:s.exclude)||void 0===i?void 0:i.map(ye),this.include||(this.initialized=!1),this.processExplicitEntities()}async update(t){this.initialized||(this.initialized=!0,this.processGroupEntities(t),this.processIncludes(t),this.config.unpack&&this.processUnpackEntities(t),this.processBatteryNotesDedup(t));const e=Object.keys(this.batteries).map(e=>{const i=this.batteries[e];return i.hass=t,i.cardUpdated});await Promise.all(e),this.processExcludes()}getBatteries(){return this.batteries}createBattery(t){me.filter(e=>null==t[e]).forEach(e=>t[e]=this.config[e]);const e=new oe;return e.entityId=t.entity,e.setConfig(t),e}processExplicitEntities(){let t=bt(this.config.entities,"entity");t=t.filter(t=>{if(!t.entity)throw new Error("Invalid configuration - missing property 'entity' on:\n"+JSON.stringify(t));return!t.entity.startsWith("group.")&&!t.unpack||(this.groupsToResolve.push(t.entity),!1)}),this.config.collapse&&Array.isArray(this.config.collapse)&&this.config.collapse.forEach(e=>{e.group_id?-1==this.groupsToResolve.indexOf(e.group_id)&&this.groupsToResolve.push(e.group_id):e.entities&&e.entities.forEach(e=>{t.some(t=>t.entity==e)||t.push({entity:e})})}),t.forEach(t=>{this.batteries[t.entity]=this.createBattery(t),this.explicitEntities.add(t.entity)})}processIncludes(t){this.include&&Array.isArray(this.include)&&0!=this.include.length&&Object.keys(t.states).forEach(e=>{if(this.batteries[e])return;const i=new ne(t,e);this.include.some(t=>t.isValid(i))&&(this.batteries[e]=this.createBattery({entity:e}))})}processGroupEntities(t){this.groupsToResolve.forEach(e=>{const i=t.states[e];if(!i)return void pt(`Group "${e}" not found`);const s=i.attributes;Array.isArray(s.entity_id)?(s.entity_id.forEach(t=>{this.batteries[t]||(this.batteries[t]=this.createBattery({entity:t}))}),this.groupsData[e]=s):pt(`Entities not found in "${e}"`)}),this.groupsToResolve=[]}processUnpackEntities(t){const e=[];Object.keys(this.batteries).forEach(i=>{var s;const r=t.states[i];r&&Array.isArray(null===(s=r.attributes)||void 0===s?void 0:s.entity_id)&&e.push(i)}),e.forEach(e=>{delete this.batteries[e];t.states[e].attributes.entity_id.forEach(t=>{this.batteries[t]||(this.batteries[t]=this.createBattery({entity:t}))})})}processExcludes(){if(null==this.exclude)return;const t=this.exclude,e=[];Object.keys(this.batteries).forEach(i=>{const s=this.batteries[i];let r=!1;for(let n of t)if(n.isValid(s.accessor)){if(n.is_permanent){e.push(i);break}r=!0}r?s.hideEntity():s.showEntity()}),e.forEach(t=>delete this.batteries[t])}processBatteryNotesDedup(t){if(!1===this.config.battery_notes_dedup)return;const e={},i={};Object.keys(this.batteries).forEach(s=>{var r;const n=new ne(t,s);i[s]=n;const o=null===(r=n.entity)||void 0===r?void 0:r.device_id;o&&(e[o]||(e[o]=[]),e[o].push(s))});const s=[];Object.keys(e).forEach(t=>{const r=e[t];if(r.length<=1)return;if(!r.some(t=>{var e;return"battery"===(null===(e=i[t].attributes)||void 0===e?void 0:e.device_class)}))return;const n=r.find(t=>{var e,s,r;const n=i[t];return"battery_notes"===(null===(e=n.entity)||void 0===e?void 0:e.platform)&&"battery"===(null===(s=n.attributes)||void 0===s?void 0:s.device_class)&&"measurement"===(null===(r=n.attributes)||void 0===r?void 0:r.state_class)});n&&r.forEach(t=>{var e;t!==n&&(this.explicitEntities.has(t)||"battery"===(null===(e=i[t].attributes)||void 0===e?void 0:e.device_class)&&s.push(t))})}),s.forEach(t=>delete this.batteries[t])}}const _e=(t,e,i)=>{var s;if(!t.some(t=>t.by))return t;const r=[];for(const n of t){if(!n.by){r.push(n);continue}const t=new Set;for(const r of i){const i=null===(s=e[r].accessor)||void 0===s?void 0:s.resolve(n.by);null!=i&&""!==i&&t.add(i.toString())}const o=n.filter||n.filters||[];for(const e of t){const t={name:n.by,value:e};r.push({name:n.name||e,secondary_info:n.secondary_info,icon:n.icon,icon_color:n.icon_color,filter:[t,...o]})}}return r},$e=(t,e,i,s)=>t.findIndex((t,r)=>{var n,o;if(t.group_id&&!(null===(o=null===(n=i[t.group_id])||void 0===n?void 0:n.entity_id)||void 0===o?void 0:o.some(t=>e.entityId==t)))return!1;if(t.entities&&!t.entities.some(t=>e.entityId==t))return!1;const a=s[r];if(a)return a.every(t=>t.isValid(e.accessor));const l=isNaN(gt(e.state))?0:gt(e.state);return l>=t.min&&l<=t.max}),we=t=>t.map(t=>{var e;return null===(e=t.filters||t.filter)||void 0===e?void 0:e.map(ye)});var Ae=t=>t.forEach(t=>{null==t.min&&(t.min=0),null!=t.max&&t.max<t.min?pt("Collapse group min value should be lower than max.\n"+JSON.stringify(t,null,2)):null==t.max&&(t.max=100)});const Ee=(t,e,i)=>{if((null==i?void 0:i.group_id)&&!t[i.group_id])throw new Error("Group not found: "+i.group_id);let s=null==i?void 0:i.name;!s&&(null==i?void 0:i.group_id)&&(s=t[i.group_id].friendly_name);let r=null==i?void 0:i.icon;return void 0===r&&(null==i?void 0:i.group_id)&&(r=t[i.group_id].icon),{title:s,icon:r,iconColor:null==i?void 0:i.icon_color,batteryIds:e,secondaryInfo:null==i?void 0:i.secondary_info}},Se=(t,e,i)=>t.replace(/\{([^}]+)\}/g,(t,s)=>{const r=s.split("|"),n=r[0],o=r.slice(1),a=xe.exec(n),l=a?a[1]:n,c=a&&a[2]||"computed.state";let d=Ce(l,c,e,i);return void 0===d?t:(o.length>0&&(d=Nt(d,o)),d)}),xe=/^([a-z]+)\(([^)]*)\)$/,Ne=(t,e,i)=>e.batteryIds.map(e=>{var s;const r=null===(s=i[e].accessor)||void 0===s?void 0:s.resolve(t);return null==r?NaN:gt(r)}).filter(t=>!isNaN(t)),Ce=(t,e,i,s)=>{switch(t){case"min":{const t=Ne(e,i,s);return t.length?Math.min(...t).toString():"0"}case"max":{const t=Ne(e,i,s);return t.length?Math.max(...t).toString():"0"}case"sum":return Ne(e,i,s).reduce((t,e)=>t+e,0).toString();case"avg":{const t=Ne(e,i,s);return t.length?(t.reduce((t,e)=>t+e,0)/t.length).toString():"0"}case"count":if("computed.state"===e)return i.batteryIds.length.toString();return i.batteryIds.filter(t=>{var i;const r=null===(i=s[t].accessor)||void 0===i?void 0:i.resolve(e);return null!=r&&""!==r&&!1!==r&&0!==r}).length.toString();case"range":{const t=Ne(e,i,s);if(!t.length)return"0";const r=Math.min(...t).toString(),n=Math.max(...t).toString();return r===n?r:r+"-"+n}default:return}},ke=(t,e,i)=>{switch(t){case"first":t=e.length>0?i[e[0]].icon:void 0;break;case"last":if(e.length>0){t=i[e[e.length-1]].icon}else t=void 0;break;default:if(t&&t.includes("{")&&e.length>0){const s=i[e[0]].accessor,r=new Et(s).process(t);t=r&&"null"!==r?r:void 0}}return t},Oe=(t,e,i)=>{switch(t){case"first":t=e.length>0?i[e[0]].iconColor:void 0;break;case"last":if(e.length>0){t=i[e[e.length-1]].iconColor}else t=void 0}return t};const Ue=(t,e)=>{let i=gt(t),s=gt(e);return i=isNaN(i)?-1:i,s=isNaN(s)?-1:s,i-s},Pe=(t,e)=>t.localeCompare(e);var Te={sort:{by:"state"},collapse:8,filter:{include:[{name:"attributes.device_class",value:"battery"}],exclude:[{name:"entity_id",value:"binary_sensor.*"}]},secondary_info:"{last_changed}",bulk_rename:[{from:" Battery"},{from:" level"}],colors:{steps:["#ff0000","#ffff00","#00ff00"],gradient:!0}};class Ie extends Rt{constructor(){super(...arguments),this.dynamicStyles="",this.list=[],this.groups=[],this.batteries={}}static get styles(){return o([Ht+".entity-spacing {\n margin: 8px 0;\n}\n\n.entity-spacing:first-child {\n margin-top: 0;\n}\n\n.entity-spacing:last-child {\n margin-bottom: 0;\n}\n\n.expandWrapper > .toggler {\n display: flex;\n align-items: center;\n cursor: pointer;\n}\n.expandWrapper > .toggler > .name {\n flex: 1;\n}\n.expandWrapper > .toggler div.chevron {\n transform: rotate(-90deg);\n font-size: 26px;\n height: 40px;\n width: 40px;\n display: flex;\n justify-content: center;\n align-items: center;\n}\n.expandWrapper > .toggler .chevron,\n.expandWrapper > .toggler + div {\n transition: all 0.5s ease;\n}\n.expandWrapper > .toggler.expanded .chevron {\n transform: rotate(-90deg) scaleX(-1);\n}\n.expandWrapper > .toggler + div {\n overflow: hidden;\n}\n.expandWrapper > .toggler:not(.expanded) + div {\n max-height: 0 !important;\n}"])}async internalUpdate(t,e){if(null==this.batteryProvider||t){if(this.config.filters&&!this.config.filter&&(this.config.filter=this.config.filters),this.config.group&&!this.config.collapse&&(this.config.collapse=this.config.group),!1!==this.config.default_config_base){const t={...Te};this.config.entities&&delete t.filter,this.config={...t,...this.config}}else 1==Object.keys(this.config).length&&(this.config={...Te});this.batteryProvider=new be(this.config)}e&&await this.batteryProvider.update(this.hass),this.header=this.config.title;const i=((t,e)=>{if(!(t&&e&&t.themes&&t.themes.themes))return;let i=t.themes.themes[e];if(!i)return void pt(`Theme "${e}" not found in Home Assistant`);if(i.modes){const s=t.themes.darkMode||!1;if(i=s?i.modes.dark:i.modes.light,!i)return void pt(`Theme "${e}" mode not found (dark: ${s})`)}const s=[];for(const[t,e]of Object.entries(i)){if("modes"===t)continue;const i=t.startsWith("--")?t:`--${t}`;s.push(`${i}: ${e}`)}return s.join("; ")})(this.hass,this.config.theme);this.style.cssText=i||"",this.dynamicStyles=this.config.style||"",this.batteries=this.batteryProvider.getBatteries();const s=((t,e)=>{let i=Object.keys(e);const s=bt(t.sort,"by").filter(t=>t.by);return i.sort((t,i)=>{let r=0;return s.find(s=>{var n,o;let a,l;switch(s.by){case"name":a=e[t].name,l=e[i].name;break;case"state":a=null==e[t].stateNumeric?e[t].state:e[t].stateNumeric,l=null==e[i].stateNumeric?e[i].state:e[i].stateNumeric;break;default:if(s.by.startsWith("entity.")){const r=s.by.substring(7);a=null===(n=e[t].accessor)||void 0===n?void 0:n.resolve(r),l=null===(o=e[i].accessor)||void 0===o?void 0:o.resolve(r)}else pt("Unknown sort field: "+s.by,"warn")}return r=ft(a)||ft(l)?Ue(a,l):void 0===a?void 0===l?0:-1:Pe(a,l),s.desc&&(r*=-1),0!=r}),r})})(this.config,this.batteries).filter(t=>!this.batteries[t].isHidden),r=((t,e,i,s)=>{const r={list:[],groups:[]};if(!i)return r.list=e,r;if("number"==typeof i){r.list=e.slice(0,i);const t=e.slice(i);t.length>0&&r.groups.push(Ee(s,t))}else{const n=_e(i,t,e);Ae(n);const o=we(n);e.forEach(e=>{const i=$e(n,t[e],s,o);-1==i?r.list.push(e):(r.groups[i]=r.groups[i]||Ee(s,[],n[i]),r.groups[i].batteryIds.push(e))})}return r.groups.forEach(e=>{e.title&&(e.title=Se(e.title,e,t)),e.secondaryInfo&&(e.secondaryInfo=Se(e.secondaryInfo,e,t)),e.icon=ke(e.icon,e.batteryIds,t),e.iconColor=Oe(e.iconColor,e.batteryIds,t)}),r})(this.batteries,s,this.config.collapse,this.batteryProvider.groupsData);JSON.stringify(r.list)!=JSON.stringify(this.list)&&(this.list=r.list),JSON.stringify(r.groups)!=JSON.stringify(this.groups)&&(this.groups=r.groups)}internalRender(){return 0==this.list.length&&0==this.groups.length?(this.style.display="none",L``):(this.style.removeProperty("display"),ae(this))}onError(){this.style.removeProperty("display")}getCardSize(){let t=bt(this.config.entities,"entity").length||1;return this.config.collapse?"number"==typeof this.config.collapse?this.config.collapse+1:this.config.collapse.length+1:t+1}}t([ht({attribute:!1})],Ie.prototype,"header",void 0),t([ht({attribute:!1})],Ie.prototype,"dynamicStyles",void 0),t([ht({attribute:!1})],Ie.prototype,"list",void 0),t([ht({attribute:!1})],Ie.prototype,"groups",void 0),void 0===customElements.get("battery-state-entity")?(console.info("%c BATTERY-STATE-CARD %c 4.2.0","color: white; background: forestgreen; font-weight: 700;","color: forestgreen; background: white; font-weight: 700;"),customElements.define("battery-state-entity",oe),customElements.define("battery-state-card",Ie)):pt("Element seems to be defined already","warn"),window.customCards=window.customCards||[],window.customCards.push({type:"battery-state-card",name:"Battery state card",preview:!0,description:"Customizable card for listing battery states/levels"})}();
//# sourceMappingURL=battery-state-card.js.map