Files
hassos_config/www/community/lovelace-slider-entity-row/slider-entity-row.js

95 lines
36 KiB
JavaScript

function t(t,e,s,i){var r,n=arguments.length,a=n<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,s,i);else for(var o=t.length-1;o>=0;o--)(r=t[o])&&(a=(n<3?r(a):n>3?r(e,s,a):r(e,s))||a);return n>3&&a&&Object.defineProperty(e,s,a),a}"function"==typeof SuppressedError&&SuppressedError;const e=globalThis,s=e.ShadowRoot&&(void 0===e.ShadyCSS||e.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,i=Symbol(),r=new WeakMap;let n=class{constructor(t,e,s){if(this._$cssResult$=!0,s!==i)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(s&&void 0===t){const s=void 0!==e&&1===e.length;s&&(t=r.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),s&&r.set(e,t))}return t}toString(){return this.cssText}};const a=(t,...e)=>{const s=1===t.length?t[0]:e.reduce(((e,s,i)=>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.")})(s)+t[i+1]),t[0]);return new n(s,t,i)},o=s?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return(t=>new n("string"==typeof t?t:t+"",void 0,i))(e)})(t):t,{is:h,defineProperty:l,getOwnPropertyDescriptor:c,getOwnPropertyNames:u,getOwnPropertySymbols:d,getPrototypeOf:_}=Object,p=globalThis,g=p.trustedTypes,b=g?g.emptyScript:"",f=p.reactiveElementPolyfillSupport,m=(t,e)=>t,v={toAttribute(t,e){switch(e){case Boolean:t=t?b:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let s=t;switch(e){case Boolean:s=null!==t;break;case Number:s=null===t?null:Number(t);break;case Object:case Array:try{s=JSON.parse(t)}catch(t){s=null}}return s}},$=(t,e)=>!h(t,e),y={attribute:!0,type:String,converter:v,reflect:!1,hasChanged:$};Symbol.metadata??=Symbol("metadata"),p.litPropertyMetadata??=new WeakMap;class w 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=y){if(e.state&&(e.attribute=!1),this._$Ei(),this.elementProperties.set(t,e),!e.noAccessor){const s=Symbol(),i=this.getPropertyDescriptor(t,s,e);void 0!==i&&l(this.prototype,t,i)}}static getPropertyDescriptor(t,e,s){const{get:i,set:r}=c(this.prototype,t)??{get(){return this[e]},set(t){this[e]=t}};return{get(){return i?.call(this)},set(e){const n=i?.call(this);r.call(this,e),this.requestUpdate(t,n,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??y}static _$Ei(){if(this.hasOwnProperty(m("elementProperties")))return;const t=_(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=[...u(t),...d(t)];for(const s of e)this.createProperty(s,t[s])}const t=this[Symbol.metadata];if(null!==t){const e=litPropertyMetadata.get(t);if(void 0!==e)for(const[t,s]of e)this.elementProperties.set(t,s)}this._$Eh=new Map;for(const[t,e]of this.elementProperties){const s=this._$Eu(t,e);void 0!==s&&this._$Eh.set(s,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const s=new Set(t.flat(1/0).reverse());for(const t of s)e.unshift(o(t))}else void 0!==t&&e.push(o(t));return e}static _$Eu(t,e){const s=e.attribute;return!1===s?void 0:"string"==typeof s?s:"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._$Eg=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)))}addController(t){(this._$ES??=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.()}removeController(t){this._$ES?.splice(this._$ES.indexOf(t)>>>0,1)}_$E_(){const t=new Map,e=this.constructor.elementProperties;for(const s of e.keys())this.hasOwnProperty(s)&&(t.set(s,this[s]),delete this[s]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return((t,i)=>{if(s)t.adoptedStyleSheets=i.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const s of i){const i=document.createElement("style"),r=e.litNonce;void 0!==r&&i.setAttribute("nonce",r),i.textContent=s.cssText,t.appendChild(i)}})(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$ES?.forEach((t=>t.hostConnected?.()))}enableUpdating(t){}disconnectedCallback(){this._$ES?.forEach((t=>t.hostDisconnected?.()))}attributeChangedCallback(t,e,s){this._$AK(t,s)}_$EO(t,e){const s=this.constructor.elementProperties.get(t),i=this.constructor._$Eu(t,s);if(void 0!==i&&!0===s.reflect){const r=(void 0!==s.converter?.toAttribute?s.converter:v).toAttribute(e,s.type);this._$Em=t,null==r?this.removeAttribute(i):this.setAttribute(i,r),this._$Em=null}}_$AK(t,e){const s=this.constructor,i=s._$Eh.get(t);if(void 0!==i&&this._$Em!==i){const t=s.getPropertyOptions(i),r="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:v;this._$Em=i,this[i]=r.fromAttribute(e,t.type),this._$Em=null}}requestUpdate(t,e,s,i=!1,r){if(void 0!==t){if(s??=this.constructor.getPropertyOptions(t),!(s.hasChanged??$)(i?r:this[t],e))return;this.C(t,e,s)}!1===this.isUpdatePending&&(this._$Eg=this._$EP())}C(t,e,s){this._$AL.has(t)||this._$AL.set(t,e),!0===s.reflect&&this._$Em!==t&&(this._$Ej??=new Set).add(t)}async _$EP(){this.isUpdatePending=!0;try{await this._$Eg}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._$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,s]of t)!0!==s.wrapped||this._$AL.has(e)||void 0===this[e]||this.C(e,this[e],s)}let t=!1;const e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),this._$ES?.forEach((t=>t.hostUpdate?.())),this.update(e)):this._$ET()}catch(e){throw t=!1,this._$ET(),e}t&&this._$AE(e)}willUpdate(t){}_$AE(t){this._$ES?.forEach((t=>t.hostUpdated?.())),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$ET(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$Eg}shouldUpdate(t){return!0}update(t){this._$Ej&&=this._$Ej.forEach((t=>this._$EO(t,this[t]))),this._$ET()}updated(t){}firstUpdated(t){}}w.elementStyles=[],w.shadowRootOptions={mode:"open"},w[m("elementProperties")]=new Map,w[m("finalized")]=new Map,f?.({ReactiveElement:w}),(p.reactiveElementVersions??=[]).push("2.0.1");const O=globalThis,j=O.trustedTypes,A=j?j.createPolicy("lit-html",{createHTML:t=>t}):void 0,S="$lit$",E=`lit$${(Math.random()+"").slice(9)}$`,x="?"+E,C=`<${x}>`,T=document,P=()=>T.createComment(""),k=t=>null===t||"object"!=typeof t&&"function"!=typeof t,M=Array.isArray,U="[ \t\n\f\r]",R=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,H=/-->/g,N=/>/g,z=RegExp(`>|${U}(?:([^\\s"'>=/]+)(${U}*=${U}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),L=/'/g,I=/"/g,D=/^(?:script|style|textarea|title)$/i,B=(t=>(e,...s)=>({_$litType$:t,strings:e,values:s}))(1),W=Symbol.for("lit-noChange"),q=Symbol.for("lit-nothing"),V=new WeakMap,K=T.createTreeWalker(T,129);function F(t,e){if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==A?A.createHTML(e):e}const J=(t,e)=>{const s=t.length-1,i=[];let r,n=2===e?"<svg>":"",a=R;for(let e=0;e<s;e++){const s=t[e];let o,h,l=-1,c=0;for(;c<s.length&&(a.lastIndex=c,h=a.exec(s),null!==h);)c=a.lastIndex,a===R?"!--"===h[1]?a=H:void 0!==h[1]?a=N:void 0!==h[2]?(D.test(h[2])&&(r=RegExp("</"+h[2],"g")),a=z):void 0!==h[3]&&(a=z):a===z?">"===h[0]?(a=r??R,l=-1):void 0===h[1]?l=-2:(l=a.lastIndex-h[2].length,o=h[1],a=void 0===h[3]?z:'"'===h[3]?I:L):a===I||a===L?a=z:a===H||a===N?a=R:(a=z,r=void 0);const u=a===z&&t[e+1].startsWith("/>")?" ":"";n+=a===R?s+C:l>=0?(i.push(o),s.slice(0,l)+S+s.slice(l)+E+u):s+E+(-2===l?e:u)}return[F(t,n+(t[s]||"<?>")+(2===e?"</svg>":"")),i]};class Z{constructor({strings:t,_$litType$:e},s){let i;this.parts=[];let r=0,n=0;const a=t.length-1,o=this.parts,[h,l]=J(t,e);if(this.el=Z.createElement(h,s),K.currentNode=this.el.content,2===e){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes)}for(;null!==(i=K.nextNode())&&o.length<a;){if(1===i.nodeType){if(i.hasAttributes())for(const t of i.getAttributeNames())if(t.endsWith(S)){const e=l[n++],s=i.getAttribute(t).split(E),a=/([.?@])?(.*)/.exec(e);o.push({type:1,index:r,name:a[2],strings:s,ctor:"."===a[1]?tt:"?"===a[1]?et:"@"===a[1]?st:X}),i.removeAttribute(t)}else t.startsWith(E)&&(o.push({type:6,index:r}),i.removeAttribute(t));if(D.test(i.tagName)){const t=i.textContent.split(E),e=t.length-1;if(e>0){i.textContent=j?j.emptyScript:"";for(let s=0;s<e;s++)i.append(t[s],P()),K.nextNode(),o.push({type:2,index:++r});i.append(t[e],P())}}}else if(8===i.nodeType)if(i.data===x)o.push({type:2,index:r});else{let t=-1;for(;-1!==(t=i.data.indexOf(E,t+1));)o.push({type:7,index:r}),t+=E.length-1}r++}}static createElement(t,e){const s=T.createElement("template");return s.innerHTML=t,s}}function G(t,e,s=t,i){if(e===W)return e;let r=void 0!==i?s._$Co?.[i]:s._$Cl;const n=k(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,s,i)),void 0!==i?(s._$Co??=[])[i]=r:s._$Cl=r),void 0!==r&&(e=G(t,r._$AS(t,e.values),r,i)),e}class Y{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:s}=this._$AD,i=(t?.creationScope??T).importNode(e,!0);K.currentNode=i;let r=K.nextNode(),n=0,a=0,o=s[0];for(;void 0!==o;){if(n===o.index){let e;2===o.type?e=new Q(r,r.nextSibling,this,t):1===o.type?e=new o.ctor(r,o.name,o.strings,this,t):6===o.type&&(e=new it(r,this,t)),this._$AV.push(e),o=s[++a]}n!==o?.index&&(r=K.nextNode(),n++)}return K.currentNode=T,i}p(t){let e=0;for(const s of this._$AV)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,e),e+=s.strings.length-2):s._$AI(t[e])),e++}}class Q{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,e,s,i){this.type=2,this._$AH=q,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=s,this.options=i,this._$Cv=i?.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=G(this,t,e),k(t)?t===q||null==t||""===t?(this._$AH!==q&&this._$AR(),this._$AH=q):t!==this._$AH&&t!==W&&this._(t):void 0!==t._$litType$?this.g(t):void 0!==t.nodeType?this.$(t):(t=>M(t)||"function"==typeof t?.[Symbol.iterator])(t)?this.T(t):this._(t)}k(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}$(t){this._$AH!==t&&(this._$AR(),this._$AH=this.k(t))}_(t){this._$AH!==q&&k(this._$AH)?this._$AA.nextSibling.data=t:this.$(T.createTextNode(t)),this._$AH=t}g(t){const{values:e,_$litType$:s}=t,i="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=Z.createElement(F(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===i)this._$AH.p(e);else{const t=new Y(i,this),s=t.u(this.options);t.p(e),this.$(s),this._$AH=t}}_$AC(t){let e=V.get(t.strings);return void 0===e&&V.set(t.strings,e=new Z(t)),e}T(t){M(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let s,i=0;for(const r of t)i===e.length?e.push(s=new Q(this.k(P()),this.k(P()),this,this.options)):s=e[i],s._$AI(r),i++;i<e.length&&(this._$AR(s&&s._$AB.nextSibling,i),e.length=i)}_$AR(t=this._$AA.nextSibling,e){for(this._$AP?.(!1,!0,e);t&&t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t))}}class X{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,s,i,r){this.type=1,this._$AH=q,this._$AN=void 0,this.element=t,this.name=e,this._$AM=i,this.options=r,s.length>2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=q}_$AI(t,e=this,s,i){const r=this.strings;let n=!1;if(void 0===r)t=G(this,t,e,0),n=!k(t)||t!==this._$AH&&t!==W,n&&(this._$AH=t);else{const i=t;let a,o;for(t=r[0],a=0;a<r.length-1;a++)o=G(this,i[s+a],e,a),o===W&&(o=this._$AH[a]),n||=!k(o)||o!==this._$AH[a],o===q?t=q:t!==q&&(t+=(o??"")+r[a+1]),this._$AH[a]=o}n&&!i&&this.O(t)}O(t){t===q?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class tt extends X{constructor(){super(...arguments),this.type=3}O(t){this.element[this.name]=t===q?void 0:t}}class et extends X{constructor(){super(...arguments),this.type=4}O(t){this.element.toggleAttribute(this.name,!!t&&t!==q)}}class st extends X{constructor(t,e,s,i,r){super(t,e,s,i,r),this.type=5}_$AI(t,e=this){if((t=G(this,t,e,0)??q)===W)return;const s=this._$AH,i=t===q&&s!==q||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,r=t!==q&&(s===q||i);i&&this.element.removeEventListener(this.name,this,s),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 it{constructor(t,e,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(t){G(this,t)}}const rt=O.litHtmlPolyfillSupport;rt?.(Z,Q),(O.litHtmlVersions??=[]).push("3.0.2");class nt 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,s)=>{const i=s?.renderBefore??e;let r=i._$litPart$;if(void 0===r){const t=s?.renderBefore??null;i._$litPart$=r=new Q(e.insertBefore(P(),t),t,void 0,s??{})}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 W}}nt._$litElement$=!0,nt.finalized=!0,globalThis.litElementHydrateSupport?.({LitElement:nt});const at=globalThis.litElementPolyfillSupport;at?.({LitElement:nt}),(globalThis.litElementVersions??=[]).push("4.0.1");const ot={attribute:!0,type:String,converter:v,reflect:!1,hasChanged:$},ht=(t=ot,e,s)=>{const{kind:i,metadata:r}=s;let n=globalThis.litPropertyMetadata.get(r);if(void 0===n&&globalThis.litPropertyMetadata.set(r,n=new Map),n.set(s.name,t),"accessor"===i){const{name:i}=s;return{set(s){const r=e.get.call(this);e.set.call(this,s),this.requestUpdate(i,r,t)},init(e){return void 0!==e&&this.C(i,void 0,t),e}}}if("setter"===i){const{name:i}=s;return function(s){const r=this[i];e.call(this,s),this.requestUpdate(i,r,t)}}throw Error("Unsupported decorator location: "+i)};function lt(t){return(e,s)=>"object"==typeof s?ht(t,e,s):((t,e,s)=>{const i=e.hasOwnProperty(s);return e.constructor.createProperty(s,i?{...t,wrapped:!0}:t),i?Object.getOwnPropertyDescriptor(e,s):void 0})(t,e,s)}const ct=(t,e,s)=>(s.configurable=!0,s.enumerable=!0,Reflect.decorate&&"object"!=typeof e&&Object.defineProperty(t,e,s),s);class ut{constructor(t,e){this._config=t}set hass(t){this._hass=t,this.stateObj=t.states[this._config.entity]}get value(){return this._value?Math.round(this._value/this.step)*this.step:0}set value(t){t!==this.value&&(this._value=t)}get string(){return`${this.value}`}get hidden(){return!1}get hasSlider(){return!0}get hasToggle(){return!0}get background(){}renderToggle(t){return this.hasToggle?B`
<ha-entity-toggle
.stateObj=${t.states[this.stateObj.entity_id]}
.hass=${t}
.class="state"
></ha-entity-toggle>
`:void 0}get isOff(){return!this.stateObj||"unavailable"===this.stateObj.state||("off"===this.stateObj.state||0===this.value)}get min(){var t,e;return null!==(e=null!==(t=this._config.min)&&void 0!==t?t:this._min)&&void 0!==e?e:0}get max(){var t,e;return null!==(e=null!==(t=this._config.max)&&void 0!==t?t:this._max)&&void 0!==e?e:100}get step(){var t,e;return null!==(e=null!==(t=this._config.step)&&void 0!==t?t:this._step)&&void 0!==e?e:5}get dir(){var t;return null!==(t=this._config.dir)&&void 0!==t?t:void 0}}ut.allowed_attributes=[];const dt={red:0,green:1,blue:2,white:3,cold_white:3,warm_white:4},_t={hue:0,saturation:1};class pt extends ut{get attribute(){return this._config.attribute||"brightness_pct"}get _rgbww(){const t=this.stateObj.attributes;switch(t.color_mode){case"rgb":case"hs":case"xy":return[...t.rgb_color,0,0];case"rgbw":return[...t.rgbw_color,0];case"rgbww":return[...t.rgbww_color];default:return[0,0,0,0,0]}}get _value(){if(!this.stateObj||"on"!==this.stateObj.state)return 0;const t=this.stateObj.attributes;switch(this.attribute){case"color_temp":return Math.round(t.color_temp_kelvin);case"color_temp_mired":return Math.round(t.color_temp);case"white_value":return Math.round(t.white_value);case"brightness":return Math.round(t.brightness);case"brightness_pct":return Math.round(100*t.brightness/255);case"red":case"green":case"blue":return t.rgb_color?Math.round(this._rgbww[dt[this.attribute]]):0;case"white":return t.rgbw_color?Math.round(100*this._rgbww[dt[this.attribute]]/255):0;case"cold_white":case"warm_white":return t.rgbww_color?Math.round(100*this._rgbww[dt[this.attribute]]/255):0;case"hue":case"saturation":return t.hs_color?Math.round(t.hs_color[_t[this.attribute]]):0;case"effect":return t.effect_list?t.effect_list.indexOf(t.effect):0;default:return 0}}get _step(){return"effect"===this.attribute?1:5}get _min(){switch(this.attribute){case"color_temp":return this.stateObj?this.stateObj.attributes.min_color_temp_kelvin:0;case"color_temp_mired":return this.stateObj?this.stateObj.attributes.min_mireds:0;default:return 0}}get _max(){switch(this.attribute){case"color_temp":return this.stateObj?this.stateObj.attributes.max_color_temp_kelvin:0;case"color_temp_mired":return this.stateObj?this.stateObj.attributes.max_mireds:0;case"red":case"green":case"blue":case"white_value":case"brightness":return 255;case"hue":return 360;case"effect":return this.stateObj&&this.stateObj.attributes.effect_list?this.stateObj.attributes.effect_list.length-1:0;default:return 100}}get isOff(){return"on"!==this.stateObj.state}set _value(t){if(!this.stateObj)return;const e=this.stateObj.attributes.color_mode;let s,i=this.attribute,r=!0;switch(i){case"brightness":case"brightness_pct":(t="brightness"===i?Math.round(t):Math.round(t/100*255))||(r=!1),i="brightness";break;case"red":case"green":case"blue":if(s=this._rgbww,s[dt[i]]=t,"rgbww"===e){i="rgbww_color",t=s;break}if("rgbw"===e){i="rgbw_color",t=s.slice(0,4);break}i="rgb_color",t=s.slice(0,3);break;case"white":s=this._rgbww,s[dt[i]]=Math.round(t/100*255),t=s.slice(0,4),i="rgbw_color";break;case"cold_white":case"warm_white":s=this._rgbww,s[dt[i]]=Math.round(t/100*255),t=s,i="rgbww_color";break;case"hue":case"saturation":s=this.stateObj.attributes.hs_color||[0,0],s[_t[i]]=t,t=s,i="hs_color";break;case"effect":t=this.stateObj.attributes.effect_list[t],i="effect";break;case"color_temp":i="kelvin";break;case"color_temp_mired":i="color_temp"}r?this._hass.callService("light","turn_on",{entity_id:this.stateObj.entity_id,[i]:t}):this._hass.callService("light","turn_off",{entity_id:this.stateObj.entity_id})}get string(){if(this.stateObj&&"off"===this.stateObj.state)return this._hass.localize("component.light.entity_component._.state.off");switch(this.attribute){case"color_temp_mired":case"brightness":return`${this.value}`;case"color_temp":return`${this.value} K`;case"brightness_pct":case"saturation":return`${this.value} %`;case"hue":return`${this.value} °`;case"effect":return this.stateObj?this.stateObj.attributes.effect:"";default:return this.value}}get hasSlider(){var t,e,s,i,r,n,a;const o=this.stateObj.attributes,h=2&o.supported_features||(null===(t=o.supported_color_modes)||void 0===t?void 0:t.some((t=>["color_temp"].includes(t)))),l=16&o.supported_features||(null===(e=o.supported_color_modes)||void 0===e?void 0:e.some((t=>["rgb","rgbw","rgbww"].includes(t)))),c=null===(s=o.supported_color_modes)||void 0===s?void 0:s.some((t=>["rgbw"].includes(t))),u=null===(i=o.supported_color_modes)||void 0===i?void 0:i.some((t=>["rgbww"].includes(t))),d=16&o.supported_features||(null===(r=o.supported_color_modes)||void 0===r?void 0:r.some((t=>["hs"].includes(t)))),_=null===(n=o.supported_color_modes)||void 0===n?void 0:n.some((t=>["xy"].includes(t))),p=1&o.supported_features||h||l||d||_||(null===(a=o.supported_color_modes)||void 0===a?void 0:a.some((t=>["brightness"].includes(t)))),g=l||d;if(!this.stateObj)return!1;switch(this.attribute){case"brightness":case"brightness_pct":return!(!("brightness"in this.stateObj.attributes)&&!p);case"color_temp":case"color_temp_mired":return!(!("color_temp"in this.stateObj.attributes)&&!h);case"white_value":return!!(128&o.supported_features||"white_value"in this.stateObj.attributes);case"white":return!!c;case"cold_white":case"warm_white":return!!u;case"red":case"green":case"blue":return!(!("rgb_color"in this.stateObj.attributes)&&!g);case"hue":case"saturation":return!(!("hs_color"in this.stateObj.attributes)&&!g);case"effect":return"effect"in this.stateObj.attributes||"effect_list"in this.stateObj.attributes;default:return!1}}get background(){return"hue"===this.attribute?"linear-gradient(to right,red,yellow,green,cyan,blue,magenta,red)":"color_temp_mired"===this.attribute?"linear-gradient(to right,rgb(166,209,255),rgb(255,255,255),rgb(255,160,0))":"color_temp"===this.attribute?"linear-gradient(to left,rgb(166,209,255),rgb(255,255,255),rgb(255,160,0))":"red"===this.attribute?"linear-gradient(to right,rgb(0,0,0),rgb(255,0,0))":"green"===this.attribute?"linear-gradient(to right,rgb(0,0,0),rgb(0,255,0))":"blue"===this.attribute?"linear-gradient(to right,rgb(0,0,0),rgb(0,0,255))":"brightness"===this.attribute?"linear-gradient(to right,rgb(0,0,0),rgb(255,255,255))":void 0}}pt.allowed_attributes=["brightness_pct","brightness","color_temp","color_temp_mired","hue","saturation","red","green","blue","effect","white","cold_white","warm_white"];class gt extends ut{get attribute(){return this._config.attribute||"position"}get _value(){switch(this.attribute){case"position":return"closed"===this.stateObj.state?0:this.stateObj.attributes.current_position;case"tilt":return this.stateObj.attributes.current_tilt_position;default:return 0}}set _value(t){switch(this.attribute){case"position":this._hass.callService("cover","set_cover_position",{entity_id:this.stateObj.entity_id,position:t});break;case"tilt":this._hass.callService("cover","set_cover_tilt_position",{entity_id:this.stateObj.entity_id,tilt_position:t})}}get string(){if(!this.hasSlider)return"";switch(this.attribute){case"position":return"closed"===this.stateObj.state?this._hass.localize("component.cover.entity_component._.state.closed"):100===this.value?this._hass.localize("component.cover.entity_component._.state.open"):`${this.value} %`;case"tilt":return`${this.value} %`}}get hasToggle(){return!0}renderToggle(t){const e=t.states[this.stateObj.entity_id];return console.log("Toggle",t),B`
<ha-cover-controls .hass=${t} .stateObj=${e}></ha-cover_controls>
`}get hasSlider(){switch(this.attribute){case"position":if("current_position"in this.stateObj.attributes)return!0;if("supported_features"in this.stateObj.attributes&&4&this.stateObj.attributes.supported_features)return!0;case"tilt":if("current_tilt_position"in this.stateObj.attributes)return!0;if("supported_features"in this.stateObj.attributes&&128&this.stateObj.attributes.supported_features)return!0;default:return!1}}get _step(){return 10}}gt.allowed_attributes=["position","tilt"];const bt={light:pt,media_player:class extends ut{get _value(){return this.stateObj.attributes.is_volume_muted?0:Math.round(100*this.stateObj.attributes.volume_level)}set _value(t){t/=100,this._hass.callService("media_player","volume_set",{entity_id:this.stateObj.entity_id,volume_level:t}),t&&this.stateObj.attributes.is_volume_muted&&this._hass.callService("media_player","volume_mute",{entity_id:this.stateObj.entity_id,is_volume_muted:!1})}get isOff(){return"off"===this.stateObj.state}get string(){return this.stateObj.attributes.is_volume_muted?"-":this.stateObj.attributes.volume_level?`${this.value} %`:this._hass.localize("component.media_player.entity_component._.state.off")}get hasToggle(){return!0}_handleMute(){this._hass.callService("media_player","volume_mute",{entity_id:this.stateObj.entity_id,is_volume_muted:!this.stateObj.attributes.is_volume_muted})}renderToggle(t){const e=t.states[this.stateObj.entity_id],s=document.createElement("ha-icon");s.style.display="flex",s.icon=e.attributes.is_volume_muted?"mdi:volume-off":"mdi:volume-high";const i=document.createElement("ha-icon-button");return i.appendChild(s),i.addEventListener("click",(()=>this._handleMute())),this.hasToggle?i:void 0}},climate:class extends ut{get _value(){return this.stateObj.attributes.temperature}set _value(t){this._hass.callService("climate","set_temperature",{entity_id:this.stateObj.entity_id,temperature:t})}get string(){return`${this.value} ${this._hass.config.unit_system.temperature}`}get isOff(){return"off"===this.stateObj.state}get _min(){return this.stateObj.attributes.min_temp}get _max(){return this.stateObj.attributes.max_temp}get _step(){return 1}},water_heater:class extends ut{get _value(){return this.stateObj.attributes.temperature}set _value(t){this._hass.callService("water_heater","set_temperature",{entity_id:this.stateObj.entity_id,temperature:t})}get string(){return`${this.value} ${this._hass.config.unit_system.temperature}`}get isOff(){return"off"===this.stateObj.state}get _min(){return this.stateObj.attributes.min_temp}get _max(){return this.stateObj.attributes.max_temp}get _step(){return 1}},cover:gt,fan:class extends ut{get _value(){return"off"!==this.stateObj.state?this.stateObj.attributes.percentage:0}set _value(t){t>0?this._hass.callService("fan","set_percentage",{entity_id:this.stateObj.entity_id,percentage:t}):this._hass.callService("fan","turn_off",{entity_id:this.stateObj.entity_id})}get string(){return"off"===this.stateObj.state?this._hass.localize("component.light.entity_component._.state.off"):`${this.stateObj.attributes.percentage} %`}get hasSlider(){return"percentage"in this.stateObj.attributes}get _step(){return this.stateObj.attributes.percentage_step}},input_number:class extends ut{get _value(){return this.stateObj.state}set _value(t){this._hass.callService("input_number","set_value",{entity_id:this.stateObj.entity_id,value:t})}get string(){return`${parseFloat(this.stateObj.state)} ${this.stateObj.attributes.unit_of_measurement||""}`.trim()}get isOff(){return!1}get hasToggle(){return!1}get hasSlider(){return"slider"===this.stateObj.attributes.mode}get _min(){return this.stateObj.attributes.min}get _max(){return this.stateObj.attributes.max}get _step(){return this.stateObj.attributes.step}},input_select:class extends ut{get _value(){return this.stateObj.attributes.options.indexOf(this.stateObj.state)}set _value(t){t in this.stateObj.attributes.options&&this._hass.callService("input_select","select_option",{entity_id:this.stateObj.entity_id,option:this.stateObj.attributes.options[t]})}get string(){return this.stateObj.state}get isOff(){return!1}get hasToggle(){return!1}get hasSlider(){return this.stateObj.attributes.options&&this.stateObj.attributes.options.length>0}get _max(){return this.stateObj.attributes.options.length-1}get _step(){return 1}},number:class extends ut{get _value(){return this.stateObj.state}set _value(t){this._hass.callService("number","set_value",{entity_id:this.stateObj.entity_id,value:t})}get string(){return`${parseFloat(this.stateObj.state)} ${this.stateObj.attributes.unit_of_measurement||""}`.trim()}get isOff(){return!1}get hasToggle(){return!1}get hasSlider(){return!0}get _min(){return this.stateObj.attributes.min}get _max(){return this.stateObj.attributes.max}get _step(){return this.stateObj.attributes.step}},humidifier:class extends ut{get _value(){return this.stateObj.attributes.humidity}set _value(t){this._hass.callService("humidifier","set_humidity",{entity_id:this.stateObj.entity_id,humidity:t})}get string(){return`${this.value} %`}get isOff(){return"off"===this.stateObj.state}get _min(){return this.stateObj.attributes.min_humidity}get _max(){return this.stateObj.attributes.max_humidity}get _step(){return 1}},timer:class extends ut{constructor(t,e){super(t,e),this._calcvalue=0,this._calcvalue=0,this._interval=window.setInterval((()=>{this._calcvalue=this.calculate_value(),e.requestUpdate()}),1e3)}get _value(){return this._calcvalue}calculate_value(){let t=this.stateObj.attributes.remaining;if(!t)return 0;const e=t.split(":").map(Number);if(t=3600*e[0]+60*e[1]+e[2],"active"===this.stateObj.state){const e=(new Date).getTime(),s=new Date(this.stateObj.last_changed).getTime();t=Math.max(t-(e-s)/1e3,0)}return t}set _value(t){t?this._hass.callService("timer","start",{entity_id:this.stateObj.entity_id,duration:t}):this._hass.callService("timer","finish",{entity_id:this.stateObj.entity_id})}get string(){if("active"===this.stateObj.state){const t=t=>t<10?`0${t}`:`${t}`,e=Math.floor(this.value/3600),s=Math.floor(this.value%3600/60),i=Math.floor(this.value%60);return e>0?`${e}:${t(s)}:${t(i)}`:s>0?`${s}:${t(i)}`:`${i}`}return this._hass.localize("component.timer.entity_component._.state.idle")}get isOff(){return"active"!==this.stateObj.state}get _min(){return 0}get _max(){return 300}get _step(){return 1}}};var ft="17.4.0";class mt extends nt{setConfig(t){this._config=t}_schema(t){var e,s,i;const r=Object.keys(bt);console.log(t,bt[t],null===(e=bt[t])||void 0===e?void 0:e.allowed_attributes);const n=null!==(i=null===(s=bt[t])||void 0===s?void 0:s.allowed_attributes)&&void 0!==i?i:[];return[{name:"entity",required:!0,selector:{entity:{filter:[{domain:r}]}}},{type:"grid",name:"",schema:[{name:"name",selector:{text:{}}},{name:"icon",selector:{icon:{}},context:{icon_entity:"entity"}}]},{type:"grid",name:"",schema:[{name:"min",selector:{number:{min:-1e32,max:1e32,mode:"box"}}},{name:"max",selector:{number:{min:-1e32,max:1e32,mode:"box"}}},{name:"step",selector:{number:{min:-1e32,max:1e32,mode:"box"}}}]},{type:"grid",name:"",schema:[{name:"toggle",selector:{boolean:{}}},{name:"hide_state",selector:{boolean:{}}},{name:"hide_when_off",selector:{boolean:{}}},{name:"full_row",selector:{boolean:{}}},{name:"show_icon",selector:{boolean:{}}}]},n.length?{type:"grid",name:"",schema:[{name:"attribute",selector:{select:{options:n}}},{name:"colorize",selector:{boolean:{}}}]}:{}]}render(){var t,e;if(!this.hass||!this._config)return"";const s=this._schema(null===(e=null===(t=this._config.entity)||void 0===t?void 0:t.split("."))||void 0===e?void 0:e[0]);return B`
<ha-form
.hass=${this.hass}
.data=${this._config}
.schema=${s}
@value-changed=${this._valueChanged}
></ha-form>
`}_valueChanged(t){this.dispatchEvent(new CustomEvent("config-changed",{detail:{config:t.detail.value}}))}}t([lt()],mt.prototype,"hass",void 0),t([function(t){return lt({...t,state:!0,attribute:!1})}()],mt.prototype,"_config",void 0),customElements.define("slider-entity-row-editor",mt);class vt extends nt{setConfig(t){if(this._config=t,!t.entity)throw new Error("No entity specified.");const e=t.entity.split(".")[0],s=function(t){return bt[t]}(e);if(!s)throw new Error(`Unsupported entity type: ${e}`);this.ctrl=new s(t,this)}static getConfigElement(){return console.log("GetConfigElement"),document.createElement("slider-entity-row-editor")}async resized(){var t,e;await this.updateComplete,this.shadowRoot&&this.parentElement&&(this.hide_state=this._config.full_row?(null===(t=this.parentElement)||void 0===t?void 0:t.clientWidth)<=180:(null===(e=this.parentElement)||void 0===e?void 0:e.clientWidth)<=335)}async firstUpdated(){await this.resized()}async updated(){var t;if(!this._slider)return;if(await this._slider.updateComplete,this._slider.shadowRoot.querySelector("style.slider-entity-row"))return;const e=document.createElement("style");e.classList.add("slider-entity-row"),e.innerHTML=".container .track::before{background: var(--_inactive-track-color);}\n .container .track::after{background: var(--_active-track-color);}",null===(t=this._slider.shadowRoot)||void 0===t||t.appendChild(e)}async connectedCallback(){super.connectedCallback(),await this.resized()}render(){var t;const e=this.ctrl;if(e.hass=this.hass,!e.stateObj)return B`
<hui-warning>
${this.hass.localize("ui.panel.lovelace.warning.entity_not_found","entity",this._config.entity)}
</hui-warning>
`;const s=(null!==(t=e.dir)&&void 0!==t?t:this.hass.translationMetadata.translations[this.hass.language||"en"].isRTL)?"rtl":"ltr",i="unavailable"!==e.stateObj.state&&e.hasSlider&&!(e.isOff&&this._config.hide_when_off),r=this._config.toggle&&e.hasToggle,n=!r&&(!1===this._config.hide_state||!this._config.hide_state&&!this.hide_state&&(!e.isOff||!this._config.hide_when_off)),a=B`
<div class="wrapper" @click=${t=>t.stopPropagation()}>
${i?B`
${this._config.colorize&&e.background?B`
<style>
ha-slider {
--paper-slider-container-color: ${e.background};
--_inactive-track-color: ${e.background};
--_active-track-color: ${e.background};
--paper-progress-active-color: transparent;
}
</style>
`:""}
<ha-slider
.min=${e.min}
.max=${e.max}
.step=${e.step}
.value=${e.value}
.dir=${s}
labeled
pin
@change=${t=>e.value=this.shadowRoot.querySelector("ha-slider").value}
class=${this._config.full_row||this._config.grow?"full":""}
ignore-bar-touch
></ha-slider>
`:""}
${r?e.renderToggle(this.hass):""}
${n?B`<span class="state">
${"unavailable"===e.stateObj.state?this.hass.localize("state.default.unavailable"):e.string}
</span>`:""}
</div>
`;if(this._config.full_row){if(this._config.hide_when_off&&e.isOff)return B``;if(!0===this._config.show_icon){const t=this._config;return B`
<div class="wrapper">
<state-badge
.hass=${this.hass}
.stateObj=${e.stateObj}
.overrideIcon=${t.icon}
.overrideImage=${t.image}
.stateColor=${t.state_color}
></state-badge>
${a}
</div>
`}return a}return B`
<hui-generic-entity-row
.hass=${this.hass}
.config=${this._config}
.catchInteraction=${!1}
>
${a}
</hui-generic-entity-row>
`}static get styles(){return a`
.wrapper {
display: flex;
align-items: center;
justify-content: flex-end;
flex: 7;
height: 40px;
}
.state {
min-width: 45px;
text-align: end;
}
ha-entity-toggle {
min-width: auto;
margin-left: 8px;
}
ha-slider {
width: 100%;
min-width: 100px;
--paper-slider-secondary-color: transparent;
}
ha-slider:not(.full) {
max-width: 200px;
}
`}}t([lt()],vt.prototype,"hass",void 0),t([lt()],vt.prototype,"hide_state",void 0),t([function(t,e){return(s,i,r)=>{const n=e=>e.renderRoot?.querySelector(t)??null;if(e){const{get:t,set:a}="object"==typeof i?s:r??(()=>{const t=Symbol();return{get(){return this[t]},set(e){this[t]=e}}})();return ct(s,i,{get(){if(e){let e=t.call(this);return void 0===e&&(e=n(this),a.call(this,e)),e}return n(this)}})}return ct(s,i,{get(){return n(this)}})}}("ha-slider")],vt.prototype,"_slider",void 0),customElements.get("slider-entity-row")||(customElements.define("slider-entity-row",vt),console.info(`%cSLIDER-ENTITY-ROW ${ft} IS INSTALLED`,"color: green; font-weight: bold",""));