@camstack/server 1.2.890 → 1.2.892
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 +22 -0
- package/dist/api/trpc/generated-cap-mounts.js +2 -1
- package/dist/api/trpc/generated-cap-routers.js +212 -39
- package/dist/core/addon/addon-registry.service.js +47 -0
- package/dist/core/addon/retire-undeclared-fixed-integrations.js +57 -0
- package/package.json +31 -19
- package/system/dist/addon-runner.js +25 -9
- package/system/dist/addon-runner.mjs +25 -9
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/alerts/alerts.addon.js +1 -1
- package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/addon.d.ts +65 -41
- package/system/dist/builtins/camera-grid/grid-blocks.d.ts +51 -0
- package/system/dist/builtins/camera-grid/grid-camera-device.d.ts +4 -3
- package/system/dist/builtins/camera-grid/grid-layout-native-provider.d.ts +3 -1
- package/system/dist/builtins/camera-grid/grid-plan.d.ts +3 -3
- package/system/dist/builtins/camera-grid/index.d.ts +2 -6
- package/system/dist/builtins/camera-grid/index.js +431 -727
- package/system/dist/builtins/camera-grid/index.mjs +428 -719
- package/system/dist/builtins/composer/composed-device.d.ts +12 -2
- package/system/dist/builtins/composer/composer.addon.js +28 -10
- package/system/dist/builtins/composer/composer.addon.mjs +28 -10
- package/system/dist/builtins/composer/composition-declarations.d.ts +3 -1
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +283 -51
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +284 -52
- package/system/dist/builtins/core-blocks/hero-layout-service.d.ts +19 -1
- package/system/dist/builtins/core-blocks/power-source-devices.d.ts +9 -0
- package/system/dist/builtins/core-blocks/power-source-service.d.ts +39 -2
- package/system/dist/builtins/core-blocks/tags-service.d.ts +20 -3
- package/system/dist/builtins/core-blocks/tags-wiring.d.ts +15 -2
- package/system/dist/builtins/device-history/device-history.addon.js +2 -2
- package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
- package/system/dist/builtins/device-manager/device-identifiers-action.d.ts +9 -0
- package/system/dist/builtins/device-manager/device-manager.addon.js +172 -5
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +172 -5
- package/system/dist/builtins/device-manager/device-meta-types.d.ts +5 -1
- package/system/dist/builtins/device-manager/device-row-store.d.ts +3 -2
- package/system/dist/builtins/device-manager/device-state-mirror.d.ts +7 -0
- package/system/dist/builtins/device-manager/workload-transition.d.ts +23 -0
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +4 -4
- package/system/dist/builtins/keychain/index.mjs +4 -4
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
- package/system/dist/builtins/local-network/local-network.addon.js +3 -3
- package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
- package/system/dist/builtins/loki-logging/index.js +1 -1
- package/system/dist/builtins/loki-logging/index.mjs +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +1 -1
- package/system/dist/builtins/record-entries/index.js +1 -1
- package/system/dist/builtins/record-entries/index.mjs +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +1 -1
- package/system/dist/builtins/snapshot/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +3 -3
- package/system/dist/builtins/system-config/system-config.addon.mjs +284 -284
- package/system/dist/builtins/winston-logging/index.js +1 -1
- package/system/dist/builtins/winston-logging/index.mjs +1 -1
- package/system/dist/{capture-engine-C1vdBL88.js → capture-engine-DHmlkW_d.js} +1 -1
- package/system/dist/{capture-engine-B1bMuzVX.mjs → capture-engine-sl6e9f9S.mjs} +1 -1
- package/system/dist/{composition-sources-Dj6qn5PP.mjs → composition-sources-CznD85Ri.mjs} +1 -1
- package/system/dist/{composition-sources-BfLlyKRe.js → composition-sources-PqcZfe3j.js} +1 -1
- package/system/dist/{constants-Ba51ywI4.mjs → constants-CHwj_mIM.mjs} +1 -1
- package/system/dist/{constants-DuB_xXYx.js → constants-_2SOk0By.js} +1 -1
- package/system/dist/{device-ca-CkXjf3ms.mjs → device-ca-D2H1EMUY.mjs} +1 -1
- package/system/dist/{device-ca-CVjaotgX.js → device-ca-WIEO5ZcE.js} +1 -1
- package/system/dist/{dist-BKojK6Wf.mjs → dist-DbAhCrHy.mjs} +2468 -454
- package/system/dist/{dist-BjhII4Uq.js → dist-yx2KHo3b.js} +2575 -453
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-identity-C0qf888i.mjs → hub-identity-BcvZqT0L.mjs} +1 -1
- package/system/dist/{hub-identity-C0ehkt78.js → hub-identity-Buegac-w.js} +1 -1
- package/system/dist/{hub-mdns-ciao-BYe34S2Q.mjs → hub-mdns-ciao-B6K_dO2s.mjs} +2 -2
- package/system/dist/{hub-mdns-ciao-DJHjyjvT.js → hub-mdns-ciao-DcNPj7WJ.js} +2 -2
- package/system/dist/index.js +33 -19
- package/system/dist/index.mjs +33 -19
- package/system/dist/kernel/moleculer/child-cap-dispatch.d.ts +3 -6
- package/system/dist/kernel/moleculer/switch-toggle.d.ts +7 -2
- package/system/dist/{legacy-integration-rows-door-G6EceE_J.js → legacy-integration-rows-door-BsZyVNiR.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-BEYgXSXr.mjs → legacy-integration-rows-door-DHOJeDPG.mjs} +1 -1
- package/system/dist/{rename-composition-block-D1mO51F9.js → rename-composition-block-BXMor7MR.js} +1 -1
- package/system/dist/{rename-composition-block-D6bq3Twf.mjs → rename-composition-block-DcVS1LuC.mjs} +1 -1
- package/system/dist/{restore-archive-FXsCWq_f.mjs → restore-archive-BG8VJ8Ar.mjs} +82 -82
- package/system/dist/{restore-archive-CJvMq13C.js → restore-archive-BURufVQd.js} +1 -1
- package/system/dist/{wal-maintenance-Ci9Dl-lB.mjs → wal-maintenance-B4wGD6QR.mjs} +0 -0
- package/system/dist/{wal-maintenance-COJ_JxrD.js → wal-maintenance-CeaJyKNT.js} +0 -0
- package/system/package.json +2 -5
- package/system/dist/builtins/camera-grid/grid-camera-declarations.d.ts +0 -59
- package/system/dist/builtins/camera-grid/grid-instances.d.ts +0 -40
- package/system/dist/builtins/camera-grid/grid-record-kinds.d.ts +0 -31
- package/system/dist/builtins/camera-grid/migrations/__fixtures__/seed.d.ts +0 -13
- package/system/dist/builtins/camera-grid/migrations/camera-grids-to-records.d.ts +0 -26
- package/system/dist/builtins/camera-grid/migrations/index.d.ts +0 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { $a as
|
|
1
|
+
import { $a as remoteCapability, $r as evaluateWhenTree, $t as REMOTE_MEDIA_COMMANDS, An as actionsCapability, B as DEFAULT_HOLD_OVERRIDE, Ba as problemsBlockSave, Bn as assertStepsOffered, Bs as composedDeviceStableId, Bt as NcTaggedRuleKindSchema, Ci as instanceCodeHash, Cr as coreBlockSourceKind, D as CORE_BLOCK_ADDON_PREFIX, Dr as customKeyOfRole, Ds as DAY_MS, Dt as IDLE_ACTION_STATUS, E as CORE_BLOCKS_ADDON_ID, Eo as schedulersCapability, Es as CompositionSchema, Fa as powerSourceActuatorConflicts, Fs as canonicalStoredBlockTarget, Gc as VocabActionError, Ia as powerSourceCapability, Ir as describeComposableCaps, Ka as readRecipeLiteral, Kl as resolveSecretMarkers, Kn as buildActionSteps, La as powerSourceLinkOfComposition, Li as isInternalActionId, Lt as MediaPlayerStatusSchema, Mi as isBuiltinTemplateId, Ms as HelperMemberSchema, N as CoreBlockSchema, Na as planComposition, Nl as isSecretRefOwnedBy, Nr as defaultTagColorId, On as actionSourceCapability, Ot as INTERNAL_ACTION_PREFIX, Pc as RecordIntegrationInstances, Qa as reexpandAutomationInstance, Qn as builtinAutomationTemplate, Qr as evaluateStepCondition, Rn as appendTrace, Sn as TemplateKindSchema, So as runSteps, Sr as coreBlockIdFromAddonId, T as COMPOSER_RUNNER_ID, Ta as occurrenceOn, Ti as internalActionId, Ts as COMPOSER_ADDON_ID, Ua as projectDeviceRow, Uo as stableIdMapOf, Vs as compositionFeatureEnabled, Wa as proposeRunningThreshold, Wi as kebabToCamel, Ws as compositionSourceKey, Xl as secretTreeFromSchema, Xn as buildHeroModel, Xs as historyRetentionFromSettings, Ys as helperMembers, Zi as localDateOf, Zt as QuantityUnitError, _ as BUILTIN_REMOTE_COMPONENTS, _a as nextOccurrence, _o as resolveRemoteSource, _r as compositionSourceRefs, _t as FanPresetSchema, ai as fanAxisPath, ao as replacedFieldKeys, as as timedRunLimitOf, ba as normalizeCoreBlockWrite, bi as hasTimeLeaves, bn as TagStyleSchema, br as coreBlockAddonId, c as ActionError, ci as fanPresetsCapability, cn as SWITCH_DEFAULT_OPTIONS, cs as timedRunSeconds, ct as EMPTY_REMOTE_ASSUMED_STATE, cu as DeviceRole, d as ActionTargetResolver, di as findChannelSource, dl as defineEntryKind, do as resolveHeroLayout, dt as FAN_CAPTURE_FIELDS, eo as remoteLayoutComponentsCapability, f as ActionVariableSchema, fl as defineRecordKinds, fs as validateComposition, ft as FAN_OSCILLATION_AXES, fu as EventCategory$1, g as BUILTIN_AUTOMATION_TEMPLATES, gi as generateAutomationBlock, h as AutomationTemplatePayloadSchema, hl as entryBody, ht as FanControlStatusSchema, in as RunningStateStatusSchema, io as replaceRecipeLiteral, is as timedRunCapability, iu as vocabCall, j as ConditionMirror, jl as isSecretMarker, jn as addonIdOfActionId, jo as seedInstanceOnce, kn as actionWaitTotalMs, l as ActionMinDelaySecSchema, ll as defineAddonMigrations, ln as SchedulerError, lo as resolveCoreBlockEntry, lr as collectDeviceTemplates, ls as toTimings, lt as EMPTY_REMOTE_CONFIG, lu as DeviceType$1, m as AutomationStateDocSchema, mr as compileScalarOverride, ms as validateSchedulerInput, n as ACTION_TARGET_INVALIDATION_EVENTS, nn as RemoteAssumedStateSchema, no as removeFromTags, nr as canonicalStoredStepTargets, ns as tagsCapability, ol as commandOrigin$1, oo as resolveActionVariables, os as timedRunMaxIn, pn as SetOscillationAxisInputSchema, pt as FAN_OSCILLATION_AXIS_SETTABLE, qa as readStoredRemoteConfig, qc as actionEffect, ql as ruleFireOfClaim, qn as buildCapabilityLookup, qt as PowerSourceInfoSchema, rl as collectSecretMarkerRefs, rn as RemoteLayoutPayloadSchema, ro as renameInTags, rr as capUnitResolver, rs as templateCapability, ru as vocabActionIdFor, s as ALL_CAPABILITY_DEFINITIONS, sr as checkTemplatePayload, ss as timedRunQuickRun, st as EMPTY_AUTOMATION_STATE, ta as lockDoorLinkOfComposition, to as remoteSourceSteps, ts as tagKey, tt as DeclaredDevices, tu as transformSecretWrite, u as ActionStepSchema, uc as BaseAddon, un as SchedulerSchema, uo as resolveCoreBlockFiles, ur as collectWhenMirrorSources, uu as errMsg$1, va as nextTimeBoundaryInMs, vr as compositionUnionReads, wi as integrationInstancesCapability, wr as coreBlocksCapability, ws as zoneOnlySite, xa as normalizeTags, xi as heroLayoutCapability, xl as hydrateSchema, xn as TagsFieldSchema, xr as coreBlockComposition, ya as normalizeActionUnits, yn as TagNameSchema, yo as resolveStepArgs, ys as weekdayOfLocalDate, za as prepareRecipeUnits, zo as siteFor, zs as composedDeviceRef } from "../../dist-DbAhCrHy.mjs";
|
|
2
2
|
import { t as require_read_all_rows } from "../../read-all-rows-TaPqdWNF.mjs";
|
|
3
|
-
import { i as parseDeviceStateChanged, r as isRecord$1, t as describeCompositionSources } from "../../composition-sources-
|
|
4
|
-
import { i as capSeriesKey } from "../../capture-engine-
|
|
3
|
+
import { i as parseDeviceStateChanged, r as isRecord$1, t as describeCompositionSources } from "../../composition-sources-CznD85Ri.mjs";
|
|
4
|
+
import { i as capSeriesKey } from "../../capture-engine-sl6e9f9S.mjs";
|
|
5
5
|
import { t as prefixRange } from "../../prefix-range-Dl0znowN.mjs";
|
|
6
6
|
import { n as unwrapStoredValue, t as loadPrefixed } from "../../prefix-walk-DAOBSyH1.mjs";
|
|
7
7
|
import { n as readCurrentCommandOrigin } from "../../cap-call-scope-Bic6Ekfw.mjs";
|
|
@@ -10,7 +10,7 @@ import { z } from "zod";
|
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
11
|
import { customizationBlockName } from "@camstack/types/node";
|
|
12
12
|
import * as path$1 from "node:path";
|
|
13
|
-
import { nodeIdOfScopedKey } from "@camstack/types/addon";
|
|
13
|
+
import { isCapMethodAbsent, nodeIdOfScopedKey } from "@camstack/types/addon";
|
|
14
14
|
import * as fs from "node:fs/promises";
|
|
15
15
|
import { isDeepStrictEqual } from "node:util";
|
|
16
16
|
import * as os$1 from "node:os";
|
|
@@ -4105,10 +4105,23 @@ function buildActionsRuntime(deps) {
|
|
|
4105
4105
|
* The link and the off time are read from the STORED composition on each call
|
|
4106
4106
|
* (D676), never cached as a second copy. A forced restart is switch off now,
|
|
4107
4107
|
* switch on after `offSeconds`, through an injected scheduler so a spec drives
|
|
4108
|
-
* the clock; the pending switch-on is cancelled on `stop()`.
|
|
4108
|
+
* the clock; the pending switch-on is cancelled on `stop()`. A switch that declares
|
|
4109
|
+
* a native power cycle (a PoE port) is cycled in one call instead, and never
|
|
4110
|
+
* switched off or on. A switch that ANSWERED it only reports (D1058) is never
|
|
4111
|
+
* switched on or off: power on / off are refused as `not-settable`, and `getStatus`
|
|
4112
|
+
* says so (`switchSettable`) for the surfaces that withdraw them.
|
|
4109
4113
|
*
|
|
4110
4114
|
* Every refusal is a typed result with its reason, logged with the device tag.
|
|
4111
4115
|
*/
|
|
4116
|
+
/** `switch.getOptions` FAILED (not absent): what the switch can do is unknown. */
|
|
4117
|
+
var SwitchOptionsUnreadableError = class extends Error {
|
|
4118
|
+
switchDeviceId;
|
|
4119
|
+
constructor(switchDeviceId, cause) {
|
|
4120
|
+
super(`switch ${switchDeviceId}: its options could not be read (${cause instanceof Error ? cause.message : String(cause)}); not power-cycling and not switching it off blind`);
|
|
4121
|
+
this.name = "SwitchOptionsUnreadableError";
|
|
4122
|
+
this.switchDeviceId = switchDeviceId;
|
|
4123
|
+
}
|
|
4124
|
+
};
|
|
4112
4125
|
var timeoutScheduler = { schedule: (delayMs, fire) => {
|
|
4113
4126
|
const handle = setTimeout(fire, delayMs);
|
|
4114
4127
|
return { cancel: () => clearTimeout(handle) };
|
|
@@ -4118,28 +4131,40 @@ var PowerSourceService = class {
|
|
|
4118
4131
|
deps;
|
|
4119
4132
|
/** Restarts whose switch-on has not run yet, by device id. */
|
|
4120
4133
|
restarting = /* @__PURE__ */ new Map();
|
|
4134
|
+
/**
|
|
4135
|
+
* Devices whose switch-options read is failing now: warned once per streak, cleared by a
|
|
4136
|
+
* success or when the device is no longer linked. A removed device leaves at most one bare id
|
|
4137
|
+
* behind (this service has no removal hook); the set dies with the process.
|
|
4138
|
+
*/
|
|
4139
|
+
optionsReadFailing = /* @__PURE__ */ new Set();
|
|
4121
4140
|
constructor(deps) {
|
|
4122
4141
|
this.deps = deps;
|
|
4123
4142
|
}
|
|
4124
4143
|
getStatus = async ({ deviceId }) => {
|
|
4125
4144
|
const link = await this.linkOf(deviceId);
|
|
4126
|
-
if (link === null)
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4145
|
+
if (link === null) {
|
|
4146
|
+
this.optionsReadFailing.delete(deviceId);
|
|
4147
|
+
return {
|
|
4148
|
+
linked: false,
|
|
4149
|
+
switchDeviceId: null,
|
|
4150
|
+
switchName: null,
|
|
4151
|
+
switchOn: null,
|
|
4152
|
+
switchOnline: null,
|
|
4153
|
+
switchSettable: null,
|
|
4154
|
+
restartInProgress: false,
|
|
4155
|
+
offSeconds: 0
|
|
4156
|
+
};
|
|
4157
|
+
}
|
|
4135
4158
|
const switchDevice = await this.deps.devices.find(link.switch).catch(() => null);
|
|
4136
4159
|
const switchOn = switchDevice === null ? null : await this.deps.devices.readOn(switchDevice.id).catch(() => null);
|
|
4160
|
+
const switchSettable = switchDevice === null ? null : await this.settableOf(deviceId, switchDevice.id);
|
|
4137
4161
|
return {
|
|
4138
4162
|
linked: true,
|
|
4139
4163
|
switchDeviceId: switchDevice?.id ?? null,
|
|
4140
4164
|
switchName: switchDevice?.name ?? link.switch.stableId,
|
|
4141
4165
|
switchOn,
|
|
4142
4166
|
switchOnline: switchDevice?.online ?? null,
|
|
4167
|
+
switchSettable,
|
|
4143
4168
|
restartInProgress: this.restarting.has(deviceId),
|
|
4144
4169
|
offSeconds: link.offSeconds
|
|
4145
4170
|
};
|
|
@@ -4161,6 +4186,28 @@ var PowerSourceService = class {
|
|
|
4161
4186
|
const { link, switchDevice } = lookup.resolved;
|
|
4162
4187
|
const switchId = switchDevice.id;
|
|
4163
4188
|
pending.switchId = switchId;
|
|
4189
|
+
const cycle = this.deps.devices.cycle;
|
|
4190
|
+
if (cycle !== void 0) {
|
|
4191
|
+
let cycled;
|
|
4192
|
+
try {
|
|
4193
|
+
cycled = await cycle(switchId);
|
|
4194
|
+
} catch (err) {
|
|
4195
|
+
this.restarting.delete(deviceId);
|
|
4196
|
+
const reason = err instanceof SwitchOptionsUnreadableError ? "switch-options-unreadable" : "switch-call-failed";
|
|
4197
|
+
return this.refuse(deviceId, reason, errorText$3(err), switchId);
|
|
4198
|
+
}
|
|
4199
|
+
if (cycled) {
|
|
4200
|
+
this.restarting.delete(deviceId);
|
|
4201
|
+
this.deps.logger.info("power-source: forced restart through the switch’s native power cycle", {
|
|
4202
|
+
tags: { deviceId },
|
|
4203
|
+
meta: {
|
|
4204
|
+
switchId,
|
|
4205
|
+
switchName: switchDevice.name
|
|
4206
|
+
}
|
|
4207
|
+
});
|
|
4208
|
+
return ACCEPTED;
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
4164
4211
|
try {
|
|
4165
4212
|
await this.deps.devices.setOn(switchId, false);
|
|
4166
4213
|
} catch (err) {
|
|
@@ -4215,6 +4262,7 @@ var PowerSourceService = class {
|
|
|
4215
4262
|
const lookup = await this.lookup(deviceId);
|
|
4216
4263
|
if (lookup.kind === "refused") return this.refuse(deviceId, lookup.reason, lookup.message, null);
|
|
4217
4264
|
const { switchDevice } = lookup.resolved;
|
|
4265
|
+
if (await this.settableOf(deviceId, switchDevice.id) === false) return this.refuse(deviceId, "not-settable", `the switch ${switchDevice.name} only reports its state; it cannot be switched ${on ? "on" : "off"}`, switchDevice.id);
|
|
4218
4266
|
try {
|
|
4219
4267
|
await this.deps.devices.setOn(switchDevice.id, on);
|
|
4220
4268
|
} catch (err) {
|
|
@@ -4229,6 +4277,32 @@ var PowerSourceService = class {
|
|
|
4229
4277
|
});
|
|
4230
4278
|
return ACCEPTED;
|
|
4231
4279
|
}
|
|
4280
|
+
/**
|
|
4281
|
+
* Whether the switch can be set: `true` for a plain switch (no options reader, or a provider
|
|
4282
|
+
* without `getOptions`), `null` when the read FAILED — never `false` for unknown. Every hero
|
|
4283
|
+
* build reads `getStatus`, so a failing read warns once per device per failure streak (tagged);
|
|
4284
|
+
* a successful read ends the streak.
|
|
4285
|
+
*/
|
|
4286
|
+
async settableOf(deviceId, switchId) {
|
|
4287
|
+
const options = this.deps.devices.options;
|
|
4288
|
+
if (options === void 0) return true;
|
|
4289
|
+
try {
|
|
4290
|
+
const settable = (await options(switchId)).supportsSetState;
|
|
4291
|
+
this.optionsReadFailing.delete(deviceId);
|
|
4292
|
+
return settable;
|
|
4293
|
+
} catch (err) {
|
|
4294
|
+
if (this.optionsReadFailing.has(deviceId)) return null;
|
|
4295
|
+
this.optionsReadFailing.add(deviceId);
|
|
4296
|
+
this.deps.logger.warn("power-source: the switch options could not be read; settable unknown", {
|
|
4297
|
+
tags: { deviceId },
|
|
4298
|
+
meta: {
|
|
4299
|
+
switchId,
|
|
4300
|
+
error: errorText$3(err)
|
|
4301
|
+
}
|
|
4302
|
+
});
|
|
4303
|
+
return null;
|
|
4304
|
+
}
|
|
4305
|
+
}
|
|
4232
4306
|
/** The link and the switch, or the reason there is nothing to act on. Reads the switch state: unknown is refused. */
|
|
4233
4307
|
async lookup(deviceId) {
|
|
4234
4308
|
const stored = await this.storedLinkOf(deviceId);
|
|
@@ -6201,6 +6275,8 @@ var RemoteComponentsService = class {
|
|
|
6201
6275
|
* count comes from the remote cap and is `null` when it cannot be asked.
|
|
6202
6276
|
*/
|
|
6203
6277
|
var REMOTE_CAP = "remote";
|
|
6278
|
+
var SWITCH_CAP = "switch";
|
|
6279
|
+
var POWER_SOURCE_CAP = "power-source";
|
|
6204
6280
|
/** Models built at once for a list; the cap bounds the list, this bounds the fan-out on the registry. */
|
|
6205
6281
|
var ROW_MODELS_CONCURRENCY = 16;
|
|
6206
6282
|
var HeroLayoutService = class {
|
|
@@ -6235,6 +6311,8 @@ var HeroLayoutService = class {
|
|
|
6235
6311
|
}
|
|
6236
6312
|
}));
|
|
6237
6313
|
const remoteCommands = await this.remoteCommands(deviceId);
|
|
6314
|
+
const switchOptions = bound.includes(SWITCH_CAP) ? await this.switchOptions(deviceId) : void 0;
|
|
6315
|
+
const powerSupplySettable = bound.includes(POWER_SOURCE_CAP) ? await this.powerSupplySettable(deviceId) : null;
|
|
6238
6316
|
return buildHeroModel({
|
|
6239
6317
|
device: {
|
|
6240
6318
|
id: deviceId,
|
|
@@ -6250,7 +6328,9 @@ var HeroLayoutService = class {
|
|
|
6250
6328
|
slices,
|
|
6251
6329
|
now: this.deps.now(),
|
|
6252
6330
|
remoteCommands,
|
|
6253
|
-
access: { canActuate: canActuate ?? true }
|
|
6331
|
+
access: { canActuate: canActuate ?? true },
|
|
6332
|
+
...switchOptions !== void 0 ? { switchOptions } : {},
|
|
6333
|
+
powerSupplySettable
|
|
6254
6334
|
});
|
|
6255
6335
|
};
|
|
6256
6336
|
/**
|
|
@@ -6283,6 +6363,34 @@ var HeroLayoutService = class {
|
|
|
6283
6363
|
return null;
|
|
6284
6364
|
}
|
|
6285
6365
|
}
|
|
6366
|
+
/**
|
|
6367
|
+
* What the switch can do. A provider without `getOptions` answers the defaults through the
|
|
6368
|
+
* reader; a read that FAILED is unknown — the hero draws on/off, as before (D315) — and is
|
|
6369
|
+
* logged with the device.
|
|
6370
|
+
*/
|
|
6371
|
+
async switchOptions(deviceId) {
|
|
6372
|
+
try {
|
|
6373
|
+
return await this.deps.reader.switchOptions(deviceId);
|
|
6374
|
+
} catch (error) {
|
|
6375
|
+
this.deps.logger.warn("hero model: the switch options could not be read; on/off drawn", {
|
|
6376
|
+
tags: { deviceId },
|
|
6377
|
+
meta: { error: error instanceof Error ? error.message : String(error) }
|
|
6378
|
+
});
|
|
6379
|
+
return;
|
|
6380
|
+
}
|
|
6381
|
+
}
|
|
6382
|
+
/** Whether the supply's switch can be set; a failed read is unknown (on/off drawn), logged. */
|
|
6383
|
+
async powerSupplySettable(deviceId) {
|
|
6384
|
+
try {
|
|
6385
|
+
return await this.deps.reader.powerSupplySettable(deviceId);
|
|
6386
|
+
} catch (error) {
|
|
6387
|
+
this.deps.logger.warn("hero model: the power supply status could not be read; power on/off drawn", {
|
|
6388
|
+
tags: { deviceId },
|
|
6389
|
+
meta: { error: error instanceof Error ? error.message : String(error) }
|
|
6390
|
+
});
|
|
6391
|
+
return null;
|
|
6392
|
+
}
|
|
6393
|
+
}
|
|
6286
6394
|
async remoteCommands(deviceId) {
|
|
6287
6395
|
try {
|
|
6288
6396
|
return await this.deps.reader.remoteCommands(deviceId);
|
|
@@ -6407,6 +6515,54 @@ async function seedLockDoors(deps) {
|
|
|
6407
6515
|
}
|
|
6408
6516
|
}
|
|
6409
6517
|
//#endregion
|
|
6518
|
+
//#region src/builtins/core-blocks/power-source-devices.ts
|
|
6519
|
+
/**
|
|
6520
|
+
* The devices `power-source` acts on, reached over `ctx.api`: the linked switch is read,
|
|
6521
|
+
* set, and — when its provider declares a native power cycle — cycled in one call.
|
|
6522
|
+
*/
|
|
6523
|
+
/** The switch's options; the defaults when its provider has no `getOptions`; throws typed when the read failed. */
|
|
6524
|
+
async function switchOptionsOf(api, deviceId) {
|
|
6525
|
+
try {
|
|
6526
|
+
return await api.switch.getOptions.query({ deviceId });
|
|
6527
|
+
} catch (err) {
|
|
6528
|
+
if (isCapMethodAbsent(err)) return SWITCH_DEFAULT_OPTIONS;
|
|
6529
|
+
throw new SwitchOptionsUnreadableError(deviceId, err);
|
|
6530
|
+
}
|
|
6531
|
+
}
|
|
6532
|
+
function powerSourceDevicesOver(requireApi) {
|
|
6533
|
+
return {
|
|
6534
|
+
find: async (ref) => {
|
|
6535
|
+
const row = (await requireApi().deviceManager.listAll.query({
|
|
6536
|
+
addonId: ref.addonId,
|
|
6537
|
+
projection: "slim"
|
|
6538
|
+
})).find((r) => r.stableId === ref.stableId);
|
|
6539
|
+
return row === void 0 ? null : {
|
|
6540
|
+
id: row.id,
|
|
6541
|
+
name: row.name,
|
|
6542
|
+
online: row.online
|
|
6543
|
+
};
|
|
6544
|
+
},
|
|
6545
|
+
readOn: async (deviceId) => {
|
|
6546
|
+
const status = await requireApi().switch.getStatus.query({ deviceId });
|
|
6547
|
+
const on = status !== null && typeof status === "object" ? Reflect.get(status, "on") : void 0;
|
|
6548
|
+
return typeof on === "boolean" ? on : null;
|
|
6549
|
+
},
|
|
6550
|
+
setOn: async (deviceId, on) => {
|
|
6551
|
+
await requireApi().switch.setState.mutate({
|
|
6552
|
+
deviceId,
|
|
6553
|
+
on
|
|
6554
|
+
});
|
|
6555
|
+
},
|
|
6556
|
+
options: (deviceId) => switchOptionsOf(requireApi(), deviceId),
|
|
6557
|
+
cycle: async (deviceId) => {
|
|
6558
|
+
const api = requireApi();
|
|
6559
|
+
if (!(await switchOptionsOf(api, deviceId)).supportsPowerCycle) return false;
|
|
6560
|
+
await api.switch.powerCycle.mutate({ deviceId });
|
|
6561
|
+
return true;
|
|
6562
|
+
}
|
|
6563
|
+
};
|
|
6564
|
+
}
|
|
6565
|
+
//#endregion
|
|
6410
6566
|
//#region src/builtins/core-blocks/fan-link-forward.ts
|
|
6411
6567
|
/**
|
|
6412
6568
|
* A write to a fan-control field the operator linked in Customize goes to the
|
|
@@ -9241,14 +9397,16 @@ async function writeComposedDeviceName(port, logger, blockId, name) {
|
|
|
9241
9397
|
//#region src/builtins/core-blocks/tags-service.ts
|
|
9242
9398
|
/**
|
|
9243
9399
|
* The `tags` cap (D1054). A tag lives on the record it labels — a core block, a
|
|
9244
|
-
* scheduler, a template, an action, a device — and only
|
|
9245
|
-
* icon) is registered here. This service is the one place that knows every owner
|
|
9400
|
+
* scheduler, a template, an action, a device, a notification rule — and only
|
|
9401
|
+
* its STYLE (colour token, icon) is registered here. This service is the one place that knows every owner
|
|
9246
9402
|
* kind, so `rename` and `remove` are ONE server operation that rewrites all of
|
|
9247
9403
|
* them; the browser never drives that sequence (a closed tab would split the
|
|
9248
9404
|
* fleet across two spellings).
|
|
9249
9405
|
*
|
|
9250
9406
|
* Owners are reached through {@link TagOwnerPort}s: the local stores directly,
|
|
9251
|
-
* the devices through
|
|
9407
|
+
* the devices and notification rules through their caps over `ctx.api` — never
|
|
9408
|
+
* a second copy. An owner that cannot be read degrades `list` (its count is
|
|
9409
|
+
* `null`) and refuses `rename` / `remove` before any write.
|
|
9252
9410
|
* Tags compare trimmed and case-insensitively (`sameTag`).
|
|
9253
9411
|
*/
|
|
9254
9412
|
/** The order owners are read and rewritten in; also the order a first spelling is picked. */
|
|
@@ -9257,14 +9415,39 @@ var OWNER_KINDS = [
|
|
|
9257
9415
|
"schedulers",
|
|
9258
9416
|
"templates",
|
|
9259
9417
|
"actions",
|
|
9260
|
-
"devices"
|
|
9418
|
+
"devices",
|
|
9419
|
+
"notificationRules"
|
|
9261
9420
|
];
|
|
9421
|
+
/** The list counts: an owner that could not be read is `null`, never `0` (D393). */
|
|
9422
|
+
function withUnknown(counts, unreachable) {
|
|
9423
|
+
return {
|
|
9424
|
+
coreBlocks: unreachable.has("coreBlocks") ? null : counts.coreBlocks,
|
|
9425
|
+
schedulers: unreachable.has("schedulers") ? null : counts.schedulers,
|
|
9426
|
+
templates: unreachable.has("templates") ? null : counts.templates,
|
|
9427
|
+
actions: unreachable.has("actions") ? null : counts.actions,
|
|
9428
|
+
devices: unreachable.has("devices") ? null : counts.devices,
|
|
9429
|
+
notificationRules: unreachable.has("notificationRules") ? null : counts.notificationRules
|
|
9430
|
+
};
|
|
9431
|
+
}
|
|
9432
|
+
/**
|
|
9433
|
+
* A rename or remove refused because one owner kind could not be read. Nothing
|
|
9434
|
+
* was written; `owner` names which one, so the operator knows what to bring back.
|
|
9435
|
+
*/
|
|
9436
|
+
var TagOwnerUnreachableError = class extends Error {
|
|
9437
|
+
owner;
|
|
9438
|
+
name = "TagOwnerUnreachableError";
|
|
9439
|
+
constructor(owner, tag, cause) {
|
|
9440
|
+
super(`[tags] "${tag}" was not changed anywhere: the ${owner} owner could not be read (${cause instanceof Error ? cause.message : String(cause)}); nothing was written — retry once it is back`, { cause });
|
|
9441
|
+
this.owner = owner;
|
|
9442
|
+
}
|
|
9443
|
+
};
|
|
9262
9444
|
var NO_UPDATES = {
|
|
9263
9445
|
coreBlocks: 0,
|
|
9264
9446
|
schedulers: 0,
|
|
9265
9447
|
templates: 0,
|
|
9266
9448
|
actions: 0,
|
|
9267
|
-
devices: 0
|
|
9449
|
+
devices: 0,
|
|
9450
|
+
notificationRules: 0
|
|
9268
9451
|
};
|
|
9269
9452
|
function requireName(value, what) {
|
|
9270
9453
|
const parsed = TagNameSchema.safeParse(value);
|
|
@@ -9288,12 +9471,27 @@ var TagsService = class {
|
|
|
9288
9471
|
}
|
|
9289
9472
|
list = async () => {
|
|
9290
9473
|
const styles = new Map((await this.readStyles()).map((s) => [tagKey(s.name), s]));
|
|
9474
|
+
const unreachable = /* @__PURE__ */ new Set();
|
|
9475
|
+
const read = [];
|
|
9476
|
+
for (const kind of OWNER_KINDS) try {
|
|
9477
|
+
read.push({
|
|
9478
|
+
kind,
|
|
9479
|
+
records: await this.deps.owners[kind].list()
|
|
9480
|
+
});
|
|
9481
|
+
} catch (err) {
|
|
9482
|
+
unreachable.add(kind);
|
|
9483
|
+
this.deps.logger.warn("tag owner could not be read — its count is unknown on this list", { meta: {
|
|
9484
|
+
owner: kind,
|
|
9485
|
+
error: err instanceof Error ? err.message : String(err)
|
|
9486
|
+
} });
|
|
9487
|
+
}
|
|
9488
|
+
const zero = () => ({ ...NO_UPDATES });
|
|
9291
9489
|
const entries = /* @__PURE__ */ new Map();
|
|
9292
9490
|
for (const style of styles.values()) entries.set(tagKey(style.name), {
|
|
9293
9491
|
name: style.name,
|
|
9294
|
-
counts:
|
|
9492
|
+
counts: zero()
|
|
9295
9493
|
});
|
|
9296
|
-
for (const kind of
|
|
9494
|
+
for (const { kind, records } of read) for (const record of records) {
|
|
9297
9495
|
const seen = /* @__PURE__ */ new Set();
|
|
9298
9496
|
for (const tag of record.tags) {
|
|
9299
9497
|
const key = tagKey(tag);
|
|
@@ -9301,7 +9499,7 @@ var TagsService = class {
|
|
|
9301
9499
|
seen.add(key);
|
|
9302
9500
|
const entry = entries.get(key) ?? {
|
|
9303
9501
|
name: tag.trim(),
|
|
9304
|
-
counts:
|
|
9502
|
+
counts: zero()
|
|
9305
9503
|
};
|
|
9306
9504
|
entry.counts[kind] += 1;
|
|
9307
9505
|
entries.set(key, entry);
|
|
@@ -9315,7 +9513,7 @@ var TagsService = class {
|
|
|
9315
9513
|
color: style?.color ?? defaultTagColorId(entry.name),
|
|
9316
9514
|
icon: style?.icon ?? "tag",
|
|
9317
9515
|
styled: style !== void 0,
|
|
9318
|
-
counts: entry.counts
|
|
9516
|
+
counts: withUnknown(entry.counts, unreachable)
|
|
9319
9517
|
});
|
|
9320
9518
|
}
|
|
9321
9519
|
return out.toSorted((a, b) => a.name.localeCompare(b.name));
|
|
@@ -9363,7 +9561,7 @@ var TagsService = class {
|
|
|
9363
9561
|
const updated = { ...NO_UPDATES };
|
|
9364
9562
|
const failed = [];
|
|
9365
9563
|
const plan = [];
|
|
9366
|
-
for (const kind of OWNER_KINDS) for (const record of await this.
|
|
9564
|
+
for (const kind of OWNER_KINDS) for (const record of await this.readOwnerOrRefuse(kind, tag)) {
|
|
9367
9565
|
const next = change(record.tags);
|
|
9368
9566
|
if (next === null) continue;
|
|
9369
9567
|
if (next.length > 20) throw new Error(`[tags] "${tag}" cannot be applied: ${kind}:${record.id} would carry ${next.length} tags (max 20); nothing was written`);
|
|
@@ -9392,6 +9590,18 @@ var TagsService = class {
|
|
|
9392
9590
|
if (failed.length > 0) throw new Error(`[tags] "${tag}" was not rewritten on ${failed.length} record(s) (${failed.slice(0, 5).join(", ")}); the style was left alone — repeat the call`);
|
|
9393
9591
|
return updated;
|
|
9394
9592
|
}
|
|
9593
|
+
/**
|
|
9594
|
+
* An owner's records for a rewrite. One that cannot be read refuses the whole
|
|
9595
|
+
* call BEFORE anything is written: a rename applied to only some owners would
|
|
9596
|
+
* leave the fleet split across two spellings.
|
|
9597
|
+
*/
|
|
9598
|
+
async readOwnerOrRefuse(kind, tag) {
|
|
9599
|
+
try {
|
|
9600
|
+
return await this.deps.owners[kind].list();
|
|
9601
|
+
} catch (err) {
|
|
9602
|
+
throw new TagOwnerUnreachableError(kind, tag, err);
|
|
9603
|
+
}
|
|
9604
|
+
}
|
|
9395
9605
|
/** The style follows the tag; a merge onto a styled target keeps the TARGET's style. */
|
|
9396
9606
|
async moveStyle(from, to) {
|
|
9397
9607
|
const fromKey = tagKey(from);
|
|
@@ -9422,7 +9632,8 @@ var TagsService = class {
|
|
|
9422
9632
|
//#region src/builtins/core-blocks/tags-wiring.ts
|
|
9423
9633
|
/**
|
|
9424
9634
|
* Builds the `tags` cap provider (D1054) over the stores core-blocks owns and the
|
|
9425
|
-
* device manager (over `ctx.api`, never a copy of
|
|
9635
|
+
* device manager and the notification rules (over `ctx.api`, never a copy of
|
|
9636
|
+
* their data).
|
|
9426
9637
|
*/
|
|
9427
9638
|
function coreBlocksPort(blocks) {
|
|
9428
9639
|
return {
|
|
@@ -9504,6 +9715,47 @@ function devicesPort(api) {
|
|
|
9504
9715
|
}
|
|
9505
9716
|
};
|
|
9506
9717
|
}
|
|
9718
|
+
function needApi(api) {
|
|
9719
|
+
const current = api();
|
|
9720
|
+
if (current === void 0) throw new Error("[tags] the cluster API is not available yet");
|
|
9721
|
+
return current;
|
|
9722
|
+
}
|
|
9723
|
+
/**
|
|
9724
|
+
* A notification rule's owner-port id is `<kind>:<ruleId>`: event rules,
|
|
9725
|
+
* summaries, timelapses and calendar-events rules live in separate stores, so
|
|
9726
|
+
* the write must name which one.
|
|
9727
|
+
*/
|
|
9728
|
+
function ruleTagOwnerId(kind, ruleId) {
|
|
9729
|
+
return `${kind}:${ruleId}`;
|
|
9730
|
+
}
|
|
9731
|
+
function parseRuleTagOwnerId(id) {
|
|
9732
|
+
const sep = id.indexOf(":");
|
|
9733
|
+
const kind = NcTaggedRuleKindSchema.safeParse(sep < 0 ? "" : id.slice(0, sep));
|
|
9734
|
+
if (!kind.success) throw new Error(`[tags] not a notification-rule owner id: ${id}`);
|
|
9735
|
+
return {
|
|
9736
|
+
kind: kind.data,
|
|
9737
|
+
ruleId: id.slice(sep + 1)
|
|
9738
|
+
};
|
|
9739
|
+
}
|
|
9740
|
+
function notificationRulesPort(api) {
|
|
9741
|
+
return {
|
|
9742
|
+
list: async () => {
|
|
9743
|
+
const { rules } = await needApi(api).notificationRules.listRuleTags.query({});
|
|
9744
|
+
return rules.map((r) => ({
|
|
9745
|
+
id: ruleTagOwnerId(r.kind, r.ruleId),
|
|
9746
|
+
tags: r.tags
|
|
9747
|
+
}));
|
|
9748
|
+
},
|
|
9749
|
+
setTags: async (id, tags) => {
|
|
9750
|
+
const { kind, ruleId } = parseRuleTagOwnerId(id);
|
|
9751
|
+
await needApi(api).notificationRules.setRuleTags.mutate({
|
|
9752
|
+
kind,
|
|
9753
|
+
ruleId,
|
|
9754
|
+
tags
|
|
9755
|
+
});
|
|
9756
|
+
}
|
|
9757
|
+
};
|
|
9758
|
+
}
|
|
9507
9759
|
function buildTagsService(deps) {
|
|
9508
9760
|
const { records } = deps;
|
|
9509
9761
|
return new TagsService({
|
|
@@ -9518,7 +9770,8 @@ function buildTagsService(deps) {
|
|
|
9518
9770
|
actions: records.kind(coreBlocksRecordKinds.actions),
|
|
9519
9771
|
links: records.kind(coreBlocksRecordKinds["action-links"])
|
|
9520
9772
|
})),
|
|
9521
|
-
devices: deps.devices ?? devicesPort(deps.api)
|
|
9773
|
+
devices: deps.devices ?? devicesPort(deps.api),
|
|
9774
|
+
notificationRules: deps.notificationRules ?? notificationRulesPort(deps.api)
|
|
9522
9775
|
},
|
|
9523
9776
|
styles: records.kind(coreBlocksRecordKinds["tag-styles"]),
|
|
9524
9777
|
logger: deps.logger
|
|
@@ -9793,7 +10046,9 @@ var CoreBlocksAddon = class extends BaseAddon {
|
|
|
9793
10046
|
deviceId,
|
|
9794
10047
|
capName
|
|
9795
10048
|
}),
|
|
9796
|
-
remoteCommands: async (deviceId) => (await requireApi().remote.listCommands.query({ deviceId })).commands.length
|
|
10049
|
+
remoteCommands: async (deviceId) => (await requireApi().remote.listCommands.query({ deviceId })).commands.length,
|
|
10050
|
+
switchOptions: (deviceId) => switchOptionsOf(requireApi(), deviceId),
|
|
10051
|
+
powerSupplySettable: async (deviceId) => (await requireApi().powerSource.getStatus.query({ deviceId })).switchSettable ?? null
|
|
9797
10052
|
}
|
|
9798
10053
|
});
|
|
9799
10054
|
}
|
|
@@ -9813,30 +10068,7 @@ var CoreBlocksAddon = class extends BaseAddon {
|
|
|
9813
10068
|
if (!api) throw new Error("core-blocks: no ctx.api on this node — power-source cannot reach devices");
|
|
9814
10069
|
return api;
|
|
9815
10070
|
};
|
|
9816
|
-
return
|
|
9817
|
-
find: async (ref) => {
|
|
9818
|
-
const row = (await requireApi().deviceManager.listAll.query({
|
|
9819
|
-
addonId: ref.addonId,
|
|
9820
|
-
projection: "slim"
|
|
9821
|
-
})).find((r) => r.stableId === ref.stableId);
|
|
9822
|
-
return row === void 0 ? null : {
|
|
9823
|
-
id: row.id,
|
|
9824
|
-
name: row.name,
|
|
9825
|
-
online: row.online
|
|
9826
|
-
};
|
|
9827
|
-
},
|
|
9828
|
-
readOn: async (deviceId) => {
|
|
9829
|
-
const status = await requireApi().switch.getStatus.query({ deviceId });
|
|
9830
|
-
const on = status !== null && typeof status === "object" ? Reflect.get(status, "on") : void 0;
|
|
9831
|
-
return typeof on === "boolean" ? on : null;
|
|
9832
|
-
},
|
|
9833
|
-
setOn: async (deviceId, on) => {
|
|
9834
|
-
await requireApi().switch.setState.mutate({
|
|
9835
|
-
deviceId,
|
|
9836
|
-
on
|
|
9837
|
-
});
|
|
9838
|
-
}
|
|
9839
|
-
};
|
|
10071
|
+
return powerSourceDevicesOver(requireApi);
|
|
9840
10072
|
}
|
|
9841
10073
|
buildRemote(records) {
|
|
9842
10074
|
const settings = this.ctx.settings;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* says "not answered", never "off" (D315/D393). The remote's saved command
|
|
9
9
|
* count comes from the remote cap and is `null` when it cannot be asked.
|
|
10
10
|
*/
|
|
11
|
-
import { type IHeroLayoutProvider, type IScopedLogger, type ReadingQuantity } from "@camstack/types";
|
|
11
|
+
import { type IHeroLayoutProvider, type IScopedLogger, type ReadingQuantity, type SwitchOptions } from "@camstack/types";
|
|
12
12
|
/** What the registry says about the device. */
|
|
13
13
|
export interface HeroDeviceFacts {
|
|
14
14
|
readonly type: string;
|
|
@@ -31,6 +31,16 @@ export interface HeroLayoutReader {
|
|
|
31
31
|
readonly slice: (deviceId: number, capName: string) => Promise<unknown>;
|
|
32
32
|
/** Saved remote commands; throws when the remote cannot be asked. */
|
|
33
33
|
readonly remoteCommands: (deviceId: number) => Promise<number>;
|
|
34
|
+
/**
|
|
35
|
+
* The `switch` provider's `getOptions`: the defaults when it has none (a plain on/off switch);
|
|
36
|
+
* throws when it cannot be asked.
|
|
37
|
+
*/
|
|
38
|
+
readonly switchOptions: (deviceId: number) => Promise<SwitchOptions>;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the switch that powers the device can be set (`power-source.getStatus().switchSettable`);
|
|
41
|
+
* `null` = not known. Throws when it cannot be asked.
|
|
42
|
+
*/
|
|
43
|
+
readonly powerSupplySettable: (deviceId: number) => Promise<boolean | null>;
|
|
34
44
|
}
|
|
35
45
|
export interface HeroLayoutServiceDeps {
|
|
36
46
|
readonly reader: HeroLayoutReader;
|
|
@@ -49,5 +59,13 @@ export declare class HeroLayoutService implements IHeroLayoutProvider {
|
|
|
49
59
|
*/
|
|
50
60
|
readonly getRowModels: IHeroLayoutProvider["getRowModels"];
|
|
51
61
|
private rowOf;
|
|
62
|
+
/**
|
|
63
|
+
* What the switch can do. A provider without `getOptions` answers the defaults through the
|
|
64
|
+
* reader; a read that FAILED is unknown — the hero draws on/off, as before (D315) — and is
|
|
65
|
+
* logged with the device.
|
|
66
|
+
*/
|
|
67
|
+
private switchOptions;
|
|
68
|
+
/** Whether the supply's switch can be set; a failed read is unknown (on/off drawn), logged. */
|
|
69
|
+
private powerSupplySettable;
|
|
52
70
|
private remoteCommands;
|
|
53
71
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The devices `power-source` acts on, reached over `ctx.api`: the linked switch is read,
|
|
3
|
+
* set, and — when its provider declares a native power cycle — cycled in one call.
|
|
4
|
+
*/
|
|
5
|
+
import { type AddonApi, type SwitchOptions } from "@camstack/types";
|
|
6
|
+
import { type PowerSourceDevices } from "./power-source-service.js";
|
|
7
|
+
/** The switch's options; the defaults when its provider has no `getOptions`; throws typed when the read failed. */
|
|
8
|
+
export declare function switchOptionsOf(api: AddonApi, deviceId: number): Promise<SwitchOptions>;
|
|
9
|
+
export declare function powerSourceDevicesOver(requireApi: () => AddonApi): PowerSourceDevices;
|