diff --git a/custom_components/omni_pca/frontend/src/omni-panel-programs.ts b/custom_components/omni_pca/frontend/src/omni-panel-programs.ts
index e089efd..6d0a8f3 100644
--- a/custom_components/omni_pca/frontend/src/omni-panel-programs.ts
+++ b/custom_components/omni_pca/frontend/src/omni-panel-programs.ts
@@ -1849,9 +1849,9 @@ export class OmniPanelPrograms extends LitElement {
): TemplateResult {
const s = decodeStructuredAnd(cond);
if (!isEditableStructuredAnd(s)) {
- // Out of editor scope (non-constant Arg2, unsupported Arg1 type,
- // or non-zero compConst). Surface as preserve-only so the user
- // can still remove the row but can't damage the encoded data.
+ // Out of editor scope (unsupported Arg1/Arg2 type or non-zero
+ // CompConst). Surface as preserve-only so the user can still
+ // remove the row but can't damage the encoded data.
return html`
Structured comparison with a shape the editor can't drive
- yet (Arg2 references another object, Arg1 is an unsupported
- type, or a CompConst value is present). Preserved on save.
+ yet (Arg1 or Arg2 is an unsupported type, or a CompConst
+ value is present). Preserved on save.
`;
}
@@ -1881,24 +1881,24 @@ export class OmniPanelPrograms extends LitElement {
/** Render the editor for one structured-AND condition. Lays out as:
*
- * Arg1 type ▸ object/picker ▸ field ▸ operator ▸ Arg2 constant
+ * Arg1 type ▸ object/picker ▸ field ▸ operator ▸
+ * Arg2 type ▸ (constant | object/picker ▸ field)
*
- * Arg2 is locked to Constant in this pass. For unary operators
- * (ODD / EVEN) the Arg2 input is hidden.
+ * Both Arg1 and Arg2 support Zone / Unit / Thermostat / Area /
+ * TimeDate references; Arg2 also supports plain Constant. For
+ * unary operators (ODD / EVEN) the Arg2 controls are hidden.
*/
private _renderStructuredAndForm(
s: DecodedStructuredAnd, idx: number,
): TemplateResult {
const update = (patch: Partial) => {
const merged = { ...s, ...patch };
- // Force Arg2 = Constant in editor scope so nothing accidentally
- // promotes to an object reference.
- merged.arg2Type = 0;
- merged.arg2Field = 0;
this._patchChainCondition(idx, encodeStructuredAnd(merged));
};
const arg1Fields = FIELDS_BY_TYPE[s.arg1Type] ?? [];
const arg1Kind = argTypeKind(s.arg1Type);
+ const arg2Fields = FIELDS_BY_TYPE[s.arg2Type] ?? [];
+ const arg2Kind = argTypeKind(s.arg2Type);
const showArg2 = !isUnaryOp(s.op);
return html`
@@ -1906,19 +1906,10 @@ export class OmniPanelPrograms extends LitElement {
Arg1 type
{
const newType = parseInt((e.target as HTMLSelectElement).value, 10);
- // Reset arg1Ix + field when type changes — keeps the form
- // self-consistent and avoids stale picker values.
- const firstField = (FIELDS_BY_TYPE[newType] ?? [{ value: 0 }])[0].value;
- const newKind = argTypeKind(newType);
- let newIx = 0;
- if (newKind === "zone") newIx = this._objects?.zones?.[0]?.index ?? 1;
- else if (newKind === "unit") newIx = this._objects?.units?.[0]?.index ?? 1;
- else if (newKind === "thermostat") newIx = this._objects?.thermostats?.[0]?.index ?? 1;
- else if (newKind === "area") newIx = this._objects?.areas?.[0]?.index ?? 1;
update({
arg1Type: newType,
- arg1Ix: newIx,
- arg1Field: firstField,
+ arg1Ix: this._defaultIxForKind(argTypeKind(newType)),
+ arg1Field: (FIELDS_BY_TYPE[newType] ?? [{ value: 0 }])[0].value,
});
}}>
${ARG_TYPES.filter((a) => a.value !== 0).map((a) => html`
@@ -1928,7 +1919,9 @@ export class OmniPanelPrograms extends LitElement {
- ${arg1Kind ? this._renderStructuredArg1Picker(s, arg1Kind, update) : ""}
+ ${arg1Kind ? this._renderStructuredObjectPicker(
+ arg1Kind, s.arg1Ix, (v) => update({ arg1Ix: v }), "Arg1",
+ ) : ""}
${arg1Fields.length > 0 ? html`
@@ -1957,37 +1950,95 @@ export class OmniPanelPrograms extends LitElement {
${showArg2 ? html`
- Compare against (constant)
- {
- const v = parseInt((e.target as HTMLInputElement).value, 10);
- if (Number.isFinite(v) && v >= 0 && v <= 0xFFFF) {
- update({ arg2Ix: v });
- }
- }}
- />
- ` : ""}
+ Arg2 type
+ {
+ const newType = parseInt((e.target as HTMLSelectElement).value, 10);
+ const newKind = argTypeKind(newType);
+ // Constant → arg2Ix is the literal value (preserve);
+ // reference type → arg2Ix is an object index (reset to
+ // first discovered or 0 for TimeDate).
+ const newIx = newType === 0
+ ? s.arg2Ix
+ : this._defaultIxForKind(newKind);
+ const newField = newType === 0
+ ? 0
+ : (FIELDS_BY_TYPE[newType] ?? [{ value: 0 }])[0].value;
+ update({
+ arg2Type: newType,
+ arg2Ix: newIx,
+ arg2Field: newField,
+ });
+ }}>
+ ${ARG_TYPES.map((a) => html`
+
+ ${a.label}
+ `)}
+
+
+
+ ${s.arg2Type === 0 ? html`
+
+ Constant
+ {
+ const v = parseInt((e.target as HTMLInputElement).value, 10);
+ if (Number.isFinite(v) && v >= 0 && v <= 0xFFFF) {
+ update({ arg2Ix: v });
+ }
+ }}
+ />
+ ` : ""}
+
+ ${arg2Kind ? this._renderStructuredObjectPicker(
+ arg2Kind, s.arg2Ix, (v) => update({ arg2Ix: v }), "Arg2",
+ ) : ""}
+
+ ${s.arg2Type !== 0 && arg2Fields.length > 0 ? html`
+
+ Arg2 field
+ update({
+ arg2Field: parseInt((e.target as HTMLSelectElement).value, 10),
+ })}>
+ ${arg2Fields.map((f) => html`
+
+ ${f.label}
+ `)}
+
+ ` : ""}
+ ` : ""}
`;
}
- private _renderStructuredArg1Picker(
- s: DecodedStructuredAnd,
+ /** First discovered object index for a given kind, falling back to 1
+ * for reference kinds (TimeDate / null returns 0 — "no object"). */
+ private _defaultIxForKind(kind: string | null): number {
+ switch (kind) {
+ case "zone": return this._objects?.zones?.[0]?.index ?? 1;
+ case "unit": return this._objects?.units?.[0]?.index ?? 1;
+ case "thermostat": return this._objects?.thermostats?.[0]?.index ?? 1;
+ case "area": return this._objects?.areas?.[0]?.index ?? 1;
+ default: return 0;
+ }
+ }
+
+ private _renderStructuredObjectPicker(
kind: string,
- update: (p: Partial) => void,
+ current: number,
+ onChange: (v: number) => void,
+ labelPrefix: string,
): TemplateResult {
const bucket = this._bucketWithPreserve(
- this._pickBucket(kind), kind, s.arg1Ix,
+ this._pickBucket(kind), kind, current,
);
- const label = kind[0].toUpperCase() + kind.slice(1);
+ const kindLabel = kind[0].toUpperCase() + kind.slice(1);
return html`
- ${label}
- update({
- arg1Ix: parseInt((e.target as HTMLSelectElement).value, 10),
- })}>
+ ${labelPrefix} ${kindLabel}
+
+ onChange(parseInt((e.target as HTMLSelectElement).value, 10))}>
${bucket.map((o) => html`
-
+
#${o.index} ${o.name}
`)}
diff --git a/custom_components/omni_pca/frontend/src/types.ts b/custom_components/omni_pca/frontend/src/types.ts
index b2ac97a..5ef524f 100644
--- a/custom_components/omni_pca/frontend/src/types.ts
+++ b/custom_components/omni_pca/frontend/src/types.ts
@@ -569,11 +569,11 @@ export function emptyThenRecord(firstUnit: number = 1): ProgramFields {
// day, days = and_compconst (BE u16 — extra constant, rarely used)
//
// Editor cuts:
-// * Arg2 locked to Constant in this pass (other-object Arg2 stays
-// read-only with a banner). Arg2-constant covers
-// "TEMP > 70", "Zone.CurrentState == 1", "Hour == 22" etc.
-// * Arg1 restricted to Zone / Unit / Thermostat / Area / TimeDate.
-// Anything else (Aux / Audio / System / etc.) stays read-only.
+// * Arg1 and Arg2 both restricted to Constant / Zone / Unit /
+// Thermostat / Area / TimeDate. Anything else (Aux / Audio /
+// System / etc.) stays read-only.
+// * Non-zero CompConst stays read-only (rarely used; preserved on
+// save).
// --------------------------------------------------------------------------
@@ -708,12 +708,15 @@ export function encodeStructuredAnd(s: DecodedStructuredAnd): Partial{for(var i=t>1?void 0:t?rt(n,e):n,r=a.length-1,s;r>=0;r--)(s=a[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&it(n,e,i),i};var U=globalThis,Y=U.ShadowRoot&&(U.ShadyCSS===void 0||U.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,K=Symbol(),ke=new WeakMap,R=class{constructor(n,e,t){if(this._$cssResult$=!0,t!==K)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=n,this.t=e}get styleSheet(){let n=this.o,e=this.t;if(Y&&n===void 0){let t=e!==void 0&&e.length===1;t&&(n=ke.get(e)),n===void 0&&((this.o=n=new CSSStyleSheet).replaceSync(this.cssText),t&&ke.set(e,n))}return n}toString(){return this.cssText}},Se=a=>new R(typeof a=="string"?a:a+"",void 0,K),J=(a,...n)=>{let e=a.length===1?a[0]:n.reduce((t,i,r)=>t+(s=>{if(s._$cssResult$===!0)return s.cssText;if(typeof s=="number")return s;throw Error("Value passed to 'css' function must be a 'css' function result: "+s+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+a[r+1],a[0]);return new R(e,a,K)},Ce=(a,n)=>{if(Y)a.adoptedStyleSheets=n.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(let e of n){let t=document.createElement("style"),i=U.litNonce;i!==void 0&&t.setAttribute("nonce",i),t.textContent=e.cssText,a.appendChild(t)}},X=Y?a=>a:a=>a instanceof CSSStyleSheet?(n=>{let e="";for(let t of n.cssRules)e+=t.cssText;return Se(e)})(a):a;var{is:at,defineProperty:ot,getOwnPropertyDescriptor:st,getOwnPropertyNames:lt,getOwnPropertySymbols:ct,getPrototypeOf:dt}=Object,B=globalThis,Te=B.trustedTypes,ut=Te?Te.emptyScript:"",pt=B.reactiveElementPolyfillSupport,D=(a,n)=>a,P={toAttribute(a,n){switch(n){case Boolean:a=a?ut:null;break;case Object:case Array:a=a==null?a:JSON.stringify(a)}return a},fromAttribute(a,n){let e=a;switch(n){case Boolean:e=a!==null;break;case Number:e=a===null?null:Number(a);break;case Object:case Array:try{e=JSON.parse(a)}catch{e=null}}return e}},W=(a,n)=>!at(a,n),Fe={attribute:!0,type:String,converter:P,reflect:!1,useDefault:!1,hasChanged:W};Symbol.metadata??=Symbol("metadata"),B.litPropertyMetadata??=new WeakMap;var y=class extends HTMLElement{static addInitializer(n){this._$Ei(),(this.l??=[]).push(n)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(n,e=Fe){if(e.state&&(e.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(n)&&((e=Object.create(e)).wrapped=!0),this.elementProperties.set(n,e),!e.noAccessor){let t=Symbol(),i=this.getPropertyDescriptor(n,t,e);i!==void 0&&ot(this.prototype,n,i)}}static getPropertyDescriptor(n,e,t){let{get:i,set:r}=st(this.prototype,n)??{get(){return this[e]},set(s){this[e]=s}};return{get:i,set(s){let c=i?.call(this);r?.call(this,s),this.requestUpdate(n,c,t)},configurable:!0,enumerable:!0}}static getPropertyOptions(n){return this.elementProperties.get(n)??Fe}static _$Ei(){if(this.hasOwnProperty(D("elementProperties")))return;let n=dt(this);n.finalize(),n.l!==void 0&&(this.l=[...n.l]),this.elementProperties=new Map(n.elementProperties)}static finalize(){if(this.hasOwnProperty(D("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(D("properties"))){let e=this.properties,t=[...lt(e),...ct(e)];for(let i of t)this.createProperty(i,e[i])}let n=this[Symbol.metadata];if(n!==null){let e=litPropertyMetadata.get(n);if(e!==void 0)for(let[t,i]of e)this.elementProperties.set(t,i)}this._$Eh=new Map;for(let[e,t]of this.elementProperties){let i=this._$Eu(e,t);i!==void 0&&this._$Eh.set(i,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(n){let e=[];if(Array.isArray(n)){let t=new Set(n.flat(1/0).reverse());for(let i of t)e.unshift(X(i))}else n!==void 0&&e.push(X(n));return e}static _$Eu(n,e){let t=e.attribute;return t===!1?void 0:typeof t=="string"?t:typeof n=="string"?n.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(n=>this.enableUpdating=n),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(n=>n(this))}addController(n){(this._$EO??=new Set).add(n),this.renderRoot!==void 0&&this.isConnected&&n.hostConnected?.()}removeController(n){this._$EO?.delete(n)}_$E_(){let n=new Map,e=this.constructor.elementProperties;for(let t of e.keys())this.hasOwnProperty(t)&&(n.set(t,this[t]),delete this[t]);n.size>0&&(this._$Ep=n)}createRenderRoot(){let n=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return Ce(n,this.constructor.elementStyles),n}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(n=>n.hostConnected?.())}enableUpdating(n){}disconnectedCallback(){this._$EO?.forEach(n=>n.hostDisconnected?.())}attributeChangedCallback(n,e,t){this._$AK(n,t)}_$ET(n,e){let t=this.constructor.elementProperties.get(n),i=this.constructor._$Eu(n,t);if(i!==void 0&&t.reflect===!0){let r=(t.converter?.toAttribute!==void 0?t.converter:P).toAttribute(e,t.type);this._$Em=n,r==null?this.removeAttribute(i):this.setAttribute(i,r),this._$Em=null}}_$AK(n,e){let t=this.constructor,i=t._$Eh.get(n);if(i!==void 0&&this._$Em!==i){let r=t.getPropertyOptions(i),s=typeof r.converter=="function"?{fromAttribute:r.converter}:r.converter?.fromAttribute!==void 0?r.converter:P;this._$Em=i;let c=s.fromAttribute(e,r.type);this[i]=c??this._$Ej?.get(i)??c,this._$Em=null}}requestUpdate(n,e,t,i=!1,r){if(n!==void 0){let s=this.constructor;if(i===!1&&(r=this[n]),t??=s.getPropertyOptions(n),!((t.hasChanged??W)(r,e)||t.useDefault&&t.reflect&&r===this._$Ej?.get(n)&&!this.hasAttribute(s._$Eu(n,t))))return;this.C(n,e,t)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(n,e,{useDefault:t,reflect:i,wrapped:r},s){t&&!(this._$Ej??=new Map).has(n)&&(this._$Ej.set(n,s??e??this[n]),r!==!0||s!==void 0)||(this._$AL.has(n)||(this.hasUpdated||t||(e=void 0),this._$AL.set(n,e)),i===!0&&this._$Em!==n&&(this._$Eq??=new Set).add(n))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(e){Promise.reject(e)}let n=this.scheduleUpdate();return n!=null&&await n,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(let[i,r]of this._$Ep)this[i]=r;this._$Ep=void 0}let t=this.constructor.elementProperties;if(t.size>0)for(let[i,r]of t){let{wrapped:s}=r,c=this[i];s!==!0||this._$AL.has(i)||c===void 0||this.C(i,void 0,r,c)}}let n=!1,e=this._$AL;try{n=this.shouldUpdate(e),n?(this.willUpdate(e),this._$EO?.forEach(t=>t.hostUpdate?.()),this.update(e)):this._$EM()}catch(t){throw n=!1,this._$EM(),t}n&&this._$AE(e)}willUpdate(n){}_$AE(n){this._$EO?.forEach(e=>e.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(n)),this.updated(n)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(n){return!0}update(n){this._$Eq&&=this._$Eq.forEach(e=>this._$ET(e,this[e])),this._$EM()}updated(n){}firstUpdated(n){}};y.elementStyles=[],y.shadowRootOptions={mode:"open"},y[D("elementProperties")]=new Map,y[D("finalized")]=new Map,pt?.({ReactiveElement:y}),(B.reactiveElementVersions??=[]).push("2.1.2");var ae=globalThis,Ae=a=>a,V=ae.trustedTypes,we=V?V.createPolicy("lit-html",{createHTML:a=>a}):void 0,ze="$lit$",$=`lit$${Math.random().toFixed(9).slice(2)}$`,Le="?"+$,ht=`<${Le}>`,S=document,M=()=>S.createComment(""),z=a=>a===null||typeof a!="object"&&typeof a!="function",oe=Array.isArray,mt=a=>oe(a)||typeof a?.[Symbol.iterator]=="function",Q=`[
-\f\r]`,I=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Re=/-->/g,De=/>/g,E=RegExp(`>|${Q}(?:([^\\s"'>=/]+)(${Q}*=${Q}*(?:[^
-\f\r"'\`<>=]|("|')|))|$)`,"g"),Pe=/'/g,Ie=/"/g,Oe=/^(?:script|style|textarea|title)$/i,se=a=>(n,...e)=>({_$litType$:a,strings:n,values:e}),o=se(1),Rt=se(2),Dt=se(3),C=Symbol.for("lit-noChange"),b=Symbol.for("lit-nothing"),Me=new WeakMap,k=S.createTreeWalker(S,129);function He(a,n){if(!oe(a)||!a.hasOwnProperty("raw"))throw Error("invalid template strings array");return we!==void 0?we.createHTML(n):n}var gt=(a,n)=>{let e=a.length-1,t=[],i,r=n===2?"":n===3?"":"",s=I;for(let c=0;c"?(s=i??I,u=-1):p[1]===void 0?u=-2:(u=s.lastIndex-p[2].length,d=p[1],s=p[3]===void 0?E:p[3]==='"'?Ie:Pe):s===Ie||s===Pe?s=E:s===Re||s===De?s=I:(s=E,i=void 0);let _=s===E&&a[c+1].startsWith("/>")?" ":"";r+=s===I?l+ht:u>=0?(t.push(d),l.slice(0,u)+ze+l.slice(u)+$+_):l+$+(u===-2?c:_)}return[He(a,r+(a[e]||">")+(n===2?" ":n===3?"":"")),t]},L=class a{constructor({strings:n,_$litType$:e},t){let i;this.parts=[];let r=0,s=0,c=n.length-1,l=this.parts,[d,p]=gt(n,e);if(this.el=a.createElement(d,t),k.currentNode=this.el.content,e===2||e===3){let u=this.el.content.firstChild;u.replaceWith(...u.childNodes)}for(;(i=k.nextNode())!==null&&l.length0){i.textContent=V?V.emptyScript:"";for(let _=0;_2||t[0]!==""||t[1]!==""?(this._$AH=Array(t.length-1).fill(new String),this.strings=t):this._$AH=b}_$AI(n,e=this,t,i){let r=this.strings,s=!1;if(r===void 0)n=F(this,n,e,0),s=!z(n)||n!==this._$AH&&n!==C,s&&(this._$AH=n);else{let c=n,l,d;for(n=r[0],l=0;l{let t=e?.renderBefore??n,i=t._$litPart$;if(i===void 0){let r=e?.renderBefore??null;t._$litPart$=i=new O(n.insertBefore(M(),r),r,void 0,e??{})}return i._$AI(a),i};var le=globalThis,x=class extends y{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){let n=super.createRenderRoot();return this.renderOptions.renderBefore??=n.firstChild,n}update(n){let e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(n),this._$Do=Ne(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return C}};x._$litElement$=!0,x.finalized=!0,le.litElementHydrateSupport?.({LitElement:x});var bt=le.litElementPolyfillSupport;bt?.({LitElement:x});(le.litElementVersions??=[]).push("4.2.2");var je=a=>(n,e)=>{e!==void 0?e.addInitializer(()=>{customElements.define(a,n)}):customElements.define(a,n)};var vt={attribute:!0,type:String,converter:P,reflect:!1,hasChanged:W},_t=(a=vt,n,e)=>{let{kind:t,metadata:i}=e,r=globalThis.litPropertyMetadata.get(i);if(r===void 0&&globalThis.litPropertyMetadata.set(i,r=new Map),t==="setter"&&((a=Object.create(a)).wrapped=!0),r.set(e.name,a),t==="accessor"){let{name:s}=e;return{set(c){let l=n.get.call(this);n.set.call(this,c),this.requestUpdate(s,l,a,!0,c)},init(c){return c!==void 0&&this.C(s,void 0,a,c),c}}}if(t==="setter"){let{name:s}=e;return function(c){let l=this[s];n.call(this,c),this.requestUpdate(s,l,a,!0,c)}}throw Error("Unsupported decorator location: "+t)};function H(a){return(n,e)=>typeof e=="object"?_t(a,n,e):((t,i,r)=>{let s=i.hasOwnProperty(r);return i.constructor.createProperty(r,t),s?Object.getOwnPropertyDescriptor(i,r):void 0})(a,n,e)}function g(a){return H({...a,state:!0,attribute:!1})}function ce(a,n){return o`${a.map(e=>yt(e,n))}`}function yt(a,n){switch(a.k){case"newline":return o` `;case"indent":return o`${a.t} `;case"keyword":return o`${a.t} `;case"operator":return o`${a.t} `;case"value":return o`${a.t} `;case"ref":{let e=n&&a.ek&&typeof a.ei=="number"?()=>n(a.ek,a.ei):void 0;return o`{for(var i=t>1?void 0:t?at(n,e):n,r=a.length-1,s;r>=0;r--)(s=a[r])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&rt(n,e,i),i};var B=globalThis,W=B.ShadowRoot&&(B.ShadyCSS===void 0||B.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,Q=Symbol(),ke=new WeakMap,D=class{constructor(n,e,t){if(this._$cssResult$=!0,t!==Q)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=n,this.t=e}get styleSheet(){let n=this.o,e=this.t;if(W&&n===void 0){let t=e!==void 0&&e.length===1;t&&(n=ke.get(e)),n===void 0&&((this.o=n=new CSSStyleSheet).replaceSync(this.cssText),t&&ke.set(e,n))}return n}toString(){return this.cssText}},Se=a=>new D(typeof a=="string"?a:a+"",void 0,Q),ee=(a,...n)=>{let e=a.length===1?a[0]:n.reduce((t,i,r)=>t+(s=>{if(s._$cssResult$===!0)return s.cssText;if(typeof s=="number")return s;throw Error("Value passed to 'css' function must be a 'css' function result: "+s+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+a[r+1],a[0]);return new D(e,a,Q)},Te=(a,n)=>{if(W)a.adoptedStyleSheets=n.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(let e of n){let t=document.createElement("style"),i=B.litNonce;i!==void 0&&t.setAttribute("nonce",i),t.textContent=e.cssText,a.appendChild(t)}},te=W?a=>a:a=>a instanceof CSSStyleSheet?(n=>{let e="";for(let t of n.cssRules)e+=t.cssText;return Se(e)})(a):a;var{is:ot,defineProperty:st,getOwnPropertyDescriptor:lt,getOwnPropertyNames:ct,getOwnPropertySymbols:dt,getPrototypeOf:ut}=Object,V=globalThis,Ce=V.trustedTypes,pt=Ce?Ce.emptyScript:"",ht=V.reactiveElementPolyfillSupport,I=(a,n)=>a,P={toAttribute(a,n){switch(n){case Boolean:a=a?pt:null;break;case Object:case Array:a=a==null?a:JSON.stringify(a)}return a},fromAttribute(a,n){let e=a;switch(n){case Boolean:e=a!==null;break;case Number:e=a===null?null:Number(a);break;case Object:case Array:try{e=JSON.parse(a)}catch{e=null}}return e}},q=(a,n)=>!ot(a,n),Fe={attribute:!0,type:String,converter:P,reflect:!1,useDefault:!1,hasChanged:q};Symbol.metadata??=Symbol("metadata"),V.litPropertyMetadata??=new WeakMap;var y=class extends HTMLElement{static addInitializer(n){this._$Ei(),(this.l??=[]).push(n)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(n,e=Fe){if(e.state&&(e.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(n)&&((e=Object.create(e)).wrapped=!0),this.elementProperties.set(n,e),!e.noAccessor){let t=Symbol(),i=this.getPropertyDescriptor(n,t,e);i!==void 0&&st(this.prototype,n,i)}}static getPropertyDescriptor(n,e,t){let{get:i,set:r}=lt(this.prototype,n)??{get(){return this[e]},set(s){this[e]=s}};return{get:i,set(s){let u=i?.call(this);r?.call(this,s),this.requestUpdate(n,u,t)},configurable:!0,enumerable:!0}}static getPropertyOptions(n){return this.elementProperties.get(n)??Fe}static _$Ei(){if(this.hasOwnProperty(I("elementProperties")))return;let n=ut(this);n.finalize(),n.l!==void 0&&(this.l=[...n.l]),this.elementProperties=new Map(n.elementProperties)}static finalize(){if(this.hasOwnProperty(I("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(I("properties"))){let e=this.properties,t=[...ct(e),...dt(e)];for(let i of t)this.createProperty(i,e[i])}let n=this[Symbol.metadata];if(n!==null){let e=litPropertyMetadata.get(n);if(e!==void 0)for(let[t,i]of e)this.elementProperties.set(t,i)}this._$Eh=new Map;for(let[e,t]of this.elementProperties){let i=this._$Eu(e,t);i!==void 0&&this._$Eh.set(i,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(n){let e=[];if(Array.isArray(n)){let t=new Set(n.flat(1/0).reverse());for(let i of t)e.unshift(te(i))}else n!==void 0&&e.push(te(n));return e}static _$Eu(n,e){let t=e.attribute;return t===!1?void 0:typeof t=="string"?t:typeof n=="string"?n.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(n=>this.enableUpdating=n),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(n=>n(this))}addController(n){(this._$EO??=new Set).add(n),this.renderRoot!==void 0&&this.isConnected&&n.hostConnected?.()}removeController(n){this._$EO?.delete(n)}_$E_(){let n=new Map,e=this.constructor.elementProperties;for(let t of e.keys())this.hasOwnProperty(t)&&(n.set(t,this[t]),delete this[t]);n.size>0&&(this._$Ep=n)}createRenderRoot(){let n=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return Te(n,this.constructor.elementStyles),n}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(n=>n.hostConnected?.())}enableUpdating(n){}disconnectedCallback(){this._$EO?.forEach(n=>n.hostDisconnected?.())}attributeChangedCallback(n,e,t){this._$AK(n,t)}_$ET(n,e){let t=this.constructor.elementProperties.get(n),i=this.constructor._$Eu(n,t);if(i!==void 0&&t.reflect===!0){let r=(t.converter?.toAttribute!==void 0?t.converter:P).toAttribute(e,t.type);this._$Em=n,r==null?this.removeAttribute(i):this.setAttribute(i,r),this._$Em=null}}_$AK(n,e){let t=this.constructor,i=t._$Eh.get(n);if(i!==void 0&&this._$Em!==i){let r=t.getPropertyOptions(i),s=typeof r.converter=="function"?{fromAttribute:r.converter}:r.converter?.fromAttribute!==void 0?r.converter:P;this._$Em=i;let u=s.fromAttribute(e,r.type);this[i]=u??this._$Ej?.get(i)??u,this._$Em=null}}requestUpdate(n,e,t,i=!1,r){if(n!==void 0){let s=this.constructor;if(i===!1&&(r=this[n]),t??=s.getPropertyOptions(n),!((t.hasChanged??q)(r,e)||t.useDefault&&t.reflect&&r===this._$Ej?.get(n)&&!this.hasAttribute(s._$Eu(n,t))))return;this.C(n,e,t)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(n,e,{useDefault:t,reflect:i,wrapped:r},s){t&&!(this._$Ej??=new Map).has(n)&&(this._$Ej.set(n,s??e??this[n]),r!==!0||s!==void 0)||(this._$AL.has(n)||(this.hasUpdated||t||(e=void 0),this._$AL.set(n,e)),i===!0&&this._$Em!==n&&(this._$Eq??=new Set).add(n))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(e){Promise.reject(e)}let n=this.scheduleUpdate();return n!=null&&await n,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(let[i,r]of this._$Ep)this[i]=r;this._$Ep=void 0}let t=this.constructor.elementProperties;if(t.size>0)for(let[i,r]of t){let{wrapped:s}=r,u=this[i];s!==!0||this._$AL.has(i)||u===void 0||this.C(i,void 0,r,u)}}let n=!1,e=this._$AL;try{n=this.shouldUpdate(e),n?(this.willUpdate(e),this._$EO?.forEach(t=>t.hostUpdate?.()),this.update(e)):this._$EM()}catch(t){throw n=!1,this._$EM(),t}n&&this._$AE(e)}willUpdate(n){}_$AE(n){this._$EO?.forEach(e=>e.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(n)),this.updated(n)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(n){return!0}update(n){this._$Eq&&=this._$Eq.forEach(e=>this._$ET(e,this[e])),this._$EM()}updated(n){}firstUpdated(n){}};y.elementStyles=[],y.shadowRootOptions={mode:"open"},y[I("elementProperties")]=new Map,y[I("finalized")]=new Map,ht?.({ReactiveElement:y}),(V.reactiveElementVersions??=[]).push("2.1.2");var le=globalThis,Ae=a=>a,G=le.trustedTypes,we=G?G.createPolicy("lit-html",{createHTML:a=>a}):void 0,ze="$lit$",$=`lit$${Math.random().toFixed(9).slice(2)}$`,Le="?"+$,mt=`<${Le}>`,S=document,z=()=>S.createComment(""),L=a=>a===null||typeof a!="object"&&typeof a!="function",ce=Array.isArray,gt=a=>ce(a)||typeof a?.[Symbol.iterator]=="function",ne=`[
+\f\r]`,M=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Re=/-->/g,De=/>/g,E=RegExp(`>|${ne}(?:([^\\s"'>=/]+)(${ne}*=${ne}*(?:[^
+\f\r"'\`<>=]|("|')|))|$)`,"g"),Ie=/'/g,Pe=/"/g,Oe=/^(?:script|style|textarea|title)$/i,de=a=>(n,...e)=>({_$litType$:a,strings:n,values:e}),o=de(1),Rt=de(2),Dt=de(3),T=Symbol.for("lit-noChange"),b=Symbol.for("lit-nothing"),Me=new WeakMap,k=S.createTreeWalker(S,129);function He(a,n){if(!ce(a)||!a.hasOwnProperty("raw"))throw Error("invalid template strings array");return we!==void 0?we.createHTML(n):n}var bt=(a,n)=>{let e=a.length-1,t=[],i,r=n===2?"":n===3?"":"",s=M;for(let u=0;u"?(s=i??M,d=-1):c[1]===void 0?d=-2:(d=s.lastIndex-c[2].length,p=c[1],s=c[3]===void 0?E:c[3]==='"'?Pe:Ie):s===Pe||s===Ie?s=E:s===Re||s===De?s=M:(s=E,i=void 0);let v=s===E&&a[u+1].startsWith("/>")?" ":"";r+=s===M?l+mt:d>=0?(t.push(p),l.slice(0,d)+ze+l.slice(d)+$+v):l+$+(d===-2?u:v)}return[He(a,r+(a[e]||">")+(n===2?" ":n===3?"":"")),t]},O=class a{constructor({strings:n,_$litType$:e},t){let i;this.parts=[];let r=0,s=0,u=n.length-1,l=this.parts,[p,c]=bt(n,e);if(this.el=a.createElement(p,t),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=G?G.emptyScript:"";for(let v=0;v2||t[0]!==""||t[1]!==""?(this._$AH=Array(t.length-1).fill(new String),this.strings=t):this._$AH=b}_$AI(n,e=this,t,i){let r=this.strings,s=!1;if(r===void 0)n=A(this,n,e,0),s=!L(n)||n!==this._$AH&&n!==T,s&&(this._$AH=n);else{let u=n,l,p;for(n=r[0],l=0;l{let t=e?.renderBefore??n,i=t._$litPart$;if(i===void 0){let r=e?.renderBefore??null;t._$litPart$=i=new H(n.insertBefore(z(),r),r,void 0,e??{})}return i._$AI(a),i};var ue=globalThis,x=class extends y{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){let n=super.createRenderRoot();return this.renderOptions.renderBefore??=n.firstChild,n}update(n){let e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(n),this._$Do=Ne(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return T}};x._$litElement$=!0,x.finalized=!0,ue.litElementHydrateSupport?.({LitElement:x});var vt=ue.litElementPolyfillSupport;vt?.({LitElement:x});(ue.litElementVersions??=[]).push("4.2.2");var je=a=>(n,e)=>{e!==void 0?e.addInitializer(()=>{customElements.define(a,n)}):customElements.define(a,n)};var _t={attribute:!0,type:String,converter:P,reflect:!1,hasChanged:q},yt=(a=_t,n,e)=>{let{kind:t,metadata:i}=e,r=globalThis.litPropertyMetadata.get(i);if(r===void 0&&globalThis.litPropertyMetadata.set(i,r=new Map),t==="setter"&&((a=Object.create(a)).wrapped=!0),r.set(e.name,a),t==="accessor"){let{name:s}=e;return{set(u){let l=n.get.call(this);n.set.call(this,u),this.requestUpdate(s,l,a,!0,u)},init(u){return u!==void 0&&this.C(s,void 0,a,u),u}}}if(t==="setter"){let{name:s}=e;return function(u){let l=this[s];n.call(this,u),this.requestUpdate(s,l,a,!0,u)}}throw Error("Unsupported decorator location: "+t)};function N(a){return(n,e)=>typeof e=="object"?yt(a,n,e):((t,i,r)=>{let s=i.hasOwnProperty(r);return i.constructor.createProperty(r,t),s?Object.getOwnPropertyDescriptor(i,r):void 0})(a,n,e)}function g(a){return N({...a,state:!0,attribute:!1})}function pe(a,n){return o`${a.map(e=>$t(e,n))}`}function $t(a,n){switch(a.k){case"newline":return o` `;case"indent":return o`${a.t} `;case"keyword":return o`${a.t} `;case"operator":return o`${a.t} `;case"value":return o`${a.t} `;case"ref":{let e=n&&a.ek&&typeof a.ei=="number"?()=>n(a.ek,a.ei):void 0;return o`
${a.t}
${a.s?o`${a.s} `:""}
- `}default:return o`${a.t} `}}var G=[{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 N(a){return G.find(n=>n.value===a)}var de=[{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"}],ue=1,pe=2,he=3;var Z=[{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 T(a){if(Z.some(n=>n.id===a))return{category:"fixed",fixedId:a};if(!(a&65280))return{category:"button",button:a&255};if((a&64512)===1024){let n=a&1023;return{category:"zone",zone:Math.floor(n/4)+1,zoneState:n%4}}if((a&64512)===2048){let n=a&1023;return{category:"unit",unit:Math.floor(n/2)+1,unitOn:(n&1)===1}}return{category:"raw",raw:a}}function me(a){switch(a.category){case"button":return(a.button??1)&255;case"zone":{let n=(a.zone??1)-1,e=(a.zoneState??0)&3;return 1024|n*4+e&1023}case"unit":{let n=(a.unit??1)-1,e=a.unitOn?1:0;return 2048|n*2+e&1023}case"fixed":return a.fixedId??768;case"raw":default:return a.raw??0}}function w(a){return(a.month??0)<<8|(a.day??0)}function Ue(a,n){return{...a,month:n>>8&255,day:n&255}}var Ye=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],ge=[{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"}],fe=[{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 Be(a){if(a===0)return{family:"none"};let n=a>>8&252,e=(a&512)!==0;return n===0?{family:"misc",misc:a&15}:n===4?{family:"zone",index:a&255,active:e}:n===8?{family:"unit",index:a&511,active:e}:n===12?{family:"time",index:a&255,active:e}:{family:"sec",index:a>>8&15,mode:a>>12&7}}function v(a){switch(a.family){case"none":return 0;case"misc":return(a.misc??0)&15;case"zone":{let n=(a.index??0)&255;return 1024|(a.active?512:0)|n}case"unit":{let n=(a.index??0)&511;return 2048|(a.active?512:0)|n}case"time":{let n=(a.index??0)&255;return 3072|(a.active?512:0)|n}case"sec":{let n=(a.index??1)&15;return((a.mode??0)&7)<<12|n<<8}}}var We=5,Ve=6,qe=7,$t=8,be=9,xt=10;function Ge(a){let n=(a.cond??0)&255,e=(a.cond2??0)>>8&255,t=n&252,i=(n&2)!==0;return n===0&&e===0?{family:"none"}:t===0?{family:"misc",misc:n&15}:t===4?{family:"zone",index:e,active:i}:t===8?{family:"unit",index:e,active:i}:t===12?{family:"time",index:e,active:i}:{family:"sec",index:n&15,mode:n>>4&7}}function ve(a){switch(a.family){case"none":return{cond:0,cond2:0};case"misc":return{cond:(a.misc??0)&15,cond2:0};case"zone":return{cond:4|(a.active?2:0),cond2:((a.index??0)&255)<<8};case"unit":return{cond:8|(a.active?2:0),cond2:((a.index??0)&255)<<8};case"time":return{cond:12|(a.active?2:0),cond2:((a.index??0)&255)<<8};case"sec":{let n=(a.index??1)&15;return{cond:((a.mode??0)&7)<<4|n,cond2:0}}}}function Ze(a){return((a.cond??0)>>8&255)!==0}function _e(){return{prog_type:$t,cond:1,cond2:0,cmd:0,par:0,pr2:0,month:0,day:0,days:0,hour:0,minute:0}}function Ke(){return{..._e(),prog_type:be}}function Je(a=1){return{prog_type:xt,cmd:0,par:0,pr2:a,cond:0,cond2:0,month:0,day:0,days:0,hour:0,minute:0}}var Xe=[{value:1,label:"=="},{value:2,label:"!="},{value:3,label:"<"},{value:4,label:">"},{value:5,label:"is odd"},{value:6,label:"is even"},{value:7,label:"is multiple of"},{value:8,label:"in (bitmask)"},{value:9,label:"not in (bitmask)"}];function ye(a){return a===5||a===6}var $e=[{value:0,label:"Constant",kind:null},{value:2,label:"Zone",kind:"zone"},{value:3,label:"Unit",kind:"unit"},{value:4,label:"Thermostat",kind:"thermostat"},{value:6,label:"Area",kind:"area"},{value:7,label:"Time / Date",kind:null}];function Et(a){return[2,3,4,6,7].includes(a)}function xe(a){let n=$e.find(e=>e.value===a);return n?n.kind:null}var Ee={2:[{value:1,label:"Loop reading"},{value:2,label:"Current state"},{value:3,label:"Arming state"},{value:4,label:"Alarm state"}],3:[{value:1,label:"Current state"},{value:2,label:"Previous state"},{value:3,label:"Timer"},{value:4,label:"Level"}],4:[{value:1,label:"Current temperature"},{value:2,label:"Heat setpoint"},{value:3,label:"Cool setpoint"},{value:4,label:"System mode"},{value:5,label:"Fan mode"},{value:6,label:"Hold mode"},{value:7,label:"Freeze alarm"},{value:8,label:"Comm error"},{value:9,label:"Humidity"},{value:10,label:"Humidify setpoint"},{value:11,label:"Dehumidify setpoint"},{value:12,label:"Outdoor temperature"},{value:13,label:"System status"}],6:[{value:1,label:"Security mode"}],7:[{value:2,label:"Year"},{value:3,label:"Month"},{value:4,label:"Day"},{value:5,label:"Day of week (1=Mon..7=Sun)"},{value:6,label:"Time (minutes since midnight)"},{value:8,label:"Hour"},{value:9,label:"Minute"}]};function Qe(a){return{op:(a.cond??0)>>8&255,arg1Type:(a.cond??0)&255,arg1Ix:a.cond2??0,arg1Field:a.cmd??0,arg2Type:a.par??0,arg2Ix:a.pr2??0,arg2Field:a.month??0,compConst:(a.day??0)<<8|(a.days??0)}}function et(a){return{cond:(a.op&255)<<8|a.arg1Type&255,cond2:a.arg1Ix&65535,cmd:a.arg1Field&255,par:a.arg2Type&255,pr2:a.arg2Ix&65535,month:a.arg2Field&255,day:a.compConst>>8&255,days:a.compConst&255}}function tt(a){return!(!Et(a.arg1Type)||!ye(a.op)&&a.arg2Type!==0||a.compConst!==0)}var nt=new Set(["TIMED","EVENT","YEARLY"]),kt=["TIMED","EVENT","YEARLY","WHEN","AT","EVERY","REMARK"],St=5e3,h=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._chainDraft=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 t=(await this.hass.connection.sendMessagePromise({type:"config_entries/get"})).filter(r=>r.domain==="omni_pca");if(t.length===0){this._error="No Omni panel configured. Add one via Settings \u2192 Devices & Services.";return}let i=t.find(r=>r.state==="loaded");this._entryId=(i??t[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 t=await this.hass.connection.sendMessagePromise(e);this._rows=t.programs,this._total=t.total,this._filteredTotal=t.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(t){this._error=t instanceof Error?t.message:String(t)}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(t){this._fireFeedback=`error: ${t instanceof Error?t.message:t}`}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(t){let i=t instanceof Error?t.message:String(t);this._writeFeedback=`error: ${i}`}setTimeout(()=>{this._writeFeedback=null},4e3)}}async _cloneProgram(e){if(!this._entryId)return;let t=this._cloneTargetSlot.trim(),i=parseInt(t,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(r){let s=r instanceof Error?r.message:String(r);this._writeFeedback=`error: ${s}`}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 t=e instanceof Error?e.message:String(e);console.warn("omni_pca: objects/list failed",t)}}async _beginEdit(){if(!this._detail||(await this._ensureObjectsLoaded(),!this._entryId))return;if(this._detail.kind==="chain"){this._beginChainEdit();return}if(!nt.has(this._detail.trigger_type))return;let e=this._detail.fields??this._defaultFieldsForType(this._detail.trigger_type);e!==null&&(this._editingDraft={...e},this._stopRefreshTimer())}_beginChainEdit(){if(!this._detail||!this._detail.chain_members)return;let e=this._detail.chain_members,t=e.find(i=>i.role==="head");t&&(this._chainDraft={headSlot:t.slot,head:{...t.fields},conditions:e.filter(i=>i.role==="condition").map(i=>({...i.fields})),actions:e.filter(i=>i.role==="action").map(i=>({...i.fields}))},this._stopRefreshTimer())}_cancelChainEdit(){this._chainDraft=null,this._startRefreshTimer()}async _saveChainDraft(){if(!(!this._chainDraft||!this._entryId)){this._writeFeedback="saving chain\u2026";try{await this.hass.connection.sendMessagePromise({type:"omni_pca/programs/chain/write",entry_id:this._entryId,head_slot:this._chainDraft.headSlot,head:this._chainDraft.head,conditions:this._chainDraft.conditions,actions:this._chainDraft.actions}),this._writeFeedback=`saved chain @ slot ${this._chainDraft.headSlot}`;let e=this._chainDraft.headSlot;this._chainDraft=null,this._startRefreshTimer(),await this._loadList(),await this._loadDetail(e)}catch(e){let t=e instanceof Error?e.message:String(e);this._writeFeedback=`error: ${t}`}setTimeout(()=>{this._writeFeedback=null},4e3)}}_patchChainHead(e){this._chainDraft&&(this._chainDraft={...this._chainDraft,head:{...this._chainDraft.head,...e}})}_patchChainCondition(e,t){if(!this._chainDraft)return;let i=[...this._chainDraft.conditions];i[e]={...i[e],...t},this._chainDraft={...this._chainDraft,conditions:i}}_addChainCondition(e=!1){if(!this._chainDraft)return;let t=e?Ke():_e();this._chainDraft={...this._chainDraft,conditions:[...this._chainDraft.conditions,t]}}_removeChainCondition(e){if(!this._chainDraft)return;let t=this._chainDraft.conditions.filter((i,r)=>r!==e);this._chainDraft={...this._chainDraft,conditions:t}}_patchChainAction(e,t){if(!this._chainDraft)return;let i=[...this._chainDraft.actions];i[e]={...i[e],...t},this._chainDraft={...this._chainDraft,actions:i}}_addChainAction(){if(!this._chainDraft)return;let e=this._objects?.units?.[0]?.index??1;this._chainDraft={...this._chainDraft,actions:[...this._chainDraft.actions,Je(e)]}}_removeChainAction(e){if(!this._chainDraft||this._chainDraft.actions.length<=1)return;let t=this._chainDraft.actions.filter((i,r)=>r!==e);this._chainDraft={...this._chainDraft,actions:t}}_defaultFieldsForType(e){let t=this._objects?.units?.[0]?.index??1;if(e==="TIMED")return{prog_type:ue,cmd:1,par:0,pr2:t,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:pe,cmd:1,par:0,pr2:t,month:0,day:i&255,hour:0,minute:0,days:0,cond:0,cond2:0}}return e==="YEARLY"?{prog_type:he,cmd:1,par:0,pr2:t,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 t=e instanceof Error?e.message:String(e);this._writeFeedback=`error: ${t}`}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 t=parseInt(e.target.value,10);if(!Number.isFinite(t))return;let i=N(t),r=this._editingDraft?.pr2??0;if(i?.ref_kind&&this._objects){let s=this._pickBucket(i.ref_kind);s&&s.length>0&&!s.some(c=>c.index===r)&&(r=s[0].index)}else i?.ref_kind||(r=0);this._patchDraft({cmd:t,pr2:r})}_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;case"thermostat":return this._objects.thermostats;default:return null}}_bucketWithPreserve(e,t,i){let r=e??[];return i===0||r.some(s=>s.index===i)?r:[{index:i,name:`(undiscovered ${t} ${i} \u2014 preserve original)`},...r]}_onObjectChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&this._patchDraft({pr2:t})}_onHourChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&t>=0&&t<=23&&this._patchDraft({hour:t})}_onMinuteChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&t>=0&&t<=59&&this._patchDraft({minute:t})}_onParChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&t>=0&&t<=255&&this._patchDraft({par:t})}_onMonthChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&t>=1&&t<=12&&this._patchDraft({month:t})}_onDayChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&t>=1&&t<=31&&this._patchDraft({day:t})}_patchEvent(e){if(!this._editingDraft)return;let t=me(e);this._editingDraft=Ue(this._editingDraft,t)}_onEventCategoryChange(e){let t=e.target.value;if(t==="button"){let i=this._objects?.buttons?.[0]?.index??1;this._patchEvent({category:"button",button:i})}else if(t==="zone"){let i=this._objects?.zones?.[0]?.index??1;this._patchEvent({category:"zone",zone:i,zoneState:1})}else if(t==="unit"){let i=this._objects?.units?.[0]?.index??1;this._patchEvent({category:"unit",unit:i,unitOn:!0})}else t==="fixed"&&this._patchEvent({category:"fixed",fixedId:772})}_onEventButtonChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&this._patchEvent({category:"button",button:t})}_onEventZoneChange(e){if(!this._editingDraft)return;let t=parseInt(e.target.value,10);if(!Number.isFinite(t))return;let i=T(w(this._editingDraft));this._patchEvent({category:"zone",zone:t,zoneState:i.zoneState??1})}_onEventZoneStateChange(e){if(!this._editingDraft)return;let t=parseInt(e.target.value,10);if(!Number.isFinite(t))return;let i=T(w(this._editingDraft));this._patchEvent({category:"zone",zone:i.zone??1,zoneState:t})}_onEventUnitChange(e){if(!this._editingDraft)return;let t=parseInt(e.target.value,10);if(!Number.isFinite(t))return;let i=T(w(this._editingDraft));this._patchEvent({category:"unit",unit:t,unitOn:i.unitOn??!0})}_onEventUnitOnChange(e){if(!this._editingDraft)return;let t=e.target.value==="1",i=T(w(this._editingDraft));this._patchEvent({category:"unit",unit:i.unit??1,unitOn:t})}_onEventFixedChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&this._patchEvent({category:"fixed",fixedId:t})}_startRefreshTimer(){this._refreshTimer===null&&(this._refreshTimer=window.setInterval(()=>{this._loadList(),this._selectedSlot!==null&&this._loadDetail(this._selectedSlot)},St))}_stopRefreshTimer(){this._refreshTimer!==null&&(window.clearInterval(this._refreshTimer),this._refreshTimer=null)}_toggleTriggerFilter(e){let t=new Set(this._activeTriggerTypes);t.has(e)?t.delete(e):t.add(e),this._activeTriggerTypes=t,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,t){this._referenceFilter=`${e}:${t}`,this._selectedSlot=null,this._detail=null,this._loadList()}_closeDetail(){this._selectedSlot=null,this._detail=null}render(){return o`
+ `}default:return o`${a.t} `}}var K=[{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 j(a){return K.find(n=>n.value===a)}var he=[{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"}],me=1,ge=2,be=3;var J=[{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(a){if(J.some(n=>n.id===a))return{category:"fixed",fixedId:a};if(!(a&65280))return{category:"button",button:a&255};if((a&64512)===1024){let n=a&1023;return{category:"zone",zone:Math.floor(n/4)+1,zoneState:n%4}}if((a&64512)===2048){let n=a&1023;return{category:"unit",unit:Math.floor(n/2)+1,unitOn:(n&1)===1}}return{category:"raw",raw:a}}function fe(a){switch(a.category){case"button":return(a.button??1)&255;case"zone":{let n=(a.zone??1)-1,e=(a.zoneState??0)&3;return 1024|n*4+e&1023}case"unit":{let n=(a.unit??1)-1,e=a.unitOn?1:0;return 2048|n*2+e&1023}case"fixed":return a.fixedId??768;case"raw":default:return a.raw??0}}function R(a){return(a.month??0)<<8|(a.day??0)}function Ye(a,n){return{...a,month:n>>8&255,day:n&255}}var Be=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],ve=[{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"}],_e=[{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 We(a){if(a===0)return{family:"none"};let n=a>>8&252,e=(a&512)!==0;return n===0?{family:"misc",misc:a&15}:n===4?{family:"zone",index:a&255,active:e}:n===8?{family:"unit",index:a&511,active:e}:n===12?{family:"time",index:a&255,active:e}:{family:"sec",index:a>>8&15,mode:a>>12&7}}function _(a){switch(a.family){case"none":return 0;case"misc":return(a.misc??0)&15;case"zone":{let n=(a.index??0)&255;return 1024|(a.active?512:0)|n}case"unit":{let n=(a.index??0)&511;return 2048|(a.active?512:0)|n}case"time":{let n=(a.index??0)&255;return 3072|(a.active?512:0)|n}case"sec":{let n=(a.index??1)&15;return((a.mode??0)&7)<<12|n<<8}}}var Ve=5,qe=6,Ge=7,xt=8,ye=9,Et=10;function Ze(a){let n=(a.cond??0)&255,e=(a.cond2??0)>>8&255,t=n&252,i=(n&2)!==0;return n===0&&e===0?{family:"none"}:t===0?{family:"misc",misc:n&15}:t===4?{family:"zone",index:e,active:i}:t===8?{family:"unit",index:e,active:i}:t===12?{family:"time",index:e,active:i}:{family:"sec",index:n&15,mode:n>>4&7}}function $e(a){switch(a.family){case"none":return{cond:0,cond2:0};case"misc":return{cond:(a.misc??0)&15,cond2:0};case"zone":return{cond:4|(a.active?2:0),cond2:((a.index??0)&255)<<8};case"unit":return{cond:8|(a.active?2:0),cond2:((a.index??0)&255)<<8};case"time":return{cond:12|(a.active?2:0),cond2:((a.index??0)&255)<<8};case"sec":{let n=(a.index??1)&15;return{cond:((a.mode??0)&7)<<4|n,cond2:0}}}}function Ke(a){return((a.cond??0)>>8&255)!==0}function xe(){return{prog_type:xt,cond:1,cond2:0,cmd:0,par:0,pr2:0,month:0,day:0,days:0,hour:0,minute:0}}function Je(){return{...xe(),prog_type:ye}}function Xe(a=1){return{prog_type:Et,cmd:0,par:0,pr2:a,cond:0,cond2:0,month:0,day:0,days:0,hour:0,minute:0}}var Qe=[{value:1,label:"=="},{value:2,label:"!="},{value:3,label:"<"},{value:4,label:">"},{value:5,label:"is odd"},{value:6,label:"is even"},{value:7,label:"is multiple of"},{value:8,label:"in (bitmask)"},{value:9,label:"not in (bitmask)"}];function Ee(a){return a===5||a===6}var X=[{value:0,label:"Constant",kind:null},{value:2,label:"Zone",kind:"zone"},{value:3,label:"Unit",kind:"unit"},{value:4,label:"Thermostat",kind:"thermostat"},{value:6,label:"Area",kind:"area"},{value:7,label:"Time / Date",kind:null}];function Ue(a){return[2,3,4,6,7].includes(a)}function U(a){let n=X.find(e=>e.value===a);return n?n.kind:null}var Y={2:[{value:1,label:"Loop reading"},{value:2,label:"Current state"},{value:3,label:"Arming state"},{value:4,label:"Alarm state"}],3:[{value:1,label:"Current state"},{value:2,label:"Previous state"},{value:3,label:"Timer"},{value:4,label:"Level"}],4:[{value:1,label:"Current temperature"},{value:2,label:"Heat setpoint"},{value:3,label:"Cool setpoint"},{value:4,label:"System mode"},{value:5,label:"Fan mode"},{value:6,label:"Hold mode"},{value:7,label:"Freeze alarm"},{value:8,label:"Comm error"},{value:9,label:"Humidity"},{value:10,label:"Humidify setpoint"},{value:11,label:"Dehumidify setpoint"},{value:12,label:"Outdoor temperature"},{value:13,label:"System status"}],6:[{value:1,label:"Security mode"}],7:[{value:2,label:"Year"},{value:3,label:"Month"},{value:4,label:"Day"},{value:5,label:"Day of week (1=Mon..7=Sun)"},{value:6,label:"Time (minutes since midnight)"},{value:8,label:"Hour"},{value:9,label:"Minute"}]};function et(a){return{op:(a.cond??0)>>8&255,arg1Type:(a.cond??0)&255,arg1Ix:a.cond2??0,arg1Field:a.cmd??0,arg2Type:a.par??0,arg2Ix:a.pr2??0,arg2Field:a.month??0,compConst:(a.day??0)<<8|(a.days??0)}}function tt(a){return{cond:(a.op&255)<<8|a.arg1Type&255,cond2:a.arg1Ix&65535,cmd:a.arg1Field&255,par:a.arg2Type&255,pr2:a.arg2Ix&65535,month:a.arg2Field&255,day:a.compConst>>8&255,days:a.compConst&255}}function nt(a){return!(!Ue(a.arg1Type)||!Ee(a.op)&&a.arg2Type!==0&&!Ue(a.arg2Type)||a.compConst!==0)}var it=new Set(["TIMED","EVENT","YEARLY"]),kt=["TIMED","EVENT","YEARLY","WHEN","AT","EVERY","REMARK"],St=5e3,h=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._chainDraft=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 t=(await this.hass.connection.sendMessagePromise({type:"config_entries/get"})).filter(r=>r.domain==="omni_pca");if(t.length===0){this._error="No Omni panel configured. Add one via Settings \u2192 Devices & Services.";return}let i=t.find(r=>r.state==="loaded");this._entryId=(i??t[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 t=await this.hass.connection.sendMessagePromise(e);this._rows=t.programs,this._total=t.total,this._filteredTotal=t.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(t){this._error=t instanceof Error?t.message:String(t)}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(t){this._fireFeedback=`error: ${t instanceof Error?t.message:t}`}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(t){let i=t instanceof Error?t.message:String(t);this._writeFeedback=`error: ${i}`}setTimeout(()=>{this._writeFeedback=null},4e3)}}async _cloneProgram(e){if(!this._entryId)return;let t=this._cloneTargetSlot.trim(),i=parseInt(t,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(r){let s=r instanceof Error?r.message:String(r);this._writeFeedback=`error: ${s}`}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 t=e instanceof Error?e.message:String(e);console.warn("omni_pca: objects/list failed",t)}}async _beginEdit(){if(!this._detail||(await this._ensureObjectsLoaded(),!this._entryId))return;if(this._detail.kind==="chain"){this._beginChainEdit();return}if(!it.has(this._detail.trigger_type))return;let e=this._detail.fields??this._defaultFieldsForType(this._detail.trigger_type);e!==null&&(this._editingDraft={...e},this._stopRefreshTimer())}_beginChainEdit(){if(!this._detail||!this._detail.chain_members)return;let e=this._detail.chain_members,t=e.find(i=>i.role==="head");t&&(this._chainDraft={headSlot:t.slot,head:{...t.fields},conditions:e.filter(i=>i.role==="condition").map(i=>({...i.fields})),actions:e.filter(i=>i.role==="action").map(i=>({...i.fields}))},this._stopRefreshTimer())}_cancelChainEdit(){this._chainDraft=null,this._startRefreshTimer()}async _saveChainDraft(){if(!(!this._chainDraft||!this._entryId)){this._writeFeedback="saving chain\u2026";try{await this.hass.connection.sendMessagePromise({type:"omni_pca/programs/chain/write",entry_id:this._entryId,head_slot:this._chainDraft.headSlot,head:this._chainDraft.head,conditions:this._chainDraft.conditions,actions:this._chainDraft.actions}),this._writeFeedback=`saved chain @ slot ${this._chainDraft.headSlot}`;let e=this._chainDraft.headSlot;this._chainDraft=null,this._startRefreshTimer(),await this._loadList(),await this._loadDetail(e)}catch(e){let t=e instanceof Error?e.message:String(e);this._writeFeedback=`error: ${t}`}setTimeout(()=>{this._writeFeedback=null},4e3)}}_patchChainHead(e){this._chainDraft&&(this._chainDraft={...this._chainDraft,head:{...this._chainDraft.head,...e}})}_patchChainCondition(e,t){if(!this._chainDraft)return;let i=[...this._chainDraft.conditions];i[e]={...i[e],...t},this._chainDraft={...this._chainDraft,conditions:i}}_addChainCondition(e=!1){if(!this._chainDraft)return;let t=e?Je():xe();this._chainDraft={...this._chainDraft,conditions:[...this._chainDraft.conditions,t]}}_removeChainCondition(e){if(!this._chainDraft)return;let t=this._chainDraft.conditions.filter((i,r)=>r!==e);this._chainDraft={...this._chainDraft,conditions:t}}_patchChainAction(e,t){if(!this._chainDraft)return;let i=[...this._chainDraft.actions];i[e]={...i[e],...t},this._chainDraft={...this._chainDraft,actions:i}}_addChainAction(){if(!this._chainDraft)return;let e=this._objects?.units?.[0]?.index??1;this._chainDraft={...this._chainDraft,actions:[...this._chainDraft.actions,Xe(e)]}}_removeChainAction(e){if(!this._chainDraft||this._chainDraft.actions.length<=1)return;let t=this._chainDraft.actions.filter((i,r)=>r!==e);this._chainDraft={...this._chainDraft,actions:t}}_defaultFieldsForType(e){let t=this._objects?.units?.[0]?.index??1;if(e==="TIMED")return{prog_type:me,cmd:1,par:0,pr2:t,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:ge,cmd:1,par:0,pr2:t,month:0,day:i&255,hour:0,minute:0,days:0,cond:0,cond2:0}}return e==="YEARLY"?{prog_type:be,cmd:1,par:0,pr2:t,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 t=e instanceof Error?e.message:String(e);this._writeFeedback=`error: ${t}`}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 t=parseInt(e.target.value,10);if(!Number.isFinite(t))return;let i=j(t),r=this._editingDraft?.pr2??0;if(i?.ref_kind&&this._objects){let s=this._pickBucket(i.ref_kind);s&&s.length>0&&!s.some(u=>u.index===r)&&(r=s[0].index)}else i?.ref_kind||(r=0);this._patchDraft({cmd:t,pr2:r})}_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;case"thermostat":return this._objects.thermostats;default:return null}}_bucketWithPreserve(e,t,i){let r=e??[];return i===0||r.some(s=>s.index===i)?r:[{index:i,name:`(undiscovered ${t} ${i} \u2014 preserve original)`},...r]}_onObjectChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&this._patchDraft({pr2:t})}_onHourChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&t>=0&&t<=23&&this._patchDraft({hour:t})}_onMinuteChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&t>=0&&t<=59&&this._patchDraft({minute:t})}_onParChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&t>=0&&t<=255&&this._patchDraft({par:t})}_onMonthChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&t>=1&&t<=12&&this._patchDraft({month:t})}_onDayChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&t>=1&&t<=31&&this._patchDraft({day:t})}_patchEvent(e){if(!this._editingDraft)return;let t=fe(e);this._editingDraft=Ye(this._editingDraft,t)}_onEventCategoryChange(e){let t=e.target.value;if(t==="button"){let i=this._objects?.buttons?.[0]?.index??1;this._patchEvent({category:"button",button:i})}else if(t==="zone"){let i=this._objects?.zones?.[0]?.index??1;this._patchEvent({category:"zone",zone:i,zoneState:1})}else if(t==="unit"){let i=this._objects?.units?.[0]?.index??1;this._patchEvent({category:"unit",unit:i,unitOn:!0})}else t==="fixed"&&this._patchEvent({category:"fixed",fixedId:772})}_onEventButtonChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&this._patchEvent({category:"button",button:t})}_onEventZoneChange(e){if(!this._editingDraft)return;let t=parseInt(e.target.value,10);if(!Number.isFinite(t))return;let i=C(R(this._editingDraft));this._patchEvent({category:"zone",zone:t,zoneState:i.zoneState??1})}_onEventZoneStateChange(e){if(!this._editingDraft)return;let t=parseInt(e.target.value,10);if(!Number.isFinite(t))return;let i=C(R(this._editingDraft));this._patchEvent({category:"zone",zone:i.zone??1,zoneState:t})}_onEventUnitChange(e){if(!this._editingDraft)return;let t=parseInt(e.target.value,10);if(!Number.isFinite(t))return;let i=C(R(this._editingDraft));this._patchEvent({category:"unit",unit:t,unitOn:i.unitOn??!0})}_onEventUnitOnChange(e){if(!this._editingDraft)return;let t=e.target.value==="1",i=C(R(this._editingDraft));this._patchEvent({category:"unit",unit:i.unit??1,unitOn:t})}_onEventFixedChange(e){let t=parseInt(e.target.value,10);Number.isFinite(t)&&this._patchEvent({category:"fixed",fixedId:t})}_startRefreshTimer(){this._refreshTimer===null&&(this._refreshTimer=window.setInterval(()=>{this._loadList(),this._selectedSlot!==null&&this._loadDetail(this._selectedSlot)},St))}_stopRefreshTimer(){this._refreshTimer!==null&&(window.clearInterval(this._refreshTimer),this._refreshTimer=null)}_toggleTriggerFilter(e){let t=new Set(this._activeTriggerTypes);t.has(e)?t.delete(e):t.add(e),this._activeTriggerTypes=t,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,t){this._referenceFilter=`${e}:${t}`,this._selectedSlot=null,this._detail=null,this._loadList()}_closeDetail(){this._selectedSlot=null,this._detail=null}render(){return o`
`}_renderStructuredAndForm(e,t){let i=c=>{let d={...e,...c};this._patchChainCondition(t,tt(d))},r=Y[e.arg1Type]??[],s=U(e.arg1Type),u=Y[e.arg2Type]??[],l=U(e.arg2Type),p=!Ee(e.op);return o`
Arg1 type
- {let d=parseInt(l.target.value,10),p=(Ee[d]??[{value:0}])[0].value,u=xe(d),f=0;u==="zone"?f=this._objects?.zones?.[0]?.index??1:u==="unit"?f=this._objects?.units?.[0]?.index??1:u==="thermostat"?f=this._objects?.thermostats?.[0]?.index??1:u==="area"&&(f=this._objects?.areas?.[0]?.index??1),i({arg1Type:d,arg1Ix:f,arg1Field:p})}}>
- ${$e.filter(l=>l.value!==0).map(l=>o`
-
- ${l.label}
+ {let d=parseInt(c.target.value,10);i({arg1Type:d,arg1Ix:this._defaultIxForKind(U(d)),arg1Field:(Y[d]??[{value:0}])[0].value})}}>
+ ${X.filter(c=>c.value!==0).map(c=>o`
+
+ ${c.label}
`)}
- ${s?this._renderStructuredArg1Picker(e,s,i):""}
+ ${s?this._renderStructuredObjectPicker(s,e.arg1Ix,c=>i({arg1Ix:c}),"Arg1"):""}
${r.length>0?o`
Field
- i({arg1Field:parseInt(l.target.value,10)})}>
- ${r.map(l=>o`
-
- ${l.label}
+ i({arg1Field:parseInt(c.target.value,10)})}>
+ ${r.map(c=>o`
+
+ ${c.label}
`)}
`:""}
Operator
- i({op:parseInt(l.target.value,10)})}>
- ${Xe.map(l=>o`
-
- ${l.label}
+ i({op:parseInt(c.target.value,10)})}>
+ ${Qe.map(c=>o`
+
+ ${c.label}
`)}
- ${c?o`
+ ${p?o`
- Compare against (constant)
- {let d=parseInt(l.target.value,10);Number.isFinite(d)&&d>=0&&d<=65535&&i({arg2Ix:d})}}
- />
- `:""}
-
`}_renderStructuredArg1Picker(e,t,i){let r=this._bucketWithPreserve(this._pickBucket(t),t,e.arg1Ix),s=t[0].toUpperCase()+t.slice(1);return o`
+ Arg2 type
+ {let d=parseInt(c.target.value,10),f=U(d),v=d===0?e.arg2Ix:this._defaultIxForKind(f),F=d===0?0:(Y[d]??[{value:0}])[0].value;i({arg2Type:d,arg2Ix:v,arg2Field:F})}}>
+ ${X.map(c=>o`
+
+ ${c.label}
+ `)}
+
+
+
+ ${e.arg2Type===0?o`
+
+ Constant
+ {let d=parseInt(c.target.value,10);Number.isFinite(d)&&d>=0&&d<=65535&&i({arg2Ix:d})}}
+ />
+ `:""}
+
+ ${l?this._renderStructuredObjectPicker(l,e.arg2Ix,c=>i({arg2Ix:c}),"Arg2"):""}
+
+ ${e.arg2Type!==0&&u.length>0?o`
+
+ Arg2 field
+ i({arg2Field:parseInt(c.target.value,10)})}>
+ ${u.map(c=>o`
+
+ ${c.label}
+ `)}
+
+ `:""}
+ `:""}
+ `}_defaultIxForKind(e){switch(e){case"zone":return this._objects?.zones?.[0]?.index??1;case"unit":return this._objects?.units?.[0]?.index??1;case"thermostat":return this._objects?.thermostats?.[0]?.index??1;case"area":return this._objects?.areas?.[0]?.index??1;default:return 0}}_renderStructuredObjectPicker(e,t,i,r){let s=this._bucketWithPreserve(this._pickBucket(e),e,t),u=e[0].toUpperCase()+e.slice(1);return o`
- ${s}
- i({arg1Ix:parseInt(c.target.value,10)})}>
- ${r.map(c=>o`
-
- #${c.index} ${c.name}
+ ${r} ${u}
+ i(parseInt(l.target.value,10))}>
+ ${s.map(l=>o`
+
+ #${l.index} ${l.name}
`)}
- `}_renderChainCondFamily(e,t){let i=s=>{let c=this._objects?.zones?.[0]?.index??1,l=this._objects?.units?.[0]?.index??1,d=this._objects?.areas?.[0]?.index??1,p;switch(s){case"none":p={family:"none"};break;case"misc":p={family:"misc",misc:1};break;case"zone":p={family:"zone",index:c,active:!1};break;case"unit":p={family:"unit",index:l,active:!0};break;case"time":p={family:"time",index:1,active:!0};break;case"sec":p={family:"sec",index:d,mode:0};break}let u=ve(p);this._patchChainCondition(t,u)},r=s=>{this._patchChainCondition(t,ve(s))};return o`
+ `}_renderChainCondFamily(e,t){let i=s=>{let u=this._objects?.zones?.[0]?.index??1,l=this._objects?.units?.[0]?.index??1,p=this._objects?.areas?.[0]?.index??1,c;switch(s){case"none":c={family:"none"};break;case"misc":c={family:"misc",misc:1};break;case"zone":c={family:"zone",index:u,active:!1};break;case"unit":c={family:"unit",index:l,active:!0};break;case"time":c={family:"time",index:1,active:!0};break;case"sec":c={family:"sec",index:p,mode:0};break}let d=$e(c);this._patchChainCondition(t,d)},r=s=>{this._patchChainCondition(t,$e(s))};return o`
Family
i(s.target.value)}>
@@ -812,7 +837,7 @@ var it=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var m=(a,n,e
Mode
t({...e,mode:parseInt(r.target.value,10)})}>
- ${fe.map(r=>o`
+ ${_e.map(r=>o`
${r.label}
`)}
@@ -835,7 +860,7 @@ var it=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var m=(a,n,e
Condition
t({family:"misc",misc:parseInt(i.target.value,10)})}>
- ${ge.map(i=>o`
+ ${ve.map(i=>o`
${i.label}
`)}
@@ -849,7 +874,7 @@ var it=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var m=(a,n,e
${e.map((t,i)=>this._renderChainActionRow(t,i,e.length))}
- `}_renderChainActionRow(e,t,i){let r=N(e.cmd??0),s=r?.ref_kind?this._bucketWithPreserve(this._pickBucket(r.ref_kind),r.ref_kind,e.pr2??0):null,c=e.cmd===9;return o`
+ `}_renderChainActionRow(e,t,i){let r=j(e.cmd??0),s=r?.ref_kind?this._bucketWithPreserve(this._pickBucket(r.ref_kind),r.ref_kind,e.pr2??0):null,u=e.cmd===9;return o`
Command
- {let d=parseInt(l.target.value,10),p=N(d),u=e.pr2??0;if(p?.ref_kind&&this._objects){let f=this._pickBucket(p.ref_kind);f&&f.length>0&&!f.some(_=>_.index===u)&&(u=f[0].index)}else p?.ref_kind||(u=0);this._patchChainAction(t,{cmd:d,pr2:u})}}>
- ${G.map(l=>o`
+ {let p=parseInt(l.target.value,10),c=j(p),d=e.pr2??0;if(c?.ref_kind&&this._objects){let f=this._pickBucket(c.ref_kind);f&&f.length>0&&!f.some(v=>v.index===d)&&(d=f[0].index)}else c?.ref_kind||(d=0);this._patchChainAction(t,{cmd:p,pr2:d})}}>
+ ${K.map(l=>o`
${l.label}
`)}
@@ -869,23 +894,23 @@ var it=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var m=(a,n,e
${r?.ref_kind?o`
${r.ref_kind[0].toUpperCase()+r.ref_kind.slice(1)}
- {let d=parseInt(l.target.value,10);Number.isFinite(d)&&this._patchChainAction(t,{pr2:d})}}>
+ {let p=parseInt(l.target.value,10);Number.isFinite(p)&&this._patchChainAction(t,{pr2:p})}}>
${(s??[]).map(l=>o`
#${l.index} ${l.name}
`)}
`:""}
- ${c?o`
+ ${u?o`
Level (0..100)
{let d=parseInt(l.target.value,10);Number.isFinite(d)&&d>=0&&d<=100&&this._patchChainAction(t,{par:d})}}
+ @input=${l=>{let p=parseInt(l.target.value,10);Number.isFinite(p)&&p>=0&&p<=100&&this._patchChainAction(t,{par:p})}}
/>
`:""}
- `}};h.styles=J`
+ `}};h.styles=ee`
:host {
display: block;
min-height: 100vh;
@@ -1283,7 +1308,7 @@ var it=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var m=(a,n,e
background: var(--secondary-background-color, #f5f5f5);
border-radius: 4px;
}
- `,m([H({attribute:!1})],h.prototype,"hass",2),m([H({attribute:!1})],h.prototype,"narrow",2),m([g()],h.prototype,"_entryId",2),m([g()],h.prototype,"_rows",2),m([g()],h.prototype,"_total",2),m([g()],h.prototype,"_filteredTotal",2),m([g()],h.prototype,"_loading",2),m([g()],h.prototype,"_error",2),m([g()],h.prototype,"_activeTriggerTypes",2),m([g()],h.prototype,"_referenceFilter",2),m([g()],h.prototype,"_searchTerm",2),m([g()],h.prototype,"_selectedSlot",2),m([g()],h.prototype,"_detail",2),m([g()],h.prototype,"_detailLoading",2),m([g()],h.prototype,"_fireFeedback",2),m([g()],h.prototype,"_writeFeedback",2),m([g()],h.prototype,"_cloneTargetSlot",2),m([g()],h.prototype,"_showCloneInput",2),m([g()],h.prototype,"_confirmingClear",2),m([g()],h.prototype,"_editingDraft",2),m([g()],h.prototype,"_objects",2),m([g()],h.prototype,"_chainDraft",2),h=m([je("omni-panel-programs")],h);export{h as OmniPanelPrograms};
+ `,m([N({attribute:!1})],h.prototype,"hass",2),m([N({attribute:!1})],h.prototype,"narrow",2),m([g()],h.prototype,"_entryId",2),m([g()],h.prototype,"_rows",2),m([g()],h.prototype,"_total",2),m([g()],h.prototype,"_filteredTotal",2),m([g()],h.prototype,"_loading",2),m([g()],h.prototype,"_error",2),m([g()],h.prototype,"_activeTriggerTypes",2),m([g()],h.prototype,"_referenceFilter",2),m([g()],h.prototype,"_searchTerm",2),m([g()],h.prototype,"_selectedSlot",2),m([g()],h.prototype,"_detail",2),m([g()],h.prototype,"_detailLoading",2),m([g()],h.prototype,"_fireFeedback",2),m([g()],h.prototype,"_writeFeedback",2),m([g()],h.prototype,"_cloneTargetSlot",2),m([g()],h.prototype,"_showCloneInput",2),m([g()],h.prototype,"_confirmingClear",2),m([g()],h.prototype,"_editingDraft",2),m([g()],h.prototype,"_objects",2),m([g()],h.prototype,"_chainDraft",2),h=m([je("omni-panel-programs")],h);export{h as OmniPanelPrograms};
/*! Bundled license information:
@lit/reactive-element/css-tag.js:
diff --git a/dev/artifacts/screenshots/2026-05-17/arg2-object-editor.png b/dev/artifacts/screenshots/2026-05-17/arg2-object-editor.png
new file mode 100644
index 0000000..a5ada69
Binary files /dev/null and b/dev/artifacts/screenshots/2026-05-17/arg2-object-editor.png differ
diff --git a/dev/screenshot_arg2_object.py b/dev/screenshot_arg2_object.py
new file mode 100644
index 0000000..ee9e5cf
--- /dev/null
+++ b/dev/screenshot_arg2_object.py
@@ -0,0 +1,150 @@
+#!/usr/bin/env python3
+"""Focused screenshot of the structured-AND Arg2-as-object editor.
+
+Drives an already-onboarded HA at localhost:8123, opens the side panel,
+clicks into the chain at slot 200, hits Edit, and snaps the form.
+"""
+
+from __future__ import annotations
+
+import argparse
+import asyncio
+import json
+import sys
+from datetime import datetime
+from pathlib import Path
+
+import httpx
+from playwright.async_api import async_playwright
+
+HA_URL = "http://localhost:8123"
+USERNAME = "demo"
+PASSWORD = "demo-password-1234"
+
+
+async def _login_token() -> str:
+ async with httpx.AsyncClient(base_url=HA_URL, timeout=30) as c:
+ r = await c.post(
+ "/auth/login_flow",
+ json={
+ "client_id": HA_URL,
+ "handler": ["homeassistant", None],
+ "redirect_uri": HA_URL,
+ },
+ )
+ flow_id = r.json()["flow_id"]
+ r = await c.post(
+ f"/auth/login_flow/{flow_id}",
+ json={
+ "username": USERNAME,
+ "password": PASSWORD,
+ "client_id": HA_URL,
+ },
+ )
+ code = r.json()["result"]
+ r = await c.post(
+ "/auth/token",
+ data={
+ "client_id": HA_URL,
+ "grant_type": "authorization_code",
+ "code": code,
+ },
+ )
+ return r.json()["access_token"]
+
+
+FIND_PANEL = """
+ (() => {
+ function find(root, depth=0) {
+ if (!root || depth > 15) return null;
+ if (root.tagName === 'OMNI-PANEL-PROGRAMS') return root;
+ for (const k of Array.from(root.children || [])) {
+ const r = find(k, depth+1);
+ if (r) return r;
+ }
+ if (root.shadowRoot) {
+ const r = find(root.shadowRoot, depth+1);
+ if (r) return r;
+ }
+ return null;
+ }
+ return find(document.body);
+ })()
+"""
+
+
+async def amain(outdir: Path) -> None:
+ token = await _login_token()
+ outdir.mkdir(parents=True, exist_ok=True)
+ async with async_playwright() as p:
+ browser = await p.chromium.launch()
+ context = await browser.new_context(viewport={"width": 1400, "height": 900})
+ await context.add_init_script(f"""
+ window.localStorage.setItem(
+ 'hassTokens',
+ JSON.stringify({{
+ access_token: '{token}',
+ token_type: 'Bearer',
+ refresh_token: '',
+ expires: Date.now() + 3600000,
+ hassUrl: '{HA_URL}',
+ clientId: '{HA_URL}',
+ }})
+ );
+ window.localStorage.setItem('selectedTheme', JSON.stringify({{dark: false}}));
+ """)
+ page = await context.new_page()
+
+ page.on("console", lambda m: print(f" [browser] {m.type}: {m.text}"))
+
+ await page.goto(f"{HA_URL}/omni-panel-programs", wait_until="domcontentloaded")
+ await page.wait_for_timeout(6000)
+
+ # Click the chain row (slot 200).
+ ok = await page.evaluate(f"""() => {{
+ const panel = {FIND_PANEL};
+ if (!panel) return 'no-panel';
+ const rows = Array.from(panel.shadowRoot.querySelectorAll('.row'));
+ const target = rows.find(r => r.textContent.includes('200'));
+ if (!target) return 'no-row-200 ' + rows.map(r => r.textContent.slice(0,40)).join(' | ');
+ target.click();
+ return 'clicked';
+ }}""")
+ print(f" row-click: {ok}")
+ await page.wait_for_timeout(800)
+
+ # Click Edit.
+ ok = await page.evaluate(f"""() => {{
+ const panel = {FIND_PANEL};
+ if (!panel) return 'no-panel';
+ const buttons = panel.shadowRoot.querySelectorAll('.detail button');
+ for (const b of buttons) {{
+ if (b.textContent.trim() === 'Edit') {{ b.click(); return 'clicked'; }}
+ }}
+ return 'no-edit-button';
+ }}""")
+ print(f" edit-click: {ok}")
+ await page.wait_for_timeout(1500)
+
+ path = outdir / "arg2-object-editor.png"
+ await page.screenshot(path=str(path), full_page=True)
+ print(f" wrote {path}")
+
+ await browser.close()
+
+
+def main() -> int:
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--outdir",
+ type=Path,
+ default=Path(__file__).parent / "artifacts" / "screenshots" /
+ datetime.now().strftime("%Y-%m-%d"),
+ )
+ args = parser.parse_args()
+ asyncio.run(amain(args.outdir))
+ return 0
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())