${A?B`
${x}
`:""}
${h.map(({value:e,icon:i,iconConfigured:a,name:o,nameConfigured:r,hide_when_off:l})=>{if(!0===l&&t===Be.OFF)return q;const h=(t=>String(t).replace(/[^a-z0-9_-]/gi,""))(e),u=((t,e,i)=>!1===t||!1===n?.names?null:b(t,e,i))(o,e,r),p=b(o,e,r),g=Ti(String(e),u,E),f="stacked"===g.layout?"label-stacked":"column"===g.layout?"label-column":"",y=u?q:$||q;return B`
{v||s(c,e)}}
@keydown=${t=>{"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),v||s(c,e))}}
>
${((t,e=!1)=>t?!1===n?.icons||!1===m||["swing","swing_horizontal","swing_vertical","vane_horizontal","vane_vertical"].includes(c)&&!0!==m&&!e?null:Oi(t):null)(i,a)}
${((t,e)=>{if(!e)return null;const i=Ti(t,e,E);return"stacked"===i.layout?B`
${i.lines.map(t=>B`${t}`)}
`:B`${i.lines[0]??e}`})(String(e),u)}
`})}
`}window.customIconsets=window.customIconsets||{},window.customIconsets.st||(window.customIconsets.st=async t=>{const e=Ri[`st:${t}`];return e?{path:`M13 19C13 17.59 13.5 16.3 14.3 15.28C14.17 14.97 14.03 14.65 13.86 14.34C14.26 14 14.57 13.59 14.77 13.11C15.26 13.21 15.78 13.39 16.25 13.67C17.07 13.25 18 13 19 13C20.05 13 21.03 13.27 21.89 13.74C21.95 13.37 22 12.96 22 12.5C22 8.92 18.03 8.13 14.33 10.13C14 9.73 13.59 9.42 13.11 9.22C13.3 8.29 13.74 7.24 14.73 6.75C17.09 5.57 17 2 12.5 2C8.93 2 8.14 5.96 10.13 9.65C9.72 9.97 9.4 10.39 9.21 10.87C8.28 10.68 7.23 10.25 6.73 9.26C5.56 6.89 2 7 2 11.5C2 15.07 5.95 15.85 9.64 13.87C9.96 14.27 10.39 14.59 10.88 14.79C10.68 15.71 10.24 16.75 9.26 17.24C6.9 18.42 7 22 11.5 22C12.31 22 13 21.78 13.5 21.41C13.19 20.67 13 19.86 13 19M12 13C11.43 13 11 12.55 11 12S11.43 11 12 11C12.54 11 13 11.45 13 12S12.54 13 12 13${e.path}`}:{path:""}});const Mi=t=>String(t).replace(/[^a-z0-9_-]/gi,"");function Pi({toggles:t,mainState:e,toggleFooterEntity:i,openEntityPopover:a}){const o=t.filter(t=>!(!0===t.hide_when_off&&e===Be.OFF));return o.length?B`
`:q}const ji={target_temp_low:{field:"target_temp_high",caps:"max"},target_temp_high:{field:"target_temp_low",caps:"min"}},Fi=Object.values(yt),Ii="hass:chevron-up",Li="hass:chevron-down",Hi="mdi:plus",Vi="mdi:minus",Di={temperature:!1,state:!1},Ui=[yt.PRESET,yt.FAN,yt.HVAC,yt.SWING,yt.SWING_HORIZONTAL,yt.SWING_VERTICAL,yt.VANE_HORIZONTAL,yt.VANE_VERTICAL,yt.DIRECTION,yt.OSCILLATING,yt.STATE],Wi=["entity","hide_when_off","hide_off_when_off"];function Bi(t,e=1){if(null===t||""===t||"boolean"==typeof t)return e;const i=Number(t);return Number.isInteger(i)&&i>=0&&i<=100?i:e}function Gi(t,e,i){const a=Ki(String(e),i);if(Zi(a))return!1!==a.include;const o=Object.keys(i).some(t=>!t.startsWith("_")&&!Wi.includes(t)),n=t===yt.PRESET;return a??!(n&&o)}function qi(t){return t.toLowerCase().replace(/\s+/g,"_")}function Ki(t,e){const i=qi(t),a=e[t];if(void 0!==a)return a;if(void 0!==e[i])return e[i];const o=Object.entries(e).find(([t])=>!t.startsWith("_")&&!Wi.includes(t)&&qi(t)===i);return o?.[1]}function Zi(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}function Ji(t,e){const i=Array.isArray(e._order)?e._order.map(String):Object.keys(e).filter(t=>!t.startsWith("_")&&!Wi.includes(t));if(0===i.length)return t;const a=new Map;t.forEach(t=>{a.set(qi(String(t)),t)});const o=new Set,n=[];return i.forEach(t=>{const e=qi(t);a.has(e)&&!o.has(e)&&(n.push(a.get(e)),o.add(e))}),t.forEach(t=>{const e=qi(String(t));o.has(e)||(n.push(t),o.add(e))}),n}function Yi(t,e,i,a={}){let o=e[i.getModeAttribute(t)];return t===yt.STATE?o=["off","on"]:t===yt.DIRECTION&&e.direction?o=["forward","reverse"]:t===yt.OSCILLATING&&"boolean"==typeof e.oscillating&&(o=[!1,!0]),Array.isArray(o)?Ji(o,a).filter(e=>Gi(t,e,a)).map(e=>{const i=String(e),n=Ki(i,a),r=Zi(n)?n:{},{name:s,...c}=r,l=!0===r.hide_when_off||!0===a.hide_off_when_off&&"off"===qi(i),d=!1!==s&&("string"==typeof s?s:Oe(i));return{...c,hide_when_off:l||void 0,icon:r.icon??(t===yt.FAN?Je(i,o):void 0)??Re(i),iconConfigured:void 0!==r.icon,nameConfigured:void 0!==s,value:i,name:d}}):[]}function Xi(t){return"string"==typeof t?.entity_id&&t.entity_id.startsWith("select.")&&Array.isArray(t.attributes?.options)}function Qi(t,e={}){return Ji(t.attributes.options,e).filter(t=>Gi("select",t,e)).map(t=>{const i=String(t),a=Ki(i,e),o=Zi(a)?a:{},{name:n,...r}=o,s=!0===o.hide_when_off||!0===e.hide_off_when_off&&"off"===qi(i),c=!1!==n&&("string"==typeof n?n:Oe(i));return{...r,hide_when_off:s||void 0,icon:o.icon??Re(i),iconConfigured:void 0!==o.icon,nameConfigured:void 0!==n,value:i,name:c}})}function ta(t,e,i,a){return Fi.includes(t)&&(t===yt.STATE?"fan"===e||"humidifier"===e:void 0!==i[a.getModeAttribute(t)])}function ea(t,e,i,a){return t.filter(t=>ta(t,e,i,a)).map(t=>({type:t,hide_when_off:!1,list:Yi(t,i,a)}))}class ia extends lt{constructor(){super(...arguments),this.modes=[],this._hass={},this.entities=[],this.footer=[],this.showEntities=!0,this.name="",this.stepSize=.5,this._values={},this._updatingValues=!1,this._hide=Di,this._updatingValuesTimeout=null,this._holdTimer=null,this._holdFired=!1,this._clickCount=0,this._clickTimer=null,this._setpointUpdateTimer=null,this._pendingSetpointUpdate=null,this._missingEntityTimer=null,this._stepRepeatDelayTimer=null,this._stepRepeatIntervalTimer=null,this._stepRepeatFired=!1,this._setpointDebounce=500,this.localize=(t,e="")=>{const i=`${e}${t}`;return this._hass.localize?.(i)||t},this.toggleEntityChanged=(t,e)=>{if(!this.header||!e)return;if(!be(this._hass?.states?.[e]))return;const i=t.target;this._callAction("homeassistant.turn_"+(i.checked?"on":"off"),{entity_id:e})},this.toggleFooterEntity=(t,e)=>{this._hass&&(xe(this._hass,t,e),_t(this,"haptic","light"))},this._stopSetpointRepeat=()=>{this._stepRepeatDelayTimer&&(clearTimeout(this._stepRepeatDelayTimer),this._stepRepeatDelayTimer=null),this._stepRepeatIntervalTimer&&(clearInterval(this._stepRepeatIntervalTimer),this._stepRepeatIntervalTimer=null)},this.setMode=(t,e)=>{if(t&&e){const i=kt(this.config.entity),a=this.modes.find(e=>e.type===t);if(a?.entity){const t=this._hass.states?.[a.entity];if(!Xi(t)||["unknown","unavailable"].includes(String(t.state))||!t.attributes.options.includes(e))return;return this._callAction("select.select_option",{entity_id:a.entity,option:e}),void _t(this,"haptic","light")}if(!be(this._hass?.states?.[this.config.entity]))return;if(t===yt.STATE)return this._callAction(`${i.getLocalizationDomain()}.turn_${e}`,{entity_id:this.config.entity}),void _t(this,"haptic","light");const o=i.transformModePayloadValue?.(t,e)??e;this._callAction(`${i.getLocalizationDomain()}.${i.getModeService(t)}`,{entity_id:this.config.entity,[i.getModePayloadKey(t)]:o}),_t(this,"haptic","light")}else _t(this,"haptic","failure")},this.openEntityPopover=(t=null)=>{_t(this,"hass-more-info",{entityId:t||this.config.entity})},this._onActionPointerDown=t=>{0!==t.button&&"mouse"===t.pointerType||(this._holdFired=!1,this._holdTimer&&clearTimeout(this._holdTimer),this._holdTimer=setTimeout(()=>{this._holdFired=!0,this._holdTimer=null,this._dispatchAction("hold")},ia.HOLD_MS))},this._onActionPointerUp=()=>{this._holdTimer&&(clearTimeout(this._holdTimer),this._holdTimer=null)},this._onActionClick=t=>{t.preventDefault(),this._holdFired?this._holdFired=!1:(this._clickCount+=1,1===this._clickCount?(this._clickTimer&&clearTimeout(this._clickTimer),this._clickTimer=setTimeout(()=>{this._clickCount=0,this._clickTimer=null,this._dispatchSetpointTap()},ia.DOUBLE_TAP_MS)):(this._clickTimer&&clearTimeout(this._clickTimer),this._clickTimer=null,this._clickCount=0,this._dispatchAction("double_tap")))},this._onSetpointKeyDown=t=>{"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),this._dispatchSetpointTap())}}static get styles(){return bt}_sendSetpointValues(t){if(!be(this._hass?.states?.[t.entity]))return;const{domain:e,service:i,data:a={}}=t.service;this._callAction(`${e}.${i}`,{entity_id:t.entity,...a,...t.values})}_flushPendingSetpointValues(){this._setpointUpdateTimer&&(clearTimeout(this._setpointUpdateTimer),this._setpointUpdateTimer=null);const t=this._pendingSetpointUpdate;this._pendingSetpointUpdate=null,t&&this._sendSetpointValues(t)}_cancelPendingSetpointValues(){this._setpointUpdateTimer&&(clearTimeout(this._setpointUpdateTimer),this._setpointUpdateTimer=null),this._pendingSetpointUpdate=null}_scheduleSetpointValues(t){const e=this._setpointDebounce,i=function(t){return Object.fromEntries(Object.entries(t).filter(([,t])=>null!=t))}(t);0!==Object.keys(i).length&&(e<=0?this._sendSetpointValues({entity:this.config.entity,service:this.service,values:i}):(this._pendingSetpointUpdate={entity:this.config.entity,service:this.service,values:i},this._setpointUpdateTimer&&clearTimeout(this._setpointUpdateTimer),this._setpointUpdateTimer=setTimeout(()=>{const t=this._pendingSetpointUpdate;this._setpointUpdateTimer=null,this._pendingSetpointUpdate=null,t&&this._sendSetpointValues(t)},e)))}_getSetpointDebounce(t){const e=Number(t?.setpoint_debounce_ms??500);return Number.isFinite(e)&&e>=0?e:500}_callAction(t,e){let i;if("function"==typeof this._hass.performAction)i=this._hass.performAction({action:t,data:e});else if("function"==typeof this._hass.callService){const[a,o]=t.split(".");i=this._hass.callService(a,o,e)}i&&"function"==typeof i.catch&&i.catch(e=>{console.error(`simple-thermostat: ${t} failed`,e)})}static getConfigElement(){return window.document.createElement(`${t}-editor`)}static getStubConfig(t){return{entity:Object.keys(t.states??{}).find(t=>t.startsWith("climate.")||t.startsWith("fan.")||t.startsWith("humidifier."))??""}}setConfig(t){if(!t?.entity||"string"!=typeof t.entity)throw new Error("Simple Thermostat requires an entity");this._flushPendingSetpointValues();const e=this.config?.entity;this._clearMissingEntityTimer(),this.config=xt({decimals:1,...t}),this.config.decimals=Bi(this.config.decimals);const i=this._getSetpointDebounce(this.config);i!==this._setpointDebounce&&(this._setpointDebounce=i),this.entities=[],this.footer=[],this.showEntities=!0,e&&e!==this.config.entity&&this._clearOptimisticSetpointState(),this.toggleAttribute("embedded",!0===this.config.embedded),this._hass?.states?.[this.config.entity]?this.updateFromHass(this._hass):this._hass?.states&&(this.entity=void 0)}_clearMissingEntityTimer(){this._missingEntityTimer&&(clearTimeout(this._missingEntityTimer),this._missingEntityTimer=null)}_scheduleMissingEntity(){this._missingEntityTimer||(this._missingEntityTimer=setTimeout(()=>{this._missingEntityTimer=null,this.entity=void 0},5e3))}set hass(t){if(t?.states&&(this._hass=t),!this.config?.entity)return;if(!t?.states)return;t.states[this.config.entity]?(this._clearMissingEntityTimer(),this.updateFromHass(t)):this._scheduleMissingEntity()}disconnectedCallback(){this._clearOptimisticSetpointState(),this._holdTimer&&(clearTimeout(this._holdTimer),this._holdTimer=null),this._clickTimer&&(clearTimeout(this._clickTimer),this._clickTimer=null),this._clearMissingEntityTimer(),this._stopSetpointRepeat(),this._flushPendingSetpointValues(),super.disconnectedCallback()}connectedCallback(){super.connectedCallback(),this.config?.entity&&this._hass?.states?.[this.config.entity]&&this.updateFromHass(this._hass)}updateFromHass(t){const e=t.states[this.config.entity];this.entity!==e&&(this.entity=e);const i=kt(this.config.entity);this.header=Ne(this.config.header,e,t,!1!==this.config.enhanced_visuals),this.service=function(t,e=St){return t||e.getSetpointService()}(this.config?.service??!1,i);const a=e.attributes;let o=function(t,e,i=St,a){return!1===t?{}:t?Object.entries(t).reduce((t,[i,o])=>{if(o?.hide)return t;const n=Array.isArray(o?.hide_when)?o.hide_when:o?.hide_when?[o.hide_when]:[];return a&&n.includes(a)||(t[i]=e?.[i]),t},{}):i.getSetpoints(e)}(this.config?.setpoints??null,a,i,e.state);this._updatingValues&&!function(t,e){const i=Object.keys(t).sort(),a=Object.keys(e).sort();return i.length===a.length&&i.every((t,e)=>t===a[e])}(o,this._values)?(this._cancelPendingSetpointValues(),this._clearOptimisticSetpointState(),this._values=o):this._updatingValues&&function(t,e){const i=Object.keys(t);return i.length===Object.keys(e).length&&!i.some(i=>t?.[i]!==e?.[i])}(o,this._values)?(this._updatingValues=!1,this._updatingValuesTimeout&&(clearTimeout(this._updatingValuesTimeout),this._updatingValuesTimeout=null)):this._updatingValues||(this._values=o);const n=this.config.entity.split(".")[0],r=function(t){return t.some(({type:t})=>t===yt.STATE)?t.map(t=>t.type&&t.type!==yt.STATE?{...t,list:t.list?.filter(({value:t})=>"off"!==t)??[]}:t):t}(function(t,e,i,a,o){if(!1===t.control)return[];if(Array.isArray(t.control))return ea(t.control,e,i,a);if(t.control&&"object"==typeof t.control){const n=t.control,r=Object.entries(t.control).filter(([t])=>!t.startsWith("_")),s=Array.isArray(n._order)?n._order.map(String):void 0,c=(s?[...s.filter(t=>r.some(([e])=>e===t)),...r.map(([t])=>t).filter(t=>!s.includes(t))]:r.map(([t])=>t)).map(t=>[t,n[t]]);if(c.length>0)return c.filter(([,t])=>!1!==t).filter(([t,o])=>!!(!0===o||!1===o?void 0:o.entity)||ta(t,e,i,a)).map(([t,e])=>{const{_name:n,_hide_when_off:r,hide_when_off:s,hide_off_when_off:c,_icons:l,_heading:d,entity:h,...u}=!0===e?{}:e,p=h?o?.states?.[h]:void 0,m=Xi(p),g={...u,...!0===c?{hide_off_when_off:c}:{}};return{type:t,entity:h,hide_when_off:s??r,icons:l,heading:d,name:n,preserve_option_order:Object.keys(u).length>0,list:h?m&&!["unknown","unavailable"].includes(String(p.state))?Qi(p,g):[]:Yi(t,i,a,g)}})}return ea(a.getDefaultControl(),e,i,a)}(this.config,n,a,i,t)),s=(c=this.config.control,Array.isArray(c)||c&&"object"==typeof c&&(Array.isArray(c._order)||Object.keys(c).some(t=>!t.startsWith("_")))?r:function(t,e){if("fan"!==e&&"climate"!==e)return t;const i=t=>{const e=Ui.indexOf(t);return-1===e?Ui.length:e};return[...t].sort((t,e)=>i(t.type)-i(e.type))}(r,n));var c;this.modes=s.map(o=>{const n=o.preserve_option_order?o.list:o.type===yt.HVAC?function(t){const e=Object.values(Be),i=[],a=[];return t.forEach(t=>{const o=e.indexOf(t.value);o>=0?i[o]=t:a.push(t)}),[...i.filter(Boolean),...a]}(o.list):o.type===yt.FAN?function(t){const e=[],i=[];return t.forEach(t=>{const a=Ge.indexOf(t.value.toLowerCase());a>=0?e[a]=t:i.push(t)}),[...e.filter(Boolean),...i]}(o.list):o.list,r=o.entity&&t.states?.[o.entity]?t.states[o.entity].state:o.type===yt.HVAC||o.type===yt.STATE?e.state:a[i.getModePayloadKey(o.type)];return{...o,list:n,mode:r}});const{step:l}=i.getRange(a);this.stepSize=Number(this.config.step_size??l??.5),this._hide={...Di,...this.config.hide??{}};const d=this.config.entities??[];!1===d?(this.showEntities=!1,this.entities=[]):d?(this.showEntities=!0,this.entities=d.map(({name:e,entity:i,attribute:a,template:o,unit:n="",decimals:r,...s})=>{let c;const l=[e];return i?(c=t.states[i],l.push(c?.attributes?.friendly_name)):a&&a in(this.entity.attributes??{})&&(c=this.entity,l.push(a)),l.push(i),{...s,name:l.find(t=>!!t),state:c,entity:i,attribute:a,template:o,unit:n,...void 0!==r?{decimals:Bi(r,this.config.decimals??1)}:{}}})):(this.showEntities=!0,this.entities=[]),this.footer=function(t){return Array.isArray(t.footer)?t.footer:[]}(this.config).map(({entity:e,name:i,icon:a,hide_when_off:o})=>{const n=t.states?.[e];return n?{entity:e,name:i,icon:a,hide_when_off:o,state:n}:null}).filter(t=>!!t)}_localizeFirst(t,e){for(const e of t){const t=this._hass.localize?.(e);if(t&&t!==e)return t}return e}_getSetpointLabel(t){return this.config.label?.setpoint??this._hass.localize?.(`ui.card.${kt(this.config.entity).getLocalizationDomain()}.target`)??this._hass.localize?.("ui.card.climate.target_temperature")??this.localize(t,"state_attributes.climate.")}render({_hide:t,_values:e,_updatingValues:i,config:a,entity:o}=this){if(!a)return B`