// omni_pca side panel — generated by frontend/build.mjs. Edit src/, not this file. var Oe=Object.defineProperty;var He=Object.getOwnPropertyDescriptor;var u=(n,t,e,r)=>{for(var i=r>1?void 0:r?He(t,e):t,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=(r?o(t,e,i):o(i))||i);return r&&i&&Oe(t,e,i),i};var j=globalThis,U=j.ShadowRoot&&(j.ShadyCSS===void 0||j.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,W=Symbol(),he=new WeakMap,R=class{constructor(t,e,r){if(this._$cssResult$=!0,r!==W)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o,e=this.t;if(U&&t===void 0){let r=e!==void 0&&e.length===1;r&&(t=he.get(e)),t===void 0&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),r&&he.set(e,t))}return t}toString(){return this.cssText}},me=n=>new R(typeof n=="string"?n:n+"",void 0,W),Z=(n,...t)=>{let e=n.length===1?n[0]:t.reduce((r,i,s)=>r+(o=>{if(o._$cssResult$===!0)return o.cssText;if(typeof o=="number")return o;throw Error("Value passed to 'css' function must be a 'css' function result: "+o+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+n[s+1],n[0]);return new R(e,n,W)},fe=(n,t)=>{if(U)n.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(let e of t){let r=document.createElement("style"),i=j.litNonce;i!==void 0&&r.setAttribute("nonce",i),r.textContent=e.cssText,n.appendChild(r)}},G=U?n=>n:n=>n instanceof CSSStyleSheet?(t=>{let e="";for(let r of t.cssRules)e+=r.cssText;return me(e)})(n):n;var{is:je,defineProperty:Ue,getOwnPropertyDescriptor:Be,getOwnPropertyNames:Ye,getOwnPropertySymbols:qe,getPrototypeOf:Ve}=Object,B=globalThis,ge=B.trustedTypes,We=ge?ge.emptyScript:"",Ze=B.reactiveElementPolyfillSupport,M=(n,t)=>n,D={toAttribute(n,t){switch(t){case Boolean:n=n?We:null;break;case Object:case Array:n=n==null?n:JSON.stringify(n)}return n},fromAttribute(n,t){let e=n;switch(t){case Boolean:e=n!==null;break;case Number:e=n===null?null:Number(n);break;case Object:case Array:try{e=JSON.parse(n)}catch{e=null}}return e}},Y=(n,t)=>!je(n,t),_e={attribute:!0,type:String,converter:D,reflect:!1,useDefault:!1,hasChanged:Y};Symbol.metadata??=Symbol("metadata"),B.litPropertyMetadata??=new WeakMap;var b=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=_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){let r=Symbol(),i=this.getPropertyDescriptor(t,r,e);i!==void 0&&Ue(this.prototype,t,i)}}static getPropertyDescriptor(t,e,r){let{get:i,set:s}=Be(this.prototype,t)??{get(){return this[e]},set(o){this[e]=o}};return{get:i,set(o){let c=i?.call(this);s?.call(this,o),this.requestUpdate(t,c,r)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??_e}static _$Ei(){if(this.hasOwnProperty(M("elementProperties")))return;let t=Ve(this);t.finalize(),t.l!==void 0&&(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"))){let e=this.properties,r=[...Ye(e),...qe(e)];for(let i of r)this.createProperty(i,e[i])}let t=this[Symbol.metadata];if(t!==null){let e=litPropertyMetadata.get(t);if(e!==void 0)for(let[r,i]of e)this.elementProperties.set(r,i)}this._$Eh=new Map;for(let[e,r]of this.elementProperties){let i=this._$Eu(e,r);i!==void 0&&this._$Eh.set(i,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){let e=[];if(Array.isArray(t)){let r=new Set(t.flat(1/0).reverse());for(let i of r)e.unshift(G(i))}else t!==void 0&&e.push(G(t));return e}static _$Eu(t,e){let r=e.attribute;return r===!1?void 0:typeof r=="string"?r:typeof t=="string"?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),this.renderRoot!==void 0&&this.isConnected&&t.hostConnected?.()}removeController(t){this._$EO?.delete(t)}_$E_(){let t=new Map,e=this.constructor.elementProperties;for(let r of e.keys())this.hasOwnProperty(r)&&(t.set(r,this[r]),delete this[r]);t.size>0&&(this._$Ep=t)}createRenderRoot(){let t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return fe(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,r){this._$AK(t,r)}_$ET(t,e){let r=this.constructor.elementProperties.get(t),i=this.constructor._$Eu(t,r);if(i!==void 0&&r.reflect===!0){let s=(r.converter?.toAttribute!==void 0?r.converter:D).toAttribute(e,r.type);this._$Em=t,s==null?this.removeAttribute(i):this.setAttribute(i,s),this._$Em=null}}_$AK(t,e){let r=this.constructor,i=r._$Eh.get(t);if(i!==void 0&&this._$Em!==i){let s=r.getPropertyOptions(i),o=typeof s.converter=="function"?{fromAttribute:s.converter}:s.converter?.fromAttribute!==void 0?s.converter:D;this._$Em=i;let c=o.fromAttribute(e,s.type);this[i]=c??this._$Ej?.get(i)??c,this._$Em=null}}requestUpdate(t,e,r,i=!1,s){if(t!==void 0){let o=this.constructor;if(i===!1&&(s=this[t]),r??=o.getPropertyOptions(t),!((r.hasChanged??Y)(s,e)||r.useDefault&&r.reflect&&s===this._$Ej?.get(t)&&!this.hasAttribute(o._$Eu(t,r))))return;this.C(t,e,r)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(t,e,{useDefault:r,reflect:i,wrapped:s},o){r&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,o??e??this[t]),s!==!0||o!==void 0)||(this._$AL.has(t)||(this.hasUpdated||r||(e=void 0),this._$AL.set(t,e)),i===!0&&this._$Em!==t&&(this._$Eq??=new Set).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(e){Promise.reject(e)}let t=this.scheduleUpdate();return t!=null&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(let[i,s]of this._$Ep)this[i]=s;this._$Ep=void 0}let r=this.constructor.elementProperties;if(r.size>0)for(let[i,s]of r){let{wrapped:o}=s,c=this[i];o!==!0||this._$AL.has(i)||c===void 0||this.C(i,void 0,s,c)}}let t=!1,e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),this._$EO?.forEach(r=>r.hostUpdate?.()),this.update(e)):this._$EM()}catch(r){throw t=!1,this._$EM(),r}t&&this._$AE(e)}willUpdate(t){}_$AE(t){this._$EO?.forEach(e=>e.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(e=>this._$ET(e,this[e])),this._$EM()}updated(t){}firstUpdated(t){}};b.elementStyles=[],b.shadowRootOptions={mode:"open"},b[M("elementProperties")]=new Map,b[M("finalized")]=new Map,Ze?.({ReactiveElement:b}),(B.reactiveElementVersions??=[]).push("2.1.2");var re=globalThis,ve=n=>n,q=re.trustedTypes,be=q?q.createPolicy("lit-html",{createHTML:n=>n}):void 0,Se="$lit$",$=`lit$${Math.random().toFixed(9).slice(2)}$`,we="?"+$,Ge=`<${we}>`,S=document,P=()=>S.createComment(""),z=n=>n===null||typeof n!="object"&&typeof n!="function",ie=Array.isArray,Ke=n=>ie(n)||typeof n?.[Symbol.iterator]=="function",K=`[ \f\r]`,I=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,ye=/-->/g,$e=/>/g,E=RegExp(`>|${K}(?:([^\\s"'>=/]+)(${K}*=${K}*(?:[^ \f\r"'\`<>=]|("|')|))|$)`,"g"),xe=/'/g,Ee=/"/g,Te=/^(?:script|style|textarea|title)$/i,ne=n=>(t,...e)=>({_$litType$:n,strings:t,values:e}),a=ne(1),dt=ne(2),pt=ne(3),w=Symbol.for("lit-noChange"),g=Symbol.for("lit-nothing"),ke=new WeakMap,k=S.createTreeWalker(S,129);function Ae(n,t){if(!ie(n)||!n.hasOwnProperty("raw"))throw Error("invalid template strings array");return be!==void 0?be.createHTML(t):t}var Je=(n,t)=>{let e=n.length-1,r=[],i,s=t===2?"":t===3?"":"",o=I;for(let c=0;c"?(o=i??I,d=-1):f[1]===void 0?d=-2:(d=o.lastIndex-f[2].length,h=f[1],o=f[3]===void 0?E:f[3]==='"'?Ee:xe):o===Ee||o===xe?o=E:o===ye||o===$e?o=I:(o=E,i=void 0);let y=o===E&&n[c+1].startsWith("/>")?" ":"";s+=o===I?l+Ge:d>=0?(r.push(h),l.slice(0,d)+Se+l.slice(d)+$+y):l+$+(d===-2?c:y)}return[Ae(n,s+(n[e]||"")+(t===2?"":t===3?"":"")),r]},N=class n{constructor({strings:t,_$litType$:e},r){let i;this.parts=[];let s=0,o=0,c=t.length-1,l=this.parts,[h,f]=Je(t,e);if(this.el=n.createElement(h,r),k.currentNode=this.el.content,e===2||e===3){let d=this.el.content.firstChild;d.replaceWith(...d.childNodes)}for(;(i=k.nextNode())!==null&&l.length0){i.textContent=q?q.emptyScript:"";for(let y=0;y2||r[0]!==""||r[1]!==""?(this._$AH=Array(r.length-1).fill(new String),this.strings=r):this._$AH=g}_$AI(t,e=this,r,i){let s=this.strings,o=!1;if(s===void 0)t=T(this,t,e,0),o=!z(t)||t!==this._$AH&&t!==w,o&&(this._$AH=t);else{let c=t,l,h;for(t=s[0],l=0;l{let r=e?.renderBefore??t,i=r._$litPart$;if(i===void 0){let s=e?.renderBefore??null;r._$litPart$=i=new L(t.insertBefore(P(),s),s,void 0,e??{})}return i._$AI(n),i};var se=globalThis,x=class extends b{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){let t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){let e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=Ce(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return w}};x._$litElement$=!0,x.finalized=!0,se.litElementHydrateSupport?.({LitElement:x});var Qe=se.litElementPolyfillSupport;Qe?.({LitElement:x});(se.litElementVersions??=[]).push("4.2.2");var Fe=n=>(t,e)=>{e!==void 0?e.addInitializer(()=>{customElements.define(n,t)}):customElements.define(n,t)};var et={attribute:!0,type:String,converter:D,reflect:!1,hasChanged:Y},tt=(n=et,t,e)=>{let{kind:r,metadata:i}=e,s=globalThis.litPropertyMetadata.get(i);if(s===void 0&&globalThis.litPropertyMetadata.set(i,s=new Map),r==="setter"&&((n=Object.create(n)).wrapped=!0),s.set(e.name,n),r==="accessor"){let{name:o}=e;return{set(c){let l=t.get.call(this);t.set.call(this,c),this.requestUpdate(o,l,n,!0,c)},init(c){return c!==void 0&&this.C(o,void 0,n,c),c}}}if(r==="setter"){let{name:o}=e;return function(c){let l=this[o];t.call(this,c),this.requestUpdate(o,l,n,!0,c)}}throw Error("Unsupported decorator location: "+r)};function O(n){return(t,e)=>typeof e=="object"?tt(n,t,e):((r,i,s)=>{let o=i.hasOwnProperty(s);return i.constructor.createProperty(s,r),o?Object.getOwnPropertyDescriptor(i,s):void 0})(n,t,e)}function m(n){return O({...n,state:!0,attribute:!1})}function oe(n,t){return a`${n.map(e=>rt(e,t))}`}function rt(n,t){switch(n.k){case"newline":return a`
`;case"indent":return a`${n.t}`;case"keyword":return a`${n.t}`;case"operator":return a`${n.t}`;case"value":return a`${n.t}`;case"ref":{let e=t&&n.ek&&typeof n.ei=="number"?()=>t(n.ek,n.ei):void 0;return a``}default:return a`${n.t}`}}var ae=[{value:0,label:"Turn OFF unit",ref_kind:"unit"},{value:1,label:"Turn ON unit",ref_kind:"unit"},{value:2,label:"All OFF",ref_kind:null},{value:3,label:"All ON",ref_kind:null},{value:4,label:"Bypass zone",ref_kind:"zone"},{value:5,label:"Restore zone",ref_kind:"zone"},{value:7,label:"Execute button",ref_kind:"button"},{value:9,label:"Set unit level %",ref_kind:"unit"},{value:48,label:"Disarm area",ref_kind:"area"},{value:49,label:"Arm area Day",ref_kind:"area"},{value:50,label:"Arm area Night",ref_kind:"area"},{value:51,label:"Arm area Away",ref_kind:"area"},{value:52,label:"Arm area Vacation",ref_kind:"area"}];function le(n){return ae.find(t=>t.value===n)}var Re=[{bit:2,label:"Mon"},{bit:4,label:"Tue"},{bit:8,label:"Wed"},{bit:16,label:"Thu"},{bit:32,label:"Fri"},{bit:64,label:"Sat"},{bit:128,label:"Sun"}],ce=1,de=2,pe=3;var ue=[{id:768,label:"Phone line dead"},{id:769,label:"Phone ringing"},{id:770,label:"Phone off hook"},{id:771,label:"Phone on hook"},{id:772,label:"AC power lost"},{id:773,label:"AC power restored"}];function C(n){if(ue.some(t=>t.id===n))return{category:"fixed",fixedId:n};if(!(n&65280))return{category:"button",button:n&255};if((n&64512)===1024){let t=n&1023;return{category:"zone",zone:Math.floor(t/4)+1,zoneState:t%4}}if((n&64512)===2048){let t=n&1023;return{category:"unit",unit:Math.floor(t/2)+1,unitOn:(t&1)===1}}return{category:"raw",raw:n}}function Me(n){switch(n.category){case"button":return(n.button??1)&255;case"zone":{let t=(n.zone??1)-1,e=(n.zoneState??0)&3;return 1024|t*4+e&1023}case"unit":{let t=(n.unit??1)-1,e=n.unitOn?1:0;return 2048|t*2+e&1023}case"fixed":return n.fixedId??768;case"raw":default:return n.raw??0}}function F(n){return(n.month??0)<<8|(n.day??0)}function De(n,t){return{...n,month:t>>8&255,day:t&255}}var Ie=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Pe=[{value:0,label:"always"},{value:1,label:"never"},{value:2,label:"it is light outside"},{value:3,label:"it is dark outside"},{value:4,label:"phone line is dead"},{value:5,label:"phone is ringing"},{value:6,label:"phone is off hook"},{value:7,label:"phone is on hook"},{value:8,label:"AC power is off"},{value:9,label:"AC power is on"},{value:10,label:"battery is low"},{value:11,label:"battery is OK"},{value:12,label:"energy cost is low"},{value:13,label:"energy cost is mid"},{value:14,label:"energy cost is high"},{value:15,label:"energy cost is critical"}],ze=[{value:0,label:"Off (disarmed)"},{value:1,label:"Day"},{value:2,label:"Night"},{value:3,label:"Away"},{value:4,label:"Vacation"},{value:5,label:"Day Instant"},{value:6,label:"Night Delayed"}];function Ne(n){if(n===0)return{family:"none"};let t=n>>8&252,e=(n&512)!==0;return t===0?{family:"misc",misc:n&15}:t===4?{family:"zone",index:n&255,active:e}:t===8?{family:"unit",index:n&511,active:e}:t===12?{family:"time",index:n&255,active:e}:{family:"sec",index:n>>8&15,mode:n>>12&7}}function _(n){switch(n.family){case"none":return 0;case"misc":return(n.misc??0)&15;case"zone":{let t=(n.index??0)&255;return 1024|(n.active?512:0)|t}case"unit":{let t=(n.index??0)&511;return 2048|(n.active?512:0)|t}case"time":{let t=(n.index??0)&255;return 3072|(n.active?512:0)|t}case"sec":{let t=(n.index??1)&15;return((n.mode??0)&7)<<12|t<<8}}}var Le=new Set(["TIMED","EVENT","YEARLY"]),it=["TIMED","EVENT","YEARLY","WHEN","AT","EVERY","REMARK"],nt=5e3,p=class extends x{constructor(){super(...arguments);this.narrow=!1;this._entryId=null;this._rows=[];this._total=0;this._filteredTotal=0;this._loading=!1;this._error=null;this._activeTriggerTypes=new Set;this._referenceFilter=null;this._searchTerm="";this._selectedSlot=null;this._detail=null;this._detailLoading=!1;this._fireFeedback=null;this._writeFeedback=null;this._cloneTargetSlot="";this._showCloneInput=!1;this._confirmingClear=!1;this._editingDraft=null;this._objects=null;this._refreshTimer=null}connectedCallback(){super.connectedCallback(),this._discoverEntry(),this._entryId&&(this._loadList(),this._startRefreshTimer())}disconnectedCallback(){super.disconnectedCallback(),this._stopRefreshTimer()}updated(e){e.has("hass")&&this._entryId===null&&(this._discoverEntry(),this._entryId&&(this._loadList(),this._startRefreshTimer()))}_discoverEntry(){this.hass?.connection&&this._discoverViaList()}async _discoverViaList(){try{let r=(await this.hass.connection.sendMessagePromise({type:"config_entries/get"})).filter(s=>s.domain==="omni_pca");if(r.length===0){this._error="No Omni panel configured. Add one via Settings \u2192 Devices & Services.";return}let i=r.find(s=>s.state==="loaded");this._entryId=(i??r[0]).entry_id,this._error=null,this._loadList(),this._startRefreshTimer()}catch(e){this._error=`Could not discover panels: ${e instanceof Error?e.message:String(e)}`}}async _loadList(){if(this._entryId){this._loading=!0,this._error=null;try{let e={type:"omni_pca/programs/list",entry_id:this._entryId};this._activeTriggerTypes.size>0&&(e.trigger_types=[...this._activeTriggerTypes]),this._referenceFilter&&(e.references_entity=this._referenceFilter),this._searchTerm&&(e.search=this._searchTerm);let r=await this.hass.connection.sendMessagePromise(e);this._rows=r.programs,this._total=r.total,this._filteredTotal=r.filtered_total}catch(e){this._error=e instanceof Error?e.message:String(e)}finally{this._loading=!1}}}async _loadDetail(e){if(this._entryId){this._detailLoading=!0,this._detail=null;try{this._detail=await this.hass.connection.sendMessagePromise({type:"omni_pca/programs/get",entry_id:this._entryId,slot:e})}catch(r){this._error=r instanceof Error?r.message:String(r)}finally{this._detailLoading=!1}}}async _fireProgram(e){if(this._entryId){this._fireFeedback="firing\u2026";try{await this.hass.connection.sendMessagePromise({type:"omni_pca/programs/fire",entry_id:this._entryId,slot:e}),this._fireFeedback=`fired slot ${e}`}catch(r){this._fireFeedback=`error: ${r instanceof Error?r.message:r}`}setTimeout(()=>{this._fireFeedback=null},4e3)}}async _clearProgram(e){if(this._entryId){this._writeFeedback="clearing\u2026";try{await this.hass.connection.sendMessagePromise({type:"omni_pca/programs/clear",entry_id:this._entryId,slot:e}),this._writeFeedback=`cleared slot ${e}`,this._confirmingClear=!1,this._selectedSlot=null,this._detail=null,await this._loadList()}catch(r){let i=r instanceof Error?r.message:String(r);this._writeFeedback=`error: ${i}`}setTimeout(()=>{this._writeFeedback=null},4e3)}}async _cloneProgram(e){if(!this._entryId)return;let r=this._cloneTargetSlot.trim(),i=parseInt(r,10);if(!Number.isFinite(i)||i<1||i>1500){this._writeFeedback="target slot must be 1..1500",setTimeout(()=>{this._writeFeedback=null},4e3);return}if(i===e){this._writeFeedback="target must differ from source",setTimeout(()=>{this._writeFeedback=null},4e3);return}this._writeFeedback="cloning\u2026";try{await this.hass.connection.sendMessagePromise({type:"omni_pca/programs/clone",entry_id:this._entryId,source_slot:e,target_slot:i}),this._writeFeedback=`cloned to slot ${i}`,this._showCloneInput=!1,this._cloneTargetSlot="",this._selectedSlot=i,await this._loadList(),await this._loadDetail(i)}catch(s){let o=s instanceof Error?s.message:String(s);this._writeFeedback=`error: ${o}`}setTimeout(()=>{this._writeFeedback=null},4e3)}_onCloneTargetInput(e){this._cloneTargetSlot=e.target.value}async _ensureObjectsLoaded(){if(!(this._objects!==null||!this._entryId))try{this._objects=await this.hass.connection.sendMessagePromise({type:"omni_pca/objects/list",entry_id:this._entryId})}catch(e){let r=e instanceof Error?e.message:String(e);console.warn("omni_pca: objects/list failed",r)}}async _beginEdit(){if(!this._detail||this._detail.kind!=="compact"||!Le.has(this._detail.trigger_type)||(await this._ensureObjectsLoaded(),!this._entryId))return;let e=this._detail.fields??this._defaultFieldsForType(this._detail.trigger_type);e!==null&&(this._editingDraft={...e},this._stopRefreshTimer())}_defaultFieldsForType(e){let r=this._objects?.units?.[0]?.index??1;if(e==="TIMED")return{prog_type:ce,cmd:1,par:0,pr2:r,hour:6,minute:0,days:62,cond:0,cond2:0,month:0,day:0};if(e==="EVENT"){let i=this._objects?.buttons?.[0]?.index??1;return{prog_type:de,cmd:1,par:0,pr2:r,month:0,day:i&255,hour:0,minute:0,days:0,cond:0,cond2:0}}return e==="YEARLY"?{prog_type:pe,cmd:1,par:0,pr2:r,month:1,day:1,hour:0,minute:0,days:0,cond:0,cond2:0}:null}async _saveDraft(){if(!(!this._editingDraft||!this._detail||!this._entryId)){this._writeFeedback="saving\u2026";try{await this.hass.connection.sendMessagePromise({type:"omni_pca/programs/write",entry_id:this._entryId,slot:this._detail.slot,program:this._editingDraft}),this._writeFeedback=`saved slot ${this._detail.slot}`,this._editingDraft=null,this._startRefreshTimer(),await this._loadList(),await this._loadDetail(this._detail.slot)}catch(e){let r=e instanceof Error?e.message:String(e);this._writeFeedback=`error: ${r}`}setTimeout(()=>{this._writeFeedback=null},4e3)}}_cancelEdit(){this._editingDraft=null,this._startRefreshTimer()}_patchDraft(e){this._editingDraft&&(this._editingDraft={...this._editingDraft,...e})}_toggleDayBit(e){if(!this._editingDraft)return;let i=(this._editingDraft.days??0)^e;this._patchDraft({days:i})}_onCommandChange(e){let r=parseInt(e.target.value,10);if(!Number.isFinite(r))return;let i=le(r),s=this._editingDraft?.pr2??0;if(i?.ref_kind&&this._objects){let o=this._pickBucket(i.ref_kind);o&&o.length>0&&!o.some(c=>c.index===s)&&(s=o[0].index)}else i?.ref_kind||(s=0);this._patchDraft({cmd:r,pr2:s})}_pickBucket(e){if(!this._objects)return null;switch(e){case"zone":return this._objects.zones;case"unit":return this._objects.units;case"area":return this._objects.areas;case"button":return this._objects.buttons;default:return null}}_bucketWithPreserve(e,r,i){let s=e??[];return i===0||s.some(o=>o.index===i)?s:[{index:i,name:`(undiscovered ${r} ${i} \u2014 preserve original)`},...s]}_onObjectChange(e){let r=parseInt(e.target.value,10);Number.isFinite(r)&&this._patchDraft({pr2:r})}_onHourChange(e){let r=parseInt(e.target.value,10);Number.isFinite(r)&&r>=0&&r<=23&&this._patchDraft({hour:r})}_onMinuteChange(e){let r=parseInt(e.target.value,10);Number.isFinite(r)&&r>=0&&r<=59&&this._patchDraft({minute:r})}_onParChange(e){let r=parseInt(e.target.value,10);Number.isFinite(r)&&r>=0&&r<=255&&this._patchDraft({par:r})}_onMonthChange(e){let r=parseInt(e.target.value,10);Number.isFinite(r)&&r>=1&&r<=12&&this._patchDraft({month:r})}_onDayChange(e){let r=parseInt(e.target.value,10);Number.isFinite(r)&&r>=1&&r<=31&&this._patchDraft({day:r})}_patchEvent(e){if(!this._editingDraft)return;let r=Me(e);this._editingDraft=De(this._editingDraft,r)}_onEventCategoryChange(e){let r=e.target.value;if(r==="button"){let i=this._objects?.buttons?.[0]?.index??1;this._patchEvent({category:"button",button:i})}else if(r==="zone"){let i=this._objects?.zones?.[0]?.index??1;this._patchEvent({category:"zone",zone:i,zoneState:1})}else if(r==="unit"){let i=this._objects?.units?.[0]?.index??1;this._patchEvent({category:"unit",unit:i,unitOn:!0})}else r==="fixed"&&this._patchEvent({category:"fixed",fixedId:772})}_onEventButtonChange(e){let r=parseInt(e.target.value,10);Number.isFinite(r)&&this._patchEvent({category:"button",button:r})}_onEventZoneChange(e){if(!this._editingDraft)return;let r=parseInt(e.target.value,10);if(!Number.isFinite(r))return;let i=C(F(this._editingDraft));this._patchEvent({category:"zone",zone:r,zoneState:i.zoneState??1})}_onEventZoneStateChange(e){if(!this._editingDraft)return;let r=parseInt(e.target.value,10);if(!Number.isFinite(r))return;let i=C(F(this._editingDraft));this._patchEvent({category:"zone",zone:i.zone??1,zoneState:r})}_onEventUnitChange(e){if(!this._editingDraft)return;let r=parseInt(e.target.value,10);if(!Number.isFinite(r))return;let i=C(F(this._editingDraft));this._patchEvent({category:"unit",unit:r,unitOn:i.unitOn??!0})}_onEventUnitOnChange(e){if(!this._editingDraft)return;let r=e.target.value==="1",i=C(F(this._editingDraft));this._patchEvent({category:"unit",unit:i.unit??1,unitOn:r})}_onEventFixedChange(e){let r=parseInt(e.target.value,10);Number.isFinite(r)&&this._patchEvent({category:"fixed",fixedId:r})}_startRefreshTimer(){this._refreshTimer===null&&(this._refreshTimer=window.setInterval(()=>{this._loadList(),this._selectedSlot!==null&&this._loadDetail(this._selectedSlot)},nt))}_stopRefreshTimer(){this._refreshTimer!==null&&(window.clearInterval(this._refreshTimer),this._refreshTimer=null)}_toggleTriggerFilter(e){let r=new Set(this._activeTriggerTypes);r.has(e)?r.delete(e):r.add(e),this._activeTriggerTypes=r,this._loadList()}_onSearchInput(e){this._searchTerm=e.target.value,this._loadList()}_clearReferenceFilter(){this._referenceFilter=null,this._loadList()}_onRowClick(e){this._selectedSlot=e,this._loadDetail(e)}_onRefClick(e,r){this._referenceFilter=`${e}:${r}`,this._selectedSlot=null,this._detail=null,this._loadList()}_closeDetail(){this._selectedSlot=null,this._detail=null}render(){return a`
Omni Programs ${this._total>0?a` ${this._filteredTotal===this._total?`${this._total} programs`:`${this._filteredTotal} of ${this._total} shown`} `:""}
${this._error?a`
${this._error}
`:""} ${this._renderFilters()}
${this._renderList()} ${this._selectedSlot!==null?this._renderDetail():""}
`}_renderFilters(){return a`
${it.map(e=>a` `)}
${this._referenceFilter?a`
filtering on ${this._referenceFilter}
`:""}
`}_renderList(){return this._loading&&this._rows.length===0?a`
loading…
`:this._rows.length===0?a`
No programs match the current filters.
`:a`
${this._rows.map(e=>a`
this._onRowClick(e.slot)} >
#${e.slot}
${oe(e.summary,(r,i)=>this._onRefClick(r,i))}
${e.trigger_type} ${e.condition_count>0?a` ${e.condition_count} cond`:""} ${e.action_count>1?a` ${e.action_count} actions`:""}
`)}
`}_renderDetail(){if(this._detailLoading)return a``;if(this._detail===null)return a``;let e=this._detail;return this._editingDraft!==null?this._renderEditor(e):a` `}_renderEditor(e){let r=this._editingDraft,i=e.trigger_type;return a` `}_renderTriggerSection(e){switch(e.prog_type){case ce:return this._renderTimedTrigger(e);case de:return this._renderEventTrigger(e);case pe:return this._renderYearlyTrigger(e);default:return a`
Editing program type ${e.prog_type} is not supported.
`}}_renderTimedTrigger(e){return a`
Time
:
Days
${Re.map(r=>{let i=((e.days??0)&r.bit)!==0;return a` `})}
`}_renderEventTrigger(e){let r=F(e),i=C(r);return a`
Trigger event ${this._renderEventCategoryFields(i)}
`}_renderEventCategoryFields(e){if(e.category==="button"){let r=this._bucketWithPreserve(this._objects?.buttons??null,"button",e.button??0);return a` `}if(e.category==="zone"){let r=this._bucketWithPreserve(this._objects?.zones??null,"zone",e.zone??0);return a` `}if(e.category==="unit"){let r=this._bucketWithPreserve(this._objects?.units??null,"unit",e.unit??0);return a` `}return e.category==="fixed"?a` `:a`
Unrecognised event ID. Switch category above to redefine.
`}_renderYearlyTrigger(e){return a`
Date
Time of day
:
`}_renderActionSection(e){let r=le(e.cmd??0),i=r?.ref_kind?this._bucketWithPreserve(this._pickBucket(r.ref_kind),r.ref_kind,e.pr2??0):null,s=e.cmd===9;return a`
Action ${r?.ref_kind?a` `:""} ${s?a` `:""}
`}_renderConditionsSection(e){return a`
Inline AND-IF conditions ${this._renderConditionSlot("First condition",e.cond??0,r=>this._patchDraft({cond:r}))} ${this._renderConditionSlot("Second condition",e.cond2??0,r=>this._patchDraft({cond2:r}))}
`}_renderConditionSlot(e,r,i){let s=Ne(r),o=c=>{let l=this._objects?.zones?.[0]?.index??1,h=this._objects?.units?.[0]?.index??1,f=this._objects?.areas?.[0]?.index??1,d;switch(c){case"none":d={family:"none"};break;case"misc":d={family:"misc",misc:1};break;case"zone":d={family:"zone",index:l,active:!1};break;case"unit":d={family:"unit",index:h,active:!0};break;case"time":d={family:"time",index:1,active:!0};break;case"sec":d={family:"sec",index:f,mode:0};break}i(_(d))};return a`
${this._renderConditionSubfields(s,i)}
`}_renderConditionSubfields(e,r){if(e.family==="none")return a``;if(e.family==="zone"){let i=this._bucketWithPreserve(this._objects?.zones??null,"zone",e.index??0);return a` `}if(e.family==="unit"){let i=this._bucketWithPreserve(this._objects?.units??null,"unit",e.index??0);return a` `}if(e.family==="sec"){let i=this._bucketWithPreserve(this._objects?.areas??null,"area",e.index??0);return a` `}return e.family==="time"?a` `:a` `}};p.styles=Z` :host { display: block; min-height: 100vh; background: var(--primary-background-color, #fafafa); color: var(--primary-text-color, #000); font-family: var(--paper-font-body1_-_font-family, sans-serif); } .header { display: flex; align-items: center; padding: 16px 20px; background: var(--primary-color, #03a9f4); color: var(--text-primary-color, #fff); } .header .title { display: flex; align-items: center; gap: 10px; font-size: 1.2rem; } .header .count { margin-left: 12px; font-size: 0.85rem; opacity: 0.85; font-weight: normal; } .error { margin: 12px 16px; padding: 10px 14px; background: var(--error-color, #db4437); color: white; border-radius: 4px; } .filters { padding: 12px 16px 8px; border-bottom: 1px solid var(--divider-color, #ddd); } .search { width: 100%; padding: 8px 10px; font-size: 0.95rem; border: 1px solid var(--divider-color, #ccc); border-radius: 4px; background: var(--card-background-color, #fff); color: inherit; box-sizing: border-box; } .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; } .chip { border: 1px solid var(--divider-color, #ccc); background: var(--card-background-color, #fff); color: var(--secondary-text-color, #555); padding: 4px 10px; border-radius: 12px; font-size: 0.78rem; cursor: pointer; font-family: inherit; } .chip:hover { background: var(--secondary-background-color, #eee); } .chip.active { background: var(--primary-color, #03a9f4); color: var(--text-primary-color, #fff); border-color: transparent; } .ref-filter { margin-top: 8px; font-size: 0.85rem; color: var(--secondary-text-color, #555); display: flex; align-items: center; gap: 8px; } .ref-filter button { border: 1px solid var(--divider-color, #ccc); background: transparent; color: inherit; padding: 2px 8px; border-radius: 8px; font-size: 0.75rem; cursor: pointer; } .body { display: grid; grid-template-columns: 1fr; gap: 0; } .body[data-narrow="false"] { grid-template-columns: 1fr 380px; } .list { max-height: calc(100vh - 200px); overflow-y: auto; } .row { display: grid; grid-template-columns: 60px 1fr auto; align-items: start; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--divider-color, #eee); cursor: pointer; } .row:hover { background: var(--secondary-background-color, #f5f5f5); } .row.selected { background: var(--state-active-color, #e3f2fd); } .row-slot { font-family: var(--code-font-family, monospace); font-size: 0.78rem; color: var(--secondary-text-color, #888); padding-top: 2px; } .row-summary { font-size: 0.92rem; line-height: 1.45; } .row-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; } /* trigger-type badges */ .trigger-badge { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.5px; padding: 2px 6px; border-radius: 3px; text-transform: uppercase; } .trigger-timed { background: #e3f2fd; color: #1565c0; } .trigger-event { background: #fff3e0; color: #e65100; } .trigger-yearly { background: #f3e5f5; color: #6a1b9a; } .trigger-when { background: #e8f5e9; color: #2e7d32; } .trigger-at { background: #e3f2fd; color: #1565c0; } .trigger-every { background: #fce4ec; color: #ad1457; } .trigger-remark { background: #f5f5f5; color: #616161; } .meta-pill { font-size: 0.7rem; color: var(--secondary-text-color, #888); background: var(--secondary-background-color, #eee); padding: 1px 6px; border-radius: 8px; } /* token-renderer styles */ .row-summary, .detail-body { font-family: var(--paper-font-body1_-_font-family, system-ui, sans-serif); } .keyword { font-weight: 600; color: var(--primary-color, #1565c0); } .operator { color: var(--secondary-text-color, #666); font-style: italic; } .value { font-family: var(--code-font-family, monospace); color: var(--accent-color, #ff6f00); } .ref { display: inline-flex; align-items: baseline; gap: 4px; border: none; background: transparent; padding: 0 2px; cursor: pointer; font: inherit; color: inherit; border-bottom: 1px dotted var(--secondary-text-color, #999); } .ref:hover { background: var(--secondary-background-color, #eee); } .ref-name { font-weight: 500; } .ref-state { font-size: 0.72rem; padding: 1px 5px; border-radius: 3px; background: var(--secondary-background-color, #eee); color: var(--secondary-text-color, #666); vertical-align: 1px; } .ref-zone .ref-name { color: var(--info-color, #0288d1); } .ref-unit .ref-name { color: var(--warning-color, #f57c00); } .ref-area .ref-name { color: var(--success-color, #388e3c); } .ref-thermostat .ref-name { color: var(--accent-color, #c2185b); } .ref-button .ref-name { color: var(--state-light-color, #7e57c2); } .indent { display: inline-block; width: 1.5em; } /* detail panel */ .detail { border-left: 1px solid var(--divider-color, #ddd); padding: 16px; max-height: calc(100vh - 200px); overflow-y: auto; box-sizing: border-box; } .body[data-narrow="true"] .detail { border-left: none; border-top: 1px solid var(--divider-color, #ddd); } .detail header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; } .detail header .slot { margin-left: 8px; font-family: var(--code-font-family, monospace); font-size: 0.85rem; color: var(--secondary-text-color, #888); } .detail .close { background: transparent; border: none; font-size: 1.4rem; cursor: pointer; color: var(--secondary-text-color, #888); } .detail-body { font-size: 0.95rem; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; background: var(--card-background-color, #fff); padding: 12px; border-radius: 4px; border: 1px solid var(--divider-color, #eee); margin: 0; } .detail footer { display: flex; align-items: center; gap: 12px; margin-top: 14px; } .fire, .primary, .secondary, .danger { border: none; padding: 8px 16px; font-size: 0.92rem; border-radius: 4px; cursor: pointer; font-family: inherit; } .fire, .primary { background: var(--primary-color, #03a9f4); color: var(--text-primary-color, #fff); } .secondary { background: var(--secondary-background-color, #eee); color: var(--primary-text-color, #000); } .danger { background: transparent; color: var(--error-color, #db4437); border: 1px solid var(--error-color, #db4437); } .fire:hover, .primary:hover, .secondary:hover, .danger:hover { filter: brightness(0.9); } .action-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding: 10px; background: var(--secondary-background-color, #f5f5f5); border-radius: 4px; font-size: 0.88rem; } .action-row.danger-row { background: var(--error-color, #db4437); color: white; } .action-row input[type="number"] { width: 70px; padding: 4px 6px; font-size: 0.9rem; border: 1px solid var(--divider-color, #ccc); border-radius: 3px; margin-left: 6px; } .action-row button { padding: 4px 12px; font-size: 0.85rem; } .fire-feedback { font-size: 0.85rem; color: var(--secondary-text-color, #666); } .chain-info { margin-top: 12px; font-size: 0.8rem; color: var(--secondary-text-color, #888); } .loading, .empty { padding: 40px 20px; text-align: center; color: var(--secondary-text-color, #888); } /* editor */ .editor-body { display: flex; flex-direction: column; gap: 12px; } .editor fieldset { border: 1px solid var(--divider-color, #ddd); border-radius: 4px; padding: 10px 12px; margin: 0; } .editor legend { padding: 0 6px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--secondary-text-color, #777); } .editor .row { display: flex; align-items: center; gap: 8px; } .editor label.block { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--secondary-text-color, #555); margin-bottom: 8px; } .editor label.block:last-child { margin-bottom: 0; } .editor input[type="number"], .editor select { padding: 6px 8px; font-size: 0.95rem; border: 1px solid var(--divider-color, #ccc); border-radius: 3px; background: var(--card-background-color, #fff); color: inherit; } .editor .time-colon { font-weight: 600; font-size: 1.4rem; margin: 0 2px; } .days-row { display: flex; flex-wrap: wrap; gap: 4px; } .day-toggle { padding: 6px 10px; border: 1px solid var(--divider-color, #ccc); background: var(--card-background-color, #fff); color: var(--secondary-text-color, #555); border-radius: 3px; cursor: pointer; font-family: inherit; font-size: 0.82rem; } .day-toggle.active { background: var(--primary-color, #03a9f4); color: var(--text-primary-color, #fff); border-color: transparent; } .conditions-readonly { padding: 10px 12px; background: var(--secondary-background-color, #f5f5f5); border-radius: 4px; font-size: 0.82rem; color: var(--secondary-text-color, #666); } .cond-slot { padding: 8px 10px; margin-top: 6px; background: var(--secondary-background-color, #f5f5f5); border-radius: 4px; } .cond-slot:first-of-type { margin-top: 0; } .cond-family-label { font-weight: 600; color: var(--primary-text-color, #000); } `,u([O({attribute:!1})],p.prototype,"hass",2),u([O({attribute:!1})],p.prototype,"narrow",2),u([m()],p.prototype,"_entryId",2),u([m()],p.prototype,"_rows",2),u([m()],p.prototype,"_total",2),u([m()],p.prototype,"_filteredTotal",2),u([m()],p.prototype,"_loading",2),u([m()],p.prototype,"_error",2),u([m()],p.prototype,"_activeTriggerTypes",2),u([m()],p.prototype,"_referenceFilter",2),u([m()],p.prototype,"_searchTerm",2),u([m()],p.prototype,"_selectedSlot",2),u([m()],p.prototype,"_detail",2),u([m()],p.prototype,"_detailLoading",2),u([m()],p.prototype,"_fireFeedback",2),u([m()],p.prototype,"_writeFeedback",2),u([m()],p.prototype,"_cloneTargetSlot",2),u([m()],p.prototype,"_showCloneInput",2),u([m()],p.prototype,"_confirmingClear",2),u([m()],p.prototype,"_editingDraft",2),u([m()],p.prototype,"_objects",2),p=u([Fe("omni-panel-programs")],p);export{p as OmniPanelPrograms}; /*! Bundled license information: @lit/reactive-element/css-tag.js: (** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) @lit/reactive-element/reactive-element.js: (** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) lit-html/lit-html.js: (** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) lit-element/lit-element.js: (** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) lit-html/is-server.js: (** * @license * Copyright 2022 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) @lit/reactive-element/decorators/custom-element.js: (** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) @lit/reactive-element/decorators/property.js: (** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) @lit/reactive-element/decorators/state.js: (** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) @lit/reactive-element/decorators/event-options.js: (** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) @lit/reactive-element/decorators/base.js: (** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) @lit/reactive-element/decorators/query.js: (** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) @lit/reactive-element/decorators/query-all.js: (** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) @lit/reactive-element/decorators/query-async.js: (** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) @lit/reactive-element/decorators/query-assigned-elements.js: (** * @license * Copyright 2021 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) @lit/reactive-element/decorators/query-assigned-nodes.js: (** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause *) */