@camstack/addon-export-alexa 1.2.194 → 1.2.196
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/CHANGELOG.md +12 -0
- package/dist/export-alexa.addon.js +1719 -562
- package/dist/export-alexa.addon.mjs +1719 -562
- package/lambda-template/README.md +1 -0
- package/lambda-template/authorize-page.js +5 -0
- package/lambda-template/index.js +31 -8
- package/package.json +2 -2
|
@@ -34,7 +34,7 @@ let node_path = require("node:path");
|
|
|
34
34
|
node_path = __toESM(node_path, 1);
|
|
35
35
|
require("node:child_process");
|
|
36
36
|
require("node:zlib");
|
|
37
|
-
//#region ../types/dist/event-category-
|
|
37
|
+
//#region ../types/dist/event-category-Dv-Gcv1f.mjs
|
|
38
38
|
var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
39
39
|
EventCategory["SystemBoot"] = "system.boot";
|
|
40
40
|
EventCategory["SystemAddonsReady"] = "system.addons-ready";
|
|
@@ -475,6 +475,15 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
|
475
475
|
*/
|
|
476
476
|
EventCategory["DeviceStateChanged"] = "device.state-changed";
|
|
477
477
|
/**
|
|
478
|
+
* A device COMMAND (a vocabulary action, D920/D983) settled in the hub's
|
|
479
|
+
* transition audit (D1022): confirmed, already in place, unconfirmed or
|
|
480
|
+
* failed. Never a device's own change. Payload: `DeviceCommandSettledEvent`
|
|
481
|
+
* (`{deviceId, action, outcome, actor, at}`, no arguments). It feeds
|
|
482
|
+
* the Notification Center `device-command` kind. Telemetry (D8): losing one
|
|
483
|
+
* costs a notification, never state; the audit row is the record.
|
|
484
|
+
*/
|
|
485
|
+
EventCategory["DeviceCommandSettled"] = "device.command-settled";
|
|
486
|
+
/**
|
|
478
487
|
* The NATIVE shadow of a cap a composition has claimed fields of moved
|
|
479
488
|
* (D663). Payload: `{ deviceId, capName, native }` — what the provider
|
|
480
489
|
* wrote, BEFORE the owned fields are overlaid. Owner-only (D224): it is for
|
|
@@ -6079,7 +6088,7 @@ var ZodIssueCode = {
|
|
|
6079
6088
|
var ZodFirstPartyTypeKind;
|
|
6080
6089
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
6081
6090
|
//#endregion
|
|
6082
|
-
//#region ../types/dist/sleep-
|
|
6091
|
+
//#region ../types/dist/sleep-DyIxjZZt.mjs
|
|
6083
6092
|
/**
|
|
6084
6093
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
6085
6094
|
* window to float samples (D455).
|
|
@@ -6762,6 +6771,13 @@ async function runAddonMigrations(host, migrations, logger, options = {}) {
|
|
|
6762
6771
|
else skipped.push(id);
|
|
6763
6772
|
};
|
|
6764
6773
|
const selected = options.only === void 0 ? null : new Set(options.only);
|
|
6774
|
+
const deferred = /* @__PURE__ */ new Set();
|
|
6775
|
+
const deferredBy = (reason) => {
|
|
6776
|
+
if (selected === null || reason === null) return null;
|
|
6777
|
+
const dep = /^dependency-(?:pending|blocked):(.+)$/.exec(reason)?.[1];
|
|
6778
|
+
if (dep === void 0 || !byId.has(dep)) return null;
|
|
6779
|
+
return !selected.has(dep) || deferred.has(dep) ? dep : null;
|
|
6780
|
+
};
|
|
6765
6781
|
for (const step of declaration.steps) {
|
|
6766
6782
|
if (selected !== null && !selected.has(step.id)) continue;
|
|
6767
6783
|
const bound = byId.get(step.id);
|
|
@@ -6773,6 +6789,19 @@ async function runAddonMigrations(host, migrations, logger, options = {}) {
|
|
|
6773
6789
|
try {
|
|
6774
6790
|
const gate = await host.startMigration({ id: step.id });
|
|
6775
6791
|
if (!gate.proceed) {
|
|
6792
|
+
const waitsFor = deferredBy(gate.reason);
|
|
6793
|
+
if (waitsFor !== null) {
|
|
6794
|
+
log.info("migration deferred: its predecessor runs in another phase of this owner", {
|
|
6795
|
+
tags,
|
|
6796
|
+
meta: {
|
|
6797
|
+
waitsFor,
|
|
6798
|
+
reason: gate.reason
|
|
6799
|
+
}
|
|
6800
|
+
});
|
|
6801
|
+
deferred.add(step.id);
|
|
6802
|
+
skipped.push(step.id);
|
|
6803
|
+
continue;
|
|
6804
|
+
}
|
|
6776
6805
|
log.warn("migration not run", {
|
|
6777
6806
|
tags,
|
|
6778
6807
|
meta: {
|
|
@@ -7817,7 +7846,7 @@ async function writeMembers(ctx, children, incoming, stored, pathOf) {
|
|
|
7817
7846
|
for (const [member, node] of children) applyMember(out, member, await writeNode(ctx, node, incoming[member], stored[member], pathOf(member)), stored);
|
|
7818
7847
|
return out;
|
|
7819
7848
|
}
|
|
7820
|
-
function rowId$
|
|
7849
|
+
function rowId$4(row, idKey) {
|
|
7821
7850
|
const raw = row[idKey];
|
|
7822
7851
|
if (typeof raw === "string" && raw.length > 0) return raw;
|
|
7823
7852
|
if (typeof raw === "number" && Number.isFinite(raw)) return String(raw);
|
|
@@ -7834,7 +7863,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
7834
7863
|
}
|
|
7835
7864
|
const storedById = /* @__PURE__ */ new Map();
|
|
7836
7865
|
for (const row of storedRows) {
|
|
7837
|
-
const id = rowId$
|
|
7866
|
+
const id = rowId$4(row, node.idKey);
|
|
7838
7867
|
if (id !== null) storedById.set(id, row);
|
|
7839
7868
|
}
|
|
7840
7869
|
const kept = /* @__PURE__ */ new Set();
|
|
@@ -7844,13 +7873,13 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
7844
7873
|
rows.push(row);
|
|
7845
7874
|
continue;
|
|
7846
7875
|
}
|
|
7847
|
-
const id = rowId$
|
|
7876
|
+
const id = rowId$4(row, node.idKey) ?? ctx.mintId();
|
|
7848
7877
|
kept.add(id);
|
|
7849
7878
|
const withId = {
|
|
7850
7879
|
...row,
|
|
7851
7880
|
[node.idKey]: row[node.idKey] ?? id
|
|
7852
7881
|
};
|
|
7853
|
-
if (rowId$
|
|
7882
|
+
if (rowId$4(withId, node.idKey) === null) withId[node.idKey] = id;
|
|
7854
7883
|
const storedRow = storedById.get(id) ?? {};
|
|
7855
7884
|
rows.push(await writeMembers(ctx, node.item, withId, storedRow, (member) => arrayItemFieldPath(fieldPath, id, member)));
|
|
7856
7885
|
}
|
|
@@ -10222,6 +10251,13 @@ var DeviceTransitionSchema = object({
|
|
|
10222
10251
|
actor: TransitionActorSchema,
|
|
10223
10252
|
command: TransitionCommandSchema.optional()
|
|
10224
10253
|
});
|
|
10254
|
+
object({
|
|
10255
|
+
deviceId: number$1().int(),
|
|
10256
|
+
action: string(),
|
|
10257
|
+
outcome: TransitionOutcomeSchema,
|
|
10258
|
+
actor: TransitionActorSchema,
|
|
10259
|
+
at: number$1()
|
|
10260
|
+
});
|
|
10225
10261
|
var READING_QUANTITIES = [
|
|
10226
10262
|
"temperature",
|
|
10227
10263
|
"pressure",
|
|
@@ -12245,7 +12281,10 @@ var ACTUATOR_CAP_VOCABULARY = {
|
|
|
12245
12281
|
"ir-transmitter": {
|
|
12246
12282
|
scope: "device",
|
|
12247
12283
|
noun: t("IR / RF transmitter", "Trasmettitore IR / RF"),
|
|
12248
|
-
notOperatorFacing: {
|
|
12284
|
+
notOperatorFacing: {
|
|
12285
|
+
send: "a raw pulse train is not something an operator composes in an automation; the remote that owns the command table sends it",
|
|
12286
|
+
learn: "an interactive capture the operator starts from the source dialog and answers by pressing a physical remote; no automation can supply the signal"
|
|
12287
|
+
}
|
|
12249
12288
|
},
|
|
12250
12289
|
control: {
|
|
12251
12290
|
scope: "device",
|
|
@@ -15166,6 +15205,32 @@ var CAP_VOCABULARY_BY_NAME = {
|
|
|
15166
15205
|
...SYSTEM_CAP_VOCABULARY
|
|
15167
15206
|
};
|
|
15168
15207
|
/**
|
|
15208
|
+
* Vocabulary actions by id (D983). An action step names a vocabulary action
|
|
15209
|
+
* (`cover.open`), never a raw cap method; this is the one lookup that turns the
|
|
15210
|
+
* id into its cap, method and effect — and a persisted legacy `cap` + `method`
|
|
15211
|
+
* pair back into the action id when exactly one action matches.
|
|
15212
|
+
*/
|
|
15213
|
+
function buildIndex() {
|
|
15214
|
+
const byId = /* @__PURE__ */ new Map();
|
|
15215
|
+
for (const [cap, entry] of Object.entries(CAP_VOCABULARY_BY_NAME)) {
|
|
15216
|
+
if (entry.scope !== "device") continue;
|
|
15217
|
+
for (const action of entry.actions ?? []) byId.set(action.id, {
|
|
15218
|
+
cap,
|
|
15219
|
+
action
|
|
15220
|
+
});
|
|
15221
|
+
}
|
|
15222
|
+
return byId;
|
|
15223
|
+
}
|
|
15224
|
+
var index;
|
|
15225
|
+
function actionIndex() {
|
|
15226
|
+
index ??= buildIndex();
|
|
15227
|
+
return index;
|
|
15228
|
+
}
|
|
15229
|
+
/** The vocabulary action with this id, or `undefined`. */
|
|
15230
|
+
function findVocabAction(actionId) {
|
|
15231
|
+
return actionIndex().get(actionId);
|
|
15232
|
+
}
|
|
15233
|
+
/**
|
|
15169
15234
|
* `addon-pages-source` — collection cap exposing per-provider raw page
|
|
15170
15235
|
* declarations. Every addon that contributes a UI page registers a
|
|
15171
15236
|
* provider here. The hub-side singleton aggregator (`addon-pages` cap,
|
|
@@ -16189,6 +16254,10 @@ Object.freeze({
|
|
|
16189
16254
|
"path": "lastEvent.eventType",
|
|
16190
16255
|
"valueType": "string"
|
|
16191
16256
|
},
|
|
16257
|
+
{
|
|
16258
|
+
"path": "lastEvent.sourceId",
|
|
16259
|
+
"valueType": "string"
|
|
16260
|
+
},
|
|
16192
16261
|
{
|
|
16193
16262
|
"path": "lastEvent.timestamp",
|
|
16194
16263
|
"valueType": "number"
|
|
@@ -19209,6 +19278,7 @@ function buildAddonRouteProvider(id, routes) {
|
|
|
19209
19278
|
query: input.query,
|
|
19210
19279
|
body: input.body,
|
|
19211
19280
|
headers: input.headers,
|
|
19281
|
+
...match.route.perInstance === true && input.instanceId !== void 0 ? { instanceId: input.instanceId } : {},
|
|
19212
19282
|
...input.user ? { user: input.user } : {},
|
|
19213
19283
|
...input.scopedToken !== void 0 ? { scopedToken: input.scopedToken } : {}
|
|
19214
19284
|
};
|
|
@@ -19276,6 +19346,18 @@ function buildCapturingReply(envelope) {
|
|
|
19276
19346
|
};
|
|
19277
19347
|
return wrapper;
|
|
19278
19348
|
}
|
|
19349
|
+
/** The instance a link was made for, with the default one spelled as the addon id. */
|
|
19350
|
+
function oauthLinkInstanceId(link, addonId) {
|
|
19351
|
+
return link.instanceId ?? addonId;
|
|
19352
|
+
}
|
|
19353
|
+
/**
|
|
19354
|
+
* True when a verified link may be used on a request addressed to
|
|
19355
|
+
* `requestInstanceId` (`AddonHttpRequest.instanceId`, absent on a route that
|
|
19356
|
+
* is not per-instance, which is the default instance).
|
|
19357
|
+
*/
|
|
19358
|
+
function oauthLinkServesInstance(link, requestInstanceId, addonId) {
|
|
19359
|
+
return oauthLinkInstanceId(link, addonId) === (requestInstanceId ?? addonId);
|
|
19360
|
+
}
|
|
19279
19361
|
/**
|
|
19280
19362
|
* notification-output — canonical, capability-gated notification delivery.
|
|
19281
19363
|
*
|
|
@@ -44064,6 +44146,41 @@ function macroOnly(macro) {
|
|
|
44064
44146
|
};
|
|
44065
44147
|
}
|
|
44066
44148
|
}
|
|
44149
|
+
var EventVocabularyKindSchema = _enum([
|
|
44150
|
+
"press",
|
|
44151
|
+
"long-press",
|
|
44152
|
+
"long-press-start",
|
|
44153
|
+
"release",
|
|
44154
|
+
"repeat",
|
|
44155
|
+
"double-press",
|
|
44156
|
+
"other"
|
|
44157
|
+
]);
|
|
44158
|
+
/** The part of the device an event comes from: a button, a channel. */
|
|
44159
|
+
var EventVocabularySourceSchema = object({
|
|
44160
|
+
id: string().min(1),
|
|
44161
|
+
label: string().min(1)
|
|
44162
|
+
});
|
|
44163
|
+
/** One scalar field of an event's `data`, by dotted path. */
|
|
44164
|
+
var EventVocabularyFieldSchema = object({
|
|
44165
|
+
path: string().min(1),
|
|
44166
|
+
kind: _enum([
|
|
44167
|
+
"string",
|
|
44168
|
+
"number",
|
|
44169
|
+
"boolean",
|
|
44170
|
+
"enum"
|
|
44171
|
+
]),
|
|
44172
|
+
enumValues: array(string()).optional(),
|
|
44173
|
+
label: string().min(1).optional()
|
|
44174
|
+
});
|
|
44175
|
+
var EventVocabularyEntrySchema = object({
|
|
44176
|
+
/** The native token, verbatim. */
|
|
44177
|
+
id: string().min(1),
|
|
44178
|
+
source: EventVocabularySourceSchema.optional(),
|
|
44179
|
+
label: string().min(1),
|
|
44180
|
+
description: string().optional(),
|
|
44181
|
+
kind: EventVocabularyKindSchema.optional(),
|
|
44182
|
+
payload: array(EventVocabularyFieldSchema).optional()
|
|
44183
|
+
});
|
|
44067
44184
|
Math.PI / 180;
|
|
44068
44185
|
/**
|
|
44069
44186
|
* WHEN something happens, as data (D983) — the one time vocabulary of the
|
|
@@ -44271,6 +44388,33 @@ var ScheduleLeafSchema = object({
|
|
|
44271
44388
|
/** @deprecated legacy cron — new schedules use `at`. */
|
|
44272
44389
|
cron: string().min(1).max(120).optional()
|
|
44273
44390
|
}).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" });
|
|
44391
|
+
/**
|
|
44392
|
+
* One payload predicate of a `device-fired` row: the value at `path` inside
|
|
44393
|
+
* the fire's `data` (dotted) equals `equals`. Compared strictly, no coercion.
|
|
44394
|
+
*/
|
|
44395
|
+
var DeviceFiredMatchSchema = object({
|
|
44396
|
+
path: string().min(1).max(120),
|
|
44397
|
+
equals: union([
|
|
44398
|
+
string(),
|
|
44399
|
+
number$1(),
|
|
44400
|
+
boolean()
|
|
44401
|
+
])
|
|
44402
|
+
});
|
|
44403
|
+
/**
|
|
44404
|
+
* "fires": one device of the `event-emitter` capability reported an event
|
|
44405
|
+
* (D1045). Every list is an OR, the lists together an AND; an absent list does
|
|
44406
|
+
* not narrow. `eventIds` are the device's own tokens, `sourceIds` the parts of
|
|
44407
|
+
* the device (a button), `kinds` the shared press kinds of its vocabulary.
|
|
44408
|
+
*/
|
|
44409
|
+
var DeviceFiredLeafSchema = object({
|
|
44410
|
+
kind: literal("device-fired"),
|
|
44411
|
+
...eventLeafId,
|
|
44412
|
+
deviceId: number$1().int().nonnegative(),
|
|
44413
|
+
eventIds: array(string().min(1)).min(1).max(64).optional(),
|
|
44414
|
+
sourceIds: array(string().min(1)).min(1).max(64).optional(),
|
|
44415
|
+
kinds: array(EventVocabularyKindSchema).min(1).optional(),
|
|
44416
|
+
match: array(DeviceFiredMatchSchema).min(1).max(8).optional()
|
|
44417
|
+
});
|
|
44274
44418
|
var ManualLeafSchema = object({
|
|
44275
44419
|
kind: literal("manual"),
|
|
44276
44420
|
...eventLeafId
|
|
@@ -44412,6 +44556,7 @@ var AutomationWhenSchema = lazy(() => discriminatedUnion("kind", [
|
|
|
44412
44556
|
}),
|
|
44413
44557
|
DeviceBecomesLeafSchema,
|
|
44414
44558
|
DeviceEventLeafSchema,
|
|
44559
|
+
DeviceFiredLeafSchema,
|
|
44415
44560
|
ScheduleLeafSchema,
|
|
44416
44561
|
ManualLeafSchema,
|
|
44417
44562
|
IntervalLeafSchema,
|
|
@@ -44426,6 +44571,7 @@ var AutomationWhenSchema = lazy(() => discriminatedUnion("kind", [
|
|
|
44426
44571
|
var EVENT_KINDS = new Set([
|
|
44427
44572
|
"device-becomes",
|
|
44428
44573
|
"device-event",
|
|
44574
|
+
"device-fired",
|
|
44429
44575
|
"schedule",
|
|
44430
44576
|
"manual",
|
|
44431
44577
|
"interval",
|
|
@@ -44506,6 +44652,7 @@ function hasEmptyContainer(node) {
|
|
|
44506
44652
|
var LEAF_WORDS = {
|
|
44507
44653
|
"device-becomes": "a device value that becomes",
|
|
44508
44654
|
"device-event": "a device event",
|
|
44655
|
+
"device-fired": "a device firing an event",
|
|
44509
44656
|
schedule: "a schedule",
|
|
44510
44657
|
manual: "a manual run",
|
|
44511
44658
|
interval: "an interval",
|
|
@@ -44755,59 +44902,47 @@ function convertLegacyWhen(half) {
|
|
|
44755
44902
|
* (instants) and state leaves (durations). It replaces the flat trigger list
|
|
44756
44903
|
* plus the separate condition tree; the firing rule is in that file and in
|
|
44757
44904
|
* ADR "one tree".
|
|
44758
|
-
* - **Actions** — the `wait` and `
|
|
44905
|
+
* - **Actions** — the `wait` and device `command` steps, plus the `{kind:'code'}`
|
|
44759
44906
|
* fragment of §3.2.2. See {@link AutomationActionSchema}.
|
|
44760
44907
|
*
|
|
44761
44908
|
* A recipe stored in the old shape (`triggers` + `conditions`) still LOADS:
|
|
44762
44909
|
* {@link AutomationRecipeSchema} (the parse-anywhere schema) converts it on parse. Nothing writes it.
|
|
44763
44910
|
*/
|
|
44764
44911
|
/**
|
|
44765
|
-
* One action step: `wait`, or a `
|
|
44912
|
+
* One action step: `wait`, or a device `command`.
|
|
44766
44913
|
*
|
|
44767
|
-
* A
|
|
44768
|
-
* `{ $var }` resolved from the run's
|
|
44769
|
-
*
|
|
44770
|
-
*
|
|
44771
|
-
*
|
|
44772
|
-
*
|
|
44914
|
+
* A command step names a VOCABULARY action (`cover.open`) and who it acts on
|
|
44915
|
+
* (D983: `devices`, a `domain`, or a `{ $var }` resolved from the run's
|
|
44916
|
+
* variables). It never names a cap method: the step runner turns the action
|
|
44917
|
+
* id into its cap + method through the vocabulary index when the step runs
|
|
44918
|
+
* (`vocabCall`), the one place that mapping happens. The step runner
|
|
44919
|
+
* (`runSteps`) owns the device-scope check, the stop-at-first-failure and the
|
|
44920
|
+
* variable substitution, once, for every caller — automations, Actions, and
|
|
44921
|
+
* the notification centre, which runs only Actions (planning#473).
|
|
44773
44922
|
*/
|
|
44923
|
+
/** The longest one `wait` step lasts. It is cut by a restart of the run and does not survive a hub restart. */
|
|
44924
|
+
var WAIT_MAX_SECONDS = 3600;
|
|
44925
|
+
var WAIT_TOO_LONG = `a wait is at most one hour (${WAIT_MAX_SECONDS} s)`;
|
|
44774
44926
|
var AutomationWaitStepSchema = object({
|
|
44775
44927
|
kind: literal("wait"),
|
|
44776
|
-
seconds: number$1().min(0).max(
|
|
44928
|
+
seconds: number$1().min(0).max(WAIT_MAX_SECONDS, WAIT_TOO_LONG)
|
|
44777
44929
|
});
|
|
44778
|
-
/** The legacy `deviceId` of a cap step: still READ, never written (D983). */
|
|
44779
|
-
var LegacyStepDeviceSchema = union([
|
|
44780
|
-
number$1().int(),
|
|
44781
|
-
array(number$1().int()).min(1),
|
|
44782
|
-
object({ $var: string().min(1) })
|
|
44783
|
-
]);
|
|
44784
44930
|
/**
|
|
44785
|
-
* The fields of a
|
|
44786
|
-
*
|
|
44787
|
-
* device); a step is {@link AutomationCapStepSchema}.
|
|
44931
|
+
* The fields of a command step, before the vocabulary check. A step is
|
|
44932
|
+
* {@link AutomationCommandStepSchema}.
|
|
44788
44933
|
*/
|
|
44789
|
-
var
|
|
44790
|
-
kind: literal("
|
|
44791
|
-
/**
|
|
44792
|
-
|
|
44793
|
-
|
|
44794
|
-
|
|
44795
|
-
* cap + method match exactly one vocabulary action.
|
|
44796
|
-
*/
|
|
44797
|
-
actionId: string().min(1).optional(),
|
|
44798
|
-
/** WHO the step acts on. The only shape that is written. */
|
|
44799
|
-
target: ActionTargetSchema.optional(),
|
|
44934
|
+
var AutomationCommandStepBaseSchema = object({
|
|
44935
|
+
kind: literal("command"),
|
|
44936
|
+
/** WHO the step acts on. */
|
|
44937
|
+
target: ActionTargetSchema,
|
|
44938
|
+
/** The vocabulary action this step performs (`cover.open`). */
|
|
44939
|
+
actionId: string().min(1),
|
|
44800
44940
|
/**
|
|
44801
|
-
*
|
|
44802
|
-
*
|
|
44803
|
-
*
|
|
44941
|
+
* The values of the action's OPEN args (`position`, `presetId`); the args
|
|
44942
|
+
* the vocabulary bakes into the action are added when the step runs. Values
|
|
44943
|
+
* may carry `{{vars.x}}` slots, or be exactly `{ $var: 'name' }`, which
|
|
44944
|
+
* SUBSTITUTE and do not evaluate (§3.2.3).
|
|
44804
44945
|
*/
|
|
44805
|
-
deviceId: LegacyStepDeviceSchema.optional(),
|
|
44806
|
-
cap: string().min(1),
|
|
44807
|
-
method: string().min(1),
|
|
44808
|
-
/** Values may carry `{{vars.x}}` slots, or be exactly `{ $var: 'name' }`, which
|
|
44809
|
-
* SUBSTITUTE and do not evaluate (§3.2.3). Anything beyond substitution is
|
|
44810
|
-
* the expression leaf. */
|
|
44811
44946
|
args: record(string(), unknown()).optional(),
|
|
44812
44947
|
/**
|
|
44813
44948
|
* The unit the person picked per arg (display only). `args` always hold the
|
|
@@ -44816,18 +44951,20 @@ var AutomationCapStepBaseSchema = object({
|
|
|
44816
44951
|
*/
|
|
44817
44952
|
argUnits: record(string(), string().min(1)).optional()
|
|
44818
44953
|
});
|
|
44954
|
+
/** The vocabulary check every command step passes: the action exists. */
|
|
44955
|
+
function refineKnownAction(step, ctx) {
|
|
44956
|
+
if (findVocabAction(step.actionId) === void 0) ctx.addIssue({
|
|
44957
|
+
code: "custom",
|
|
44958
|
+
message: `"${step.actionId}" is not a vocabulary action id`,
|
|
44959
|
+
path: ["actionId"]
|
|
44960
|
+
});
|
|
44961
|
+
}
|
|
44819
44962
|
/**
|
|
44820
|
-
* The steps an internal Action may contain:
|
|
44963
|
+
* The steps an internal Action may contain: command and wait, and nothing that can
|
|
44821
44964
|
* call back into an Action — so an Action can never reach itself (no cycles).
|
|
44822
44965
|
* This is the LEAF shape: no condition of its own.
|
|
44823
44966
|
*/
|
|
44824
|
-
var LeafActionStepSchema = discriminatedUnion("kind", [AutomationWaitStepSchema,
|
|
44825
|
-
message: "a cap step needs a target",
|
|
44826
|
-
path: ["target"]
|
|
44827
|
-
}).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
|
|
44828
|
-
message: "a domain target needs the vocabulary action it applies to (actionId)",
|
|
44829
|
-
path: ["actionId"]
|
|
44830
|
-
})]);
|
|
44967
|
+
var LeafActionStepSchema = discriminatedUnion("kind", [AutomationWaitStepSchema, AutomationCommandStepBaseSchema.superRefine(refineKnownAction)]);
|
|
44831
44968
|
/**
|
|
44832
44969
|
* The optional guard of a step (#472): `if` is the ONE `when` tree (D980), read
|
|
44833
44970
|
* on the state mirror when the step is reached; `else` runs when it is false.
|
|
@@ -44843,39 +44980,209 @@ var elseNeedsIf = {
|
|
|
44843
44980
|
path: ["else"]
|
|
44844
44981
|
};
|
|
44845
44982
|
var GuardedWaitStepSchema = AutomationWaitStepSchema.extend(stepGuardShape).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
|
|
44846
|
-
var GuardedCapStepSchema = AutomationCapStepBaseSchema.extend(stepGuardShape).refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
|
|
44847
|
-
message: "a cap step needs a target",
|
|
44848
|
-
path: ["target"]
|
|
44849
|
-
}).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
|
|
44850
|
-
message: "a domain target needs the vocabulary action it applies to (actionId)",
|
|
44851
|
-
path: ["actionId"]
|
|
44852
|
-
}).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
|
|
44853
44983
|
/**
|
|
44854
44984
|
* A step of a STANDALONE list (an action, a scheduler point, a preset): the
|
|
44855
44985
|
* same two step kinds an automation runs, minus a guard that reads the
|
|
44856
44986
|
* automation's trigger, which such a list does not have.
|
|
44857
44987
|
*/
|
|
44858
|
-
var ActionStepSchema = discriminatedUnion("kind", [GuardedWaitStepSchema,
|
|
44988
|
+
var ActionStepSchema = discriminatedUnion("kind", [GuardedWaitStepSchema, AutomationCommandStepBaseSchema.extend(stepGuardShape).superRefine(refineKnownAction).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf)]).superRefine((step, ctx) => {
|
|
44859
44989
|
if (step.if !== void 0 && hasTriggeredByLeaves(step.if)) ctx.addIssue({
|
|
44860
44990
|
code: "custom",
|
|
44861
44991
|
message: TRIGGERED_BY_NEEDS_AUTOMATION,
|
|
44862
44992
|
path: ["if"]
|
|
44863
44993
|
});
|
|
44864
44994
|
});
|
|
44995
|
+
/**
|
|
44996
|
+
* Flow control of an AUTOMATION's list (#500). A standalone list (an action, a
|
|
44997
|
+
* scheduler point, a preset) stays `wait` and `cap`: it has no run of its own
|
|
44998
|
+
* to end and no variable bag to write.
|
|
44999
|
+
*/
|
|
45000
|
+
var continueOnErrorShape = {
|
|
45001
|
+
/** A failure of this step is traced `failed-continued` and the next step runs. */
|
|
45002
|
+
continueOnError: literal(true).optional() };
|
|
45003
|
+
/** An automation's command step: the shared guarded command step, plus `continueOnError`. */
|
|
45004
|
+
var AutomationGuardedCommandStepSchema = AutomationCommandStepBaseSchema.extend({
|
|
45005
|
+
...stepGuardShape,
|
|
45006
|
+
...continueOnErrorShape
|
|
45007
|
+
}).superRefine(refineKnownAction).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
|
|
45008
|
+
/** End the run here, on purpose. `reason` may carry `{{vars.x}}` slots. */
|
|
45009
|
+
var AutomationStopStepSchema = object({
|
|
45010
|
+
kind: literal("stop"),
|
|
45011
|
+
reason: string().min(1, "a stop needs a reason: it is what the run trace shows").max(200),
|
|
45012
|
+
/** `ok`: the run ends as a success. `failed`: it ends as a failure, with the reason. */
|
|
45013
|
+
outcome: _enum(["ok", "failed"]),
|
|
45014
|
+
/** Stop only when this reads true; false or unknown does not stop. */
|
|
45015
|
+
if: AutomationWhenSchema.optional()
|
|
45016
|
+
});
|
|
45017
|
+
var SET_VAR_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]{0,39}$/;
|
|
45018
|
+
/** Names the run itself writes and reads (`leaf` is what `triggered-by` judges): a step may not overwrite them. */
|
|
45019
|
+
var RESERVED_RUN_VARS = [
|
|
45020
|
+
"kind",
|
|
45021
|
+
"leaf",
|
|
45022
|
+
"at"
|
|
45023
|
+
];
|
|
45024
|
+
/**
|
|
45025
|
+
* Write variables into the run's bag, for the steps after it. SUBSTITUTION
|
|
45026
|
+
* only, never evaluation: a text value may carry `{{vars.x}}` slots.
|
|
45027
|
+
*/
|
|
45028
|
+
var AutomationSetStepSchema = object({
|
|
45029
|
+
kind: literal("set"),
|
|
45030
|
+
vars: record(string(), union([
|
|
45031
|
+
string().max(500),
|
|
45032
|
+
number$1(),
|
|
45033
|
+
boolean()
|
|
45034
|
+
])).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` }),
|
|
45035
|
+
/** Set only when this reads true; false or unknown leaves the bag as it is. */
|
|
45036
|
+
if: AutomationWhenSchema.optional()
|
|
45037
|
+
});
|
|
45038
|
+
var AutomationRunActionStepSchema = object({
|
|
45039
|
+
kind: literal("action"),
|
|
45040
|
+
/** An entry of the `actions` surface (`internal:<uuid>` or `<addonId>:<localId>`). */
|
|
45041
|
+
actionId: string().min(1),
|
|
45042
|
+
/** Values for the action's declared variables; the others take their default. */
|
|
45043
|
+
variables: record(string(), union([
|
|
45044
|
+
string(),
|
|
45045
|
+
number$1(),
|
|
45046
|
+
boolean()
|
|
45047
|
+
])).optional(),
|
|
45048
|
+
...continueOnErrorShape
|
|
45049
|
+
});
|
|
45050
|
+
/**
|
|
45051
|
+
* A step INSIDE a branch of a `choose`: a flow step with no condition of its
|
|
45052
|
+
* own (the branch is the condition) and no block inside it. Strict, so an `if`
|
|
45053
|
+
* written on such a step is refused rather than dropped.
|
|
45054
|
+
*/
|
|
45055
|
+
/** The longest a `wait-until` may wait: six hours. */
|
|
45056
|
+
var WAIT_UNTIL_TIMEOUT_MAX_S = 21600;
|
|
45057
|
+
/**
|
|
45058
|
+
* Pause the run until a condition is true (#500). The timeout is mandatory: a
|
|
45059
|
+
* run never waits without an end. `onTimeout` says what a wait that ran out
|
|
45060
|
+
* does: `continue` goes on to the next step, `stop` ends the run as a failure.
|
|
45061
|
+
* A condition that cannot be read is not "true": the wait goes on (D49).
|
|
45062
|
+
*/
|
|
45063
|
+
var AutomationWaitUntilStepSchema = object({
|
|
45064
|
+
kind: literal("wait-until"),
|
|
45065
|
+
when: AutomationWhenSchema,
|
|
45066
|
+
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)`),
|
|
45067
|
+
onTimeout: _enum(["continue", "stop"])
|
|
45068
|
+
}).strict();
|
|
45069
|
+
/** The step kinds that hold steps of their own, or pause on a condition: they nest two levels at most. */
|
|
45070
|
+
var BLOCK_STEP_KINDS = [
|
|
45071
|
+
"choose",
|
|
45072
|
+
"repeat",
|
|
45073
|
+
"parallel",
|
|
45074
|
+
"wait-until"
|
|
45075
|
+
];
|
|
45076
|
+
var NEST_TOO_DEEP = `steps nest two levels at most: a step inside a nested choose or repeat can be a plain step only`;
|
|
45077
|
+
function kindOf(input) {
|
|
45078
|
+
return typeof input === "object" && input !== null ? Reflect.get(input, "kind") : void 0;
|
|
45079
|
+
}
|
|
45080
|
+
/** Where the nesting ends, a block step is refused in words rather than as an unknown kind. */
|
|
45081
|
+
function nestTooDeep(issue) {
|
|
45082
|
+
const kind = kindOf(issue.input);
|
|
45083
|
+
return typeof kind === "string" && BLOCK_STEP_KINDS.includes(kind) ? NEST_TOO_DEEP : void 0;
|
|
45084
|
+
}
|
|
45085
|
+
var plainStepSchemas = [
|
|
45086
|
+
AutomationWaitStepSchema.strict(),
|
|
45087
|
+
AutomationCommandStepBaseSchema.extend(continueOnErrorShape).strict().superRefine(refineKnownAction),
|
|
45088
|
+
AutomationStopStepSchema.omit({ if: true }).strict(),
|
|
45089
|
+
AutomationSetStepSchema.omit({ if: true }).strict(),
|
|
45090
|
+
AutomationRunActionStepSchema.strict()
|
|
45091
|
+
];
|
|
45092
|
+
/**
|
|
45093
|
+
* A plain step: a flow step with no condition of its own and no step inside
|
|
45094
|
+
* it. The second (last) level of nesting holds these only.
|
|
45095
|
+
*/
|
|
45096
|
+
var AutomationBranchStepSchema = discriminatedUnion("kind", plainStepSchemas, { error: nestTooDeep });
|
|
45097
|
+
/** A step that can run beside others: it writes no variable and does not end the run. */
|
|
45098
|
+
var AutomationParallelMemberSchema = AutomationBranchStepSchema.refine((step) => step.kind === "command" || 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");
|
|
45099
|
+
/**
|
|
45100
|
+
* Several steps at once (#500): all are started together and all are awaited.
|
|
45101
|
+
* A failure fails the run once the others finished, as in a sequence; a member
|
|
45102
|
+
* marked "continue if this fails" does not.
|
|
45103
|
+
*/
|
|
45104
|
+
var AutomationParallelStepSchema = object({
|
|
45105
|
+
kind: literal("parallel"),
|
|
45106
|
+
steps: array(AutomationParallelMemberSchema).min(2, "a parallel needs at least two steps").max(5, `a parallel takes at most 5 steps`)
|
|
45107
|
+
}).strict();
|
|
45108
|
+
var REPEAT_NEEDS_MAX = "a repeat on a condition needs a maximum number of iterations";
|
|
45109
|
+
/** A loop on a condition: the bound is mandatory, so a run never loops without an end. */
|
|
45110
|
+
var repeatConditionShape = {
|
|
45111
|
+
when: AutomationWhenSchema,
|
|
45112
|
+
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`),
|
|
45113
|
+
/** A pause between two iterations, never after the last. */
|
|
45114
|
+
waitS: number$1().int().min(1).max(WAIT_MAX_SECONDS, WAIT_TOO_LONG).optional()
|
|
45115
|
+
};
|
|
45116
|
+
/** What decides how many times a `repeat` runs. */
|
|
45117
|
+
var AutomationRepeatLoopSchema = discriminatedUnion("by", [
|
|
45118
|
+
object({
|
|
45119
|
+
by: literal("count"),
|
|
45120
|
+
count: number$1().int().min(1).max(20, `a repeat runs at most 20 times`)
|
|
45121
|
+
}).strict(),
|
|
45122
|
+
object({
|
|
45123
|
+
by: literal("while"),
|
|
45124
|
+
...repeatConditionShape
|
|
45125
|
+
}).strict(),
|
|
45126
|
+
object({
|
|
45127
|
+
by: literal("until"),
|
|
45128
|
+
...repeatConditionShape
|
|
45129
|
+
}).strict(),
|
|
45130
|
+
object({
|
|
45131
|
+
by: literal("forEach"),
|
|
45132
|
+
target: object({
|
|
45133
|
+
kind: literal("devices"),
|
|
45134
|
+
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`)
|
|
45135
|
+
}).strict()
|
|
45136
|
+
}).strict()
|
|
45137
|
+
]);
|
|
45138
|
+
/**
|
|
45139
|
+
* The same steps several times (#500). Every form is bounded at save, so a
|
|
45140
|
+
* run cannot loop without an end. A failure or a `stop` in the steps ends the
|
|
45141
|
+
* loop and the run, as in a sequence.
|
|
45142
|
+
*/
|
|
45143
|
+
function repeatSchemaOf(step) {
|
|
45144
|
+
return object({
|
|
45145
|
+
kind: literal("repeat"),
|
|
45146
|
+
loop: AutomationRepeatLoopSchema,
|
|
45147
|
+
steps: array(step).min(1, "a repeat needs at least one step").max(10, `a repeat takes at most 10 steps`)
|
|
45148
|
+
}).strict();
|
|
45149
|
+
}
|
|
45150
|
+
/**
|
|
45151
|
+
* One step, several ways (#500): the branches are read in order and the FIRST
|
|
45152
|
+
* whose condition is true runs; `else` runs when every branch is false. A
|
|
45153
|
+
* branch that cannot be read ends the choice: nothing runs, not the branches
|
|
45154
|
+
* after it and not the else (D49). The #472 `if` / `else` of a wait or cap
|
|
45155
|
+
* step is the one-branch case and stays as it is stored.
|
|
45156
|
+
*/
|
|
45157
|
+
function chooseSchemaOf(step) {
|
|
45158
|
+
const steps = array(step).max(10);
|
|
45159
|
+
return object({
|
|
45160
|
+
kind: literal("choose"),
|
|
45161
|
+
branches: array(object({
|
|
45162
|
+
if: AutomationWhenSchema,
|
|
45163
|
+
steps: steps.min(1, "a branch needs at least one step")
|
|
45164
|
+
})).min(1, "a choose needs at least one branch").max(6, `a choose takes at most 6 branches`),
|
|
45165
|
+
else: steps.optional()
|
|
45166
|
+
});
|
|
45167
|
+
}
|
|
45168
|
+
var AutomationBodyStepSchema = discriminatedUnion("kind", [
|
|
45169
|
+
...plainStepSchemas,
|
|
45170
|
+
AutomationWaitUntilStepSchema,
|
|
45171
|
+
AutomationParallelStepSchema,
|
|
45172
|
+
chooseSchemaOf(AutomationBranchStepSchema),
|
|
45173
|
+
repeatSchemaOf(AutomationBranchStepSchema)
|
|
45174
|
+
]);
|
|
45175
|
+
var AutomationRepeatStepSchema = repeatSchemaOf(AutomationBodyStepSchema);
|
|
44865
45176
|
var AutomationActionSchema = discriminatedUnion("kind", [
|
|
44866
45177
|
GuardedWaitStepSchema,
|
|
44867
|
-
|
|
44868
|
-
|
|
44869
|
-
|
|
44870
|
-
|
|
44871
|
-
|
|
44872
|
-
|
|
44873
|
-
|
|
44874
|
-
|
|
44875
|
-
number$1(),
|
|
44876
|
-
boolean()
|
|
44877
|
-
])).optional()
|
|
44878
|
-
}),
|
|
45178
|
+
AutomationGuardedCommandStepSchema,
|
|
45179
|
+
AutomationStopStepSchema,
|
|
45180
|
+
AutomationSetStepSchema,
|
|
45181
|
+
chooseSchemaOf(AutomationBodyStepSchema),
|
|
45182
|
+
AutomationWaitUntilStepSchema,
|
|
45183
|
+
AutomationParallelStepSchema,
|
|
45184
|
+
AutomationRepeatStepSchema,
|
|
45185
|
+
AutomationRunActionStepSchema,
|
|
44879
45186
|
object({
|
|
44880
45187
|
kind: literal("code"),
|
|
44881
45188
|
/** Compiled into the automation's OWN block by esbuild — not a third
|
|
@@ -44938,44 +45245,7 @@ function convertLegacyRecipe(legacy) {
|
|
|
44938
45245
|
...rest
|
|
44939
45246
|
};
|
|
44940
45247
|
}
|
|
44941
|
-
/**
|
|
44942
|
-
* Where recipes are PARSED (the core-blocks cap, the MCP tool, the literal a
|
|
44943
|
-
* saved block carries): the new shape as it is, or the old shape converted to
|
|
44944
|
-
* it. The output type is always the new one.
|
|
44945
|
-
*/
|
|
44946
45248
|
var AutomationRecipeSchema = union([CurrentAutomationRecipeSchema, LegacyAutomationRecipeSchema.transform(convertLegacyRecipe)]);
|
|
44947
|
-
var DETECTION_DESCRIPTIONS = {
|
|
44948
|
-
deviceId: "the camera that saw it",
|
|
44949
|
-
className: "what it saw",
|
|
44950
|
-
trackId: "the track",
|
|
44951
|
-
score: "how sure the detector was",
|
|
44952
|
-
label: "the label it matched (a name, a plate), empty when none"
|
|
44953
|
-
};
|
|
44954
|
-
var STATIONARY_DESCRIPTIONS = {
|
|
44955
|
-
deviceId: "the camera that saw it",
|
|
44956
|
-
className: "what it saw",
|
|
44957
|
-
zones: "the zones it is in",
|
|
44958
|
-
phase: "appeared or departed",
|
|
44959
|
-
entryId: "the stopped object"
|
|
44960
|
-
};
|
|
44961
|
-
var BECOMES_DESCRIPTIONS = {
|
|
44962
|
-
deviceId: "the device that changed",
|
|
44963
|
-
from: "the value before the change, empty when it is not known",
|
|
44964
|
-
to: "the value it changed to"
|
|
44965
|
-
};
|
|
44966
|
-
function describe$1(descriptions) {
|
|
44967
|
-
return Object.entries(descriptions).map(([name, description]) => ({
|
|
44968
|
-
name,
|
|
44969
|
-
description
|
|
44970
|
-
}));
|
|
44971
|
-
}
|
|
44972
|
-
describe$1(DETECTION_DESCRIPTIONS);
|
|
44973
|
-
describe$1(STATIONARY_DESCRIPTIONS);
|
|
44974
|
-
describe$1(BECOMES_DESCRIPTIONS).map((v) => v.name === "deviceId" ? {
|
|
44975
|
-
...v,
|
|
44976
|
-
hintKey: "becomesDeviceId"
|
|
44977
|
-
} : v);
|
|
44978
|
-
new Set(Object.values(COCO_TO_MACRO.mapping));
|
|
44979
45249
|
/**
|
|
44980
45250
|
* Schedulers (D983) — an entity that performs actions over the day.
|
|
44981
45251
|
*
|
|
@@ -45027,12 +45297,16 @@ var HoldOverrideSchema = discriminatedUnion("mode", [object({ mode: literal("res
|
|
|
45027
45297
|
})]);
|
|
45028
45298
|
/** A missed edge up to this late still runs. */
|
|
45029
45299
|
var DEFAULT_MAX_LATE_MS = 10 * 6e4;
|
|
45300
|
+
var SchedulerStepSchema = ActionStepSchema.refine((step) => step.kind !== "wait" || step.seconds <= 300, {
|
|
45301
|
+
message: `a scheduler point waits at most five minutes (300 s); put a longer wait in an action`,
|
|
45302
|
+
path: ["seconds"]
|
|
45303
|
+
});
|
|
45030
45304
|
var SchedulerPointSchema = object({
|
|
45031
45305
|
id: string().min(1).max(64),
|
|
45032
45306
|
at: SchedulerTimeSpecSchema,
|
|
45033
45307
|
mode: SchedulerPointModeSchema,
|
|
45034
45308
|
/** The actions of an `edge` or `hold`; a `release` has none. */
|
|
45035
|
-
steps: array(
|
|
45309
|
+
steps: array(SchedulerStepSchema).max(20).default([]),
|
|
45036
45310
|
/** Checked when the point runs (an edge) or is applied (a hold). */
|
|
45037
45311
|
conditions: SchedulerStateTreeSchema.optional(),
|
|
45038
45312
|
/** Hold only; absent means `respect`. */
|
|
@@ -45230,6 +45504,7 @@ var AutomationConditionTraceNodeSchema = object({
|
|
|
45230
45504
|
"triggered-by",
|
|
45231
45505
|
"device-becomes",
|
|
45232
45506
|
"device-event",
|
|
45507
|
+
"device-fired",
|
|
45233
45508
|
"schedule",
|
|
45234
45509
|
"interval",
|
|
45235
45510
|
"manual",
|
|
@@ -45300,18 +45575,46 @@ var StepTraceBaseSchema = object({
|
|
|
45300
45575
|
]).optional(),
|
|
45301
45576
|
/** Why the condition read what it read, in the evaluator's own words. */
|
|
45302
45577
|
conditionReason: string().optional(),
|
|
45303
|
-
/** `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. */
|
|
45578
|
+
/** `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). */
|
|
45304
45579
|
outcome: _enum([
|
|
45305
45580
|
"ok",
|
|
45306
45581
|
"error",
|
|
45307
45582
|
"not-run",
|
|
45308
45583
|
"empty",
|
|
45309
|
-
"skipped"
|
|
45584
|
+
"skipped",
|
|
45585
|
+
"failed-continued",
|
|
45586
|
+
"timed-out"
|
|
45310
45587
|
]),
|
|
45311
45588
|
message: string().optional()
|
|
45312
45589
|
});
|
|
45590
|
+
/** What a block step adds to its row: which list ran, what each branch read, how many rounds. */
|
|
45591
|
+
var blockTraceShape = {
|
|
45592
|
+
/** A `choose` step (#500): the list that ran, `branches.<n>` or `else`. Absent when none did. */
|
|
45593
|
+
branch: string().optional(),
|
|
45594
|
+
/** A `choose` step: what each branch read, in order, up to the one that decided. */
|
|
45595
|
+
branchChecks: array(object({
|
|
45596
|
+
condition: _enum([
|
|
45597
|
+
"true",
|
|
45598
|
+
"false",
|
|
45599
|
+
"unknown"
|
|
45600
|
+
]),
|
|
45601
|
+
conditionReason: string().optional()
|
|
45602
|
+
})).optional(),
|
|
45603
|
+
/** A `repeat` step (#500): how many times its steps ran. */
|
|
45604
|
+
iterations: number$1().int().optional()
|
|
45605
|
+
};
|
|
45606
|
+
/** A step one level down: it may be a block step itself, whose own steps are plain rows (the nesting ends there). */
|
|
45607
|
+
var NestedStepTraceSchema = StepTraceBaseSchema.extend({
|
|
45608
|
+
...blockTraceShape,
|
|
45609
|
+
steps: array(StepTraceBaseSchema).optional()
|
|
45610
|
+
});
|
|
45313
45611
|
/** A step trace; the `else` steps that ran are one level of the same shape (the nesting is bounded at one). */
|
|
45314
|
-
var AutomationStepTraceSchema = StepTraceBaseSchema.extend({
|
|
45612
|
+
var AutomationStepTraceSchema = StepTraceBaseSchema.extend({
|
|
45613
|
+
else: array(StepTraceBaseSchema).optional(),
|
|
45614
|
+
...blockTraceShape,
|
|
45615
|
+
/** A `choose` step: the steps of the list that ran. A `parallel`: its members. A `repeat`: the LAST iteration. */
|
|
45616
|
+
steps: array(NestedStepTraceSchema).optional()
|
|
45617
|
+
});
|
|
45315
45618
|
var AutomationRunTraceSchema = object({
|
|
45316
45619
|
runId: string().min(1),
|
|
45317
45620
|
startedAt: number$1(),
|
|
@@ -45341,6 +45644,86 @@ var AutomationStateDocSchema = object({
|
|
|
45341
45644
|
lastRunStartedAt: number$1().nullable(),
|
|
45342
45645
|
traces: array(AutomationRunTraceSchema)
|
|
45343
45646
|
});
|
|
45647
|
+
var DETECTION_DESCRIPTIONS = {
|
|
45648
|
+
deviceId: "the camera that saw it",
|
|
45649
|
+
className: "what it saw",
|
|
45650
|
+
trackId: "the track",
|
|
45651
|
+
score: "how sure the detector was",
|
|
45652
|
+
label: "the label it matched (a name, a plate), empty when none"
|
|
45653
|
+
};
|
|
45654
|
+
var STATIONARY_DESCRIPTIONS = {
|
|
45655
|
+
deviceId: "the camera that saw it",
|
|
45656
|
+
className: "what it saw",
|
|
45657
|
+
zones: "the zones it is in",
|
|
45658
|
+
phase: "appeared or departed",
|
|
45659
|
+
entryId: "the stopped object"
|
|
45660
|
+
};
|
|
45661
|
+
var BECOMES_DESCRIPTIONS = {
|
|
45662
|
+
deviceId: "the device that changed",
|
|
45663
|
+
from: "the value before the change, empty when it is not known",
|
|
45664
|
+
to: "the value it changed to"
|
|
45665
|
+
};
|
|
45666
|
+
/**
|
|
45667
|
+
* A fire's payload is offered too, as `data.<path>` (`{{vars.data.channel}}`):
|
|
45668
|
+
* those names depend on the device, so they are not in this list.
|
|
45669
|
+
*/
|
|
45670
|
+
var FIRED_DESCRIPTIONS = {
|
|
45671
|
+
deviceId: "the device that fired",
|
|
45672
|
+
eventType: "the event, as the device names it",
|
|
45673
|
+
sourceId: "the part of the device that fired (a button), empty when it names none",
|
|
45674
|
+
eventKind: "the kind of press (press, long-press …), empty when the device declares none"
|
|
45675
|
+
};
|
|
45676
|
+
function describe$1(descriptions) {
|
|
45677
|
+
return Object.entries(descriptions).map(([name, description]) => ({
|
|
45678
|
+
name,
|
|
45679
|
+
description
|
|
45680
|
+
}));
|
|
45681
|
+
}
|
|
45682
|
+
describe$1(DETECTION_DESCRIPTIONS);
|
|
45683
|
+
describe$1(STATIONARY_DESCRIPTIONS);
|
|
45684
|
+
describe$1(FIRED_DESCRIPTIONS).map((v) => v.name === "deviceId" ? {
|
|
45685
|
+
...v,
|
|
45686
|
+
hintKey: "firedDeviceId"
|
|
45687
|
+
} : v);
|
|
45688
|
+
describe$1(BECOMES_DESCRIPTIONS).map((v) => v.name === "deviceId" ? {
|
|
45689
|
+
...v,
|
|
45690
|
+
hintKey: "becomesDeviceId"
|
|
45691
|
+
} : v);
|
|
45692
|
+
new Set(Object.values(COCO_TO_MACRO.mapping));
|
|
45693
|
+
/**
|
|
45694
|
+
* Generic stateless event emitter. Installed on a `DeviceType.EventEmitter`
|
|
45695
|
+
* device. Carries the device's EXACT declared event vocabulary verbatim
|
|
45696
|
+
* (NO normalization). Two shapes:
|
|
45697
|
+
* - structured source (HA `event.*` entity) → `vocabulary` is the fixed
|
|
45698
|
+
* declared set (e.g. press_short, press_long, …).
|
|
45699
|
+
* - generic/legacy source (HA bus events, e.g. zha_event) → `vocabulary`
|
|
45700
|
+
* is [] (open) and `lastEvent.data` carries the complex payload.
|
|
45701
|
+
* `vocabulary` (D1044) names each event for a person and types it for a
|
|
45702
|
+
* rule; `eventTypes` is its list of native tokens, kept for older readers.
|
|
45703
|
+
* A fire names the part of the device it came from in `sourceId` when the
|
|
45704
|
+
* vocabulary declares sources (a remote's buttons).
|
|
45705
|
+
* `seq` is monotonic so two identical events still produce distinct slice writes.
|
|
45706
|
+
*/
|
|
45707
|
+
var EventFireSchema = object({
|
|
45708
|
+
deviceId: number$1(),
|
|
45709
|
+
eventType: string(),
|
|
45710
|
+
sourceId: string().optional(),
|
|
45711
|
+
data: record(string(), unknown()).nullable(),
|
|
45712
|
+
timestamp: number$1().meta(readingMeta("none")),
|
|
45713
|
+
seq: number$1().meta(readingMeta("count"))
|
|
45714
|
+
});
|
|
45715
|
+
var EventEmitterStatusSchema = object({
|
|
45716
|
+
eventTypes: array(string()),
|
|
45717
|
+
/**
|
|
45718
|
+
* Required of a provider by the type. A status written before the field
|
|
45719
|
+
* existed still parses, as an empty vocabulary: read it through
|
|
45720
|
+
* `readEventVocabulary`, which then answers with the plain tokens.
|
|
45721
|
+
*/
|
|
45722
|
+
vocabulary: array(EventVocabularyEntrySchema).default([]),
|
|
45723
|
+
lastEvent: EventFireSchema.nullable(),
|
|
45724
|
+
eventCountSinceStart: number$1().meta(readingMeta("count"))
|
|
45725
|
+
});
|
|
45726
|
+
DeviceType.EventEmitter;
|
|
45344
45727
|
/**
|
|
45345
45728
|
* Actions — named, runnable things an operator (or an automation) can start,
|
|
45346
45729
|
* declared as LIST ENTRIES, never as devices.
|
|
@@ -45603,6 +45986,343 @@ function pruneDeletedEntities(selection, live, log, exporter) {
|
|
|
45603
45986
|
dropped
|
|
45604
45987
|
};
|
|
45605
45988
|
}
|
|
45989
|
+
/**
|
|
45990
|
+
* `device-export` — collection cap for addons that export camstack
|
|
45991
|
+
* devices to external ecosystems (HomeAssistant via MQTT discovery,
|
|
45992
|
+
* HomeKit/HAP, Alexa Smart Home, …).
|
|
45993
|
+
*
|
|
45994
|
+
* No `ecosystem` enum — the addon id identifies the export target.
|
|
45995
|
+
* Each addon owns its mapping logic in its own settings UI. The cap
|
|
45996
|
+
* exposes only the COMMON surface: link state, supported device
|
|
45997
|
+
* kinds (so the UI can filter the device picker), and per-device
|
|
45998
|
+
* expose/unexpose.
|
|
45999
|
+
*
|
|
46000
|
+
* INSTANCES. One export addon can serve several independent targets (a
|
|
46001
|
+
* HomeKit bridge, a Home Assistant broker). `listInstances` names them.
|
|
46002
|
+
* `instanceId` on a READ is optional: absent = the whole addon (linked if any
|
|
46003
|
+
* enabled instance is, `exposedDeviceCount` = distinct devices, `setup` = the
|
|
46004
|
+
* default instance's); present = that instance; an id the provider does not
|
|
46005
|
+
* serve is refused with `ExportInstanceUnknownError` (`export-instance-unknown`),
|
|
46006
|
+
* never answered empty. `instanceId` on a WRITE is REQUIRED: a membership
|
|
46007
|
+
* change always names the target it changes. A single-instance provider
|
|
46008
|
+
* accepts an absent id on a read or its own id, and refuses any other.
|
|
46009
|
+
*/
|
|
46010
|
+
/** Which instance of an export addon a call addresses. Absent on a read = the whole addon. */
|
|
46011
|
+
var InstanceIdSchema$1 = string().min(1);
|
|
46012
|
+
var InstancePinSchema = object({ instanceId: InstanceIdSchema$1.optional() });
|
|
46013
|
+
/** One independent export target of an addon. */
|
|
46014
|
+
var ExportInstanceSchema = object({
|
|
46015
|
+
instanceId: InstanceIdSchema$1,
|
|
46016
|
+
name: string(),
|
|
46017
|
+
enabled: boolean(),
|
|
46018
|
+
kind: string().optional(),
|
|
46019
|
+
/**
|
|
46020
|
+
* What this instance's platform accepts as a device name, in one operator-facing sentence
|
|
46021
|
+
* (D1049). The derived "Name on <instance>" field shows it; absent = the field says nothing
|
|
46022
|
+
* about the rule.
|
|
46023
|
+
*/
|
|
46024
|
+
nameRule: string().optional()
|
|
46025
|
+
});
|
|
46026
|
+
var EXPORT_INSTANCE_UNKNOWN = "export-instance-unknown";
|
|
46027
|
+
/** The named failure of an `instanceId` the provider does not serve. The message starts with the code. */
|
|
46028
|
+
var ExportInstanceUnknownError = class extends Error {
|
|
46029
|
+
code = EXPORT_INSTANCE_UNKNOWN;
|
|
46030
|
+
instanceId;
|
|
46031
|
+
constructor(addon, instanceId) {
|
|
46032
|
+
super(`${EXPORT_INSTANCE_UNKNOWN}: ${addon} serves no instance "${instanceId}"`);
|
|
46033
|
+
this.name = "ExportInstanceUnknownError";
|
|
46034
|
+
this.instanceId = instanceId;
|
|
46035
|
+
}
|
|
46036
|
+
};
|
|
46037
|
+
/**
|
|
46038
|
+
* The instance a `getStatus` call names. The cap's `status` block injects a per-device
|
|
46039
|
+
* `getStatus({ deviceId })` beside the method's own `{ instanceId? }`, so the provider sees
|
|
46040
|
+
* both shapes; only the second names an instance (a per-device status read is addon-wide).
|
|
46041
|
+
*/
|
|
46042
|
+
function statusInstanceOf(input) {
|
|
46043
|
+
return "instanceId" in input ? input.instanceId : void 0;
|
|
46044
|
+
}
|
|
46045
|
+
var LinkStateSchema = _enum([
|
|
46046
|
+
"unlinked",
|
|
46047
|
+
"linked",
|
|
46048
|
+
"error"
|
|
46049
|
+
]);
|
|
46050
|
+
/**
|
|
46051
|
+
* A single label/value row surfaced in the export panel's "Setup"
|
|
46052
|
+
* section. Rendered with a copy-to-clipboard button. `secret: true`
|
|
46053
|
+
* rows are masked by default with a reveal toggle (client ids,
|
|
46054
|
+
* secrets, …).
|
|
46055
|
+
*/
|
|
46056
|
+
var ExportSetupFieldSchema = object({
|
|
46057
|
+
label: string(),
|
|
46058
|
+
value: string(),
|
|
46059
|
+
/** Mask the value by default + render a reveal toggle (client id, secrets). */
|
|
46060
|
+
secret: boolean().optional()
|
|
46061
|
+
});
|
|
46062
|
+
/**
|
|
46063
|
+
* Generic, addon-agnostic pairing/account block. Any export addon can
|
|
46064
|
+
* surface a scannable QR, a set of copyable label/value rows, and a
|
|
46065
|
+
* free-form operator note — the `DeviceExportPanel` renders whatever
|
|
46066
|
+
* the provider supplies and skips the section entirely when `setup`
|
|
46067
|
+
* is unset.
|
|
46068
|
+
*/
|
|
46069
|
+
var ExportSetupSchema = object({
|
|
46070
|
+
/** A string to render as a scannable QR — HAP `X-HM://…` URI, a pairing URL, etc. Omitted when there's nothing to scan. */
|
|
46071
|
+
qr: string().optional(),
|
|
46072
|
+
/** Label/value rows shown with a copy button (HAP setup code, OAuth URLs, client id, linked-account count, …). */
|
|
46073
|
+
fields: array(ExportSetupFieldSchema).readonly().optional(),
|
|
46074
|
+
/** Free-form operator instructions rendered above the fields. */
|
|
46075
|
+
note: string().optional()
|
|
46076
|
+
});
|
|
46077
|
+
var DeviceExportStatusSchema = object({
|
|
46078
|
+
linkState: LinkStateSchema,
|
|
46079
|
+
exposedDeviceCount: number$1(),
|
|
46080
|
+
error: string().optional(),
|
|
46081
|
+
/**
|
|
46082
|
+
* Optional pairing/account info the panel renders in a generic
|
|
46083
|
+
* "Setup" section. Addon-agnostic — the addon id identifies the
|
|
46084
|
+
* export target, never an `ecosystem` key here.
|
|
46085
|
+
*/
|
|
46086
|
+
setup: ExportSetupSchema.optional()
|
|
46087
|
+
});
|
|
46088
|
+
var DeviceKindSchema = string();
|
|
46089
|
+
/**
|
|
46090
|
+
* EXPOSED NAME. What one instance calls a device on its platform, when it should not be the
|
|
46091
|
+
* device's own name. The exporter owns it: it is stored per instance in the exporter's per-device
|
|
46092
|
+
* store (D865), validated by the exporter against its platform's naming rules, and never reaches
|
|
46093
|
+
* the exported id — a rename updates the SAME device on the platform, never a second one.
|
|
46094
|
+
* Blank or `null` = the device's own name. A name the platform would refuse is refused with
|
|
46095
|
+
* `ExportNameRefusedError` (`export-name-refused`), whose message says why.
|
|
46096
|
+
*/
|
|
46097
|
+
var ExposedDeviceSchema = object({
|
|
46098
|
+
deviceId: string(),
|
|
46099
|
+
exposedAs: string().optional(),
|
|
46100
|
+
/** The operator's name for this device on this instance; absent = the device's own name. */
|
|
46101
|
+
exposedName: string().optional(),
|
|
46102
|
+
capabilities: array(string()).optional()
|
|
46103
|
+
});
|
|
46104
|
+
var ExposeInputSchema = object({
|
|
46105
|
+
instanceId: InstanceIdSchema$1,
|
|
46106
|
+
deviceId: string(),
|
|
46107
|
+
capabilities: array(string()).optional(),
|
|
46108
|
+
/** Set the exposed name in the same call; absent = leave it as it is, blank/null = clear it. */
|
|
46109
|
+
exposedName: string().nullable().optional()
|
|
46110
|
+
});
|
|
46111
|
+
var SetExposedNameInputSchema = object({
|
|
46112
|
+
instanceId: InstanceIdSchema$1,
|
|
46113
|
+
deviceId: string(),
|
|
46114
|
+
/** Blank or null = the device's own name. */
|
|
46115
|
+
name: string().nullable(),
|
|
46116
|
+
/**
|
|
46117
|
+
* Validate only: refuse exactly as a real call would, write nothing. A caller saving several
|
|
46118
|
+
* names at once checks every one first, so one refusal writes none (D1049).
|
|
46119
|
+
*/
|
|
46120
|
+
dryRun: boolean().optional()
|
|
46121
|
+
});
|
|
46122
|
+
var EXPORT_NAME_REFUSED = "export-name-refused";
|
|
46123
|
+
/** A name the instance's platform would refuse. The message starts with the code, then the reason. */
|
|
46124
|
+
var ExportNameRefusedError = class extends Error {
|
|
46125
|
+
code = EXPORT_NAME_REFUSED;
|
|
46126
|
+
instanceId;
|
|
46127
|
+
reason;
|
|
46128
|
+
constructor(instanceId, reason) {
|
|
46129
|
+
super(`${EXPORT_NAME_REFUSED}: ${reason}`);
|
|
46130
|
+
this.name = "ExportNameRefusedError";
|
|
46131
|
+
this.instanceId = instanceId;
|
|
46132
|
+
this.reason = reason;
|
|
46133
|
+
}
|
|
46134
|
+
};
|
|
46135
|
+
var UnexposeInputSchema = object({
|
|
46136
|
+
instanceId: InstanceIdSchema$1,
|
|
46137
|
+
deviceId: string()
|
|
46138
|
+
});
|
|
46139
|
+
/**
|
|
46140
|
+
* What an exporter may expose besides devices (D968). An action and a
|
|
46141
|
+
* notification target are LIST ENTRIES, never devices (D954): they enter an
|
|
46142
|
+
* exporter's own selection, not the device registry.
|
|
46143
|
+
*/
|
|
46144
|
+
var ExportEntityKindSchema = _enum([
|
|
46145
|
+
"device",
|
|
46146
|
+
"action",
|
|
46147
|
+
"notifier"
|
|
46148
|
+
]);
|
|
46149
|
+
var ExportEntityRefSchema = discriminatedUnion("kind", [
|
|
46150
|
+
object({
|
|
46151
|
+
kind: literal("device"),
|
|
46152
|
+
deviceId: string()
|
|
46153
|
+
}),
|
|
46154
|
+
object({
|
|
46155
|
+
kind: literal("action"),
|
|
46156
|
+
actionId: string().min(1)
|
|
46157
|
+
}),
|
|
46158
|
+
object({
|
|
46159
|
+
kind: literal("notifier"),
|
|
46160
|
+
targetId: string().min(1)
|
|
46161
|
+
})
|
|
46162
|
+
]);
|
|
46163
|
+
var ExposedEntitySchema = object({
|
|
46164
|
+
entity: ExportEntityRefSchema,
|
|
46165
|
+
exposedAs: string().optional()
|
|
46166
|
+
});
|
|
46167
|
+
var ExposeEntityInputSchema = object({
|
|
46168
|
+
instanceId: InstanceIdSchema$1,
|
|
46169
|
+
entity: ExportEntityRefSchema
|
|
46170
|
+
});
|
|
46171
|
+
var UnexposeEntityInputSchema = object({
|
|
46172
|
+
instanceId: InstanceIdSchema$1,
|
|
46173
|
+
entity: ExportEntityRefSchema
|
|
46174
|
+
});
|
|
46175
|
+
var deviceExportCapability = {
|
|
46176
|
+
name: "device-export",
|
|
46177
|
+
scope: "system",
|
|
46178
|
+
mode: "collection",
|
|
46179
|
+
providerKind: "device-export",
|
|
46180
|
+
status: {
|
|
46181
|
+
schema: DeviceExportStatusSchema,
|
|
46182
|
+
kind: "poll"
|
|
46183
|
+
},
|
|
46184
|
+
/**
|
|
46185
|
+
* Each export provider MAY contribute its own per-device "Export" panel
|
|
46186
|
+
* (enabled toggle, preferred stream, addon-specific knobs). The three
|
|
46187
|
+
* framework methods are mounted on the cap router when present.
|
|
46188
|
+
* `IDeviceExportProvider` leaves them optional: an exporter with no
|
|
46189
|
+
* per-device panel omits them (a `deviceConfig` cap's UI is derived and
|
|
46190
|
+
* never hand-written — D14 — and an exporter is not one of those).
|
|
46191
|
+
*/
|
|
46192
|
+
exposesDeviceSettings: true,
|
|
46193
|
+
methods: {
|
|
46194
|
+
getStatus: method(InstancePinSchema, DeviceExportStatusSchema),
|
|
46195
|
+
listInstances: method(_void(), array(ExportInstanceSchema)),
|
|
46196
|
+
listSupportedDeviceKinds: method(InstancePinSchema, array(DeviceKindSchema)),
|
|
46197
|
+
listExposedDevices: method(InstancePinSchema, array(ExposedDeviceSchema)),
|
|
46198
|
+
exposeDevice: method(ExposeInputSchema, _void(), {
|
|
46199
|
+
kind: "mutation",
|
|
46200
|
+
auth: "admin"
|
|
46201
|
+
}),
|
|
46202
|
+
unexposeDevice: method(UnexposeInputSchema, _void(), {
|
|
46203
|
+
kind: "mutation",
|
|
46204
|
+
auth: "admin"
|
|
46205
|
+
}),
|
|
46206
|
+
setExposedName: method(SetExposedNameInputSchema, _void(), {
|
|
46207
|
+
kind: "mutation",
|
|
46208
|
+
auth: "admin"
|
|
46209
|
+
}),
|
|
46210
|
+
listSupportedEntityKinds: optionalMethod(_void(), array(ExportEntityKindSchema)),
|
|
46211
|
+
listExposedEntities: optionalMethod(InstancePinSchema, array(ExposedEntitySchema)),
|
|
46212
|
+
exposeEntity: optionalMethod(ExposeEntityInputSchema, _void(), {
|
|
46213
|
+
kind: "mutation",
|
|
46214
|
+
auth: "admin"
|
|
46215
|
+
}),
|
|
46216
|
+
unexposeEntity: optionalMethod(UnexposeEntityInputSchema, _void(), {
|
|
46217
|
+
kind: "mutation",
|
|
46218
|
+
auth: "admin"
|
|
46219
|
+
})
|
|
46220
|
+
}
|
|
46221
|
+
};
|
|
46222
|
+
/**
|
|
46223
|
+
* The exposed name of a device on one export instance (`device-export`, D1049).
|
|
46224
|
+
*
|
|
46225
|
+
* Every exporter keeps its names the same way: in ITS per-device store (D865), under
|
|
46226
|
+
* {@link EXPOSED_NAMES_STORE_KEY}, one entry per instance id. The store is cleared centrally
|
|
46227
|
+
* when the device is deleted, so no removal hook is needed for it. Each exporter supplies the
|
|
46228
|
+
* validator of its own platform; the normalisation, the store shape and the refusal are here so
|
|
46229
|
+
* the four exporters cannot drift apart.
|
|
46230
|
+
*
|
|
46231
|
+
* The name is a label only: no exporter derives the exported id from it, so a rename updates
|
|
46232
|
+
* the same device on the platform.
|
|
46233
|
+
*/
|
|
46234
|
+
/** The per-device store key holding `{ [instanceId]: name }`. */
|
|
46235
|
+
var EXPOSED_NAMES_STORE_KEY = "exposedNames";
|
|
46236
|
+
var ExposedNamesSchema = record(string(), string());
|
|
46237
|
+
/** Trim and collapse whitespace, then the platform rule. Blank or null clears (`name: null`). */
|
|
46238
|
+
function checkExposedName(raw, validate) {
|
|
46239
|
+
if (raw === null || raw === void 0) return {
|
|
46240
|
+
ok: true,
|
|
46241
|
+
name: null
|
|
46242
|
+
};
|
|
46243
|
+
if (typeof raw !== "string") return {
|
|
46244
|
+
ok: false,
|
|
46245
|
+
reason: "The name must be text."
|
|
46246
|
+
};
|
|
46247
|
+
const name = raw.trim().replace(/\s+/g, " ");
|
|
46248
|
+
if (name.length === 0) return {
|
|
46249
|
+
ok: true,
|
|
46250
|
+
name: null
|
|
46251
|
+
};
|
|
46252
|
+
return validate(name);
|
|
46253
|
+
}
|
|
46254
|
+
/** Every saved name of a device, by instance id. A malformed blob reads as none. */
|
|
46255
|
+
function readExposedNames(store) {
|
|
46256
|
+
const parsed = ExposedNamesSchema.safeParse(store[EXPOSED_NAMES_STORE_KEY]);
|
|
46257
|
+
return parsed.success ? parsed.data : {};
|
|
46258
|
+
}
|
|
46259
|
+
/**
|
|
46260
|
+
* The saved name of one instance, or null: never saved, or a stored value the platform would
|
|
46261
|
+
* now refuse (the device's own name is used rather than pushing a name the platform rejects).
|
|
46262
|
+
*/
|
|
46263
|
+
function readExposedName(store, instanceId, validate) {
|
|
46264
|
+
const saved = readExposedNames(store)[instanceId];
|
|
46265
|
+
if (saved === void 0) return null;
|
|
46266
|
+
const check = checkExposedName(saved, validate);
|
|
46267
|
+
return check.ok ? check.name : null;
|
|
46268
|
+
}
|
|
46269
|
+
/** The store patch that sets (or, with null, clears) one instance's name and keeps the others. */
|
|
46270
|
+
function exposedNamePatch(store, instanceId, name) {
|
|
46271
|
+
const others = Object.fromEntries(Object.entries(readExposedNames(store)).filter(([id]) => id !== instanceId));
|
|
46272
|
+
return { [EXPOSED_NAMES_STORE_KEY]: name === null ? others : {
|
|
46273
|
+
...others,
|
|
46274
|
+
[instanceId]: name
|
|
46275
|
+
} };
|
|
46276
|
+
}
|
|
46277
|
+
/**
|
|
46278
|
+
* Validate and save one instance's name. A name the platform would refuse throws
|
|
46279
|
+
* {@link ExportNameRefusedError} BEFORE anything is written, so the old name stays.
|
|
46280
|
+
*/
|
|
46281
|
+
async function saveExposedName(input) {
|
|
46282
|
+
const check = checkExposedName(input.raw, input.validate);
|
|
46283
|
+
if (!check.ok) throw new ExportNameRefusedError(input.instanceId, check.reason);
|
|
46284
|
+
if (input.dryRun === true) return {
|
|
46285
|
+
changed: false,
|
|
46286
|
+
name: check.name
|
|
46287
|
+
};
|
|
46288
|
+
const store = await input.store.read(input.deviceId);
|
|
46289
|
+
if ((readExposedNames(store)[input.instanceId] ?? null) === check.name) return {
|
|
46290
|
+
changed: false,
|
|
46291
|
+
name: check.name
|
|
46292
|
+
};
|
|
46293
|
+
await input.store.write(input.deviceId, exposedNamePatch(store, input.instanceId, check.name));
|
|
46294
|
+
return {
|
|
46295
|
+
changed: true,
|
|
46296
|
+
name: check.name
|
|
46297
|
+
};
|
|
46298
|
+
}
|
|
46299
|
+
/** The exporter's per-device store as an {@link ExposedNameStore}; throws when settings are absent. */
|
|
46300
|
+
function exposedNameStoreOf(settings, owner) {
|
|
46301
|
+
const access = () => {
|
|
46302
|
+
if (settings === void 0) throw new Error(`${owner}: settings are not available`);
|
|
46303
|
+
return settings;
|
|
46304
|
+
};
|
|
46305
|
+
return {
|
|
46306
|
+
read: (deviceId) => access().readDeviceStore(deviceId),
|
|
46307
|
+
write: (deviceId, patch) => access().writeDeviceStore(deviceId, patch)
|
|
46308
|
+
};
|
|
46309
|
+
}
|
|
46310
|
+
/**
|
|
46311
|
+
* Remove every name saved for `instanceId` (the instance was deleted), so a later instance that
|
|
46312
|
+
* reuses the id does not inherit them. Returns the device ids that lost a name. A store that
|
|
46313
|
+
* cannot be read throws; nothing is written for the devices not reached.
|
|
46314
|
+
*/
|
|
46315
|
+
async function pruneExposedNames(settings, instanceId) {
|
|
46316
|
+
const ids = await settings.listDeviceStoreIds();
|
|
46317
|
+
if (ids.length === 0) return [];
|
|
46318
|
+
const pruned = [];
|
|
46319
|
+
for (const [deviceId, store] of await settings.readDeviceStoreBatch(ids)) {
|
|
46320
|
+
if (readExposedNames(store)[instanceId] === void 0) continue;
|
|
46321
|
+
await settings.writeDeviceStore(deviceId, exposedNamePatch(store, instanceId, null));
|
|
46322
|
+
pruned.push(deviceId);
|
|
46323
|
+
}
|
|
46324
|
+
return pruned;
|
|
46325
|
+
}
|
|
45606
46326
|
_enum([
|
|
45607
46327
|
"automation",
|
|
45608
46328
|
"action",
|
|
@@ -45801,7 +46521,9 @@ var AddonHttpRouteSchema = object({
|
|
|
45801
46521
|
]).optional(),
|
|
45802
46522
|
description: string().optional(),
|
|
45803
46523
|
/** The hub limits this route per client address before the handler runs. */
|
|
45804
|
-
rateLimit: _enum(["auth"]).optional()
|
|
46524
|
+
rateLimit: _enum(["auth"]).optional(),
|
|
46525
|
+
/** Served once per integration instance; the handler reads `instanceId`. */
|
|
46526
|
+
perInstance: boolean().optional()
|
|
45805
46527
|
});
|
|
45806
46528
|
/**
|
|
45807
46529
|
* Cross-process route invocation envelope. The hub captures the
|
|
@@ -45818,6 +46540,8 @@ var InvokeRequestSchema = object({
|
|
|
45818
46540
|
query: record(string(), string()),
|
|
45819
46541
|
body: unknown(),
|
|
45820
46542
|
headers: record(string(), string()),
|
|
46543
|
+
/** The instance the hub resolved for a `perInstance` route. */
|
|
46544
|
+
instanceId: string().optional(),
|
|
45821
46545
|
user: object({
|
|
45822
46546
|
id: string(),
|
|
45823
46547
|
username: string(),
|
|
@@ -49885,11 +50609,13 @@ var IrCodecError = class extends Error {
|
|
|
49885
50609
|
this.code = code;
|
|
49886
50610
|
}
|
|
49887
50611
|
};
|
|
50612
|
+
/** Maximum number of mark/space entries one pulse train may carry. */
|
|
50613
|
+
var IR_TIMINGS_MAX = 1024;
|
|
49888
50614
|
/**
|
|
49889
50615
|
* A pulse train in signed microseconds: mark (+) first, then space (-), strictly
|
|
49890
50616
|
* alternating, no zeros, 2..1024 entries.
|
|
49891
50617
|
*/
|
|
49892
|
-
var IrTimingsSchema = array(number$1().int()).min(2).max(
|
|
50618
|
+
var IrTimingsSchema = array(number$1().int()).min(2).max(IR_TIMINGS_MAX).superRefine((timings, ctx) => {
|
|
49893
50619
|
timings.forEach((value, index) => {
|
|
49894
50620
|
const expectMark = index % 2 === 0;
|
|
49895
50621
|
if (value === 0 || value > 0 !== expectMark) ctx.addIssue({
|
|
@@ -49936,15 +50662,186 @@ function decodePronto(code) {
|
|
|
49936
50662
|
carrierHz: Math.round(1e6 / unitUs)
|
|
49937
50663
|
};
|
|
49938
50664
|
}
|
|
49939
|
-
/**
|
|
49940
|
-
|
|
49941
|
-
|
|
49942
|
-
|
|
49943
|
-
|
|
49944
|
-
|
|
49945
|
-
|
|
49946
|
-
|
|
49947
|
-
|
|
50665
|
+
/**
|
|
50666
|
+
* FastLZ level 1: a byte-oriented LZ77 stream. A control byte below 32 starts a
|
|
50667
|
+
* literal run of `ctrl + 1` bytes; otherwise it is a back-reference whose length
|
|
50668
|
+
* is `ctrl >> 5` (extended by one byte when 7) and whose distance is split
|
|
50669
|
+
* between the low 5 bits and the next byte.
|
|
50670
|
+
*/
|
|
50671
|
+
var MAX_DISTANCE = 8192;
|
|
50672
|
+
var MAX_LITERAL_RUN = 32;
|
|
50673
|
+
var MIN_MATCH = 3;
|
|
50674
|
+
var MAX_MATCH = 264;
|
|
50675
|
+
/**
|
|
50676
|
+
* Most bytes a decoded IR code may hold: two bytes per timing. A level-1 stream
|
|
50677
|
+
* can expand ~130x, so the decoder checks this bound before every write.
|
|
50678
|
+
*/
|
|
50679
|
+
var IR_DECOMPRESSED_MAX = IR_TIMINGS_MAX * 2;
|
|
50680
|
+
function fastlzDecompress(input) {
|
|
50681
|
+
const out = [];
|
|
50682
|
+
let ip = 0;
|
|
50683
|
+
const room = (count) => {
|
|
50684
|
+
if (out.length + count > IR_DECOMPRESSED_MAX) throw new IrCodecError("tuya-malformed", "decompressed code is larger than any IR train");
|
|
50685
|
+
};
|
|
50686
|
+
const next = () => {
|
|
50687
|
+
const byte = input[ip++];
|
|
50688
|
+
if (byte === void 0) throw new IrCodecError("tuya-malformed", "compressed stream is truncated");
|
|
50689
|
+
return byte;
|
|
50690
|
+
};
|
|
50691
|
+
while (ip < input.length) {
|
|
50692
|
+
const ctrl = next();
|
|
50693
|
+
if (ctrl < 32) {
|
|
50694
|
+
room(ctrl + 1);
|
|
50695
|
+
for (let i = 0; i <= ctrl; i++) out.push(next());
|
|
50696
|
+
continue;
|
|
50697
|
+
}
|
|
50698
|
+
let len = (ctrl >> 5) - 1;
|
|
50699
|
+
if (len === 6) len += next();
|
|
50700
|
+
const distance = ((ctrl & 31) << 8) + next() + 1;
|
|
50701
|
+
const start = out.length - distance;
|
|
50702
|
+
if (start < 0) throw new IrCodecError("tuya-malformed", "back-reference points before the stream");
|
|
50703
|
+
room(len + 3);
|
|
50704
|
+
for (let i = 0; i < len + 3; i++) {
|
|
50705
|
+
const byte = out[start + i];
|
|
50706
|
+
if (byte === void 0) throw new IrCodecError("tuya-malformed", "back-reference is invalid");
|
|
50707
|
+
out.push(byte);
|
|
50708
|
+
}
|
|
50709
|
+
}
|
|
50710
|
+
return Uint8Array.from(out);
|
|
50711
|
+
}
|
|
50712
|
+
function fastlzCompress(input) {
|
|
50713
|
+
const out = [];
|
|
50714
|
+
const lastSeen = /* @__PURE__ */ new Map();
|
|
50715
|
+
let literalStart = 0;
|
|
50716
|
+
const flushLiterals = (end) => {
|
|
50717
|
+
for (let from = literalStart; from < end; from += MAX_LITERAL_RUN) {
|
|
50718
|
+
const to = Math.min(from + MAX_LITERAL_RUN, end);
|
|
50719
|
+
out.push(to - from - 1);
|
|
50720
|
+
for (let i = from; i < to; i++) out.push(input[i] ?? 0);
|
|
50721
|
+
}
|
|
50722
|
+
};
|
|
50723
|
+
let pos = 0;
|
|
50724
|
+
while (pos < input.length) {
|
|
50725
|
+
let matchLen = 0;
|
|
50726
|
+
let matchDistance = 0;
|
|
50727
|
+
if (pos + MIN_MATCH <= input.length) {
|
|
50728
|
+
const key = (input[pos] ?? 0) << 16 | (input[pos + 1] ?? 0) << 8 | (input[pos + 2] ?? 0);
|
|
50729
|
+
const candidate = lastSeen.get(key);
|
|
50730
|
+
lastSeen.set(key, pos);
|
|
50731
|
+
if (candidate !== void 0 && pos - candidate <= MAX_DISTANCE) {
|
|
50732
|
+
let len = 0;
|
|
50733
|
+
while (pos + len < input.length && len < MAX_MATCH && input[candidate + len] === input[pos + len]) len++;
|
|
50734
|
+
if (len >= MIN_MATCH) {
|
|
50735
|
+
matchLen = len;
|
|
50736
|
+
matchDistance = pos - candidate - 1;
|
|
50737
|
+
}
|
|
50738
|
+
}
|
|
50739
|
+
}
|
|
50740
|
+
if (matchLen === 0) {
|
|
50741
|
+
pos++;
|
|
50742
|
+
continue;
|
|
50743
|
+
}
|
|
50744
|
+
flushLiterals(pos);
|
|
50745
|
+
const enc = matchLen - 2;
|
|
50746
|
+
if (enc < 7) out.push(enc << 5 | matchDistance >> 8);
|
|
50747
|
+
else out.push(224 | matchDistance >> 8, enc - 7);
|
|
50748
|
+
out.push(matchDistance & 255);
|
|
50749
|
+
pos += matchLen;
|
|
50750
|
+
literalStart = pos;
|
|
50751
|
+
}
|
|
50752
|
+
flushLiterals(input.length);
|
|
50753
|
+
return Uint8Array.from(out);
|
|
50754
|
+
}
|
|
50755
|
+
var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
50756
|
+
var MAX_DURATION_US = 65535;
|
|
50757
|
+
function toBase64(bytes) {
|
|
50758
|
+
let out = "";
|
|
50759
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
50760
|
+
const a = bytes[i] ?? 0;
|
|
50761
|
+
const b = bytes[i + 1] ?? 0;
|
|
50762
|
+
const c = bytes[i + 2] ?? 0;
|
|
50763
|
+
const word = a << 16 | b << 8 | c;
|
|
50764
|
+
out += ALPHABET[word >> 18 & 63];
|
|
50765
|
+
out += ALPHABET[word >> 12 & 63];
|
|
50766
|
+
out += i + 1 < bytes.length ? ALPHABET[word >> 6 & 63] : "=";
|
|
50767
|
+
out += i + 2 < bytes.length ? ALPHABET[word & 63] : "=";
|
|
50768
|
+
}
|
|
50769
|
+
return out;
|
|
50770
|
+
}
|
|
50771
|
+
function fromBase64(text) {
|
|
50772
|
+
const clean = text.trim().replace(/=+$/, "");
|
|
50773
|
+
if (clean.length === 0 || clean.length % 4 === 1) throw new IrCodecError("tuya-malformed", "not a base64 string");
|
|
50774
|
+
const out = [];
|
|
50775
|
+
let bits = 0;
|
|
50776
|
+
let acc = 0;
|
|
50777
|
+
for (const ch of clean) {
|
|
50778
|
+
const value = ALPHABET.indexOf(ch);
|
|
50779
|
+
if (value < 0) throw new IrCodecError("tuya-malformed", "not a base64 string");
|
|
50780
|
+
acc = acc << 6 | value;
|
|
50781
|
+
bits += 6;
|
|
50782
|
+
if (bits >= 8) {
|
|
50783
|
+
bits -= 8;
|
|
50784
|
+
out.push(acc >> bits & 255);
|
|
50785
|
+
}
|
|
50786
|
+
}
|
|
50787
|
+
return Uint8Array.from(out);
|
|
50788
|
+
}
|
|
50789
|
+
/** Signed pulse train to a Tuya IR code: base64(FastLZ(uint16 LE durations)). */
|
|
50790
|
+
function encodeTuya(timings) {
|
|
50791
|
+
const bytes = new Uint8Array(timings.length * 2);
|
|
50792
|
+
timings.forEach((value, index) => {
|
|
50793
|
+
const duration = Math.abs(value);
|
|
50794
|
+
if (duration === 0 || duration > MAX_DURATION_US) throw new IrCodecError("invalid-timings", `timing ${index} does not fit 16 bits`);
|
|
50795
|
+
bytes[index * 2] = duration & 255;
|
|
50796
|
+
bytes[index * 2 + 1] = duration >> 8;
|
|
50797
|
+
});
|
|
50798
|
+
return toBase64(fastlzCompress(bytes));
|
|
50799
|
+
}
|
|
50800
|
+
/** A Tuya IR code to a signed pulse train (mark first). Throws `IrCodecError`. */
|
|
50801
|
+
function decodeTuya(code) {
|
|
50802
|
+
const bytes = fastlzDecompress(fromBase64(code));
|
|
50803
|
+
if (bytes.length === 0 || bytes.length % 2 !== 0) throw new IrCodecError("tuya-malformed", "payload is not a list of 16-bit durations");
|
|
50804
|
+
const timings = [];
|
|
50805
|
+
for (let i = 0; i < bytes.length; i += 2) {
|
|
50806
|
+
const duration = (bytes[i] ?? 0) | (bytes[i + 1] ?? 0) << 8;
|
|
50807
|
+
timings.push(i / 2 % 2 === 0 ? duration : -duration);
|
|
50808
|
+
}
|
|
50809
|
+
const checked = IrTimingsSchema.safeParse(timings);
|
|
50810
|
+
if (!checked.success) throw new IrCodecError("tuya-malformed", checked.error.message);
|
|
50811
|
+
return checked.data;
|
|
50812
|
+
}
|
|
50813
|
+
/** Device-native IR code formats a transmitter can replay verbatim. */
|
|
50814
|
+
var IrNativeFormatSchema = _enum(["tuya"]);
|
|
50815
|
+
/**
|
|
50816
|
+
* Longest native code accepted: base64 of the worst-case compressed stream
|
|
50817
|
+
* (every decoded byte as a literal, plus one control byte per 32), with margin.
|
|
50818
|
+
*/
|
|
50819
|
+
var IR_NATIVE_CODE_MAX_CHARS = Math.ceil((IR_DECOMPRESSED_MAX + Math.ceil(IR_DECOMPRESSED_MAX / 32)) / 3) * 4 + 256;
|
|
50820
|
+
var IrNativeCodeSchema = object({
|
|
50821
|
+
format: IrNativeFormatSchema,
|
|
50822
|
+
code: string().min(1).max(IR_NATIVE_CODE_MAX_CHARS)
|
|
50823
|
+
});
|
|
50824
|
+
var IR_NATIVE_CODECS = { tuya: {
|
|
50825
|
+
encode: encodeTuya,
|
|
50826
|
+
decode: decodeTuya
|
|
50827
|
+
} };
|
|
50828
|
+
/** What a remote command stores: a raw pulse train, a learned Pronto code, or a device-native code. */
|
|
50829
|
+
var IrPayloadSchema = discriminatedUnion("kind", [
|
|
50830
|
+
object({
|
|
50831
|
+
kind: literal("raw"),
|
|
50832
|
+
timings: array(number$1().int()),
|
|
50833
|
+
settings: TransmitSettingsSchema.optional()
|
|
50834
|
+
}),
|
|
50835
|
+
object({
|
|
50836
|
+
kind: literal("pronto"),
|
|
50837
|
+
code: string()
|
|
50838
|
+
}),
|
|
50839
|
+
object({
|
|
50840
|
+
kind: literal("native"),
|
|
50841
|
+
format: IrNativeFormatSchema,
|
|
50842
|
+
code: string()
|
|
50843
|
+
})
|
|
50844
|
+
]);
|
|
49948
50845
|
/** Resolve a payload to what `ir-transmitter.send` takes. Throws `IrCodecError`. */
|
|
49949
50846
|
function toTimings(payload) {
|
|
49950
50847
|
if (payload.kind === "pronto") {
|
|
@@ -49954,6 +50851,10 @@ function toTimings(payload) {
|
|
|
49954
50851
|
settings: { carrierHz: decoded.carrierHz }
|
|
49955
50852
|
};
|
|
49956
50853
|
}
|
|
50854
|
+
if (payload.kind === "native") return {
|
|
50855
|
+
timings: IR_NATIVE_CODECS[payload.format].decode(payload.code),
|
|
50856
|
+
settings: {}
|
|
50857
|
+
};
|
|
49957
50858
|
const checked = IrTimingsSchema.safeParse(payload.timings);
|
|
49958
50859
|
if (!checked.success) throw new IrCodecError("invalid-timings", checked.error.message);
|
|
49959
50860
|
return {
|
|
@@ -52038,193 +52939,6 @@ method(object({
|
|
|
52038
52939
|
kind: "mutation",
|
|
52039
52940
|
auth: "admin"
|
|
52040
52941
|
});
|
|
52041
|
-
/**
|
|
52042
|
-
* `device-export` — collection cap for addons that export camstack
|
|
52043
|
-
* devices to external ecosystems (HomeAssistant via MQTT discovery,
|
|
52044
|
-
* HomeKit/HAP, Alexa Smart Home, …).
|
|
52045
|
-
*
|
|
52046
|
-
* No `ecosystem` enum — the addon id identifies the export target.
|
|
52047
|
-
* Each addon owns its mapping logic in its own settings UI. The cap
|
|
52048
|
-
* exposes only the COMMON surface: link state, supported device
|
|
52049
|
-
* kinds (so the UI can filter the device picker), and per-device
|
|
52050
|
-
* expose/unexpose.
|
|
52051
|
-
*
|
|
52052
|
-
* INSTANCES. One export addon can serve several independent targets (a
|
|
52053
|
-
* HomeKit bridge, a Home Assistant broker). `listInstances` names them.
|
|
52054
|
-
* `instanceId` on a READ is optional: absent = the whole addon (linked if any
|
|
52055
|
-
* enabled instance is, `exposedDeviceCount` = distinct devices, `setup` = the
|
|
52056
|
-
* default instance's); present = that instance; an id the provider does not
|
|
52057
|
-
* serve is refused with `ExportInstanceUnknownError` (`export-instance-unknown`),
|
|
52058
|
-
* never answered empty. `instanceId` on a WRITE is REQUIRED: a membership
|
|
52059
|
-
* change always names the target it changes. A single-instance provider
|
|
52060
|
-
* accepts an absent id on a read or its own id, and refuses any other.
|
|
52061
|
-
*/
|
|
52062
|
-
/** Which instance of an export addon a call addresses. Absent on a read = the whole addon. */
|
|
52063
|
-
var InstanceIdSchema$1 = string().min(1);
|
|
52064
|
-
var InstancePinSchema = object({ instanceId: InstanceIdSchema$1.optional() });
|
|
52065
|
-
/** One independent export target of an addon. */
|
|
52066
|
-
var ExportInstanceSchema = object({
|
|
52067
|
-
instanceId: InstanceIdSchema$1,
|
|
52068
|
-
name: string(),
|
|
52069
|
-
enabled: boolean(),
|
|
52070
|
-
kind: string().optional()
|
|
52071
|
-
});
|
|
52072
|
-
var EXPORT_INSTANCE_UNKNOWN = "export-instance-unknown";
|
|
52073
|
-
/** The named failure of an `instanceId` the provider does not serve. The message starts with the code. */
|
|
52074
|
-
var ExportInstanceUnknownError = class extends Error {
|
|
52075
|
-
code = EXPORT_INSTANCE_UNKNOWN;
|
|
52076
|
-
instanceId;
|
|
52077
|
-
constructor(addon, instanceId) {
|
|
52078
|
-
super(`${EXPORT_INSTANCE_UNKNOWN}: ${addon} serves no instance "${instanceId}"`);
|
|
52079
|
-
this.name = "ExportInstanceUnknownError";
|
|
52080
|
-
this.instanceId = instanceId;
|
|
52081
|
-
}
|
|
52082
|
-
};
|
|
52083
|
-
/**
|
|
52084
|
-
* The instance a `getStatus` call names. The cap's `status` block injects a per-device
|
|
52085
|
-
* `getStatus({ deviceId })` beside the method's own `{ instanceId? }`, so the provider sees
|
|
52086
|
-
* both shapes; only the second names an instance (a per-device status read is addon-wide).
|
|
52087
|
-
*/
|
|
52088
|
-
function statusInstanceOf(input) {
|
|
52089
|
-
return "instanceId" in input ? input.instanceId : void 0;
|
|
52090
|
-
}
|
|
52091
|
-
var LinkStateSchema = _enum([
|
|
52092
|
-
"unlinked",
|
|
52093
|
-
"linked",
|
|
52094
|
-
"error"
|
|
52095
|
-
]);
|
|
52096
|
-
/**
|
|
52097
|
-
* A single label/value row surfaced in the export panel's "Setup"
|
|
52098
|
-
* section. Rendered with a copy-to-clipboard button. `secret: true`
|
|
52099
|
-
* rows are masked by default with a reveal toggle (client ids,
|
|
52100
|
-
* secrets, …).
|
|
52101
|
-
*/
|
|
52102
|
-
var ExportSetupFieldSchema = object({
|
|
52103
|
-
label: string(),
|
|
52104
|
-
value: string(),
|
|
52105
|
-
/** Mask the value by default + render a reveal toggle (client id, secrets). */
|
|
52106
|
-
secret: boolean().optional()
|
|
52107
|
-
});
|
|
52108
|
-
/**
|
|
52109
|
-
* Generic, addon-agnostic pairing/account block. Any export addon can
|
|
52110
|
-
* surface a scannable QR, a set of copyable label/value rows, and a
|
|
52111
|
-
* free-form operator note — the `DeviceExportPanel` renders whatever
|
|
52112
|
-
* the provider supplies and skips the section entirely when `setup`
|
|
52113
|
-
* is unset.
|
|
52114
|
-
*/
|
|
52115
|
-
var ExportSetupSchema = object({
|
|
52116
|
-
/** A string to render as a scannable QR — HAP `X-HM://…` URI, a pairing URL, etc. Omitted when there's nothing to scan. */
|
|
52117
|
-
qr: string().optional(),
|
|
52118
|
-
/** Label/value rows shown with a copy button (HAP setup code, OAuth URLs, client id, linked-account count, …). */
|
|
52119
|
-
fields: array(ExportSetupFieldSchema).readonly().optional(),
|
|
52120
|
-
/** Free-form operator instructions rendered above the fields. */
|
|
52121
|
-
note: string().optional()
|
|
52122
|
-
});
|
|
52123
|
-
var DeviceExportStatusSchema = object({
|
|
52124
|
-
linkState: LinkStateSchema,
|
|
52125
|
-
exposedDeviceCount: number$1(),
|
|
52126
|
-
error: string().optional(),
|
|
52127
|
-
/**
|
|
52128
|
-
* Optional pairing/account info the panel renders in a generic
|
|
52129
|
-
* "Setup" section. Addon-agnostic — the addon id identifies the
|
|
52130
|
-
* export target, never an `ecosystem` key here.
|
|
52131
|
-
*/
|
|
52132
|
-
setup: ExportSetupSchema.optional()
|
|
52133
|
-
});
|
|
52134
|
-
var DeviceKindSchema = string();
|
|
52135
|
-
var ExposedDeviceSchema = object({
|
|
52136
|
-
deviceId: string(),
|
|
52137
|
-
exposedAs: string().optional(),
|
|
52138
|
-
capabilities: array(string()).optional()
|
|
52139
|
-
});
|
|
52140
|
-
var ExposeInputSchema = object({
|
|
52141
|
-
instanceId: InstanceIdSchema$1,
|
|
52142
|
-
deviceId: string(),
|
|
52143
|
-
capabilities: array(string()).optional()
|
|
52144
|
-
});
|
|
52145
|
-
var UnexposeInputSchema = object({
|
|
52146
|
-
instanceId: InstanceIdSchema$1,
|
|
52147
|
-
deviceId: string()
|
|
52148
|
-
});
|
|
52149
|
-
/**
|
|
52150
|
-
* What an exporter may expose besides devices (D968). An action and a
|
|
52151
|
-
* notification target are LIST ENTRIES, never devices (D954): they enter an
|
|
52152
|
-
* exporter's own selection, not the device registry.
|
|
52153
|
-
*/
|
|
52154
|
-
var ExportEntityKindSchema = _enum([
|
|
52155
|
-
"device",
|
|
52156
|
-
"action",
|
|
52157
|
-
"notifier"
|
|
52158
|
-
]);
|
|
52159
|
-
var ExportEntityRefSchema = discriminatedUnion("kind", [
|
|
52160
|
-
object({
|
|
52161
|
-
kind: literal("device"),
|
|
52162
|
-
deviceId: string()
|
|
52163
|
-
}),
|
|
52164
|
-
object({
|
|
52165
|
-
kind: literal("action"),
|
|
52166
|
-
actionId: string().min(1)
|
|
52167
|
-
}),
|
|
52168
|
-
object({
|
|
52169
|
-
kind: literal("notifier"),
|
|
52170
|
-
targetId: string().min(1)
|
|
52171
|
-
})
|
|
52172
|
-
]);
|
|
52173
|
-
var ExposedEntitySchema = object({
|
|
52174
|
-
entity: ExportEntityRefSchema,
|
|
52175
|
-
exposedAs: string().optional()
|
|
52176
|
-
});
|
|
52177
|
-
var ExposeEntityInputSchema = object({
|
|
52178
|
-
instanceId: InstanceIdSchema$1,
|
|
52179
|
-
entity: ExportEntityRefSchema
|
|
52180
|
-
});
|
|
52181
|
-
var UnexposeEntityInputSchema = object({
|
|
52182
|
-
instanceId: InstanceIdSchema$1,
|
|
52183
|
-
entity: ExportEntityRefSchema
|
|
52184
|
-
});
|
|
52185
|
-
var deviceExportCapability = {
|
|
52186
|
-
name: "device-export",
|
|
52187
|
-
scope: "system",
|
|
52188
|
-
mode: "collection",
|
|
52189
|
-
providerKind: "device-export",
|
|
52190
|
-
status: {
|
|
52191
|
-
schema: DeviceExportStatusSchema,
|
|
52192
|
-
kind: "poll"
|
|
52193
|
-
},
|
|
52194
|
-
/**
|
|
52195
|
-
* Each export provider MAY contribute its own per-device "Export" panel
|
|
52196
|
-
* (enabled toggle, preferred stream, addon-specific knobs). The three
|
|
52197
|
-
* framework methods are mounted on the cap router when present.
|
|
52198
|
-
* `IDeviceExportProvider` leaves them optional: an exporter with no
|
|
52199
|
-
* per-device panel omits them (a `deviceConfig` cap's UI is derived and
|
|
52200
|
-
* never hand-written — D14 — and an exporter is not one of those).
|
|
52201
|
-
*/
|
|
52202
|
-
exposesDeviceSettings: true,
|
|
52203
|
-
methods: {
|
|
52204
|
-
getStatus: method(InstancePinSchema, DeviceExportStatusSchema),
|
|
52205
|
-
listInstances: method(_void(), array(ExportInstanceSchema)),
|
|
52206
|
-
listSupportedDeviceKinds: method(InstancePinSchema, array(DeviceKindSchema)),
|
|
52207
|
-
listExposedDevices: method(InstancePinSchema, array(ExposedDeviceSchema)),
|
|
52208
|
-
exposeDevice: method(ExposeInputSchema, _void(), {
|
|
52209
|
-
kind: "mutation",
|
|
52210
|
-
auth: "admin"
|
|
52211
|
-
}),
|
|
52212
|
-
unexposeDevice: method(UnexposeInputSchema, _void(), {
|
|
52213
|
-
kind: "mutation",
|
|
52214
|
-
auth: "admin"
|
|
52215
|
-
}),
|
|
52216
|
-
listSupportedEntityKinds: optionalMethod(_void(), array(ExportEntityKindSchema)),
|
|
52217
|
-
listExposedEntities: optionalMethod(InstancePinSchema, array(ExposedEntitySchema)),
|
|
52218
|
-
exposeEntity: optionalMethod(ExposeEntityInputSchema, _void(), {
|
|
52219
|
-
kind: "mutation",
|
|
52220
|
-
auth: "admin"
|
|
52221
|
-
}),
|
|
52222
|
-
unexposeEntity: optionalMethod(UnexposeEntityInputSchema, _void(), {
|
|
52223
|
-
kind: "mutation",
|
|
52224
|
-
auth: "admin"
|
|
52225
|
-
})
|
|
52226
|
-
}
|
|
52227
|
-
};
|
|
52228
52942
|
var DeviceAliasSchema = string().max(64).regex(/^[a-z][a-z0-9_]*$/);
|
|
52229
52943
|
var DeviceTemplateSchema = string().min(1).max(4096);
|
|
52230
52944
|
/** One value a caller hands the renderer for `thisDevice`. */
|
|
@@ -55075,29 +55789,6 @@ var EnumSensorStatusSchema = object({
|
|
|
55075
55789
|
lastFetchedAt: number$1()
|
|
55076
55790
|
});
|
|
55077
55791
|
DeviceType.Sensor;
|
|
55078
|
-
/**
|
|
55079
|
-
* Generic stateless event emitter. Installed on a `DeviceType.EventEmitter`
|
|
55080
|
-
* device. Carries the device's EXACT declared event vocabulary verbatim
|
|
55081
|
-
* (NO normalization). Two shapes:
|
|
55082
|
-
* - structured source (HA `event.*` entity) → `eventTypes` is the fixed
|
|
55083
|
-
* declared vocabulary (e.g. ['press_short','press_long',...]).
|
|
55084
|
-
* - generic/legacy source (HA bus events, e.g. zha_event) → `eventTypes`
|
|
55085
|
-
* is [] (open) and `lastEvent.data` carries the complex payload.
|
|
55086
|
-
* `seq` is monotonic so two identical events still produce distinct slice writes.
|
|
55087
|
-
*/
|
|
55088
|
-
var EventFireSchema = object({
|
|
55089
|
-
deviceId: number$1(),
|
|
55090
|
-
eventType: string(),
|
|
55091
|
-
data: record(string(), unknown()).nullable(),
|
|
55092
|
-
timestamp: number$1().meta(readingMeta("none")),
|
|
55093
|
-
seq: number$1().meta(readingMeta("count"))
|
|
55094
|
-
});
|
|
55095
|
-
var EventEmitterStatusSchema = object({
|
|
55096
|
-
eventTypes: array(string()),
|
|
55097
|
-
lastEvent: EventFireSchema.nullable(),
|
|
55098
|
-
eventCountSinceStart: number$1().meta(readingMeta("count"))
|
|
55099
|
-
});
|
|
55100
|
-
DeviceType.EventEmitter;
|
|
55101
55792
|
var IdentitySchema = object({
|
|
55102
55793
|
id: string(),
|
|
55103
55794
|
name: string(),
|
|
@@ -56396,6 +57087,128 @@ var StateLookSchema = object({
|
|
|
56396
57087
|
background: _enum(HERO_BACKGROUNDS),
|
|
56397
57088
|
animation: HeroAnimationSchema
|
|
56398
57089
|
});
|
|
57090
|
+
/** A string in both languages, as the cap vocabulary writes it (D920): no `t()` in the model. */
|
|
57091
|
+
var HeroTextSchema = object({
|
|
57092
|
+
en: string(),
|
|
57093
|
+
it: string()
|
|
57094
|
+
});
|
|
57095
|
+
/**
|
|
57096
|
+
* The ONE measurement a simple sensor shows (card wave, phase 1).
|
|
57097
|
+
*
|
|
57098
|
+
* A sensor that measures a single quantity (a temperature, a humidity, a power,
|
|
57099
|
+
* a contact, a text state) is drawn as that reading, once, big, inside a scene
|
|
57100
|
+
* whose motion says what the number means: heat rising when hot, flakes when
|
|
57101
|
+
* cold, a wire flowing at the speed of the power, a ring while a window is
|
|
57102
|
+
* open. Everything the card draws is decided here; a client only paints it.
|
|
57103
|
+
*/
|
|
57104
|
+
var HERO_MEASUREMENT_QUANTITIES = [
|
|
57105
|
+
"temperature",
|
|
57106
|
+
"humidity",
|
|
57107
|
+
"power",
|
|
57108
|
+
"contact",
|
|
57109
|
+
"text"
|
|
57110
|
+
];
|
|
57111
|
+
/** How a temperature reads to a person; drives the heat or the cold scene. */
|
|
57112
|
+
var HERO_MEASUREMENT_BANDS = [
|
|
57113
|
+
"hot",
|
|
57114
|
+
"mild",
|
|
57115
|
+
"cold"
|
|
57116
|
+
];
|
|
57117
|
+
/** `updated` = the value was last read then ("2 min ago"); `changed` = it has held since then ("for 12 min"). */
|
|
57118
|
+
var HERO_MEASUREMENT_SINCE_KINDS = ["updated", "changed"];
|
|
57119
|
+
var HeroMeasurementReadingSchema = object({
|
|
57120
|
+
value: number$1(),
|
|
57121
|
+
quantity: ReadingQuantitySchema
|
|
57122
|
+
});
|
|
57123
|
+
var HeroMeasurementSchema = object({
|
|
57124
|
+
quantity: _enum(HERO_MEASUREMENT_QUANTITIES),
|
|
57125
|
+
reading: HeroMeasurementReadingSchema.nullable(),
|
|
57126
|
+
icon: IconKeySchema.nullable(),
|
|
57127
|
+
value: HeroTextSchema,
|
|
57128
|
+
unit: string().nullable(),
|
|
57129
|
+
band: _enum(HERO_MEASUREMENT_BANDS).nullable(),
|
|
57130
|
+
level: number$1().min(0).max(1).nullable(),
|
|
57131
|
+
word: HeroTextSchema,
|
|
57132
|
+
tone: _enum(HERO_TONES),
|
|
57133
|
+
since: number$1().nullable(),
|
|
57134
|
+
sinceKind: _enum(HERO_MEASUREMENT_SINCE_KINDS),
|
|
57135
|
+
historyKey: string().nullable()
|
|
57136
|
+
});
|
|
57137
|
+
var same$2 = (text) => t(text, text);
|
|
57138
|
+
var clamp01$1 = (n) => Math.min(1, Math.max(0, n));
|
|
57139
|
+
var trimmed = (n, digits) => String(Number(n.toFixed(digits)));
|
|
57140
|
+
function temperatureBand(celsius) {
|
|
57141
|
+
if (celsius < 12) return "cold";
|
|
57142
|
+
if (celsius > 28) return "hot";
|
|
57143
|
+
return "mild";
|
|
57144
|
+
}
|
|
57145
|
+
var BAND_WORD = {
|
|
57146
|
+
hot: t("Hot", "Caldo"),
|
|
57147
|
+
mild: t("Normal", "Normale"),
|
|
57148
|
+
cold: t("Cold", "Freddo")
|
|
57149
|
+
};
|
|
57150
|
+
var BAND_TONE = {
|
|
57151
|
+
hot: "warning",
|
|
57152
|
+
mild: "muted",
|
|
57153
|
+
cold: "info"
|
|
57154
|
+
};
|
|
57155
|
+
function temperatureMeasurement(celsius, since) {
|
|
57156
|
+
const band = temperatureBand(celsius);
|
|
57157
|
+
return {
|
|
57158
|
+
quantity: "temperature",
|
|
57159
|
+
reading: {
|
|
57160
|
+
value: celsius,
|
|
57161
|
+
quantity: "temperature"
|
|
57162
|
+
},
|
|
57163
|
+
icon: "thermometer",
|
|
57164
|
+
value: same$2(trimmed(celsius, 1)),
|
|
57165
|
+
unit: "°C",
|
|
57166
|
+
band,
|
|
57167
|
+
level: null,
|
|
57168
|
+
word: BAND_WORD[band],
|
|
57169
|
+
tone: BAND_TONE[band],
|
|
57170
|
+
since,
|
|
57171
|
+
sinceKind: "updated",
|
|
57172
|
+
historyKey: "cap:temperature-sensor.temperature"
|
|
57173
|
+
};
|
|
57174
|
+
}
|
|
57175
|
+
function humidityMeasurement(percent, since) {
|
|
57176
|
+
const dry = percent < 30;
|
|
57177
|
+
const humid = percent > 70;
|
|
57178
|
+
return {
|
|
57179
|
+
quantity: "humidity",
|
|
57180
|
+
reading: {
|
|
57181
|
+
value: percent,
|
|
57182
|
+
quantity: "humidity"
|
|
57183
|
+
},
|
|
57184
|
+
icon: "droplets",
|
|
57185
|
+
value: same$2(String(Math.round(percent))),
|
|
57186
|
+
unit: "%",
|
|
57187
|
+
band: null,
|
|
57188
|
+
level: clamp01$1(percent / 100),
|
|
57189
|
+
word: dry ? t("Dry", "Secco") : humid ? t("Humid", "Umido") : t("Normal", "Normale"),
|
|
57190
|
+
tone: dry || humid ? "warning" : "info",
|
|
57191
|
+
since,
|
|
57192
|
+
sinceKind: "updated",
|
|
57193
|
+
historyKey: "cap:humidity-sensor.humidity"
|
|
57194
|
+
};
|
|
57195
|
+
}
|
|
57196
|
+
function textMeasurement(text, since) {
|
|
57197
|
+
return {
|
|
57198
|
+
quantity: "text",
|
|
57199
|
+
reading: null,
|
|
57200
|
+
icon: null,
|
|
57201
|
+
value: same$2(text),
|
|
57202
|
+
unit: null,
|
|
57203
|
+
band: null,
|
|
57204
|
+
level: null,
|
|
57205
|
+
word: t("Changed", "Cambiato"),
|
|
57206
|
+
tone: "muted",
|
|
57207
|
+
since,
|
|
57208
|
+
sinceKind: "updated",
|
|
57209
|
+
historyKey: null
|
|
57210
|
+
};
|
|
57211
|
+
}
|
|
56399
57212
|
/** The scene as the model carries it. `null` = the device did not say (never a guess). */
|
|
56400
57213
|
var HeroSceneSchema = object({
|
|
56401
57214
|
id: _enum([
|
|
@@ -56447,11 +57260,6 @@ var HeroSceneSchema = object({
|
|
|
56447
57260
|
});
|
|
56448
57261
|
DeviceType.Camera, DeviceType.Hub, DeviceType.Light, DeviceType.Siren, DeviceType.Switch, DeviceType.Sensor, DeviceType.Climate, DeviceType.Button, DeviceType.EventEmitter, DeviceType.Update, DeviceType.Generic, DeviceType.Notifier, DeviceType.Script, DeviceType.Automation, DeviceType.Lock, DeviceType.Cover, DeviceType.Valve, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.HeatPump, DeviceType.Fan, DeviceType.MediaPlayer, DeviceType.AlarmPanel, DeviceType.Control, DeviceType.Presence, DeviceType.Weather, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.Container, DeviceType.Image, DeviceType.PetFeeder, DeviceType.PetFountain, DeviceType.Dishwasher, DeviceType.Washer, DeviceType.Dryer, DeviceType.Gateway;
|
|
56449
57262
|
DeviceRole.Siren, DeviceRole.Floodlight, DeviceRole.Spotlight, DeviceRole.PirSensor, DeviceRole.Chime, DeviceRole.Autotrack, DeviceRole.Nightvision, DeviceRole.PrivacyMask, DeviceRole.Doorbell, DeviceRole.CoverBlind, DeviceRole.CoverShutter, DeviceRole.CoverAwning, DeviceRole.CoverCurtain, DeviceRole.CoverGarage, DeviceRole.CoverGate, DeviceRole.CoverDoor, DeviceRole.CoverWindow, DeviceRole.BinaryHelper, DeviceRole.Outlet, DeviceRole.SwitchHeater, DeviceRole.SwitchFan, DeviceRole.ClimateAc, DeviceRole.ClimateThermostat, DeviceRole.ClimateFloor, DeviceRole.ClimateRadiator, DeviceRole.ClimateHeater, DeviceRole.ClimateHeatPumpCircuit, DeviceRole.MotionSensor, DeviceRole.ContactSensor, DeviceRole.LeakSensor, DeviceRole.SmokeSensor, DeviceRole.COSensor, DeviceRole.GasSensor, DeviceRole.TamperSensor, DeviceRole.VibrationSensor, DeviceRole.ConnectivitySensor, DeviceRole.SoundSensor, DeviceRole.BinarySensor, DeviceRole.TemperatureSensor, DeviceRole.HumiditySensor, DeviceRole.AmbientLightSensor, DeviceRole.PressureSensor, DeviceRole.WindSensor, DeviceRole.RainSensor, DeviceRole.UvSensor, DeviceRole.SolarRadiationSensor, DeviceRole.SoilMoistureSensor, DeviceRole.PowerSensor, DeviceRole.EnergySensor, DeviceRole.VoltageSensor, DeviceRole.CurrentSensor, DeviceRole.AirQualitySensor, DeviceRole.BatterySensor, DeviceRole.NumericSensor, DeviceRole.EnumSensor, DeviceRole.DateTimeSensor, DeviceRole.GenericSensor, DeviceRole.NumericControl, DeviceRole.SelectControl, DeviceRole.TextControl, DeviceRole.DateTimeControl, DeviceRole.MobilePushNotifier, DeviceRole.MessagingNotifier, DeviceRole.EmailNotifier, DeviceRole.GenericNotifier, DeviceRole.IrTransmitter;
|
|
56450
|
-
/** A string in both languages, as the cap vocabulary writes it (D920): no `t()` in the model. */
|
|
56451
|
-
var HeroTextSchema = object({
|
|
56452
|
-
en: string(),
|
|
56453
|
-
it: string()
|
|
56454
|
-
});
|
|
56455
57263
|
var HeroRowIdSchema = _enum([
|
|
56456
57264
|
"progress",
|
|
56457
57265
|
"run-for",
|
|
@@ -56557,6 +57365,25 @@ var HeroControlSchema = discriminatedUnion("kind", [
|
|
|
56557
57365
|
optionLabels: record(string(), HeroTextSchema).optional(),
|
|
56558
57366
|
call: HeroCallSchema,
|
|
56559
57367
|
valueArg: string()
|
|
57368
|
+
}),
|
|
57369
|
+
object({
|
|
57370
|
+
kind: literal("number"),
|
|
57371
|
+
id: string(),
|
|
57372
|
+
label: HeroTextSchema,
|
|
57373
|
+
value: number$1().nullable(),
|
|
57374
|
+
/** `null` = any number; the device rounds what it does not accept. */
|
|
57375
|
+
step: number$1().nullable(),
|
|
57376
|
+
unit: string(),
|
|
57377
|
+
call: HeroCallSchema,
|
|
57378
|
+
valueArg: string()
|
|
57379
|
+
}),
|
|
57380
|
+
object({
|
|
57381
|
+
kind: literal("text"),
|
|
57382
|
+
id: string(),
|
|
57383
|
+
label: HeroTextSchema,
|
|
57384
|
+
value: string().nullable(),
|
|
57385
|
+
call: HeroCallSchema,
|
|
57386
|
+
valueArg: string()
|
|
56560
57387
|
})
|
|
56561
57388
|
]);
|
|
56562
57389
|
/** Declared by its interface: a `z.infer` of one more icon union pushes the cap's inferred type past what the compiler can print. */
|
|
@@ -56758,6 +57585,11 @@ var HeroModelSchema = object({
|
|
|
56758
57585
|
timedRun: HeroTimedRunSlotSchema.nullable(),
|
|
56759
57586
|
powerSupply: HeroPowerSupplySlotSchema.nullable(),
|
|
56760
57587
|
rows: array(HeroRowSchema),
|
|
57588
|
+
/**
|
|
57589
|
+
* The ONE measurement of a simple sensor, drawn once inside the scene in place of
|
|
57590
|
+
* the caption, tiles and value chips. Absent = the card draws as before.
|
|
57591
|
+
*/
|
|
57592
|
+
measurement: HeroMeasurementSchema.optional(),
|
|
56761
57593
|
/** Ids of parts that actuate the device, hidden from a session that may not act on it. */
|
|
56762
57594
|
gated: array(string()),
|
|
56763
57595
|
provenance: array(HeroProvenanceSchema)
|
|
@@ -56829,8 +57661,23 @@ var HeroRowModelSchema = object({
|
|
|
56829
57661
|
* the call. Absent or empty = `primary` alone.
|
|
56830
57662
|
*/
|
|
56831
57663
|
extras: array(HeroControlSchema).max(2).optional(),
|
|
56832
|
-
trailing: HeroFactSchema.nullable()
|
|
57664
|
+
trailing: HeroFactSchema.nullable(),
|
|
57665
|
+
/**
|
|
57666
|
+
* The simple sensor's one reading (the hero's `measurement`): the row draws its value
|
|
57667
|
+
* at the right, the unit small, the quantity's icon in the mini-scene. Absent = an
|
|
57668
|
+
* older server or a device that is not a simple sensor: draw `trailing`.
|
|
57669
|
+
*/
|
|
57670
|
+
measurement: HeroMeasurementSchema.optional()
|
|
56833
57671
|
});
|
|
57672
|
+
new Set([
|
|
57673
|
+
"temperature",
|
|
57674
|
+
"humidity",
|
|
57675
|
+
"pressure",
|
|
57676
|
+
"illuminance",
|
|
57677
|
+
"reading",
|
|
57678
|
+
"air-quality",
|
|
57679
|
+
"valve"
|
|
57680
|
+
]);
|
|
56834
57681
|
DeviceType.Climate;
|
|
56835
57682
|
DeviceType.Climate, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.MediaPlayer;
|
|
56836
57683
|
/**
|
|
@@ -57147,6 +57994,12 @@ var IntegrationLiteSchema = object({
|
|
|
57147
57994
|
var AvailableIntegrationTypeSchema = object({
|
|
57148
57995
|
addonId: string(),
|
|
57149
57996
|
name: string(),
|
|
57997
|
+
/**
|
|
57998
|
+
* Product name a new integration is prefilled from (`<label> - Home`).
|
|
57999
|
+
* Absent: the client uses `name`. Set when the catalog title is not the
|
|
58000
|
+
* product (Bosch SHC, MQTT).
|
|
58001
|
+
*/
|
|
58002
|
+
providerLabel: string().optional(),
|
|
57150
58003
|
description: string(),
|
|
57151
58004
|
iconUrl: string().nullable(),
|
|
57152
58005
|
color: string(),
|
|
@@ -57658,13 +58511,32 @@ var IrSendResultSchema = object({
|
|
|
57658
58511
|
var IrTransmitterInfoSchema = object({
|
|
57659
58512
|
media: array(IrMediumSchema),
|
|
57660
58513
|
settable: array(TransmitSettingKeySchema),
|
|
57661
|
-
maxTimings: number$1().int().positive()
|
|
58514
|
+
maxTimings: number$1().int().positive(),
|
|
58515
|
+
/** The transmitter can learn a code (`learn`). */
|
|
58516
|
+
learn: boolean().default(false),
|
|
58517
|
+
/** Native code formats the transmitter replays verbatim (`send.native`). */
|
|
58518
|
+
formats: array(IrNativeFormatSchema).default([])
|
|
58519
|
+
});
|
|
58520
|
+
var IR_LEARN_TIMEOUT_DEFAULT_MS = 2e4;
|
|
58521
|
+
var IR_LEARN_TIMEOUT_MAX_MS = 6e4;
|
|
58522
|
+
var IrLearnResultSchema = object({
|
|
58523
|
+
/** The code in the device's own format, when it reports one. */
|
|
58524
|
+
native: IrNativeCodeSchema.nullable(),
|
|
58525
|
+
timings: IrTimingsSchema,
|
|
58526
|
+
carrierHz: number$1().int().positive().nullable()
|
|
57662
58527
|
});
|
|
57663
58528
|
DeviceType.Generic, method(object({
|
|
57664
58529
|
deviceId: number$1().int().nonnegative(),
|
|
57665
|
-
timings: IrTimingsSchema,
|
|
58530
|
+
timings: IrTimingsSchema.optional(),
|
|
58531
|
+
native: IrNativeCodeSchema.optional(),
|
|
57666
58532
|
settings: TransmitSettingsSchema.optional()
|
|
57667
|
-
}), IrSendResultSchema, {
|
|
58533
|
+
}).refine((input) => input.timings === void 0 !== (input.native === void 0), { message: "send takes exactly one of timings or native" }), IrSendResultSchema, {
|
|
58534
|
+
kind: "mutation",
|
|
58535
|
+
auth: "protected"
|
|
58536
|
+
}), method(object({
|
|
58537
|
+
deviceId: number$1().int().nonnegative(),
|
|
58538
|
+
timeoutMs: number$1().int().positive().max(IR_LEARN_TIMEOUT_MAX_MS).default(IR_LEARN_TIMEOUT_DEFAULT_MS)
|
|
58539
|
+
}), IrLearnResultSchema, {
|
|
57668
58540
|
kind: "mutation",
|
|
57669
58541
|
auth: "protected"
|
|
57670
58542
|
}), method(object({ deviceId: number$1().int().nonnegative() }), IrTransmitterInfoSchema, {
|
|
@@ -66887,6 +67759,7 @@ var NcSystemEventKindSchema = _enum([
|
|
|
66887
67759
|
"recording-degraded",
|
|
66888
67760
|
"device-attention-required",
|
|
66889
67761
|
"device-attention-resolved",
|
|
67762
|
+
"device-command",
|
|
66890
67763
|
"storage-location-low",
|
|
66891
67764
|
"storage-location-critical",
|
|
66892
67765
|
"storage-location-ok",
|
|
@@ -66949,11 +67822,6 @@ var NC_ALARM_SYSTEM_EVENT_KINDS = [
|
|
|
66949
67822
|
"alarm-sensor-bypass",
|
|
66950
67823
|
"alarm-disarmed"
|
|
66951
67824
|
];
|
|
66952
|
-
/**
|
|
66953
|
-
* One coherent system-event condition. `kinds` is the required opt-in safety
|
|
66954
|
-
* gate; the remaining lists are optional narrowing filters relevant to the
|
|
66955
|
-
* selected kinds.
|
|
66956
|
-
*/
|
|
66957
67825
|
var NcSystemEventConditionSchema = object({
|
|
66958
67826
|
kinds: array(NcSystemEventKindSchema).min(1),
|
|
66959
67827
|
deviceIds: array(number$1().int()).min(1).optional(),
|
|
@@ -66985,6 +67853,28 @@ var NcSystemEventConditionSchema = object({
|
|
|
66985
67853
|
nodeIds: array(string().min(1)).min(1).optional(),
|
|
66986
67854
|
packageNames: array(string().min(1)).min(1).optional(),
|
|
66987
67855
|
/**
|
|
67856
|
+
* `device-command` only: the vocabulary ACTION IDS (D983, `powerSource.forceRestart`)
|
|
67857
|
+
* this rule speaks about - the same dictionary the automation action blocks
|
|
67858
|
+
* pick from. The hub refuses an id the action index does not know.
|
|
67859
|
+
*/
|
|
67860
|
+
commandActions: array(string().min(1)).min(1).optional(),
|
|
67861
|
+
/** `device-command` only: how the command settled. A device's own change is not a command. */
|
|
67862
|
+
commandOutcomes: array(_enum([
|
|
67863
|
+
"confirmed",
|
|
67864
|
+
"already",
|
|
67865
|
+
"unconfirmed",
|
|
67866
|
+
"failed"
|
|
67867
|
+
])).min(1).optional(),
|
|
67868
|
+
/** `device-command` only: who asked (`user`, `addon`, `action`, `scheduler`, `composition`, `node`). */
|
|
67869
|
+
commandActorKinds: array(_enum([
|
|
67870
|
+
"user",
|
|
67871
|
+
"addon",
|
|
67872
|
+
"action",
|
|
67873
|
+
"scheduler",
|
|
67874
|
+
"composition",
|
|
67875
|
+
"node"
|
|
67876
|
+
])).min(1).optional(),
|
|
67877
|
+
/**
|
|
66988
67878
|
* At or below this remaining-life %, a consumable is LOW for THIS rule
|
|
66989
67879
|
* (D642). Absent = {@link NC_CONSUMABLE_LOW_PERCENT_DEFAULT}; at most
|
|
66990
67880
|
* {@link NC_CONSUMABLE_LOW_PERCENT_MAX}, so every episode can recover. Scoped to the
|
|
@@ -67965,6 +68855,13 @@ var NcRuleInputSchema = object({
|
|
|
67965
68855
|
*/
|
|
67966
68856
|
groupingSec: number$1().int().min(5).max(60).optional(),
|
|
67967
68857
|
/**
|
|
68858
|
+
* Hold deliveries of this rule to one target and, when two or more arrive
|
|
68859
|
+
* before the window ends, send them as one summary. Absent = the kind's
|
|
68860
|
+
* default (`groupWithinSecOf`): 5 s for a system-event rule, 0 for every
|
|
68861
|
+
* other kind. `0` sends each delivery as it does today.
|
|
68862
|
+
*/
|
|
68863
|
+
groupWithinSec: number$1().int().min(0).max(300).optional(),
|
|
68864
|
+
/**
|
|
67968
68865
|
* ASK ME TO CONFIRM DETECTIONS (#243): a DETECTION notification of this rule
|
|
67969
68866
|
* carries "Correct" / "Wrong" buttons (and, where the channel has room, a
|
|
67970
68867
|
* "Wrong, it is a <class>" choice). A tap marks the track for retraining, the
|
|
@@ -68401,7 +69298,12 @@ var NcHistoryEntrySchema = object({
|
|
|
68401
69298
|
* Assistant export) must render as "no image right now", never as a
|
|
68402
69299
|
* broken link.
|
|
68403
69300
|
*/
|
|
68404
|
-
artifactIds: array(string().min(1)).optional()
|
|
69301
|
+
artifactIds: array(string().min(1)).optional(),
|
|
69302
|
+
/**
|
|
69303
|
+
* When this row was folded into a group-window summary, the outbox id of
|
|
69304
|
+
* that one notification. Absent on a row that was sent as itself.
|
|
69305
|
+
*/
|
|
69306
|
+
groupedInto: string().min(1).optional()
|
|
68405
69307
|
});
|
|
68406
69308
|
/**
|
|
68407
69309
|
* Query filter for `getHistory` (spec §4.2). Every field is a narrowing
|
|
@@ -69288,7 +70190,18 @@ var OauthIntegrationDescriptorSchema = object({
|
|
|
69288
70190
|
* The value is baked into the authorization code at `/authorize` and travels
|
|
69289
70191
|
* on the tokens, so editing this field changes FUTURE links only.
|
|
69290
70192
|
*/
|
|
69291
|
-
refreshTokenTtlSec: union([number$1().int().positive(), literal("never")]).optional()
|
|
70193
|
+
refreshTokenTtlSec: union([number$1().int().positive(), literal("never")]).optional(),
|
|
70194
|
+
/**
|
|
70195
|
+
* The integration instances an account can be linked to (planning#415),
|
|
70196
|
+
* beside the default one. `/api/oauth2/authorize?instance=<id>` is accepted
|
|
70197
|
+
* only for an id listed here; with no `instance=` the link is made to the
|
|
70198
|
+
* default instance, which is never listed and always accepted — it is the
|
|
70199
|
+
* address third parties already hold. Omit for a single-instance integration.
|
|
70200
|
+
*/
|
|
70201
|
+
instances: array(object({
|
|
70202
|
+
id: string(),
|
|
70203
|
+
displayName: string()
|
|
70204
|
+
})).optional()
|
|
69292
70205
|
});
|
|
69293
70206
|
var oauthIntegrationCapability = {
|
|
69294
70207
|
name: "oauth-integration",
|
|
@@ -73853,10 +74766,15 @@ var RecordingSignalStatusSchema = object({
|
|
|
73853
74766
|
});
|
|
73854
74767
|
RecordingSignalStatusSchema.extend({ lastFetchedAt: number$1() });
|
|
73855
74768
|
DeviceType.Camera, method(object({ deviceId: number$1() }), RecordingSignalStatusSchema);
|
|
73856
|
-
var RemoteBindingSchema = object({ action:
|
|
73857
|
-
|
|
73858
|
-
|
|
73859
|
-
|
|
74769
|
+
var RemoteBindingSchema = object({ action: object({
|
|
74770
|
+
kind: literal("cap"),
|
|
74771
|
+
deviceId: number$1().int().nonnegative(),
|
|
74772
|
+
cap: string().min(1),
|
|
74773
|
+
method: string().min(1),
|
|
74774
|
+
args: record(string(), unknown()).optional(),
|
|
74775
|
+
/** The unit the person picked per arg (display only); `args` always hold the cap's own unit. */
|
|
74776
|
+
argUnits: record(string(), string().min(1)).optional()
|
|
74777
|
+
}) });
|
|
73860
74778
|
var RemoteCustomButtonSchema = object({
|
|
73861
74779
|
/** The slug after `custom:` in the role. */
|
|
73862
74780
|
key: string().refine(isRemoteCustomKey, { message: "a lowercase slug" }),
|
|
@@ -75433,6 +76351,13 @@ var SsoBridgeClaimsSchema = object({
|
|
|
75433
76351
|
/** OAuth authorization-code binding — set only on `oauth-code` tokens. */
|
|
75434
76352
|
redirectUri: string().optional(),
|
|
75435
76353
|
integrationId: string().optional(),
|
|
76354
|
+
/**
|
|
76355
|
+
* The integration INSTANCE an OAuth link was made for (planning#415). Set on
|
|
76356
|
+
* `oauth-code`, `oauth-access` and `oauth-refresh` tokens of a link made
|
|
76357
|
+
* with `instance=`; absent on a link to the default instance. A cloud relay
|
|
76358
|
+
* reads it off the access token to route; the hub answers from the session.
|
|
76359
|
+
*/
|
|
76360
|
+
instanceId: string().optional(),
|
|
75436
76361
|
/** JWT ID — unique per issued code; consumed-set enforces single-use. */
|
|
75437
76362
|
jti: string().optional(),
|
|
75438
76363
|
/** PKCE S256 challenge — set only on `oauth-code` tokens issued to a public
|
|
@@ -77521,6 +78446,8 @@ var OauthSessionSummarySchema = object({
|
|
|
77521
78446
|
userId: string(),
|
|
77522
78447
|
username: string(),
|
|
77523
78448
|
integrationId: string(),
|
|
78449
|
+
/** The instance the link was made for; `null` = the default instance. */
|
|
78450
|
+
instanceId: string().nullable().optional(),
|
|
77524
78451
|
scopes: array(TokenScopeSchema),
|
|
77525
78452
|
createdAt: number$1(),
|
|
77526
78453
|
lastUsedAt: number$1(),
|
|
@@ -77620,6 +78547,9 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(_void(), ob
|
|
|
77620
78547
|
access: "view"
|
|
77621
78548
|
}), method(object({
|
|
77622
78549
|
integrationId: string(),
|
|
78550
|
+
/** The integration instance the link is for. Omit for the default
|
|
78551
|
+
* instance — never pass the addon id to mean it. */
|
|
78552
|
+
instanceId: string().optional(),
|
|
77623
78553
|
userId: string(),
|
|
77624
78554
|
username: string(),
|
|
77625
78555
|
scopes: array(TokenScopeSchema),
|
|
@@ -77658,7 +78588,13 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(_void(), ob
|
|
|
77658
78588
|
}), method(object({ token: string() }), object({
|
|
77659
78589
|
userId: string(),
|
|
77660
78590
|
username: string(),
|
|
77661
|
-
scopes: array(TokenScopeSchema)
|
|
78591
|
+
scopes: array(TokenScopeSchema),
|
|
78592
|
+
/** The instance the link was made for, read from the SESSION.
|
|
78593
|
+
* Absent = the default instance. `oauthLinkServesInstance` is the
|
|
78594
|
+
* helper a per-instance route calls to compare it with the instance
|
|
78595
|
+
* of its path; no route declares `perInstance` yet (the Alexa
|
|
78596
|
+
* per-instance route, T3, is the first consumer). */
|
|
78597
|
+
instanceId: string().optional()
|
|
77662
78598
|
}).nullable(), { access: "view" }), method(object({ userId: string() }), array(ExternalIdentitySchema), { auth: "admin" }), method(ExternalIdentityKeySchema, object({
|
|
77663
78599
|
userId: string(),
|
|
77664
78600
|
issuer: string()
|
|
@@ -79272,6 +80208,13 @@ function contribution(cap, schema, build) {
|
|
|
79272
80208
|
}
|
|
79273
80209
|
};
|
|
79274
80210
|
}
|
|
80211
|
+
/** The fragment, carrying the cap's single measurement when it has one. */
|
|
80212
|
+
function measured(fragment, measurement) {
|
|
80213
|
+
return measurement === void 0 ? fragment : {
|
|
80214
|
+
...fragment,
|
|
80215
|
+
measurement
|
|
80216
|
+
};
|
|
80217
|
+
}
|
|
79275
80218
|
function action(id, label, icon, cap, method, args = {}, emphasis = "normal", confirm = null) {
|
|
79276
80219
|
return {
|
|
79277
80220
|
id,
|
|
@@ -80546,10 +81489,26 @@ var controlContribution = contribution("control", ControlStatusSchema, (slice, c
|
|
|
80546
81489
|
};
|
|
80547
81490
|
});
|
|
80548
81491
|
var CONTROL_LABEL = t("Value", "Valore");
|
|
80549
|
-
/**
|
|
81492
|
+
/**
|
|
81493
|
+
* A number with known bounds is a slider, one without a number field, a choice a picker,
|
|
81494
|
+
* free text a text field; a date stays read-only.
|
|
81495
|
+
*/
|
|
80550
81496
|
function controlRows(slice) {
|
|
80551
81497
|
if (slice.kind === "numeric" && typeof slice.value === "number") {
|
|
80552
|
-
if (slice.min === void 0 || slice.max === void 0) return [
|
|
81498
|
+
if (slice.min === void 0 || slice.max === void 0) return [row$1("control", "sliders-horizontal", null, [{
|
|
81499
|
+
kind: "number",
|
|
81500
|
+
id: "control.value",
|
|
81501
|
+
label: CONTROL_LABEL,
|
|
81502
|
+
value: slice.value,
|
|
81503
|
+
step: slice.step ?? null,
|
|
81504
|
+
unit: "",
|
|
81505
|
+
call: {
|
|
81506
|
+
cap: "control",
|
|
81507
|
+
method: "setValue",
|
|
81508
|
+
args: { control: { kind: "numeric" } }
|
|
81509
|
+
},
|
|
81510
|
+
valueArg: "control.value"
|
|
81511
|
+
}])];
|
|
80553
81512
|
return [row$1("control", "sliders-horizontal", null, [{
|
|
80554
81513
|
kind: "slider",
|
|
80555
81514
|
id: "control.value",
|
|
@@ -80580,6 +81539,18 @@ function controlRows(slice) {
|
|
|
80580
81539
|
},
|
|
80581
81540
|
valueArg: "control.value"
|
|
80582
81541
|
}])];
|
|
81542
|
+
if (slice.kind === "text") return [row$1("control", "sliders-horizontal", null, [{
|
|
81543
|
+
kind: "text",
|
|
81544
|
+
id: "control.value",
|
|
81545
|
+
label: CONTROL_LABEL,
|
|
81546
|
+
value: typeof slice.value === "string" ? slice.value : null,
|
|
81547
|
+
call: {
|
|
81548
|
+
cap: "control",
|
|
81549
|
+
method: "setValue",
|
|
81550
|
+
args: { control: { kind: "text" } }
|
|
81551
|
+
},
|
|
81552
|
+
valueArg: "control.value"
|
|
81553
|
+
}])];
|
|
80583
81554
|
return [];
|
|
80584
81555
|
}
|
|
80585
81556
|
var SENSORS_FAMILY_CONTRIBUTIONS = {
|
|
@@ -80935,15 +81906,15 @@ function sensorFragment(value, id, icon, en, it, text) {
|
|
|
80935
81906
|
tiles: { right: [tile$1(en, it, text)] }
|
|
80936
81907
|
};
|
|
80937
81908
|
}
|
|
80938
|
-
var temperatureContribution = contribution("temperature-sensor", TemperatureSensorStatusSchema, (slice) => sensorFragment(slice?.temperature ?? null, "temperature", "thermometer", "Temperature", "Temperatura", formatDegrees(slice?.temperature ?? 0)));
|
|
80939
|
-
var humidityContribution = contribution("humidity-sensor", HumiditySensorStatusSchema, (slice) => sensorFragment(slice?.humidity ?? null, "humidity", "droplets", "Humidity", "Umidità", `${Math.round(slice?.humidity ?? 0)}%`));
|
|
81909
|
+
var temperatureContribution = contribution("temperature-sensor", TemperatureSensorStatusSchema, (slice) => measured(sensorFragment(slice?.temperature ?? null, "temperature", "thermometer", "Temperature", "Temperatura", formatDegrees(slice?.temperature ?? 0)), slice?.temperature == null ? void 0 : temperatureMeasurement(slice.temperature, slice.lastFetchedAt)));
|
|
81910
|
+
var humidityContribution = contribution("humidity-sensor", HumiditySensorStatusSchema, (slice) => measured(sensorFragment(slice?.humidity ?? null, "humidity", "droplets", "Humidity", "Umidità", `${Math.round(slice?.humidity ?? 0)}%`), slice?.humidity == null ? void 0 : humidityMeasurement(slice.humidity, slice.lastFetchedAt)));
|
|
80940
81911
|
var pressureContribution = contribution("pressure-sensor", PressureSensorStatusSchema, (slice) => sensorFragment(slice?.pressure ?? null, "pressure", "gauge", "Pressure", "Pressione", `${Math.round(slice?.pressure ?? 0)} hPa`));
|
|
80941
81912
|
var illuminanceContribution = contribution("ambient-light-sensor", AmbientLightSensorStatusSchema, (slice) => sensorFragment(slice?.illuminance ?? null, "illuminance", "sun", "Light", "Luce", `${Math.round(slice?.illuminance ?? 0)} lx`));
|
|
80942
81913
|
var numericContribution = contribution("numeric-sensor", NumericSensorStatusSchema, (slice) => sensorFragment(slice?.value ?? null, "reading", "gauge", "Value", "Valore", String(Number((slice?.value ?? 0).toFixed(2)))));
|
|
80943
81914
|
var enumContribution = contribution("enum-sensor", EnumSensorStatusSchema, (slice) => {
|
|
80944
81915
|
if (slice === void 0 || slice.value === "") return { reading: reading("sensor", "unknown") };
|
|
80945
81916
|
if (slice.timestamp === true) return { reading: reading("sensor", "on") };
|
|
80946
|
-
return sensorFragment(slice.value, "reading", "gauge", "State", "Stato", slice.value);
|
|
81917
|
+
return measured(sensorFragment(slice.value, "reading", "gauge", "State", "Stato", slice.value), textMeasurement(slice.value, slice.lastFetchedAt));
|
|
80947
81918
|
});
|
|
80948
81919
|
/** Index bands: the headline of an air-quality sensor is a word, not a number. */
|
|
80949
81920
|
function airQualityWord(aqi) {
|
|
@@ -83839,6 +84810,13 @@ Object.freeze({
|
|
|
83839
84810
|
access: "view",
|
|
83840
84811
|
role: "admin"
|
|
83841
84812
|
},
|
|
84813
|
+
"deviceExport.setExposedName": {
|
|
84814
|
+
capName: "device-export",
|
|
84815
|
+
capScope: "system",
|
|
84816
|
+
addonId: null,
|
|
84817
|
+
access: "create",
|
|
84818
|
+
role: "admin"
|
|
84819
|
+
},
|
|
83842
84820
|
"deviceExport.unexposeDevice": {
|
|
83843
84821
|
capName: "device-export",
|
|
83844
84822
|
capScope: "system",
|
|
@@ -85778,6 +86756,13 @@ Object.freeze({
|
|
|
85778
86756
|
access: "view",
|
|
85779
86757
|
role: "viewer"
|
|
85780
86758
|
},
|
|
86759
|
+
"irTransmitter.learn": {
|
|
86760
|
+
capName: "ir-transmitter",
|
|
86761
|
+
capScope: "device",
|
|
86762
|
+
addonId: null,
|
|
86763
|
+
access: "create",
|
|
86764
|
+
role: "viewer"
|
|
86765
|
+
},
|
|
85781
86766
|
"irTransmitter.send": {
|
|
85782
86767
|
capName: "ir-transmitter",
|
|
85783
86768
|
capScope: "device",
|
|
@@ -92296,48 +93281,6 @@ Object.freeze({
|
|
|
92296
93281
|
role: "admin"
|
|
92297
93282
|
}
|
|
92298
93283
|
});
|
|
92299
|
-
/**
|
|
92300
|
-
* "Do" actions an operator can pick for a device — presentation-free.
|
|
92301
|
-
*
|
|
92302
|
-
* The wire shape stays `{ cap, method, args }`. Since D920 this module no
|
|
92303
|
-
* longer HOLDS a catalogue: {@link DEVICE_DO_ACTIONS} is a projection of the
|
|
92304
|
-
* cap vocabulary (`cap-vocabulary/`), the one cap-keyed map of every action
|
|
92305
|
-
* and trigger — so a picker built on this module and one built on
|
|
92306
|
-
* `actionsForDevice` (the vocabulary resolver) can never disagree about what
|
|
92307
|
-
* a device can do. Ids, baked args and the matching of saved steps are the
|
|
92308
|
-
* vocabulary's; labels here are its English labels.
|
|
92309
|
-
*
|
|
92310
|
-
* Shared by the admin NC Sequences / rule Do editor and Automations; the
|
|
92311
|
-
* viewer can reuse the same catalogue once its step editor catches up.
|
|
92312
|
-
*/
|
|
92313
|
-
function openArgKind(offer) {
|
|
92314
|
-
if (offer.kind === "number") return "number";
|
|
92315
|
-
if (offer.kind === "dynamic" && offer.valueKind === "number") return "number";
|
|
92316
|
-
if (offer.kind === "enum" && offer.values.every((v) => typeof v.value === "number")) return "number";
|
|
92317
|
-
return "string";
|
|
92318
|
-
}
|
|
92319
|
-
function projectOpenArg(arg) {
|
|
92320
|
-
return {
|
|
92321
|
-
key: arg.key,
|
|
92322
|
-
label: arg.label.en,
|
|
92323
|
-
kind: openArgKind(arg.offer),
|
|
92324
|
-
offer: arg.offer,
|
|
92325
|
-
...arg.optional === true ? { optional: true } : {}
|
|
92326
|
-
};
|
|
92327
|
-
}
|
|
92328
|
-
function projectAction(cap, action) {
|
|
92329
|
-
const open = action.openArgs ?? [];
|
|
92330
|
-
return {
|
|
92331
|
-
id: action.id,
|
|
92332
|
-
label: action.label.en,
|
|
92333
|
-
cap,
|
|
92334
|
-
method: action.method,
|
|
92335
|
-
args: action.args ?? {},
|
|
92336
|
-
...open.length > 0 ? { openArgs: open.map(projectOpenArg) } : {}
|
|
92337
|
-
};
|
|
92338
|
-
}
|
|
92339
|
-
Object.entries(CAP_VOCABULARY_BY_NAME).flatMap(([cap, entry]) => entry.scope === "device" ? (entry.actions ?? []).map((a) => projectAction(cap, a)) : []);
|
|
92340
|
-
DeviceType.Camera, DeviceType.Hub, DeviceType.Light, DeviceType.Siren, DeviceType.Switch, DeviceType.Sensor, DeviceType.Climate, DeviceType.Button, DeviceType.EventEmitter, DeviceType.Update, DeviceType.Generic, DeviceType.Notifier, DeviceType.Script, DeviceType.Automation, DeviceType.Lock, DeviceType.Cover, DeviceType.Valve, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.HeatPump, DeviceType.Fan, DeviceType.MediaPlayer, DeviceType.AlarmPanel, DeviceType.Control, DeviceType.Presence, DeviceType.Weather, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.Container, DeviceType.Image, DeviceType.PetFeeder, DeviceType.PetFountain, DeviceType.Dishwasher, DeviceType.Washer, DeviceType.Dryer, DeviceType.Gateway;
|
|
92341
93284
|
DeviceFeature.BatteryOperated;
|
|
92342
93285
|
function bound(cap, methods = [], authority = "reported") {
|
|
92343
93286
|
return {
|
|
@@ -93654,6 +94597,11 @@ Object.freeze({
|
|
|
93654
94597
|
form: "single",
|
|
93655
94598
|
optional: false
|
|
93656
94599
|
}],
|
|
94600
|
+
"irTransmitter.learn": [{
|
|
94601
|
+
name: "deviceId",
|
|
94602
|
+
form: "single",
|
|
94603
|
+
optional: false
|
|
94604
|
+
}],
|
|
93657
94605
|
"irTransmitter.send": [{
|
|
93658
94606
|
name: "deviceId",
|
|
93659
94607
|
form: "single",
|
|
@@ -95593,7 +96541,10 @@ var NC_SYSTEM_EVENT_FILTER_KEYS = [
|
|
|
95593
96541
|
"deviceTypes",
|
|
95594
96542
|
"nodeIds",
|
|
95595
96543
|
"packageNames",
|
|
95596
|
-
"consumableLowPercent"
|
|
96544
|
+
"consumableLowPercent",
|
|
96545
|
+
"commandActions",
|
|
96546
|
+
"commandOutcomes",
|
|
96547
|
+
"commandActorKinds"
|
|
95597
96548
|
];
|
|
95598
96549
|
new Map(Object.entries({
|
|
95599
96550
|
"device-online": "device-events",
|
|
@@ -95616,6 +96567,7 @@ new Map(Object.entries({
|
|
|
95616
96567
|
"recording-degraded": "device-events",
|
|
95617
96568
|
"device-attention-required": "device-events",
|
|
95618
96569
|
"device-attention-resolved": "device-events",
|
|
96570
|
+
"device-command": "device-events",
|
|
95619
96571
|
"node-online": "system",
|
|
95620
96572
|
"node-offline": "system",
|
|
95621
96573
|
"node-restarting": "system",
|
|
@@ -95716,6 +96668,12 @@ var NC_SYSTEM_EVENT_KIND_GROUP_SPECS = [
|
|
|
95716
96668
|
label: "Needs attention",
|
|
95717
96669
|
kinds: ["device-attention-required", "device-attention-resolved"]
|
|
95718
96670
|
},
|
|
96671
|
+
{
|
|
96672
|
+
id: "device-command",
|
|
96673
|
+
family: "device-events",
|
|
96674
|
+
label: "Commands given to devices",
|
|
96675
|
+
kinds: ["device-command"]
|
|
96676
|
+
},
|
|
95719
96677
|
{
|
|
95720
96678
|
id: "nodes",
|
|
95721
96679
|
family: "system",
|
|
@@ -95793,6 +96751,15 @@ function systemEventKindsOfFamily(family) {
|
|
|
95793
96751
|
return NC_SYSTEM_EVENT_KIND_GROUP_SPECS.filter((g) => g.family === family).flatMap((g) => g.kinds);
|
|
95794
96752
|
}
|
|
95795
96753
|
NC_AUDIO_DEFAULTS.hitPercent, NC_AUDIO_DEFAULTS.samplingSeconds;
|
|
96754
|
+
new Set([
|
|
96755
|
+
"alarm.trigger",
|
|
96756
|
+
"alarm.disarm",
|
|
96757
|
+
"alarm.arm.home",
|
|
96758
|
+
"alarm.arm.away",
|
|
96759
|
+
"alarm.arm.night",
|
|
96760
|
+
"alarm.arm.vacation",
|
|
96761
|
+
"alarm.arm.custom_bypass"
|
|
96762
|
+
]);
|
|
95796
96763
|
/**
|
|
95797
96764
|
* WHICH WAY A BOOLEAN SENSOR MOVED — read off the one slice a sensor event
|
|
95798
96765
|
* persists (D640 "a sensor rule fires on the raise, the clear, or both").
|
|
@@ -95988,6 +96955,7 @@ var DEVICE_EVENTS = [
|
|
|
95988
96955
|
"recording-healthy",
|
|
95989
96956
|
"recording-degraded",
|
|
95990
96957
|
...DEVICE_ATTENTION,
|
|
96958
|
+
"device-command",
|
|
95991
96959
|
...ALARM
|
|
95992
96960
|
];
|
|
95993
96961
|
/** Every kind a summary may speak about — the two summarisable families. */
|
|
@@ -96141,6 +97109,9 @@ var STATE_SUMMARY_VARS = [
|
|
|
96141
97109
|
[...RULE_BODY_ONLY],
|
|
96142
97110
|
[...RULE_TEXT],
|
|
96143
97111
|
([...RULE_TEXT], [...DEVICE_EVENTS]),
|
|
97112
|
+
[...RULE_TEXT],
|
|
97113
|
+
[...RULE_TEXT],
|
|
97114
|
+
([...RULE_TEXT], [...DEVICE_EVENTS]),
|
|
96144
97115
|
([...RULE_TEXT], [...COMBINED_ALARM]),
|
|
96145
97116
|
([...RULE_TEXT], [...COMBINED_ALARM]),
|
|
96146
97117
|
([...RULE_TEXT], [...DEVICE_EVENTS]),
|
|
@@ -104674,6 +105645,21 @@ async function rotateBrokerCredential(fetchImpl, brokerUrl, credential) {
|
|
|
104674
105645
|
async function revokeBrokerCredential(fetchImpl, brokerUrl, credential) {
|
|
104675
105646
|
await call(fetchImpl, brokerUrl, "/broker/revoke", { bearer: credential }, unknown());
|
|
104676
105647
|
}
|
|
105648
|
+
function judgeTokenInstance(token, skill) {
|
|
105649
|
+
if (token.instanceId !== void 0) return oauthLinkServesInstance({ instanceId: token.instanceId }, skill.id, "export-alexa") ? { kind: "serves" } : {
|
|
105650
|
+
kind: "refused",
|
|
105651
|
+
reason: "token-instance-mismatch"
|
|
105652
|
+
};
|
|
105653
|
+
if (skill.id === "export-alexa") return { kind: "serves" };
|
|
105654
|
+
return skill.hasLinkedUser(token.userId) ? { kind: "serves" } : {
|
|
105655
|
+
kind: "refused",
|
|
105656
|
+
reason: "token-instance-unstated"
|
|
105657
|
+
};
|
|
105658
|
+
}
|
|
105659
|
+
/** The operator-facing sentence for a refusal, sent back to the Lambda and logged. */
|
|
105660
|
+
function describeTokenInstanceRefusal(reason) {
|
|
105661
|
+
return reason === "token-instance-mismatch" ? "the account was linked to another skill instance of this hub" : "the account link names no skill instance and this skill has not linked the account; update the skill Lambda and link again";
|
|
105662
|
+
}
|
|
104677
105663
|
//#endregion
|
|
104678
105664
|
//#region src/handlers/lwa-tokens-callback.ts
|
|
104679
105665
|
/**
|
|
@@ -104698,13 +105684,33 @@ async function revokeBrokerCredential(fetchImpl, brokerUrl, credential) {
|
|
|
104698
105684
|
var OauthVerifiedResultSchema$1 = object({
|
|
104699
105685
|
userId: string(),
|
|
104700
105686
|
username: string(),
|
|
104701
|
-
scopes: array(TokenScopeSchema)
|
|
105687
|
+
scopes: array(TokenScopeSchema),
|
|
105688
|
+
/** The instance the link was made for; absent = the default instance (D1047). */
|
|
105689
|
+
instanceId: string().optional()
|
|
104702
105690
|
}).nullable();
|
|
104703
105691
|
var LwaTokensCallbackBodySchema = object({
|
|
104704
105692
|
lwaAccessToken: string().min(1),
|
|
104705
105693
|
lwaRefreshToken: string().min(1),
|
|
104706
105694
|
expiresAt: number$1().int().nonnegative()
|
|
104707
105695
|
});
|
|
105696
|
+
/**
|
|
105697
|
+
* Refuse (403, logged with the reason) a caller whose token was linked to another instance.
|
|
105698
|
+
* True when the reply was sent; the caller must return.
|
|
105699
|
+
*/
|
|
105700
|
+
function refusedForInstance(caller, reply, deps, label) {
|
|
105701
|
+
const verdict = deps.judgeInstance(caller);
|
|
105702
|
+
if (verdict.kind === "serves") return false;
|
|
105703
|
+
deps.logger.warn(`${label}: refused — ${verdict.reason}`, { meta: {
|
|
105704
|
+
instanceId: deps.instanceId,
|
|
105705
|
+
tokenInstanceId: caller.instanceId ?? null,
|
|
105706
|
+
userId: caller.userId
|
|
105707
|
+
} });
|
|
105708
|
+
reply.code(403).send({
|
|
105709
|
+
error: verdict.reason,
|
|
105710
|
+
message: describeTokenInstanceRefusal(verdict.reason)
|
|
105711
|
+
});
|
|
105712
|
+
return true;
|
|
105713
|
+
}
|
|
104708
105714
|
async function handleLwaTokensCallback(request, reply, deps) {
|
|
104709
105715
|
const parsed = LwaTokensCallbackBodySchema.safeParse(request.body);
|
|
104710
105716
|
if (!parsed.success) {
|
|
@@ -104724,6 +105730,7 @@ async function handleLwaTokensCallback(request, reply, deps) {
|
|
|
104724
105730
|
});
|
|
104725
105731
|
return;
|
|
104726
105732
|
}
|
|
105733
|
+
if (refusedForInstance(caller, reply, deps, "alexa lwa-tokens-callback")) return;
|
|
104727
105734
|
const { userId, username } = caller;
|
|
104728
105735
|
await deps.upsertToken({
|
|
104729
105736
|
userId,
|
|
@@ -104750,10 +105757,14 @@ async function resolveCaller(request, deps) {
|
|
|
104750
105757
|
if (!bearer) return null;
|
|
104751
105758
|
const rawVerified = await deps.ctx.api.userManagement.oauthVerifyAccessToken.query({ token: bearer });
|
|
104752
105759
|
const verifiedParse = OauthVerifiedResultSchema$1.safeParse(rawVerified);
|
|
104753
|
-
if (verifiedParse.success && verifiedParse.data)
|
|
104754
|
-
userId
|
|
104755
|
-
|
|
104756
|
-
|
|
105760
|
+
if (verifiedParse.success && verifiedParse.data) {
|
|
105761
|
+
const { userId, username, instanceId } = verifiedParse.data;
|
|
105762
|
+
return {
|
|
105763
|
+
userId,
|
|
105764
|
+
username,
|
|
105765
|
+
...instanceId !== void 0 ? { instanceId } : {}
|
|
105766
|
+
};
|
|
105767
|
+
}
|
|
104757
105768
|
deps.logger.debug("alexa lwa-tokens-callback: bearer present but did not verify");
|
|
104758
105769
|
return null;
|
|
104759
105770
|
}
|
|
@@ -104826,6 +105837,7 @@ async function handleBrokerLinkCallback(request, reply, deps) {
|
|
|
104826
105837
|
});
|
|
104827
105838
|
return;
|
|
104828
105839
|
}
|
|
105840
|
+
if (refusedForInstance(caller, reply, deps, "alexa broker-link")) return;
|
|
104829
105841
|
await deps.upsertToken({
|
|
104830
105842
|
userId: caller.userId,
|
|
104831
105843
|
accessToken: body.lwaAccessToken,
|
|
@@ -105106,12 +106118,16 @@ async function handleSnapshotFetch(req, reply, deps) {
|
|
|
105106
106118
|
* we register via the `addon-routes` capability.
|
|
105107
106119
|
*
|
|
105108
106120
|
* Public URLs (assuming the hub is reachable as `https://<hub>`):
|
|
105109
|
-
* POST /addon/export-alexa/
|
|
105110
|
-
* POST /addon/export-alexa/oauth/broker-link
|
|
105111
|
-
* POST /addon/export-alexa/oauth/lwa-tokens
|
|
106121
|
+
* POST /addon/export-alexa[/instances/:instanceId]/directive
|
|
106122
|
+
* POST /addon/export-alexa[/instances/:instanceId]/oauth/broker-link (Lambda → hub, D753)
|
|
106123
|
+
* POST /addon/export-alexa[/instances/:instanceId]/oauth/lwa-tokens (Lambda → hub, pre-D753)
|
|
105112
106124
|
*
|
|
105113
|
-
* The
|
|
105114
|
-
* to the
|
|
106125
|
+
* The three are `perInstance` routes (D1046): the hub reads the instance segment. Without one
|
|
106126
|
+
* the skill is found by its ingress token, then falls back to the default skill
|
|
106127
|
+
* (`instance-routing.ts`). The same three with a trailing `/:instanceId` are the addresses a
|
|
106128
|
+
* Lambda built with `HUB_INSTANCE_ID` before D1046 still calls (planning#422); they stay.
|
|
106129
|
+
*
|
|
106130
|
+
* A token linked to another instance is refused (`token-instance.ts`, D1047).
|
|
105115
106131
|
*
|
|
105116
106132
|
* OAuth account-linking is handled by the core `/oauth2/*` server
|
|
105117
106133
|
* (integration=export-alexa). This addon registers an `oauth-integration`
|
|
@@ -105120,23 +106136,26 @@ async function handleSnapshotFetch(req, reply, deps) {
|
|
|
105120
106136
|
var OauthVerifiedResultSchema = object({
|
|
105121
106137
|
userId: string(),
|
|
105122
106138
|
username: string(),
|
|
105123
|
-
scopes: array(TokenScopeSchema)
|
|
106139
|
+
scopes: array(TokenScopeSchema),
|
|
106140
|
+
/** The instance the link was made for; absent = the default instance (D1047). */
|
|
106141
|
+
instanceId: string().optional()
|
|
105124
106142
|
}).nullable();
|
|
105125
106143
|
/** Header the D753 Lambda sends its broker origin on. */
|
|
105126
106144
|
var BROKER_HEADER = "x-camstack-broker";
|
|
105127
106145
|
function buildRoutes(deps) {
|
|
105128
106146
|
const forSkill = (description, path, handler) => [{
|
|
105129
106147
|
method: "POST",
|
|
105130
|
-
path
|
|
106148
|
+
path,
|
|
105131
106149
|
access: "public",
|
|
105132
|
-
|
|
105133
|
-
|
|
106150
|
+
perInstance: true,
|
|
106151
|
+
description: `${description} (the skill named by the instance segment; without one, the skill that presents its ingress token, else the default skill)`,
|
|
106152
|
+
handler: (req, reply) => routeToSkill(req, reply, deps, explicitInstance(req.instanceId), handler)
|
|
105134
106153
|
}, {
|
|
105135
106154
|
method: "POST",
|
|
105136
|
-
path
|
|
106155
|
+
path: `${path}/:instanceId`,
|
|
105137
106156
|
access: "public",
|
|
105138
|
-
description: `${description} (
|
|
105139
|
-
handler: (req, reply) => routeToSkill(req, reply, deps,
|
|
106157
|
+
description: `${description} (one skill, named after the path: the address older Lambdas call)`,
|
|
106158
|
+
handler: (req, reply) => routeToSkill(req, reply, deps, req.params["instanceId"], handler)
|
|
105140
106159
|
}];
|
|
105141
106160
|
return [
|
|
105142
106161
|
...forSkill("Alexa Smart Home directive ingress (forwarded by the user-owned Lambda)", "/directive", (req, reply, skill) => handleDirective(req, reply, deps, skill)),
|
|
@@ -105157,6 +106176,14 @@ function buildRoutes(deps) {
|
|
|
105157
106176
|
}
|
|
105158
106177
|
];
|
|
105159
106178
|
}
|
|
106179
|
+
/**
|
|
106180
|
+
* The instance a per-instance request names for the resolver. The default instance (no segment,
|
|
106181
|
+
* or the addon id) names none: its address is shared with a Lambda that finds its skill by the
|
|
106182
|
+
* ingress header (planning#422), so the resolver keeps that lookup for it.
|
|
106183
|
+
*/
|
|
106184
|
+
function explicitInstance(instanceId) {
|
|
106185
|
+
return instanceId === void 0 || instanceId === "export-alexa" ? void 0 : instanceId;
|
|
106186
|
+
}
|
|
105160
106187
|
/** Resolve the request's skill, or answer that there is none. */
|
|
105161
106188
|
async function routeToSkill(request, reply, deps, pathInstanceId, handler) {
|
|
105162
106189
|
const skill = deps.resolveSkill({
|
|
@@ -105269,6 +106296,19 @@ async function handleDirective(request, reply, deps, skill) {
|
|
|
105269
106296
|
reply.code(200).send(preParseErrorEnvelope("INVALID_AUTHORIZATION_CREDENTIAL", verdict.kind === "stale" ? "token was issued for another hub address; re-link the Alexa skill" : `hub has no public endpoint (${verdict.reason.code}); set it on the Network page`));
|
|
105270
106297
|
return;
|
|
105271
106298
|
}
|
|
106299
|
+
const instanceVerdict = judgeTokenInstance(verified, skill);
|
|
106300
|
+
if (instanceVerdict.kind === "refused") {
|
|
106301
|
+
deps.logger.warn(`alexa directive: refused — ${instanceVerdict.reason}`, {
|
|
106302
|
+
...arrival.deviceId !== void 0 ? { tags: { deviceId: arrival.deviceId } } : {},
|
|
106303
|
+
meta: {
|
|
106304
|
+
instanceId: skill.id,
|
|
106305
|
+
tokenInstanceId: verified.instanceId ?? null,
|
|
106306
|
+
userId: verified.userId
|
|
106307
|
+
}
|
|
106308
|
+
});
|
|
106309
|
+
reply.code(200).send(preParseErrorEnvelope("INVALID_AUTHORIZATION_CREDENTIAL", describeTokenInstanceRefusal(instanceVerdict.reason)));
|
|
106310
|
+
return;
|
|
106311
|
+
}
|
|
105272
106312
|
try {
|
|
105273
106313
|
assertDeviceScope(verified.scopes);
|
|
105274
106314
|
} catch {
|
|
@@ -105299,6 +106339,133 @@ function pickSkill(skills, lookup) {
|
|
|
105299
106339
|
return skills.find((s) => s.id === "export-alexa" && s.enabled) ?? null;
|
|
105300
106340
|
}
|
|
105301
106341
|
//#endregion
|
|
106342
|
+
//#region src/endpoints/alexa-name.ts
|
|
106343
|
+
/**
|
|
106344
|
+
* The Alexa naming rule (D875, amended by D1049): what a device may be called in Alexa.
|
|
106345
|
+
*
|
|
106346
|
+
* The name itself is the generic `device-export` exposed name (D1049): stored per skill
|
|
106347
|
+
* instance in this addon's per-device store, saved through `setExposedName`, and used as the
|
|
106348
|
+
* endpoint `friendlyName`. It never reaches the endpoint id (`<deviceId>__dev`), so renaming
|
|
106349
|
+
* updates the SAME Alexa device on the next AddOrUpdateReport instead of creating a duplicate.
|
|
106350
|
+
* This module holds only Amazon's rule, and the key of the retired Alexa-only name the
|
|
106351
|
+
* migration reads.
|
|
106352
|
+
*
|
|
106353
|
+
* Amazon's friendlyName rule (Alexa.Discovery objects, endpoint object): "Up
|
|
106354
|
+
* to 256 alphanumeric characters and spaces. Don't include special characters
|
|
106355
|
+
* or punctuation." Letters of any script count as alphanumeric, so an Italian
|
|
106356
|
+
* name keeps its accents. The validator rejects what Amazon would reject, with
|
|
106357
|
+
* a message the operator can act on.
|
|
106358
|
+
*/
|
|
106359
|
+
/**
|
|
106360
|
+
* Per-device store key of the RETIRED Alexa-only name (one per device, shared by every skill).
|
|
106361
|
+
* Only the migration `export-alexa/2026-11-12-alexa-name-to-exposed-name` reads it.
|
|
106362
|
+
*/
|
|
106363
|
+
var LEGACY_ALEXA_NAME_KEY = "alexaName";
|
|
106364
|
+
/** Amazon's rule, as the derived "Name on <skill>" field states it (D1049). */
|
|
106365
|
+
var ALEXA_NAME_RULE = `Amazon accepts letters, digits and spaces only (no punctuation), up to 256 characters.`;
|
|
106366
|
+
/** Letters (any script, with their combining marks), digits and spaces. */
|
|
106367
|
+
var ALLOWED_PATTERN = /^[\p{L}\p{M}\p{N} ]+$/u;
|
|
106368
|
+
/** Amazon's rule over a normalised, non-blank name. */
|
|
106369
|
+
var alexaNameValidator = (name) => {
|
|
106370
|
+
if (name.length > 256) return {
|
|
106371
|
+
ok: false,
|
|
106372
|
+
reason: `The Alexa name is ${name.length} characters; Amazon allows at most 256.`
|
|
106373
|
+
};
|
|
106374
|
+
if (!ALLOWED_PATTERN.test(name)) return {
|
|
106375
|
+
ok: false,
|
|
106376
|
+
reason: "The Alexa name may contain only letters, digits and spaces (Amazon rejects punctuation and special characters)."
|
|
106377
|
+
};
|
|
106378
|
+
return {
|
|
106379
|
+
ok: true,
|
|
106380
|
+
name
|
|
106381
|
+
};
|
|
106382
|
+
};
|
|
106383
|
+
/** Validate an operator-typed Alexa name. Blank clears it (`name: null`, the device name is used). */
|
|
106384
|
+
function validateAlexaName(raw) {
|
|
106385
|
+
return checkExposedName(raw, alexaNameValidator);
|
|
106386
|
+
}
|
|
106387
|
+
//#endregion
|
|
106388
|
+
//#region src/migrations/alexa-name-to-exposed-name.ts
|
|
106389
|
+
/**
|
|
106390
|
+
* The Alexa-only device name becomes the generic exposed name (D1049, amending D875).
|
|
106391
|
+
*
|
|
106392
|
+
* Before: one `alexaName` per device in this addon's per-device store (`addon-device-settings`,
|
|
106393
|
+
* row `export-alexa:<deviceId>.alexaName`), and every skill of the addon (planning#422) showed
|
|
106394
|
+
* it. After: the `device-export` exposed name of EVERY skill that exists, row
|
|
106395
|
+
* `export-alexa:<deviceId>.exposedNames` = `{ <skillId>: name, … }` — so each skill keeps calling
|
|
106396
|
+
* the device what it called it. A skill id that has no `skills` record (the default one on a hub
|
|
106397
|
+
* that never configured Alexa) gets nothing: no running skill would read it.
|
|
106398
|
+
*
|
|
106399
|
+
* One plan, so the copy and the delete commit together. A name is copied as Alexa read it
|
|
106400
|
+
* (normalised; a stored value Alexa would have refused was never used and is not copied). A name
|
|
106401
|
+
* already saved for a skill through the new field was saved by the build that reads it, so it is
|
|
106402
|
+
* never overwritten; the other skills of that device still get the old name. The legacy key is
|
|
106403
|
+
* deleted in every case: nothing reads it any more. A rerun finds no legacy key and does nothing.
|
|
106404
|
+
* A read that fails throws, nothing written.
|
|
106405
|
+
*/
|
|
106406
|
+
var OWNER = "export-alexa";
|
|
106407
|
+
/** The per-device settings table: one row per field, id `<addonId>:<deviceId>.<field>`. */
|
|
106408
|
+
var DEVICE_SETTINGS_TABLE = "addon-device-settings";
|
|
106409
|
+
var rowId$3 = (deviceId, field) => `${OWNER}:${deviceId}.${field}`;
|
|
106410
|
+
var rowOf = (deviceId, field, value) => ({
|
|
106411
|
+
addonId: OWNER,
|
|
106412
|
+
deviceId: String(deviceId),
|
|
106413
|
+
key: field,
|
|
106414
|
+
value
|
|
106415
|
+
});
|
|
106416
|
+
/** The held `exposedNames` blob as a record, or `{}` when it is not one. */
|
|
106417
|
+
function heldNames(value) {
|
|
106418
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return {};
|
|
106419
|
+
return Object.fromEntries(Object.entries(value));
|
|
106420
|
+
}
|
|
106421
|
+
async function planAlexaNameToExposedName(ports) {
|
|
106422
|
+
const ids = await ports.listDeviceIds();
|
|
106423
|
+
if (ids.length === 0) return { edits: [] };
|
|
106424
|
+
const legacy = await ports.readDeviceField(ids, LEGACY_ALEXA_NAME_KEY);
|
|
106425
|
+
if (legacy.size === 0) return { edits: [] };
|
|
106426
|
+
const skills = await ports.listSkillIds();
|
|
106427
|
+
const held = await ports.readDeviceField([...legacy.keys()], EXPOSED_NAMES_STORE_KEY);
|
|
106428
|
+
const written = {};
|
|
106429
|
+
const expected = {};
|
|
106430
|
+
const retired = {};
|
|
106431
|
+
for (const [deviceId, stored] of legacy) {
|
|
106432
|
+
retired[rowId$3(deviceId, LEGACY_ALEXA_NAME_KEY)] = rowOf(deviceId, LEGACY_ALEXA_NAME_KEY, stored);
|
|
106433
|
+
const check = validateAlexaName(stored);
|
|
106434
|
+
if (!check.ok || check.name === null) continue;
|
|
106435
|
+
if (skills.length === 0) {
|
|
106436
|
+
ports.warn(`Alexa migration: device ${deviceId} had an Alexa name but no Alexa skill exists; it is not kept`);
|
|
106437
|
+
continue;
|
|
106438
|
+
}
|
|
106439
|
+
const before = held.has(deviceId) ? heldNames(held.get(deviceId)) : null;
|
|
106440
|
+
const merged = { ...before };
|
|
106441
|
+
for (const skillId of skills) {
|
|
106442
|
+
if (skillId in merged) {
|
|
106443
|
+
ports.warn(`Alexa migration: device ${deviceId} already has a name on skill ${skillId}; its old Alexa name is not copied there`);
|
|
106444
|
+
continue;
|
|
106445
|
+
}
|
|
106446
|
+
merged[skillId] = check.name;
|
|
106447
|
+
}
|
|
106448
|
+
if (before !== null && Object.keys(merged).length === Object.keys(before).length) continue;
|
|
106449
|
+
const id = rowId$3(deviceId, EXPOSED_NAMES_STORE_KEY);
|
|
106450
|
+
written[id] = rowOf(deviceId, EXPOSED_NAMES_STORE_KEY, merged);
|
|
106451
|
+
expected[id] = before === null ? null : rowOf(deviceId, EXPOSED_NAMES_STORE_KEY, held.get(deviceId));
|
|
106452
|
+
}
|
|
106453
|
+
const edits = [];
|
|
106454
|
+
if (Object.keys(written).length > 0) edits.push({
|
|
106455
|
+
op: "setKeys",
|
|
106456
|
+
scope: DEVICE_SETTINGS_TABLE,
|
|
106457
|
+
values: written,
|
|
106458
|
+
precondition: preconditionOf(expected)
|
|
106459
|
+
});
|
|
106460
|
+
edits.push({
|
|
106461
|
+
op: "deleteKeys",
|
|
106462
|
+
scope: DEVICE_SETTINGS_TABLE,
|
|
106463
|
+
keys: Object.keys(retired),
|
|
106464
|
+
precondition: preconditionOf(retired)
|
|
106465
|
+
});
|
|
106466
|
+
return { edits };
|
|
106467
|
+
}
|
|
106468
|
+
//#endregion
|
|
105302
106469
|
//#region src/migrations/drop-public-hub-url.ts
|
|
105303
106470
|
/**
|
|
105304
106471
|
* The hub's public URL is no longer a setting of this addon (planning#378): Alexa reads the
|
|
@@ -105898,6 +107065,7 @@ var EXPOSURE_TO_RECORD_ID = "export-alexa/2026-11-04-exposure-to-record";
|
|
|
105898
107065
|
var DROP_MOVED_EXPOSURE_ID = "export-alexa/2026-11-04-drop-moved-exposure";
|
|
105899
107066
|
var STATE_TO_INSTANCE_ID = "export-alexa/2026-11-04-state-to-instance";
|
|
105900
107067
|
var DROP_MOVED_STATE_ID = "export-alexa/2026-11-04-drop-moved-state";
|
|
107068
|
+
var ALEXA_NAME_TO_EXPOSED_NAME_ID = "export-alexa/2026-11-12-alexa-name-to-exposed-name";
|
|
105901
107069
|
var FIXTURE_MARK = "the endpoint sync state the migration does not know";
|
|
105902
107070
|
/**
|
|
105903
107071
|
* The `export-alexa` catalogue (D987): offered to the engine when the addon initialises. Every
|
|
@@ -106031,30 +107199,27 @@ var ADDON_MIGRATIONS = [
|
|
|
106031
107199
|
fixtureMark: FIXTURE_MARK
|
|
106032
107200
|
},
|
|
106033
107201
|
plan: planDropMovedState
|
|
107202
|
+
},
|
|
107203
|
+
{
|
|
107204
|
+
meta: {
|
|
107205
|
+
id: ALEXA_NAME_TO_EXPOSED_NAME_ID,
|
|
107206
|
+
owner: "export-alexa",
|
|
107207
|
+
level: "addon-state",
|
|
107208
|
+
seq: 9,
|
|
107209
|
+
dependsOn: [],
|
|
107210
|
+
store: "settings",
|
|
107211
|
+
scope: "cluster",
|
|
107212
|
+
onFailure: "tolerate",
|
|
107213
|
+
bodyKind: "plan",
|
|
107214
|
+
description: "Copy every device`s Alexa name to the exposed name of every Alexa skill and delete the alexaName key",
|
|
107215
|
+
fixtureMark: FIXTURE_MARK
|
|
107216
|
+
},
|
|
107217
|
+
plan: planAlexaNameToExposedName
|
|
106034
107218
|
}
|
|
106035
107219
|
];
|
|
106036
107220
|
//#endregion
|
|
106037
107221
|
//#region src/oauth-integration.ts
|
|
106038
107222
|
/**
|
|
106039
|
-
* The `export-alexa` OAuth client — the descriptor behind
|
|
106040
|
-
* `/api/oauth2/authorize?integration=export-alexa`.
|
|
106041
|
-
*
|
|
106042
|
-
* Shaped deliberately like
|
|
106043
|
-
* `packages/addon-provider-homeassistant/src/ha-export/oauth-integration.ts`:
|
|
106044
|
-
* one named `OauthIntegrationDescriptor` per integration, in its own module,
|
|
106045
|
-
* registered from the addon's `onInitialize` through `oauthIntegrationCapability`
|
|
106046
|
-
* ([D101](../../../docs/decisions/adr-0101.md)). The two integrations differ
|
|
106047
|
-
* only in the FIELDS below, never in how they are declared — which is the whole
|
|
106048
|
-
* claim being made: a third one is configuration, not framework work.
|
|
106049
|
-
*
|
|
106050
|
-
* Typed rather than inlined, and that is not cosmetic. As an untyped object
|
|
106051
|
-
* literal this needed three `as const` assertions to satisfy the schema and was
|
|
106052
|
-
* checked for the first time at `/authorize`, i.e. in front of an operator
|
|
106053
|
-
* mid-link. The annotation moves that to compile time.
|
|
106054
|
-
*
|
|
106055
|
-
* @see docs/decisions/adr-0092.md — why `client_secret` is never checked here.
|
|
106056
|
-
*/
|
|
106057
|
-
/**
|
|
106058
107223
|
* Where Alexa lands after consent — Amazon's three regional account-linking
|
|
106059
107224
|
* origins, fixed and public. Contrast Home Assistant, whose callback is on the
|
|
106060
107225
|
* operator's own LAN and needs `allowedPrivateHostPaths`; that difference is
|
|
@@ -106090,7 +107255,7 @@ var ALEXA_REDIRECT_PREFIXES = [
|
|
|
106090
107255
|
* no `requiresPkce` here. That is a property of the two clients, expressed
|
|
106091
107256
|
* through the same descriptor field.
|
|
106092
107257
|
*/
|
|
106093
|
-
function buildAlexaOauthIntegration(publicOrigin) {
|
|
107258
|
+
function buildAlexaOauthIntegration(publicOrigin, instances = []) {
|
|
106094
107259
|
return {
|
|
106095
107260
|
integrationId: "export-alexa",
|
|
106096
107261
|
displayName: "Alexa Smart Home",
|
|
@@ -106127,7 +107292,8 @@ function buildAlexaOauthIntegration(publicOrigin) {
|
|
|
106127
107292
|
* "Unlink Amazon account" button does; see `unlinkAlexaAccounts`.
|
|
106128
107293
|
*/
|
|
106129
107294
|
refreshTokenTtlSec: "never",
|
|
106130
|
-
...publicOrigin ? { hubUrl: publicOrigin } : {}
|
|
107295
|
+
...publicOrigin ? { hubUrl: publicOrigin } : {},
|
|
107296
|
+
...instances.length > 0 ? { instances: [...instances] } : {}
|
|
106131
107297
|
};
|
|
106132
107298
|
}
|
|
106133
107299
|
//#endregion
|
|
@@ -106916,72 +108082,33 @@ var AlexaEgressPrewarm = class {
|
|
|
106916
108082
|
}
|
|
106917
108083
|
};
|
|
106918
108084
|
//#endregion
|
|
106919
|
-
//#region src/
|
|
106920
|
-
|
|
106921
|
-
|
|
106922
|
-
|
|
106923
|
-
|
|
106924
|
-
|
|
106925
|
-
|
|
106926
|
-
|
|
106927
|
-
|
|
106928
|
-
|
|
106929
|
-
|
|
106930
|
-
|
|
106931
|
-
|
|
106932
|
-
|
|
106933
|
-
|
|
106934
|
-
|
|
106935
|
-
|
|
106936
|
-
|
|
106937
|
-
|
|
106938
|
-
|
|
106939
|
-
|
|
106940
|
-
|
|
106941
|
-
|
|
106942
|
-
|
|
106943
|
-
|
|
106944
|
-
|
|
106945
|
-
|
|
106946
|
-
*/
|
|
106947
|
-
function validateAlexaName(raw) {
|
|
106948
|
-
if (raw === null || raw === void 0) return {
|
|
106949
|
-
ok: true,
|
|
106950
|
-
name: null
|
|
106951
|
-
};
|
|
106952
|
-
if (typeof raw !== "string") return {
|
|
106953
|
-
ok: false,
|
|
106954
|
-
error: "The Alexa name must be text."
|
|
106955
|
-
};
|
|
106956
|
-
const name = raw.trim().replace(/\s+/g, " ");
|
|
106957
|
-
if (name.length === 0) return {
|
|
106958
|
-
ok: true,
|
|
106959
|
-
name: null
|
|
106960
|
-
};
|
|
106961
|
-
if (name.length > 256) return {
|
|
106962
|
-
ok: false,
|
|
106963
|
-
error: `The Alexa name is ${name.length} characters; Amazon allows at most 256.`
|
|
106964
|
-
};
|
|
106965
|
-
if (!ALLOWED_PATTERN.test(name)) return {
|
|
106966
|
-
ok: false,
|
|
106967
|
-
error: "The Alexa name may contain only letters, digits and spaces (Amazon rejects punctuation and special characters)."
|
|
106968
|
-
};
|
|
106969
|
-
return {
|
|
106970
|
-
ok: true,
|
|
106971
|
-
name
|
|
106972
|
-
};
|
|
106973
|
-
}
|
|
106974
|
-
var StoredNameSchema = string();
|
|
106975
|
-
/**
|
|
106976
|
-
* The saved Alexa name in a per-device store blob, or null (never saved, or a
|
|
106977
|
-
* stored value that no longer validates: the device name is used rather than
|
|
106978
|
-
* pushing a name Amazon would refuse).
|
|
106979
|
-
*/
|
|
106980
|
-
function readAlexaName(store) {
|
|
106981
|
-
const parsed = StoredNameSchema.safeParse(store[ALEXA_NAME_KEY]);
|
|
106982
|
-
if (!parsed.success) return null;
|
|
106983
|
-
const check = validateAlexaName(parsed.data);
|
|
106984
|
-
return check.ok ? check.name : null;
|
|
108085
|
+
//#region src/exposed-name-rename.ts
|
|
108086
|
+
async function renameOnSkill(deps, deviceIdRaw, raw, options = {}) {
|
|
108087
|
+
const deviceId = Number.parseInt(deviceIdRaw, 10);
|
|
108088
|
+
if (!Number.isFinite(deviceId)) throw new Error(`export-alexa: deviceId must be numeric — got "${deviceIdRaw}"`);
|
|
108089
|
+
const saved = await saveExposedName({
|
|
108090
|
+
store: deps.store,
|
|
108091
|
+
deviceId,
|
|
108092
|
+
instanceId: deps.instanceId,
|
|
108093
|
+
raw,
|
|
108094
|
+
validate: alexaNameValidator,
|
|
108095
|
+
...options.dryRun === true ? { dryRun: true } : {}
|
|
108096
|
+
});
|
|
108097
|
+
if (!saved.changed) return;
|
|
108098
|
+
deps.logger.info("export-alexa: Alexa name saved", {
|
|
108099
|
+
tags: { deviceId },
|
|
108100
|
+
meta: {
|
|
108101
|
+
instanceId: deps.instanceId,
|
|
108102
|
+
name: saved.name
|
|
108103
|
+
}
|
|
108104
|
+
});
|
|
108105
|
+
if (!deps.isExposed(deviceId)) return;
|
|
108106
|
+
deps.push(deviceId).catch((err) => {
|
|
108107
|
+
deps.logger.warn("export-alexa: push after an Alexa name change failed", {
|
|
108108
|
+
tags: { deviceId },
|
|
108109
|
+
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
108110
|
+
});
|
|
108111
|
+
});
|
|
106985
108112
|
}
|
|
106986
108113
|
//#endregion
|
|
106987
108114
|
//#region src/stream-preference.ts
|
|
@@ -109870,15 +110997,22 @@ var SkillRuntime = class {
|
|
|
109870
110997
|
}
|
|
109871
110998
|
/** The routes' view of this skill: what a directive or a Lambda callback acts on. */
|
|
109872
110999
|
routed() {
|
|
111000
|
+
const hasLinkedUser = (userId) => this.view.linkedAccounts.some((a) => a.userId === userId);
|
|
109873
111001
|
return {
|
|
109874
111002
|
id: this.instanceId,
|
|
109875
111003
|
getSettings: () => this.effectiveSettings(),
|
|
109876
111004
|
directiveDeps: this.directiveDeps(),
|
|
111005
|
+
hasLinkedUser,
|
|
109877
111006
|
lwaTokensCallbackDeps: {
|
|
109878
111007
|
ctx: this.ctx,
|
|
109879
111008
|
logger: this.ctx.logger,
|
|
109880
111009
|
upsertToken: (input) => this.upsertToken(input),
|
|
109881
|
-
recordLinkedAccount: (input) => this.recordLinkedAccount(input)
|
|
111010
|
+
recordLinkedAccount: (input) => this.recordLinkedAccount(input),
|
|
111011
|
+
instanceId: this.instanceId,
|
|
111012
|
+
judgeInstance: (caller) => judgeTokenInstance(caller, {
|
|
111013
|
+
id: this.instanceId,
|
|
111014
|
+
hasLinkedUser
|
|
111015
|
+
})
|
|
109882
111016
|
},
|
|
109883
111017
|
onBrokerAdvertised: (raw) => this.rememberAdvertisedBroker(raw)
|
|
109884
111018
|
};
|
|
@@ -110029,7 +111163,7 @@ var SkillRuntime = class {
|
|
|
110029
111163
|
logger: this.ctx.logger,
|
|
110030
111164
|
snapshots: this.view.snapshots,
|
|
110031
111165
|
...this.view.detectionSensors ? { detectionClasses: async (id) => effectiveSensorClasses(await classesOf(id), parseSensorSelection(await vision.readPrefs(id))) } : {},
|
|
110032
|
-
alexaName: async (id) =>
|
|
111166
|
+
alexaName: async (id) => readExposedName(await vision.readPrefs(id), this.instanceId, alexaNameValidator),
|
|
110033
111167
|
...this.view.objectDetection ? { objectDetection: async (id) => vision.buildClasses(id, await classesOf(id)) } : {}
|
|
110034
111168
|
});
|
|
110035
111169
|
}
|
|
@@ -110475,27 +111609,11 @@ var SkillRuntime = class {
|
|
|
110475
111609
|
value: enabled,
|
|
110476
111610
|
immediate: true
|
|
110477
111611
|
},
|
|
110478
|
-
...opts.shared ? [await this.alexaNameField(deviceId, enabledKey)] : [],
|
|
110479
111612
|
...kind === "camera" ? this.cameraOnlyExportFields(deviceId, settings, enabledKey) : [],
|
|
110480
111613
|
...kind === "camera" && opts.shared ? await this.cameraDetectionFields(deviceId, enabledKey) : []
|
|
110481
111614
|
]
|
|
110482
111615
|
};
|
|
110483
111616
|
}
|
|
110484
|
-
/** D875: the "Alexa name" field, with the validation error of the saved value. */
|
|
110485
|
-
async alexaNameField(deviceId, enabledKey) {
|
|
110486
|
-
const saved = readAlexaName(await this.vision.readPrefs(deviceId));
|
|
110487
|
-
return {
|
|
110488
|
-
type: "text",
|
|
110489
|
-
key: alexaNameKey(deviceId),
|
|
110490
|
-
label: "Alexa name",
|
|
110491
|
-
description: `What Alexa calls this device. Leave empty to use the device name. Letters, digits and spaces only (no punctuation), up to 256 characters. Renaming updates the same Alexa device; it does not create a duplicate.`,
|
|
110492
|
-
value: saved ?? "",
|
|
110493
|
-
showWhen: {
|
|
110494
|
-
field: enabledKey,
|
|
110495
|
-
equals: true
|
|
110496
|
-
}
|
|
110497
|
-
};
|
|
110498
|
-
}
|
|
110499
111617
|
/**
|
|
110500
111618
|
* The camera's detection fields: which classes become Alexa sensors (D778;
|
|
110501
111619
|
* only the classes its pipeline produces are offered) and its object
|
|
@@ -110517,24 +111635,6 @@ var SkillRuntime = class {
|
|
|
110517
111635
|
})];
|
|
110518
111636
|
}
|
|
110519
111637
|
/**
|
|
110520
|
-
* D875: save the Alexa name from a device-settings patch. A name Amazon would
|
|
110521
|
-
* refuse throws BEFORE anything is written, so the form shows the reason and
|
|
110522
|
-
* the old name stays. True when the saved name changed.
|
|
110523
|
-
*/
|
|
110524
|
-
async applyAlexaNamePatch(deviceId, patch) {
|
|
110525
|
-
const key = alexaNameKey(deviceId);
|
|
110526
|
-
if (!(key in patch)) return false;
|
|
110527
|
-
const check = validateAlexaName(patch[key]);
|
|
110528
|
-
if (!check.ok) throw new Error(`export-alexa: ${check.error}`);
|
|
110529
|
-
if (readAlexaName(await this.vision.readPrefs(deviceId)) === check.name) return false;
|
|
110530
|
-
await this.vision.writePrefs(deviceId, { [ALEXA_NAME_KEY]: check.name ?? void 0 });
|
|
110531
|
-
this.ctx.logger.info("export-alexa: Alexa name saved", {
|
|
110532
|
-
tags: { deviceId },
|
|
110533
|
-
meta: { name: check.name }
|
|
110534
|
-
});
|
|
110535
|
-
return true;
|
|
110536
|
-
}
|
|
110537
|
-
/**
|
|
110538
111638
|
* Persist the camera's detection preferences from a device-settings patch
|
|
110539
111639
|
* into this addon's per-device store. True when anything changed — the
|
|
110540
111640
|
* camera's Alexa shape then needs a reconcile.
|
|
@@ -110585,15 +111685,32 @@ var SkillRuntime = class {
|
|
|
110585
111685
|
}];
|
|
110586
111686
|
}
|
|
110587
111687
|
/**
|
|
110588
|
-
* The device's own preferences in a patch (
|
|
110589
|
-
*
|
|
110590
|
-
*
|
|
111688
|
+
* The device's own preferences in a patch (detection classes, object detection): shared by
|
|
111689
|
+
* every skill, so they are saved ONCE, before any skill applies its own part (an expose in
|
|
111690
|
+
* the same patch then builds with them).
|
|
110591
111691
|
*/
|
|
110592
111692
|
async applySharedPrefs(deviceId, patch) {
|
|
110593
|
-
return {
|
|
110594
|
-
|
|
110595
|
-
|
|
110596
|
-
|
|
111693
|
+
return { prefsChanged: await this.applyDetectionPrefsPatch(deviceId, patch) };
|
|
111694
|
+
}
|
|
111695
|
+
/** D1049: this skill's exposed name for a device, or null (the device's own name). */
|
|
111696
|
+
async exposedNameOf(deviceId) {
|
|
111697
|
+
return readExposedName(await this.vision.readPrefs(deviceId), this.instanceId, alexaNameValidator);
|
|
111698
|
+
}
|
|
111699
|
+
/**
|
|
111700
|
+
* D1049: save this skill's name for a device (`device-export.setExposedName`); an exposed
|
|
111701
|
+
* device is pushed again under the same endpoint id. `renameOnSkill` holds the rule.
|
|
111702
|
+
*/
|
|
111703
|
+
async setExposedName(deviceIdRaw, raw, dryRun = false) {
|
|
111704
|
+
await renameOnSkill({
|
|
111705
|
+
instanceId: this.instanceId,
|
|
111706
|
+
store: {
|
|
111707
|
+
read: (id) => exposedNameStoreOf(this.ctx.settings, "export-alexa").read(id),
|
|
111708
|
+
write: (id, patch) => this.vision.writePrefs(id, patch)
|
|
111709
|
+
},
|
|
111710
|
+
logger: this.ctx.logger,
|
|
111711
|
+
isExposed: (id) => this.findEntry(id) !== null,
|
|
111712
|
+
push: (id) => this.requireSyncEngine().pushDevice(id)
|
|
111713
|
+
}, deviceIdRaw, raw, { dryRun });
|
|
110597
111714
|
}
|
|
110598
111715
|
/**
|
|
110599
111716
|
* Apply this skill's part of a patch produced by the device-details "Export" panel. Flips
|
|
@@ -110606,7 +111723,7 @@ var SkillRuntime = class {
|
|
|
110606
111723
|
* the new preference. See remaining-work notes in CLAUDE.md.
|
|
110607
111724
|
*/
|
|
110608
111725
|
async applyEntryPatch(deviceId, patch, shared) {
|
|
110609
|
-
const { prefsChanged
|
|
111726
|
+
const { prefsChanged } = shared;
|
|
110610
111727
|
const idStr = String(deviceId);
|
|
110611
111728
|
const current = this.findEntry(deviceId);
|
|
110612
111729
|
const wasEnabled = current !== null;
|
|
@@ -110635,12 +111752,6 @@ var SkillRuntime = class {
|
|
|
110635
111752
|
const currentAllow = current?.settings?.allowTranscode !== false;
|
|
110636
111753
|
await this.patchEntrySettings(deviceId, nextSettings);
|
|
110637
111754
|
const sourceChanged = currentPref !== streamPreference || currentAllow !== allowTranscode;
|
|
110638
|
-
if (nameChanged && !sourceChanged) this.requireSyncEngine().pushDevice(deviceId).catch((err) => {
|
|
110639
|
-
this.ctx.logger.warn("export-alexa: push after an Alexa name change failed", {
|
|
110640
|
-
tags: { deviceId },
|
|
110641
|
-
meta: { error: errMsg$1(err) }
|
|
110642
|
-
});
|
|
110643
|
-
});
|
|
110644
111755
|
if (prefsChanged && !sourceChanged) this.requireSyncEngine().reconcileDevice(deviceId).catch((err) => {
|
|
110645
111756
|
this.ctx.logger.warn("export-alexa: re-sync after a detection preference change failed", {
|
|
110646
111757
|
tags: { deviceId },
|
|
@@ -111186,15 +112297,30 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
111186
112297
|
instanceId: row.id,
|
|
111187
112298
|
name: row.body.name,
|
|
111188
112299
|
enabled: row.enabled,
|
|
111189
|
-
kind: "alexa-skill"
|
|
112300
|
+
kind: "alexa-skill",
|
|
112301
|
+
nameRule: ALEXA_NAME_RULE
|
|
111190
112302
|
}));
|
|
111191
112303
|
},
|
|
111192
112304
|
listSupportedDeviceKinds: async ({ instanceId }) => {
|
|
111193
112305
|
ownInstance(instanceId);
|
|
111194
112306
|
return [...SUPPORTED_KINDS];
|
|
111195
112307
|
},
|
|
111196
|
-
listExposedDevices: async ({ instanceId }) =>
|
|
111197
|
-
|
|
112308
|
+
listExposedDevices: async ({ instanceId }) => {
|
|
112309
|
+
const runtime = ownInstance(instanceId);
|
|
112310
|
+
return Promise.all(runtime.exposedDevices.map(async (e) => {
|
|
112311
|
+
const exposedName = await runtime.exposedNameOf(e.deviceId);
|
|
112312
|
+
return {
|
|
112313
|
+
deviceId: String(e.deviceId),
|
|
112314
|
+
...exposedName !== null ? { exposedName } : {}
|
|
112315
|
+
};
|
|
112316
|
+
}));
|
|
112317
|
+
},
|
|
112318
|
+
exposeDevice: async ({ instanceId, deviceId, exposedName }) => {
|
|
112319
|
+
const runtime = ownInstance(instanceId);
|
|
112320
|
+
if (exposedName !== void 0) await runtime.setExposedName(deviceId, exposedName);
|
|
112321
|
+
return runtime.exposeDevice(deviceId);
|
|
112322
|
+
},
|
|
112323
|
+
setExposedName: async ({ instanceId, deviceId, name, dryRun }) => ownInstance(instanceId).setExposedName(deviceId, name, dryRun === true),
|
|
111198
112324
|
unexposeDevice: async ({ instanceId, deviceId }) => ownInstance(instanceId).unexposeDevice(deviceId),
|
|
111199
112325
|
listSupportedEntityKinds: async () => ["device", "action"],
|
|
111200
112326
|
listExposedEntities: async ({ instanceId }) => {
|
|
@@ -111250,7 +112376,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
111250
112376
|
const oauthIntegrationProvider = { getDescriptor: async () => {
|
|
111251
112377
|
const endpoint = await this.publicEndpoint();
|
|
111252
112378
|
if (!endpoint.ok) this.ctx.logger.warn(`export-alexa: linking without a routing claim — ${endpoint.reason.code}: ${endpoint.reason.message}`);
|
|
111253
|
-
return buildAlexaOauthIntegration(endpoint.ok ? endpoint.origin : void 0);
|
|
112379
|
+
return buildAlexaOauthIntegration(endpoint.ok ? endpoint.origin : void 0, this.linkableInstances());
|
|
111254
112380
|
} };
|
|
111255
112381
|
const reaper = setInterval(() => {
|
|
111256
112382
|
this.reapDeadEgressHandles();
|
|
@@ -111298,6 +112424,13 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
111298
112424
|
async onConfigChanged() {
|
|
111299
112425
|
for (const runtime of this.runtimes.values()) await runtime.applyShapeSwitches();
|
|
111300
112426
|
}
|
|
112427
|
+
/** The running skills an account may be linked to with `instance=` (all but the default). */
|
|
112428
|
+
linkableInstances() {
|
|
112429
|
+
return [...this.runtimes.values()].filter((r) => !r.isDefault).map((r) => ({
|
|
112430
|
+
id: r.instanceId,
|
|
112431
|
+
displayName: r.skillName
|
|
112432
|
+
}));
|
|
112433
|
+
}
|
|
111301
112434
|
/** Build and start the runtime of one skill. */
|
|
111302
112435
|
async startRuntime(instanceId) {
|
|
111303
112436
|
const runtime = new SkillRuntime(instanceId, this.host());
|
|
@@ -111315,6 +112448,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
111315
112448
|
if (change === "deleted") {
|
|
111316
112449
|
await this.stopRuntime(id);
|
|
111317
112450
|
await this.deleteSkillRows(id);
|
|
112451
|
+
await this.pruneSkillNames(id);
|
|
111318
112452
|
return;
|
|
111319
112453
|
}
|
|
111320
112454
|
const row = await this.requireInstances().readResolved(id);
|
|
@@ -111330,6 +112464,16 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
111330
112464
|
await running.refreshRecords();
|
|
111331
112465
|
await running.applyShapeSwitches();
|
|
111332
112466
|
}
|
|
112467
|
+
/** A deleted skill's device names go too, so a skill that reuses the id inherits none (D1049). */
|
|
112468
|
+
async pruneSkillNames(id) {
|
|
112469
|
+
const settings = this.ctx.settings;
|
|
112470
|
+
if (settings === void 0) return;
|
|
112471
|
+
const pruned = await pruneExposedNames(settings, id);
|
|
112472
|
+
if (pruned.length > 0) this.ctx.logger.info("export-alexa: deleted skill names removed", { meta: {
|
|
112473
|
+
instanceId: id,
|
|
112474
|
+
devices: pruned.length
|
|
112475
|
+
} });
|
|
112476
|
+
}
|
|
111333
112477
|
/** What a deleted skill leaves behind: its links, its exposure and its hidden state. */
|
|
111334
112478
|
async deleteSkillRows(id) {
|
|
111335
112479
|
await deleteSkillRows(this.requireHandles(), id);
|
|
@@ -111408,6 +112552,19 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
111408
112552
|
readState: async () => (await stateHandle.getResolved("export-alexa"))?.data ?? null,
|
|
111409
112553
|
clearIngressTokenSecret: async () => {
|
|
111410
112554
|
await this.clearSecrets(["ingressToken"]);
|
|
112555
|
+
},
|
|
112556
|
+
listSkillIds: async () => (await this.requireInstances().listResolved()).map((r) => r.id),
|
|
112557
|
+
listDeviceIds: async () => {
|
|
112558
|
+
const settings = this.ctx.settings;
|
|
112559
|
+
if (settings === void 0) throw new Error("export-alexa: the settings store is unavailable");
|
|
112560
|
+
return settings.listDeviceStoreIds();
|
|
112561
|
+
},
|
|
112562
|
+
readDeviceField: async (deviceIds, field) => {
|
|
112563
|
+
const settings = this.ctx.settings;
|
|
112564
|
+
if (settings === void 0) throw new Error("export-alexa: the settings store is unavailable");
|
|
112565
|
+
const found = /* @__PURE__ */ new Map();
|
|
112566
|
+
for (const [deviceId, blob] of await settings.readDeviceStoreBatch(deviceIds)) if (field in blob) found.set(deviceId, blob[field]);
|
|
112567
|
+
return found;
|
|
111411
112568
|
}
|
|
111412
112569
|
};
|
|
111413
112570
|
}
|