forked from thomasloven/lovelace-slider-entity-row
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslider-entity-row.js
59 lines (59 loc) · 30.4 KB
/
slider-entity-row.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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}const e=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s=Symbol(),i=new Map;class r{constructor(t,e){if(this._$cssResult$=!0,e!==s)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t}get styleSheet(){let t=i.get(this.cssText);return e&&void 0===t&&(i.set(this.cssText,t=new CSSStyleSheet),t.replaceSync(this.cssText)),t}toString(){return this.cssText}}const n=(t,...e)=>{const i=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 r(i,s)},a=e?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return(t=>new r("string"==typeof t?t:t+"",s))(e)})(t):t;var o;const l=window.reactiveElementPolyfillSupport,h={toAttribute(t,e){switch(e){case Boolean:t=t?"":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}},u=(t,e)=>e!==t&&(e==e||t==t),c={attribute:!0,type:String,converter:h,reflect:!1,hasChanged:u};class d extends HTMLElement{constructor(){super(),this._$Et=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Ei=null,this.o()}static addInitializer(t){var e;null!==(e=this.l)&&void 0!==e||(this.l=[]),this.l.push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,s)=>{const i=this._$Eh(s,e);void 0!==i&&(this._$Eu.set(i,s),t.push(i))})),t}static createProperty(t,e=c){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const s="symbol"==typeof t?Symbol():"__"+t,i=this.getPropertyDescriptor(t,s,e);void 0!==i&&Object.defineProperty(this.prototype,t,i)}}static getPropertyDescriptor(t,e,s){return{get(){return this[e]},set(i){const r=this[t];this[e]=i,this.requestUpdate(t,r,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||c}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),this.elementProperties=new Map(t.elementProperties),this._$Eu=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const s of e)this.createProperty(s,t[s])}return this.elementStyles=this.finalizeStyles(this.styles),!0}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(a(t))}else void 0!==t&&e.push(a(t));return e}static _$Eh(t,e){const s=e.attribute;return!1===s?void 0:"string"==typeof s?s:"string"==typeof t?t.toLowerCase():void 0}o(){var t;this._$Ev=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Ep(),this.requestUpdate(),null===(t=this.constructor.l)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,s;(null!==(e=this._$Em)&&void 0!==e?e:this._$Em=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(s=t.hostConnected)||void 0===s||s.call(t))}removeController(t){var e;null===(e=this._$Em)||void 0===e||e.splice(this._$Em.indexOf(t)>>>0,1)}_$Ep(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Et.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const s=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return((t,s)=>{e?t.adoptedStyleSheets=s.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):s.forEach((e=>{const s=document.createElement("style"),i=window.litNonce;void 0!==i&&s.setAttribute("nonce",i),s.textContent=e.cssText,t.appendChild(s)}))})(s,this.constructor.elementStyles),s}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$Em)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$Em)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,s){this._$AK(t,s)}_$Eg(t,e,s=c){var i,r;const n=this.constructor._$Eh(t,s);if(void 0!==n&&!0===s.reflect){const a=(null!==(r=null===(i=s.converter)||void 0===i?void 0:i.toAttribute)&&void 0!==r?r:h.toAttribute)(e,s.type);this._$Ei=t,null==a?this.removeAttribute(n):this.setAttribute(n,a),this._$Ei=null}}_$AK(t,e){var s,i,r;const n=this.constructor,a=n._$Eu.get(t);if(void 0!==a&&this._$Ei!==a){const t=n.getPropertyOptions(a),o=t.converter,l=null!==(r=null!==(i=null===(s=o)||void 0===s?void 0:s.fromAttribute)&&void 0!==i?i:"function"==typeof o?o:null)&&void 0!==r?r:h.fromAttribute;this._$Ei=a,this[a]=l(e,t.type),this._$Ei=null}}requestUpdate(t,e,s){let i=!0;void 0!==t&&(((s=s||this.constructor.getPropertyOptions(t)).hasChanged||u)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===s.reflect&&this._$Ei!==t&&(void 0===this._$ES&&(this._$ES=new Map),this._$ES.set(t,s))):i=!1),!this.isUpdatePending&&i&&(this._$Ev=this._$EC())}async _$EC(){this.isUpdatePending=!0;try{await this._$Ev}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Et&&(this._$Et.forEach(((t,e)=>this[e]=t)),this._$Et=void 0);let e=!1;const s=this._$AL;try{e=this.shouldUpdate(s),e?(this.willUpdate(s),null===(t=this._$Em)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(s)):this._$EU()}catch(t){throw e=!1,this._$EU(),t}e&&this._$AE(s)}willUpdate(t){}_$AE(t){var e;null===(e=this._$Em)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EU(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$Ev}shouldUpdate(t){return!0}update(t){void 0!==this._$ES&&(this._$ES.forEach(((t,e)=>this._$Eg(e,this[e],t))),this._$ES=void 0),this._$EU()}updated(t){}firstUpdated(t){}}var _;d.finalized=!0,d.elementProperties=new Map,d.elementStyles=[],d.shadowRootOptions={mode:"open"},null==l||l({ReactiveElement:d}),(null!==(o=globalThis.reactiveElementVersions)&&void 0!==o?o:globalThis.reactiveElementVersions=[]).push("1.0.1");const p=globalThis.trustedTypes,g=p?p.createPolicy("lit-html",{createHTML:t=>t}):void 0,b=`lit$${(Math.random()+"").slice(9)}$`,v="?"+b,f=`<${v}>`,m=document,$=(t="")=>m.createComment(t),y=t=>null===t||"object"!=typeof t&&"function"!=typeof t,w=Array.isArray,O=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,A=/-->/g,j=/>/g,S=/>|[ \n\r](?:([^\s"'>=/]+)([ \n\r]*=[ \n\r]*(?:[^ \n\r"'`<>=]|("|')|))|$)/g,E=/'/g,x=/"/g,C=/^(?:script|style|textarea)$/i,T=(t=>(e,...s)=>({_$litType$:t,strings:e,values:s}))(1),U=Symbol.for("lit-noChange"),P=Symbol.for("lit-nothing"),M=new WeakMap,H=m.createTreeWalker(m,129,null,!1),k=(t,e)=>{const s=t.length-1,i=[];let r,n=2===e?"<svg>":"",a=O;for(let e=0;e<s;e++){const s=t[e];let o,l,h=-1,u=0;for(;u<s.length&&(a.lastIndex=u,l=a.exec(s),null!==l);)u=a.lastIndex,a===O?"!--"===l[1]?a=A:void 0!==l[1]?a=j:void 0!==l[2]?(C.test(l[2])&&(r=RegExp("</"+l[2],"g")),a=S):void 0!==l[3]&&(a=S):a===S?">"===l[0]?(a=null!=r?r:O,h=-1):void 0===l[1]?h=-2:(h=a.lastIndex-l[2].length,o=l[1],a=void 0===l[3]?S:'"'===l[3]?x:E):a===x||a===E?a=S:a===A||a===j?a=O:(a=S,r=void 0);const c=a===S&&t[e+1].startsWith("/>")?" ":"";n+=a===O?s+f:h>=0?(i.push(o),s.slice(0,h)+"$lit$"+s.slice(h)+b+c):s+b+(-2===h?(i.push(void 0),e):c)}const o=n+(t[s]||"<?>")+(2===e?"</svg>":"");return[void 0!==g?g.createHTML(o):o,i]};class R{constructor({strings:t,_$litType$:e},s){let i;this.parts=[];let r=0,n=0;const a=t.length-1,o=this.parts,[l,h]=k(t,e);if(this.el=R.createElement(l,s),H.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(i=H.nextNode())&&o.length<a;){if(1===i.nodeType){if(i.hasAttributes()){const t=[];for(const e of i.getAttributeNames())if(e.endsWith("$lit$")||e.startsWith(b)){const s=h[n++];if(t.push(e),void 0!==s){const t=i.getAttribute(s.toLowerCase()+"$lit$").split(b),e=/([.?@])?(.*)/.exec(s);o.push({type:1,index:r,name:e[2],strings:t,ctor:"."===e[1]?D:"?"===e[1]?B:"@"===e[1]?W:I})}else o.push({type:6,index:r})}for(const e of t)i.removeAttribute(e)}if(C.test(i.tagName)){const t=i.textContent.split(b),e=t.length-1;if(e>0){i.textContent=p?p.emptyScript:"";for(let s=0;s<e;s++)i.append(t[s],$()),H.nextNode(),o.push({type:2,index:++r});i.append(t[e],$())}}}else if(8===i.nodeType)if(i.data===v)o.push({type:2,index:r});else{let t=-1;for(;-1!==(t=i.data.indexOf(b,t+1));)o.push({type:7,index:r}),t+=b.length-1}r++}}static createElement(t,e){const s=m.createElement("template");return s.innerHTML=t,s}}function N(t,e,s=t,i){var r,n,a,o;if(e===U)return e;let l=void 0!==i?null===(r=s._$Cl)||void 0===r?void 0:r[i]:s._$Cu;const h=y(e)?void 0:e._$litDirective$;return(null==l?void 0:l.constructor)!==h&&(null===(n=null==l?void 0:l._$AO)||void 0===n||n.call(l,!1),void 0===h?l=void 0:(l=new h(t),l._$AT(t,s,i)),void 0!==i?(null!==(a=(o=s)._$Cl)&&void 0!==a?a:o._$Cl=[])[i]=l:s._$Cu=l),void 0!==l&&(e=N(t,l._$AS(t,e.values),l,i)),e}class z{constructor(t,e){this.v=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}p(t){var e;const{el:{content:s},parts:i}=this._$AD,r=(null!==(e=null==t?void 0:t.creationScope)&&void 0!==e?e:m).importNode(s,!0);H.currentNode=r;let n=H.nextNode(),a=0,o=0,l=i[0];for(;void 0!==l;){if(a===l.index){let e;2===l.type?e=new L(n,n.nextSibling,this,t):1===l.type?e=new l.ctor(n,l.name,l.strings,this,t):6===l.type&&(e=new V(n,this,t)),this.v.push(e),l=i[++o]}a!==(null==l?void 0:l.index)&&(n=H.nextNode(),a++)}return r}m(t){let e=0;for(const s of this.v)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,e),e+=s.strings.length-2):s._$AI(t[e])),e++}}class L{constructor(t,e,s,i){var r;this.type=2,this._$AH=P,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=s,this.options=i,this._$Cg=null===(r=null==i?void 0:i.isConnected)||void 0===r||r}get _$AU(){var t,e;return null!==(e=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==e?e:this._$Cg}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=N(this,t,e),y(t)?t===P||null==t||""===t?(this._$AH!==P&&this._$AR(),this._$AH=P):t!==this._$AH&&t!==U&&this.$(t):void 0!==t._$litType$?this.T(t):void 0!==t.nodeType?this.S(t):(t=>{var e;return w(t)||"function"==typeof(null===(e=t)||void 0===e?void 0:e[Symbol.iterator])})(t)?this.M(t):this.$(t)}A(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}S(t){this._$AH!==t&&(this._$AR(),this._$AH=this.A(t))}$(t){this._$AH!==P&&y(this._$AH)?this._$AA.nextSibling.data=t:this.S(m.createTextNode(t)),this._$AH=t}T(t){var e;const{values:s,_$litType$:i}=t,r="number"==typeof i?this._$AC(t):(void 0===i.el&&(i.el=R.createElement(i.h,this.options)),i);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===r)this._$AH.m(s);else{const t=new z(r,this),e=t.p(this.options);t.m(s),this.S(e),this._$AH=t}}_$AC(t){let e=M.get(t.strings);return void 0===e&&M.set(t.strings,e=new R(t)),e}M(t){w(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 L(this.A($()),this.A($()),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){var s;for(null===(s=this._$AP)||void 0===s||s.call(this,!1,!0,e);t&&t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){var e;void 0===this._$AM&&(this._$Cg=t,null===(e=this._$AP)||void 0===e||e.call(this,t))}}class I{constructor(t,e,s,i,r){this.type=1,this._$AH=P,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=P}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,s,i){const r=this.strings;let n=!1;if(void 0===r)t=N(this,t,e,0),n=!y(t)||t!==this._$AH&&t!==U,n&&(this._$AH=t);else{const i=t;let a,o;for(t=r[0],a=0;a<r.length-1;a++)o=N(this,i[s+a],e,a),o===U&&(o=this._$AH[a]),n||(n=!y(o)||o!==this._$AH[a]),o===P?t=P:t!==P&&(t+=(null!=o?o:"")+r[a+1]),this._$AH[a]=o}n&&!i&&this.k(t)}k(t){t===P?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,null!=t?t:"")}}class D extends I{constructor(){super(...arguments),this.type=3}k(t){this.element[this.name]=t===P?void 0:t}}class B extends I{constructor(){super(...arguments),this.type=4}k(t){t&&t!==P?this.element.setAttribute(this.name,""):this.element.removeAttribute(this.name)}}class W extends I{constructor(t,e,s,i,r){super(t,e,s,i,r),this.type=5}_$AI(t,e=this){var s;if((t=null!==(s=N(this,t,e,0))&&void 0!==s?s:P)===U)return;const i=this._$AH,r=t===P&&i!==P||t.capture!==i.capture||t.once!==i.once||t.passive!==i.passive,n=t!==P&&(i===P||r);r&&this.element.removeEventListener(this.name,this,i),n&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e,s;"function"==typeof this._$AH?this._$AH.call(null!==(s=null===(e=this.options)||void 0===e?void 0:e.host)&&void 0!==s?s:this.element,t):this._$AH.handleEvent(t)}}class V{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){N(this,t)}}const q=window.litHtmlPolyfillSupport;var K,F;null==q||q(R,L),(null!==(_=globalThis.litHtmlVersions)&&void 0!==_?_:globalThis.litHtmlVersions=[]).push("2.0.1");class J extends d{constructor(){super(...arguments),this.renderOptions={host:this},this._$Dt=void 0}createRenderRoot(){var t,e;const s=super.createRenderRoot();return null!==(t=(e=this.renderOptions).renderBefore)&&void 0!==t||(e.renderBefore=s.firstChild),s}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Dt=((t,e,s)=>{var i,r;const n=null!==(i=null==s?void 0:s.renderBefore)&&void 0!==i?i:e;let a=n._$litPart$;if(void 0===a){const t=null!==(r=null==s?void 0:s.renderBefore)&&void 0!==r?r:null;n._$litPart$=a=new L(e.insertBefore($(),t),t,void 0,null!=s?s:{})}return a._$AI(t),a})(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!1)}render(){return U}}J.finalized=!0,J._$litElement$=!0,null===(K=globalThis.litElementHydrateSupport)||void 0===K||K.call(globalThis,{LitElement:J});const Z=globalThis.litElementPolyfillSupport;null==Z||Z({LitElement:J}),(null!==(F=globalThis.litElementVersions)&&void 0!==F?F:globalThis.litElementVersions=[]).push("3.0.1");const Y=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(s){s.createProperty(e.key,t)}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:e.key,initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this))},finisher(s){s.createProperty(e.key,t)}};function G(t){return(e,s)=>void 0!==s?((t,e,s)=>{e.constructor.createProperty(s,t)})(t,e,s):Y(t,e)}console.warn("The main 'lit-element' module entrypoint is deprecated. Please update your imports to use the 'lit' package: 'lit' and 'lit/decorators.ts' or import from 'lit-element/lit-element.ts'. See https://lit.dev/msg/deprecated-import-path for more information.");class Q{constructor(t){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}renderToggle(t){return this.hasToggle?T`
<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}}const X={red:0,green:1,blue:2,white:3,cold_white:3,warm_white:4},tt={hue:0,saturation:1};class et extends Q{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);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[X[this.attribute]]):0;case"white":return t.rgbw_color?Math.round(100*this._rgbww[X[this.attribute]]/255):0;case"cold_white":case"warm_white":return t.rgbww_color?Math.round(100*this._rgbww[X[this.attribute]]/255):0;case"hue":case"saturation":return t.hs_color?Math.round(t.hs_color[tt[this.attribute]]):0;case"effect":return t.effect_list?t.effect_list.indexOf(t.effect):0;default:return 0}}get _step(){switch(this.attribute){case"effect":return 1;default:return 5}}get _min(){switch(this.attribute){case"color_temp":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_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[X[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[X[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[X[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[tt[i]]=t,t=s,i="hs_color";break;case"effect":t=this.stateObj.attributes.effect_list[t],i="effect"}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.state._.off");switch(this.attribute){case"color_temp":case"brightness":return`${this.value}`;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,l=2&o.supported_features||(null===(t=o.supported_color_modes)||void 0===t?void 0:t.some((t=>["color_temp"].includes(t)))),h=16&o.supported_features||(null===(e=o.supported_color_modes)||void 0===e?void 0:e.some((t=>["rgb","rgbw","rgbww"].includes(t)))),u=null===(s=o.supported_color_modes)||void 0===s?void 0:s.some((t=>["rgbw"].includes(t))),c=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||l||h||d||_||(null===(a=o.supported_color_modes)||void 0===a?void 0:a.some((t=>["brightness"].includes(t)))),g=h||d;if(!this.stateObj)return!1;switch(this.attribute){case"brightness":case"brightness_pct":return!(!("brightness"in this.stateObj.attributes)&&!p);case"color_temp":return!(!("color_temp"in this.stateObj.attributes)&&!l);case"white_value":return!!(128&o.supported_features||"white_value"in this.stateObj.attributes);case"white":return!!u;case"cold_white":case"warm_white":return!!c;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}}}class st extends Q{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.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}}class it extends Q{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}}class rt extends Q{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.state._.closed"):100===this.value?this._hass.localize("component.cover.state._.open"):`${this.value} %`;case"tilt":return this.value}}get hasToggle(){return!1}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}}class nt extends Q{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.fan.state._.off"):`${this.stateObj.attributes.percentage} %`}get hasSlider(){return"percentage"in this.stateObj.attributes}get _step(){return this.stateObj.attributes.percentage_step}}class at extends Q{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}}class ot extends Q{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}}class lt extends Q{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}}class ht extends Q{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}}class ut extends Q{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}}var ct="17.2.1";class dt extends J{setConfig(t){if(this._config=t,!t.entity)throw new Error("No entity specified.");const e=t.entity.split(".")[0],s=function(t){return{light:et,media_player:st,climate:it,water_heater:ht,cover:rt,fan:nt,input_number:at,input_select:ot,number:lt,humidifier:ut}[t]}(e);if(!s)throw new Error(`Unsupported entity type: ${e}`);this.ctrl=new s(t)}async resized(){await this.updateComplete,this.shadowRoot&&(this.hide_state=this._config.full_row?this.parentElement.clientWidth<=180:this.parentElement.clientWidth<=335)}async firstUpdated(){await this.resized()}render(){var t;const e=this.ctrl;if(e.hass=this.hass,!e.stateObj)return T`
<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=T`
<div class="wrapper" @click=${t=>t.stopPropagation()}>
${i?T`
<ha-slider
.min=${e.min}
.max=${e.max}
.step=${e.step}
.value=${e.value}
.dir=${s}
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?T`<span class="state">
${"unavailable"===e.stateObj.state?this.hass.localize("state.default.unavailable"):e.string}
</span>`:""}
</div>
`;return this._config.full_row?this._config.hide_when_off&&e.isOff?T``:a:T`
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
${a}
</hui-generic-entity-row>
`}static get styles(){return n`
.wrapper {
display: flex;
align-items: center;
justify-content: flex-end;
flex: 100;
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([G()],dt.prototype,"hass",void 0),t([G()],dt.prototype,"hide_state",void 0),customElements.get("slider-entity-row")||(customElements.define("slider-entity-row",dt),console.info(`%cSLIDER-ENTITY-ROW ${ct} IS INSTALLED`,"color: green; font-weight: bold",""));