@camstack/types 1.2.548 → 1.2.550

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/addon/addon-instance.d.ts +24 -0
  3. package/dist/addon/build-addon-route-provider.d.ts +2 -0
  4. package/dist/addon.js +5 -5
  5. package/dist/addon.mjs +5 -5
  6. package/dist/automation/index.d.ts +4 -3
  7. package/dist/automation/recipe.d.ts +12105 -604
  8. package/dist/automation/scheduler.d.ts +7 -0
  9. package/dist/automation/step-runner.d.ts +70 -0
  10. package/dist/automation/trace.d.ts +252 -145
  11. package/dist/automation/wait-until.d.ts +32 -0
  12. package/dist/automation/when-site.d.ts +1 -1
  13. package/dist/capabilities/accessories.cap.d.ts +1 -1
  14. package/dist/capabilities/actions.cap.d.ts +1 -178
  15. package/dist/capabilities/addon-routes.cap.d.ts +3 -0
  16. package/dist/capabilities/battery.cap.d.ts +2 -2
  17. package/dist/capabilities/capability-definition.d.ts +47 -1
  18. package/dist/capabilities/climate-control.cap.d.ts +8 -1
  19. package/dist/capabilities/core-blocks.cap.d.ts +119 -8723
  20. package/dist/capabilities/customize-catalog.d.ts +3 -1
  21. package/dist/capabilities/customize-spec.d.ts +26 -2
  22. package/dist/capabilities/device-manager.cap.d.ts +6 -0
  23. package/dist/capabilities/event-emitter.cap.d.ts +99 -3
  24. package/dist/capabilities/event-vocabulary.d.ts +99 -0
  25. package/dist/capabilities/fan-control.cap.d.ts +248 -0
  26. package/dist/capabilities/fan-presets.cap.d.ts +172 -536
  27. package/dist/capabilities/group-active.cap.d.ts +1 -1
  28. package/dist/capabilities/group-commands.cap.d.ts +1 -1
  29. package/dist/capabilities/group-status.cap.d.ts +1 -1
  30. package/dist/capabilities/heating-valve.cap.d.ts +1 -1
  31. package/dist/capabilities/hero-layout.cap.d.ts +2 -0
  32. package/dist/capabilities/humidifier.cap.d.ts +5 -0
  33. package/dist/capabilities/humidity-sensor.cap.d.ts +1 -1
  34. package/dist/capabilities/index.d.ts +5 -4
  35. package/dist/capabilities/media-player.cap.d.ts +7 -0
  36. package/dist/capabilities/oauth-integration.cap.d.ts +8 -0
  37. package/dist/capabilities/pet-fountain.cap.d.ts +5 -0
  38. package/dist/capabilities/power-meter.cap.d.ts +5 -5
  39. package/dist/capabilities/power-source.cap.d.ts +5 -0
  40. package/dist/capabilities/running-state.cap.d.ts +2 -2
  41. package/dist/capabilities/schedulers.cap.d.ts +1 -178
  42. package/dist/capabilities/sso-bridge.cap.d.ts +3 -0
  43. package/dist/capabilities/switch.cap.d.ts +1 -1
  44. package/dist/capabilities/temperature-sensor.cap.d.ts +1 -1
  45. package/dist/capabilities/timed-run.cap.d.ts +19 -5
  46. package/dist/capabilities/user-management.cap.d.ts +4 -0
  47. package/dist/capabilities/water-heater.cap.d.ts +7 -0
  48. package/dist/client.js +7 -11
  49. package/dist/client.mjs +7 -11
  50. package/dist/{composed-stable-id-DrGLxjVF.js → composed-stable-id-CDNLq7Y8.js} +27 -10
  51. package/dist/{composed-stable-id-DFNyOFzz.mjs → composed-stable-id-CPp3votu.mjs} +27 -10
  52. package/dist/composition/composition-report.d.ts +6 -0
  53. package/dist/composition/evaluate-field.d.ts +7 -0
  54. package/dist/composition/field-kinds.d.ts +12 -1
  55. package/dist/composition/helpers/index.d.ts +1 -1
  56. package/dist/composition/helpers/source-pick.d.ts +0 -5
  57. package/dist/composition/power-source-link.d.ts +15 -0
  58. package/dist/composition/state-fields.d.ts +2 -0
  59. package/dist/composition/validate-composition.d.ts +15 -1
  60. package/dist/device/base-device-provider.d.ts +13 -0
  61. package/dist/device/device-control-resolution.d.ts +1 -33
  62. package/dist/device/device-kind.d.ts +36 -0
  63. package/dist/device/device-management.d.ts +3 -0
  64. package/dist/device/device-type.d.ts +27 -10
  65. package/dist/device/hero/hero-fragment.d.ts +2 -0
  66. package/dist/device/hero/hero-layout.d.ts +1 -3
  67. package/dist/device/hero/hero-look.d.ts +18 -12
  68. package/dist/device/hero/hero-scene.d.ts +9 -3
  69. package/dist/device/index.d.ts +2 -1
  70. package/dist/device/power-switch.d.ts +82 -0
  71. package/dist/device/schema-fields.d.ts +10 -1
  72. package/dist/generated/addon-api.d.ts +7 -0
  73. package/dist/generated/addon-cap-facts.d.ts +1 -1
  74. package/dist/generated/cap-input-defaults.d.ts +1 -1
  75. package/dist/generated/collection-array-methods.d.ts +1 -1
  76. package/dist/generated/customize-catalog.d.ts +257 -8
  77. package/dist/generated/method-access-map.d.ts +1 -1
  78. package/dist/generated/method-device-selectors.d.ts +1 -1
  79. package/dist/{implemented-methods-M5aguGon.mjs → implemented-methods-5YMDeE3f.mjs} +1 -1
  80. package/dist/{implemented-methods-8AU92riC.js → implemented-methods-Cj65uy2F.js} +1 -1
  81. package/dist/index.d.ts +11 -6
  82. package/dist/index.js +2386 -494
  83. package/dist/index.mjs +2312 -488
  84. package/dist/interfaces/addon-routes.d.ts +13 -0
  85. package/dist/interfaces/config-ui.d.ts +15 -24
  86. package/dist/node.js +2 -2
  87. package/dist/node.mjs +2 -2
  88. package/dist/{sleep-D_NpiLFP.mjs → sleep-D0roI_CZ.mjs} +50 -1
  89. package/dist/{sleep-vzHEmsrO.js → sleep-dcR4vBFG.js} +50 -1
  90. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sleep = require("./sleep-vzHEmsrO.js");
2
+ const require_sleep = require("./sleep-dcR4vBFG.js");
3
3
  const require_event_category = require("./event-category-BC4RRerT.js");
4
- const require_composed_stable_id = require("./composed-stable-id-DrGLxjVF.js");
5
- const require_implemented_methods = require("./implemented-methods-8AU92riC.js");
4
+ const require_composed_stable_id = require("./composed-stable-id-CDNLq7Y8.js");
5
+ const require_implemented_methods = require("./implemented-methods-Cj65uy2F.js");
6
6
  const require_node_color = require("./node-color.js");
7
7
  const require_convert = require("./convert-BmtM6K-5.js");
8
8
  const require_enums = require("./enums.js");
@@ -461,6 +461,7 @@ function buildAddonRouteProvider(id, routes) {
461
461
  query: input.query,
462
462
  body: input.body,
463
463
  headers: input.headers,
464
+ ...match.route.perInstance === true && input.instanceId !== void 0 ? { instanceId: input.instanceId } : {},
464
465
  ...input.user ? { user: input.user } : {},
465
466
  ...input.scopedToken !== void 0 ? { scopedToken: input.scopedToken } : {}
466
467
  };
@@ -529,6 +530,36 @@ function buildCapturingReply(envelope) {
529
530
  return wrapper;
530
531
  }
531
532
  //#endregion
533
+ //#region src/addon/addon-instance.ts
534
+ /**
535
+ * The integration instance of an addon, as it appears in an address or on an
536
+ * OAuth link (planning#415, D1046).
537
+ *
538
+ * The DEFAULT instance has two spellings on the wire and one in the code: a
539
+ * path with no instance segment and a link with no instance both mean it, and
540
+ * its id is the addon id. {@link oauthLinkServesInstance} is the one
541
+ * comparison a per-instance route is meant to call, so nobody compares
542
+ * `undefined` with an id. Nothing calls it yet: no route declares
543
+ * `perInstance` (the Alexa per-instance route, T3, is the first consumer).
544
+ */
545
+ /** An instance id as it may appear in a path or a query: no separator, no escape, bounded. */
546
+ var ADDON_INSTANCE_ID_RE = /^[A-Za-z0-9._-]{1,64}$/;
547
+ function isAddonInstanceId(value) {
548
+ return ADDON_INSTANCE_ID_RE.test(value);
549
+ }
550
+ /** The instance a link was made for, with the default one spelled as the addon id. */
551
+ function oauthLinkInstanceId(link, addonId) {
552
+ return link.instanceId ?? addonId;
553
+ }
554
+ /**
555
+ * True when a verified link may be used on a request addressed to
556
+ * `requestInstanceId` (`AddonHttpRequest.instanceId`, absent on a route that
557
+ * is not per-instance, which is the default instance).
558
+ */
559
+ function oauthLinkServesInstance(link, requestInstanceId, addonId) {
560
+ return oauthLinkInstanceId(link, addonId) === (requestInstanceId ?? addonId);
561
+ }
562
+ //#endregion
532
563
  //#region src/addon/session-health.ts
533
564
  var SESSION_LOST_ALERT_CATEGORY = "integration.session-lost";
534
565
  var SESSION_EPISODE_KEY = "session-lost";
@@ -31187,16 +31218,39 @@ function metaQuantity(schema) {
31187
31218
  function quantityOfField(schema) {
31188
31219
  return metaQuantity(schema) ?? metaQuantity(unwrapSchema(schema));
31189
31220
  }
31221
+ function scalarKind(schema) {
31222
+ const s = unwrapSchema(schema);
31223
+ if (s instanceof zod.z.ZodNumber) return "number";
31224
+ if (s instanceof zod.z.ZodString) return "string";
31225
+ if (s instanceof zod.z.ZodBoolean) return "boolean";
31226
+ return null;
31227
+ }
31228
+ /** A union is a leaf only when EVERY member is a scalar; one object or array member keeps it out. */
31229
+ function unionMembersOf(s) {
31230
+ const members = [];
31231
+ for (const option of s.options) {
31232
+ if (!(option instanceof zod.z.ZodType)) return null;
31233
+ const kind = scalarKind(option);
31234
+ if (kind === null) return null;
31235
+ if (!members.includes(kind)) members.push(kind);
31236
+ }
31237
+ return members.length > 0 ? members : null;
31238
+ }
31190
31239
  function leafKind(schema) {
31191
31240
  const s = unwrapSchema(schema);
31192
31241
  if (s instanceof zod.z.ZodEnum) return {
31193
31242
  kind: "enum",
31194
31243
  enumValues: s.options
31195
31244
  };
31196
- if (s instanceof zod.z.ZodNumber) return { kind: "number" };
31197
- if (s instanceof zod.z.ZodString) return { kind: "string" };
31198
- if (s instanceof zod.z.ZodBoolean) return { kind: "boolean" };
31199
- return null;
31245
+ if (s instanceof zod.z.ZodUnion) {
31246
+ const members = unionMembersOf(s);
31247
+ return members === null ? null : {
31248
+ kind: "union",
31249
+ unionMembers: members
31250
+ };
31251
+ }
31252
+ const scalar = scalarKind(s);
31253
+ return scalar === null ? null : { kind: scalar };
31200
31254
  }
31201
31255
  /** Walk a cap status schema into flat wireable leaf fields (dotted paths).
31202
31256
  * Recurses into nested ZodObject (unwrapping nullable/optional/default first),
@@ -31221,6 +31275,7 @@ function enumerateSchemaFields(schema, prefix = "") {
31221
31275
  path,
31222
31276
  kind: leaf.kind,
31223
31277
  ...leaf.enumValues ? { enumValues: leaf.enumValues } : {},
31278
+ ...leaf.unionMembers ? { unionMembers: leaf.unionMembers } : {},
31224
31279
  ...quantity !== void 0 ? { quantity } : {}
31225
31280
  });
31226
31281
  }
@@ -33391,9 +33446,12 @@ function convertLegacyWhen(half) {
33391
33446
  * every caller — automations, Actions, and the notification centre, which runs
33392
33447
  * only Actions (planning#473).
33393
33448
  */
33449
+ /** The longest one `wait` step lasts. It is cut by a restart of the run and does not survive a hub restart. */
33450
+ var WAIT_MAX_SECONDS = 3600;
33451
+ var WAIT_TOO_LONG = `a wait is at most one hour (${WAIT_MAX_SECONDS} s)`;
33394
33452
  var AutomationWaitStepSchema = zod.z.object({
33395
33453
  kind: zod.z.literal("wait"),
33396
- seconds: zod.z.number().min(0).max(300)
33454
+ seconds: zod.z.number().min(0).max(WAIT_MAX_SECONDS, WAIT_TOO_LONG)
33397
33455
  });
33398
33456
  /** The legacy `deviceId` of a cap step: still READ, never written (D983). */
33399
33457
  var LegacyStepDeviceSchema = zod.z.union([
@@ -33523,20 +33581,224 @@ var ActionStepSchema = zod.z.discriminatedUnion("kind", [GuardedWaitStepSchema,
33523
33581
  path: ["if"]
33524
33582
  });
33525
33583
  });
33584
+ /**
33585
+ * Flow control of an AUTOMATION's list (#500). A standalone list (an action, a
33586
+ * scheduler point, a preset) stays `wait` and `cap`: it has no run of its own
33587
+ * to end and no variable bag to write.
33588
+ */
33589
+ var continueOnErrorShape = {
33590
+ /** A failure of this step is traced `failed-continued` and the next step runs. */
33591
+ continueOnError: zod.z.literal(true).optional() };
33592
+ /** An automation's cap step: the shared guarded cap step, plus `continueOnError`. */
33593
+ var AutomationGuardedCapStepSchema = AutomationCapStepBaseSchema.extend({
33594
+ ...stepGuardShape,
33595
+ ...continueOnErrorShape
33596
+ }).refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
33597
+ message: "a cap step needs a target",
33598
+ path: ["target"]
33599
+ }).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
33600
+ message: "a domain target needs the vocabulary action it applies to (actionId)",
33601
+ path: ["actionId"]
33602
+ }).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
33603
+ var STOP_REASON_MAX = 200;
33604
+ /** End the run here, on purpose. `reason` may carry `{{vars.x}}` slots. */
33605
+ var AutomationStopStepSchema = zod.z.object({
33606
+ kind: zod.z.literal("stop"),
33607
+ reason: zod.z.string().min(1, "a stop needs a reason: it is what the run trace shows").max(200),
33608
+ /** `ok`: the run ends as a success. `failed`: it ends as a failure, with the reason. */
33609
+ outcome: zod.z.enum(["ok", "failed"]),
33610
+ /** Stop only when this reads true; false or unknown does not stop. */
33611
+ if: AutomationWhenSchema.optional()
33612
+ });
33613
+ var SET_VARS_MAX = 20;
33614
+ var SET_VAR_VALUE_MAX = 500;
33615
+ var SET_VAR_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]{0,39}$/;
33616
+ /** Names the run itself writes and reads (`leaf` is what `triggered-by` judges): a step may not overwrite them. */
33617
+ var RESERVED_RUN_VARS = [
33618
+ "kind",
33619
+ "leaf",
33620
+ "at"
33621
+ ];
33622
+ /**
33623
+ * Write variables into the run's bag, for the steps after it. SUBSTITUTION
33624
+ * only, never evaluation: a text value may carry `{{vars.x}}` slots.
33625
+ */
33626
+ var AutomationSetStepSchema = zod.z.object({
33627
+ kind: zod.z.literal("set"),
33628
+ vars: zod.z.record(zod.z.string(), zod.z.union([
33629
+ zod.z.string().max(500),
33630
+ zod.z.number(),
33631
+ zod.z.boolean()
33632
+ ])).refine((vars) => Object.keys(vars).every((name) => SET_VAR_NAME_RE.test(name)), { message: "a variable name is letters, digits and _, not starting with a digit (max 40)" }).refine((vars) => Object.keys(vars).length >= 1, { message: "set needs at least one variable" }).refine((vars) => Object.keys(vars).length <= 20, { message: `set holds at most 20 variables` }).refine((vars) => Object.keys(vars).every((name) => !RESERVED_RUN_VARS.includes(name)), { message: `the names ${RESERVED_RUN_VARS.join(", ")} belong to the run and cannot be set` }),
33633
+ /** Set only when this reads true; false or unknown leaves the bag as it is. */
33634
+ if: AutomationWhenSchema.optional()
33635
+ });
33636
+ var AutomationRunActionStepSchema = zod.z.object({
33637
+ kind: zod.z.literal("action"),
33638
+ /** An entry of the `actions` surface (`internal:<uuid>` or `<addonId>:<localId>`). */
33639
+ actionId: zod.z.string().min(1),
33640
+ /** Values for the action's declared variables; the others take their default. */
33641
+ variables: zod.z.record(zod.z.string(), zod.z.union([
33642
+ zod.z.string(),
33643
+ zod.z.number(),
33644
+ zod.z.boolean()
33645
+ ])).optional(),
33646
+ ...continueOnErrorShape
33647
+ });
33648
+ /** How many branches one `choose` holds. */
33649
+ var CHOOSE_BRANCHES_MAX = 6;
33650
+ /**
33651
+ * A step INSIDE a branch of a `choose`: a flow step with no condition of its
33652
+ * own (the branch is the condition) and no block inside it. Strict, so an `if`
33653
+ * written on such a step is refused rather than dropped.
33654
+ */
33655
+ /** The longest a `wait-until` may wait: six hours. */
33656
+ var WAIT_UNTIL_TIMEOUT_MAX_S = 21600;
33657
+ /**
33658
+ * Pause the run until a condition is true (#500). The timeout is mandatory: a
33659
+ * run never waits without an end. `onTimeout` says what a wait that ran out
33660
+ * does: `continue` goes on to the next step, `stop` ends the run as a failure.
33661
+ * A condition that cannot be read is not "true": the wait goes on (D49).
33662
+ */
33663
+ var AutomationWaitUntilStepSchema = zod.z.object({
33664
+ kind: zod.z.literal("wait-until"),
33665
+ when: AutomationWhenSchema,
33666
+ timeoutS: zod.z.number().int().min(1, "a wait needs a timeout of at least one second").max(WAIT_UNTIL_TIMEOUT_MAX_S, `a wait for a condition is at most six hours (${WAIT_UNTIL_TIMEOUT_MAX_S} s)`),
33667
+ onTimeout: zod.z.enum(["continue", "stop"])
33668
+ }).strict();
33669
+ /** The step kinds that hold steps of their own, or pause on a condition: they nest two levels at most. */
33670
+ var BLOCK_STEP_KINDS = [
33671
+ "choose",
33672
+ "repeat",
33673
+ "parallel",
33674
+ "wait-until"
33675
+ ];
33676
+ var STEP_NEST_MAX = 2;
33677
+ var NEST_TOO_DEEP = `steps nest two levels at most: a step inside a nested choose or repeat can be a plain step only`;
33678
+ function kindOf(input) {
33679
+ return typeof input === "object" && input !== null ? Reflect.get(input, "kind") : void 0;
33680
+ }
33681
+ /** Where the nesting ends, a block step is refused in words rather than as an unknown kind. */
33682
+ function nestTooDeep(issue) {
33683
+ const kind = kindOf(issue.input);
33684
+ return typeof kind === "string" && BLOCK_STEP_KINDS.includes(kind) ? NEST_TOO_DEEP : void 0;
33685
+ }
33686
+ var plainStepSchemas = [
33687
+ AutomationWaitStepSchema.strict(),
33688
+ AutomationCapStepBaseSchema.extend(continueOnErrorShape).strict().refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
33689
+ message: "a cap step needs a target",
33690
+ path: ["target"]
33691
+ }).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
33692
+ message: "a domain target needs the vocabulary action it applies to (actionId)",
33693
+ path: ["actionId"]
33694
+ }),
33695
+ AutomationStopStepSchema.omit({ if: true }).strict(),
33696
+ AutomationSetStepSchema.omit({ if: true }).strict(),
33697
+ AutomationRunActionStepSchema.strict()
33698
+ ];
33699
+ /**
33700
+ * A plain step: a flow step with no condition of its own and no step inside
33701
+ * it. The second (last) level of nesting holds these only.
33702
+ */
33703
+ var AutomationBranchStepSchema = zod.z.discriminatedUnion("kind", plainStepSchemas, { error: nestTooDeep });
33704
+ var PARALLEL_STEPS_MIN = 2;
33705
+ var PARALLEL_STEPS_MAX = 5;
33706
+ /** A step that can run beside others: it writes no variable and does not end the run. */
33707
+ var AutomationParallelMemberSchema = AutomationBranchStepSchema.refine((step) => step.kind === "cap" || step.kind === "action" || step.kind === "wait", "a parallel holds device commands, actions and waits only: a set or a stop beside other steps has no order");
33708
+ /**
33709
+ * Several steps at once (#500): all are started together and all are awaited.
33710
+ * A failure fails the run once the others finished, as in a sequence; a member
33711
+ * marked "continue if this fails" does not.
33712
+ */
33713
+ var AutomationParallelStepSchema = zod.z.object({
33714
+ kind: zod.z.literal("parallel"),
33715
+ steps: zod.z.array(AutomationParallelMemberSchema).min(2, "a parallel needs at least two steps").max(5, `a parallel takes at most 5 steps`)
33716
+ }).strict();
33717
+ var REPEAT_COUNT_MAX = 20;
33718
+ var REPEAT_ITERATIONS_MAX = 50;
33719
+ var REPEAT_STEPS_MAX = 10;
33720
+ var REPEAT_DEVICES_MAX = 50;
33721
+ /** The run variable a loop over devices writes before each iteration: the device id. */
33722
+ var REPEAT_ITEM_VAR = "item";
33723
+ var REPEAT_NEEDS_MAX = "a repeat on a condition needs a maximum number of iterations";
33724
+ /** A loop on a condition: the bound is mandatory, so a run never loops without an end. */
33725
+ var repeatConditionShape = {
33726
+ when: AutomationWhenSchema,
33727
+ maxIterations: zod.z.number({ error: REPEAT_NEEDS_MAX }).int().min(1, REPEAT_NEEDS_MAX).max(50, `a repeat on a condition runs at most 50 times`),
33728
+ /** A pause between two iterations, never after the last. */
33729
+ waitS: zod.z.number().int().min(1).max(WAIT_MAX_SECONDS, WAIT_TOO_LONG).optional()
33730
+ };
33731
+ /** What decides how many times a `repeat` runs. */
33732
+ var AutomationRepeatLoopSchema = zod.z.discriminatedUnion("by", [
33733
+ zod.z.object({
33734
+ by: zod.z.literal("count"),
33735
+ count: zod.z.number().int().min(1).max(20, `a repeat runs at most 20 times`)
33736
+ }).strict(),
33737
+ zod.z.object({
33738
+ by: zod.z.literal("while"),
33739
+ ...repeatConditionShape
33740
+ }).strict(),
33741
+ zod.z.object({
33742
+ by: zod.z.literal("until"),
33743
+ ...repeatConditionShape
33744
+ }).strict(),
33745
+ zod.z.object({
33746
+ by: zod.z.literal("forEach"),
33747
+ target: zod.z.object({
33748
+ kind: zod.z.literal("devices"),
33749
+ ids: zod.z.array(zod.z.number().int()).min(1, "a repeat over devices needs at least one device").max(50, `a repeat over devices takes at most 50 devices`)
33750
+ }).strict()
33751
+ }).strict()
33752
+ ]);
33753
+ /**
33754
+ * The same steps several times (#500). Every form is bounded at save, so a
33755
+ * run cannot loop without an end. A failure or a `stop` in the steps ends the
33756
+ * loop and the run, as in a sequence.
33757
+ */
33758
+ function repeatSchemaOf(step) {
33759
+ return zod.z.object({
33760
+ kind: zod.z.literal("repeat"),
33761
+ loop: AutomationRepeatLoopSchema,
33762
+ steps: zod.z.array(step).min(1, "a repeat needs at least one step").max(10, `a repeat takes at most 10 steps`)
33763
+ }).strict();
33764
+ }
33765
+ /**
33766
+ * One step, several ways (#500): the branches are read in order and the FIRST
33767
+ * whose condition is true runs; `else` runs when every branch is false. A
33768
+ * branch that cannot be read ends the choice: nothing runs, not the branches
33769
+ * after it and not the else (D49). The #472 `if` / `else` of a wait or cap
33770
+ * step is the one-branch case and stays as it is stored.
33771
+ */
33772
+ function chooseSchemaOf(step) {
33773
+ const steps = zod.z.array(step).max(10);
33774
+ return zod.z.object({
33775
+ kind: zod.z.literal("choose"),
33776
+ branches: zod.z.array(zod.z.object({
33777
+ if: AutomationWhenSchema,
33778
+ steps: steps.min(1, "a branch needs at least one step")
33779
+ })).min(1, "a choose needs at least one branch").max(6, `a choose takes at most 6 branches`),
33780
+ else: steps.optional()
33781
+ });
33782
+ }
33783
+ var AutomationBodyStepSchema = zod.z.discriminatedUnion("kind", [
33784
+ ...plainStepSchemas,
33785
+ AutomationWaitUntilStepSchema,
33786
+ AutomationParallelStepSchema,
33787
+ chooseSchemaOf(AutomationBranchStepSchema),
33788
+ repeatSchemaOf(AutomationBranchStepSchema)
33789
+ ]);
33790
+ var AutomationRepeatStepSchema = repeatSchemaOf(AutomationBodyStepSchema);
33791
+ var AutomationChooseStepSchema = chooseSchemaOf(AutomationBodyStepSchema);
33526
33792
  var AutomationActionSchema = zod.z.discriminatedUnion("kind", [
33527
33793
  GuardedWaitStepSchema,
33528
- GuardedCapStepSchema,
33529
- zod.z.object({
33530
- kind: zod.z.literal("action"),
33531
- /** An entry of the `actions` surface (`internal:<uuid>` or `<addonId>:<localId>`). */
33532
- actionId: zod.z.string().min(1),
33533
- /** Values for the action's declared variables; the others take their default. */
33534
- variables: zod.z.record(zod.z.string(), zod.z.union([
33535
- zod.z.string(),
33536
- zod.z.number(),
33537
- zod.z.boolean()
33538
- ])).optional()
33539
- }),
33794
+ AutomationGuardedCapStepSchema,
33795
+ AutomationStopStepSchema,
33796
+ AutomationSetStepSchema,
33797
+ AutomationChooseStepSchema,
33798
+ AutomationWaitUntilStepSchema,
33799
+ AutomationParallelStepSchema,
33800
+ AutomationRepeatStepSchema,
33801
+ AutomationRunActionStepSchema,
33540
33802
  zod.z.object({
33541
33803
  kind: zod.z.literal("code"),
33542
33804
  /** Compiled into the automation's OWN block by esbuild — not a third
@@ -33602,12 +33864,47 @@ function convertLegacyRecipe(legacy) {
33602
33864
  ...rest
33603
33865
  };
33604
33866
  }
33605
- /**
33606
- * Where recipes are PARSED (the core-blocks cap, the MCP tool, the literal a
33607
- * saved block carries): the new shape as it is, or the old shape converted to
33608
- * it. The output type is always the new one.
33609
- */
33610
33867
  var AutomationRecipeSchema = zod.z.union([CurrentAutomationRecipeSchema, LegacyAutomationRecipeSchema.transform(convertLegacyRecipe)]);
33868
+ /** The `if` of a step that can carry one (`action`, `code`, `choose` and `wait-until` steps cannot). */
33869
+ function stepGuardOf(action) {
33870
+ switch (action.kind) {
33871
+ case "action":
33872
+ case "code":
33873
+ case "choose":
33874
+ case "wait-until":
33875
+ case "parallel":
33876
+ case "repeat": return;
33877
+ default: return action.if;
33878
+ }
33879
+ }
33880
+ /** Every condition of a step: its own `if`, or the `if` of each branch of a `choose`. */
33881
+ function stepConditionsOf(action) {
33882
+ const under = (prefix, steps) => steps.flatMap((step, at) => stepConditionsOf(step).map((ref) => ({
33883
+ ...ref,
33884
+ path: `${prefix}.${at}.${ref.path}`
33885
+ })));
33886
+ if (action.kind === "choose") return [...action.branches.flatMap((branch, i) => [{
33887
+ path: `branches.${i}.if`,
33888
+ when: branch.if
33889
+ }, ...under(`branches.${i}.steps`, branch.steps)]), ...under("else", action.else ?? [])];
33890
+ if (action.kind === "wait-until") return [{
33891
+ path: "when",
33892
+ when: action.when
33893
+ }];
33894
+ if (action.kind === "repeat") return [...action.loop.by === "while" || action.loop.by === "until" ? [{
33895
+ path: "loop.when",
33896
+ when: action.loop.when
33897
+ }] : [], ...under("steps", action.steps)];
33898
+ const when = stepGuardOf(action);
33899
+ return when === void 0 ? [] : [{
33900
+ path: "if",
33901
+ when
33902
+ }];
33903
+ }
33904
+ /** Every step a block step holds, at both levels, in the order they are written; none for a plain step. */
33905
+ function nestedStepsOf(action) {
33906
+ return (action.kind === "parallel" || action.kind === "repeat" ? action.steps : action.kind === "choose" ? [...action.branches.flatMap((branch) => branch.steps), ...action.else ?? []] : []).flatMap((step) => [step, ...nestedStepsOf(step)]);
33907
+ }
33611
33908
  /** Bounds, shared by `when` and the old names the guards still know. */
33612
33909
  var MAX_CONDITION_DEPTH = 4;
33613
33910
  var MAX_CONDITION_LEAVES = 32;
@@ -33623,9 +33920,8 @@ function validateRecipeBounds(recipe) {
33623
33920
  const ids = new Set(identifiedEventLeaves(recipe.when).map((entry) => entry.id));
33624
33921
  const inRules = triggeredByIssue(recipe.when, ids, "the rules");
33625
33922
  if (inRules !== null) return inRules;
33626
- for (const [index, action] of recipe.actions.entries()) {
33627
- if (action.kind !== "wait" && action.kind !== "cap" || action.if === void 0) continue;
33628
- const issue = triggeredByIssue(action.if, ids, `step ${index + 1}`);
33923
+ for (const [index, action] of recipe.actions.entries()) for (const condition of stepConditionsOf(action)) {
33924
+ const issue = triggeredByIssue(condition.when, ids, `step ${index + 1}`);
33629
33925
  if (issue !== null) return issue;
33630
33926
  }
33631
33927
  return null;
@@ -34401,6 +34697,12 @@ function stepMetaOf(action) {
34401
34697
  case "wait": return { kind: "wait" };
34402
34698
  case "code": return { kind: "code" };
34403
34699
  case "action": return { kind: "action" };
34700
+ case "stop": return { kind: "stop" };
34701
+ case "wait-until": return { kind: "wait-until" };
34702
+ case "parallel": return { kind: "parallel" };
34703
+ case "repeat": return { kind: "repeat" };
34704
+ case "set": return { kind: "set" };
34705
+ case "choose": return { kind: "choose" };
34404
34706
  case "cap": {
34405
34707
  const { target, actionId } = normalizeCapStep(action);
34406
34708
  return {
@@ -34621,42 +34923,15 @@ function emitLeaf(trigger, path) {
34621
34923
  }`;
34622
34924
  }
34623
34925
  }
34624
- /** The body of a wait or cap step, shared by a top-level step and an else step. */
34625
- function emitLeafBody(action) {
34926
+ /** What a plain step does when it runs: the body of its `run`, wherever the step sits. */
34927
+ function emitStepBody(action) {
34626
34928
  switch (action.kind) {
34627
34929
  case "wait": return ` await sleep(${j(action.seconds * 1e3)})`;
34628
34930
  case "cap": {
34629
34931
  const { target, actionId } = normalizeCapStep(action);
34630
34932
  return ` await actuateTarget(scope, ${j(target)}, ${j(actionId)}, ${j(action.cap)}, ${j(action.method)}, ${j(action.args ?? {})}, vars)`;
34631
34933
  }
34632
- default: return null;
34633
- }
34634
- }
34635
- /** A step's `if` (#472) and its else list, as the fields of a RunnableStep. */
34636
- function emitGuard(action, index) {
34637
- if (action.kind !== "wait" && action.kind !== "cap") return "";
34638
- if (action.if === void 0) return "";
34639
- const otherwise = (action.else ?? []).map((el) => {
34640
- const body = emitLeafBody(el);
34641
- return `{ meta: ${j(stepMetaOf(el))}, run: async (scope) => {\n${body ?? ""}\n } }`;
34642
- }).join(", ");
34643
- return ` guard: () => evaluateCondition(${j(action.if)}, ${j(`actions.${index}.if`)}, vars),${otherwise === "" ? "" : `\n otherwise: [${otherwise}],`}
34644
- `;
34645
- }
34646
- function emitAction(action, index) {
34647
- const step = (body) => ` {
34648
- meta: STEP_META[${index}]!,
34649
- ${emitGuard(action, index)} run: async (scope) => {
34650
- ${body}
34651
- },
34652
- },`;
34653
- switch (action.kind) {
34654
- case "wait": return step(` await sleep(${j(action.seconds * 1e3)})`);
34655
- case "cap": {
34656
- const { target, actionId } = normalizeCapStep(action);
34657
- return step(` await actuateTarget(scope, ${j(target)}, ${j(actionId)}, ${j(action.cap)}, ${j(action.method)}, ${j(action.args ?? {})}, vars)`);
34658
- }
34659
- case "action": return step(` // an Action run, awaited: the step takes THAT run's outcome
34934
+ case "action": return ` // an Action run, awaited: the step takes THAT run's outcome
34660
34935
  const result = await ctx.api.actions.run.mutate({
34661
34936
  actionId: ${j(action.actionId)},
34662
34937
  variables: substituteVariables(${j(action.variables ?? {})}, vars),
@@ -34665,13 +34940,153 @@ ${body}
34665
34940
  })
34666
34941
  if (result.outcome !== 'ran') {
34667
34942
  throw new Error('action ' + ${j(action.actionId)} + ' ' + result.outcome + (result.message === undefined ? '' : ': ' + result.message))
34668
- }`);
34669
- case "code": return step(` // inline code action — a fragment of THIS block, bundled by esbuild
34943
+ }`;
34944
+ case "stop": return ` // end the run here, on purpose: the steps after it are not-run with this reason
34945
+ scope.stop(String(substitute(${j(action.reason)}, vars)), ${j(action.outcome)})`;
34946
+ case "set": return ` // write the run's own bag, for the steps after this one — substitution only
34947
+ Object.assign(vars, substituteVariables(${j(action.vars)}, vars))`;
34948
+ case "code": return ` // inline code action — a fragment of THIS block, bundled by esbuild
34670
34949
  await (async () => {
34671
34950
  ${action.code.split("\n").map((line) => ` ${line}`).join("\n")}
34672
- })()`);
34951
+ })()`;
34952
+ }
34953
+ }
34954
+ function continues(action) {
34955
+ return (action.kind === "cap" || action.kind === "action") && action.continueOnError === true;
34956
+ }
34957
+ /** Whether the site is inside a block step: the automation's own steps sit at `actions.<n>`. */
34958
+ function isNestedSite(site) {
34959
+ return site.path.split(".").length > 2;
34960
+ }
34961
+ /** A list of steps under `path` (a branch, an else list, the steps of a repeat or a parallel). */
34962
+ function emitList(steps, path) {
34963
+ return steps.map((step, at) => emitStep(step, {
34964
+ meta: j(stepMetaOf(step)),
34965
+ path: `${path}.${at}`
34966
+ })).join("\n");
34967
+ }
34968
+ /** A step's `if` (#472) and its else list, as the fields of a RunnableStep. */
34969
+ function emitGuard(action, site) {
34970
+ const when = stepGuardOf(action);
34971
+ if (when === void 0) return "";
34972
+ const otherwise = emitList(action.kind === "wait" || action.kind === "cap" ? action.else ?? [] : [], `${site.path}.else`);
34973
+ return ` guard: () => evaluateCondition(${j(when)}, ${j(`${site.path}.if`)}, vars),${otherwise === "" ? "" : `\n otherwise: [\n${otherwise}\n],`}
34974
+ `;
34975
+ }
34976
+ /** A `choose` step: its branches, each a condition and a list, and its else list. */
34977
+ function emitChoose(action, site) {
34978
+ const branches = action.branches.map((branch, b) => ` {
34979
+ guard: () => evaluateCondition(${j(branch.if)}, ${j(`${site.path}.branches.${b}.if`)}, vars),
34980
+ steps: [
34981
+ ${emitList(branch.steps, `${site.path}.branches.${b}.steps`)}
34982
+ ],
34983
+ },`).join("\n");
34984
+ const otherwise = emitList(action.else ?? [], `${site.path}.else`);
34985
+ return ` {
34986
+ meta: ${site.meta},
34987
+ // a choose step: the runner reads the branches in order and runs the first that is true
34988
+ run: async () => {},
34989
+ choose: {
34990
+ branches: [
34991
+ ${branches}
34992
+ ],${otherwise === "" ? "" : `\n otherwise: [\n${otherwise}\n],`}
34993
+ },
34994
+ },`;
34995
+ }
34996
+ /** The devices whose report can change a tree's answer; null when one is named by a stable id (any report wakes it). */
34997
+ function wakeDevicesOf(when) {
34998
+ const ids = [];
34999
+ for (const source of collectWhenMirrorSources(when)) {
35000
+ if (source.kind !== "device") return null;
35001
+ if (!ids.includes(source.deviceId)) ids.push(source.deviceId);
35002
+ }
35003
+ return ids;
35004
+ }
35005
+ /** A `wait-until` step: read the condition, wait for a wake, read again, until the timeout. */
35006
+ function emitWaitUntil(action, site) {
35007
+ const onTimeout = action.onTimeout === "stop" ? `scope.stop(message, 'failed')` : "scope.markTimedOut(message)";
35008
+ return ` {
35009
+ meta: ${site.meta},
35010
+ run: async (scope) => {
35011
+ // woken by a report of one of its devices, by the reconcile tick, or by a restart
35012
+ const waited = await waitUntil({
35013
+ read: () => evaluateCondition(${j(action.when)}, ${j(`${site.path}.when`)}, vars),
35014
+ timeoutMs: ${j(action.timeoutS * 1e3)},
35015
+ now: () => Date.now(),
35016
+ isAborted: () => token.aborted,
35017
+ nextWake: (ms) => waitForWake(ms, token, ${j(wakeDevicesOf(action.when))}),
35018
+ })
35019
+ if (waited.result === 'timed-out') {
35020
+ const message = waitTimedOutMessage(${j(action.timeoutS)}, waited.lastReason)
35021
+ ctx.logger.info('wait-until timed out', { step: ${j(site.path)}, onTimeout: ${j(action.onTimeout)}, reason: waited.lastReason })
35022
+ ${onTimeout}
35023
+ }
35024
+ },
35025
+ },`;
35026
+ }
35027
+ /** How a `repeat` decides its iterations, as the fields of a RunnableRepeat. */
35028
+ function emitRepeatLoop(loop, site) {
35029
+ switch (loop.by) {
35030
+ case "count": return `limit: ${j(loop.count)}, limitIsTimeout: false,`;
35031
+ case "forEach": return `// once per device: the device id is in vars.${REPEAT_ITEM_VAR} for the steps of that iteration
35032
+ limit: ${j(loop.target.ids.length)}, limitIsTimeout: false,
35033
+ ...(() => {
35034
+ const ids = ${j(loop.target.ids)}
35035
+ let outer: unknown
35036
+ return {
35037
+ before: async (iteration) => {
35038
+ if (iteration === 0) outer = vars[${j(REPEAT_ITEM_VAR)}]
35039
+ if (iteration < ids.length) vars[${j(REPEAT_ITEM_VAR)}] = ids[iteration]
35040
+ else if (${j(isNestedSite(site))} && outer !== undefined) vars[${j(REPEAT_ITEM_VAR)}] = outer
35041
+ return { go: true }
35042
+ },
35043
+ }
35044
+ })(),`;
35045
+ case "while":
35046
+ case "until": {
35047
+ const read = `repeatCheck(${j(loop.by)}, await evaluateCondition(${j(loop.when)}, ${j(`${site.path}.loop.when`)}, vars))`;
35048
+ const pause = loop.waitS === void 0 ? "" : `\n between: () => sleep(${j(loop.waitS * 1e3)}),`;
35049
+ return `limit: ${j(loop.maxIterations)}, limitIsTimeout: true,
35050
+ ${loop.by === "while" ? "before" : "after"}: async () => ${read},${pause}`;
35051
+ }
34673
35052
  }
34674
35053
  }
35054
+ /** One step, wherever it sits: a block step emits its own steps one level down, under its path. */
35055
+ function emitStep(action, site) {
35056
+ if (action.kind === "repeat") return ` {
35057
+ meta: ${site.meta},
35058
+ // a repeat step: the runner runs these once per iteration, under the bound
35059
+ run: async () => {},
35060
+ repeat: {
35061
+ steps: [
35062
+ ${emitList(action.steps, `${site.path}.steps`)}
35063
+ ],
35064
+ ${emitRepeatLoop(action.loop, site)}
35065
+ },
35066
+ },`;
35067
+ if (action.kind === "choose") return emitChoose(action, site);
35068
+ if (action.kind === "wait-until") return emitWaitUntil(action, site);
35069
+ if (action.kind === "parallel") return ` {
35070
+ meta: ${site.meta},
35071
+ // a parallel step: the runner starts these together and awaits them all
35072
+ run: async () => {},
35073
+ parallel: [
35074
+ ${emitList(action.steps, `${site.path}.steps`)}
35075
+ ],
35076
+ },`;
35077
+ return ` {
35078
+ meta: ${site.meta},
35079
+ ${emitGuard(action, site)}${continues(action) ? " continueOnError: true,\n" : ""} run: async (scope) => {
35080
+ ${emitStepBody(action)}
35081
+ },
35082
+ },`;
35083
+ }
35084
+ function emitAction(action, index) {
35085
+ return emitStep(action, {
35086
+ meta: `STEP_META[${index}]!`,
35087
+ path: `actions.${index}`
35088
+ });
35089
+ }
34675
35090
  /**
34676
35091
  * Compile a recipe to the TypeScript of a core block.
34677
35092
  *
@@ -34685,12 +35100,18 @@ function generateAutomationBlock(input) {
34685
35100
  const { name, recipe } = input;
34686
35101
  const runMode = recipe.runMode ?? { mode: "single" };
34687
35102
  const stepMeta = recipe.actions.map(stepMetaOf);
34688
- const hasDomainTarget = recipe.actions.some((a) => a.kind === "cap" && normalizeCapStep(a).target.kind === "domain");
34689
- const guardHoldTrees = recipe.actions.flatMap((a, i) => (a.kind === "wait" || a.kind === "cap") && a.if !== void 0 && hasHoldLeaves(a.if) ? [{
34690
- path: `actions.${i}.if`,
34691
- when: a.if
34692
- }] : []);
34693
- const hasTime = hasTimeLeaves(recipe.when) || recipe.actions.some((a) => (a.kind === "wait" || a.kind === "cap") && a.if !== void 0 && hasTimeLeaves(a.if));
35103
+ const elseSteps = (a) => a.kind === "wait" || a.kind === "cap" ? a.else ?? [] : [];
35104
+ const hasDomainTarget = recipe.actions.flatMap((a) => [
35105
+ a,
35106
+ ...elseSteps(a),
35107
+ ...nestedStepsOf(a)
35108
+ ]).some((a) => a.kind === "cap" && normalizeCapStep(a).target.kind === "domain");
35109
+ const guardHoldTrees = recipe.actions.flatMap((a, i) => stepConditionsOf(a).flatMap(({ path, when }) => hasHoldLeaves(when) ? [{
35110
+ path: `actions.${i}.${path}`,
35111
+ when
35112
+ }] : []));
35113
+ const hasTime = hasTimeLeaves(recipe.when) || recipe.actions.some((a) => stepConditionsOf(a).some(({ when }) => hasTimeLeaves(when)));
35114
+ const hasWaitUntil = recipe.actions.some((a) => a.kind === "wait-until" || nestedStepsOf(a).some((n) => n.kind === "wait-until"));
34694
35115
  const eventLeaves = [];
34695
35116
  forEachLeaf(recipe.when, (leaf, path) => {
34696
35117
  if (isEventLeaf(leaf)) eventLeaves.push({
@@ -34739,6 +35160,9 @@ import {
34739
35160
  runForDevices,
34740
35161
  evaluateStepCondition,
34741
35162
  runSteps,
35163
+ repeatCheck,
35164
+ waitUntil,
35165
+ waitTimedOutMessage,
34742
35166
  siteFor,
34743
35167
  validateTimeSpecForSite,
34744
35168
  zoneOnlySite,
@@ -34866,7 +35290,8 @@ ${hasTime ? ` /** The site clock a \`time-is\` leaf reads: memory only at evalu
34866
35290
 
34867
35291
  interface RunToken {
34868
35292
  aborted: boolean
34869
- wake?: () => void
35293
+ /** What cuts short whatever the run is paused on; several at once inside a \`parallel\`. */
35294
+ readonly wakes: Set<() => void>
34870
35295
  }
34871
35296
  interface QueuedRun {
34872
35297
  readonly trigger: Record<string, unknown>
@@ -34877,11 +35302,29 @@ ${hasTime ? ` /** The site clock a \`time-is\` leaf reads: memory only at evalu
34877
35302
  /** Sleep that a restart can cut short. */
34878
35303
  const abortableSleep = (ms: number, token: RunToken): Promise<void> =>
34879
35304
  new Promise((resolve) => {
34880
- const timer = setTimeout(resolve, ms)
34881
- token.wake = () => {
35305
+ const done = (): void => {
35306
+ clearTimeout(timer)
35307
+ token.wakes.delete(done)
35308
+ resolve()
35309
+ }
35310
+ const timer = setTimeout(done, ms)
35311
+ token.wakes.add(done)
35312
+ })
35313
+
35314
+ /** The runs paused on a \`wait-until\`, each with the devices whose report wakes it (null = any). */
35315
+ const stateWaiters = new Map<() => void, readonly number[] | null>()
35316
+ /** Resolve at a report of one of \`deviceIds\`, at the reconcile tick, at a restart, or after \`ms\`. */
35317
+ const waitForWake = (ms: number, token: RunToken, deviceIds: readonly number[] | null): Promise<void> =>
35318
+ new Promise((resolve) => {
35319
+ const done = (): void => {
34882
35320
  clearTimeout(timer)
35321
+ stateWaiters.delete(done)
35322
+ token.wakes.delete(done)
34883
35323
  resolve()
34884
35324
  }
35325
+ const timer = setTimeout(done, Math.min(ms, RECONCILE_MS))
35326
+ stateWaiters.set(done, deviceIds)
35327
+ token.wakes.add(done)
34885
35328
  })
34886
35329
 
34887
35330
  // ── the hub's runs ledger: the stamp is read ONCE here, the ring is written through RPC ──
@@ -35209,6 +35652,13 @@ ${recipe.actions.map((a, i) => emitAction(a, i)).join("\n")}
35209
35652
  error: failure.message,
35210
35653
  })
35211
35654
  },
35655
+ onContinuedFailure: (failure) => {
35656
+ ctx.logger.warn('action failed — continuing, the step is marked to be passed over', {
35657
+ ...(failure.deviceId === undefined ? {} : { tags: { deviceId: failure.deviceId } }),
35658
+ step: failure.index,
35659
+ error: failure.message,
35660
+ })
35661
+ },
35212
35662
  onGuardUnknown: (skipped) => {
35213
35663
  ctx.logger.warn('step skipped — its condition could not be read', {
35214
35664
  ...(skipped.deviceId === undefined ? {} : { tags: { deviceId: skipped.deviceId } }),
@@ -35258,7 +35708,7 @@ ${recipe.actions.map((a, i) => emitAction(a, i)).join("\n")}
35258
35708
  reason: string,
35259
35709
  admission: AutomationRunVerdict,
35260
35710
  ): Promise<void> {
35261
- const token: RunToken = { aborted: false }
35711
+ const token: RunToken = { aborted: false, wakes: new Set() }
35262
35712
  runningTokens.add(token)
35263
35713
  const startedAt = Date.now()
35264
35714
  const runId = newRunId(startedAt)
@@ -35372,7 +35822,7 @@ ${recipe.actions.map((a, i) => emitAction(a, i)).join("\n")}
35372
35822
  ctx.logger.info('automation restarting — ' + admission.reason, deviceTags(trigger))
35373
35823
  for (const running of runningTokens) {
35374
35824
  running.aborted = true
35375
- running.wake?.()
35825
+ for (const wake of [...running.wakes]) wake()
35376
35826
  }
35377
35827
  break
35378
35828
  case 'run':
@@ -35431,6 +35881,16 @@ ${hasTime ? " await refreshSite()\n" : ""} await refreshMirror()
35431
35881
  disposers.push(() => clearInterval(mirrorReconcile))
35432
35882
  }
35433
35883
 
35884
+ ${hasWaitUntil ? ` // a paused run reads its condition again when one of its devices reports
35885
+ disposers.push(
35886
+ ctx.eventBus.subscribe({ category: EventCategory.DeviceStateChanged }, (event) => {
35887
+ const deviceId = event.data['deviceId']
35888
+ for (const [wake, deviceIds] of [...stateWaiters]) {
35889
+ if (deviceIds === null || (typeof deviceId === 'number' && deviceIds.includes(deviceId))) wake()
35890
+ }
35891
+ }),
35892
+ )
35893
+ ` : ""}
35434
35894
  ${eventLeaves.map(({ leaf, path }) => emitLeaf(leaf, path)).join("\n\n")}
35435
35895
 
35436
35896
  return () => {
@@ -35440,7 +35900,7 @@ ${eventLeaves.map(({ leaf, path }) => emitLeaf(leaf, path)).join("\n\n")}
35440
35900
  flushSkip()
35441
35901
  for (const running of runningTokens) {
35442
35902
  running.aborted = true
35443
- running.wake?.()
35903
+ for (const wake of [...running.wakes]) wake()
35444
35904
  }
35445
35905
  for (const dispose of disposers) dispose()
35446
35906
  }
@@ -35785,7 +36245,7 @@ function stepGuardSiteIssues(steps, reading, rootPath) {
35785
36245
  }
35786
36246
  /** The whole recipe: its `when` tree and every step guard. */
35787
36247
  function recipeSiteIssues(recipe, reading) {
35788
- return [...whenSiteIssues(recipe.when, reading), ...stepGuardSiteIssues(recipe.actions, reading, "actions")];
36248
+ return [...whenSiteIssues(recipe.when, reading), ...recipe.actions.flatMap((action, i) => stepConditionsOf(action).flatMap((condition) => whenSiteIssues(condition.when, reading, `actions.${i}.${condition.path}`)))];
35789
36249
  }
35790
36250
  //#endregion
35791
36251
  //#region src/automation/scheduler.ts
@@ -35844,12 +36304,23 @@ var DEFAULT_MAX_HOLD_ATTEMPTS = 3;
35844
36304
  var MAX_HOLD_ATTEMPTS_LIMIT = 20;
35845
36305
  /** A missed edge up to this late still runs. */
35846
36306
  var DEFAULT_MAX_LATE_MS = 10 * 6e4;
36307
+ /**
36308
+ * The longest one `wait` of a scheduler point lasts. A point's steps run in
36309
+ * the scheduler's one serial queue, with no run ceiling: a wait holds every
36310
+ * other scheduler's points for as long as it lasts. An action (one hour) has
36311
+ * its own run and ceiling; a point keeps the five minutes it always had.
36312
+ */
36313
+ var SCHEDULER_WAIT_MAX_SECONDS = 300;
36314
+ var SchedulerStepSchema = ActionStepSchema.refine((step) => step.kind !== "wait" || step.seconds <= 300, {
36315
+ message: `a scheduler point waits at most five minutes (300 s); put a longer wait in an action`,
36316
+ path: ["seconds"]
36317
+ });
35847
36318
  var SchedulerPointSchema = zod.z.object({
35848
36319
  id: zod.z.string().min(1).max(64),
35849
36320
  at: SchedulerTimeSpecSchema,
35850
36321
  mode: SchedulerPointModeSchema,
35851
36322
  /** The actions of an `edge` or `hold`; a `release` has none. */
35852
- steps: zod.z.array(ActionStepSchema).max(20).default([]),
36323
+ steps: zod.z.array(SchedulerStepSchema).max(20).default([]),
35853
36324
  /** Checked when the point runs (an edge) or is applied (a hold). */
35854
36325
  conditions: SchedulerStateTreeSchema.optional(),
35855
36326
  /** Hold only; absent means `respect`. */
@@ -36226,18 +36697,46 @@ var StepTraceBaseSchema = zod.z.object({
36226
36697
  ]).optional(),
36227
36698
  /** Why the condition read what it read, in the evaluator's own words. */
36228
36699
  conditionReason: zod.z.string().optional(),
36229
- /** `empty`: the target resolved to no device, so nothing was done — never silently `ok`. `skipped`: its `if` was false (or unknown) and nothing ran in its place. */
36700
+ /** `empty`: the target resolved to no device, so nothing was done — never silently `ok`. `skipped`: its `if` was false (or unknown) and nothing ran in its place. `failed-continued`: it failed and was marked to be passed over (#500). */
36230
36701
  outcome: zod.z.enum([
36231
36702
  "ok",
36232
36703
  "error",
36233
36704
  "not-run",
36234
36705
  "empty",
36235
- "skipped"
36706
+ "skipped",
36707
+ "failed-continued",
36708
+ "timed-out"
36236
36709
  ]),
36237
36710
  message: zod.z.string().optional()
36238
36711
  });
36712
+ /** What a block step adds to its row: which list ran, what each branch read, how many rounds. */
36713
+ var blockTraceShape = {
36714
+ /** A `choose` step (#500): the list that ran, `branches.<n>` or `else`. Absent when none did. */
36715
+ branch: zod.z.string().optional(),
36716
+ /** A `choose` step: what each branch read, in order, up to the one that decided. */
36717
+ branchChecks: zod.z.array(zod.z.object({
36718
+ condition: zod.z.enum([
36719
+ "true",
36720
+ "false",
36721
+ "unknown"
36722
+ ]),
36723
+ conditionReason: zod.z.string().optional()
36724
+ })).optional(),
36725
+ /** A `repeat` step (#500): how many times its steps ran. */
36726
+ iterations: zod.z.number().int().optional()
36727
+ };
36728
+ /** A step one level down: it may be a block step itself, whose own steps are plain rows (the nesting ends there). */
36729
+ var NestedStepTraceSchema = StepTraceBaseSchema.extend({
36730
+ ...blockTraceShape,
36731
+ steps: zod.z.array(StepTraceBaseSchema).optional()
36732
+ });
36239
36733
  /** A step trace; the `else` steps that ran are one level of the same shape (the nesting is bounded at one). */
36240
- var AutomationStepTraceSchema = StepTraceBaseSchema.extend({ else: zod.z.array(StepTraceBaseSchema).optional() });
36734
+ var AutomationStepTraceSchema = StepTraceBaseSchema.extend({
36735
+ else: zod.z.array(StepTraceBaseSchema).optional(),
36736
+ ...blockTraceShape,
36737
+ /** A `choose` step: the steps of the list that ran. A `parallel`: its members. A `repeat`: the LAST iteration. */
36738
+ steps: zod.z.array(NestedStepTraceSchema).optional()
36739
+ });
36241
36740
  var AutomationRunTraceSchema = zod.z.object({
36242
36741
  runId: zod.z.string().min(1),
36243
36742
  startedAt: zod.z.number(),
@@ -36640,6 +37139,46 @@ async function evaluateStepCondition(when, fetchers, now = Date.now, history, si
36640
37139
  }
36641
37140
  //#endregion
36642
37141
  //#region src/automation/step-runner.ts
37142
+ /**
37143
+ * Read the branches in order and stop at the first that decides: `true` runs
37144
+ * it, `unknown` ends the choice with nothing run (D49). All `false` runs the
37145
+ * else list, when there is one.
37146
+ */
37147
+ async function readChoose(choose) {
37148
+ const checks = [];
37149
+ for (const [index, branch] of choose.branches.entries()) {
37150
+ const verdict = await readGuard(branch.guard);
37151
+ checks.push({
37152
+ condition: verdict.result,
37153
+ conditionReason: verdict.reason
37154
+ });
37155
+ if (verdict.result === "true") return {
37156
+ checks,
37157
+ decision: {
37158
+ kind: "run",
37159
+ branch: `branches.${index}`,
37160
+ steps: branch.steps
37161
+ }
37162
+ };
37163
+ if (verdict.result === "unknown") return {
37164
+ checks,
37165
+ decision: {
37166
+ kind: "unknown",
37167
+ index,
37168
+ reason: verdict.reason
37169
+ }
37170
+ };
37171
+ }
37172
+ const otherwise = choose.otherwise ?? [];
37173
+ return {
37174
+ checks,
37175
+ decision: otherwise.length === 0 ? { kind: "none" } : {
37176
+ kind: "run",
37177
+ branch: "else",
37178
+ steps: otherwise
37179
+ }
37180
+ };
37181
+ }
36643
37182
  function errorMessage(err) {
36644
37183
  return err instanceof Error ? err.message : String(err);
36645
37184
  }
@@ -36654,17 +37193,125 @@ async function readGuard(guard) {
36654
37193
  };
36655
37194
  }
36656
37195
  }
37196
+ /**
37197
+ * What a loop's condition says about going on. A `while` goes on while it
37198
+ * reads true, an `until` goes on while it reads false; `unknown` ends either,
37199
+ * with the reason (D49): a loop never runs on a value it could not read.
37200
+ */
37201
+ function repeatCheck(by, verdict) {
37202
+ if (verdict.result === "unknown") return {
37203
+ go: false,
37204
+ reason: `the condition could not be read: ${verdict.reason}`,
37205
+ unknown: true
37206
+ };
37207
+ if (by === "while") return verdict.result === "true" ? { go: true } : {
37208
+ go: false,
37209
+ reason: "the condition is no longer true"
37210
+ };
37211
+ return verdict.result === "true" ? {
37212
+ go: false,
37213
+ reason: "the condition is true"
37214
+ } : { go: true };
37215
+ }
37216
+ /** A loop condition that throws ends the loop as unreadable, never a crash of the run. */
37217
+ async function readRepeatCheck(check, iteration) {
37218
+ if (check === void 0) return { go: true };
37219
+ try {
37220
+ return await check(iteration);
37221
+ } catch (err) {
37222
+ return {
37223
+ go: false,
37224
+ reason: `the condition could not be read: ${errorMessage(err)}`,
37225
+ unknown: true
37226
+ };
37227
+ }
37228
+ }
37229
+ /** Run a loop's steps until its count, its condition, its bound, a failure, a stop or an abort ends it. */
37230
+ async function runRepeat(repeat, options, path) {
37231
+ let iterations = 0;
37232
+ let last;
37233
+ for (;;) {
37234
+ if (options.isAborted()) return {
37235
+ iterations,
37236
+ last,
37237
+ timedOut: false
37238
+ };
37239
+ const before = await readRepeatCheck(repeat.before, iterations);
37240
+ if (!before.go) return {
37241
+ iterations,
37242
+ last,
37243
+ ended: before.reason,
37244
+ timedOut: false,
37245
+ ...before.unknown === true ? { unknown: before.reason } : {}
37246
+ };
37247
+ if (iterations >= repeat.limit) return repeat.limitIsTimeout ? {
37248
+ iterations,
37249
+ last,
37250
+ ended: `stopped at ${repeat.limit} iterations`,
37251
+ timedOut: true
37252
+ } : {
37253
+ iterations,
37254
+ last,
37255
+ ended: "",
37256
+ timedOut: false
37257
+ };
37258
+ last = await runSteps(repeat.steps, {
37259
+ ...options,
37260
+ pathPrefix: `${path}.steps`,
37261
+ indexOffset: 0
37262
+ });
37263
+ iterations += 1;
37264
+ if (last.failed || last.aborted || last.stopped !== void 0) return {
37265
+ iterations,
37266
+ last,
37267
+ timedOut: false
37268
+ };
37269
+ const after = await readRepeatCheck(repeat.after, iterations - 1);
37270
+ if (!after.go) return {
37271
+ iterations,
37272
+ last,
37273
+ ended: after.reason,
37274
+ timedOut: false,
37275
+ ...after.unknown === true ? { unknown: after.reason } : {}
37276
+ };
37277
+ if (repeat.between !== void 0 && iterations < repeat.limit) await repeat.between();
37278
+ }
37279
+ }
36657
37280
  /** The else level of a trace is one level deep: a nested trace carries no `else` of its own. */
36658
37281
  function withoutElse(trace) {
36659
37282
  const { else: _else, ...rest } = trace;
36660
37283
  return rest;
36661
37284
  }
37285
+ /** A plain row: the last level of a trace carries no list of its own. */
37286
+ function plainRow(trace) {
37287
+ const { else: _else, steps: _steps, ...rest } = trace;
37288
+ return rest;
37289
+ }
37290
+ /** A row one level down: it keeps its own steps as plain rows, and no `else`. */
37291
+ function withoutNested(trace) {
37292
+ const { else: _else, steps, ...rest } = trace;
37293
+ return steps === void 0 ? rest : {
37294
+ ...rest,
37295
+ steps: steps.map(plainRow)
37296
+ };
37297
+ }
36662
37298
  async function runSteps(steps, options) {
36663
37299
  const traces = [];
36664
37300
  let failed = false;
36665
37301
  let aborted = false;
36666
- for (const [index, step] of steps.entries()) {
37302
+ let stopped;
37303
+ for (const [position, step] of steps.entries()) {
37304
+ const index = position + (options.indexOffset ?? 0);
36667
37305
  const path = `${options.pathPrefix}.${index}`;
37306
+ if (stopped !== void 0) {
37307
+ traces.push({
37308
+ ...step.meta,
37309
+ path,
37310
+ outcome: "not-run",
37311
+ message: `stopped at ${stopped.path}: ${stopped.reason}`
37312
+ });
37313
+ continue;
37314
+ }
36668
37315
  if (failed || aborted || options.isAborted()) {
36669
37316
  if (!failed) aborted = true;
36670
37317
  traces.push({
@@ -36676,6 +37323,96 @@ async function runSteps(steps, options) {
36676
37323
  continue;
36677
37324
  }
36678
37325
  const startedAt = options.now();
37326
+ if (step.parallel !== void 0) {
37327
+ const members = await Promise.all(step.parallel.map((member, at) => runSteps([member], {
37328
+ ...options,
37329
+ pathPrefix: `${path}.steps`,
37330
+ indexOffset: at
37331
+ })));
37332
+ const anyFailed = members.some((m) => m.failed);
37333
+ if (anyFailed) failed = true;
37334
+ else if (members.some((m) => m.aborted)) aborted = true;
37335
+ traces.push({
37336
+ ...step.meta,
37337
+ path,
37338
+ startedAt,
37339
+ endedAt: options.now(),
37340
+ outcome: anyFailed ? "error" : "ok",
37341
+ ...anyFailed ? { message: "a parallel step failed" } : {},
37342
+ steps: members.flatMap((m) => m.steps.map(withoutNested))
37343
+ });
37344
+ continue;
37345
+ }
37346
+ if (step.repeat !== void 0) {
37347
+ const loop = await runRepeat(step.repeat, options, path);
37348
+ const sub = loop.last;
37349
+ if (loop.unknown !== void 0) options.onGuardUnknown?.({
37350
+ index,
37351
+ path: `${path}.loop.when`,
37352
+ reason: loop.unknown,
37353
+ deviceId: step.meta.deviceId
37354
+ });
37355
+ const bodyFailed = loop.ended === void 0 && sub?.failed === true;
37356
+ if (bodyFailed) failed = true;
37357
+ else if (loop.ended === void 0 && sub?.stopped !== void 0) stopped = sub.stopped;
37358
+ else if (loop.ended === void 0) aborted = true;
37359
+ const times = `ran ${loop.iterations} times`;
37360
+ const message = bodyFailed ? `a step failed in iteration ${loop.iterations}` : loop.ended === void 0 ? times : loop.timedOut ? loop.ended : loop.ended === "" ? times : `${times}: ${loop.ended}`;
37361
+ traces.push({
37362
+ ...step.meta,
37363
+ path,
37364
+ startedAt,
37365
+ endedAt: options.now(),
37366
+ outcome: bodyFailed ? "error" : loop.timedOut ? "timed-out" : "ok",
37367
+ message,
37368
+ iterations: loop.iterations,
37369
+ ...sub === void 0 ? {} : { steps: sub.steps.map(withoutNested) }
37370
+ });
37371
+ continue;
37372
+ }
37373
+ if (step.choose !== void 0) {
37374
+ const reading = await readChoose(step.choose);
37375
+ const base = {
37376
+ ...step.meta,
37377
+ path,
37378
+ startedAt,
37379
+ branchChecks: [...reading.checks]
37380
+ };
37381
+ const { decision } = reading;
37382
+ if (decision.kind !== "run") {
37383
+ if (decision.kind === "unknown") options.onGuardUnknown?.({
37384
+ index,
37385
+ path: `${path}.branches.${decision.index}.if`,
37386
+ reason: decision.reason,
37387
+ deviceId: step.meta.deviceId
37388
+ });
37389
+ traces.push({
37390
+ ...base,
37391
+ endedAt: options.now(),
37392
+ outcome: "skipped",
37393
+ message: decision.kind === "unknown" ? `not run: branch ${decision.index + 1} could not be read (${decision.reason})` : "not run: no branch is true"
37394
+ });
37395
+ continue;
37396
+ }
37397
+ const listPath = decision.branch === "else" ? `${path}.else` : `${path}.${decision.branch}.steps`;
37398
+ const sub = await runSteps(decision.steps, {
37399
+ ...options,
37400
+ pathPrefix: listPath,
37401
+ indexOffset: 0
37402
+ });
37403
+ if (sub.failed) failed = true;
37404
+ else if (sub.aborted) aborted = true;
37405
+ if (sub.stopped !== void 0) stopped = sub.stopped;
37406
+ traces.push({
37407
+ ...base,
37408
+ endedAt: options.now(),
37409
+ outcome: sub.failed ? "error" : "ok",
37410
+ ...sub.failed ? { message: "a step of the branch failed" } : {},
37411
+ branch: decision.branch,
37412
+ steps: sub.steps.map(withoutNested)
37413
+ });
37414
+ continue;
37415
+ }
36679
37416
  let guardTrace = {};
36680
37417
  if (step.guard !== void 0) {
36681
37418
  const verdict = await readGuard(step.guard);
@@ -36705,10 +37442,12 @@ async function runSteps(steps, options) {
36705
37442
  }
36706
37443
  const sub = await runSteps(branch, {
36707
37444
  ...options,
36708
- pathPrefix: `${path}.else`
37445
+ pathPrefix: `${path}.else`,
37446
+ indexOffset: 0
36709
37447
  });
36710
37448
  if (sub.failed) failed = true;
36711
37449
  else if (sub.aborted) aborted = true;
37450
+ if (sub.stopped !== void 0) stopped = sub.stopped;
36712
37451
  traces.push({
36713
37452
  ...step.meta,
36714
37453
  ...guardTrace,
@@ -36726,6 +37465,7 @@ async function runSteps(steps, options) {
36726
37465
  let sent;
36727
37466
  const perDevice = [];
36728
37467
  let emptyReason;
37468
+ let timedOutReason;
36729
37469
  let templateNotes = [];
36730
37470
  const scope = {
36731
37471
  setDeviceId: (id) => {
@@ -36742,6 +37482,16 @@ async function runSteps(steps, options) {
36742
37482
  },
36743
37483
  setTemplateNotes: (notes) => {
36744
37484
  templateNotes = notes.slice(0, 20);
37485
+ },
37486
+ stop: (reason, outcome) => {
37487
+ stopped = {
37488
+ reason,
37489
+ outcome,
37490
+ path
37491
+ };
37492
+ },
37493
+ markTimedOut: (reason) => {
37494
+ timedOutReason = reason;
36745
37495
  }
36746
37496
  };
36747
37497
  const templatesTrace = () => templateNotes.length === 0 ? {} : { templates: [...templateNotes] };
@@ -36749,6 +37499,29 @@ async function runSteps(steps, options) {
36749
37499
  const devicesTrace = () => perDevice.length === 0 ? {} : { devices: perDevice.slice(0, 200) };
36750
37500
  try {
36751
37501
  await step.run(scope);
37502
+ const stop = (() => stopped)();
37503
+ if (stop !== void 0) {
37504
+ const message = `stopped: ${stop.reason}`;
37505
+ if (stop.outcome === "failed") {
37506
+ failed = true;
37507
+ options.onFailure({
37508
+ index,
37509
+ path,
37510
+ message,
37511
+ deviceId
37512
+ });
37513
+ }
37514
+ traces.push({
37515
+ ...step.meta,
37516
+ ...guardTrace,
37517
+ path,
37518
+ startedAt,
37519
+ endedAt: options.now(),
37520
+ outcome: stop.outcome === "failed" ? "error" : "ok",
37521
+ message
37522
+ });
37523
+ continue;
37524
+ }
36752
37525
  traces.push({
36753
37526
  ...step.meta,
36754
37527
  ...deviceId === void 0 || perDevice.length > 1 ? {} : { deviceId },
@@ -36759,18 +37532,27 @@ async function runSteps(steps, options) {
36759
37532
  path,
36760
37533
  startedAt,
36761
37534
  endedAt: options.now(),
36762
- outcome: emptyReason === void 0 ? "ok" : "empty",
36763
- ...emptyReason === void 0 ? {} : { message: emptyReason }
37535
+ outcome: timedOutReason !== void 0 ? "timed-out" : emptyReason === void 0 ? "ok" : "empty",
37536
+ ...timedOutReason !== void 0 ? { message: timedOutReason } : emptyReason === void 0 ? {} : { message: emptyReason }
36764
37537
  });
36765
37538
  } catch (err) {
36766
- failed = true;
36767
37539
  const message = errorMessage(err);
36768
- options.onFailure({
37540
+ const continued = step.continueOnError === true;
37541
+ if (continued) options.onContinuedFailure?.({
36769
37542
  index,
36770
37543
  path,
36771
37544
  message,
36772
37545
  deviceId
36773
37546
  });
37547
+ else {
37548
+ failed = true;
37549
+ options.onFailure({
37550
+ index,
37551
+ path,
37552
+ message,
37553
+ deviceId
37554
+ });
37555
+ }
36774
37556
  traces.push({
36775
37557
  ...step.meta,
36776
37558
  ...deviceId === void 0 || perDevice.length > 1 ? {} : { deviceId },
@@ -36781,7 +37563,7 @@ async function runSteps(steps, options) {
36781
37563
  path,
36782
37564
  startedAt,
36783
37565
  endedAt: options.now(),
36784
- outcome: "error",
37566
+ outcome: continued ? "failed-continued" : "error",
36785
37567
  message
36786
37568
  });
36787
37569
  }
@@ -36789,7 +37571,8 @@ async function runSteps(steps, options) {
36789
37571
  return {
36790
37572
  steps: traces,
36791
37573
  failed,
36792
- aborted: aborted && !failed
37574
+ aborted: aborted && !failed,
37575
+ ...stopped === void 0 ? {} : { stopped }
36793
37576
  };
36794
37577
  }
36795
37578
  function isVarRef(value) {
@@ -37071,6 +37854,49 @@ function buildActionSteps(steps, vars, deps) {
37071
37854
  });
37072
37855
  }
37073
37856
  //#endregion
37857
+ //#region src/automation/wait-until.ts
37858
+ async function readSafely(read) {
37859
+ try {
37860
+ return await read();
37861
+ } catch (err) {
37862
+ return {
37863
+ result: "unknown",
37864
+ reason: err instanceof Error ? err.message : String(err)
37865
+ };
37866
+ }
37867
+ }
37868
+ async function waitUntil(input) {
37869
+ const startedAt = input.now();
37870
+ const deadline = startedAt + input.timeoutMs;
37871
+ for (;;) {
37872
+ const verdict = await readSafely(input.read);
37873
+ const waitedMs = input.now() - startedAt;
37874
+ if (input.isAborted()) return {
37875
+ result: "aborted",
37876
+ waitedMs
37877
+ };
37878
+ if (verdict.result === "true") return {
37879
+ result: "met",
37880
+ waitedMs
37881
+ };
37882
+ const remaining = deadline - input.now();
37883
+ if (remaining <= 0) return {
37884
+ result: "timed-out",
37885
+ waitedMs,
37886
+ lastReason: verdict.reason
37887
+ };
37888
+ await input.nextWake(remaining);
37889
+ if (input.isAborted()) return {
37890
+ result: "aborted",
37891
+ waitedMs: input.now() - startedAt
37892
+ };
37893
+ }
37894
+ }
37895
+ /** What the run trace says of a wait that ran out. */
37896
+ function waitTimedOutMessage(timeoutS, lastReason) {
37897
+ return `timed out after ${timeoutS} s: ${lastReason}`;
37898
+ }
37899
+ //#endregion
37074
37900
  //#region src/units/quantity-units.ts
37075
37901
  /**
37076
37902
  * Which units a person may pick for a number of a given quantity. The
@@ -37932,7 +38758,7 @@ var accessoriesCapability = {
37932
38758
  require_composed_stable_id.DeviceType.Switch,
37933
38759
  require_composed_stable_id.DeviceType.Light,
37934
38760
  require_composed_stable_id.DeviceType.Sensor,
37935
- require_composed_stable_id.DeviceType.Thermostat,
38761
+ require_composed_stable_id.DeviceType.Climate,
37936
38762
  require_composed_stable_id.DeviceType.Cover,
37937
38763
  require_composed_stable_id.DeviceType.Lock,
37938
38764
  require_composed_stable_id.DeviceType.Fan,
@@ -38243,7 +39069,9 @@ var AddonHttpRouteSchema = zod.z.object({
38243
39069
  ]).optional(),
38244
39070
  description: zod.z.string().optional(),
38245
39071
  /** The hub limits this route per client address before the handler runs. */
38246
- rateLimit: zod.z.enum(["auth"]).optional()
39072
+ rateLimit: zod.z.enum(["auth"]).optional(),
39073
+ /** Served once per integration instance; the handler reads `instanceId`. */
39074
+ perInstance: zod.z.boolean().optional()
38247
39075
  });
38248
39076
  /**
38249
39077
  * Cross-process route invocation envelope. The hub captures the
@@ -38260,6 +39088,8 @@ var InvokeRequestSchema = zod.z.object({
38260
39088
  query: zod.z.record(zod.z.string(), zod.z.string()),
38261
39089
  body: zod.z.unknown(),
38262
39090
  headers: zod.z.record(zod.z.string(), zod.z.string()),
39091
+ /** The instance the hub resolved for a `perInstance` route. */
39092
+ instanceId: zod.z.string().optional(),
38263
39093
  user: zod.z.object({
38264
39094
  id: zod.z.string(),
38265
39095
  username: zod.z.string(),
@@ -41061,7 +41891,7 @@ var BATTERY_DEVICE_TYPES = [
41061
41891
  require_composed_stable_id.DeviceType.Switch,
41062
41892
  require_composed_stable_id.DeviceType.PetFeeder,
41063
41893
  require_composed_stable_id.DeviceType.Container,
41064
- require_composed_stable_id.DeviceType.Thermostat,
41894
+ require_composed_stable_id.DeviceType.Climate,
41065
41895
  require_composed_stable_id.DeviceType.EventEmitter
41066
41896
  ];
41067
41897
  /** Generic Customize target for the percentage reading (D936). */
@@ -43332,7 +44162,14 @@ var climateControlCapability = {
43332
44162
  scope: "device",
43333
44163
  deviceNative: true,
43334
44164
  mode: "singleton",
43335
- deviceTypes: [require_composed_stable_id.DeviceType.Thermostat, require_composed_stable_id.DeviceType.Climate],
44165
+ deviceTypes: [require_composed_stable_id.DeviceType.Climate],
44166
+ power: {
44167
+ kind: "mode",
44168
+ field: "mode",
44169
+ offValue: "off",
44170
+ set: "setMode",
44171
+ lastField: "lastActiveMode"
44172
+ },
43336
44173
  methods: {
43337
44174
  setMode: require_sleep.method(zod.z.object({
43338
44175
  deviceId: zod.z.number().int().nonnegative(),
@@ -43752,7 +44589,8 @@ function describeStateField(schema, path) {
43752
44589
  kind: leaf.kind,
43753
44590
  nullable: field.safeParse(null).success,
43754
44591
  required: !field.safeParse(void 0).success,
43755
- ...leaf.enumValues === void 0 ? {} : { enumValues: leaf.enumValues }
44592
+ ...leaf.enumValues === void 0 ? {} : { enumValues: leaf.enumValues },
44593
+ ...leaf.unionMembers === void 0 ? {} : { unionMembers: leaf.unionMembers }
43756
44594
  };
43757
44595
  }
43758
44596
  function describeTopLevelStateFields(schema) {
@@ -43875,6 +44713,7 @@ var CompositionProblemCodeSchema = zod.z.enum([
43875
44713
  "nested-field",
43876
44714
  "missing-field",
43877
44715
  "kind-mismatch",
44716
+ "source-kind-mismatch",
43878
44717
  "may-be-null",
43879
44718
  "source-missing",
43880
44719
  "source-unreadable",
@@ -43896,7 +44735,8 @@ var CompositionProblemCodeSchema = zod.z.enum([
43896
44735
  "command-method-unknown",
43897
44736
  "command-source-unknown",
43898
44737
  "command-input-unknown",
43899
- "command-input-missing"
44738
+ "command-input-missing",
44739
+ "power-source-is-actuator"
43900
44740
  ]);
43901
44741
  /** One refusal, named (D391). `path` points into the composition, e.g. `features[0].fields.temperature`. */
43902
44742
  var CompositionProblemSchema = zod.z.object({
@@ -45071,6 +45911,13 @@ var mediaPlayerCapability = {
45071
45911
  deviceNative: true,
45072
45912
  mode: "singleton",
45073
45913
  deviceTypes: [require_composed_stable_id.DeviceType.MediaPlayer],
45914
+ power: {
45915
+ kind: "methods",
45916
+ field: "state",
45917
+ offValues: ["off", "standby"],
45918
+ on: "turnOn",
45919
+ off: "turnOff"
45920
+ },
45074
45921
  methods: {
45075
45922
  turnOn: require_sleep.optionalMethod(deviceOnly, zod.z.void(), {
45076
45923
  kind: "mutation",
@@ -45205,7 +46052,7 @@ var mediaPlayerCapability = {
45205
46052
  //#region src/generated/customize-catalog.ts
45206
46053
  /**
45207
46054
  * Customize catalog, projected from every `*.cap.ts` `customize` block.
45208
- * 10 caps. Field keys are `runtimeState` paths. No Zod.
46055
+ * 11 caps. Field keys are `runtimeState` paths. No Zod.
45209
46056
  */
45210
46057
  var CAP_CUSTOMIZE_CATALOG = {
45211
46058
  "battery": {
@@ -45220,7 +46067,7 @@ var CAP_CUSTOMIZE_CATALOG = {
45220
46067
  require_composed_stable_id.DeviceType.Switch,
45221
46068
  require_composed_stable_id.DeviceType.PetFeeder,
45222
46069
  require_composed_stable_id.DeviceType.Container,
45223
- require_composed_stable_id.DeviceType.Thermostat,
46070
+ require_composed_stable_id.DeviceType.Climate,
45224
46071
  require_composed_stable_id.DeviceType.EventEmitter
45225
46072
  ],
45226
46073
  apply: "add",
@@ -45276,7 +46123,6 @@ var CAP_CUSTOMIZE_CATALOG = {
45276
46123
  require_composed_stable_id.DeviceType.Siren,
45277
46124
  require_composed_stable_id.DeviceType.Switch,
45278
46125
  require_composed_stable_id.DeviceType.Sensor,
45279
- require_composed_stable_id.DeviceType.Thermostat,
45280
46126
  require_composed_stable_id.DeviceType.Climate,
45281
46127
  require_composed_stable_id.DeviceType.Button,
45282
46128
  require_composed_stable_id.DeviceType.EventEmitter,
@@ -45304,7 +46150,6 @@ var CAP_CUSTOMIZE_CATALOG = {
45304
46150
  require_composed_stable_id.DeviceType.PetFountain,
45305
46151
  require_composed_stable_id.DeviceType.Dishwasher,
45306
46152
  require_composed_stable_id.DeviceType.Washer,
45307
- require_composed_stable_id.DeviceType.Heater,
45308
46153
  require_composed_stable_id.DeviceType.Dryer,
45309
46154
  require_composed_stable_id.DeviceType.Gateway,
45310
46155
  require_composed_stable_id.DeviceType.HeatPump
@@ -45438,6 +46283,247 @@ var CAP_CUSTOMIZE_CATALOG = {
45438
46283
  debounceMs: 2e3
45439
46284
  }]
45440
46285
  },
46286
+ "fan-control": {
46287
+ version: 1,
46288
+ targets: [
46289
+ {
46290
+ id: "horizontal-oscillating",
46291
+ cardinality: "scalar",
46292
+ deviceTypes: [require_composed_stable_id.DeviceType.Fan],
46293
+ apply: "replace",
46294
+ vocabularyCap: "fan-control",
46295
+ vocabularyStateField: "oscillating",
46296
+ sources: [{
46297
+ kind: "switch",
46298
+ transformKinds: ["identity"],
46299
+ transforms: [{ kind: "identity" }]
46300
+ }],
46301
+ sourceReport: { status: "assignment-status" },
46302
+ advancedExpression: false,
46303
+ section: "oscillation-axes",
46304
+ path: "oscillationAxes.horizontal.oscillating",
46305
+ valueKind: "boolean",
46306
+ nullable: true
46307
+ },
46308
+ {
46309
+ id: "horizontal-angle",
46310
+ cardinality: "scalar",
46311
+ deviceTypes: [require_composed_stable_id.DeviceType.Fan],
46312
+ apply: "replace",
46313
+ vocabularyCap: "fan-control",
46314
+ sources: [{
46315
+ kind: "numeric",
46316
+ transformKinds: ["identity"],
46317
+ transforms: [{ kind: "identity" }]
46318
+ }],
46319
+ sourceReport: { status: "assignment-status" },
46320
+ advancedExpression: false,
46321
+ section: "oscillation-axes",
46322
+ path: "oscillationAxes.horizontal.angle",
46323
+ valueKind: "number",
46324
+ nullable: true,
46325
+ companions: [
46326
+ {
46327
+ kind: "source-field",
46328
+ path: "oscillationAxes.horizontal.min",
46329
+ field: "min"
46330
+ },
46331
+ {
46332
+ kind: "source-field",
46333
+ path: "oscillationAxes.horizontal.max",
46334
+ field: "max"
46335
+ },
46336
+ {
46337
+ kind: "source-field",
46338
+ path: "oscillationAxes.horizontal.step",
46339
+ field: "step"
46340
+ }
46341
+ ]
46342
+ },
46343
+ {
46344
+ id: "horizontal-sweepFrom",
46345
+ cardinality: "scalar",
46346
+ deviceTypes: [require_composed_stable_id.DeviceType.Fan],
46347
+ apply: "replace",
46348
+ vocabularyCap: "fan-control",
46349
+ sources: [{
46350
+ kind: "numeric",
46351
+ transformKinds: ["identity"],
46352
+ transforms: [{ kind: "identity" }]
46353
+ }],
46354
+ sourceReport: { status: "assignment-status" },
46355
+ advancedExpression: false,
46356
+ section: "oscillation-axes",
46357
+ path: "oscillationAxes.horizontal.sweepFrom",
46358
+ valueKind: "number",
46359
+ nullable: true
46360
+ },
46361
+ {
46362
+ id: "horizontal-sweepTo",
46363
+ cardinality: "scalar",
46364
+ deviceTypes: [require_composed_stable_id.DeviceType.Fan],
46365
+ apply: "replace",
46366
+ vocabularyCap: "fan-control",
46367
+ sources: [{
46368
+ kind: "numeric",
46369
+ transformKinds: ["identity"],
46370
+ transforms: [{ kind: "identity" }]
46371
+ }],
46372
+ sourceReport: { status: "assignment-status" },
46373
+ advancedExpression: false,
46374
+ section: "oscillation-axes",
46375
+ path: "oscillationAxes.horizontal.sweepTo",
46376
+ valueKind: "number",
46377
+ nullable: true
46378
+ },
46379
+ {
46380
+ id: "vertical-oscillating",
46381
+ cardinality: "scalar",
46382
+ deviceTypes: [require_composed_stable_id.DeviceType.Fan],
46383
+ apply: "replace",
46384
+ vocabularyCap: "fan-control",
46385
+ vocabularyStateField: "oscillating",
46386
+ sources: [{
46387
+ kind: "switch",
46388
+ transformKinds: ["identity"],
46389
+ transforms: [{ kind: "identity" }]
46390
+ }],
46391
+ sourceReport: { status: "assignment-status" },
46392
+ advancedExpression: false,
46393
+ section: "oscillation-axes",
46394
+ path: "oscillationAxes.vertical.oscillating",
46395
+ valueKind: "boolean",
46396
+ nullable: true
46397
+ },
46398
+ {
46399
+ id: "vertical-angle",
46400
+ cardinality: "scalar",
46401
+ deviceTypes: [require_composed_stable_id.DeviceType.Fan],
46402
+ apply: "replace",
46403
+ vocabularyCap: "fan-control",
46404
+ sources: [{
46405
+ kind: "numeric",
46406
+ transformKinds: ["identity"],
46407
+ transforms: [{ kind: "identity" }]
46408
+ }],
46409
+ sourceReport: { status: "assignment-status" },
46410
+ advancedExpression: false,
46411
+ section: "oscillation-axes",
46412
+ path: "oscillationAxes.vertical.angle",
46413
+ valueKind: "number",
46414
+ nullable: true,
46415
+ companions: [
46416
+ {
46417
+ kind: "source-field",
46418
+ path: "oscillationAxes.vertical.min",
46419
+ field: "min"
46420
+ },
46421
+ {
46422
+ kind: "source-field",
46423
+ path: "oscillationAxes.vertical.max",
46424
+ field: "max"
46425
+ },
46426
+ {
46427
+ kind: "source-field",
46428
+ path: "oscillationAxes.vertical.step",
46429
+ field: "step"
46430
+ }
46431
+ ]
46432
+ },
46433
+ {
46434
+ id: "vertical-sweepFrom",
46435
+ cardinality: "scalar",
46436
+ deviceTypes: [require_composed_stable_id.DeviceType.Fan],
46437
+ apply: "replace",
46438
+ vocabularyCap: "fan-control",
46439
+ sources: [{
46440
+ kind: "numeric",
46441
+ transformKinds: ["identity"],
46442
+ transforms: [{ kind: "identity" }]
46443
+ }],
46444
+ sourceReport: { status: "assignment-status" },
46445
+ advancedExpression: false,
46446
+ section: "oscillation-axes",
46447
+ path: "oscillationAxes.vertical.sweepFrom",
46448
+ valueKind: "number",
46449
+ nullable: true
46450
+ },
46451
+ {
46452
+ id: "vertical-sweepTo",
46453
+ cardinality: "scalar",
46454
+ deviceTypes: [require_composed_stable_id.DeviceType.Fan],
46455
+ apply: "replace",
46456
+ vocabularyCap: "fan-control",
46457
+ sources: [{
46458
+ kind: "numeric",
46459
+ transformKinds: ["identity"],
46460
+ transforms: [{ kind: "identity" }]
46461
+ }],
46462
+ sourceReport: { status: "assignment-status" },
46463
+ advancedExpression: false,
46464
+ section: "oscillation-axes",
46465
+ path: "oscillationAxes.vertical.sweepTo",
46466
+ valueKind: "number",
46467
+ nullable: true
46468
+ },
46469
+ {
46470
+ id: "preset",
46471
+ cardinality: "scalar",
46472
+ deviceTypes: [require_composed_stable_id.DeviceType.Fan],
46473
+ apply: "replace",
46474
+ vocabularyCap: "fan-control",
46475
+ sources: [{
46476
+ kind: "field",
46477
+ valueKinds: ["string"],
46478
+ transformKinds: ["identity"],
46479
+ transforms: [{ kind: "identity" }]
46480
+ }],
46481
+ sourceReport: { status: "assignment-status" },
46482
+ advancedExpression: false,
46483
+ path: "preset",
46484
+ valueKind: "string",
46485
+ nullable: false
46486
+ }
46487
+ ],
46488
+ overridable: [
46489
+ {
46490
+ path: "oscillationAxes.horizontal.oscillating",
46491
+ by: "horizontal-oscillating"
46492
+ },
46493
+ {
46494
+ path: "oscillationAxes.horizontal.angle",
46495
+ by: "horizontal-angle"
46496
+ },
46497
+ {
46498
+ path: "oscillationAxes.horizontal.sweepFrom",
46499
+ by: "horizontal-sweepFrom"
46500
+ },
46501
+ {
46502
+ path: "oscillationAxes.horizontal.sweepTo",
46503
+ by: "horizontal-sweepTo"
46504
+ },
46505
+ {
46506
+ path: "oscillationAxes.vertical.oscillating",
46507
+ by: "vertical-oscillating"
46508
+ },
46509
+ {
46510
+ path: "oscillationAxes.vertical.angle",
46511
+ by: "vertical-angle"
46512
+ },
46513
+ {
46514
+ path: "oscillationAxes.vertical.sweepFrom",
46515
+ by: "vertical-sweepFrom"
46516
+ },
46517
+ {
46518
+ path: "oscillationAxes.vertical.sweepTo",
46519
+ by: "vertical-sweepTo"
46520
+ },
46521
+ {
46522
+ path: "preset",
46523
+ by: "preset"
46524
+ }
46525
+ ]
46526
+ },
45441
46527
  "fan-presets": {
45442
46528
  version: 1,
45443
46529
  targets: [{
@@ -45538,7 +46624,6 @@ var CAP_CUSTOMIZE_CATALOG = {
45538
46624
  require_composed_stable_id.DeviceType.Light,
45539
46625
  require_composed_stable_id.DeviceType.Fan,
45540
46626
  require_composed_stable_id.DeviceType.Climate,
45541
- require_composed_stable_id.DeviceType.Thermostat,
45542
46627
  require_composed_stable_id.DeviceType.Humidifier,
45543
46628
  require_composed_stable_id.DeviceType.WaterHeater,
45544
46629
  require_composed_stable_id.DeviceType.MediaPlayer,
@@ -45547,8 +46632,7 @@ var CAP_CUSTOMIZE_CATALOG = {
45547
46632
  require_composed_stable_id.DeviceType.Dishwasher,
45548
46633
  require_composed_stable_id.DeviceType.Vacuum,
45549
46634
  require_composed_stable_id.DeviceType.LawnMower,
45550
- require_composed_stable_id.DeviceType.PetFeeder,
45551
- require_composed_stable_id.DeviceType.Heater
46635
+ require_composed_stable_id.DeviceType.PetFeeder
45552
46636
  ],
45553
46637
  apply: "add",
45554
46638
  vocabularyCap: "power-meter",
@@ -45578,7 +46662,6 @@ var CAP_CUSTOMIZE_CATALOG = {
45578
46662
  require_composed_stable_id.DeviceType.Light,
45579
46663
  require_composed_stable_id.DeviceType.Fan,
45580
46664
  require_composed_stable_id.DeviceType.Climate,
45581
- require_composed_stable_id.DeviceType.Thermostat,
45582
46665
  require_composed_stable_id.DeviceType.Humidifier,
45583
46666
  require_composed_stable_id.DeviceType.WaterHeater,
45584
46667
  require_composed_stable_id.DeviceType.MediaPlayer,
@@ -45587,8 +46670,7 @@ var CAP_CUSTOMIZE_CATALOG = {
45587
46670
  require_composed_stable_id.DeviceType.Dishwasher,
45588
46671
  require_composed_stable_id.DeviceType.Vacuum,
45589
46672
  require_composed_stable_id.DeviceType.LawnMower,
45590
- require_composed_stable_id.DeviceType.PetFeeder,
45591
- require_composed_stable_id.DeviceType.Heater
46673
+ require_composed_stable_id.DeviceType.PetFeeder
45592
46674
  ],
45593
46675
  apply: "add",
45594
46676
  vocabularyCap: "power-meter",
@@ -45618,7 +46700,6 @@ var CAP_CUSTOMIZE_CATALOG = {
45618
46700
  require_composed_stable_id.DeviceType.Light,
45619
46701
  require_composed_stable_id.DeviceType.Fan,
45620
46702
  require_composed_stable_id.DeviceType.Climate,
45621
- require_composed_stable_id.DeviceType.Thermostat,
45622
46703
  require_composed_stable_id.DeviceType.Humidifier,
45623
46704
  require_composed_stable_id.DeviceType.WaterHeater,
45624
46705
  require_composed_stable_id.DeviceType.MediaPlayer,
@@ -45627,8 +46708,7 @@ var CAP_CUSTOMIZE_CATALOG = {
45627
46708
  require_composed_stable_id.DeviceType.Dishwasher,
45628
46709
  require_composed_stable_id.DeviceType.Vacuum,
45629
46710
  require_composed_stable_id.DeviceType.LawnMower,
45630
- require_composed_stable_id.DeviceType.PetFeeder,
45631
- require_composed_stable_id.DeviceType.Heater
46711
+ require_composed_stable_id.DeviceType.PetFeeder
45632
46712
  ],
45633
46713
  apply: "add",
45634
46714
  vocabularyCap: "power-meter",
@@ -45658,7 +46738,6 @@ var CAP_CUSTOMIZE_CATALOG = {
45658
46738
  require_composed_stable_id.DeviceType.Light,
45659
46739
  require_composed_stable_id.DeviceType.Fan,
45660
46740
  require_composed_stable_id.DeviceType.Climate,
45661
- require_composed_stable_id.DeviceType.Thermostat,
45662
46741
  require_composed_stable_id.DeviceType.Humidifier,
45663
46742
  require_composed_stable_id.DeviceType.WaterHeater,
45664
46743
  require_composed_stable_id.DeviceType.MediaPlayer,
@@ -45667,8 +46746,7 @@ var CAP_CUSTOMIZE_CATALOG = {
45667
46746
  require_composed_stable_id.DeviceType.Dishwasher,
45668
46747
  require_composed_stable_id.DeviceType.Vacuum,
45669
46748
  require_composed_stable_id.DeviceType.LawnMower,
45670
- require_composed_stable_id.DeviceType.PetFeeder,
45671
- require_composed_stable_id.DeviceType.Heater
46749
+ require_composed_stable_id.DeviceType.PetFeeder
45672
46750
  ],
45673
46751
  apply: "add",
45674
46752
  vocabularyCap: "power-meter",
@@ -45770,9 +46848,7 @@ var CAP_CUSTOMIZE_CATALOG = {
45770
46848
  require_composed_stable_id.DeviceType.Humidifier,
45771
46849
  require_composed_stable_id.DeviceType.Fan,
45772
46850
  require_composed_stable_id.DeviceType.Climate,
45773
- require_composed_stable_id.DeviceType.Thermostat,
45774
- require_composed_stable_id.DeviceType.PetFeeder,
45775
- require_composed_stable_id.DeviceType.Heater
46851
+ require_composed_stable_id.DeviceType.PetFeeder
45776
46852
  ],
45777
46853
  apply: "add",
45778
46854
  vocabularyCap: "running-state",
@@ -46091,12 +47167,37 @@ function readKinds(read, lookupCap) {
46091
47167
  code: "source-field-unknown",
46092
47168
  message: `\`${read.cap}\` has no field \`${read.fieldPath}\``
46093
47169
  };
46094
- const base = field.kind === "enum" ? "string" : field.kind;
47170
+ const bases = field.kind === "union" ? field.unionMembers ?? [] : [field.kind === "enum" ? "string" : field.kind];
46095
47171
  return {
46096
47172
  ok: true,
46097
- kinds: new Set(field.nullable ? [base, "null"] : [base])
47173
+ kinds: new Set(field.nullable ? [...bases, "null"] : bases)
46098
47174
  };
46099
47175
  }
47176
+ /** A union field is read as a source (D1034), never written: no single kind to check a source against. */
47177
+ function unionTargetProblem(cap, path, at) {
47178
+ return problem("kind-mismatch", at, `\`${cap}.${path}\` is a union — it is read as a source, never written`);
47179
+ }
47180
+ /** The one value kind a target field accepts. */
47181
+ function acceptedKind(target) {
47182
+ if (target.kind === "union") return null;
47183
+ return target.kind === "enum" ? "string" : target.kind;
47184
+ }
47185
+ /**
47186
+ * A direct read of a UNION source field (D1034) is judged by the member that
47187
+ * fits the target: when one does, the read produces that kind only (a reading
47188
+ * of another kind is UNAVAILABLE at read time, never a coerced value); when
47189
+ * none does, the kinds stay as they are and `compatibility` names the mismatch.
47190
+ */
47191
+ function narrowUnionRead(source, target, kinds, lookupCap) {
47192
+ if (source.kind !== "from") return kinds;
47193
+ const def = lookupCap(source.cap);
47194
+ const schema = def?.runtimeState ?? def?.status?.schema;
47195
+ if (schema === void 0) return kinds;
47196
+ const field = describeStateField(schema, source.fieldPath);
47197
+ const accepted = acceptedKind(target);
47198
+ if (field?.kind !== "union" || accepted === null || !kinds.has(accepted)) return kinds;
47199
+ return new Set(kinds.has("null") ? [accepted, "null"] : [accepted]);
47200
+ }
46100
47201
  function sourceKinds(source, lookupCap) {
46101
47202
  if (source.kind === "from") return readKinds(source, lookupCap);
46102
47203
  if (source.kind === "code") return {
@@ -46133,7 +47234,8 @@ function sourceKinds(source, lookupCap) {
46133
47234
  };
46134
47235
  }
46135
47236
  function compatibility(cap, target, kinds, at) {
46136
- const allowed = target.kind === "enum" ? "string" : target.kind;
47237
+ const allowed = acceptedKind(target);
47238
+ if (allowed === null) return [unionTargetProblem(cap, target.path, at)];
46137
47239
  const offending = [...kinds].filter((k) => k !== "null" && k !== allowed);
46138
47240
  const problems = [];
46139
47241
  if (offending.length > 0) problems.push(problem("kind-mismatch", at, `\`${cap}.${target.path}\` is a ${target.kind}; this source can produce ${offending.join(" or ")}`));
@@ -46244,6 +47346,7 @@ function planItemField(ctx, leaf) {
46244
47346
  if (ctx.reserved.has(path)) return refused(problem("item-field-reserved", at, `\`${capName}.${itemArray.path}[].${path}\` is set by the composer itself — it takes no source`));
46245
47347
  const tf = describeStateField(itemArray.itemSchema, path);
46246
47348
  if (tf === null) return refused(problem("unknown-field", at, `a \`${capName}\` item has no field \`${path}\``));
47349
+ if (tf.kind === "union") return refused(unionTargetProblem(capName, path, at));
46247
47350
  const kinds = sourceKinds(source, lookupCap);
46248
47351
  if (!kinds.ok) return refused(problem(kinds.code, at, kinds.message));
46249
47352
  const role = roleOf(source);
@@ -46269,7 +47372,7 @@ function planItemField(ctx, leaf) {
46269
47372
  };
46270
47373
  const enumProblem = enumLiteralProblem(capName, tf, source, at);
46271
47374
  return {
46272
- problems: [...compatibility(capName, tf, kinds.kinds, at), ...enumProblem === null ? [] : [enumProblem]],
47375
+ problems: [...compatibility(capName, tf, narrowUnionRead(source, tf, kinds.kinds, lookupCap), at), ...enumProblem === null ? [] : [enumProblem]],
46273
47376
  fields: [plan],
46274
47377
  features: [],
46275
47378
  events: []
@@ -46501,7 +47604,7 @@ function numeric(input) {
46501
47604
  }, ...alsoFrom === void 0 ? [] : [alsoFrom.accept]]
46502
47605
  };
46503
47606
  }
46504
- var CLIMATE_DEVICES = [require_composed_stable_id.DeviceType.Thermostat, require_composed_stable_id.DeviceType.Climate];
47607
+ var CLIMATE_DEVICES = [require_composed_stable_id.DeviceType.Climate];
46505
47608
  function binary(input) {
46506
47609
  return {
46507
47610
  ...input,
@@ -46823,8 +47926,8 @@ var GROUP_TEMPLATES = [
46823
47926
  actuator({
46824
47927
  id: "climate",
46825
47928
  summary: "Running when at least one thermostat or air conditioner is not off, or only when all of them are. Target temperature and fan are offered only when every device has them. A device that reports nothing is left out, never read as off.",
46826
- deviceType: require_composed_stable_id.DeviceType.Thermostat,
46827
- memberDeviceTypes: [require_composed_stable_id.DeviceType.Thermostat, require_composed_stable_id.DeviceType.Climate],
47929
+ deviceType: require_composed_stable_id.DeviceType.Climate,
47930
+ memberDeviceTypes: [require_composed_stable_id.DeviceType.Climate],
46828
47931
  outputCap: "group-active",
46829
47932
  outputField: "active",
46830
47933
  member: {
@@ -48288,6 +49391,233 @@ function findCandidateCycles(candidate, stored) {
48288
49391
  });
48289
49392
  }
48290
49393
  //#endregion
49394
+ //#region src/capabilities/power-source.cap.ts
49395
+ /**
49396
+ * power-source — a device that hangs is powered by a smart switch, and the
49397
+ * operator picks that switch in the device's Customize. The device then offers
49398
+ * power on, power off and a forced restart (switch off, wait, switch on).
49399
+ *
49400
+ * Manual by default: nothing here restarts a device by itself. The one
49401
+ * exception (D997) is a device's OWN provider calling `forceRestart` for its own
49402
+ * device as a bounded self-recovery (unreachable for a long stretch, linked,
49403
+ * one attempt per cooldown, never with a live session); Velux is the first. It
49404
+ * is not the native `reboot` cap and never replaces or wraps it: `reboot` talks
49405
+ * to the device, this cuts the power of the device that no longer answers.
49406
+ *
49407
+ * The link is a Customize extension (`add`): one scalar target whose source is
49408
+ * the switch. The stored composition is the ONE copy of the link and of
49409
+ * `offSeconds` (`powerSourceLinkOfComposition`, D676); the composed slice only
49410
+ * mirrors the switch state for the UI. The methods are served by the
49411
+ * `core-blocks` system provider, so they are `systemMethod`s and carry a
49412
+ * top-level `deviceId`.
49413
+ *
49414
+ * Every action answers a typed result and never throws for an expected
49415
+ * refusal, so a caller tells "the switch is offline" from "a restart is
49416
+ * already running" without parsing text.
49417
+ */
49418
+ /** Bounds of the off time of a forced restart, in seconds. */
49419
+ var POWER_SOURCE_OFF_SECONDS_MIN = 3;
49420
+ var POWER_SOURCE_OFF_SECONDS_MAX = 120;
49421
+ var POWER_SOURCE_OFF_SECONDS_DEFAULT = 10;
49422
+ var PowerSourceRefusalReasonSchema = zod.z.enum([
49423
+ "no-power-source",
49424
+ "switch-missing",
49425
+ "switch-offline",
49426
+ "switch-unknown",
49427
+ "restart-in-progress",
49428
+ "switch-call-failed",
49429
+ "switch-is-actuator"
49430
+ ]);
49431
+ var PowerSourceActionResultSchema = zod.z.discriminatedUnion("accepted", [zod.z.object({ accepted: zod.z.literal(true) }), zod.z.object({
49432
+ accepted: zod.z.literal(false),
49433
+ reason: PowerSourceRefusalReasonSchema,
49434
+ /** One line for the operator, naming the switch. */
49435
+ message: zod.z.string()
49436
+ })]);
49437
+ var PowerSourceInfoSchema = zod.z.object({
49438
+ /** False when the device has no power source linked; the rest is then empty. */
49439
+ linked: zod.z.boolean(),
49440
+ switchDeviceId: zod.z.number().nullable(),
49441
+ switchName: zod.z.string().nullable(),
49442
+ /** The switch's on/off state, or null when it is unknown. Never false for unknown (D393). */
49443
+ switchOn: zod.z.boolean().nullable(),
49444
+ switchOnline: zod.z.boolean().nullable(),
49445
+ restartInProgress: zod.z.boolean(),
49446
+ offSeconds: zod.z.number().int()
49447
+ });
49448
+ /** The composed slice: the switch state the link mirrors, plus the stored off time. */
49449
+ var PowerSourceStateSchema = zod.z.object({
49450
+ /** Null while the switch has not reported: unknown is never `false` (D393). */
49451
+ switchOn: zod.z.boolean().nullable(),
49452
+ offSeconds: zod.z.number().int(),
49453
+ lastFetchedAt: zod.z.number()
49454
+ });
49455
+ var POWER_SOURCE_DEVICE_TYPES = [
49456
+ require_composed_stable_id.DeviceType.Gateway,
49457
+ require_composed_stable_id.DeviceType.Camera,
49458
+ require_composed_stable_id.DeviceType.Sensor,
49459
+ require_composed_stable_id.DeviceType.MediaPlayer,
49460
+ require_composed_stable_id.DeviceType.Vacuum,
49461
+ require_composed_stable_id.DeviceType.Generic,
49462
+ require_composed_stable_id.DeviceType.Washer,
49463
+ require_composed_stable_id.DeviceType.Dryer,
49464
+ require_composed_stable_id.DeviceType.Dishwasher,
49465
+ require_composed_stable_id.DeviceType.PetFountain,
49466
+ require_composed_stable_id.DeviceType.Fan,
49467
+ require_composed_stable_id.DeviceType.Humidifier,
49468
+ require_composed_stable_id.DeviceType.Climate,
49469
+ require_composed_stable_id.DeviceType.WaterHeater
49470
+ ];
49471
+ var powerSourceCustomize = {
49472
+ version: 1,
49473
+ targets: [{
49474
+ id: "switch",
49475
+ cardinality: "scalar",
49476
+ vocabulary: {
49477
+ cap: "power-source",
49478
+ stateField: "switchOn"
49479
+ },
49480
+ deviceTypes: POWER_SOURCE_DEVICE_TYPES,
49481
+ apply: "add",
49482
+ path: "switchOn",
49483
+ sources: [{
49484
+ kind: "switch",
49485
+ transforms: [{ kind: "identity" }]
49486
+ }],
49487
+ companions: [{
49488
+ kind: "constant",
49489
+ path: "offSeconds",
49490
+ value: 10,
49491
+ when: "add",
49492
+ formerValues: [0]
49493
+ }, {
49494
+ kind: "clock",
49495
+ path: "lastFetchedAt",
49496
+ when: "always"
49497
+ }],
49498
+ sourceReport: { status: "assignment-status" }
49499
+ }]
49500
+ };
49501
+ var deviceInput$2 = zod.z.object({ deviceId: zod.z.number().int().nonnegative() });
49502
+ var powerSourceCapability = {
49503
+ name: "power-source",
49504
+ scope: "device",
49505
+ mode: "singleton",
49506
+ deviceTypes: POWER_SOURCE_DEVICE_TYPES,
49507
+ methods: {
49508
+ getStatus: require_sleep.systemMethod(deviceInput$2, PowerSourceInfoSchema, { auth: "protected" }),
49509
+ powerOn: require_sleep.systemMethod(deviceInput$2, PowerSourceActionResultSchema, {
49510
+ kind: "mutation",
49511
+ auth: "protected"
49512
+ }),
49513
+ powerOff: require_sleep.systemMethod(deviceInput$2, PowerSourceActionResultSchema, {
49514
+ kind: "mutation",
49515
+ auth: "protected"
49516
+ }),
49517
+ forceRestart: require_sleep.systemMethod(deviceInput$2, PowerSourceActionResultSchema, {
49518
+ kind: "mutation",
49519
+ auth: "protected"
49520
+ })
49521
+ },
49522
+ runtimeState: PowerSourceStateSchema,
49523
+ customize: powerSourceCustomize,
49524
+ /**
49525
+ * Runtime-state durability: **session** — mirrored from the linked switch on
49526
+ * its next report; a restored value would outlive the reading it names.
49527
+ *
49528
+ * See `RuntimeStateDurability`. Enforced by
49529
+ * `scripts/check-runtime-state-durability.ts`.
49530
+ */
49531
+ durability: "session",
49532
+ history: "none"
49533
+ };
49534
+ //#endregion
49535
+ //#region src/composition/power-source-link.ts
49536
+ /**
49537
+ * Which smart switch powers a device (the `power-source` Customize extension):
49538
+ * the source its stored `power-source.switchOn` field reads, and the off time of
49539
+ * a forced restart stored beside it. Read from the STORED composition, never kept
49540
+ * as a second copy (D676). Shared by the hub (which acts on the switch) and the
49541
+ * admin UI (which shows it).
49542
+ */
49543
+ /**
49544
+ * The stored off time, or the default when none is stored. A stored number out
49545
+ * of range is CLAMPED to the bounds (a hand-written value never refuses the
49546
+ * link, it just cannot cut power for an absurd time); a non-integer is rounded.
49547
+ */
49548
+ function normalizeOffSeconds(value) {
49549
+ if (typeof value !== "number" || !Number.isFinite(value)) return 10;
49550
+ return Math.min(120, Math.max(3, Math.round(value)));
49551
+ }
49552
+ /** The constant a stored `offSeconds` field carries, or undefined when it is not a literal number. */
49553
+ function storedOffSeconds(composition) {
49554
+ const feature = composition.features.find((f) => f.cap === "power-source");
49555
+ if (feature === void 0 || feature.kind !== "fields") return void 0;
49556
+ const field = feature.fields["offSeconds"];
49557
+ if (field === void 0 || field.kind !== "expression") return void 0;
49558
+ const n = Number(field.expr);
49559
+ return field.expr.trim() === "" || !Number.isFinite(n) ? void 0 : n;
49560
+ }
49561
+ /**
49562
+ * The link a composition stores. An `existing` target names its own device; a
49563
+ * `new` target (a composed device) is the composer's own device, so the caller
49564
+ * passes the block id and a new-target composition without one has no link.
49565
+ */
49566
+ function powerSourceLinkOfComposition(composition, blockId) {
49567
+ if (composition === null) return null;
49568
+ let device;
49569
+ if (composition.target.kind === "existing") device = composition.target.device;
49570
+ else if (blockId !== void 0) device = require_implemented_methods.composedDeviceRef(blockId);
49571
+ else return null;
49572
+ const feature = composition.features.find((f) => f.cap === "power-source");
49573
+ if (feature === void 0 || feature.kind !== "fields" || feature.enabled === false) return null;
49574
+ const field = feature.fields["switchOn"];
49575
+ if (field === void 0) return null;
49576
+ const read = require_implemented_methods.fieldReads(field).find((r) => r.cap === "switch");
49577
+ if (read === void 0) return null;
49578
+ return {
49579
+ device,
49580
+ switch: read.source,
49581
+ offSeconds: normalizeOffSeconds(storedOffSeconds(composition))
49582
+ };
49583
+ }
49584
+ var ACTUATOR_CAP = "switch";
49585
+ /**
49586
+ * The devices that ACT for this composition: the device itself when it is an
49587
+ * existing one, and every source its own `switch` feature reads or forwards a
49588
+ * command to (a heater's plug, every member of a switch group).
49589
+ */
49590
+ function actuatorKeys(composition) {
49591
+ const keys = /* @__PURE__ */ new Set();
49592
+ if (composition.target.kind === "existing") keys.add(require_implemented_methods.compositionSourceKey(composition.target.device));
49593
+ composition.features.forEach((feature, index) => {
49594
+ if (feature.kind !== "fields" || feature.cap !== ACTUATOR_CAP) return;
49595
+ if (!require_implemented_methods.compositionFeatureEnabled(feature)) return;
49596
+ for (const source of require_implemented_methods.featureSources(feature)) for (const read of require_implemented_methods.fieldReads(source)) keys.add(require_implemented_methods.compositionSourceKey(read.source));
49597
+ for (const forward of featureForwards(feature, index)) keys.add(require_implemented_methods.compositionSourceKey(forward.command.source));
49598
+ });
49599
+ return keys;
49600
+ }
49601
+ /**
49602
+ * The supply plug is never one of the device's own actuators (#462): cutting
49603
+ * power through the switch that IS the device's on/off leaves nothing to
49604
+ * restart, and makes "power off" and "turn off" the same press. Refused at save
49605
+ * time (`power-source-is-actuator`) and again by the power-source provider for a
49606
+ * link stored before this check existed (`switch-is-actuator`).
49607
+ */
49608
+ function powerSourceActuatorConflicts(composition) {
49609
+ const index = composition.features.findIndex((f) => f.cap === "power-source");
49610
+ const feature = composition.features[index];
49611
+ if (feature === void 0 || feature.kind !== "fields" || feature.enabled === false) return [];
49612
+ const field = feature.fields["switchOn"];
49613
+ if (field === void 0) return [];
49614
+ const actuators = actuatorKeys(composition);
49615
+ return require_implemented_methods.fieldReads(field).filter((read) => read.cap === ACTUATOR_CAP && actuators.has(require_implemented_methods.compositionSourceKey(read.source))).map((read) => ({
49616
+ path: `features[${index}].fields.switchOn`,
49617
+ switch: read.source
49618
+ }));
49619
+ }
49620
+ //#endregion
48291
49621
  //#region src/composition/validate-composition.ts
48292
49622
  function buildCapabilityLookup(defs) {
48293
49623
  const byName = new Map(defs.map((d) => [d.name, d]));
@@ -48349,12 +49679,25 @@ function builtCapProblems({ def, state, fields: targetFields }, feature, at, dev
48349
49679
  }
48350
49680
  return problems;
48351
49681
  }
48352
- function planTopLevelField({ def, fields }, field, mode, lookupCap) {
49682
+ /**
49683
+ * A dotted leaf is planned only on a `replace` (D1034): the feature already
49684
+ * passed `overridesOnlyDeclared`, so the leaf is one the cap lists in its
49685
+ * `overridable`, and the hub sets it into the native object. Anywhere else a
49686
+ * nested field is still refused.
49687
+ */
49688
+ function stateFieldOf({ fields, state }, path, mode) {
49689
+ if (!path.includes(".")) return fields.get(path);
49690
+ if (mode !== "replace") return "nested";
49691
+ return describeStateField(state, path) ?? void 0;
49692
+ }
49693
+ function planTopLevelField(cap, field, mode, lookupCap) {
49694
+ const { def } = cap;
48353
49695
  const { featureIndex, path, source } = field;
48354
49696
  const fieldAt = `features[${featureIndex}].fields.${path}`;
48355
- if (path.includes(".")) return refused(problem("nested-field", fieldAt, `\`${path}\` is nested — nested fields arrive in a later slice`));
48356
- const tf = fields.get(path);
49697
+ const tf = stateFieldOf(cap, path, mode);
49698
+ if (tf === "nested") return refused(problem("nested-field", fieldAt, `\`${path}\` is nested — a nested field is planned only on a declared replace (D1034)`));
48357
49699
  if (tf === void 0) return refused(problem("unknown-field", fieldAt, `\`${def.name}\` has no field \`${path}\``));
49700
+ if (tf.kind === "union") return refused(unionTargetProblem(def.name, path, fieldAt));
48358
49701
  const kinds = sourceKinds(source, lookupCap);
48359
49702
  if (!kinds.ok) return refused(problem(kinds.code, fieldAt, kinds.message));
48360
49703
  const role = roleOf(source);
@@ -48375,7 +49718,7 @@ function planTopLevelField({ def, fields }, field, mode, lookupCap) {
48375
49718
  };
48376
49719
  const enumProblem = enumLiteralProblem(def.name, tf, source, fieldAt);
48377
49720
  return {
48378
- problems: [...compatibility(def.name, tf, kinds.kinds, fieldAt), ...enumProblem === null ? [] : [enumProblem]],
49721
+ problems: [...compatibility(def.name, tf, narrowUnionRead(source, tf, kinds.kinds, lookupCap), fieldAt), ...enumProblem === null ? [] : [enumProblem]],
48379
49722
  fields: [plan],
48380
49723
  features: [],
48381
49724
  events: []
@@ -48478,7 +49821,7 @@ var customizeCatalog = CAP_CUSTOMIZE_CATALOG;
48478
49821
  function overridesOnlyDeclared(feature) {
48479
49822
  const entry = customizeCatalog[feature.cap];
48480
49823
  const allowed = new Set((entry?.overridable ?? []).flatMap((o) => {
48481
- const companions = ((entry?.targets.find((t) => t.id === o.by && t.path === o.path))?.companions ?? []).filter((c) => c.kind === "transition-time" || c.when === "always");
49824
+ const companions = ((entry?.targets.find((t) => t.id === o.by && t.path === o.path))?.companions ?? []).filter((c) => c.kind === "transition-time" || c.kind === "source-field" || c.when === "always");
48482
49825
  return [o.path, ...companions.map((c) => c.path)];
48483
49826
  }));
48484
49827
  const paths = Object.keys(feature.fields);
@@ -48549,6 +49892,20 @@ function compositionSourceRefs(composition) {
48549
49892
  return [...new Map([...refs, ...forwardSourceRefs(composition)].map((r) => [require_implemented_methods.compositionSourceKey(r), r])).values()];
48550
49893
  }
48551
49894
  /**
49895
+ * Every DIRECT read (`from`) of a union source field (D1034): the reads whose
49896
+ * source's live kind a save looks up, so a numeric control is never linked to
49897
+ * a string field. A read inside an expression is judged by the expression.
49898
+ */
49899
+ function compositionUnionReads(composition, lookupCap) {
49900
+ return composition.features.flatMap((f) => require_implemented_methods.compositionFeatureEnabled(f) && f.kind === "fields" ? require_implemented_methods.featureSources(f).flatMap((source) => {
49901
+ if (source.kind !== "from") return [];
49902
+ const def = lookupCap(source.cap);
49903
+ const schema = def?.runtimeState ?? def?.status?.schema;
49904
+ if (schema === void 0) return [];
49905
+ return describeStateField(schema, source.fieldPath)?.kind === "union" ? [source] : [];
49906
+ }) : []);
49907
+ }
49908
+ /**
48552
49909
  * The candidate's device: the existing target itself, else `self`, else a
48553
49910
  * placeholder that cannot collide with a stored target. An existing target is
48554
49911
  * known even on create, so a second customization of it is refused on create too.
@@ -48582,6 +49939,18 @@ function selfReadProblems(read, at, fields, self) {
48582
49939
  if (isNativeCap(self.native, read.cap)) return [];
48583
49940
  return [problem("source-capability-missing", at, `the target device (device ${self.native.deviceId}) has no native \`${read.cap}\``)];
48584
49941
  }
49942
+ /**
49943
+ * A direct read of a union field is judged by the source's LIVE kind when the
49944
+ * save knew it (D1034): a numeric control feeds only a number field, a select
49945
+ * only a string or enum one.
49946
+ */
49947
+ function liveKindProblems(field, read, desc, at) {
49948
+ if (field.source.kind !== "from") return [];
49949
+ const live = desc.liveKinds?.get(`${read.cap}.${read.fieldPath}`);
49950
+ const accepted = field.kind === "enum" ? "string" : field.kind;
49951
+ if (live === void 0 || live === accepted) return [];
49952
+ return [problem("source-kind-mismatch", at, `\`${read.cap}.${read.fieldPath}\` of device ${desc.deviceId} reads a ${live} now; \`${field.cap}.${field.path}\` takes a ${accepted}`)];
49953
+ }
48585
49954
  function sourceProblems(fields, ctx, self) {
48586
49955
  const selfKey = require_implemented_methods.compositionSourceKey(self.ref);
48587
49956
  return fields.flatMap((field) => field.reads.flatMap((read) => {
@@ -48592,7 +49961,7 @@ function sourceProblems(fields, ctx, self) {
48592
49961
  if (desc === void 0 || desc.kind === "unreadable") return [problem("source-unreadable", at, `could not read source \`${key}\` (${desc === void 0 ? "it was not read" : desc.error}) — the save is refused rather than stored unchecked`)];
48593
49962
  if (desc.kind === "absent") return [problem("source-missing", at, `source \`${key}\` does not exist`)];
48594
49963
  if (!desc.caps.has(read.cap)) return [problem("source-capability-missing", at, `source \`${key}\` (device ${desc.deviceId}) has no \`${read.cap}\``)];
48595
- return [];
49964
+ return liveKindProblems(field, read, desc, at);
48596
49965
  }));
48597
49966
  }
48598
49967
  /**
@@ -48684,7 +50053,8 @@ function validateComposition(composition, ctx) {
48684
50053
  ...sourceProblems(plan.fields, ctx, self),
48685
50054
  ...forwardSourceProblems(composition, ctx.sources),
48686
50055
  ...cycles,
48687
- ...helperSaveProblems(composition, facts)
50056
+ ...helperSaveProblems(composition, facts),
50057
+ ...powerSourceActuatorConflicts(composition).map((c) => problem("power-source-is-actuator", c.path, `the power source \`${c.switch.stableId}\` is one of this device's own switches — pick the plug that feeds it`))
48688
50058
  ];
48689
50059
  return {
48690
50060
  ok: problems.length === 0,
@@ -48746,13 +50116,13 @@ function describeComposableCaps(defs, deviceType) {
48746
50116
  const itemArray = def.status?.itemArray;
48747
50117
  return {
48748
50118
  cap: def.name,
48749
- fields: fields.map((f) => ({
50119
+ fields: fields.flatMap((f) => f.kind === "union" ? [] : [{
48750
50120
  path: f.path,
48751
50121
  kind: f.kind,
48752
50122
  nullable: f.nullable,
48753
50123
  required: f.required,
48754
50124
  ...f.enumValues === void 0 ? {} : { enumValues: [...f.enumValues] }
48755
- })),
50125
+ }]),
48756
50126
  ...itemArray === void 0 ? {} : { itemArray: {
48757
50127
  path: itemArray.path,
48758
50128
  keyField: itemArray.keyField
@@ -52351,8 +53721,14 @@ var deviceManagerCapability = {
52351
53721
  "string",
52352
53722
  "number",
52353
53723
  "boolean",
52354
- "enum"
53724
+ "enum",
53725
+ "union"
52355
53726
  ]),
53727
+ unionMembers: zod.z.array(zod.z.enum([
53728
+ "string",
53729
+ "number",
53730
+ "boolean"
53731
+ ])).optional(),
52356
53732
  enumValues: zod.z.array(zod.z.string()).optional(),
52357
53733
  item: zod.z.boolean().optional(),
52358
53734
  quantity: require_sleep.ReadingQuantitySchema.optional()
@@ -55777,26 +57153,174 @@ var enumSensorCapability = {
55777
57153
  volatileStateFields: ["lastFetchedAt", "timestamp"]
55778
57154
  };
55779
57155
  //#endregion
57156
+ //#region src/capabilities/event-vocabulary.ts
57157
+ /**
57158
+ * The declared vocabulary of an `event-emitter` device (D1044): what the
57159
+ * device can fire, named for a person and typed for a rule.
57160
+ *
57161
+ * `id` is the native token, verbatim. `kind` is the meaning shared by every
57162
+ * integration, so "any long press" can be asked without knowing a vendor's
57163
+ * token. A device with several buttons declares one entry per button and
57164
+ * token: an entry is identified by its token AND its source.
57165
+ */
57166
+ /** The cross-integration meaning of an event. */
57167
+ var EVENT_VOCABULARY_KINDS = [
57168
+ "press",
57169
+ "long-press",
57170
+ "long-press-start",
57171
+ "release",
57172
+ "repeat",
57173
+ "double-press",
57174
+ "other"
57175
+ ];
57176
+ var EventVocabularyKindSchema = zod.z.enum(EVENT_VOCABULARY_KINDS);
57177
+ /** The part of the device an event comes from: a button, a channel. */
57178
+ var EventVocabularySourceSchema = zod.z.object({
57179
+ id: zod.z.string().min(1),
57180
+ label: zod.z.string().min(1)
57181
+ });
57182
+ /** One scalar field of an event's `data`, by dotted path. */
57183
+ var EventVocabularyFieldSchema = zod.z.object({
57184
+ path: zod.z.string().min(1),
57185
+ kind: zod.z.enum([
57186
+ "string",
57187
+ "number",
57188
+ "boolean",
57189
+ "enum"
57190
+ ]),
57191
+ enumValues: zod.z.array(zod.z.string()).optional(),
57192
+ label: zod.z.string().min(1).optional()
57193
+ });
57194
+ var EventVocabularyEntrySchema = zod.z.object({
57195
+ /** The native token, verbatim. */
57196
+ id: zod.z.string().min(1),
57197
+ source: EventVocabularySourceSchema.optional(),
57198
+ label: zod.z.string().min(1),
57199
+ description: zod.z.string().optional(),
57200
+ kind: EventVocabularyKindSchema.optional(),
57201
+ payload: zod.z.array(EventVocabularyFieldSchema).optional()
57202
+ });
57203
+ /**
57204
+ * The vocabulary of a source that declares tokens and nothing else: one
57205
+ * entry per token, labelled with the token itself.
57206
+ */
57207
+ function plainEventVocabulary(eventTypes) {
57208
+ return [...new Set(eventTypes)].filter((eventType) => eventType !== "").map((eventType) => ({
57209
+ id: eventType,
57210
+ label: eventType
57211
+ }));
57212
+ }
57213
+ /**
57214
+ * Tokens many integrations use for a button, by their normalised spelling
57215
+ * (lower case, words joined by `_`). Exact matches only: a token that
57216
+ * merely contains one of these words gets no kind.
57217
+ */
57218
+ var CONVENTIONAL_KINDS = {
57219
+ press: "press",
57220
+ pressed: "press",
57221
+ single: "press",
57222
+ single_press: "press",
57223
+ single_click: "press",
57224
+ short_press: "press",
57225
+ press_short: "press",
57226
+ click: "press",
57227
+ initial_press: "press",
57228
+ long_press: "long-press",
57229
+ press_long: "long-press",
57230
+ long_click: "long-press",
57231
+ hold: "long-press",
57232
+ long_press_start: "long-press-start",
57233
+ press_long_start: "long-press-start",
57234
+ release: "release",
57235
+ released: "release",
57236
+ long_release: "release",
57237
+ long_press_release: "release",
57238
+ press_long_release: "release",
57239
+ short_release: "release",
57240
+ repeat: "repeat",
57241
+ hold_repeat: "repeat",
57242
+ press_cont: "repeat",
57243
+ double_press: "double-press",
57244
+ double_click: "double-press",
57245
+ double: "double-press",
57246
+ multi_press_2: "double-press"
57247
+ };
57248
+ function normalisedToken(token) {
57249
+ return token.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
57250
+ }
57251
+ function readableToken(token) {
57252
+ const words = normalisedToken(token).replace(/_/g, " ");
57253
+ if (words === "") return token;
57254
+ return `${words.charAt(0).toUpperCase()}${words.slice(1)}`;
57255
+ }
57256
+ /**
57257
+ * The vocabulary of a source that declares tokens only, read by convention:
57258
+ * a readable label, and the shared kind when the token is one many
57259
+ * integrations use for a button. The token itself is kept verbatim.
57260
+ */
57261
+ function conventionalEventVocabulary(eventTypes) {
57262
+ return plainEventVocabulary(eventTypes).map((entry) => {
57263
+ const kind = CONVENTIONAL_KINDS[normalisedToken(entry.id)];
57264
+ const label = readableToken(entry.id);
57265
+ return kind === void 0 ? {
57266
+ id: entry.id,
57267
+ label
57268
+ } : {
57269
+ id: entry.id,
57270
+ label,
57271
+ kind
57272
+ };
57273
+ });
57274
+ }
57275
+ /** The native tokens of a vocabulary, each once, in declaration order. */
57276
+ function eventTypesOfVocabulary(vocabulary) {
57277
+ return [...new Set(vocabulary.map((entry) => entry.id))];
57278
+ }
57279
+ /**
57280
+ * The vocabulary to show and match against. A status with none declared
57281
+ * answers with its plain tokens, so an older provider is still usable.
57282
+ */
57283
+ function readEventVocabulary(status) {
57284
+ const declared = status.vocabulary;
57285
+ if (declared !== void 0 && declared.length > 0) return declared;
57286
+ return plainEventVocabulary(status.eventTypes);
57287
+ }
57288
+ /** The entry a fire belongs to: same token, same source (or both without one). */
57289
+ function findVocabularyEntry(vocabulary, eventType, sourceId) {
57290
+ return vocabulary.find((entry) => entry.id === eventType && entry.source?.id === sourceId);
57291
+ }
57292
+ //#endregion
55780
57293
  //#region src/capabilities/event-emitter.cap.ts
55781
57294
  /**
55782
57295
  * Generic stateless event emitter. Installed on a `DeviceType.EventEmitter`
55783
57296
  * device. Carries the device's EXACT declared event vocabulary verbatim
55784
57297
  * (NO normalization). Two shapes:
55785
- * - structured source (HA `event.*` entity) → `eventTypes` is the fixed
55786
- * declared vocabulary (e.g. ['press_short','press_long',...]).
55787
- * - generic/legacy source (HA bus events, e.g. zha_event) → `eventTypes`
57298
+ * - structured source (HA `event.*` entity) → `vocabulary` is the fixed
57299
+ * declared set (e.g. press_short, press_long, …).
57300
+ * - generic/legacy source (HA bus events, e.g. zha_event) → `vocabulary`
55788
57301
  * is [] (open) and `lastEvent.data` carries the complex payload.
57302
+ * `vocabulary` (D1044) names each event for a person and types it for a
57303
+ * rule; `eventTypes` is its list of native tokens, kept for older readers.
57304
+ * A fire names the part of the device it came from in `sourceId` when the
57305
+ * vocabulary declares sources (a remote's buttons).
55789
57306
  * `seq` is monotonic so two identical events still produce distinct slice writes.
55790
57307
  */
55791
57308
  var EventFireSchema = zod.z.object({
55792
57309
  deviceId: zod.z.number(),
55793
57310
  eventType: zod.z.string(),
57311
+ sourceId: zod.z.string().optional(),
55794
57312
  data: zod.z.record(zod.z.string(), zod.z.unknown()).nullable(),
55795
57313
  timestamp: zod.z.number().meta(require_sleep.readingMeta("none")),
55796
57314
  seq: zod.z.number().meta(require_sleep.readingMeta("count"))
55797
57315
  });
55798
57316
  var EventEmitterStatusSchema = zod.z.object({
55799
57317
  eventTypes: zod.z.array(zod.z.string()),
57318
+ /**
57319
+ * Required of a provider by the type. A status written before the field
57320
+ * existed still parses, as an empty vocabulary: read it through
57321
+ * `readEventVocabulary`, which then answers with the plain tokens.
57322
+ */
57323
+ vocabulary: zod.z.array(EventVocabularyEntrySchema).default([]),
55800
57324
  lastEvent: EventFireSchema.nullable(),
55801
57325
  eventCountSinceStart: zod.z.number().meta(require_sleep.readingMeta("count"))
55802
57326
  });
@@ -56379,8 +57903,88 @@ list: require_sleep.method(zod.z.void(), zod.z.array(FailureContributionSchema).
56379
57903
  * - `FanPreset` — preset selector
56380
57904
  * - `FanDirection` — direction toggle (ceiling fans)
56381
57905
  * - `FanOscillating` — oscillation toggle
57906
+ *
57907
+ * Per-axis oscillation (`oscillationAxes`, `setOscillationAxis`, D1034): an air
57908
+ * circulator sweeps horizontally and vertically, each axis with its own
57909
+ * switch, fixed angle, sweep bounds and limits. A provider may report them
57910
+ * natively; otherwise the OPERATOR links sibling devices to each field in
57911
+ * Customize (a `replace` over the fields listed in `overridable` — nothing is
57912
+ * linked or inferred by itself), and a write to a linked field is forwarded to
57913
+ * its source. `oscillating` stays the single summary flag: when axes exist it
57914
+ * means "any axis oscillates" (`anyAxisOscillating`).
56382
57915
  */
56383
57916
  var FanDirectionSchema = zod.z.enum(["forward", "reverse"]);
57917
+ var FAN_OSCILLATION_AXES = ["horizontal", "vertical"];
57918
+ var FanOscillationAxisNameSchema = zod.z.enum(FAN_OSCILLATION_AXES);
57919
+ /** The fields of one axis a caller may set. */
57920
+ var FAN_OSCILLATION_AXIS_SETTABLE = [
57921
+ "oscillating",
57922
+ "angle",
57923
+ "sweepFrom",
57924
+ "sweepTo"
57925
+ ];
57926
+ var FanOscillationAxisFieldSchema = zod.z.enum(FAN_OSCILLATION_AXIS_SETTABLE);
57927
+ /** The limits of one axis, read from the source that serves its angle. */
57928
+ var FAN_OSCILLATION_AXIS_LIMITS = [
57929
+ "min",
57930
+ "max",
57931
+ "step"
57932
+ ];
57933
+ /**
57934
+ * One oscillation axis. Every reading the device has not reported is `null`,
57935
+ * never `0` (D393): `0°` is a real position. Each leaf defaults to `null`, so
57936
+ * a slice that names only the leaves it knows (a Customize link of one field)
57937
+ * is still a whole axis.
57938
+ */
57939
+ var FanOscillationAxisSchema = zod.z.object({
57940
+ /** Whether the axis sweeps. */
57941
+ oscillating: zod.z.boolean().nullable().default(null),
57942
+ /** The fixed position (degrees) the axis holds when it does not sweep. */
57943
+ angle: zod.z.number().nullable().default(null),
57944
+ /** The sweep bounds (degrees): left → right, bottom → top. */
57945
+ sweepFrom: zod.z.number().nullable().default(null),
57946
+ sweepTo: zod.z.number().nullable().default(null),
57947
+ /** The angles the axis accepts. Null when the device states none. */
57948
+ min: zod.z.number().nullable().default(null),
57949
+ max: zod.z.number().nullable().default(null),
57950
+ step: zod.z.number().nullable().default(null)
57951
+ });
57952
+ /** Both axes; an axis the device does not have is `null`. */
57953
+ var FanOscillationAxesSchema = zod.z.object({
57954
+ horizontal: FanOscillationAxisSchema.nullable().default(null),
57955
+ vertical: FanOscillationAxisSchema.nullable().default(null)
57956
+ });
57957
+ var FAN_OSCILLATION_AXIS_REFUSALS = [
57958
+ "nothing-to-set",
57959
+ "axis-not-linked",
57960
+ "out-of-range",
57961
+ "source-gone",
57962
+ "source-unknown",
57963
+ "source-call-failed"
57964
+ ];
57965
+ var FanOscillationAxisRefusalSchema = zod.z.enum(FAN_OSCILLATION_AXIS_REFUSALS);
57966
+ var FanOscillationAxisResultSchema = zod.z.discriminatedUnion("status", [zod.z.object({ status: zod.z.literal("applied") }), zod.z.object({
57967
+ status: zod.z.literal("refused"),
57968
+ reason: FanOscillationAxisRefusalSchema,
57969
+ /** The field at fault, when one is. */
57970
+ field: FanOscillationAxisFieldSchema.optional(),
57971
+ /** One line for the operator, naming the axis, the field and the source. */
57972
+ detail: zod.z.string(),
57973
+ /** Fields that DID land before the refusal (writes run in order, stop at the first failure). */
57974
+ applied: zod.z.array(FanOscillationAxisFieldSchema)
57975
+ })]);
57976
+ var SetOscillationAxisInputSchema = zod.z.object({
57977
+ deviceId: zod.z.number().int().nonnegative(),
57978
+ axis: FanOscillationAxisNameSchema,
57979
+ oscillating: zod.z.boolean().optional(),
57980
+ angle: zod.z.number().optional(),
57981
+ sweepFrom: zod.z.number().optional(),
57982
+ sweepTo: zod.z.number().optional()
57983
+ });
57984
+ /** The state path of one axis field: `oscillationAxes.<axis>.<field>`. */
57985
+ function fanAxisPath(axis, field) {
57986
+ return `oscillationAxes.${axis}.${field}`;
57987
+ }
56384
57988
  var FanControlStatusSchema = zod.z.object({
56385
57989
  /** Active speed as 0..100 inclusive. Null when the device has no
56386
57990
  * speed surface (single-speed fan). */
@@ -56399,9 +58003,116 @@ var FanControlStatusSchema = zod.z.object({
56399
58003
  /** Oscillation toggle. Null when the device has no oscillation
56400
58004
  * surface. */
56401
58005
  oscillating: zod.z.boolean().nullable(),
58006
+ /**
58007
+ * Per-axis oscillation (air circulators). Absent when the device has no
58008
+ * per-axis surface and nothing is linked in Customize.
58009
+ */
58010
+ oscillationAxes: FanOscillationAxesSchema.optional(),
56402
58011
  /** Ms epoch when the slice was last updated. */
56403
58012
  lastChangedAt: zod.z.number()
56404
58013
  });
58014
+ /**
58015
+ * The summary flag: with axes, "any axis oscillates"; without an axis that
58016
+ * reports, the device's own `oscillating`.
58017
+ */
58018
+ function anyAxisOscillating(status) {
58019
+ const axes = status.oscillationAxes;
58020
+ if (axes === void 0) return status.oscillating;
58021
+ const known = FAN_OSCILLATION_AXES.flatMap((axis) => {
58022
+ const value = axes[axis]?.oscillating;
58023
+ return value === null || value === void 0 ? [] : [value];
58024
+ });
58025
+ if (known.length === 0) return status.oscillating;
58026
+ return known.some(Boolean);
58027
+ }
58028
+ var FAN_CUSTOMIZE_DEVICE_TYPES = [require_composed_stable_id.DeviceType.Fan];
58029
+ /** The Customize section the axis targets are listed under. */
58030
+ var AXES_SECTION = "oscillation-axes";
58031
+ function axisOscillatingTarget(axis) {
58032
+ return {
58033
+ id: `${axis}-oscillating`,
58034
+ cardinality: "scalar",
58035
+ vocabulary: {
58036
+ cap: "fan-control",
58037
+ stateField: "oscillating"
58038
+ },
58039
+ deviceTypes: FAN_CUSTOMIZE_DEVICE_TYPES,
58040
+ apply: "replace",
58041
+ section: AXES_SECTION,
58042
+ path: fanAxisPath(axis, "oscillating"),
58043
+ sources: [{
58044
+ kind: "switch",
58045
+ transforms: [{ kind: "identity" }]
58046
+ }],
58047
+ sourceReport: { status: "assignment-status" }
58048
+ };
58049
+ }
58050
+ /**
58051
+ * A numeric axis field. The `angle` link also carries the axis limits, read
58052
+ * from the SAME linked control's own range (`min`/`max`/`step`), so the limits
58053
+ * are the source's, never guessed.
58054
+ */
58055
+ function axisNumericTarget(axis, field) {
58056
+ const base = {
58057
+ id: `${axis}-${field}`,
58058
+ cardinality: "scalar",
58059
+ vocabulary: { cap: "fan-control" },
58060
+ deviceTypes: FAN_CUSTOMIZE_DEVICE_TYPES,
58061
+ apply: "replace",
58062
+ section: AXES_SECTION,
58063
+ path: fanAxisPath(axis, field),
58064
+ sources: [{
58065
+ kind: "numeric",
58066
+ transforms: [{ kind: "identity" }]
58067
+ }],
58068
+ sourceReport: { status: "assignment-status" }
58069
+ };
58070
+ if (field !== "angle") return base;
58071
+ return {
58072
+ ...base,
58073
+ companions: FAN_OSCILLATION_AXIS_LIMITS.map((limit) => ({
58074
+ kind: "source-field",
58075
+ path: fanAxisPath(axis, limit),
58076
+ field: limit
58077
+ }))
58078
+ };
58079
+ }
58080
+ var AXIS_TARGETS = FAN_OSCILLATION_AXES.flatMap((axis) => [
58081
+ axisOscillatingTarget(axis),
58082
+ axisNumericTarget(axis, "angle"),
58083
+ axisNumericTarget(axis, "sweepFrom"),
58084
+ axisNumericTarget(axis, "sweepTo")
58085
+ ]);
58086
+ /** A select (an enum control) the operator links to the fan's `preset`. */
58087
+ var PRESET_TARGET = {
58088
+ id: "preset",
58089
+ cardinality: "scalar",
58090
+ vocabulary: { cap: "fan-control" },
58091
+ deviceTypes: FAN_CUSTOMIZE_DEVICE_TYPES,
58092
+ apply: "replace",
58093
+ path: "preset",
58094
+ sources: [{
58095
+ kind: "field",
58096
+ valueKinds: ["string"],
58097
+ transforms: [{ kind: "identity" }]
58098
+ }],
58099
+ sourceReport: { status: "assignment-status" }
58100
+ };
58101
+ var FAN_CONTROL_TARGETS = [...AXIS_TARGETS, PRESET_TARGET];
58102
+ /**
58103
+ * Customize (D1034): the fan already serves `fan-control` natively, so every
58104
+ * target is a `replace` over a field listed in `overridable` — the axis leaves
58105
+ * and `preset`, nothing else. Nothing is pre-linked: the operator picks each
58106
+ * source (D356).
58107
+ */
58108
+ var fanControlCustomize = {
58109
+ version: 1,
58110
+ overridable: FAN_CONTROL_TARGETS.map((target) => ({
58111
+ path: target.path,
58112
+ by: target.id
58113
+ })),
58114
+ targets: FAN_CONTROL_TARGETS
58115
+ };
56405
58116
  var fanControlCapability = {
56406
58117
  name: "fan-control",
56407
58118
  scope: "device",
@@ -56436,6 +58147,18 @@ var fanControlCapability = {
56436
58147
  }), zod.z.void(), {
56437
58148
  kind: "mutation",
56438
58149
  auth: "protected"
58150
+ }),
58151
+ /**
58152
+ * Sets one oscillation axis: its switch, fixed angle and/or sweep bounds.
58153
+ * Fields left out are untouched. A field linked in Customize is forwarded
58154
+ * to its linked source (D1034); otherwise the native provider serves it;
58155
+ * neither → `axis-not-linked`. Ranges are checked against the axis limits
58156
+ * before anything is written; writes run in order and stop at the first
58157
+ * failure, which the result names.
58158
+ */
58159
+ setOscillationAxis: require_sleep.optionalMethod(SetOscillationAxisInputSchema, FanOscillationAxisResultSchema, {
58160
+ kind: "mutation",
58161
+ auth: "protected"
56439
58162
  })
56440
58163
  },
56441
58164
  status: {
@@ -56447,6 +58170,7 @@ var fanControlCapability = {
56447
58170
  * sliders read `speed` for live updates.
56448
58171
  */
56449
58172
  runtimeState: FanControlStatusSchema,
58173
+ customize: fanControlCustomize,
56450
58174
  /**
56451
58175
  * Runtime-state durability: **session** — as `brightness`.
56452
58176
  *
@@ -56469,12 +58193,15 @@ var fanControlCapability = {
56469
58193
  //#endregion
56470
58194
  //#region src/capabilities/fan-presets.cap.ts
56471
58195
  /**
56472
- * fan-presets — named settings the operator composes for a fan ("Night":
56473
- * speed 25 %, oscillation off, the room's light off). A preset is a short
56474
- * sequence of action steps over the fan itself and the devices that sit in the
56475
- * same container (its siblings); applying it runs the steps in order and
56476
- * reports every one, so a caller tells "applied" from "the speed was set but
56477
- * the light step failed" without parsing text.
58196
+ * fan-presets — named settings the operator keeps for a fan ("Night": speed
58197
+ * 25 %, horizontal sweep off, angle 30°). A preset is a DESIRED fan-control
58198
+ * state (D1034): the fields it names, nothing else. Applying it calls the
58199
+ * fan's own `fan-control` methods — `setPreset`, `setPercentage`,
58200
+ * `setDirection`, `setOscillationAxis` — and an axis the operator linked in
58201
+ * Customize reaches its sibling device through that link, never through a
58202
+ * step the preset stores. Every field is reported (applied / failed / not-run
58203
+ * / refused), so a caller tells "applied" from "the speed was set but the
58204
+ * angle was refused" without parsing text.
56478
58205
  *
56479
58206
  * It is a Customize `config` extension of a fan: the presets are the
56480
58207
  * operator's, stored per device (D865), and the editor is derived from the
@@ -56483,17 +58210,33 @@ var fanControlCapability = {
56483
58210
  * (a scene, a switch, a button) offer it.
56484
58211
  */
56485
58212
  var FAN_PRESETS_MAX = 12;
56486
- var FAN_PRESET_STEPS_MAX = 20;
58213
+ /** One axis as a preset wants it; an absent field is left as it is. */
58214
+ var FanPresetAxisSchema = zod.z.object({
58215
+ oscillating: zod.z.boolean().optional(),
58216
+ angle: zod.z.number().optional(),
58217
+ sweepFrom: zod.z.number().optional(),
58218
+ sweepTo: zod.z.number().optional()
58219
+ });
58220
+ /** The fan-control state a preset sets; an absent field is left as it is. */
58221
+ var FanPresetStateSchema = zod.z.object({
58222
+ speed: zod.z.number().min(0).max(100).optional(),
58223
+ /** The fan's own preset mode (or the linked select's option). */
58224
+ preset: zod.z.string().min(1).optional(),
58225
+ direction: FanDirectionSchema.optional(),
58226
+ oscillationAxes: zod.z.object({
58227
+ horizontal: FanPresetAxisSchema.optional(),
58228
+ vertical: FanPresetAxisSchema.optional()
58229
+ }).optional()
58230
+ });
56487
58231
  var FanPresetSchema = zod.z.object({
56488
58232
  /** Stable key; never reused after a delete within one device's list. */
56489
58233
  id: zod.z.string().min(1).max(64),
56490
58234
  /** What the operator and a voice assistant call it. */
56491
58235
  name: zod.z.string().trim().min(1).max(40),
56492
- steps: zod.z.array(ActionStepSchema).min(1).max(20)
58236
+ state: FanPresetStateSchema
56493
58237
  });
56494
58238
  var FAN_PRESETS_REFUSALS = [
56495
- "not-sibling",
56496
- "bad-target",
58239
+ "empty-state",
56497
58240
  "duplicate-name",
56498
58241
  "duplicate-id",
56499
58242
  "too-many",
@@ -56506,66 +58249,50 @@ var FanPresetsSetResultSchema = zod.z.discriminatedUnion("status", [zod.z.object
56506
58249
  }), zod.z.object({
56507
58250
  status: zod.z.literal("refused"),
56508
58251
  reason: FanPresetsRefusalSchema,
56509
- /** Names the preset and step at fault. */
58252
+ /** Names the preset at fault. */
56510
58253
  detail: zod.z.string()
56511
58254
  })]);
56512
- var FanPresetStepResultSchema = zod.z.object({
56513
- index: zod.z.number().int().nonnegative(),
58255
+ var FanPresetFieldResultSchema = zod.z.object({
58256
+ /** The state path: `speed`, `preset`, `direction`, `oscillationAxes.horizontal.angle`. */
58257
+ field: zod.z.string(),
56514
58258
  outcome: zod.z.enum([
56515
58259
  "applied",
56516
58260
  "failed",
56517
58261
  "not-run",
56518
58262
  "refused"
56519
58263
  ]),
56520
- deviceId: zod.z.number().int().nonnegative().optional(),
56521
- cap: zod.z.string().optional(),
56522
- method: zod.z.string().optional(),
56523
58264
  /** The cause, for every outcome but `applied`. */
56524
58265
  message: zod.z.string().optional()
56525
58266
  });
56526
58267
  var FanPresetApplyResultSchema = zod.z.object({
56527
- /** `applied`: every step ran. `partial`: some ran, one failed. `refused`: nothing ran. */
58268
+ /** `applied`: every field landed. `partial`: some did, one did not. `refused`: nothing ran. */
56528
58269
  status: zod.z.enum([
56529
58270
  "applied",
56530
58271
  "partial",
56531
58272
  "refused"
56532
58273
  ]),
56533
- steps: zod.z.array(FanPresetStepResultSchema)
58274
+ fields: zod.z.array(FanPresetFieldResultSchema)
56534
58275
  });
56535
- /** The fan's own readings a capture may take. */
58276
+ /** The fan-control fields a capture may take. */
56536
58277
  var FAN_CAPTURE_FIELDS = [
56537
58278
  "speed",
56538
- "oscillating",
56539
58279
  "direction",
56540
- "preset"
58280
+ "preset",
58281
+ "oscillationAxes"
56541
58282
  ];
56542
58283
  var FanCaptureFieldSchema = zod.z.enum(FAN_CAPTURE_FIELDS);
56543
58284
  var FanCaptureOmissionSchema = zod.z.object({
56544
- /** A fan field (`speed`) or `step <n>` for a sibling step. */
58285
+ /** A state path (`speed`, `oscillationAxes.vertical.angle`). */
56545
58286
  what: zod.z.string(),
56546
- /** Why no value was taken: unknown reading (never stored as 0, D393), or a step that cannot be read. */
58287
+ /** Why no value was taken: an unknown reading is never stored as 0 (D393). */
56547
58288
  reason: zod.z.string()
56548
58289
  });
56549
- /** Where a proposed step belongs in the review list. */
56550
- var FAN_CAPTURE_GROUPS = [
56551
- "fan",
56552
- "oscillation",
56553
- "angles"
56554
- ];
56555
- var FanCaptureGroupSchema = zod.z.enum(FAN_CAPTURE_GROUPS);
56556
- var FanCaptureItemSchema = zod.z.object({
56557
- group: FanCaptureGroupSchema,
56558
- /** What the step sets, in the operator's words (a device name, a fan field). */
56559
- label: zod.z.string()
56560
- });
56561
58290
  var FanPresetCaptureResultSchema = zod.z.object({
56562
- /** The steps filled from the device's current values; NOT saved. */
56563
- steps: zod.z.array(ActionStepSchema),
56564
- /** One entry per step, same order: its review group and label. */
56565
- items: zod.z.array(FanCaptureItemSchema),
58291
+ /** The fan's CURRENT fan-control state, as a preset; NOT saved. */
58292
+ state: FanPresetStateSchema,
56566
58293
  omitted: zod.z.array(FanCaptureOmissionSchema)
56567
58294
  });
56568
- var deviceInput$2 = zod.z.object({ deviceId: zod.z.number().int().nonnegative() });
58295
+ var deviceInput$1 = zod.z.object({ deviceId: zod.z.number().int().nonnegative() });
56569
58296
  var fanPresetsCustomize = {
56570
58297
  version: 1,
56571
58298
  targets: [{
@@ -56583,28 +58310,22 @@ var fanPresetsCapability = {
56583
58310
  scope: "system",
56584
58311
  mode: "singleton",
56585
58312
  methods: {
56586
- getPresets: require_sleep.method(deviceInput$2, zod.z.array(FanPresetSchema), { auth: "protected" }),
56587
- setPresets: require_sleep.method(deviceInput$2.extend({ presets: zod.z.array(FanPresetSchema).max(12) }), FanPresetsSetResultSchema, {
58313
+ getPresets: require_sleep.method(deviceInput$1, zod.z.array(FanPresetSchema), { auth: "protected" }),
58314
+ setPresets: require_sleep.method(deviceInput$1.extend({ presets: zod.z.array(FanPresetSchema).max(12) }), FanPresetsSetResultSchema, {
56588
58315
  kind: "mutation",
56589
58316
  auth: "admin"
56590
58317
  }),
56591
- applyPreset: require_sleep.method(deviceInput$2.extend({ presetId: zod.z.string().min(1) }), FanPresetApplyResultSchema, {
58318
+ applyPreset: require_sleep.method(deviceInput$1.extend({ presetId: zod.z.string().min(1) }), FanPresetApplyResultSchema, {
56592
58319
  kind: "mutation",
56593
58320
  auth: "protected"
56594
58321
  }),
56595
58322
  /**
56596
- * Fills steps from the CURRENT values: the fan's own fields named in
56597
- * `fields` (all when absent) and the sibling `steps` already composed
56598
- * (a control value, a switch state). With no `steps` it proposes EVERY
56599
- * switch and control in the fan's container, ordered angle bounds,
56600
- * oscillation, fixed angles, fan fields, speed last. A reading that is
56601
- * unknown is left out and named in `omitted`, never captured as 0. Nothing
56602
- * is saved.
58323
+ * The fan's CURRENT fan-control state as a preset: the fields named in
58324
+ * `fields` (all when absent), read from its merged slice — a field linked
58325
+ * in Customize reads its link. A reading that is unknown is left out and
58326
+ * named in `omitted`, never captured as 0. Nothing is saved.
56603
58327
  */
56604
- capturePreset: require_sleep.method(deviceInput$2.extend({
56605
- fields: zod.z.array(FanCaptureFieldSchema).optional(),
56606
- steps: zod.z.array(ActionStepSchema).max(20).default([])
56607
- }), FanPresetCaptureResultSchema, { auth: "protected" })
58328
+ capturePreset: require_sleep.method(deviceInput$1.extend({ fields: zod.z.array(FanCaptureFieldSchema).optional() }), FanPresetCaptureResultSchema, { auth: "protected" })
56608
58329
  },
56609
58330
  customize: fanPresetsCustomize
56610
58331
  };
@@ -56842,8 +58563,7 @@ var groupActiveCapability = {
56842
58563
  require_composed_stable_id.DeviceType.Valve,
56843
58564
  require_composed_stable_id.DeviceType.Lock,
56844
58565
  require_composed_stable_id.DeviceType.MediaPlayer,
56845
- require_composed_stable_id.DeviceType.Climate,
56846
- require_composed_stable_id.DeviceType.Thermostat
58566
+ require_composed_stable_id.DeviceType.Climate
56847
58567
  ],
56848
58568
  methods: {},
56849
58569
  status: {
@@ -56894,7 +58614,6 @@ var groupCommandsCapability = {
56894
58614
  require_composed_stable_id.DeviceType.Valve,
56895
58615
  require_composed_stable_id.DeviceType.Lock,
56896
58616
  require_composed_stable_id.DeviceType.MediaPlayer,
56897
- require_composed_stable_id.DeviceType.Thermostat,
56898
58617
  require_composed_stable_id.DeviceType.Climate
56899
58618
  ],
56900
58619
  methods: {},
@@ -56952,7 +58671,6 @@ var groupStatusCapability = {
56952
58671
  require_composed_stable_id.DeviceType.Valve,
56953
58672
  require_composed_stable_id.DeviceType.Lock,
56954
58673
  require_composed_stable_id.DeviceType.MediaPlayer,
56955
- require_composed_stable_id.DeviceType.Thermostat,
56956
58674
  require_composed_stable_id.DeviceType.Climate
56957
58675
  ],
56958
58676
  methods: {},
@@ -57328,7 +59046,7 @@ var heatingValveCapability = {
57328
59046
  scope: "device",
57329
59047
  deviceNative: true,
57330
59048
  mode: "singleton",
57331
- deviceTypes: [require_composed_stable_id.DeviceType.Thermostat],
59049
+ deviceTypes: [require_composed_stable_id.DeviceType.Climate],
57332
59050
  methods: {},
57333
59051
  status: {
57334
59052
  schema: HeatingValveStatusSchema,
@@ -57360,30 +59078,42 @@ var heatingValveCapability = {
57360
59078
  * retried in a loop - D49); a future one is re-armed.
57361
59079
  *
57362
59080
  * What a device may be run for, and for how long at most, is per device type
57363
- * ({@link TIMED_RUN_LIMITS}): the maximum is a safety bound, not a preference,
59081
+ * and role ({@link timedRunLimitOf}): the maximum is a safety bound, not a preference,
57364
59082
  * so a request above it is REFUSED with a typed reason, never clamped.
57365
59083
  */
57366
59084
  var TimedRunUnitSchema = zod.z.enum(["s", "min"]);
57367
59085
  /** What a timed run switches: the `switch` cap's `setState` or the fountain's `setPump`. */
57368
59086
  var TimedRunActuatorSchema = zod.z.enum(["switch", "pet-fountain"]);
57369
- /** The longest run, per device type. Only these types are offered `timed-run`. */
57370
- var TIMED_RUN_LIMITS = {
57371
- [require_composed_stable_id.DeviceType.Heater]: {
57372
- actuator: "switch",
57373
- maxSeconds: 10800,
57374
- unit: "min",
57375
- quickRunDefault: 30
57376
- },
57377
- [require_composed_stable_id.DeviceType.PetFountain]: {
57378
- actuator: "pet-fountain",
57379
- maxSeconds: 300,
57380
- unit: "s",
57381
- quickRunDefault: 60
57382
- }
59087
+ /** A plug-in heater (switch + `switch-heater`): up to 3 h, in minutes. */
59088
+ var TIMED_RUN_HEATER_LIMIT = {
59089
+ actuator: "switch",
59090
+ maxSeconds: 10800,
59091
+ unit: "min",
59092
+ quickRunDefault: 30
57383
59093
  };
57384
- var TIMED_RUN_DEVICE_TYPES = [require_composed_stable_id.DeviceType.Heater, require_composed_stable_id.DeviceType.PetFountain];
57385
- function timedRunLimitOf(deviceType) {
57386
- return TIMED_RUN_LIMITS[deviceType] ?? null;
59094
+ /** A pet fountain's pump: up to 5 min, in seconds. */
59095
+ var TIMED_RUN_PET_FOUNTAIN_LIMIT = {
59096
+ actuator: "pet-fountain",
59097
+ maxSeconds: 300,
59098
+ unit: "s",
59099
+ quickRunDefault: 60
59100
+ };
59101
+ /**
59102
+ * The device types `timed-run` may be offered on. A `switch` is narrowed by
59103
+ * role ({@link TIMED_RUN_DEVICE_ROLES}): only a plug-in heater runs on a timer.
59104
+ */
59105
+ var TIMED_RUN_DEVICE_TYPES = [require_composed_stable_id.DeviceType.Switch, require_composed_stable_id.DeviceType.PetFountain];
59106
+ /** The roles that make a device of these types timed-run-able (D1033). */
59107
+ var TIMED_RUN_DEVICE_ROLES = { [require_composed_stable_id.DeviceType.Switch]: [require_composed_stable_id.DeviceRole.SwitchHeater] };
59108
+ /**
59109
+ * The longest run of a device, by its type AND role (D1033): a `switch` is a
59110
+ * heater only with role `switch-heater`, a pet fountain always is what it is.
59111
+ * `null` - the device is not offered `timed-run`.
59112
+ */
59113
+ function timedRunLimitOf(deviceType, role) {
59114
+ if (deviceType === require_composed_stable_id.DeviceType.PetFountain) return TIMED_RUN_PET_FOUNTAIN_LIMIT;
59115
+ if (deviceType === require_composed_stable_id.DeviceType.Switch && role === require_composed_stable_id.DeviceRole.SwitchHeater) return TIMED_RUN_HEATER_LIMIT;
59116
+ return null;
57387
59117
  }
57388
59118
  var MS_PER_SECOND = 1e3;
57389
59119
  var MS_PER_MINUTE = 6e4;
@@ -57465,6 +59195,7 @@ var timedRunCapability = {
57465
59195
  kind: "wrapper",
57466
59196
  defaultActive: true,
57467
59197
  deviceTypes: TIMED_RUN_DEVICE_TYPES,
59198
+ deviceRoles: TIMED_RUN_DEVICE_ROLES,
57468
59199
  deviceConfig: { ui: {
57469
59200
  kind: "derived-form",
57470
59201
  builderId: "timed-run",
@@ -57656,8 +59387,7 @@ var HERO_SCENE_BY_TYPE = {
57656
59387
  [require_composed_stable_id.DeviceType.Siren]: "siren",
57657
59388
  [require_composed_stable_id.DeviceType.Switch]: "plug",
57658
59389
  [require_composed_stable_id.DeviceType.Sensor]: "sensor-sparkline",
57659
- [require_composed_stable_id.DeviceType.Thermostat]: "thermostat",
57660
- [require_composed_stable_id.DeviceType.Climate]: "ac",
59390
+ [require_composed_stable_id.DeviceType.Climate]: "thermostat",
57661
59391
  [require_composed_stable_id.DeviceType.Button]: "button",
57662
59392
  [require_composed_stable_id.DeviceType.EventEmitter]: "event-stream",
57663
59393
  [require_composed_stable_id.DeviceType.Update]: "update",
@@ -57685,7 +59415,6 @@ var HERO_SCENE_BY_TYPE = {
57685
59415
  [require_composed_stable_id.DeviceType.PetFountain]: "pet-fountain",
57686
59416
  [require_composed_stable_id.DeviceType.Dishwasher]: "dishwasher",
57687
59417
  [require_composed_stable_id.DeviceType.Washer]: "washer",
57688
- [require_composed_stable_id.DeviceType.Heater]: "heater",
57689
59418
  [require_composed_stable_id.DeviceType.Dryer]: "dryer",
57690
59419
  [require_composed_stable_id.DeviceType.Gateway]: "gateway"
57691
59420
  };
@@ -57710,6 +59439,14 @@ var HERO_SCENE_BY_ROLE = {
57710
59439
  [require_composed_stable_id.DeviceRole.CoverWindow]: "inherit",
57711
59440
  [require_composed_stable_id.DeviceRole.BinaryHelper]: "inherit",
57712
59441
  [require_composed_stable_id.DeviceRole.Outlet]: "plug",
59442
+ [require_composed_stable_id.DeviceRole.SwitchHeater]: "heater",
59443
+ [require_composed_stable_id.DeviceRole.SwitchFan]: "fan",
59444
+ [require_composed_stable_id.DeviceRole.ClimateAc]: "ac",
59445
+ [require_composed_stable_id.DeviceRole.ClimateThermostat]: "inherit",
59446
+ [require_composed_stable_id.DeviceRole.ClimateFloor]: "inherit",
59447
+ [require_composed_stable_id.DeviceRole.ClimateRadiator]: "inherit",
59448
+ [require_composed_stable_id.DeviceRole.ClimateHeater]: "inherit",
59449
+ [require_composed_stable_id.DeviceRole.ClimateHeatPumpCircuit]: "inherit",
57713
59450
  [require_composed_stable_id.DeviceRole.MotionSensor]: "presence",
57714
59451
  [require_composed_stable_id.DeviceRole.ContactSensor]: "contact",
57715
59452
  [require_composed_stable_id.DeviceRole.LeakSensor]: "inherit",
@@ -58273,10 +60010,7 @@ function trailingOf(facts) {
58273
60010
  * A type whose primary is a named control, not its power: a climate row is the mode
58274
60011
  * (which carries "off") and the setpoint, with no power toggle.
58275
60012
  */
58276
- var ROW_PRIMARY_BY_TYPE = {
58277
- [require_composed_stable_id.DeviceType.Climate]: "climate.mode",
58278
- [require_composed_stable_id.DeviceType.Thermostat]: "climate.mode"
58279
- };
60013
+ var ROW_PRIMARY_BY_TYPE = { [require_composed_stable_id.DeviceType.Climate]: "climate.mode" };
58280
60014
  function primaryOf(model) {
58281
60015
  const named = ROW_PRIMARY_BY_TYPE[model.type];
58282
60016
  if (named !== void 0) {
@@ -58309,7 +60043,6 @@ function primaryOf(model) {
58309
60043
  */
58310
60044
  var ROW_EXTRAS_BY_TYPE = {
58311
60045
  [require_composed_stable_id.DeviceType.Climate]: ["climate.target"],
58312
- [require_composed_stable_id.DeviceType.Thermostat]: ["climate.target"],
58313
60046
  [require_composed_stable_id.DeviceType.Vacuum]: ["vacuum.base"],
58314
60047
  [require_composed_stable_id.DeviceType.LawnMower]: ["mower.dock"],
58315
60048
  [require_composed_stable_id.DeviceType.MediaPlayer]: ["volume.level", REMOTE_OPEN_ACTION_ID]
@@ -58432,7 +60165,11 @@ var heroLayoutCapability = {
58432
60165
  auth: "protected",
58433
60166
  role: "viewer"
58434
60167
  }),
58435
- getLayout: require_sleep.method(zod.z.object({ deviceType: zod.z.string() }), HeroLayoutRowsSchema, {
60168
+ /** The fixed rows of a kind: the type, refined by the role (D1033 — a heater is a switch). */
60169
+ getLayout: require_sleep.method(zod.z.object({
60170
+ deviceType: zod.z.string(),
60171
+ role: zod.z.string().nullable().optional()
60172
+ }), HeroLayoutRowsSchema, {
58436
60173
  auth: "protected",
58437
60174
  role: "viewer"
58438
60175
  })
@@ -58483,6 +60220,11 @@ var humidifierCapability = {
58483
60220
  deviceNative: true,
58484
60221
  mode: "singleton",
58485
60222
  deviceTypes: [require_composed_stable_id.DeviceType.Humidifier],
60223
+ power: {
60224
+ kind: "field",
60225
+ field: "on",
60226
+ set: "setOn"
60227
+ },
58486
60228
  methods: {
58487
60229
  setOn: require_sleep.method(zod.z.object({
58488
60230
  deviceId: zod.z.number().int().nonnegative(),
@@ -58558,7 +60300,7 @@ var humiditySensorCapability = {
58558
60300
  scope: "device",
58559
60301
  deviceNative: true,
58560
60302
  mode: "singleton",
58561
- deviceTypes: [require_composed_stable_id.DeviceType.Sensor, require_composed_stable_id.DeviceType.Thermostat],
60303
+ deviceTypes: [require_composed_stable_id.DeviceType.Sensor, require_composed_stable_id.DeviceType.Climate],
58562
60304
  methods: {},
58563
60305
  status: {
58564
60306
  schema: HumiditySensorStatusSchema,
@@ -76452,7 +78194,18 @@ var OauthIntegrationDescriptorSchema = zod.z.object({
76452
78194
  * The value is baked into the authorization code at `/authorize` and travels
76453
78195
  * on the tokens, so editing this field changes FUTURE links only.
76454
78196
  */
76455
- refreshTokenTtlSec: zod.z.union([zod.z.number().int().positive(), zod.z.literal("never")]).optional()
78197
+ refreshTokenTtlSec: zod.z.union([zod.z.number().int().positive(), zod.z.literal("never")]).optional(),
78198
+ /**
78199
+ * The integration instances an account can be linked to (planning#415),
78200
+ * beside the default one. `/api/oauth2/authorize?instance=<id>` is accepted
78201
+ * only for an id listed here; with no `instance=` the link is made to the
78202
+ * default instance, which is never listed and always accepted — it is the
78203
+ * address third parties already hold. Omit for a single-instance integration.
78204
+ */
78205
+ instances: zod.z.array(zod.z.object({
78206
+ id: zod.z.string(),
78207
+ displayName: zod.z.string()
78208
+ })).optional()
76456
78209
  });
76457
78210
  var oauthIntegrationCapability = {
76458
78211
  name: "oauth-integration",
@@ -77128,6 +78881,11 @@ var petFountainCapability = {
77128
78881
  deviceNative: true,
77129
78882
  mode: "singleton",
77130
78883
  deviceTypes: [require_composed_stable_id.DeviceType.PetFountain],
78884
+ power: {
78885
+ kind: "field",
78886
+ field: "pumpRunning",
78887
+ set: "setPump"
78888
+ },
77131
78889
  methods: {
77132
78890
  /** Start or stop the pump. */
77133
78891
  setPump: require_sleep.method(zod.z.object({
@@ -80042,7 +81800,6 @@ var POWER_METER_DEVICE_TYPES = [
80042
81800
  require_composed_stable_id.DeviceType.Light,
80043
81801
  require_composed_stable_id.DeviceType.Fan,
80044
81802
  require_composed_stable_id.DeviceType.Climate,
80045
- require_composed_stable_id.DeviceType.Thermostat,
80046
81803
  require_composed_stable_id.DeviceType.Humidifier,
80047
81804
  require_composed_stable_id.DeviceType.WaterHeater,
80048
81805
  require_composed_stable_id.DeviceType.MediaPlayer,
@@ -80051,8 +81808,7 @@ var POWER_METER_DEVICE_TYPES = [
80051
81808
  require_composed_stable_id.DeviceType.Dishwasher,
80052
81809
  require_composed_stable_id.DeviceType.Vacuum,
80053
81810
  require_composed_stable_id.DeviceType.LawnMower,
80054
- require_composed_stable_id.DeviceType.PetFeeder,
80055
- require_composed_stable_id.DeviceType.Heater
81811
+ require_composed_stable_id.DeviceType.PetFeeder
80056
81812
  ];
80057
81813
  /** Everything but a bare `Sensor`: a sensor that takes its reading from another sensor adds nothing. */
80058
81814
  var POWER_METER_CUSTOMIZE_DEVICE_TYPES = POWER_METER_DEVICE_TYPES.filter((type) => type !== require_composed_stable_id.DeviceType.Sensor);
@@ -80166,146 +81922,6 @@ var powerMeterCapability = {
80166
81922
  customize: powerMeterCustomize
80167
81923
  };
80168
81924
  //#endregion
80169
- //#region src/capabilities/power-source.cap.ts
80170
- /**
80171
- * power-source — a device that hangs is powered by a smart switch, and the
80172
- * operator picks that switch in the device's Customize. The device then offers
80173
- * power on, power off and a forced restart (switch off, wait, switch on).
80174
- *
80175
- * Manual by default: nothing here restarts a device by itself. The one
80176
- * exception (D997) is a device's OWN provider calling `forceRestart` for its own
80177
- * device as a bounded self-recovery (unreachable for a long stretch, linked,
80178
- * one attempt per cooldown, never with a live session); Velux is the first. It
80179
- * is not the native `reboot` cap and never replaces or wraps it: `reboot` talks
80180
- * to the device, this cuts the power of the device that no longer answers.
80181
- *
80182
- * The link is a Customize extension (`add`): one scalar target whose source is
80183
- * the switch. The stored composition is the ONE copy of the link and of
80184
- * `offSeconds` (`powerSourceLinkOfComposition`, D676); the composed slice only
80185
- * mirrors the switch state for the UI. The methods are served by the
80186
- * `core-blocks` system provider, so they are `systemMethod`s and carry a
80187
- * top-level `deviceId`.
80188
- *
80189
- * Every action answers a typed result and never throws for an expected
80190
- * refusal, so a caller tells "the switch is offline" from "a restart is
80191
- * already running" without parsing text.
80192
- */
80193
- /** Bounds of the off time of a forced restart, in seconds. */
80194
- var POWER_SOURCE_OFF_SECONDS_MIN = 3;
80195
- var POWER_SOURCE_OFF_SECONDS_MAX = 120;
80196
- var POWER_SOURCE_OFF_SECONDS_DEFAULT = 10;
80197
- var PowerSourceRefusalReasonSchema = zod.z.enum([
80198
- "no-power-source",
80199
- "switch-missing",
80200
- "switch-offline",
80201
- "switch-unknown",
80202
- "restart-in-progress",
80203
- "switch-call-failed"
80204
- ]);
80205
- var PowerSourceActionResultSchema = zod.z.discriminatedUnion("accepted", [zod.z.object({ accepted: zod.z.literal(true) }), zod.z.object({
80206
- accepted: zod.z.literal(false),
80207
- reason: PowerSourceRefusalReasonSchema,
80208
- /** One line for the operator, naming the switch. */
80209
- message: zod.z.string()
80210
- })]);
80211
- var PowerSourceInfoSchema = zod.z.object({
80212
- /** False when the device has no power source linked; the rest is then empty. */
80213
- linked: zod.z.boolean(),
80214
- switchDeviceId: zod.z.number().nullable(),
80215
- switchName: zod.z.string().nullable(),
80216
- /** The switch's on/off state, or null when it is unknown. Never false for unknown (D393). */
80217
- switchOn: zod.z.boolean().nullable(),
80218
- switchOnline: zod.z.boolean().nullable(),
80219
- restartInProgress: zod.z.boolean(),
80220
- offSeconds: zod.z.number().int()
80221
- });
80222
- /** The composed slice: the switch state the link mirrors, plus the stored off time. */
80223
- var PowerSourceStateSchema = zod.z.object({
80224
- /** Null while the switch has not reported: unknown is never `false` (D393). */
80225
- switchOn: zod.z.boolean().nullable(),
80226
- offSeconds: zod.z.number().int(),
80227
- lastFetchedAt: zod.z.number()
80228
- });
80229
- var POWER_SOURCE_DEVICE_TYPES = [
80230
- require_composed_stable_id.DeviceType.Gateway,
80231
- require_composed_stable_id.DeviceType.Camera,
80232
- require_composed_stable_id.DeviceType.Sensor,
80233
- require_composed_stable_id.DeviceType.MediaPlayer,
80234
- require_composed_stable_id.DeviceType.Vacuum,
80235
- require_composed_stable_id.DeviceType.Generic,
80236
- require_composed_stable_id.DeviceType.Washer,
80237
- require_composed_stable_id.DeviceType.Dryer,
80238
- require_composed_stable_id.DeviceType.Dishwasher,
80239
- require_composed_stable_id.DeviceType.PetFountain,
80240
- require_composed_stable_id.DeviceType.Fan,
80241
- require_composed_stable_id.DeviceType.Humidifier,
80242
- require_composed_stable_id.DeviceType.Climate,
80243
- require_composed_stable_id.DeviceType.WaterHeater
80244
- ];
80245
- var powerSourceCustomize = {
80246
- version: 1,
80247
- targets: [{
80248
- id: "switch",
80249
- cardinality: "scalar",
80250
- vocabulary: {
80251
- cap: "power-source",
80252
- stateField: "switchOn"
80253
- },
80254
- deviceTypes: POWER_SOURCE_DEVICE_TYPES,
80255
- apply: "add",
80256
- path: "switchOn",
80257
- sources: [{
80258
- kind: "switch",
80259
- transforms: [{ kind: "identity" }]
80260
- }],
80261
- companions: [{
80262
- kind: "constant",
80263
- path: "offSeconds",
80264
- value: 10,
80265
- when: "add",
80266
- formerValues: [0]
80267
- }, {
80268
- kind: "clock",
80269
- path: "lastFetchedAt",
80270
- when: "always"
80271
- }],
80272
- sourceReport: { status: "assignment-status" }
80273
- }]
80274
- };
80275
- var deviceInput$1 = zod.z.object({ deviceId: zod.z.number().int().nonnegative() });
80276
- var powerSourceCapability = {
80277
- name: "power-source",
80278
- scope: "device",
80279
- mode: "singleton",
80280
- deviceTypes: POWER_SOURCE_DEVICE_TYPES,
80281
- methods: {
80282
- getStatus: require_sleep.systemMethod(deviceInput$1, PowerSourceInfoSchema, { auth: "protected" }),
80283
- powerOn: require_sleep.systemMethod(deviceInput$1, PowerSourceActionResultSchema, {
80284
- kind: "mutation",
80285
- auth: "protected"
80286
- }),
80287
- powerOff: require_sleep.systemMethod(deviceInput$1, PowerSourceActionResultSchema, {
80288
- kind: "mutation",
80289
- auth: "protected"
80290
- }),
80291
- forceRestart: require_sleep.systemMethod(deviceInput$1, PowerSourceActionResultSchema, {
80292
- kind: "mutation",
80293
- auth: "protected"
80294
- })
80295
- },
80296
- runtimeState: PowerSourceStateSchema,
80297
- customize: powerSourceCustomize,
80298
- /**
80299
- * Runtime-state durability: **session** — mirrored from the linked switch on
80300
- * its next report; a restored value would outlive the reading it names.
80301
- *
80302
- * See `RuntimeStateDurability`. Enforced by
80303
- * `scripts/check-runtime-state-durability.ts`.
80304
- */
80305
- durability: "session",
80306
- history: "none"
80307
- };
80308
- //#endregion
80309
81925
  //#region src/capabilities/presence.cap.ts
80310
81926
  /**
80311
81927
  * Presence cap. Models HA `person.*` and `device_tracker.*` entities
@@ -85273,9 +86889,7 @@ var RUNNING_CUSTOMIZE_DEVICE_TYPES = [
85273
86889
  require_composed_stable_id.DeviceType.Humidifier,
85274
86890
  require_composed_stable_id.DeviceType.Fan,
85275
86891
  require_composed_stable_id.DeviceType.Climate,
85276
- require_composed_stable_id.DeviceType.Thermostat,
85277
- require_composed_stable_id.DeviceType.PetFeeder,
85278
- require_composed_stable_id.DeviceType.Heater
86892
+ require_composed_stable_id.DeviceType.PetFeeder
85279
86893
  ];
85280
86894
  var runningStateCapability = {
85281
86895
  name: "running-state",
@@ -86846,6 +88460,13 @@ var SsoBridgeClaimsSchema = zod.z.object({
86846
88460
  /** OAuth authorization-code binding — set only on `oauth-code` tokens. */
86847
88461
  redirectUri: zod.z.string().optional(),
86848
88462
  integrationId: zod.z.string().optional(),
88463
+ /**
88464
+ * The integration INSTANCE an OAuth link was made for (planning#415). Set on
88465
+ * `oauth-code`, `oauth-access` and `oauth-refresh` tokens of a link made
88466
+ * with `instance=`; absent on a link to the default instance. A cloud relay
88467
+ * reads it off the access token to route; the hub answers from the session.
88468
+ */
88469
+ instanceId: zod.z.string().optional(),
86849
88470
  /** JWT ID — unique per issued code; consumed-set enforces single-use. */
86850
88471
  jti: zod.z.string().optional(),
86851
88472
  /** PKCE S256 challenge — set only on `oauth-code` tokens issued to a public
@@ -87963,8 +89584,7 @@ var switchCapability = {
87963
89584
  require_composed_stable_id.DeviceType.Switch,
87964
89585
  require_composed_stable_id.DeviceType.Siren,
87965
89586
  require_composed_stable_id.DeviceType.Light,
87966
- require_composed_stable_id.DeviceType.Fan,
87967
- require_composed_stable_id.DeviceType.Heater
89587
+ require_composed_stable_id.DeviceType.Fan
87968
89588
  ],
87969
89589
  methods: { setState: require_sleep.method(zod.z.object({
87970
89590
  deviceId: zod.z.number(),
@@ -88828,7 +90448,7 @@ var temperatureSensorCapability = {
88828
90448
  scope: "device",
88829
90449
  deviceNative: true,
88830
90450
  mode: "singleton",
88831
- deviceTypes: [require_composed_stable_id.DeviceType.Sensor, require_composed_stable_id.DeviceType.Thermostat],
90451
+ deviceTypes: [require_composed_stable_id.DeviceType.Sensor, require_composed_stable_id.DeviceType.Climate],
88832
90452
  methods: {},
88833
90453
  status: {
88834
90454
  schema: TemperatureSensorStatusSchema,
@@ -89908,6 +91528,8 @@ var OauthSessionSummarySchema = zod.z.object({
89908
91528
  userId: zod.z.string(),
89909
91529
  username: zod.z.string(),
89910
91530
  integrationId: zod.z.string(),
91531
+ /** The instance the link was made for; `null` = the default instance. */
91532
+ instanceId: zod.z.string().nullable().optional(),
89911
91533
  scopes: zod.z.array(TokenScopeSchema),
89912
91534
  createdAt: zod.z.number(),
89913
91535
  lastUsedAt: zod.z.number(),
@@ -90036,6 +91658,9 @@ var userManagementCapability = {
90036
91658
  }),
90037
91659
  oauthIssueCode: require_sleep.method(zod.z.object({
90038
91660
  integrationId: zod.z.string(),
91661
+ /** The integration instance the link is for. Omit for the default
91662
+ * instance — never pass the addon id to mean it. */
91663
+ instanceId: zod.z.string().optional(),
90039
91664
  userId: zod.z.string(),
90040
91665
  username: zod.z.string(),
90041
91666
  scopes: zod.z.array(TokenScopeSchema),
@@ -90077,7 +91702,13 @@ var userManagementCapability = {
90077
91702
  oauthVerifyAccessToken: require_sleep.method(zod.z.object({ token: zod.z.string() }), zod.z.object({
90078
91703
  userId: zod.z.string(),
90079
91704
  username: zod.z.string(),
90080
- scopes: zod.z.array(TokenScopeSchema)
91705
+ scopes: zod.z.array(TokenScopeSchema),
91706
+ /** The instance the link was made for, read from the SESSION.
91707
+ * Absent = the default instance. `oauthLinkServesInstance` is the
91708
+ * helper a per-instance route calls to compare it with the instance
91709
+ * of its path; no route declares `perInstance` yet (the Alexa
91710
+ * per-instance route, T3, is the first consumer). */
91711
+ instanceId: zod.z.string().optional()
90081
91712
  }).nullable(), { access: "view" }),
90082
91713
  listExternalIdentities: require_sleep.method(zod.z.object({ userId: zod.z.string() }), zod.z.array(ExternalIdentitySchema), { auth: "admin" }),
90083
91714
  /** The user an identity is linked to, or `null`. */
@@ -90860,6 +92491,13 @@ var waterHeaterCapability = {
90860
92491
  deviceNative: true,
90861
92492
  mode: "singleton",
90862
92493
  deviceTypes: [require_composed_stable_id.DeviceType.WaterHeater],
92494
+ power: {
92495
+ kind: "mode",
92496
+ field: "operationMode",
92497
+ offValue: "off",
92498
+ set: "setOperationMode",
92499
+ lastField: "lastActiveMode"
92500
+ },
90863
92501
  methods: {
90864
92502
  setTargetTemp: require_sleep.method(zod.z.object({
90865
92503
  deviceId: zod.z.number().int().nonnegative(),
@@ -97465,11 +99103,6 @@ function evaluateAggregate(input) {
97465
99103
  }
97466
99104
  //#endregion
97467
99105
  //#region src/composition/helpers/source-pick.ts
97468
- /**
97469
- * The request the common source selector (#236) accepts for a helper (D944 §5).
97470
- * The selector's layout is not specified here. Groups ask for one device type
97471
- * and the catalog field; they do not opt into incompatible fields.
97472
- */
97473
99106
  /** What the member step asks the selector for this template. */
97474
99107
  function sourcePickForTemplate(template) {
97475
99108
  const valueKind = template.family === "numeric" ? "number" : template.activeWhen === void 0 ? "boolean" : "state";
@@ -97551,30 +99184,6 @@ function sourcePickForMath(kind) {
97551
99184
  function numericAccept() {
97552
99185
  return historyAccept("statistic").filter((field) => field.valueKind === "number");
97553
99186
  }
97554
- /**
97555
- * The one thing a naked heater needs at creation (D1004 point 5): the plug it
97556
- * switches. On and off forward to that plug; no other facet is attached.
97557
- */
97558
- function sourcePickForHeaterPlug() {
97559
- return {
97560
- fieldChoice: "operator",
97561
- purpose: "member",
97562
- multiple: false,
97563
- max: 1,
97564
- deviceTypes: [require_composed_stable_id.DeviceType.Switch],
97565
- accept: [{
97566
- cap: "switch",
97567
- fieldPath: "on",
97568
- valueKind: "boolean"
97569
- }],
97570
- history: {
97571
- required: false,
97572
- minRetentionMs: null
97573
- },
97574
- mustBindCaps: ["switch"],
97575
- exclude: []
97576
- };
97577
- }
97578
99187
  //#endregion
97579
99188
  //#region src/composition/customize/field-source.ts
97580
99189
  function fromRead(source, cap, fieldPath) {
@@ -97670,7 +99279,7 @@ function compileValue$1(input) {
97670
99279
  const transform = input.draft.transform;
97671
99280
  if (transform.kind === "identity" || transform.kind === "number") return {
97672
99281
  ok: true,
97673
- value: identityValue(read, input.sourceValueKind)
99282
+ value: identityValue(read, input.sourceValueKind, targetValueKind(input))
97674
99283
  };
97675
99284
  if (transform.kind === "invert") {
97676
99285
  if (input.sourceValueKind !== "boolean") return fail$2("source-kind");
@@ -97683,8 +99292,16 @@ function compileValue$1(input) {
97683
99292
  if (transform.kind === "linear") return linearValue$1(transform, read, input.sourceValueKind);
97684
99293
  return fail$2("transform");
97685
99294
  }
97686
- function identityValue(read, valueKind) {
97687
- if (valueKind === "string") return expression("number(x)", { x: read });
99295
+ /** The kind of the field a draft writes, from the catalog. */
99296
+ function targetValueKind(input) {
99297
+ return catalogTarget$4(input.draft.cap, input.draft.targetId)?.valueKind;
99298
+ }
99299
+ /**
99300
+ * A string reading feeds a NUMBER field through `number(x)`; a string field
99301
+ * (a fan `preset` linked to a select, D1034) takes the string as it is.
99302
+ */
99303
+ function identityValue(read, valueKind, targetKind) {
99304
+ if (valueKind === "string" && targetKind !== "string" && targetKind !== "enum") return expression("number(x)", { x: read });
97688
99305
  return read;
97689
99306
  }
97690
99307
  /**
@@ -97766,7 +99383,7 @@ function compileCompanions$1(input, target, value) {
97766
99383
  });
97767
99384
  }
97768
99385
  function companionIncluded$1(companion, apply) {
97769
- if (companion.kind === "transition-time") return true;
99386
+ if (companion.kind === "transition-time" || companion.kind === "source-field") return true;
97770
99387
  return companion.when === "always" || apply === "add";
97771
99388
  }
97772
99389
  function companionField(input, path, companion, value) {
@@ -97782,6 +99399,10 @@ function companionField(input, path, companion, value) {
97782
99399
  ok: true,
97783
99400
  value: literal("now")
97784
99401
  };
99402
+ if (companion.kind === "source-field") return {
99403
+ ok: true,
99404
+ value: fromRead(refOf$1(input.draft), input.draft.source.cap, companion.field)
99405
+ };
97785
99406
  return transitionField(input, path, companion.sourceChangedAt, value);
97786
99407
  }
97787
99408
  function transitionField(input, path, sourceChangedAt, value) {
@@ -97975,7 +99596,12 @@ function describeRead(read) {
97975
99596
  function isConfirmed(reading) {
97976
99597
  return reading.fatal || reading.confirmed === true;
97977
99598
  }
97978
- function fromReading(reading, read) {
99599
+ /** Whether a non-null value is of the kind a field of `kind` holds. */
99600
+ function valueFitsKind(value, kind) {
99601
+ if (value === null) return true;
99602
+ return typeof value === (kind === "enum" ? "string" : kind);
99603
+ }
99604
+ function fromReading(reading, read, targetKind) {
97979
99605
  if (reading.state === "unavailable") return {
97980
99606
  state: "unavailable",
97981
99607
  value: null,
@@ -97983,6 +99609,13 @@ function fromReading(reading, read) {
97983
99609
  fatal: reading.fatal,
97984
99610
  confirmed: isConfirmed(reading)
97985
99611
  };
99612
+ if (targetKind !== void 0 && !valueFitsKind(reading.value, targetKind)) return {
99613
+ state: "unavailable",
99614
+ value: null,
99615
+ reason: `${describeRead(read)}: source-kind-mismatch, it reads a ${typeof reading.value} and the field takes a ${targetKind}`,
99616
+ fatal: false,
99617
+ confirmed: true
99618
+ };
97986
99619
  return {
97987
99620
  state: reading.state,
97988
99621
  value: reading.value,
@@ -98106,7 +99739,7 @@ function aggregateField(source, read) {
98106
99739
  function evaluateCompositionField(input) {
98107
99740
  const { source } = input;
98108
99741
  switch (source.kind) {
98109
- case "from": return fromReading(input.read(source), source);
99742
+ case "from": return fromReading(input.read(source), source, input.targetKind);
98110
99743
  case "expression": return expressionOutcome(source, input.read, input.now, input.stateful);
98111
99744
  case "aggregate": return aggregateField(source, input.read);
98112
99745
  case "series": return {
@@ -98342,56 +99975,6 @@ function lockDoorLinkOfComposition(composition) {
98342
99975
  };
98343
99976
  }
98344
99977
  //#endregion
98345
- //#region src/composition/power-source-link.ts
98346
- /**
98347
- * Which smart switch powers a device (the `power-source` Customize extension):
98348
- * the source its stored `power-source.switchOn` field reads, and the off time of
98349
- * a forced restart stored beside it. Read from the STORED composition, never kept
98350
- * as a second copy (D676). Shared by the hub (which acts on the switch) and the
98351
- * admin UI (which shows it).
98352
- */
98353
- /**
98354
- * The stored off time, or the default when none is stored. A stored number out
98355
- * of range is CLAMPED to the bounds (a hand-written value never refuses the
98356
- * link, it just cannot cut power for an absurd time); a non-integer is rounded.
98357
- */
98358
- function normalizeOffSeconds(value) {
98359
- if (typeof value !== "number" || !Number.isFinite(value)) return 10;
98360
- return Math.min(120, Math.max(3, Math.round(value)));
98361
- }
98362
- /** The constant a stored `offSeconds` field carries, or undefined when it is not a literal number. */
98363
- function storedOffSeconds(composition) {
98364
- const feature = composition.features.find((f) => f.cap === "power-source");
98365
- if (feature === void 0 || feature.kind !== "fields") return void 0;
98366
- const field = feature.fields["offSeconds"];
98367
- if (field === void 0 || field.kind !== "expression") return void 0;
98368
- const n = Number(field.expr);
98369
- return field.expr.trim() === "" || !Number.isFinite(n) ? void 0 : n;
98370
- }
98371
- /**
98372
- * The link a composition stores. An `existing` target names its own device; a
98373
- * `new` target (a composed device) is the composer's own device, so the caller
98374
- * passes the block id and a new-target composition without one has no link.
98375
- */
98376
- function powerSourceLinkOfComposition(composition, blockId) {
98377
- if (composition === null) return null;
98378
- let device;
98379
- if (composition.target.kind === "existing") device = composition.target.device;
98380
- else if (blockId !== void 0) device = require_implemented_methods.composedDeviceRef(blockId);
98381
- else return null;
98382
- const feature = composition.features.find((f) => f.cap === "power-source");
98383
- if (feature === void 0 || feature.kind !== "fields" || feature.enabled === false) return null;
98384
- const field = feature.fields["switchOn"];
98385
- if (field === void 0) return null;
98386
- const read = require_implemented_methods.fieldReads(field).find((r) => r.cap === "switch");
98387
- if (read === void 0) return null;
98388
- return {
98389
- device,
98390
- switch: read.source,
98391
- offSeconds: normalizeOffSeconds(storedOffSeconds(composition))
98392
- };
98393
- }
98394
- //#endregion
98395
99978
  //#region src/composition/presets/numeric-transforms.ts
98396
99979
  /**
98397
99980
  * Self-only invert / unit-convert composition features (D663, D939).
@@ -99219,7 +100802,7 @@ function drafted(field, transform, sourceValueKind, cap, targetId) {
99219
100802
  };
99220
100803
  }
99221
100804
  function inferApply$1(target, fields) {
99222
- const addPaths = (target.companions ?? []).flatMap((companion) => companion.kind !== "transition-time" && companion.when === "add" ? [companion.path] : []);
100805
+ const addPaths = (target.companions ?? []).flatMap((companion) => (companion.kind === "constant" || companion.kind === "clock") && companion.when === "add" ? [companion.path] : []);
99223
100806
  if (addPaths.length === 0) return "replace";
99224
100807
  const present = addPaths.filter((path) => fields[path] !== void 0);
99225
100808
  if (present.length === addPaths.length) return "add";
@@ -99564,7 +101147,7 @@ function compileCompanions(target, apply) {
99564
101147
  });
99565
101148
  }
99566
101149
  function companionIncluded(companion, apply) {
99567
- if (companion.kind === "transition-time") return false;
101150
+ if (companion.kind === "transition-time" || companion.kind === "source-field") return false;
99568
101151
  return companion.when === "always" || apply === "add";
99569
101152
  }
99570
101153
  function refOf(draft) {
@@ -99743,7 +101326,7 @@ function isConstant(source) {
99743
101326
  return source?.kind === "expression" && Object.keys(source.bindings).length === 0;
99744
101327
  }
99745
101328
  function inferApply(target, fields) {
99746
- const addPaths = (target.companions ?? []).flatMap((companion) => companion.kind !== "transition-time" && companion.when === "add" ? [companion.path] : []);
101329
+ const addPaths = (target.companions ?? []).flatMap((companion) => (companion.kind === "constant" || companion.kind === "clock") && companion.when === "add" ? [companion.path] : []);
99747
101330
  if (addPaths.length === 0) return "replace";
99748
101331
  const present = addPaths.filter((path) => fields[path] !== void 0);
99749
101332
  if (present.length === addPaths.length) return "add";
@@ -99752,7 +101335,7 @@ function inferApply(target, fields) {
99752
101335
  }
99753
101336
  function companionsMatch(target, fields, apply) {
99754
101337
  const expected = (target.companions ?? []).flatMap((companion) => {
99755
- if (companion.kind === "transition-time") return [];
101338
+ if (companion.kind === "transition-time" || companion.kind === "source-field") return [];
99756
101339
  if (companion.when === "always" || apply === "add") return [companion.path];
99757
101340
  return [];
99758
101341
  });
@@ -101816,15 +103399,16 @@ var BaseDeviceProvider = class extends require_sleep.BaseAddon {
101816
103399
  });
101817
103400
  const meta = await this.ctx.api.deviceManager.loadMeta.query({ deviceId: id });
101818
103401
  if (meta === null) throw new Error(`${this.providerName}: no persisted meta for "${stableId}" (id ${id}) — cannot reload`);
101819
- const deviceType = Object.values(require_composed_stable_id.DeviceType).find((t) => t === meta.type);
101820
- const Class = deviceType !== void 0 ? this.deviceClasses[deviceType] : void 0;
103402
+ const Class = this.deviceClassForRow({
103403
+ type: meta.type,
103404
+ stableId
103405
+ });
101821
103406
  if (!Class) throw new Error(`${this.providerName}: no device class for type "${meta.type}" — "${stableId}" is an accessory child; reload its parent instead`);
101822
103407
  await devices.create(stableId, Class, {}, meta.parentDeviceId ?? null);
101823
103408
  const rows = await this.ctx.api.deviceManager.listPersistedByAddon.query({ addonId: this.addonId });
101824
103409
  for (const row of rows) {
101825
103410
  if (row.parentDeviceId !== id) continue;
101826
- const childType = Object.values(require_composed_stable_id.DeviceType).find((t) => t === row.type);
101827
- const ChildClass = childType !== void 0 ? this.deviceClasses[childType] : void 0;
103411
+ const ChildClass = this.deviceClassForRow(row);
101828
103412
  if (!ChildClass) continue;
101829
103413
  try {
101830
103414
  await devices.create(row.stableId, ChildClass, {}, id);
@@ -101851,6 +103435,16 @@ var BaseDeviceProvider = class extends require_sleep.BaseAddon {
101851
103435
  return { deviceId: id };
101852
103436
  }
101853
103437
  /**
103438
+ * The class a PERSISTED row is rebuilt with. Default: by type, from
103439
+ * `deviceClasses`. A provider whose distinct devices share one type (D1033:
103440
+ * a radiator valve and a room climate are both `climate`) overrides this
103441
+ * and tells them apart by the row's stable id or config.
103442
+ */
103443
+ deviceClassForRow(row) {
103444
+ const type = Object.values(require_composed_stable_id.DeviceType).find((t) => t === row.type);
103445
+ return type !== void 0 ? this.deviceClasses[type] : void 0;
103446
+ }
103447
+ /**
101854
103448
  * Restore devices from persisted state. Two-pass:
101855
103449
  *
101856
103450
  * 1. **Top-level pass** — invokes `kernel.devices.create()` for every
@@ -101911,7 +103505,7 @@ var BaseDeviceProvider = class extends require_sleep.BaseAddon {
101911
103505
  restored.add(saved.id);
101912
103506
  return;
101913
103507
  }
101914
- const Class = this.deviceClasses[saved.type];
103508
+ const Class = this.deviceClassForRow(saved);
101915
103509
  if (!Class) throw new Error(`no device class registered for type "${saved.type}"`);
101916
103510
  if (saved.parentDeviceId !== null && !restored.has(saved.parentDeviceId)) throw new Error(`parent device ${saved.parentDeviceId} not restored`);
101917
103511
  await this.healSavedConfig(saved, savedDevices);
@@ -101928,7 +103522,7 @@ var BaseDeviceProvider = class extends require_sleep.BaseAddon {
101928
103522
  };
101929
103523
  const topLevel = savedDevices.filter((saved) => saved.parentDeviceId === null);
101930
103524
  const restoreOne = async (saved) => {
101931
- if (!this.deviceClasses[saved.type]) {
103525
+ if (!this.deviceClassForRow(saved)) {
101932
103526
  this.ctx.logger.warn("No device class registered for restored type — skipping", {
101933
103527
  tags: {
101934
103528
  deviceId: saved.id,
@@ -101967,7 +103561,7 @@ var BaseDeviceProvider = class extends require_sleep.BaseAddon {
101967
103561
  const failedTopLevelIds = new Set(failures.map((failure) => failure.saved.id));
101968
103562
  const childRows = savedDevices.filter((s) => s.parentDeviceId !== null);
101969
103563
  for (const saved of childRows) {
101970
- if (!this.deviceClasses[saved.type]) continue;
103564
+ if (!this.deviceClassForRow(saved)) continue;
101971
103565
  if (saved.parentDeviceId === null) continue;
101972
103566
  if (restored.has(saved.parentDeviceId)) {
101973
103567
  try {
@@ -102158,7 +103752,6 @@ function applyPrimaryChildRule(rule, children) {
102158
103752
  var CONTAINER_CHILD_PRIORITY = [
102159
103753
  "media-player",
102160
103754
  "alarm-panel",
102161
- "thermostat",
102162
103755
  "climate",
102163
103756
  "humidifier",
102164
103757
  "water-heater",
@@ -102778,6 +104371,73 @@ function widenDeviceConstructor(ctor) {
102778
104371
  return ctor;
102779
104372
  }
102780
104373
  //#endregion
104374
+ //#region src/device/device-kind.ts
104375
+ /**
104376
+ * A device's KIND is its type plus its role (D1033): the type is the set of
104377
+ * controls it has, the role says which thing it is among the devices that
104378
+ * share those controls. A plug-in heater is a `switch` with role
104379
+ * `switch-heater`; an air conditioner and a radiator valve are both `climate`,
104380
+ * told apart by their `climate-*` role.
104381
+ */
104382
+ /**
104383
+ * Type values a persisted row may still carry after the type was retired, and
104384
+ * the type each one is read as. The row is rewritten by the next registration
104385
+ * of the device (its provider stamps the live type), so this is a read alias,
104386
+ * not a migration.
104387
+ *
104388
+ * `heater` is deliberately absent: the only heaters were composed devices the
104389
+ * operator deletes. Such a row stays an unknown type, which every reader
104390
+ * treats as a generic device.
104391
+ */
104392
+ var RETIRED_DEVICE_TYPES = { thermostat: require_composed_stable_id.DeviceType.Climate };
104393
+ /** The live type a stored `type` value stands for (itself unless retired). */
104394
+ function canonicalStoredDeviceType(stored) {
104395
+ return RETIRED_DEVICE_TYPES[stored] ?? stored;
104396
+ }
104397
+ /** The `climate-*` roles, in the order the role picker lists them. */
104398
+ var CLIMATE_ROLES = [
104399
+ require_composed_stable_id.DeviceRole.ClimateThermostat,
104400
+ require_composed_stable_id.DeviceRole.ClimateAc,
104401
+ require_composed_stable_id.DeviceRole.ClimateRadiator,
104402
+ require_composed_stable_id.DeviceRole.ClimateFloor,
104403
+ require_composed_stable_id.DeviceRole.ClimateHeater,
104404
+ require_composed_stable_id.DeviceRole.ClimateHeatPumpCircuit
104405
+ ];
104406
+ function isClimateRole(role) {
104407
+ return CLIMATE_ROLES.some((candidate) => candidate === role);
104408
+ }
104409
+ /**
104410
+ * Which climate device this is. A climate device with no role, or a role that
104411
+ * is not a climate one, is a room thermostat: that is what most of them are,
104412
+ * and it is the presentation a thermostat had before the types were folded.
104413
+ */
104414
+ function climateRoleOf(role) {
104415
+ return role !== null && role !== void 0 && isClimateRole(role) ? role : require_composed_stable_id.DeviceRole.ClimateThermostat;
104416
+ }
104417
+ /** An air conditioner: exports present it as an AC unit, not a thermostat. */
104418
+ function isAirConditioner(type, role) {
104419
+ return type === require_composed_stable_id.DeviceType.Climate && climateRoleOf(role) === require_composed_stable_id.DeviceRole.ClimateAc;
104420
+ }
104421
+ /**
104422
+ * Is a capability offered on a device of this type and role?
104423
+ *
104424
+ * Fails open where the old type-only gate did: no `deviceTypes` (or an empty
104425
+ * list) applies to every device, and an unknown type never filters (a failed
104426
+ * meta read must not destroy work, D49). A type the cap's `deviceRoles` names
104427
+ * is offered only to the roles listed there; an unknown role is NOT one of
104428
+ * them, so a `switch` whose role could not be read is not a heater.
104429
+ */
104430
+ function capAppliesToDeviceKind(gate, deviceType, role) {
104431
+ if (deviceType === void 0) return true;
104432
+ const types = gate?.deviceTypes;
104433
+ if (!types || types.length === 0) return true;
104434
+ const type = types.find((candidate) => candidate === deviceType);
104435
+ if (type === void 0) return false;
104436
+ const roles = gate?.deviceRoles?.[type];
104437
+ if (roles === void 0) return true;
104438
+ return role !== null && role !== void 0 && roles.some((candidate) => candidate === role);
104439
+ }
104440
+ //#endregion
102781
104441
  //#region src/device/device-control-resolution.ts
102782
104442
  /**
102783
104443
  * Device-control RESOLUTION LOGIC — the single, presentation-free source of
@@ -102830,8 +104490,7 @@ var DEVICE_TYPE_CONTROL_KIND = {
102830
104490
  [require_composed_stable_id.DeviceType.Light]: "light",
102831
104491
  [require_composed_stable_id.DeviceType.Fan]: "fan",
102832
104492
  [require_composed_stable_id.DeviceType.Sensor]: "sensor",
102833
- [require_composed_stable_id.DeviceType.Thermostat]: "thermostat",
102834
- [require_composed_stable_id.DeviceType.Climate]: "climate",
104493
+ [require_composed_stable_id.DeviceType.Climate]: "thermostat",
102835
104494
  [require_composed_stable_id.DeviceType.Button]: "button",
102836
104495
  [require_composed_stable_id.DeviceType.EventEmitter]: "dummy",
102837
104496
  [require_composed_stable_id.DeviceType.Update]: "update",
@@ -102851,7 +104510,6 @@ var DEVICE_TYPE_CONTROL_KIND = {
102851
104510
  [require_composed_stable_id.DeviceType.Image]: "image",
102852
104511
  [require_composed_stable_id.DeviceType.PetFeeder]: "pet-feeder",
102853
104512
  [require_composed_stable_id.DeviceType.PetFountain]: "pet-fountain",
102854
- [require_composed_stable_id.DeviceType.Heater]: "heater",
102855
104513
  [require_composed_stable_id.DeviceType.Dishwasher]: "dishwasher",
102856
104514
  [require_composed_stable_id.DeviceType.Washer]: "appliance",
102857
104515
  [require_composed_stable_id.DeviceType.Dryer]: "appliance",
@@ -102865,8 +104523,11 @@ var DEVICE_TYPE_VALUES = new Set(Object.values(require_composed_stable_id.Device
102865
104523
  * narrows the string to a `DeviceType` before indexing (documented enum-string
102866
104524
  * boundary).
102867
104525
  */
102868
- function resolveDeviceControlKind(type) {
102869
- return DEVICE_TYPE_VALUES.has(type) ? DEVICE_TYPE_CONTROL_KIND[type] : null;
104526
+ function resolveDeviceControlKind(type, role) {
104527
+ if (!DEVICE_TYPE_VALUES.has(type)) return null;
104528
+ if (isAirConditioner(type, role)) return "climate";
104529
+ if (type === require_composed_stable_id.DeviceType.Switch && role === require_composed_stable_id.DeviceRole.SwitchHeater) return "heater";
104530
+ return DEVICE_TYPE_CONTROL_KIND[type];
102870
104531
  }
102871
104532
  /** Kebab feature flag advertised by an accessory that auto-activates when its
102872
104533
  * parent camera detects motion. The cap's kebab name is `motion-trigger` (see
@@ -105188,9 +106849,6 @@ function durationText(seconds) {
105188
106849
  const text = `${Math.floor(m / 60)} h ${String(m % 60).padStart(2, "0")}`;
105189
106850
  return require_sleep.t(text, text);
105190
106851
  }
105191
- function deviceTypeOf(type) {
105192
- return Object.values(require_composed_stable_id.DeviceType).find((t) => t === type);
105193
- }
105194
106852
  var switchContribution = contribution("switch", SwitchStatusSchema, (slice) => {
105195
106853
  const on = slice?.on ?? null;
105196
106854
  return {
@@ -105371,8 +107029,7 @@ function remainingWords(amount, unit) {
105371
107029
  return require_sleep.t(`${amount} ${word}`, `${amount} ${word}`);
105372
107030
  }
105373
107031
  var timedRunContribution = contribution("timed-run", TimedRunStatusSchema, (slice, ctx) => {
105374
- const type = deviceTypeOf(ctx.type);
105375
- const limit = type === void 0 ? null : timedRunLimitOf(type);
107032
+ const limit = timedRunLimitOf(ctx.type, ctx.role);
105376
107033
  if (limit === null) return {};
105377
107034
  const quickRun = slice?.quickRun ?? timedRunQuickRun(limit, null);
105378
107035
  const activeUntil = slice?.activeUntil != null && slice.activeUntil > ctx.now ? slice.activeUntil : null;
@@ -105813,7 +107470,6 @@ var HERO_LAYOUT_BY_TYPE = {
105813
107470
  [require_composed_stable_id.DeviceType.Siren]: HERO_LAYOUT_DEFAULT,
105814
107471
  [require_composed_stable_id.DeviceType.Switch]: SWITCH_LAYOUT,
105815
107472
  [require_composed_stable_id.DeviceType.Sensor]: HERO_LAYOUT_DEFAULT,
105816
- [require_composed_stable_id.DeviceType.Thermostat]: CLIMATE_LAYOUT,
105817
107473
  [require_composed_stable_id.DeviceType.Climate]: CLIMATE_LAYOUT,
105818
107474
  [require_composed_stable_id.DeviceType.Button]: BUTTON_LAYOUT,
105819
107475
  [require_composed_stable_id.DeviceType.EventEmitter]: HERO_LAYOUT_DEFAULT,
@@ -105842,7 +107498,6 @@ var HERO_LAYOUT_BY_TYPE = {
105842
107498
  [require_composed_stable_id.DeviceType.PetFountain]: FOUNTAIN_LAYOUT,
105843
107499
  [require_composed_stable_id.DeviceType.Dishwasher]: DISHWASHER_LAYOUT,
105844
107500
  [require_composed_stable_id.DeviceType.Washer]: APPLIANCE_LAYOUT,
105845
- [require_composed_stable_id.DeviceType.Heater]: HEATER_LAYOUT,
105846
107501
  [require_composed_stable_id.DeviceType.Dryer]: APPLIANCE_LAYOUT,
105847
107502
  [require_composed_stable_id.DeviceType.Gateway]: HERO_LAYOUT_DEFAULT
105848
107503
  };
@@ -105850,7 +107505,8 @@ function isDeviceType$1(type) {
105850
107505
  return Object.values(require_composed_stable_id.DeviceType).includes(type);
105851
107506
  }
105852
107507
  /** The layout of a type; a type this build does not know gets the default. */
105853
- function resolveHeroLayout(type) {
107508
+ function resolveHeroLayout(type, role = null) {
107509
+ if (type === require_composed_stable_id.DeviceType.Switch && role === require_composed_stable_id.DeviceRole.SwitchHeater) return HEATER_LAYOUT;
105854
107510
  return isDeviceType$1(type) ? HERO_LAYOUT_BY_TYPE[type] : HERO_LAYOUT_DEFAULT;
105855
107511
  }
105856
107512
  //#endregion
@@ -106531,7 +108187,7 @@ var HERO_MODE_LOOK = {
106531
108187
  open: null,
106532
108188
  closed: null
106533
108189
  };
106534
- var MODE_LOOK_TYPES = [require_composed_stable_id.DeviceType.Climate, require_composed_stable_id.DeviceType.Thermostat];
108190
+ var MODE_LOOK_TYPES = [require_composed_stable_id.DeviceType.Climate];
106535
108191
  var HERO_LOOK_BY_TYPE = {
106536
108192
  [require_composed_stable_id.DeviceType.Camera]: CAMERA_LOOK,
106537
108193
  [require_composed_stable_id.DeviceType.Hub]: HERO_LOOK_DEFAULT,
@@ -106539,8 +108195,7 @@ var HERO_LOOK_BY_TYPE = {
106539
108195
  [require_composed_stable_id.DeviceType.Siren]: HERO_LOOK_DEFAULT,
106540
108196
  [require_composed_stable_id.DeviceType.Switch]: SWITCH_LOOK,
106541
108197
  [require_composed_stable_id.DeviceType.Sensor]: READING_SENSOR_LOOK,
106542
- [require_composed_stable_id.DeviceType.Thermostat]: THERMOSTAT_LOOK,
106543
- [require_composed_stable_id.DeviceType.Climate]: CLIMATE_LOOK,
108198
+ [require_composed_stable_id.DeviceType.Climate]: THERMOSTAT_LOOK,
106544
108199
  [require_composed_stable_id.DeviceType.Button]: BUTTON_LOOK,
106545
108200
  [require_composed_stable_id.DeviceType.EventEmitter]: EVENT_EMITTER_LOOK,
106546
108201
  [require_composed_stable_id.DeviceType.Update]: UPDATE_LOOK,
@@ -106568,7 +108223,6 @@ var HERO_LOOK_BY_TYPE = {
106568
108223
  [require_composed_stable_id.DeviceType.PetFountain]: FOUNTAIN_LOOK,
106569
108224
  [require_composed_stable_id.DeviceType.Dishwasher]: DISHWASHER_LOOK,
106570
108225
  [require_composed_stable_id.DeviceType.Washer]: WASHER_LOOK,
106571
- [require_composed_stable_id.DeviceType.Heater]: HEATER_LOOK,
106572
108226
  [require_composed_stable_id.DeviceType.Dryer]: DRYER_LOOK,
106573
108227
  [require_composed_stable_id.DeviceType.Gateway]: HERO_LOOK_DEFAULT
106574
108228
  };
@@ -106593,6 +108247,14 @@ var HERO_LOOK_BY_ROLE = {
106593
108247
  [require_composed_stable_id.DeviceRole.CoverWindow]: "inherit",
106594
108248
  [require_composed_stable_id.DeviceRole.BinaryHelper]: "inherit",
106595
108249
  [require_composed_stable_id.DeviceRole.Outlet]: "inherit",
108250
+ [require_composed_stable_id.DeviceRole.SwitchHeater]: HEATER_LOOK,
108251
+ [require_composed_stable_id.DeviceRole.SwitchFan]: FAN_LOOK,
108252
+ [require_composed_stable_id.DeviceRole.ClimateAc]: "inherit",
108253
+ [require_composed_stable_id.DeviceRole.ClimateThermostat]: "inherit",
108254
+ [require_composed_stable_id.DeviceRole.ClimateFloor]: "inherit",
108255
+ [require_composed_stable_id.DeviceRole.ClimateRadiator]: "inherit",
108256
+ [require_composed_stable_id.DeviceRole.ClimateHeater]: "inherit",
108257
+ [require_composed_stable_id.DeviceRole.ClimateHeatPumpCircuit]: "inherit",
106596
108258
  [require_composed_stable_id.DeviceRole.MotionSensor]: MOTION_LOOK,
106597
108259
  [require_composed_stable_id.DeviceRole.ContactSensor]: "inherit",
106598
108260
  [require_composed_stable_id.DeviceRole.LeakSensor]: LEAK_LOOK,
@@ -106650,6 +108312,7 @@ function resolveHeroLook(role, type, state, mode = null) {
106650
108312
  const byMode = HERO_MODE_LOOK[mode];
106651
108313
  if (byMode !== null) return byMode;
106652
108314
  }
108315
+ if (isAirConditioner(type, role)) return CLIMATE_LOOK[state];
106653
108316
  return ((isDeviceType(type) ? HERO_LOOK_BY_TYPE[type] : void 0) ?? HERO_LOOK_DEFAULT)[state];
106654
108317
  }
106655
108318
  /** Every look the model declares, for the exhaustiveness guard and its spec. */
@@ -106832,6 +108495,7 @@ function buildHeroModel(input) {
106832
108495
  const ctx = {
106833
108496
  deviceId: device.id,
106834
108497
  type: device.type,
108498
+ role: device.role,
106835
108499
  features: input.features,
106836
108500
  now: input.now,
106837
108501
  running: runningOf(input),
@@ -106860,7 +108524,7 @@ function buildHeroModel(input) {
106860
108524
  }
106861
108525
  };
106862
108526
  const allRows = fragments.flatMap((f) => f.rows ?? []);
106863
- const rows = resolveHeroLayout(device.type).rows.flatMap((id) => {
108527
+ const rows = resolveHeroLayout(device.type, device.role).rows.flatMap((id) => {
106864
108528
  return allRows.filter((r) => r.id === id).map((r) => HERO_SCENE_ROW_IDS.has(r.id) ? {
106865
108529
  ...r,
106866
108530
  placement: "scene"
@@ -110437,6 +112101,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
110437
112101
  access: "create",
110438
112102
  role: "viewer"
110439
112103
  },
112104
+ "fanControl.setOscillationAxis": {
112105
+ capName: "fan-control",
112106
+ capScope: "device",
112107
+ addonId: null,
112108
+ access: "create",
112109
+ role: "viewer"
112110
+ },
110440
112111
  "fanControl.setPercentage": {
110441
112112
  capName: "fan-control",
110442
112113
  capScope: "device",
@@ -117956,7 +119627,6 @@ var DEVICE_TYPE_DO_CAPS = {
117956
119627
  [require_composed_stable_id.DeviceType.Siren]: ["switch", "motion-trigger"],
117957
119628
  [require_composed_stable_id.DeviceType.Switch]: ["switch", "motion-trigger"],
117958
119629
  [require_composed_stable_id.DeviceType.Sensor]: [],
117959
- [require_composed_stable_id.DeviceType.Thermostat]: ["climate-control"],
117960
119630
  [require_composed_stable_id.DeviceType.Climate]: ["climate-control"],
117961
119631
  [require_composed_stable_id.DeviceType.Button]: ["button"],
117962
119632
  [require_composed_stable_id.DeviceType.EventEmitter]: [],
@@ -117983,7 +119653,6 @@ var DEVICE_TYPE_DO_CAPS = {
117983
119653
  [require_composed_stable_id.DeviceType.Image]: [],
117984
119654
  [require_composed_stable_id.DeviceType.PetFeeder]: ["pet-feeder"],
117985
119655
  [require_composed_stable_id.DeviceType.PetFountain]: ["pet-fountain", "timed-run"],
117986
- [require_composed_stable_id.DeviceType.Heater]: ["switch", "timed-run"],
117987
119656
  [require_composed_stable_id.DeviceType.Dishwasher]: ["dishwasher"],
117988
119657
  [require_composed_stable_id.DeviceType.Washer]: [],
117989
119658
  [require_composed_stable_id.DeviceType.Dryer]: [],
@@ -118008,7 +119677,6 @@ function isDoPickerDeviceType(type) {
118008
119677
  function deviceDoFamily(type) {
118009
119678
  switch (type) {
118010
119679
  case require_composed_stable_id.DeviceType.Climate:
118011
- case require_composed_stable_id.DeviceType.Thermostat:
118012
119680
  case require_composed_stable_id.DeviceType.Humidifier:
118013
119681
  case require_composed_stable_id.DeviceType.WaterHeater:
118014
119682
  case require_composed_stable_id.DeviceType.HeatPump: return "climate-family";
@@ -118931,6 +120599,151 @@ function createRuntimeStateBridge(params) {
118931
120599
  };
118932
120600
  }
118933
120601
  //#endregion
120602
+ //#region src/device/power-switch.ts
120603
+ var PowerSwitchRefusedError = class extends Error {
120604
+ reason;
120605
+ constructor(reason, message) {
120606
+ super(message);
120607
+ this.name = "PowerSwitchRefusedError";
120608
+ this.reason = reason;
120609
+ }
120610
+ };
120611
+ /** `true` / `false` from the owner slice, `null` when the hinted field is
120612
+ * absent or not of the hinted shape. */
120613
+ function powerOnFromSlice(hint, slice) {
120614
+ const value = slice?.[hint.field];
120615
+ switch (hint.kind) {
120616
+ case "field": return typeof value === "boolean" ? value : null;
120617
+ case "methods": return typeof value === "string" ? !hint.offValues.includes(value) : null;
120618
+ case "mode": return typeof value === "string" ? value !== hint.offValue : null;
120619
+ }
120620
+ }
120621
+ function ownerMethod(owner, name, capName) {
120622
+ const fn = Reflect.get(owner, name);
120623
+ if (typeof fn !== "function") throw new PowerSwitchRefusedError("owner-method-missing", `${capName} provider does not serve '${name}', which its power hint names`);
120624
+ return async (input) => fn.call(owner, input);
120625
+ }
120626
+ async function lastNonOffMode(host, capName, hint) {
120627
+ const isMode = (v) => typeof v === "string" && v.length > 0 && v !== hint.offValue;
120628
+ const fromHub = (await host.readHubSlice(capName).catch(() => null))?.[hint.lastField];
120629
+ if (isMode(fromHub)) return fromHub;
120630
+ const local = host.runtimeState.getCapState(capName)?.[hint.lastField];
120631
+ return isMode(local) ? local : null;
120632
+ }
120633
+ async function applyPower(host, capName, hint, owner, on) {
120634
+ const deviceId = host.deviceId;
120635
+ switch (hint.kind) {
120636
+ case "field":
120637
+ await ownerMethod(owner, hint.set, capName)({
120638
+ deviceId,
120639
+ on
120640
+ });
120641
+ return;
120642
+ case "methods":
120643
+ await ownerMethod(owner, on ? hint.on : hint.off, capName)({ deviceId });
120644
+ return;
120645
+ case "mode": {
120646
+ const set = ownerMethod(owner, hint.set, capName);
120647
+ if (!on) {
120648
+ await set({
120649
+ deviceId,
120650
+ mode: hint.offValue
120651
+ });
120652
+ return;
120653
+ }
120654
+ const mode = await lastNonOffMode(host, capName, hint);
120655
+ if (mode === null) throw new PowerSwitchRefusedError("no-last-mode", `device ${deviceId}: ${capName} has no last non-off mode to restore; pick a mode instead`);
120656
+ await set({
120657
+ deviceId,
120658
+ mode
120659
+ });
120660
+ return;
120661
+ }
120662
+ }
120663
+ }
120664
+ function hintedMethods(hint) {
120665
+ return hint.kind === "methods" ? [hint.on, hint.off] : [hint.set];
120666
+ }
120667
+ /** Whether `owner` serves every method its cap's power hint names. A media
120668
+ * player whose `turnOn` / `turnOff` are not served has no power, so no switch. */
120669
+ function powerServedBy(hint, owner) {
120670
+ if (hint === void 0) return false;
120671
+ return hintedMethods(hint).every((name) => typeof Reflect.get(owner, name) === "function");
120672
+ }
120673
+ /** Builds the `switch` provider and starts the slice projection. Exported
120674
+ * for the specs; providers call `registerPowerSwitch`. */
120675
+ function buildPowerSwitch(host, cap, owner) {
120676
+ const hint = cap.power;
120677
+ if (hint === void 0) throw new Error(`capability '${cap.name}' has no power hint: it has no switch to project`);
120678
+ const read = () => powerOnFromSlice(hint, host.runtimeState.getCapState(cap.name));
120679
+ const project = () => {
120680
+ const on = read();
120681
+ const current = host.runtimeState.getCapState(switchCapability.name);
120682
+ if (current !== void 0 && current["on"] === on) return;
120683
+ const next = {
120684
+ on,
120685
+ lastChangedAt: Date.now()
120686
+ };
120687
+ host.runtimeState.setCapState(switchCapability.name, next);
120688
+ };
120689
+ const stop = host.runtimeState.subscribeCap(cap.name, project);
120690
+ if (host.runtimeState.getCapState(cap.name) !== void 0) project();
120691
+ return {
120692
+ provider: {
120693
+ getStatus: async () => {
120694
+ const current = host.runtimeState.getCapState(switchCapability.name);
120695
+ const lastChangedAt = typeof current?.["lastChangedAt"] === "number" ? current["lastChangedAt"] : 0;
120696
+ return {
120697
+ on: read(),
120698
+ lastChangedAt
120699
+ };
120700
+ },
120701
+ setState: async ({ on }) => applyPower(host, cap.name, hint, owner, on)
120702
+ },
120703
+ dispose: stop
120704
+ };
120705
+ }
120706
+ /**
120707
+ * Registers `switch` for a device whose `cap` carries a `power` hint, built
120708
+ * from `owner` (the provider the device registered for `cap`). Call it right
120709
+ * after `registerNativeCap(cap, owner)`.
120710
+ */
120711
+ function registerPowerSwitch(device, cap, owner) {
120712
+ const deviceId = device.ctx.id;
120713
+ if (cap.power !== void 0 && !powerServedBy(cap.power, owner)) {
120714
+ device.ctx.logger.debug("power switch: owner serves no power control, no switch registered", {
120715
+ tags: { deviceId },
120716
+ meta: { capName: cap.name }
120717
+ });
120718
+ return () => {};
120719
+ }
120720
+ const host = {
120721
+ deviceId,
120722
+ runtimeState: device.runtimeState,
120723
+ registerNativeCap: (c, p) => device.ctx.registerNativeCap(c, p),
120724
+ readHubSlice: async (capName) => {
120725
+ try {
120726
+ return await device.ctx.api.deviceState.getCapSlice.query({
120727
+ deviceId,
120728
+ capName
120729
+ });
120730
+ } catch (err) {
120731
+ device.ctx.logger.warn("power switch: hub slice read failed", {
120732
+ tags: { deviceId },
120733
+ meta: {
120734
+ capName,
120735
+ error: err instanceof Error ? err.message : String(err)
120736
+ }
120737
+ });
120738
+ return null;
120739
+ }
120740
+ }
120741
+ };
120742
+ const built = buildPowerSwitch(host, cap, owner);
120743
+ host.registerNativeCap(switchCapability, built.provider);
120744
+ return built.dispose;
120745
+ }
120746
+ //#endregion
118934
120747
  //#region src/device/system-mirror.ts
118935
120748
  var STATE_CHANGED_CATEGORY = "device.state-changed";
118936
120749
  var BINDING_CHANGED_CATEGORY = "capability.binding-changed";
@@ -120804,6 +122617,11 @@ var METHOD_DEVICE_SELECTORS = Object.freeze({
120804
122617
  form: "single",
120805
122618
  optional: false
120806
122619
  }],
122620
+ "fanControl.setOscillationAxis": [{
122621
+ name: "deviceId",
122622
+ form: "single",
122623
+ optional: false
122624
+ }],
120807
122625
  "fanControl.setPercentage": [{
120808
122626
  name: "deviceId",
120809
122627
  form: "single",
@@ -123659,6 +125477,12 @@ var CUSTOMIZE_CARDINALITIES = [
123659
125477
  var CUSTOMIZE_EVENT_SHAPES = ["pulse", "span"];
123660
125478
  /** Who applies a stored event or scalar assignment; the table branches on it. */
123661
125479
  var CUSTOMIZE_APPLY_AUTHORITY_KINDS = ["composition-claim", "camera-sensors"];
125480
+ /**
125481
+ * A named group a cap may file its targets under in the Customize table
125482
+ * (D1034). Admin-ui keys a section title off this list; a target without one
125483
+ * lands in the section its cardinality implies.
125484
+ */
125485
+ var CUSTOMIZE_TARGET_SECTIONS = ["oscillation-axes"];
123662
125486
  //#endregion
123663
125487
  //#region src/composition/customize/scalar-status.ts
123664
125488
  function projectScalarAssignment(input) {
@@ -136855,18 +138679,25 @@ exports.AutoTuneWarningSchema = AutoTuneWarningSchema;
136855
138679
  exports.AutoUpdateSettingsSchema = AutoUpdateSettingsSchema;
136856
138680
  exports.AutomationActionSchema = AutomationActionSchema;
136857
138681
  exports.AutomationCapStepSchema = AutomationCapStepSchema;
138682
+ exports.AutomationChooseStepSchema = AutomationChooseStepSchema;
136858
138683
  exports.AutomationConditionOperatorSchema = AutomationConditionOperatorSchema;
136859
138684
  exports.AutomationConditionTraceNodeSchema = AutomationConditionTraceNodeSchema;
136860
138685
  exports.AutomationControlStatusSchema = AutomationControlStatusSchema;
138686
+ exports.AutomationParallelStepSchema = AutomationParallelStepSchema;
136861
138687
  exports.AutomationRecipeSchema = AutomationRecipeSchema;
138688
+ exports.AutomationRepeatLoopSchema = AutomationRepeatLoopSchema;
138689
+ exports.AutomationRepeatStepSchema = AutomationRepeatStepSchema;
136862
138690
  exports.AutomationRunModeSchema = AutomationRunModeSchema;
136863
138691
  exports.AutomationRunOutcomeSchema = AutomationRunOutcomeSchema;
136864
138692
  exports.AutomationRunTraceSchema = AutomationRunTraceSchema;
136865
138693
  exports.AutomationRunVerdictSchema = AutomationRunVerdictSchema;
138694
+ exports.AutomationSetStepSchema = AutomationSetStepSchema;
136866
138695
  exports.AutomationStateDocSchema = AutomationStateDocSchema;
136867
138696
  exports.AutomationStepTraceSchema = AutomationStepTraceSchema;
138697
+ exports.AutomationStopStepSchema = AutomationStopStepSchema;
136868
138698
  exports.AutomationTriggerTraceSchema = AutomationTriggerTraceSchema;
136869
138699
  exports.AutomationWaitStepSchema = AutomationWaitStepSchema;
138700
+ exports.AutomationWaitUntilStepSchema = AutomationWaitUntilStepSchema;
136870
138701
  exports.AutomationWhenSchema = AutomationWhenSchema;
136871
138702
  exports.AvailableIntegrationTypeSchema = AvailableIntegrationTypeSchema;
136872
138703
  exports.BASE_DEVICE_CAPS = BASE_DEVICE_CAPS;
@@ -136944,8 +138775,10 @@ exports.CAP_RUNTIME_FIELD_UNITS = CAP_RUNTIME_FIELD_UNITS;
136944
138775
  exports.CAP_VOCABULARY = require_sleep.CAP_VOCABULARY;
136945
138776
  exports.CAP_VOCABULARY_BY_NAME = require_sleep.CAP_VOCABULARY_BY_NAME;
136946
138777
  exports.CATALOG_LANGS = CATALOG_LANGS;
138778
+ exports.CHOOSE_BRANCHES_MAX = CHOOSE_BRANCHES_MAX;
136947
138779
  exports.CIVIL_TWILIGHT_ALTITUDE_DEG = CIVIL_TWILIGHT_ALTITUDE_DEG;
136948
138780
  exports.CLASS_MAP_MACRO_TARGETS = CLASS_MAP_MACRO_TARGETS;
138781
+ exports.CLIMATE_ROLES = CLIMATE_ROLES;
136949
138782
  exports.CLIP_BROKER_PACED_RATES = CLIP_BROKER_PACED_RATES;
136950
138783
  exports.CLIP_LABEL_EVENT_FETCH_LIMIT = CLIP_LABEL_EVENT_FETCH_LIMIT;
136951
138784
  exports.CLIP_PLAYBACK_OPTIONS = CLIP_PLAYBACK_OPTIONS;
@@ -136991,6 +138824,7 @@ exports.CUSTOMIZATION_BLOCK_NAME_PREFIX = require_implemented_methods.CUSTOMIZAT
136991
138824
  exports.CUSTOMIZE_APPLY_AUTHORITY_KINDS = CUSTOMIZE_APPLY_AUTHORITY_KINDS;
136992
138825
  exports.CUSTOMIZE_CARDINALITIES = CUSTOMIZE_CARDINALITIES;
136993
138826
  exports.CUSTOMIZE_EVENT_SHAPES = CUSTOMIZE_EVENT_SHAPES;
138827
+ exports.CUSTOMIZE_TARGET_SECTIONS = CUSTOMIZE_TARGET_SECTIONS;
136994
138828
  exports.CalendarColorSchema = CalendarColorSchema;
136995
138829
  exports.CalendarEntrySchema = CalendarEntrySchema;
136996
138830
  exports.CalendarEventSchema = CalendarEventSchema;
@@ -137444,6 +139278,7 @@ exports.EVENT_LEAF_ID_RE = EVENT_LEAF_ID_RE;
137444
139278
  exports.EVENT_OWNER_TYPES = EVENT_OWNER_TYPES;
137445
139279
  exports.EVENT_PAD_MS = EVENT_PAD_MS;
137446
139280
  exports.EVENT_TAXONOMY = EVENT_TAXONOMY;
139281
+ exports.EVENT_VOCABULARY_KINDS = EVENT_VOCABULARY_KINDS;
137447
139282
  exports.EXPORT_DENSE_MAX_RANGES = EXPORT_DENSE_MAX_RANGES;
137448
139283
  exports.EXPORT_INSTANCE_UNKNOWN = EXPORT_INSTANCE_UNKNOWN;
137449
139284
  exports.EXPRESSION_BUILTINS = require_implemented_methods.EXPRESSION_BUILTINS;
@@ -137498,6 +139333,10 @@ exports.EventMediaKindSchema = EventMediaKindSchema;
137498
139333
  exports.EventMediaProductionSchema = EventMediaProductionSchema;
137499
139334
  exports.EventOwnerTypeSchema = EventOwnerTypeSchema;
137500
139335
  exports.EventSourceType = require_enums.EventSourceType$1;
139336
+ exports.EventVocabularyEntrySchema = EventVocabularyEntrySchema;
139337
+ exports.EventVocabularyFieldSchema = EventVocabularyFieldSchema;
139338
+ exports.EventVocabularyKindSchema = EventVocabularyKindSchema;
139339
+ exports.EventVocabularySourceSchema = EventVocabularySourceSchema;
137501
139340
  exports.ExportBytesSchema = ExportBytesSchema;
137502
139341
  exports.ExportClipSubjectSchema = ExportClipSubjectSchema;
137503
139342
  exports.ExportDenseRangeSchema = ExportDenseRangeSchema;
@@ -137550,11 +139389,13 @@ exports.FACE_RESCORE_INTERVAL_KEY = FACE_RESCORE_INTERVAL_KEY;
137550
139389
  exports.FACE_RESCORE_INTERVAL_MIN_RUNNING = FACE_RESCORE_INTERVAL_MIN_RUNNING;
137551
139390
  exports.FACE_RESCORE_SECTION_ID = FACE_RESCORE_SECTION_ID;
137552
139391
  exports.FAN_CAPTURE_FIELDS = FAN_CAPTURE_FIELDS;
137553
- exports.FAN_CAPTURE_GROUPS = FAN_CAPTURE_GROUPS;
139392
+ exports.FAN_OSCILLATION_AXES = FAN_OSCILLATION_AXES;
139393
+ exports.FAN_OSCILLATION_AXIS_LIMITS = FAN_OSCILLATION_AXIS_LIMITS;
139394
+ exports.FAN_OSCILLATION_AXIS_REFUSALS = FAN_OSCILLATION_AXIS_REFUSALS;
139395
+ exports.FAN_OSCILLATION_AXIS_SETTABLE = FAN_OSCILLATION_AXIS_SETTABLE;
137554
139396
  exports.FAN_OUT_CONCURRENCY = FAN_OUT_CONCURRENCY;
137555
139397
  exports.FAN_PRESETS_MAX = FAN_PRESETS_MAX;
137556
139398
  exports.FAN_PRESETS_REFUSALS = FAN_PRESETS_REFUSALS;
137557
- exports.FAN_PRESET_STEPS_MAX = FAN_PRESET_STEPS_MAX;
137558
139399
  exports.FEEDER_EXAMPLE_ADDON_ID = FEEDER_EXAMPLE_ADDON_ID;
137559
139400
  exports.FEEDER_EXAMPLE_HA_DEVICE_ID = FEEDER_EXAMPLE_HA_DEVICE_ID;
137560
139401
  exports.FEW_SHOT_COUNT = FEW_SHOT_COUNT;
@@ -137567,15 +139408,21 @@ exports.FailureContributionSchema = FailureContributionSchema;
137567
139408
  exports.FailureCounters = FailureCounters;
137568
139409
  exports.FailureReasonCountSchema = FailureReasonCountSchema;
137569
139410
  exports.FanCaptureFieldSchema = FanCaptureFieldSchema;
137570
- exports.FanCaptureGroupSchema = FanCaptureGroupSchema;
137571
- exports.FanCaptureItemSchema = FanCaptureItemSchema;
137572
139411
  exports.FanCaptureOmissionSchema = FanCaptureOmissionSchema;
137573
139412
  exports.FanControlStatusSchema = FanControlStatusSchema;
137574
139413
  exports.FanDirectionSchema = FanDirectionSchema;
139414
+ exports.FanOscillationAxesSchema = FanOscillationAxesSchema;
139415
+ exports.FanOscillationAxisFieldSchema = FanOscillationAxisFieldSchema;
139416
+ exports.FanOscillationAxisNameSchema = FanOscillationAxisNameSchema;
139417
+ exports.FanOscillationAxisRefusalSchema = FanOscillationAxisRefusalSchema;
139418
+ exports.FanOscillationAxisResultSchema = FanOscillationAxisResultSchema;
139419
+ exports.FanOscillationAxisSchema = FanOscillationAxisSchema;
137575
139420
  exports.FanPresetApplyResultSchema = FanPresetApplyResultSchema;
139421
+ exports.FanPresetAxisSchema = FanPresetAxisSchema;
137576
139422
  exports.FanPresetCaptureResultSchema = FanPresetCaptureResultSchema;
139423
+ exports.FanPresetFieldResultSchema = FanPresetFieldResultSchema;
137577
139424
  exports.FanPresetSchema = FanPresetSchema;
137578
- exports.FanPresetStepResultSchema = FanPresetStepResultSchema;
139425
+ exports.FanPresetStateSchema = FanPresetStateSchema;
137579
139426
  exports.FanPresetsRefusalSchema = FanPresetsRefusalSchema;
137580
139427
  exports.FanPresetsSetResultSchema = FanPresetsSetResultSchema;
137581
139428
  exports.FeatureManifestSchema = FeatureManifestSchema;
@@ -138341,6 +140188,8 @@ exports.PALETTE_MIN_CONTRAST = PALETTE_MIN_CONTRAST;
138341
140188
  exports.PALETTE_MIN_DELTA_E = PALETTE_MIN_DELTA_E;
138342
140189
  exports.PALETTE_MIN_DELTA_E_MARK = PALETTE_MIN_DELTA_E_MARK;
138343
140190
  exports.PALETTE_PRESET_IDS = PALETTE_PRESET_IDS;
140191
+ exports.PARALLEL_STEPS_MAX = PARALLEL_STEPS_MAX;
140192
+ exports.PARALLEL_STEPS_MIN = PARALLEL_STEPS_MIN;
138344
140193
  exports.PAUSE_MAX_MS = PAUSE_MAX_MS;
138345
140194
  exports.PEER_BYTES_CHUNK_BYTES = require_sleep.PEER_BYTES_CHUNK_BYTES;
138346
140195
  exports.PEER_BYTES_MAX_OUTSTANDING = require_sleep.PEER_BYTES_MAX_OUTSTANDING;
@@ -138417,6 +140266,7 @@ exports.PowerSourceActionResultSchema = PowerSourceActionResultSchema;
138417
140266
  exports.PowerSourceInfoSchema = PowerSourceInfoSchema;
138418
140267
  exports.PowerSourceRefusalReasonSchema = PowerSourceRefusalReasonSchema;
138419
140268
  exports.PowerSourceStateSchema = PowerSourceStateSchema;
140269
+ exports.PowerSwitchRefusedError = PowerSwitchRefusedError;
138420
140270
  exports.PrecisionGopsSchema = PrecisionGopsSchema;
138421
140271
  exports.PreferenceDeviceIdSchema = PreferenceDeviceIdSchema;
138422
140272
  exports.PreferenceNamespaceSchema = PreferenceNamespaceSchema;
@@ -138527,8 +140377,14 @@ exports.REMOTE_WIDGET_ROLES = REMOTE_WIDGET_ROLES;
138527
140377
  exports.REMOVAL_RECONCILE_INTERVAL_MS = REMOVAL_RECONCILE_INTERVAL_MS;
138528
140378
  exports.REMOVED_MODEL_IDS = REMOVED_MODEL_IDS;
138529
140379
  exports.REMOVE_LEAF = require_sleep.REMOVE_LEAF;
140380
+ exports.REPEAT_COUNT_MAX = REPEAT_COUNT_MAX;
140381
+ exports.REPEAT_DEVICES_MAX = REPEAT_DEVICES_MAX;
140382
+ exports.REPEAT_ITEM_VAR = REPEAT_ITEM_VAR;
140383
+ exports.REPEAT_ITERATIONS_MAX = REPEAT_ITERATIONS_MAX;
140384
+ exports.REPEAT_STEPS_MAX = REPEAT_STEPS_MAX;
138530
140385
  exports.RESERVED_BINDING_NAMES = require_implemented_methods.RESERVED_BINDING_NAMES;
138531
140386
  exports.RESERVED_COLLECTION_SOURCES = RESERVED_COLLECTION_SOURCES;
140387
+ exports.RESERVED_RUN_VARS = RESERVED_RUN_VARS;
138532
140388
  exports.RESET_PERIODS = require_implemented_methods.RESET_PERIODS;
138533
140389
  exports.RESTORED_CAP_NAMES = RESTORED_CAP_NAMES;
138534
140390
  exports.RESTREAM_INPUT_PROBE = require_implemented_methods.RESTREAM_INPUT_PROBE;
@@ -138762,6 +140618,7 @@ exports.SCENE_DEFAULT_QUIET_SECONDS = SCENE_DEFAULT_QUIET_SECONDS;
138762
140618
  exports.SCENE_DEFAULT_UNCOVERED_POLICY = SCENE_DEFAULT_UNCOVERED_POLICY;
138763
140619
  exports.SCENE_DIVERGED = SCENE_DIVERGED;
138764
140620
  exports.SCENE_RESET_RECAPTURES = SCENE_RESET_RECAPTURES;
140621
+ exports.SCHEDULER_WAIT_MAX_SECONDS = SCHEDULER_WAIT_MAX_SECONDS;
138765
140622
  exports.SCOPED_SETTINGS_SCOPES = require_sleep.SCOPED_SETTINGS_SCOPES;
138766
140623
  exports.SCOPE_PRESETS = SCOPE_PRESETS;
138767
140624
  exports.SECRET_CLEAR = require_sleep.SECRET_CLEAR;
@@ -138775,6 +140632,9 @@ exports.SERVER_NAME_MAX_LENGTH = SERVER_NAME_MAX_LENGTH;
138775
140632
  exports.SERVER_NAME_SETTING_KEY = SERVER_NAME_SETTING_KEY;
138776
140633
  exports.SESSION_LOST_ALERT_CATEGORY = SESSION_LOST_ALERT_CATEGORY;
138777
140634
  exports.SESSION_PLACEMENT_SETTING_KEY = SESSION_PLACEMENT_SETTING_KEY;
140635
+ exports.SET_VARS_MAX = SET_VARS_MAX;
140636
+ exports.SET_VAR_NAME_RE = SET_VAR_NAME_RE;
140637
+ exports.SET_VAR_VALUE_MAX = SET_VAR_VALUE_MAX;
138778
140638
  exports.SHARE_AFFINITY_TOLERANCE_SESSIONS = SHARE_AFFINITY_TOLERANCE_SESSIONS;
138779
140639
  exports.SHARE_SOURCE_SETTING_KEY = SHARE_SOURCE_SETTING_KEY;
138780
140640
  exports.SHARE_VIEW_KINDS = require_sleep.SHARE_VIEW_KINDS;
@@ -138802,6 +140662,8 @@ exports.STATE_LABEL_KEYS = STATE_LABEL_KEYS;
138802
140662
  exports.STATIONARY_OVERLAY_STYLE = STATIONARY_OVERLAY_STYLE;
138803
140663
  exports.STATISTIC_STATS = require_implemented_methods.STATISTIC_STATS;
138804
140664
  exports.STEP_DEVICE_CONCURRENCY = STEP_DEVICE_CONCURRENCY;
140665
+ exports.STEP_NEST_MAX = STEP_NEST_MAX;
140666
+ exports.STOP_REASON_MAX = STOP_REASON_MAX;
138805
140667
  exports.STORAGE_ACCESS_FALLBACK = STORAGE_ACCESS_FALLBACK;
138806
140668
  exports.STORAGE_BYTES_PER_GB = STORAGE_BYTES_PER_GB;
138807
140669
  exports.STORAGE_LOCATION_MODES = STORAGE_LOCATION_MODES;
@@ -138861,6 +140723,7 @@ exports.SessionPlacementPolicySchema = SessionPlacementPolicySchema;
138861
140723
  exports.SessionTriggerSchema = SessionTriggerSchema;
138862
140724
  exports.SetCameraSensorsInputSchema = SetCameraSensorsInputSchema;
138863
140725
  exports.SetLoggingSettingsInputSchema = SetLoggingSettingsInputSchema;
140726
+ exports.SetOscillationAxisInputSchema = SetOscillationAxisInputSchema;
138864
140727
  exports.SetShareSourceInputSchema = SetShareSourceInputSchema;
138865
140728
  exports.SetSiteLocationInputSchema = SetSiteLocationInputSchema;
138866
140729
  exports.SetTrackPurityInputSchema = SetTrackPurityInputSchema;
@@ -138981,8 +140844,10 @@ exports.TEMPLATE_KINDS = TEMPLATE_KINDS;
138981
140844
  exports.TEMPLATE_PAYLOAD_SCHEMAS = TEMPLATE_PAYLOAD_SCHEMAS;
138982
140845
  exports.TEMPLATE_WRITE_REFUSALS = TEMPLATE_WRITE_REFUSALS;
138983
140846
  exports.THRESHOLD_GRID_W = THRESHOLD_GRID_W;
140847
+ exports.TIMED_RUN_DEVICE_ROLES = TIMED_RUN_DEVICE_ROLES;
138984
140848
  exports.TIMED_RUN_DEVICE_TYPES = TIMED_RUN_DEVICE_TYPES;
138985
- exports.TIMED_RUN_LIMITS = TIMED_RUN_LIMITS;
140849
+ exports.TIMED_RUN_HEATER_LIMIT = TIMED_RUN_HEATER_LIMIT;
140850
+ exports.TIMED_RUN_PET_FOUNTAIN_LIMIT = TIMED_RUN_PET_FOUNTAIN_LIMIT;
138986
140851
  exports.TIMELAPSE_DENSE_FLOOR_SEC = TIMELAPSE_DENSE_FLOOR_SEC;
138987
140852
  exports.TIMEZONES = TIMEZONES;
138988
140853
  exports.TRACK_RELATIONS_DEFAULT_LIMIT = TRACK_RELATIONS_DEFAULT_LIMIT;
@@ -139158,6 +141023,8 @@ exports.VideoEncodeSchema = VideoEncodeSchema;
139158
141023
  exports.ViewerDeviceAllowSchema = ViewerDeviceAllowSchema;
139159
141024
  exports.ViewerFeatureIdSchema = ViewerFeatureIdSchema;
139160
141025
  exports.ViewerTokenScopeSchema = ViewerTokenScopeSchema;
141026
+ exports.WAIT_MAX_SECONDS = WAIT_MAX_SECONDS;
141027
+ exports.WAIT_UNTIL_TIMEOUT_MAX_S = WAIT_UNTIL_TIMEOUT_MAX_S;
139161
141028
  exports.WEBRTC_CLIMB_HOLD_CODES = WEBRTC_CLIMB_HOLD_CODES;
139162
141029
  exports.WEBRTC_EGRESS_PROFILE = WEBRTC_EGRESS_PROFILE;
139163
141030
  exports.WEBRTC_TRY_BLOCKERS = WEBRTC_TRY_BLOCKERS;
@@ -139243,6 +141110,7 @@ exports.allVocabActions = require_sleep.allVocabActions;
139243
141110
  exports.allowedSuppliedEffect = allowedSuppliedEffect;
139244
141111
  exports.ambientLightSensorCapability = ambientLightSensorCapability;
139245
141112
  exports.annotateClipsWithEventLabels = annotateClipsWithEventLabels;
141113
+ exports.anyAxisOscillating = anyAxisOscillating;
139246
141114
  exports.anySubjectMatches = anySubjectMatches;
139247
141115
  exports.appFlowLocation = appFlowLocation;
139248
141116
  exports.appendTrace = appendTrace;
@@ -139320,6 +141188,7 @@ exports.buildModelVariantGroups = buildModelVariantGroups;
139320
141188
  exports.buildNcTaxonomy = buildNcTaxonomy;
139321
141189
  exports.buildNotificationTargetInstances = buildNotificationTargetInstances;
139322
141190
  exports.buildPlusCatalogClassMap = buildPlusCatalogClassMap;
141191
+ exports.buildPowerSwitch = buildPowerSwitch;
139323
141192
  exports.buildRepairPrompt = buildRepairPrompt;
139324
141193
  exports.buildRoleScopes = buildRoleScopes;
139325
141194
  exports.buildSecretRef = require_sleep.buildSecretRef;
@@ -139352,7 +141221,9 @@ exports.canConvertUnit = require_convert.canConvertUnit;
139352
141221
  exports.canonicalEgressPlan = canonicalEgressPlan;
139353
141222
  exports.canonicalIconKey = canonicalIconKey;
139354
141223
  exports.canonicalJson = canonicalJson;
141224
+ exports.canonicalStoredDeviceType = canonicalStoredDeviceType;
139355
141225
  exports.canonicalizeAppCallback = canonicalizeAppCallback;
141226
+ exports.capAppliesToDeviceKind = capAppliesToDeviceKind;
139356
141227
  exports.capUnitResolver = capUnitResolver;
139357
141228
  exports.capabilityScopesOf = capabilityScopesOf;
139358
141229
  exports.capacityForModel = capacityForModel;
@@ -139381,6 +141252,7 @@ exports.clearKnownSecrets = require_sleep.clearKnownSecrets;
139381
141252
  exports.clearModelBoundOverrides = clearModelBoundOverrides;
139382
141253
  exports.clearModelBoundSetting = clearModelBoundSetting;
139383
141254
  exports.climateControlCapability = climateControlCapability;
141255
+ exports.climateRoleOf = climateRoleOf;
139384
141256
  exports.clipEventLabelDepsFromApi = clipEventLabelDepsFromApi;
139385
141257
  exports.clipExportFailure = clipExportFailure;
139386
141258
  exports.clipExportFailureOf = clipExportFailureOf;
@@ -139437,6 +141309,7 @@ exports.compositionSliceKey = require_implemented_methods.compositionSliceKey;
139437
141309
  exports.compositionSourceKey = require_implemented_methods.compositionSourceKey;
139438
141310
  exports.compositionSourceRefs = compositionSourceRefs;
139439
141311
  exports.compositionTargetCaps = compositionTargetCaps;
141312
+ exports.compositionUnionReads = compositionUnionReads;
139440
141313
  exports.computeCapacityShares = computeCapacityShares;
139441
141314
  exports.computeScores = computeScores;
139442
141315
  exports.conditionExclusionReason = conditionExclusionReason;
@@ -139449,6 +141322,7 @@ exports.consumablesCapability = consumablesCapability;
139449
141322
  exports.contactCapability = contactCapability;
139450
141323
  exports.containingParentIndex = containingParentIndex;
139451
141324
  exports.controlCapability = controlCapability;
141325
+ exports.conventionalEventVocabulary = conventionalEventVocabulary;
139452
141326
  exports.convertLegacyCondition = convertLegacyCondition;
139453
141327
  exports.convertLegacyRecipe = convertLegacyRecipe;
139454
141328
  exports.convertLegacyWhen = convertLegacyWhen;
@@ -139637,6 +141511,7 @@ exports.eventEmitterCapability = eventEmitterCapability;
139637
141511
  exports.eventKindLabel = eventKindLabel;
139638
141512
  exports.eventLeafIdAt = eventLeafIdAt;
139639
141513
  exports.eventOverlapsClipWindow = eventOverlapsClipWindow;
141514
+ exports.eventTypesOfVocabulary = eventTypesOfVocabulary;
139640
141515
  exports.evictionPolicyForMode = evictionPolicyForMode;
139641
141516
  exports.evictionPolicyOfLocation = evictionPolicyOfLocation;
139642
141517
  exports.expandAudioChunkToF32le = require_sleep.expandAudioChunkToF32le;
@@ -139654,6 +141529,7 @@ exports.extractSourceInfoFromMetadata = extractSourceInfoFromMetadata;
139654
141529
  exports.faceGalleryCapability = faceGalleryCapability;
139655
141530
  exports.failureContributionCapability = failureContributionCapability;
139656
141531
  exports.failureRate = failureRate;
141532
+ exports.fanAxisPath = fanAxisPath;
139657
141533
  exports.fanControlCapability = fanControlCapability;
139658
141534
  exports.fanOutTargets = fanOutTargets;
139659
141535
  exports.fanPresetsCapability = fanPresetsCapability;
@@ -139680,6 +141556,7 @@ exports.findCompositionCycles = findCompositionCycles;
139680
141556
  exports.findMigrationsBlocked = require_sleep.findMigrationsBlocked;
139681
141557
  exports.findTimezone = findTimezone;
139682
141558
  exports.findVocabAction = require_sleep.findVocabAction;
141559
+ exports.findVocabularyEntry = findVocabularyEntry;
139683
141560
  exports.flattenNestedRecords = flattenNestedRecords;
139684
141561
  exports.flattenPortsOver = flattenPortsOver;
139685
141562
  exports.flipperIrDraft = flipperIrDraft;
@@ -139795,7 +141672,9 @@ exports.invertPresetFeature = invertPresetFeature;
139795
141672
  exports.invocationFromEncodeProfile = require_implemented_methods.invocationFromEncodeProfile;
139796
141673
  exports.irSourceProblem = irSourceProblem;
139797
141674
  exports.irTransmitterCapability = irTransmitterCapability;
141675
+ exports.isAddonInstanceId = isAddonInstanceId;
139798
141676
  exports.isAgentOnlyPlacement = isAgentOnlyPlacement;
141677
+ exports.isAirConditioner = isAirConditioner;
139799
141678
  exports.isAlarmControllableCap = isAlarmControllableCap;
139800
141679
  exports.isAlertEpisodeOpen = isAlertEpisodeOpen;
139801
141680
  exports.isAlertEpisodeSeverity = isAlertEpisodeSeverity;
@@ -140006,6 +141885,7 @@ exports.nativeObjectDetectionCapability = nativeObjectDetectionCapability;
140006
141885
  exports.navigationCapability = navigationCapability;
140007
141886
  exports.ncAlarmSystemDefaultSettings = ncAlarmSystemDefaultSettings;
140008
141887
  exports.ncMediaPolicyError = ncMediaPolicyError;
141888
+ exports.nestedStepsOf = nestedStepsOf;
140009
141889
  exports.networkAccessCapability = networkAccessCapability;
140010
141890
  exports.networkLinkCapability = networkLinkCapability;
140011
141891
  exports.networkQualityCapability = networkQualityCapability;
@@ -140045,6 +141925,8 @@ exports.notifierCapability = notifierCapability;
140045
141925
  exports.numericSensorCapability = numericSensorCapability;
140046
141926
  exports.oauthIntegrationCapability = oauthIntegrationCapability;
140047
141927
  exports.oauthLandingUrl = oauthLandingUrl;
141928
+ exports.oauthLinkInstanceId = oauthLinkInstanceId;
141929
+ exports.oauthLinkServesInstance = oauthLinkServesInstance;
140048
141930
  exports.objectInputDeclaresAddonId = objectInputDeclaresAddonId;
140049
141931
  exports.objectInputDeclaresRequiredDeviceId = objectInputDeclaresRequiredDeviceId;
140050
141932
  exports.observeHoldLeaves = observeHoldLeaves;
@@ -140126,6 +142008,7 @@ exports.pipelineAnalyticsCapability = pipelineAnalyticsCapability;
140126
142008
  exports.pipelineExecutorCapability = pipelineExecutorCapability;
140127
142009
  exports.pipelineOrchestratorCapability = pipelineOrchestratorCapability;
140128
142010
  exports.pipelineRunnerCapability = pipelineRunnerCapability;
142011
+ exports.plainEventVocabulary = plainEventVocabulary;
140129
142012
  exports.planComposition = planComposition;
140130
142013
  exports.planCompositionEvents = planCompositionEvents;
140131
142014
  exports.planItems = planItems;
@@ -140140,6 +142023,9 @@ exports.plusCatalogDefaultClassFloors = plusCatalogDefaultClassFloors;
140140
142023
  exports.plusCatalogLabelFields = plusCatalogLabelFields;
140141
142024
  exports.poolMemoryThreshold = poolMemoryThreshold;
140142
142025
  exports.powerMeterCapability = powerMeterCapability;
142026
+ exports.powerOnFromSlice = powerOnFromSlice;
142027
+ exports.powerServedBy = powerServedBy;
142028
+ exports.powerSourceActuatorConflicts = powerSourceActuatorConflicts;
140143
142029
  exports.powerSourceCapability = powerSourceCapability;
140144
142030
  exports.powerSourceLinkOfComposition = powerSourceLinkOfComposition;
140145
142031
  exports.preconditionOf = preconditionOf;
@@ -140181,6 +142067,7 @@ exports.readCommandOrigin = require_sleep.readCommandOrigin;
140181
142067
  exports.readDetailCropConvention = readDetailCropConvention;
140182
142068
  exports.readDeviceStateFrom = readDeviceStateFrom;
140183
142069
  exports.readErrorI18n = require_sleep.readErrorI18n;
142070
+ exports.readEventVocabulary = readEventVocabulary;
140184
142071
  exports.readFaceRescoreIntervalMinutes = readFaceRescoreIntervalMinutes;
140185
142072
  exports.readHubMotionDetected = readHubMotionDetected;
140186
142073
  exports.readHubMotionStatus = readHubMotionStatus;
@@ -140219,6 +142106,7 @@ exports.rectsToCells = rectsToCells;
140219
142106
  exports.reducePoints = reducePoints;
140220
142107
  exports.reducerForActive = reducerForActive;
140221
142108
  exports.registerKnownSecret = require_sleep.registerKnownSecret;
142109
+ exports.registerPowerSwitch = registerPowerSwitch;
140222
142110
  exports.registrySwitchPortsOver = require_sleep.registrySwitchPortsOver;
140223
142111
  exports.registrySwitchToBodyId = require_sleep.registrySwitchToBodyId;
140224
142112
  exports.registrySwitchToBodyMigration = require_sleep.registrySwitchToBodyMigration;
@@ -140233,6 +142121,7 @@ exports.removeGroup = removeGroup;
140233
142121
  exports.removeScalarTarget = removeScalarTarget;
140234
142122
  exports.renameAlarmProfile = renameAlarmProfile;
140235
142123
  exports.renderVocabPhrase = renderVocabPhrase;
142124
+ exports.repeatCheck = repeatCheck;
140236
142125
  exports.replacedFieldKeys = replacedFieldKeys;
140237
142126
  exports.replayDwellIntervals = replayDwellIntervals;
140238
142127
  exports.reportIsScalable = reportIsScalable;
@@ -140421,7 +142310,6 @@ exports.smokeCapability = smokeCapability;
140421
142310
  exports.smtpProviderCapability = smtpProviderCapability;
140422
142311
  exports.smtpSinceKey = smtpSinceKey;
140423
142312
  exports.snapshotCapability = snapshotCapability;
140424
- exports.sourcePickForHeaterPlug = sourcePickForHeaterPlug;
140425
142313
  exports.sourcePickForHistory = sourcePickForHistory;
140426
142314
  exports.sourcePickForMath = sourcePickForMath;
140427
142315
  exports.sourcePickForTemplate = sourcePickForTemplate;
@@ -140437,6 +142325,8 @@ exports.stateVocabularyFor = stateVocabularyFor;
140437
142325
  exports.statisticCadenceMs = require_implemented_methods.statisticCadenceMs;
140438
142326
  exports.statisticDraft = statisticDraft;
140439
142327
  exports.statusInstanceOf = statusInstanceOf;
142328
+ exports.stepConditionsOf = stepConditionsOf;
142329
+ exports.stepGuardOf = stepGuardOf;
140440
142330
  exports.stepGuardSiteIssues = stepGuardSiteIssues;
140441
142331
  exports.stepModelRunsOnFormat = stepModelRunsOnFormat;
140442
142332
  exports.stepPulse = stepPulse;
@@ -140585,6 +142475,8 @@ exports.viewerUiCapability = require_sleep.viewerUiCapability;
140585
142475
  exports.vocabActionIdFor = require_sleep.vocabActionIdFor;
140586
142476
  exports.vocabularyActionsForDevice = actionsForDevice$1;
140587
142477
  exports.vocabularyTriggersForDevice = triggersForDevice;
142478
+ exports.waitTimedOutMessage = waitTimedOutMessage;
142479
+ exports.waitUntil = waitUntil;
140588
142480
  exports.waterHeaterCapability = waterHeaterCapability;
140589
142481
  exports.wattMillisecondsToKwh = require_implemented_methods.wattMillisecondsToKwh;
140590
142482
  exports.weatherCapability = weatherCapability;