Ryan Malloy 5870e2f7ee
Some checks are pending
Validate / HACS validation (push) Waiting to run
Validate / Hassfest (push) Waiting to run
panel: inline AND-IF condition editor for compact-form programs
Replaces the read-only "conditions present but not editable" banner
with a real editor for the cond / cond2 u16 fields on TIMED / EVENT /
YEARLY programs.

Compact-form conditions split into five families per
clsText.GetConditionalText (clsText.cs:2224-2274):

  none     — cond = 0 (no inline condition)
  misc     — family 0x00, low nibble = enuMiscConditional
             (NONE / NEVER / LIGHT / DARK / PHONE_* / AC_POWER_* /
             BATTERY_* / ENERGY_COST_*)
  zone     — family 0x04, low byte = zone, bit 0x0200 = NOT_READY
  unit     — family 0x08, low 9 bits = unit, bit 0x0200 = ON
  time     — family 0x0C, low byte = time-clock #, bit 0x0200 = enabled
  sec      — family >= 0x10, bits 8-11 = area, bits 12-14 = security mode

types.ts gains decodeCondition / encodeCondition + the
MISC_CONDITIONALS / SECURITY_MODE_NAMES enums. Round-trip is exact:
decode(encode(c)) === c for every supported family.

UI: two condition slots per editor (matching the two u16 fields on
the wire). Each slot has a family-picker dropdown that swaps the
sub-fields (zone picker + secure/not-ready, unit picker + on/off,
area picker + security mode, time-clock # + enabled/disabled, misc
condition picker, or "none"). Picking a family seeds sensible defaults
(NEVER for misc, first zone secure, first unit ON, area 1 disarmed,
time clock 1 enabled).

Object pickers reuse the same _bucketWithPreserve helper introduced
for the action editor, so out-of-range zone/unit/area refs in inline
conditions keep their original value with a "preserve" label.

Live smoke test against the real panel: slot #1's actual condition
"AND IF Time clock 4 is disabled" now decodes into the editor as
Family=Time clock / # = 4 / Is = disabled — exactly the on-disk state.

Frontend bundle: 63 KB minified (up from 56 KB with the new editor
section + cond helpers).
2026-05-17 01:43:32 -06:00

960 lines
61 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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?"<svg>":t===3?"<math>":"",o=I;for(let c=0;c<e;c++){let l=n[c],h,f,d=-1,v=0;for(;v<l.length&&(o.lastIndex=v,f=o.exec(l),f!==null);)v=o.lastIndex,o===I?f[1]==="!--"?o=ye:f[1]!==void 0?o=$e:f[2]!==void 0?(Te.test(f[2])&&(i=RegExp("</"+f[2],"g")),o=E):f[3]!==void 0&&(o=E):o===E?f[0]===">"?(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?"</svg>":t===3?"</math>":"")),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.length<c;){if(i.nodeType===1){if(i.hasAttributes())for(let d of i.getAttributeNames())if(d.endsWith(Se)){let v=f[o++],y=i.getAttribute(d).split($),H=/([.?@])?(.*)/.exec(v);l.push({type:1,index:s,name:H[2],strings:y,ctor:H[1]==="."?X:H[1]==="?"?Q:H[1]==="@"?ee:A}),i.removeAttribute(d)}else d.startsWith($)&&(l.push({type:6,index:s}),i.removeAttribute(d));if(Te.test(i.tagName)){let d=i.textContent.split($),v=d.length-1;if(v>0){i.textContent=q?q.emptyScript:"";for(let y=0;y<v;y++)i.append(d[y],P()),k.nextNode(),l.push({type:2,index:++s});i.append(d[v],P())}}}else if(i.nodeType===8)if(i.data===we)l.push({type:2,index:s});else{let d=-1;for(;(d=i.data.indexOf($,d+1))!==-1;)l.push({type:7,index:s}),d+=$.length-1}s++}}static createElement(t,e){let r=S.createElement("template");return r.innerHTML=t,r}};function T(n,t,e=n,r){if(t===w)return t;let i=r!==void 0?e._$Co?.[r]:e._$Cl,s=z(t)?void 0:t._$litDirective$;return i?.constructor!==s&&(i?._$AO?.(!1),s===void 0?i=void 0:(i=new s(n),i._$AT(n,e,r)),r!==void 0?(e._$Co??=[])[r]=i:e._$Cl=i),i!==void 0&&(t=T(n,i._$AS(n,t.values),i,r)),t}var J=class{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){let{el:{content:e},parts:r}=this._$AD,i=(t?.creationScope??S).importNode(e,!0);k.currentNode=i;let s=k.nextNode(),o=0,c=0,l=r[0];for(;l!==void 0;){if(o===l.index){let h;l.type===2?h=new L(s,s.nextSibling,this,t):l.type===1?h=new l.ctor(s,l.name,l.strings,this,t):l.type===6&&(h=new te(s,this,t)),this._$AV.push(h),l=r[++c]}o!==l?.index&&(s=k.nextNode(),o++)}return k.currentNode=S,i}p(t){let e=0;for(let r of this._$AV)r!==void 0&&(r.strings!==void 0?(r._$AI(t,r,e),e+=r.strings.length-2):r._$AI(t[e])),e++}},L=class n{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,e,r,i){this.type=2,this._$AH=g,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=r,this.options=i,this._$Cv=i?.isConnected??!0}get parentNode(){let t=this._$AA.parentNode,e=this._$AM;return e!==void 0&&t?.nodeType===11&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=T(this,t,e),z(t)?t===g||t==null||t===""?(this._$AH!==g&&this._$AR(),this._$AH=g):t!==this._$AH&&t!==w&&this._(t):t._$litType$!==void 0?this.$(t):t.nodeType!==void 0?this.T(t):Ke(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==g&&z(this._$AH)?this._$AA.nextSibling.data=t:this.T(S.createTextNode(t)),this._$AH=t}$(t){let{values:e,_$litType$:r}=t,i=typeof r=="number"?this._$AC(t):(r.el===void 0&&(r.el=N.createElement(Ae(r.h,r.h[0]),this.options)),r);if(this._$AH?._$AD===i)this._$AH.p(e);else{let s=new J(i,this),o=s.u(this.options);s.p(e),this.T(o),this._$AH=s}}_$AC(t){let e=ke.get(t.strings);return e===void 0&&ke.set(t.strings,e=new N(t)),e}k(t){ie(this._$AH)||(this._$AH=[],this._$AR());let e=this._$AH,r,i=0;for(let s of t)i===e.length?e.push(r=new n(this.O(P()),this.O(P()),this,this.options)):r=e[i],r._$AI(s),i++;i<e.length&&(this._$AR(r&&r._$AB.nextSibling,i),e.length=i)}_$AR(t=this._$AA.nextSibling,e){for(this._$AP?.(!1,!0,e);t!==this._$AB;){let r=ve(t).nextSibling;ve(t).remove(),t=r}}setConnected(t){this._$AM===void 0&&(this._$Cv=t,this._$AP?.(t))}},A=class{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,r,i,s){this.type=1,this._$AH=g,this._$AN=void 0,this.element=t,this.name=e,this._$AM=i,this.options=s,r.length>2||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<s.length-1;l++)h=T(this,c[r+l],e,l),h===w&&(h=this._$AH[l]),o||=!z(h)||h!==this._$AH[l],h===g?t=g:t!==g&&(t+=(h??"")+s[l+1]),this._$AH[l]=h}o&&!i&&this.j(t)}j(t){t===g?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}},X=class extends A{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===g?void 0:t}},Q=class extends A{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==g)}},ee=class extends A{constructor(t,e,r,i,s){super(t,e,r,i,s),this.type=5}_$AI(t,e=this){if((t=T(this,t,e,0)??g)===w)return;let r=this._$AH,i=t===g&&r!==g||t.capture!==r.capture||t.once!==r.once||t.passive!==r.passive,s=t!==g&&(r===g||i);i&&this.element.removeEventListener(this.name,this,r),s&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){typeof this._$AH=="function"?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t)}},te=class{constructor(t,e,r){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=r}get _$AU(){return this._$AM._$AU}_$AI(t){T(this,t)}};var Xe=re.litHtmlPolyfillSupport;Xe?.(N,L),(re.litHtmlVersions??=[]).push("3.3.3");var Ce=(n,t,e)=>{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`<br />`;case"indent":return a`<span class="indent">${n.t}</span>`;case"keyword":return a`<span class="keyword">${n.t}</span>`;case"operator":return a`<span class="operator">${n.t}</span>`;case"value":return a`<span class="value">${n.t}</span>`;case"ref":{let e=t&&n.ek&&typeof n.ei=="number"?()=>t(n.ek,n.ei):void 0;return a`<button
type="button"
class="ref ref-${n.ek}"
title=${n.ek??""}
@click=${e}
>
<span class="ref-name">${n.t}</span>
${n.s?a`<span class="ref-state">${n.s}</span>`:""}
</button>`}default:return a`<span>${n.t}</span>`}}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`
<div class="header">
<div class="title">
<ha-icon icon="mdi:script-text-outline"></ha-icon>
<span>Omni Programs</span>
${this._total>0?a`
<span class="count">
${this._filteredTotal===this._total?`${this._total} programs`:`${this._filteredTotal} of ${this._total} shown`}
</span>`:""}
</div>
</div>
${this._error?a`
<div class="error">${this._error}</div>`:""}
${this._renderFilters()}
<div class="body" data-narrow=${this.narrow}>
${this._renderList()}
${this._selectedSlot!==null?this._renderDetail():""}
</div>
`}_renderFilters(){return a`
<div class="filters">
<input
type="search"
class="search"
placeholder="search programs..."
.value=${this._searchTerm}
@input=${this._onSearchInput}
/>
<div class="chips">
${it.map(e=>a`
<button
type="button"
class="chip ${this._activeTriggerTypes.has(e)?"active":""}"
@click=${()=>this._toggleTriggerFilter(e)}
>${e}</button>
`)}
</div>
${this._referenceFilter?a`
<div class="ref-filter">
<span>filtering on <strong>${this._referenceFilter}</strong></span>
<button type="button" @click=${this._clearReferenceFilter}>clear</button>
</div>`:""}
</div>
`}_renderList(){return this._loading&&this._rows.length===0?a`<div class="loading">loading…</div>`:this._rows.length===0?a`<div class="empty">No programs match the current filters.</div>`:a`
<div class="list">
${this._rows.map(e=>a`
<div
class="row ${this._selectedSlot===e.slot?"selected":""}"
@click=${()=>this._onRowClick(e.slot)}
>
<div class="row-slot">#${e.slot}</div>
<div class="row-summary">
${oe(e.summary,(r,i)=>this._onRefClick(r,i))}
</div>
<div class="row-meta">
<span class="trigger-badge trigger-${e.trigger_type.toLowerCase()}">
${e.trigger_type}
</span>
${e.condition_count>0?a`
<span class="meta-pill">${e.condition_count} cond</span>`:""}
${e.action_count>1?a`
<span class="meta-pill">${e.action_count} actions</span>`:""}
</div>
</div>
`)}
</div>
`}_renderDetail(){if(this._detailLoading)return a`<aside class="detail"><div class="loading">loading…</div></aside>`;if(this._detail===null)return a`<aside class="detail"></aside>`;let e=this._detail;return this._editingDraft!==null?this._renderEditor(e):a`
<aside class="detail">
<header>
<div>
<span class="trigger-badge trigger-${e.trigger_type.toLowerCase()}">
${e.trigger_type}
</span>
<span class="slot">slot #${e.slot}</span>
</div>
<button type="button" class="close" @click=${this._closeDetail}>×</button>
</header>
<pre class="detail-body">${oe(e.tokens,(r,i)=>this._onRefClick(r,i))}</pre>
<footer>
<button
type="button"
class="fire"
@click=${()=>this._fireProgram(e.slot)}
>▶ Fire now</button>
${e.kind==="compact"&&Le.has(e.trigger_type)?a`
<button
type="button"
class="secondary"
@click=${this._beginEdit}
>Edit</button>`:""}
<button
type="button"
class="secondary"
@click=${()=>{this._showCloneInput=!this._showCloneInput,this._confirmingClear=!1}}
>Clone…</button>
<button
type="button"
class="danger"
@click=${()=>{this._confirmingClear=!this._confirmingClear,this._showCloneInput=!1}}
>Clear</button>
${this._fireFeedback?a`
<span class="fire-feedback">${this._fireFeedback}</span>`:""}
${this._writeFeedback?a`
<span class="fire-feedback">${this._writeFeedback}</span>`:""}
</footer>
${this._showCloneInput?a`
<div class="action-row">
<label>Clone slot ${e.slot} → target slot:
<input
type="number"
min="1"
max="1500"
.value=${this._cloneTargetSlot}
@input=${this._onCloneTargetInput}
@keydown=${r=>{r.key==="Enter"&&this._cloneProgram(e.slot)}}
/>
</label>
<button
type="button"
class="primary"
@click=${()=>this._cloneProgram(e.slot)}
>Clone</button>
<button
type="button"
@click=${()=>{this._showCloneInput=!1}}
>Cancel</button>
</div>`:""}
${this._confirmingClear?a`
<div class="action-row danger-row">
<span>
<strong>Clear slot ${e.slot}?</strong>
This deletes the program from the panel.
</span>
<button
type="button"
class="danger"
@click=${()=>this._clearProgram(e.slot)}
>Yes, clear</button>
<button
type="button"
@click=${()=>{this._confirmingClear=!1}}
>Cancel</button>
</div>`:""}
${e.chain_slots&&e.chain_slots.length>1?a`
<div class="chain-info">
spans slots
${e.chain_slots.map((r,i)=>a`
${i>0?"\u2192":""}#${r}`)}
</div>`:""}
</aside>
`}_renderEditor(e){let r=this._editingDraft,i=e.trigger_type;return a`
<aside class="detail editor">
<header>
<div>
<span class="trigger-badge trigger-${i.toLowerCase()}">
EDIT • ${i}
</span>
<span class="slot">slot #${e.slot}</span>
</div>
<button type="button" class="close" @click=${this._cancelEdit}>×</button>
</header>
<div class="editor-body">
${this._renderTriggerSection(r)}
${this._renderActionSection(r)}
${this._renderConditionsSection(r)}
</div>
<footer>
<button type="button" class="primary" @click=${this._saveDraft}>
Save
</button>
<button type="button" class="secondary" @click=${this._cancelEdit}>
Cancel
</button>
${this._writeFeedback?a`
<span class="fire-feedback">${this._writeFeedback}</span>`:""}
</footer>
</aside>
`}_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`<div class="conditions-readonly">
Editing program type ${e.prog_type} is not supported.
</div>`}}_renderTimedTrigger(e){return a`
<fieldset>
<legend>Time</legend>
<div class="row">
<label>
Hour
<input
type="number" min="0" max="23"
.value=${String(e.hour??0)}
@input=${this._onHourChange}
/>
</label>
<span class="time-colon">:</span>
<label>
Minute
<input
type="number" min="0" max="59" step="1"
.value=${String(e.minute??0)}
@input=${this._onMinuteChange}
/>
</label>
</div>
</fieldset>
<fieldset>
<legend>Days</legend>
<div class="days-row">
${Re.map(r=>{let i=((e.days??0)&r.bit)!==0;return a`
<button
type="button"
class="day-toggle ${i?"active":""}"
@click=${()=>this._toggleDayBit(r.bit)}
>${r.label}</button>
`})}
</div>
</fieldset>
`}_renderEventTrigger(e){let r=F(e),i=C(r);return a`
<fieldset>
<legend>Trigger event</legend>
<label class="block">
Category
<select @change=${this._onEventCategoryChange}>
<option value="button"
?selected=${i.category==="button"}>
Button press
</option>
<option value="zone"
?selected=${i.category==="zone"}>
Zone state change
</option>
<option value="unit"
?selected=${i.category==="unit"}>
Unit state change
</option>
<option value="fixed"
?selected=${i.category==="fixed"}>
Fixed event (phone / AC)
</option>
${i.category==="raw"?a`
<option value="raw" selected>
Raw 0x${r.toString(16).padStart(4,"0")}
</option>`:""}
</select>
</label>
${this._renderEventCategoryFields(i)}
</fieldset>
`}_renderEventCategoryFields(e){if(e.category==="button"){let r=this._bucketWithPreserve(this._objects?.buttons??null,"button",e.button??0);return a`
<label class="block">
Button
<select @change=${this._onEventButtonChange}>
${r.map(i=>a`
<option .value=${String(i.index)}
?selected=${i.index===e.button}>
#${i.index} ${i.name}
</option>
`)}
</select>
</label>`}if(e.category==="zone"){let r=this._bucketWithPreserve(this._objects?.zones??null,"zone",e.zone??0);return a`
<label class="block">
Zone
<select @change=${this._onEventZoneChange}>
${r.map(i=>a`
<option .value=${String(i.index)}
?selected=${i.index===e.zone}>
#${i.index} ${i.name}
</option>
`)}
</select>
</label>
<label class="block">
Becomes
<select @change=${this._onEventZoneStateChange}>
<option value="0" ?selected=${e.zoneState===0}>secure</option>
<option value="1" ?selected=${e.zoneState===1}>not ready</option>
<option value="2" ?selected=${e.zoneState===2}>trouble</option>
<option value="3" ?selected=${e.zoneState===3}>tamper</option>
</select>
</label>`}if(e.category==="unit"){let r=this._bucketWithPreserve(this._objects?.units??null,"unit",e.unit??0);return a`
<label class="block">
Unit
<select @change=${this._onEventUnitChange}>
${r.map(i=>a`
<option .value=${String(i.index)}
?selected=${i.index===e.unit}>
#${i.index} ${i.name}
</option>
`)}
</select>
</label>
<label class="block">
Turns
<select @change=${this._onEventUnitOnChange}>
<option value="1" ?selected=${e.unitOn===!0}>ON</option>
<option value="0" ?selected=${e.unitOn===!1}>OFF</option>
</select>
</label>`}return e.category==="fixed"?a`
<label class="block">
Event
<select @change=${this._onEventFixedChange}>
${ue.map(r=>a`
<option .value=${String(r.id)}
?selected=${r.id===e.fixedId}>
${r.label}
</option>
`)}
</select>
</label>`:a`
<div class="conditions-readonly">
Unrecognised event ID. Switch category above to redefine.
</div>`}_renderYearlyTrigger(e){return a`
<fieldset>
<legend>Date</legend>
<div class="row">
<label>
Month
<select @change=${this._onMonthChange}>
${Ie.map((r,i)=>a`
<option .value=${String(i+1)}
?selected=${(e.month??1)===i+1}>
${r} (${i+1})
</option>
`)}
</select>
</label>
<label>
Day
<input
type="number" min="1" max="31"
.value=${String(e.day??1)}
@input=${this._onDayChange}
/>
</label>
</div>
</fieldset>
<fieldset>
<legend>Time of day</legend>
<div class="row">
<label>
Hour
<input
type="number" min="0" max="23"
.value=${String(e.hour??0)}
@input=${this._onHourChange}
/>
</label>
<span class="time-colon">:</span>
<label>
Minute
<input
type="number" min="0" max="59"
.value=${String(e.minute??0)}
@input=${this._onMinuteChange}
/>
</label>
</div>
</fieldset>
`}_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`
<fieldset>
<legend>Action</legend>
<label class="block">
Command
<select @change=${this._onCommandChange}>
${ae.map(o=>a`
<option .value=${String(o.value)}
?selected=${o.value===e.cmd}>
${o.label}
</option>
`)}
</select>
</label>
${r?.ref_kind?a`
<label class="block">
${r.ref_kind[0].toUpperCase()+r.ref_kind.slice(1)}
<select @change=${this._onObjectChange}>
${(i??[]).map(o=>a`
<option .value=${String(o.index)}
?selected=${o.index===e.pr2}>
#${o.index} ${o.name}
</option>
`)}
</select>
</label>`:""}
${s?a`
<label class="block">
Level (0..100)
<input
type="number" min="0" max="100"
.value=${String(e.par??0)}
@input=${this._onParChange}
/>
</label>`:""}
</fieldset>
`}_renderConditionsSection(e){return a`
<fieldset>
<legend>Inline AND-IF conditions</legend>
${this._renderConditionSlot("First condition",e.cond??0,r=>this._patchDraft({cond:r}))}
${this._renderConditionSlot("Second condition",e.cond2??0,r=>this._patchDraft({cond2:r}))}
</fieldset>
`}_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`
<div class="cond-slot">
<label class="block cond-family-label">
${e}
<select @change=${c=>o(c.target.value)}>
<option value="none" ?selected=${s.family==="none"}>(none)</option>
<option value="zone" ?selected=${s.family==="zone"}>Zone state</option>
<option value="unit" ?selected=${s.family==="unit"}>Unit state</option>
<option value="sec" ?selected=${s.family==="sec"}>Area in security mode</option>
<option value="time" ?selected=${s.family==="time"}>Time clock</option>
<option value="misc" ?selected=${s.family==="misc"}>Misc (light, AC power, …)</option>
</select>
</label>
${this._renderConditionSubfields(s,i)}
</div>
`}_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`
<label class="block">
Zone
<select @change=${s=>{let o=parseInt(s.target.value,10);r(_({...e,index:o}))}}>
${i.map(s=>a`
<option .value=${String(s.index)}
?selected=${s.index===e.index}>
#${s.index} ${s.name}
</option>
`)}
</select>
</label>
<label class="block">
Is
<select @change=${s=>{let o=s.target.value==="1";r(_({...e,active:o}))}}>
<option value="0" ?selected=${!e.active}>secure</option>
<option value="1" ?selected=${e.active}>not ready</option>
</select>
</label>`}if(e.family==="unit"){let i=this._bucketWithPreserve(this._objects?.units??null,"unit",e.index??0);return a`
<label class="block">
Unit
<select @change=${s=>{let o=parseInt(s.target.value,10);r(_({...e,index:o}))}}>
${i.map(s=>a`
<option .value=${String(s.index)}
?selected=${s.index===e.index}>
#${s.index} ${s.name}
</option>
`)}
</select>
</label>
<label class="block">
Is
<select @change=${s=>{let o=s.target.value==="1";r(_({...e,active:o}))}}>
<option value="1" ?selected=${e.active}>ON</option>
<option value="0" ?selected=${!e.active}>OFF</option>
</select>
</label>`}if(e.family==="sec"){let i=this._bucketWithPreserve(this._objects?.areas??null,"area",e.index??0);return a`
<label class="block">
Area
<select @change=${s=>{let o=parseInt(s.target.value,10);r(_({...e,index:o}))}}>
${i.map(s=>a`
<option .value=${String(s.index)}
?selected=${s.index===e.index}>
#${s.index} ${s.name}
</option>
`)}
</select>
</label>
<label class="block">
Mode
<select @change=${s=>{let o=parseInt(s.target.value,10);r(_({...e,mode:o}))}}>
${ze.map(s=>a`
<option .value=${String(s.value)}
?selected=${s.value===e.mode}>
${s.label}
</option>
`)}
</select>
</label>`}return e.family==="time"?a`
<label class="block">
Time clock # (1..3)
<input
type="number" min="1" max="3"
.value=${String(e.index??1)}
@input=${i=>{let s=parseInt(i.target.value,10);Number.isFinite(s)&&r(_({...e,index:s}))}}
/>
</label>
<label class="block">
Is
<select @change=${i=>{let s=i.target.value==="1";r(_({...e,active:s}))}}>
<option value="1" ?selected=${e.active}>enabled</option>
<option value="0" ?selected=${!e.active}>disabled</option>
</select>
</label>`:a`
<label class="block">
Condition
<select @change=${i=>{let s=parseInt(i.target.value,10);r(_({family:"misc",misc:s}))}}>
${Pe.map(i=>a`
<option .value=${String(i.value)}
?selected=${i.value===e.misc}>
${i.label}
</option>
`)}
</select>
</label>`}};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
*)
*/