@camstack/addon-provider-homematic 1.2.190 → 1.2.192

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.
package/dist/addon.js CHANGED
@@ -6053,7 +6053,7 @@ var ZodIssueCode = {
6053
6053
  var ZodFirstPartyTypeKind;
6054
6054
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
6055
6055
  //#endregion
6056
- //#region ../types/dist/sleep-Bn346wCJ.mjs
6056
+ //#region ../types/dist/sleep-D0roI_CZ.mjs
6057
6057
  /**
6058
6058
  * The audio chunk plane's byte format, and the ONE expansion from a coded
6059
6059
  * window to float samples (D455).
@@ -16208,6 +16208,10 @@ Object.freeze({
16208
16208
  "path": "lastEvent.eventType",
16209
16209
  "valueType": "string"
16210
16210
  },
16211
+ {
16212
+ "path": "lastEvent.sourceId",
16213
+ "valueType": "string"
16214
+ },
16211
16215
  {
16212
16216
  "path": "lastEvent.timestamp",
16213
16217
  "valueType": "number"
@@ -44078,6 +44082,59 @@ function macroOnly(macro) {
44078
44082
  };
44079
44083
  }
44080
44084
  }
44085
+ var EventVocabularyKindSchema = _enum([
44086
+ "press",
44087
+ "long-press",
44088
+ "long-press-start",
44089
+ "release",
44090
+ "repeat",
44091
+ "double-press",
44092
+ "other"
44093
+ ]);
44094
+ /** The part of the device an event comes from: a button, a channel. */
44095
+ var EventVocabularySourceSchema = object({
44096
+ id: string().min(1),
44097
+ label: string().min(1)
44098
+ });
44099
+ /** One scalar field of an event's `data`, by dotted path. */
44100
+ var EventVocabularyFieldSchema = object({
44101
+ path: string().min(1),
44102
+ kind: _enum([
44103
+ "string",
44104
+ "number",
44105
+ "boolean",
44106
+ "enum"
44107
+ ]),
44108
+ enumValues: array(string()).optional(),
44109
+ label: string().min(1).optional()
44110
+ });
44111
+ var EventVocabularyEntrySchema = object({
44112
+ /** The native token, verbatim. */
44113
+ id: string().min(1),
44114
+ source: EventVocabularySourceSchema.optional(),
44115
+ label: string().min(1),
44116
+ description: string().optional(),
44117
+ kind: EventVocabularyKindSchema.optional(),
44118
+ payload: array(EventVocabularyFieldSchema).optional()
44119
+ });
44120
+ /**
44121
+ * The vocabulary of a source that declares tokens and nothing else: one
44122
+ * entry per token, labelled with the token itself.
44123
+ */
44124
+ function plainEventVocabulary(eventTypes) {
44125
+ return [...new Set(eventTypes)].filter((eventType) => eventType !== "").map((eventType) => ({
44126
+ id: eventType,
44127
+ label: eventType
44128
+ }));
44129
+ }
44130
+ /** The native tokens of a vocabulary, each once, in declaration order. */
44131
+ function eventTypesOfVocabulary(vocabulary) {
44132
+ return [...new Set(vocabulary.map((entry) => entry.id))];
44133
+ }
44134
+ /** The entry a fire belongs to: same token, same source (or both without one). */
44135
+ function findVocabularyEntry(vocabulary, eventType, sourceId) {
44136
+ return vocabulary.find((entry) => entry.id === eventType && entry.source?.id === sourceId);
44137
+ }
44081
44138
  Math.PI / 180;
44082
44139
  /**
44083
44140
  * WHEN something happens, as data (D983) — the one time vocabulary of the
@@ -44285,6 +44342,33 @@ var ScheduleLeafSchema = object({
44285
44342
  /** @deprecated legacy cron — new schedules use `at`. */
44286
44343
  cron: string().min(1).max(120).optional()
44287
44344
  }).refine((leaf) => leaf.at === void 0 !== (leaf.cron === void 0), { message: "a schedule names exactly one of `at` (a time spec) and `cron` (legacy)" }).refine((leaf) => leaf.days === void 0 || leaf.at !== void 0, { message: "`days` goes with `at`; a cron expression carries its own days" });
44345
+ /**
44346
+ * One payload predicate of a `device-fired` row: the value at `path` inside
44347
+ * the fire's `data` (dotted) equals `equals`. Compared strictly, no coercion.
44348
+ */
44349
+ var DeviceFiredMatchSchema = object({
44350
+ path: string().min(1).max(120),
44351
+ equals: union([
44352
+ string(),
44353
+ number$1(),
44354
+ boolean()
44355
+ ])
44356
+ });
44357
+ /**
44358
+ * "fires": one device of the `event-emitter` capability reported an event
44359
+ * (D1045). Every list is an OR, the lists together an AND; an absent list does
44360
+ * not narrow. `eventIds` are the device's own tokens, `sourceIds` the parts of
44361
+ * the device (a button), `kinds` the shared press kinds of its vocabulary.
44362
+ */
44363
+ var DeviceFiredLeafSchema = object({
44364
+ kind: literal("device-fired"),
44365
+ ...eventLeafId,
44366
+ deviceId: number$1().int().nonnegative(),
44367
+ eventIds: array(string().min(1)).min(1).max(64).optional(),
44368
+ sourceIds: array(string().min(1)).min(1).max(64).optional(),
44369
+ kinds: array(EventVocabularyKindSchema).min(1).optional(),
44370
+ match: array(DeviceFiredMatchSchema).min(1).max(8).optional()
44371
+ });
44288
44372
  var ManualLeafSchema = object({
44289
44373
  kind: literal("manual"),
44290
44374
  ...eventLeafId
@@ -44426,6 +44510,7 @@ var AutomationWhenSchema = lazy(() => discriminatedUnion("kind", [
44426
44510
  }),
44427
44511
  DeviceBecomesLeafSchema,
44428
44512
  DeviceEventLeafSchema,
44513
+ DeviceFiredLeafSchema,
44429
44514
  ScheduleLeafSchema,
44430
44515
  ManualLeafSchema,
44431
44516
  IntervalLeafSchema,
@@ -44440,6 +44525,7 @@ var AutomationWhenSchema = lazy(() => discriminatedUnion("kind", [
44440
44525
  var EVENT_KINDS = new Set([
44441
44526
  "device-becomes",
44442
44527
  "device-event",
44528
+ "device-fired",
44443
44529
  "schedule",
44444
44530
  "manual",
44445
44531
  "interval",
@@ -44520,6 +44606,7 @@ function hasEmptyContainer(node) {
44520
44606
  var LEAF_WORDS = {
44521
44607
  "device-becomes": "a device value that becomes",
44522
44608
  "device-event": "a device event",
44609
+ "device-fired": "a device firing an event",
44523
44610
  schedule: "a schedule",
44524
44611
  manual: "a manual run",
44525
44612
  interval: "an interval",
@@ -44785,9 +44872,12 @@ function convertLegacyWhen(half) {
44785
44872
  * every caller — automations, Actions, and the notification centre, which runs
44786
44873
  * only Actions (planning#473).
44787
44874
  */
44875
+ /** The longest one `wait` step lasts. It is cut by a restart of the run and does not survive a hub restart. */
44876
+ var WAIT_MAX_SECONDS = 3600;
44877
+ var WAIT_TOO_LONG = `a wait is at most one hour (${WAIT_MAX_SECONDS} s)`;
44788
44878
  var AutomationWaitStepSchema = object({
44789
44879
  kind: literal("wait"),
44790
- seconds: number$1().min(0).max(300)
44880
+ seconds: number$1().min(0).max(WAIT_MAX_SECONDS, WAIT_TOO_LONG)
44791
44881
  });
44792
44882
  /** The legacy `deviceId` of a cap step: still READ, never written (D983). */
44793
44883
  var LegacyStepDeviceSchema = union([
@@ -44857,39 +44947,227 @@ var elseNeedsIf = {
44857
44947
  path: ["else"]
44858
44948
  };
44859
44949
  var GuardedWaitStepSchema = AutomationWaitStepSchema.extend(stepGuardShape).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
44860
- var GuardedCapStepSchema = AutomationCapStepBaseSchema.extend(stepGuardShape).refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
44861
- message: "a cap step needs a target",
44862
- path: ["target"]
44863
- }).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
44864
- message: "a domain target needs the vocabulary action it applies to (actionId)",
44865
- path: ["actionId"]
44866
- }).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
44867
44950
  /**
44868
44951
  * A step of a STANDALONE list (an action, a scheduler point, a preset): the
44869
44952
  * same two step kinds an automation runs, minus a guard that reads the
44870
44953
  * automation's trigger, which such a list does not have.
44871
44954
  */
44872
- var ActionStepSchema = discriminatedUnion("kind", [GuardedWaitStepSchema, GuardedCapStepSchema]).superRefine((step, ctx) => {
44955
+ var ActionStepSchema = discriminatedUnion("kind", [GuardedWaitStepSchema, AutomationCapStepBaseSchema.extend(stepGuardShape).refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
44956
+ message: "a cap step needs a target",
44957
+ path: ["target"]
44958
+ }).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
44959
+ message: "a domain target needs the vocabulary action it applies to (actionId)",
44960
+ path: ["actionId"]
44961
+ }).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf)]).superRefine((step, ctx) => {
44873
44962
  if (step.if !== void 0 && hasTriggeredByLeaves(step.if)) ctx.addIssue({
44874
44963
  code: "custom",
44875
44964
  message: TRIGGERED_BY_NEEDS_AUTOMATION,
44876
44965
  path: ["if"]
44877
44966
  });
44878
44967
  });
44968
+ /**
44969
+ * Flow control of an AUTOMATION's list (#500). A standalone list (an action, a
44970
+ * scheduler point, a preset) stays `wait` and `cap`: it has no run of its own
44971
+ * to end and no variable bag to write.
44972
+ */
44973
+ var continueOnErrorShape = {
44974
+ /** A failure of this step is traced `failed-continued` and the next step runs. */
44975
+ continueOnError: literal(true).optional() };
44976
+ /** An automation's cap step: the shared guarded cap step, plus `continueOnError`. */
44977
+ var AutomationGuardedCapStepSchema = AutomationCapStepBaseSchema.extend({
44978
+ ...stepGuardShape,
44979
+ ...continueOnErrorShape
44980
+ }).refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
44981
+ message: "a cap step needs a target",
44982
+ path: ["target"]
44983
+ }).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
44984
+ message: "a domain target needs the vocabulary action it applies to (actionId)",
44985
+ path: ["actionId"]
44986
+ }).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
44987
+ /** End the run here, on purpose. `reason` may carry `{{vars.x}}` slots. */
44988
+ var AutomationStopStepSchema = object({
44989
+ kind: literal("stop"),
44990
+ reason: string().min(1, "a stop needs a reason: it is what the run trace shows").max(200),
44991
+ /** `ok`: the run ends as a success. `failed`: it ends as a failure, with the reason. */
44992
+ outcome: _enum(["ok", "failed"]),
44993
+ /** Stop only when this reads true; false or unknown does not stop. */
44994
+ if: AutomationWhenSchema.optional()
44995
+ });
44996
+ var SET_VAR_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]{0,39}$/;
44997
+ /** Names the run itself writes and reads (`leaf` is what `triggered-by` judges): a step may not overwrite them. */
44998
+ var RESERVED_RUN_VARS = [
44999
+ "kind",
45000
+ "leaf",
45001
+ "at"
45002
+ ];
45003
+ /**
45004
+ * Write variables into the run's bag, for the steps after it. SUBSTITUTION
45005
+ * only, never evaluation: a text value may carry `{{vars.x}}` slots.
45006
+ */
45007
+ var AutomationSetStepSchema = object({
45008
+ kind: literal("set"),
45009
+ vars: record(string(), union([
45010
+ string().max(500),
45011
+ number$1(),
45012
+ boolean()
45013
+ ])).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` }),
45014
+ /** Set only when this reads true; false or unknown leaves the bag as it is. */
45015
+ if: AutomationWhenSchema.optional()
45016
+ });
45017
+ var AutomationRunActionStepSchema = object({
45018
+ kind: literal("action"),
45019
+ /** An entry of the `actions` surface (`internal:<uuid>` or `<addonId>:<localId>`). */
45020
+ actionId: string().min(1),
45021
+ /** Values for the action's declared variables; the others take their default. */
45022
+ variables: record(string(), union([
45023
+ string(),
45024
+ number$1(),
45025
+ boolean()
45026
+ ])).optional(),
45027
+ ...continueOnErrorShape
45028
+ });
45029
+ /**
45030
+ * A step INSIDE a branch of a `choose`: a flow step with no condition of its
45031
+ * own (the branch is the condition) and no block inside it. Strict, so an `if`
45032
+ * written on such a step is refused rather than dropped.
45033
+ */
45034
+ /** The longest a `wait-until` may wait: six hours. */
45035
+ var WAIT_UNTIL_TIMEOUT_MAX_S = 21600;
45036
+ /**
45037
+ * Pause the run until a condition is true (#500). The timeout is mandatory: a
45038
+ * run never waits without an end. `onTimeout` says what a wait that ran out
45039
+ * does: `continue` goes on to the next step, `stop` ends the run as a failure.
45040
+ * A condition that cannot be read is not "true": the wait goes on (D49).
45041
+ */
45042
+ var AutomationWaitUntilStepSchema = object({
45043
+ kind: literal("wait-until"),
45044
+ when: AutomationWhenSchema,
45045
+ timeoutS: number$1().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)`),
45046
+ onTimeout: _enum(["continue", "stop"])
45047
+ }).strict();
45048
+ /** The step kinds that hold steps of their own, or pause on a condition: they nest two levels at most. */
45049
+ var BLOCK_STEP_KINDS = [
45050
+ "choose",
45051
+ "repeat",
45052
+ "parallel",
45053
+ "wait-until"
45054
+ ];
45055
+ var NEST_TOO_DEEP = `steps nest two levels at most: a step inside a nested choose or repeat can be a plain step only`;
45056
+ function kindOf(input) {
45057
+ return typeof input === "object" && input !== null ? Reflect.get(input, "kind") : void 0;
45058
+ }
45059
+ /** Where the nesting ends, a block step is refused in words rather than as an unknown kind. */
45060
+ function nestTooDeep(issue) {
45061
+ const kind = kindOf(issue.input);
45062
+ return typeof kind === "string" && BLOCK_STEP_KINDS.includes(kind) ? NEST_TOO_DEEP : void 0;
45063
+ }
45064
+ var plainStepSchemas = [
45065
+ AutomationWaitStepSchema.strict(),
45066
+ AutomationCapStepBaseSchema.extend(continueOnErrorShape).strict().refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
45067
+ message: "a cap step needs a target",
45068
+ path: ["target"]
45069
+ }).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
45070
+ message: "a domain target needs the vocabulary action it applies to (actionId)",
45071
+ path: ["actionId"]
45072
+ }),
45073
+ AutomationStopStepSchema.omit({ if: true }).strict(),
45074
+ AutomationSetStepSchema.omit({ if: true }).strict(),
45075
+ AutomationRunActionStepSchema.strict()
45076
+ ];
45077
+ /**
45078
+ * A plain step: a flow step with no condition of its own and no step inside
45079
+ * it. The second (last) level of nesting holds these only.
45080
+ */
45081
+ var AutomationBranchStepSchema = discriminatedUnion("kind", plainStepSchemas, { error: nestTooDeep });
45082
+ /** A step that can run beside others: it writes no variable and does not end the run. */
45083
+ 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");
45084
+ /**
45085
+ * Several steps at once (#500): all are started together and all are awaited.
45086
+ * A failure fails the run once the others finished, as in a sequence; a member
45087
+ * marked "continue if this fails" does not.
45088
+ */
45089
+ var AutomationParallelStepSchema = object({
45090
+ kind: literal("parallel"),
45091
+ steps: array(AutomationParallelMemberSchema).min(2, "a parallel needs at least two steps").max(5, `a parallel takes at most 5 steps`)
45092
+ }).strict();
45093
+ var REPEAT_NEEDS_MAX = "a repeat on a condition needs a maximum number of iterations";
45094
+ /** A loop on a condition: the bound is mandatory, so a run never loops without an end. */
45095
+ var repeatConditionShape = {
45096
+ when: AutomationWhenSchema,
45097
+ maxIterations: number$1({ error: REPEAT_NEEDS_MAX }).int().min(1, REPEAT_NEEDS_MAX).max(50, `a repeat on a condition runs at most 50 times`),
45098
+ /** A pause between two iterations, never after the last. */
45099
+ waitS: number$1().int().min(1).max(WAIT_MAX_SECONDS, WAIT_TOO_LONG).optional()
45100
+ };
45101
+ /** What decides how many times a `repeat` runs. */
45102
+ var AutomationRepeatLoopSchema = discriminatedUnion("by", [
45103
+ object({
45104
+ by: literal("count"),
45105
+ count: number$1().int().min(1).max(20, `a repeat runs at most 20 times`)
45106
+ }).strict(),
45107
+ object({
45108
+ by: literal("while"),
45109
+ ...repeatConditionShape
45110
+ }).strict(),
45111
+ object({
45112
+ by: literal("until"),
45113
+ ...repeatConditionShape
45114
+ }).strict(),
45115
+ object({
45116
+ by: literal("forEach"),
45117
+ target: object({
45118
+ kind: literal("devices"),
45119
+ ids: array(number$1().int()).min(1, "a repeat over devices needs at least one device").max(50, `a repeat over devices takes at most 50 devices`)
45120
+ }).strict()
45121
+ }).strict()
45122
+ ]);
45123
+ /**
45124
+ * The same steps several times (#500). Every form is bounded at save, so a
45125
+ * run cannot loop without an end. A failure or a `stop` in the steps ends the
45126
+ * loop and the run, as in a sequence.
45127
+ */
45128
+ function repeatSchemaOf(step) {
45129
+ return object({
45130
+ kind: literal("repeat"),
45131
+ loop: AutomationRepeatLoopSchema,
45132
+ steps: array(step).min(1, "a repeat needs at least one step").max(10, `a repeat takes at most 10 steps`)
45133
+ }).strict();
45134
+ }
45135
+ /**
45136
+ * One step, several ways (#500): the branches are read in order and the FIRST
45137
+ * whose condition is true runs; `else` runs when every branch is false. A
45138
+ * branch that cannot be read ends the choice: nothing runs, not the branches
45139
+ * after it and not the else (D49). The #472 `if` / `else` of a wait or cap
45140
+ * step is the one-branch case and stays as it is stored.
45141
+ */
45142
+ function chooseSchemaOf(step) {
45143
+ const steps = array(step).max(10);
45144
+ return object({
45145
+ kind: literal("choose"),
45146
+ branches: array(object({
45147
+ if: AutomationWhenSchema,
45148
+ steps: steps.min(1, "a branch needs at least one step")
45149
+ })).min(1, "a choose needs at least one branch").max(6, `a choose takes at most 6 branches`),
45150
+ else: steps.optional()
45151
+ });
45152
+ }
45153
+ var AutomationBodyStepSchema = discriminatedUnion("kind", [
45154
+ ...plainStepSchemas,
45155
+ AutomationWaitUntilStepSchema,
45156
+ AutomationParallelStepSchema,
45157
+ chooseSchemaOf(AutomationBranchStepSchema),
45158
+ repeatSchemaOf(AutomationBranchStepSchema)
45159
+ ]);
45160
+ var AutomationRepeatStepSchema = repeatSchemaOf(AutomationBodyStepSchema);
44879
45161
  var AutomationActionSchema = discriminatedUnion("kind", [
44880
45162
  GuardedWaitStepSchema,
44881
- GuardedCapStepSchema,
44882
- object({
44883
- kind: literal("action"),
44884
- /** An entry of the `actions` surface (`internal:<uuid>` or `<addonId>:<localId>`). */
44885
- actionId: string().min(1),
44886
- /** Values for the action's declared variables; the others take their default. */
44887
- variables: record(string(), union([
44888
- string(),
44889
- number$1(),
44890
- boolean()
44891
- ])).optional()
44892
- }),
45163
+ AutomationGuardedCapStepSchema,
45164
+ AutomationStopStepSchema,
45165
+ AutomationSetStepSchema,
45166
+ chooseSchemaOf(AutomationBodyStepSchema),
45167
+ AutomationWaitUntilStepSchema,
45168
+ AutomationParallelStepSchema,
45169
+ AutomationRepeatStepSchema,
45170
+ AutomationRunActionStepSchema,
44893
45171
  object({
44894
45172
  kind: literal("code"),
44895
45173
  /** Compiled into the automation's OWN block by esbuild — not a third
@@ -44952,11 +45230,6 @@ function convertLegacyRecipe(legacy) {
44952
45230
  ...rest
44953
45231
  };
44954
45232
  }
44955
- /**
44956
- * Where recipes are PARSED (the core-blocks cap, the MCP tool, the literal a
44957
- * saved block carries): the new shape as it is, or the old shape converted to
44958
- * it. The output type is always the new one.
44959
- */
44960
45233
  var AutomationRecipeSchema = union([CurrentAutomationRecipeSchema, LegacyAutomationRecipeSchema.transform(convertLegacyRecipe)]);
44961
45234
  var DETECTION_DESCRIPTIONS = {
44962
45235
  deviceId: "the camera that saw it",
@@ -44977,6 +45250,16 @@ var BECOMES_DESCRIPTIONS = {
44977
45250
  from: "the value before the change, empty when it is not known",
44978
45251
  to: "the value it changed to"
44979
45252
  };
45253
+ /**
45254
+ * A fire's payload is offered too, as `data.<path>` (`{{vars.data.channel}}`):
45255
+ * those names depend on the device, so they are not in this list.
45256
+ */
45257
+ var FIRED_DESCRIPTIONS = {
45258
+ deviceId: "the device that fired",
45259
+ eventType: "the event, as the device names it",
45260
+ sourceId: "the part of the device that fired (a button), empty when it names none",
45261
+ eventKind: "the kind of press (press, long-press …), empty when the device declares none"
45262
+ };
44980
45263
  function describe$1(descriptions) {
44981
45264
  return Object.entries(descriptions).map(([name, description]) => ({
44982
45265
  name,
@@ -44985,12 +45268,74 @@ function describe$1(descriptions) {
44985
45268
  }
44986
45269
  describe$1(DETECTION_DESCRIPTIONS);
44987
45270
  describe$1(STATIONARY_DESCRIPTIONS);
45271
+ describe$1(FIRED_DESCRIPTIONS).map((v) => v.name === "deviceId" ? {
45272
+ ...v,
45273
+ hintKey: "firedDeviceId"
45274
+ } : v);
44988
45275
  describe$1(BECOMES_DESCRIPTIONS).map((v) => v.name === "deviceId" ? {
44989
45276
  ...v,
44990
45277
  hintKey: "becomesDeviceId"
44991
45278
  } : v);
44992
45279
  new Set(Object.values(COCO_TO_MACRO.mapping));
44993
45280
  /**
45281
+ * Generic stateless event emitter. Installed on a `DeviceType.EventEmitter`
45282
+ * device. Carries the device's EXACT declared event vocabulary verbatim
45283
+ * (NO normalization). Two shapes:
45284
+ * - structured source (HA `event.*` entity) → `vocabulary` is the fixed
45285
+ * declared set (e.g. press_short, press_long, …).
45286
+ * - generic/legacy source (HA bus events, e.g. zha_event) → `vocabulary`
45287
+ * is [] (open) and `lastEvent.data` carries the complex payload.
45288
+ * `vocabulary` (D1044) names each event for a person and types it for a
45289
+ * rule; `eventTypes` is its list of native tokens, kept for older readers.
45290
+ * A fire names the part of the device it came from in `sourceId` when the
45291
+ * vocabulary declares sources (a remote's buttons).
45292
+ * `seq` is monotonic so two identical events still produce distinct slice writes.
45293
+ */
45294
+ var EventFireSchema = object({
45295
+ deviceId: number$1(),
45296
+ eventType: string(),
45297
+ sourceId: string().optional(),
45298
+ data: record(string(), unknown()).nullable(),
45299
+ timestamp: number$1().meta(readingMeta("none")),
45300
+ seq: number$1().meta(readingMeta("count"))
45301
+ });
45302
+ var EventEmitterStatusSchema = object({
45303
+ eventTypes: array(string()),
45304
+ /**
45305
+ * Required of a provider by the type. A status written before the field
45306
+ * existed still parses, as an empty vocabulary: read it through
45307
+ * `readEventVocabulary`, which then answers with the plain tokens.
45308
+ */
45309
+ vocabulary: array(EventVocabularyEntrySchema).default([]),
45310
+ lastEvent: EventFireSchema.nullable(),
45311
+ eventCountSinceStart: number$1().meta(readingMeta("count"))
45312
+ });
45313
+ var eventEmitterCapability = {
45314
+ name: "event-emitter",
45315
+ scope: "device",
45316
+ deviceNative: true,
45317
+ mode: "singleton",
45318
+ deviceTypes: [DeviceType.EventEmitter],
45319
+ methods: {},
45320
+ events: { onEvent: { data: EventFireSchema } },
45321
+ status: {
45322
+ schema: EventEmitterStatusSchema,
45323
+ kind: "push"
45324
+ },
45325
+ runtimeState: EventEmitterStatusSchema,
45326
+ /**
45327
+ * Runtime-state durability: **session** — `eventCountSinceStart` names its own scope.
45328
+ *
45329
+ * See `RuntimeStateDurability`. Enforced by
45330
+ * `scripts/check-runtime-state-durability.ts`.
45331
+ */
45332
+ durability: "session",
45333
+ /**
45334
+ * History (D850): none — `eventCountSinceStart` resets with the addon; events live in ledgers.
45335
+ */
45336
+ history: "none"
45337
+ };
45338
+ /**
44994
45339
  * Schedulers (D983) — an entity that performs actions over the day.
44995
45340
  *
44996
45341
  * A scheduler has profiles; a profile has weekdays and a timeline of POINTS.
@@ -45041,12 +45386,16 @@ var HoldOverrideSchema = discriminatedUnion("mode", [object({ mode: literal("res
45041
45386
  })]);
45042
45387
  /** A missed edge up to this late still runs. */
45043
45388
  var DEFAULT_MAX_LATE_MS = 10 * 6e4;
45389
+ var SchedulerStepSchema = ActionStepSchema.refine((step) => step.kind !== "wait" || step.seconds <= 300, {
45390
+ message: `a scheduler point waits at most five minutes (300 s); put a longer wait in an action`,
45391
+ path: ["seconds"]
45392
+ });
45044
45393
  var SchedulerPointSchema = object({
45045
45394
  id: string().min(1).max(64),
45046
45395
  at: SchedulerTimeSpecSchema,
45047
45396
  mode: SchedulerPointModeSchema,
45048
45397
  /** The actions of an `edge` or `hold`; a `release` has none. */
45049
- steps: array(ActionStepSchema).max(20).default([]),
45398
+ steps: array(SchedulerStepSchema).max(20).default([]),
45050
45399
  /** Checked when the point runs (an edge) or is applied (a hold). */
45051
45400
  conditions: SchedulerStateTreeSchema.optional(),
45052
45401
  /** Hold only; absent means `respect`. */
@@ -45244,6 +45593,7 @@ var AutomationConditionTraceNodeSchema = object({
45244
45593
  "triggered-by",
45245
45594
  "device-becomes",
45246
45595
  "device-event",
45596
+ "device-fired",
45247
45597
  "schedule",
45248
45598
  "interval",
45249
45599
  "manual",
@@ -45314,18 +45664,46 @@ var StepTraceBaseSchema = object({
45314
45664
  ]).optional(),
45315
45665
  /** Why the condition read what it read, in the evaluator's own words. */
45316
45666
  conditionReason: string().optional(),
45317
- /** `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. */
45667
+ /** `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). */
45318
45668
  outcome: _enum([
45319
45669
  "ok",
45320
45670
  "error",
45321
45671
  "not-run",
45322
45672
  "empty",
45323
- "skipped"
45673
+ "skipped",
45674
+ "failed-continued",
45675
+ "timed-out"
45324
45676
  ]),
45325
45677
  message: string().optional()
45326
45678
  });
45679
+ /** What a block step adds to its row: which list ran, what each branch read, how many rounds. */
45680
+ var blockTraceShape = {
45681
+ /** A `choose` step (#500): the list that ran, `branches.<n>` or `else`. Absent when none did. */
45682
+ branch: string().optional(),
45683
+ /** A `choose` step: what each branch read, in order, up to the one that decided. */
45684
+ branchChecks: array(object({
45685
+ condition: _enum([
45686
+ "true",
45687
+ "false",
45688
+ "unknown"
45689
+ ]),
45690
+ conditionReason: string().optional()
45691
+ })).optional(),
45692
+ /** A `repeat` step (#500): how many times its steps ran. */
45693
+ iterations: number$1().int().optional()
45694
+ };
45695
+ /** A step one level down: it may be a block step itself, whose own steps are plain rows (the nesting ends there). */
45696
+ var NestedStepTraceSchema = StepTraceBaseSchema.extend({
45697
+ ...blockTraceShape,
45698
+ steps: array(StepTraceBaseSchema).optional()
45699
+ });
45327
45700
  /** A step trace; the `else` steps that ran are one level of the same shape (the nesting is bounded at one). */
45328
- var AutomationStepTraceSchema = StepTraceBaseSchema.extend({ else: array(StepTraceBaseSchema).optional() });
45701
+ var AutomationStepTraceSchema = StepTraceBaseSchema.extend({
45702
+ else: array(StepTraceBaseSchema).optional(),
45703
+ ...blockTraceShape,
45704
+ /** A `choose` step: the steps of the list that ran. A `parallel`: its members. A `repeat`: the LAST iteration. */
45705
+ steps: array(NestedStepTraceSchema).optional()
45706
+ });
45329
45707
  var AutomationRunTraceSchema = object({
45330
45708
  runId: string().min(1),
45331
45709
  startedAt: number$1(),
@@ -45732,7 +46110,9 @@ var AddonHttpRouteSchema = object({
45732
46110
  ]).optional(),
45733
46111
  description: string().optional(),
45734
46112
  /** The hub limits this route per client address before the handler runs. */
45735
- rateLimit: _enum(["auth"]).optional()
46113
+ rateLimit: _enum(["auth"]).optional(),
46114
+ /** Served once per integration instance; the handler reads `instanceId`. */
46115
+ perInstance: boolean().optional()
45736
46116
  });
45737
46117
  /**
45738
46118
  * Cross-process route invocation envelope. The hub captures the
@@ -45749,6 +46129,8 @@ var InvokeRequestSchema = object({
45749
46129
  query: record(string(), string()),
45750
46130
  body: unknown(),
45751
46131
  headers: record(string(), string()),
46132
+ /** The instance the hub resolved for a `perInstance` route. */
46133
+ instanceId: string().optional(),
45752
46134
  user: object({
45753
46135
  id: string(),
45754
46136
  username: string(),
@@ -56441,53 +56823,6 @@ var enumSensorCapability = {
56441
56823
  * whether persisting is worth a SQLite commit. */
56442
56824
  volatileStateFields: ["lastFetchedAt", "timestamp"]
56443
56825
  };
56444
- /**
56445
- * Generic stateless event emitter. Installed on a `DeviceType.EventEmitter`
56446
- * device. Carries the device's EXACT declared event vocabulary verbatim
56447
- * (NO normalization). Two shapes:
56448
- * - structured source (HA `event.*` entity) → `eventTypes` is the fixed
56449
- * declared vocabulary (e.g. ['press_short','press_long',...]).
56450
- * - generic/legacy source (HA bus events, e.g. zha_event) → `eventTypes`
56451
- * is [] (open) and `lastEvent.data` carries the complex payload.
56452
- * `seq` is monotonic so two identical events still produce distinct slice writes.
56453
- */
56454
- var EventFireSchema = object({
56455
- deviceId: number$1(),
56456
- eventType: string(),
56457
- data: record(string(), unknown()).nullable(),
56458
- timestamp: number$1().meta(readingMeta("none")),
56459
- seq: number$1().meta(readingMeta("count"))
56460
- });
56461
- var EventEmitterStatusSchema = object({
56462
- eventTypes: array(string()),
56463
- lastEvent: EventFireSchema.nullable(),
56464
- eventCountSinceStart: number$1().meta(readingMeta("count"))
56465
- });
56466
- var eventEmitterCapability = {
56467
- name: "event-emitter",
56468
- scope: "device",
56469
- deviceNative: true,
56470
- mode: "singleton",
56471
- deviceTypes: [DeviceType.EventEmitter],
56472
- methods: {},
56473
- events: { onEvent: { data: EventFireSchema } },
56474
- status: {
56475
- schema: EventEmitterStatusSchema,
56476
- kind: "push"
56477
- },
56478
- runtimeState: EventEmitterStatusSchema,
56479
- /**
56480
- * Runtime-state durability: **session** — `eventCountSinceStart` names its own scope.
56481
- *
56482
- * See `RuntimeStateDurability`. Enforced by
56483
- * `scripts/check-runtime-state-durability.ts`.
56484
- */
56485
- durability: "session",
56486
- /**
56487
- * History (D850): none — `eventCountSinceStart` resets with the addon; events live in ledgers.
56488
- */
56489
- history: "none"
56490
- };
56491
56826
  var IdentitySchema = object({
56492
56827
  id: string(),
56493
56828
  name: string(),
@@ -59063,6 +59398,12 @@ var IntegrationLiteSchema = object({
59063
59398
  var AvailableIntegrationTypeSchema = object({
59064
59399
  addonId: string(),
59065
59400
  name: string(),
59401
+ /**
59402
+ * Product name a new integration is prefilled from (`<label> - Home`).
59403
+ * Absent: the client uses `name`. Set when the catalog title is not the
59404
+ * product (Bosch SHC, MQTT).
59405
+ */
59406
+ providerLabel: string().optional(),
59066
59407
  description: string(),
59067
59408
  iconUrl: string().nullable(),
59068
59409
  color: string(),
@@ -71951,7 +72292,18 @@ var OauthIntegrationDescriptorSchema = object({
71951
72292
  * The value is baked into the authorization code at `/authorize` and travels
71952
72293
  * on the tokens, so editing this field changes FUTURE links only.
71953
72294
  */
71954
- refreshTokenTtlSec: union([number$1().int().positive(), literal("never")]).optional()
72295
+ refreshTokenTtlSec: union([number$1().int().positive(), literal("never")]).optional(),
72296
+ /**
72297
+ * The integration instances an account can be linked to (planning#415),
72298
+ * beside the default one. `/api/oauth2/authorize?instance=<id>` is accepted
72299
+ * only for an id listed here; with no `instance=` the link is made to the
72300
+ * default instance, which is never listed and always accepted — it is the
72301
+ * address third parties already hold. Omit for a single-instance integration.
72302
+ */
72303
+ instances: array(object({
72304
+ id: string(),
72305
+ displayName: string()
72306
+ })).optional()
71955
72307
  });
71956
72308
  method(_void(), OauthIntegrationDescriptorSchema, { auth: "admin" });
71957
72309
  /**
@@ -78880,6 +79232,13 @@ var SsoBridgeClaimsSchema = object({
78880
79232
  /** OAuth authorization-code binding — set only on `oauth-code` tokens. */
78881
79233
  redirectUri: string().optional(),
78882
79234
  integrationId: string().optional(),
79235
+ /**
79236
+ * The integration INSTANCE an OAuth link was made for (planning#415). Set on
79237
+ * `oauth-code`, `oauth-access` and `oauth-refresh` tokens of a link made
79238
+ * with `instance=`; absent on a link to the default instance. A cloud relay
79239
+ * reads it off the access token to route; the hub answers from the session.
79240
+ */
79241
+ instanceId: string().optional(),
78883
79242
  /** JWT ID — unique per issued code; consumed-set enforces single-use. */
78884
79243
  jti: string().optional(),
78885
79244
  /** PKCE S256 challenge — set only on `oauth-code` tokens issued to a public
@@ -81258,6 +81617,8 @@ var OauthSessionSummarySchema = object({
81258
81617
  userId: string(),
81259
81618
  username: string(),
81260
81619
  integrationId: string(),
81620
+ /** The instance the link was made for; `null` = the default instance. */
81621
+ instanceId: string().nullable().optional(),
81261
81622
  scopes: array(TokenScopeSchema),
81262
81623
  createdAt: number$1(),
81263
81624
  lastUsedAt: number$1(),
@@ -81357,6 +81718,9 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(_void(), ob
81357
81718
  access: "view"
81358
81719
  }), method(object({
81359
81720
  integrationId: string(),
81721
+ /** The integration instance the link is for. Omit for the default
81722
+ * instance — never pass the addon id to mean it. */
81723
+ instanceId: string().optional(),
81360
81724
  userId: string(),
81361
81725
  username: string(),
81362
81726
  scopes: array(TokenScopeSchema),
@@ -81395,7 +81759,13 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(_void(), ob
81395
81759
  }), method(object({ token: string() }), object({
81396
81760
  userId: string(),
81397
81761
  username: string(),
81398
- scopes: array(TokenScopeSchema)
81762
+ scopes: array(TokenScopeSchema),
81763
+ /** The instance the link was made for, read from the SESSION.
81764
+ * Absent = the default instance. `oauthLinkServesInstance` is the
81765
+ * helper a per-instance route calls to compare it with the instance
81766
+ * of its path; no route declares `perInstance` yet (the Alexa
81767
+ * per-instance route, T3, is the first consumer). */
81768
+ instanceId: string().optional()
81399
81769
  }).nullable(), { access: "view" }), method(object({ userId: string() }), array(ExternalIdentitySchema), { auth: "admin" }), method(ExternalIdentityKeySchema, object({
81400
81770
  userId: string(),
81401
81771
  issuer: string()
@@ -98150,6 +98520,149 @@ function offered(received) {
98150
98520
  };
98151
98521
  }
98152
98522
  offered(HA_AS), withheld(HOMEKIT_REASON), withheld(ALEXA_REASON), withheld(GOOGLE_REASON), withheld(MATTER_REASON);
98523
+ var PowerSwitchRefusedError = class extends Error {
98524
+ reason;
98525
+ constructor(reason, message) {
98526
+ super(message);
98527
+ this.name = "PowerSwitchRefusedError";
98528
+ this.reason = reason;
98529
+ }
98530
+ };
98531
+ /** `true` / `false` from the owner slice, `null` when the hinted field is
98532
+ * absent or not of the hinted shape. */
98533
+ function powerOnFromSlice(hint, slice) {
98534
+ const value = slice?.[hint.field];
98535
+ switch (hint.kind) {
98536
+ case "field": return typeof value === "boolean" ? value : null;
98537
+ case "methods": return typeof value === "string" ? !hint.offValues.includes(value) : null;
98538
+ case "mode": return typeof value === "string" ? value !== hint.offValue : null;
98539
+ }
98540
+ }
98541
+ function ownerMethod(owner, name, capName) {
98542
+ const fn = Reflect.get(owner, name);
98543
+ if (typeof fn !== "function") throw new PowerSwitchRefusedError("owner-method-missing", `${capName} provider does not serve '${name}', which its power hint names`);
98544
+ return async (input) => fn.call(owner, input);
98545
+ }
98546
+ async function lastNonOffMode(host, capName, hint) {
98547
+ const isMode = (v) => typeof v === "string" && v.length > 0 && v !== hint.offValue;
98548
+ const fromHub = (await host.readHubSlice(capName).catch(() => null))?.[hint.lastField];
98549
+ if (isMode(fromHub)) return fromHub;
98550
+ const local = host.runtimeState.getCapState(capName)?.[hint.lastField];
98551
+ return isMode(local) ? local : null;
98552
+ }
98553
+ async function applyPower(host, capName, hint, owner, on) {
98554
+ const deviceId = host.deviceId;
98555
+ switch (hint.kind) {
98556
+ case "field":
98557
+ await ownerMethod(owner, hint.set, capName)({
98558
+ deviceId,
98559
+ on
98560
+ });
98561
+ return;
98562
+ case "methods":
98563
+ await ownerMethod(owner, on ? hint.on : hint.off, capName)({ deviceId });
98564
+ return;
98565
+ case "mode": {
98566
+ const set = ownerMethod(owner, hint.set, capName);
98567
+ if (!on) {
98568
+ await set({
98569
+ deviceId,
98570
+ mode: hint.offValue
98571
+ });
98572
+ return;
98573
+ }
98574
+ const mode = await lastNonOffMode(host, capName, hint);
98575
+ if (mode === null) throw new PowerSwitchRefusedError("no-last-mode", `device ${deviceId}: ${capName} has no last non-off mode to restore; pick a mode instead`);
98576
+ await set({
98577
+ deviceId,
98578
+ mode
98579
+ });
98580
+ return;
98581
+ }
98582
+ }
98583
+ }
98584
+ function hintedMethods(hint) {
98585
+ return hint.kind === "methods" ? [hint.on, hint.off] : [hint.set];
98586
+ }
98587
+ /** Whether `owner` serves every method its cap's power hint names. A media
98588
+ * player whose `turnOn` / `turnOff` are not served has no power, so no switch. */
98589
+ function powerServedBy(hint, owner) {
98590
+ if (hint === void 0) return false;
98591
+ return hintedMethods(hint).every((name) => typeof Reflect.get(owner, name) === "function");
98592
+ }
98593
+ /** Builds the `switch` provider and starts the slice projection. Exported
98594
+ * for the specs; providers call `registerPowerSwitch`. */
98595
+ function buildPowerSwitch(host, cap, owner) {
98596
+ const hint = cap.power;
98597
+ if (hint === void 0) throw new Error(`capability '${cap.name}' has no power hint: it has no switch to project`);
98598
+ const read = () => powerOnFromSlice(hint, host.runtimeState.getCapState(cap.name));
98599
+ const project = () => {
98600
+ const on = read();
98601
+ const current = host.runtimeState.getCapState(switchCapability.name);
98602
+ if (current !== void 0 && current["on"] === on) return;
98603
+ const next = {
98604
+ on,
98605
+ lastChangedAt: Date.now()
98606
+ };
98607
+ host.runtimeState.setCapState(switchCapability.name, next);
98608
+ };
98609
+ const stop = host.runtimeState.subscribeCap(cap.name, project);
98610
+ if (host.runtimeState.getCapState(cap.name) !== void 0) project();
98611
+ return {
98612
+ provider: {
98613
+ getStatus: async () => {
98614
+ const current = host.runtimeState.getCapState(switchCapability.name);
98615
+ const lastChangedAt = typeof current?.["lastChangedAt"] === "number" ? current["lastChangedAt"] : 0;
98616
+ return {
98617
+ on: read(),
98618
+ lastChangedAt
98619
+ };
98620
+ },
98621
+ setState: async ({ on }) => applyPower(host, cap.name, hint, owner, on)
98622
+ },
98623
+ dispose: stop
98624
+ };
98625
+ }
98626
+ /**
98627
+ * Registers `switch` for a device whose `cap` carries a `power` hint, built
98628
+ * from `owner` (the provider the device registered for `cap`). Call it right
98629
+ * after `registerNativeCap(cap, owner)`.
98630
+ */
98631
+ function registerPowerSwitch(device, cap, owner) {
98632
+ const deviceId = device.ctx.id;
98633
+ if (cap.power !== void 0 && !powerServedBy(cap.power, owner)) {
98634
+ device.ctx.logger.debug("power switch: owner serves no power control, no switch registered", {
98635
+ tags: { deviceId },
98636
+ meta: { capName: cap.name }
98637
+ });
98638
+ return () => {};
98639
+ }
98640
+ const host = {
98641
+ deviceId,
98642
+ runtimeState: device.runtimeState,
98643
+ registerNativeCap: (c, p) => device.ctx.registerNativeCap(c, p),
98644
+ readHubSlice: async (capName) => {
98645
+ try {
98646
+ return await device.ctx.api.deviceState.getCapSlice.query({
98647
+ deviceId,
98648
+ capName
98649
+ });
98650
+ } catch (err) {
98651
+ device.ctx.logger.warn("power switch: hub slice read failed", {
98652
+ tags: { deviceId },
98653
+ meta: {
98654
+ capName,
98655
+ error: err instanceof Error ? err.message : String(err)
98656
+ }
98657
+ });
98658
+ return null;
98659
+ }
98660
+ }
98661
+ };
98662
+ const built = buildPowerSwitch(host, cap, owner);
98663
+ host.registerNativeCap(switchCapability, built.provider);
98664
+ return built.dispose;
98665
+ }
98153
98666
  Object.freeze({
98154
98667
  "accessories.getStatus": [{
98155
98668
  name: "deviceId",
@@ -102722,6 +103235,38 @@ function bestLocationMatch(externalName, existing, threshold = .8) {
102722
103235
  return best;
102723
103236
  }
102724
103237
  /**
103238
+ * Names chosen when an integration or a Gateway device is created.
103239
+ * A stored name is never rewritten from these helpers.
103240
+ */
103241
+ var HOME_SUFFIX = "Home";
103242
+ function collapse(value) {
103243
+ return value.trim().replace(/\s+/g, " ");
103244
+ }
103245
+ /** "KLF-200" → "KLF200". A hyphen between words ("Home Hub") stays. */
103246
+ function compactModelToken(value) {
103247
+ return value.replace(/([A-Za-z])-(\d)/g, "$1$2");
103248
+ }
103249
+ /** Prefill for a new integration: "<provider> - Home". The operator can edit it. */
103250
+ function defaultIntegrationName(providerLabel) {
103251
+ const label = collapse(providerLabel);
103252
+ if (label.length === 0) return HOME_SUFFIX;
103253
+ return `${label} - ${HOME_SUFFIX}`;
103254
+ }
103255
+ /**
103256
+ * A Gateway device: "<Brand> <Model>". An unknown model is the brand alone
103257
+ * (the caller passes the brand-level fallback it already has, e.g. "Velux KLF-200").
103258
+ */
103259
+ function gatewayDeviceName(brand, model) {
103260
+ const brandPart = compactModelToken(collapse(brand));
103261
+ const raw = collapse(model ?? "");
103262
+ if (raw.length === 0) return brandPart;
103263
+ const modelPart = compactModelToken(raw);
103264
+ const prefix = `${brandPart.toLowerCase()} `;
103265
+ if (modelPart.toLowerCase() === brandPart.toLowerCase()) return brandPart;
103266
+ if (modelPart.toLowerCase().startsWith(prefix)) return modelPart;
103267
+ return `${brandPart} ${modelPart}`;
103268
+ }
103269
+ /**
102725
103270
  * Closes the gap D49 leaves: an integration deleted while its provider was down never emits an
102726
103271
  * event the provider sees. An integration id absent from an ANSWERED list is only a suspect; its
102727
103272
  * devices go (through the provider's own removeDevices) when a SECOND answered read, at least
@@ -127692,9 +128237,10 @@ var HM_KEY_PRESS_DATAPOINTS = [
127692
128237
  /** Set form for O(1) fire-detection membership tests. */
127693
128238
  var HM_KEY_PRESS_SET = new Set(HM_KEY_PRESS_DATAPOINTS);
127694
128239
  /** Cold-start event-emitter slice; vocabulary supplied per-device. */
127695
- function coldEventEmitter(eventTypes) {
128240
+ function coldEventEmitter(vocabulary) {
127696
128241
  return {
127697
- eventTypes: [...eventTypes],
128242
+ eventTypes: eventTypesOfVocabulary(vocabulary),
128243
+ vocabulary: [...vocabulary],
127698
128244
  lastEvent: null,
127699
128245
  eventCountSinceStart: 0
127700
128246
  };
@@ -128538,7 +129084,7 @@ var HmActuatorDevice = class extends HmChildDevice {
128538
129084
  }
128539
129085
  registerClimateCap() {
128540
129086
  const channel = this.actuatorChannel;
128541
- this.ctx.registerNativeCap(climateControlCapability, {
129087
+ const provider = {
128542
129088
  getStatus: async () => this.runtimeState.getCapState("climate-control") ?? COLD_CLIMATE,
128543
129089
  setMode: async ({ mode }) => {
128544
129090
  await this.requireFacade().climateSetMode(this.address, channel, toHmClimateMode(mode));
@@ -128554,7 +129100,9 @@ var HmActuatorDevice = class extends HmChildDevice {
128554
129100
  setTargetHumidity: async () => this.unsupported("climate humidity control"),
128555
129101
  setSwingVertical: async () => this.unsupported("climate vertical swing"),
128556
129102
  setSwingHorizontal: async () => this.unsupported("climate horizontal swing")
128557
- });
129103
+ };
129104
+ this.ctx.registerNativeCap(climateControlCapability, provider);
129105
+ registerPowerSwitch(this, climateControlCapability, provider);
128558
129106
  this.runtimeState.setCapState("climate-control", COLD_CLIMATE);
128559
129107
  this.registeredCap = "climate-control";
128560
129108
  }
@@ -128772,6 +129320,64 @@ var HmSensorDevice = class extends HmChildDevice {
128772
129320
  }
128773
129321
  };
128774
129322
  //#endregion
129323
+ //#region src/devices/hm-key-vocabulary.ts
129324
+ var PRESS_MEANING = {
129325
+ PRESS_SHORT: {
129326
+ label: "Short press",
129327
+ kind: "press"
129328
+ },
129329
+ PRESS_LONG: {
129330
+ label: "Long press",
129331
+ kind: "long-press"
129332
+ },
129333
+ PRESS_LONG_START: {
129334
+ label: "Long press started",
129335
+ kind: "long-press-start"
129336
+ },
129337
+ PRESS_LONG_RELEASE: {
129338
+ label: "Long press released",
129339
+ kind: "release"
129340
+ },
129341
+ PRESS_CONT: {
129342
+ label: "Long press held",
129343
+ kind: "repeat"
129344
+ }
129345
+ };
129346
+ /** The channels of a device that are buttons, in channel order. */
129347
+ function hmKeyChannels(device) {
129348
+ return mapHmDeviceChannels(device).filter(({ mapping }) => mapping.capabilities.includes("event-emitter")).map(({ channel }) => channel);
129349
+ }
129350
+ /** The presses one key channel has; the standard set when it lists none. */
129351
+ function pressesOf(channel) {
129352
+ const listed = new Set((channel.dataPoints ?? []).map((dataPoint) => dataPoint.parameter).filter((parameter) => HM_KEY_PRESS_SET.has(parameter)));
129353
+ if (listed.size === 0) return HM_KEY_PRESS_DATAPOINTS;
129354
+ return HM_KEY_PRESS_DATAPOINTS.filter((parameter) => listed.has(parameter));
129355
+ }
129356
+ function entryOf(parameter, source) {
129357
+ const meaning = PRESS_MEANING[parameter];
129358
+ if (meaning === void 0) return {
129359
+ id: parameter,
129360
+ source,
129361
+ label: parameter
129362
+ };
129363
+ return {
129364
+ id: parameter,
129365
+ source,
129366
+ label: meaning.label,
129367
+ kind: meaning.kind
129368
+ };
129369
+ }
129370
+ function hmKeyVocabulary(device) {
129371
+ return hmKeyChannels(device).flatMap((channel, position) => {
129372
+ const index = channelIndexFromAddress(channel.address) ?? String(channel.index);
129373
+ const source = {
129374
+ id: index,
129375
+ label: `Button ${position + 1} (channel ${index})`
129376
+ };
129377
+ return pressesOf(channel).map((parameter) => entryOf(parameter, source));
129378
+ });
129379
+ }
129380
+ //#endregion
128775
129381
  //#region src/devices/hm-event-emitter-device.ts
128776
129382
  /**
128777
129383
  * Event-emitter child config: the persisted native press vocabulary for the
@@ -128782,31 +129388,93 @@ var hmEventEmitterSchema = hmChildSchema.extend({ eventTypes: array(string()).op
128782
129388
  /**
128783
129389
  * ONE Homematic event-emitter accessory child collapsing all of a device's key
128784
129390
  * channels (HmIP-WRC* wall switches / HmIP-RC* remotes / KEY channels). The
128785
- * event vocabulary is the verbatim union of the channels' native `PRESS_*`
128786
- * datapoints (persisted in config at adoption). Presses fire
128787
- * `EventCategory.EventEmitted` with the button index (`:N` channel suffix) in
128788
- * `data.channel` — lifted VERBATIM from the legacy flat device.
129391
+ * event vocabulary is one source per key channel with that channel's native
129392
+ * `PRESS_*` datapoints, verbatim (`hm-key-vocabulary.ts`). Presses fire
129393
+ * `EventCategory.EventEmitted` with the button index (`:N` channel suffix)
129394
+ * as `sourceId`.
128789
129395
  */
128790
129396
  var HmEventEmitterDevice = class extends HmChildDevice {
128791
- eventTypes;
129397
+ /** The tokens persisted at adoption: the vocabulary of last resort. */
129398
+ persistedEventTypes;
129399
+ /** The vocabulary read from the CCU's channel list, once it answered. */
129400
+ #declared = null;
129401
+ /** Fires already reported as outside the vocabulary, as `source:token`. */
129402
+ #undeclaredLogged = /* @__PURE__ */ new Set();
128792
129403
  #eventSeq = 0;
128793
129404
  #eventCount = 0;
129405
+ /** Unsubscribe for the integration's state-change fan-out. */
129406
+ #snapshotUnsub = null;
128794
129407
  constructor(ctx) {
128795
129408
  super(ctx, hmEventEmitterSchema);
128796
129409
  const persisted = this.config.values.eventTypes;
128797
- this.eventTypes = persisted && persisted.length > 0 ? persisted : HM_KEY_PRESS_DATAPOINTS;
129410
+ this.persistedEventTypes = persisted && persisted.length > 0 ? persisted : HM_KEY_PRESS_DATAPOINTS;
128798
129411
  this.registerEventEmitterCap();
128799
129412
  this.attachValueChangedListener((event) => this.decodeKeyPress(event));
129413
+ if (this.integrationId !== void 0) this.#snapshotUnsub = homematicFacades.onSnapshot(this.integrationId, () => this.refreshDeclaredVocabulary());
129414
+ }
129415
+ /**
129416
+ * Rewrite the slice with the buttons once the CCU's channel list carries
129417
+ * them. A no-op while it does not, and after the buttons were declared.
129418
+ */
129419
+ refreshDeclaredVocabulary() {
129420
+ if (this.#declared !== null) return;
129421
+ const vocabulary = this.vocabulary();
129422
+ if (this.#declared === null) return;
129423
+ const current = this.runtimeState.getCapState("event-emitter");
129424
+ this.runtimeState.setCapState("event-emitter", {
129425
+ eventTypes: eventTypesOfVocabulary(vocabulary),
129426
+ vocabulary: [...vocabulary],
129427
+ lastEvent: current?.lastEvent ?? null,
129428
+ eventCountSinceStart: current?.eventCountSinceStart ?? 0
129429
+ });
129430
+ }
129431
+ async removeDevice() {
129432
+ this.#snapshotUnsub?.();
129433
+ this.#snapshotUnsub = null;
129434
+ await super.removeDevice();
128800
129435
  }
128801
129436
  registerEventEmitterCap() {
128802
- this.ctx.registerNativeCap(eventEmitterCapability, { getStatus: async () => this.runtimeState.getCapState("event-emitter") ?? coldEventEmitter(this.eventTypes) });
128803
- this.runtimeState.setCapState("event-emitter", coldEventEmitter(this.eventTypes));
129437
+ this.ctx.registerNativeCap(eventEmitterCapability, { getStatus: async () => this.runtimeState.getCapState("event-emitter") ?? coldEventEmitter(this.vocabulary()) });
129438
+ this.runtimeState.setCapState("event-emitter", coldEventEmitter(this.vocabulary()));
129439
+ }
129440
+ /**
129441
+ * The buttons and their presses, read LIVE from the CCU's channel list.
129442
+ *
129443
+ * Not from the child's config: that is written once, at adoption, so a
129444
+ * remote adopted before the vocabulary existed would never get its
129445
+ * buttons. While the CCU has not answered, the persisted tokens stand in,
129446
+ * with no button; the next write after it answers carries the buttons.
129447
+ */
129448
+ vocabulary() {
129449
+ if (this.#declared !== null) return this.#declared;
129450
+ const device = this.resolveHmDevice();
129451
+ const live = device === null ? [] : hmKeyVocabulary(device);
129452
+ if (live.length === 0) return plainEventVocabulary(this.persistedEventTypes);
129453
+ this.#declared = live;
129454
+ return live;
129455
+ }
129456
+ /** A press the vocabulary does not declare is delivered, and said once. */
129457
+ noteUndeclared(vocabulary, eventType, sourceId) {
129458
+ if (this.#declared === null) return;
129459
+ if (findVocabularyEntry(vocabulary, eventType, sourceId ?? void 0) !== void 0) return;
129460
+ const key = `${sourceId ?? ""}:${eventType}`;
129461
+ if (this.#undeclaredLogged.has(key)) return;
129462
+ this.#undeclaredLogged.add(key);
129463
+ this.ctx.logger.warn("Homematic press is not in the declared event vocabulary", {
129464
+ tags: { deviceId: this.ctx.id },
129465
+ meta: {
129466
+ address: this.address,
129467
+ eventType,
129468
+ sourceId
129469
+ }
129470
+ });
128804
129471
  }
128805
129472
  /**
128806
129473
  * Translate a key-channel `PRESS_*` datapoint into an `EventFire`: emit
128807
129474
  * `EventCategory.EventEmitted` on the bus and write the `event-emitter`
128808
129475
  * slice. The `eventType` is the native datapoint name VERBATIM; the button
128809
- * index (`:N` suffix of the channel address) travels in `data.channel`.
129476
+ * index (`:N` suffix of the channel address) is the fire's `sourceId`, and
129477
+ * stays in `data.channel` for readers older than the vocabulary.
128810
129478
  * Non-key datapoints and value resets are ignored.
128811
129479
  */
128812
129480
  decodeKeyPress(event) {
@@ -128818,6 +129486,7 @@ var HmEventEmitterDevice = class extends HmChildDevice {
128818
129486
  const fire = {
128819
129487
  deviceId: this.id,
128820
129488
  eventType: parameter,
129489
+ ...channelIndex !== null ? { sourceId: channelIndex } : {},
128821
129490
  data: channelIndex !== null ? { channel: channelIndex } : {},
128822
129491
  timestamp: now,
128823
129492
  seq: ++this.#eventSeq
@@ -128828,8 +129497,11 @@ var HmEventEmitterDevice = class extends HmChildDevice {
128828
129497
  deviceId: this.id,
128829
129498
  addonId: this.ctx.deviceMeta.addonId
128830
129499
  }, fire));
129500
+ const vocabulary = this.vocabulary();
129501
+ this.noteUndeclared(vocabulary, parameter, channelIndex);
128831
129502
  const slice = {
128832
- eventTypes: [...this.eventTypes],
129503
+ eventTypes: eventTypesOfVocabulary(vocabulary),
129504
+ vocabulary: [...vocabulary],
128833
129505
  lastEvent: fire,
128834
129506
  eventCountSinceStart: ++this.#eventCount
128835
129507
  };
@@ -129537,7 +130209,7 @@ function buildCcuGatewayCandidate(input) {
129537
130209
  const adoptedId = input.adopted.get(nativeId) ?? null;
129538
130210
  return {
129539
130211
  childNativeId: nativeId,
129540
- name: input.integrationName,
130212
+ name: gatewayDeviceName("Homematic", "CCU3"),
129541
130213
  type: DeviceType.Gateway,
129542
130214
  status: input.online ? "online" : "offline",
129543
130215
  metadata: {
@@ -129806,7 +130478,7 @@ function buildHmAdoptionProvider(deps) {
129806
130478
  const { deviceId } = await adoptGateway({
129807
130479
  integrationId,
129808
130480
  nativeId,
129809
- name: perCandidate?.[nativeId]?.name ?? registry.getName(integrationId) ?? "Homematic CCU"
130481
+ name: perCandidate?.[nativeId]?.name ?? gatewayDeviceName("Homematic", "CCU3")
129810
130482
  });
129811
130483
  adopted.push({
129812
130484
  childNativeId: nativeId,
@@ -130009,7 +130681,7 @@ function homematicDiscoveryCandidates(proposals) {
130009
130681
  return proposals.map((found) => ({
130010
130682
  stableId: `homematic:${found.id}`,
130011
130683
  type: DeviceType.Gateway,
130012
- suggestedName: found.name,
130684
+ suggestedName: defaultIntegrationName("Homematic"),
130013
130685
  prefilledConfig: { host: found.host },
130014
130686
  setupIntegration: true
130015
130687
  }));