@camstack/addon-provider-hikvision 1.2.135 → 1.2.136

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/addon.js +240 -229
  2. package/dist/addon.mjs +240 -229
  3. package/package.json +1 -1
package/dist/addon.js CHANGED
@@ -33,7 +33,7 @@ let node_net = require("node:net");
33
33
  let node_http = require("node:http");
34
34
  let node_https = require("node:https");
35
35
  let node_os = require("node:os");
36
- //#region ../types/dist/event-category-C5xZWqz6.mjs
36
+ //#region ../types/dist/event-category-BGmz_oxW.mjs
37
37
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
38
38
  EventCategory["SystemBoot"] = "system.boot";
39
39
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -566,6 +566,15 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
566
566
  */
567
567
  EventCategory["PipelineAudioInferenceResult"] = "pipeline.audio-inference-result";
568
568
  EventCategory["DetectionPhaseTransition"] = "detection.phase-transition";
569
+ /**
570
+ * A camera provider's RAW onboard motion push (D673): the `MotionOnMotionChanged`
571
+ * data shape without `triggeredBy`, built by `providerMotionEvent`. Its one
572
+ * consumer is the orchestrator's camera-sensors bridge, which re-emits the
573
+ * camera's EFFECTIVE onboard motion as `MotionOnMotionChanged` (a pass-through
574
+ * for a camera with no attached sensor). Providers must not emit
575
+ * `MotionOnMotionChanged` themselves; `scripts/check-onboard-motion-emitters.ts`
576
+ * keeps it so (camera-grid is a named, deferred exception).
577
+ */
569
578
  EventCategory["ProviderMotion"] = "provider.motion";
570
579
  EventCategory["ProviderDetection"] = "provider.detection";
571
580
  EventCategory["EnrichmentEmbeddingStored"] = "enrichment.embedding.stored";
@@ -5404,7 +5413,7 @@ var ZodIssueCode = {
5404
5413
  var ZodFirstPartyTypeKind;
5405
5414
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5406
5415
  //#endregion
5407
- //#region ../types/dist/sleep-gU6hqv4_.mjs
5416
+ //#region ../types/dist/sleep-CDCONfkt.mjs
5408
5417
  /**
5409
5418
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5410
5419
  * window to float samples (D455).
@@ -7449,7 +7458,7 @@ var DeviceRole = /* @__PURE__ */ function(DeviceRole) {
7449
7458
  return DeviceRole;
7450
7459
  }({});
7451
7460
  //#endregion
7452
- //#region ../types/dist/composition-Dq42XWp0.mjs
7461
+ //#region ../types/dist/composition-43aqsZQj.mjs
7453
7462
  /**
7454
7463
  * The ffmpeg build every CamStack node downloads, per platform and arch.
7455
7464
  *
@@ -7506,13 +7515,12 @@ portable("linux64"), portable("linuxarm64"), portable("macarm64"), portable("mac
7506
7515
  * LA tabella "quale booleano di questo tipo di device conta come ALTO", e il
7507
7516
  * valutatore puro del suo FRONTE.
7508
7517
  *
7509
- * Viveva dentro il builtin virtual-doorbell
7510
- * (`@camstack/system` — `builtins/doorbell/trigger-engine.ts`) e i suoi
7511
- * predicati erano privati al modulo. Il recorder ne ha bisogno per il trigger
7512
- * `RecordingTriggers.sensorDeviceIds`: copiarla avrebbe creato la SECONDA
7513
- * tabella, che diverge alla prima cap aggiunta e il cui sintomo — "il sensore
7514
- * fa suonare il campanello ma non registra" — è esattamente D62. Quindi si
7515
- * SPOSTA qui e il doorbell la ri-esporta.
7518
+ * UNA tabella per tutti quelli che chiedono "questo device è ALTO?": il
7519
+ * trigger `RecordingTriggers.sensorDeviceIds` del recorder, i marker dei
7520
+ * sensori della post-analysis, il bridge camera-sensors dell'orchestratore e
7521
+ * le sorgenti di un campanello composto (`doorbellFeatureSources`, D671).
7522
+ * Una seconda copia divergerebbe alla prima cap aggiunta, e il sintomo — "il
7523
+ * sensore fa suonare il campanello ma non registra" — è esattamente D62.
7516
7524
  *
7517
7525
  * ⚠ NON è `DEVICE_STATE_READERS` (`catalogs/device-state-vocabulary.ts`), e le
7518
7526
  * due non vanno unificate: quella risponde a "qual è la PAROLA di stato per una
@@ -7538,8 +7546,6 @@ var SOURCE_CAP_ACTIVE_FIELD = {
7538
7546
  vibration: "detected",
7539
7547
  tamper: "tampered"
7540
7548
  };
7541
- /** Cap names whose presence in a device's bindings qualify it as a source. */
7542
- var SOURCE_CAPS = Object.keys(SOURCE_CAP_ACTIVE_FIELD);
7543
7549
  /**
7544
7550
  * Error types for the safe expression engine. Two distinct classes so callers
7545
7551
  * can tell a compile-time (grammar) failure from a runtime (evaluation)
@@ -9269,7 +9275,7 @@ var RecordingTriggersSchema = object({
9269
9275
  *
9270
9276
  * Cosa vuol dire "alto" dipende dal TIPO di device e non è deciso qui:
9271
9277
  * `SOURCE_CAP_ACTIVE_FIELD` (`catalogs/sensor-active-state.ts`) è LA tabella,
9272
- * la stessa che il virtual-doorbell usa dal 2026-08-05. Ed è il FRONTE, non
9278
+ * la stessa del campanello composto (D671). Ed è il FRONTE, non
9273
9279
  * il livello: un contatto trovato già aperto al riavvio del runner non fa
9274
9280
  * registrare.
9275
9281
  */
@@ -16039,109 +16045,10 @@ method(object({
16039
16045
  deviceIds: array(number()).readonly(),
16040
16046
  caps: array(string()).readonly().optional()
16041
16047
  }), record(string(), record(string(), unknown().nullable())));
16042
- /**
16043
- * Doorbell button cap. Two kinds of providers coexist behind this cap
16044
- * name (same pattern as `snapshot`):
16045
- *
16046
- * - **Native** providers: registered per-device by device-driver
16047
- * addons via `ctx.registerNativeCap` — either on a
16048
- * `DeviceType.Button` accessory with `role: DeviceRole.Doorbell`,
16049
- * or directly on the camera (Reolink registers at camera level).
16050
- * Emits an `onPressed` event every time the firmware pushes a
16051
- * ring; status tracks the last press and a pressCount since start
16052
- * (diagnostic).
16053
- *
16054
- * - **Wrapper** provider: the `virtual-doorbell` system builtin
16055
- * (`@camstack/system/builtins/doorbell`). Turns ANY binary-ish
16056
- * device (contact / switch / event-emitter …) into a doorbell for
16057
- * a camera. `defaultActive: false` — the operator explicitly binds
16058
- * it per camera in the device-bindings UI, then picks the source
16059
- * device + trigger in the per-device settings.
16060
- *
16061
- * The DeviceEventPropagator re-emits `onPressed` on the camera parent
16062
- * — subscribers listening at the camera level receive ring events
16063
- * with `via[]` populated. No code on the parent needed.
16064
- */
16065
- var DoorbellStatusSchema = object({
16066
- /** Ms epoch of the last press. null = never observed since this provider started. */
16067
- lastPressedAt: number().nullable(),
16068
- /** Counter since provider start. Resets on reboot. Useful for metrics/debug. */
16069
- pressCountSinceStart: number()
16070
- });
16071
- var DoorbellPressEventSchema = object({
16072
- deviceId: number(),
16073
- timestamp: number()
16074
- });
16075
- /**
16076
- * The `doorbell-source` extension slot's editable value (D648): the camera's
16077
- * virtual-doorbell trigger devices, exactly what the wrapper's
16078
- * `doorbellSources` persists (as `{ deviceId }` records).
16079
- */
16080
- var DoorbellSourceSlotValueSchema = object({ deviceIds: array(number().int().positive()) });
16081
- /**
16082
- * The `doorbell-source` slot — which devices ring this camera's VIRTUAL
16083
- * doorbell, owned by the `virtual-doorbell` wrapper over its
16084
- * `doorbellSources` store (D648). A source rings when one of its
16085
- * `SOURCE_CAPS` rises. Whether the wrapper is bound to the camera at all is a
16086
- * different authority (`deviceManager.setWrapperActive`, D62) — the slot
16087
- * reports it, it never writes it.
16088
- */
16089
- var DOORBELL_SOURCE_SLOT = {
16090
- id: "doorbell-source",
16091
- label: "Doorbell trigger devices",
16092
- description: "Any of these becoming active rings this camera's virtual doorbell: a binary sensor when it goes active, a switch when it turns on.",
16093
- shape: "association",
16094
- hostDeviceTypes: [DeviceType.Camera],
16095
- sourceCaps: SOURCE_CAPS,
16096
- cardinality: "many",
16097
- value: DoorbellSourceSlotValueSchema
16098
- };
16099
- var doorbellCapability = {
16100
- name: "doorbell",
16101
- scope: "device",
16102
- deviceNative: true,
16103
- mode: "singleton",
16104
- kind: "wrapper",
16105
- defaultActive: false,
16106
- deviceTypes: [DeviceType.Button, DeviceType.Camera],
16107
- extensionSlots: [DOORBELL_SOURCE_SLOT],
16108
- methods: {},
16109
- events: {
16110
- /**
16111
- * Fires once per physical press. Reolink delivers via Baichuan
16112
- * push (`ReolinkSimpleEvent.type === 'doorbell'`). There is no
16113
- * release/duration — it's a pulse.
16114
- */
16115
- onPressed: {
16116
- data: DoorbellPressEventSchema,
16117
- fromState: {
16118
- field: "lastPressedAt",
16119
- on: "advance"
16120
- }
16121
- } },
16122
- status: {
16123
- schema: DoorbellStatusSchema,
16124
- kind: "push"
16125
- },
16126
- /**
16127
- * Runtime-state slice — last press timestamp + lifetime press count.
16128
- * Mirrored by the kernel and readable via
16129
- * `device.state.doorbell.value`. UIs can show "last ring 5m ago"
16130
- * without subscribing.
16131
- */
16132
- runtimeState: DoorbellStatusSchema,
16133
- /**
16134
- * Runtime-state durability: **restored** — a monotonic accumulator: the slice IS the record. `lastPressedAt` is content here, not a clock, so it is deliberately NOT volatile.
16135
- *
16136
- * See `RuntimeStateDurability`. Enforced by
16137
- * `scripts/check-runtime-state-durability.ts`.
16138
- */
16139
- durability: "restored"
16140
- };
16141
- var ExtensionSlotIdSchema = _enum(["doorbell-source", "linked-devices"]);
16142
- DeviceType.Camera, DeviceType.Camera;
16048
+ var ExtensionSlotIdSchema = _enum(["linked-devices"]);
16049
+ DeviceType.Camera;
16143
16050
  /** A slot's editable value, discriminated on `slot`. */
16144
- var ExtensionSlotValueSchema = discriminatedUnion("slot", [DoorbellSourceSlotValueSchema.extend({ slot: literal("doorbell-source") }), LinkedDevicesSlotValueSchema.extend({ slot: literal("linked-devices") })]);
16051
+ var ExtensionSlotValueSchema = discriminatedUnion("slot", [LinkedDevicesSlotValueSchema.extend({ slot: literal("linked-devices") })]);
16145
16052
  DeviceType.Camera;
16146
16053
  var ExtensionSourceAvailabilitySchema = discriminatedUnion("state", [object({ state: literal("ok") }), object({
16147
16054
  state: literal("unreachable"),
@@ -16178,10 +16085,11 @@ var ExtensionSlotSourceSchema = object({
16178
16085
  });
16179
16086
  /**
16180
16087
  * A DIFFERENT authority that gates whether the slot's sources do anything —
16181
- * reported read-only, named, never written through this contract (D62). The
16182
- * virtual doorbell's sources ring only while the wrapper is bound to the
16183
- * camera, and that binding belongs to `deviceManager.setWrapperActive`.
16184
- * `unknown` means the gate could not be read; it is not "inactive" (D315).
16088
+ * reported read-only, named, never written through this contract (D62) — e.g.
16089
+ * a slot whose sources act only while a wrapper is bound to the host, a
16090
+ * binding that belongs to `deviceManager.setWrapperActive`. No slot reports
16091
+ * one today (`linked-devices` answers `null`). `unknown` means the gate could
16092
+ * not be read; it is not "inactive" (D315).
16185
16093
  */
16186
16094
  var ExtensionSlotActivationSchema = object({
16187
16095
  state: _enum([
@@ -16197,7 +16105,7 @@ var ExtensionSlotRowSchema = discriminatedUnion("state", [object({
16197
16105
  /** `<source>:<slotId>` — the routing key for `listCandidates` / `setSlot`. */
16198
16106
  slotRef: string(),
16199
16107
  slot: ExtensionSlotIdSchema,
16200
- /** Names the store written (D62), e.g. `virtual-doorbell:doorbellSources`. */
16108
+ /** Names the store written (D62), e.g. `device-manager:_linkedDeviceIds`. */
16201
16109
  authority: string(),
16202
16110
  activation: ExtensionSlotActivationSchema.nullable(),
16203
16111
  value: ExtensionSlotValueSchema,
@@ -21338,12 +21246,26 @@ var CameraSensorRefSchema = object({
21338
21246
  function cameraSensorRefKey(ref) {
21339
21247
  return `${ref.addonId}/${ref.stableId}`;
21340
21248
  }
21341
- /** CS-1 accepts exactly one mode; CS-2 (D673) widens it to confirm / replace. */
21342
- var CameraSensorsModeSchema = _enum(["in-addition"]);
21343
- var CameraSensorsConfigSchema = object({
21344
- mode: CameraSensorsModeSchema,
21345
- sensors: array(CameraSensorRefSchema).min(1).max(8)
21346
- }).superRefine((value, ctx) => {
21249
+ /**
21250
+ * A sensor's mode (D673). `in-addition`: its motion is the camera's motion too.
21251
+ * `replace`: its motion is the camera's, and while one is READY the camera's
21252
+ * own motion no longer counts on its own. `confirm`: while one is READY the
21253
+ * camera's own motion counts only while a confirm sensor is active — with or
21254
+ * without a replace sensor (spec C2, the controller's ruling on Q1).
21255
+ */
21256
+ var CameraSensorModeSchema = _enum([
21257
+ "in-addition",
21258
+ "confirm",
21259
+ "replace"
21260
+ ]);
21261
+ /** A stored sensor with no mode — every CS-1 row — is in addition. */
21262
+ var DEFAULT_CAMERA_SENSOR_MODE = "in-addition";
21263
+ /**
21264
+ * A camera's attached sensors. A CS-1 row carried an envelope
21265
+ * `mode: 'in-addition'`: `z.object` drops it on parse, and the PARSED value is
21266
+ * what the write stores (D672 rule 3), so it is never written again.
21267
+ */
21268
+ var CameraSensorsConfigSchema = object({ sensors: array(CameraSensorRefSchema.extend({ mode: CameraSensorModeSchema.default(DEFAULT_CAMERA_SENSOR_MODE) })).min(1).max(8) }).superRefine((value, ctx) => {
21347
21269
  const seen = /* @__PURE__ */ new Set();
21348
21270
  value.sensors.forEach((ref, index) => {
21349
21271
  const key = cameraSensorRefKey(ref);
@@ -21355,39 +21277,41 @@ var CameraSensorsConfigSchema = object({
21355
21277
  seen.add(key);
21356
21278
  });
21357
21279
  });
21358
- var RefFields = {
21280
+ /** Every attachment names its mode; an older orchestrator that does not is in addition. */
21281
+ var AttachmentFields = {
21359
21282
  addonId: string(),
21360
- stableId: string()
21283
+ stableId: string(),
21284
+ mode: CameraSensorModeSchema.default(DEFAULT_CAMERA_SENSOR_MODE)
21361
21285
  };
21362
21286
  var CameraSensorAttachmentSchema = discriminatedUnion("state", [
21363
21287
  object({
21364
- ...RefFields,
21288
+ ...AttachmentFields,
21365
21289
  state: literal("ready"),
21366
21290
  deviceId: number(),
21367
21291
  name: string(),
21368
21292
  caps: array(string()).readonly()
21369
21293
  }),
21370
21294
  object({
21371
- ...RefFields,
21295
+ ...AttachmentFields,
21372
21296
  state: literal("offline"),
21373
21297
  deviceId: number(),
21374
21298
  name: string(),
21375
21299
  reason: _enum(["offline", "disabled"])
21376
21300
  }),
21377
21301
  object({
21378
- ...RefFields,
21302
+ ...AttachmentFields,
21379
21303
  state: literal("missing"),
21380
21304
  reason: string()
21381
21305
  }),
21382
21306
  object({
21383
- ...RefFields,
21307
+ ...AttachmentFields,
21384
21308
  state: literal("unsupported"),
21385
21309
  deviceId: number(),
21386
21310
  name: string(),
21387
21311
  reason: string()
21388
21312
  }),
21389
21313
  object({
21390
- ...RefFields,
21314
+ ...AttachmentFields,
21391
21315
  state: literal("unreadable"),
21392
21316
  reason: string()
21393
21317
  })
@@ -21400,17 +21324,49 @@ var CameraSensorAttachmentSchema = discriminatedUnion("state", [
21400
21324
  * say.
21401
21325
  */
21402
21326
  var CameraSensorsNotForwardedSchema = _enum(["onboard-not-listed", "no-active-detection"]);
21327
+ /** Whether the camera's OWN motion counts on its own (D673 C2), from its READY sensors (C3). */
21328
+ var CameraOwnMotionSchema = _enum([
21329
+ "always",
21330
+ "when-confirmed",
21331
+ "never"
21332
+ ]);
21333
+ /** Confirm / Replace cannot suppress this camera's motion: its provider still emits it directly (D673 C13). */
21334
+ var CameraSensorsNotEnforcedSchema = _enum(["provider-not-split"]);
21335
+ /**
21336
+ * The camera's OWN onboard motion (D696): the raw input the bridge combines,
21337
+ * never the effective value. The camera's `motion` slice is the effective one,
21338
+ * so a view of the camera's own row reads this.
21339
+ * - `atMs`: when the bridge received the camera's last own edge.
21340
+ * - `detected`: evaluated WHEN THE STATUS IS ASKED — the last edge said `true`
21341
+ * AND it is younger than the window the bridge counts the camera's own motion
21342
+ * for (`motionCooldownMs`, floored at two sustain ticks). A camera that never
21343
+ * sends a clear (heartbeats only) therefore reads `false` once no push came
21344
+ * within the window; a status read is a snapshot, so a live view re-asks.
21345
+ * Absent = this orchestrator has not received the camera's own motion since it
21346
+ * started (unknown, never "quiet"), or an orchestrator older than D696.
21347
+ */
21348
+ var CameraRawLevelSchema = object({
21349
+ detected: boolean(),
21350
+ atMs: number()
21351
+ });
21403
21352
  var CameraSensorsStatusSchema = discriminatedUnion("state", [
21404
- object({ state: literal("not-configured") }),
21353
+ object({
21354
+ state: literal("not-configured"),
21355
+ cameraLevel: CameraRawLevelSchema.optional()
21356
+ }),
21405
21357
  object({
21406
21358
  state: literal("unreadable"),
21407
- reason: string()
21359
+ reason: string(),
21360
+ cameraLevel: CameraRawLevelSchema.optional()
21408
21361
  }),
21409
21362
  object({
21410
21363
  state: literal("configured"),
21411
- mode: CameraSensorsModeSchema,
21364
+ cameraLevel: CameraRawLevelSchema.optional(),
21412
21365
  sensors: array(CameraSensorAttachmentSchema).readonly(),
21413
- notForwarded: CameraSensorsNotForwardedSchema.optional()
21366
+ /** Absent = an orchestrator older than CS-2: it does not say (D315). */
21367
+ cameraMotion: CameraOwnMotionSchema.optional(),
21368
+ notForwarded: CameraSensorsNotForwardedSchema.optional(),
21369
+ notEnforced: CameraSensorsNotEnforcedSchema.optional()
21414
21370
  })
21415
21371
  ]);
21416
21372
  Object.freeze({
@@ -24641,8 +24597,10 @@ var RunnerCameraConfigSchema = object({
24641
24597
  * - `analyzer`: ML/frame-diff motion detection (motion-wasm or other
24642
24598
  * analyzer providers) running on decoded frames in this runner.
24643
24599
  * - `onboard`: camera-native motion pushes (Reolink Baichuan, ONVIF
24644
- * analytics). The provider emits ProviderMotion
24645
- * events; the orchestrator forwards to `reportMotion`.
24600
+ * analytics). The provider emits its raw push as `ProviderMotion`
24601
+ * (D673); the orchestrator's camera-sensors bridge re-emits the camera's
24602
+ * effective motion as `MotionOnMotionChanged`, which is what reaches
24603
+ * `reportMotion`.
24646
24604
  */
24647
24605
  motionSources: MotionSourcesSchema.default(["analyzer"]),
24648
24606
  /**
@@ -24819,7 +24777,15 @@ var RunnerLocalLoadSchema = object({
24819
24777
  hasGpu: boolean(),
24820
24778
  inferenceBackend: string().optional(),
24821
24779
  cpuCores: number().optional()
24822
- })
24780
+ }),
24781
+ /**
24782
+ * Who writes a camera's `motion` runtime slice (D696). `'orchestrator'`: this
24783
+ * runner never writes it. ABSENT = a runner older than D696, which still
24784
+ * writes the slice from its phase machine; the orchestrator does not write
24785
+ * while any runner node is absent-or-unanswered, so one slice never has two
24786
+ * writers.
24787
+ */
24788
+ motionSliceWriter: literal("orchestrator").optional()
24823
24789
  });
24824
24790
  /**
24825
24791
  * Aggregate runtime metrics for the runner's whole local pool. Mirrors the
@@ -30862,6 +30828,70 @@ onStatusChanged: { data: object({
30862
30828
  * whether persisting is worth a SQLite commit. */
30863
30829
  volatileStateFields: ["lastChangedAt"]
30864
30830
  };
30831
+ var DoorbellStatusSchema = object({
30832
+ /** Ms epoch of the last press. null = never observed since this provider started. */
30833
+ lastPressedAt: number().nullable(),
30834
+ /** Counter since provider start. Resets on reboot. Useful for metrics/debug. */
30835
+ pressCountSinceStart: number()
30836
+ });
30837
+ var DoorbellPressEventSchema = object({
30838
+ deviceId: number(),
30839
+ timestamp: number()
30840
+ });
30841
+ /**
30842
+ * Doorbell button cap. Two kinds of provider serve it, and to every consumer
30843
+ * they are the same cap:
30844
+ *
30845
+ * - **Native** providers, registered per device by a driver addon through
30846
+ * `ctx.registerNativeCap` — a `DeviceType.Button` accessory with
30847
+ * `role: DeviceRole.Doorbell`, or the camera itself (Reolink registers at
30848
+ * camera level). They emit `onPressed` on every firmware ring.
30849
+ * - **A composed doorbell** (D670, D671): a camera's customization gives it
30850
+ * the cap, its `lastPressedAt` rising from the sources the operator
30851
+ * assigned in Customize → Doorbell, and the composer emits `onPressed`
30852
+ * from that field's advance (`fromState`).
30853
+ *
30854
+ * The DeviceEventPropagator re-emits `onPressed` on the camera parent.
30855
+ */
30856
+ var doorbellCapability = {
30857
+ name: "doorbell",
30858
+ scope: "device",
30859
+ deviceNative: true,
30860
+ mode: "singleton",
30861
+ deviceTypes: [DeviceType.Button, DeviceType.Camera],
30862
+ methods: {},
30863
+ events: {
30864
+ /**
30865
+ * Fires once per physical press. Reolink delivers via Baichuan
30866
+ * push (`ReolinkSimpleEvent.type === 'doorbell'`). There is no
30867
+ * release/duration — it's a pulse.
30868
+ */
30869
+ onPressed: {
30870
+ data: DoorbellPressEventSchema,
30871
+ fromState: {
30872
+ field: "lastPressedAt",
30873
+ on: "advance"
30874
+ }
30875
+ } },
30876
+ status: {
30877
+ schema: DoorbellStatusSchema,
30878
+ kind: "push"
30879
+ },
30880
+ /**
30881
+ * Runtime-state slice — last press timestamp + lifetime press count.
30882
+ * Mirrored by the kernel and readable via
30883
+ * `device.state.doorbell.value`. UIs can show "last ring 5m ago"
30884
+ * without subscribing.
30885
+ */
30886
+ runtimeState: DoorbellStatusSchema,
30887
+ /**
30888
+ * Runtime-state durability: **restored** — a monotonic accumulator: the slice IS the record. `lastPressedAt` is content here, not a clock, so it is deliberately NOT volatile.
30889
+ *
30890
+ * See `RuntimeStateDurability`. Enforced by
30891
+ * `scripts/check-runtime-state-durability.ts`.
30892
+ */
30893
+ durability: "restored"
30894
+ };
30865
30895
  /**
30866
30896
  * Enum-state sensor — a string value picked from a finite option set.
30867
30897
  * Drives HA `sensor` entries with `state_class: enum` (HVAC action
@@ -33001,39 +33031,14 @@ authKey: string().optional() }), object({
33001
33031
  /** Human-readable error when `ok: false`. */
33002
33032
  error: string().optional()
33003
33033
  }), { kind: "mutation" });
33004
- /**
33005
- * Hardware / firmware motion sensor cap — binary detected state plus
33006
- * a timestamp of the last observation. Distinct from
33007
- * `motion-detection.cap.ts` which owns the LOCAL ML motion pipeline;
33008
- * `motion` is the lightweight readout from on-camera motion (Reolink
33009
- * `GetMdState`, Baichuan push `type: motion`, ONVIF analytics).
33010
- *
33011
- * Native-motion providers also fan out to `detection.camera-native`
33012
- * with `source: 'onboard'` so cross-cutting system services
33013
- * (alert-center, advanced-notifier) can subscribe once and receive
33014
- * motion from every camera.
33015
- */
33016
- /**
33017
- * How long after a camera's last rising edge `pipeline-analytics` closes the
33018
- * motion EPISODE row it kept open for it (D475) — "il delay della cap", in
33019
- * the operator's words. One authority for the whole system: every provider
33020
- * that seeds `autoClearAfterMs` on a `Camera` device writes this SAME
33021
- * constant while `detected: true` (never its own number — Hikvision used to
33022
- * seed its internal 3 s inactivity timer here, which is a different clock for
33023
- * a different purpose), and `MotionEpisodeTracker` imports it directly rather
33024
- * than reading the live cap value on the hot path. A `Sensor` device (HA
33025
- * binary sensor, Homematic) gets a genuine push both ways and has no episode
33026
- * to close on a timer, so it writes `null`, never this constant.
33027
- */
33028
- var MOTION_CLOSE_AFTER_MS = 15e3;
33029
33034
  var MotionStatusSchema = object({
33030
33035
  detected: boolean(),
33031
33036
  /** Ms epoch of the last detected-true observation. Null if never detected. */
33032
33037
  lastDetectedAt: number().nullable(),
33033
33038
  /**
33034
- * `MOTION_CLOSE_AFTER_MS` while `detected: true` on a `Camera` device,
33035
- * `null` while false and on every `Sensor` device (D475) — see that
33036
- * constant's doc for the one-authority rule.
33039
+ * `MOTION_CLOSE_AFTER_MS` while `detected: true` on a `Camera` device (the
33040
+ * orchestrator writes it, D696), `null` while false and on every `Sensor`
33041
+ * device (D475) — see that constant's doc for the one-authority rule.
33037
33042
  *
33038
33043
  * ## Reading this field still arms nothing
33039
33044
  *
@@ -33051,34 +33056,31 @@ var MotionStatusSchema = object({
33051
33056
  * `addon-export-alexa/src/motion-clear-hold.ts` and
33052
33057
  * `addon-export-hap`'s `RESET_DEBOUNCE_MS` both do.
33053
33058
  *
33054
- * ## Who writes it
33055
- *
33056
- * - **Cameras** — the runner's phase machine, `active → watching` on
33057
- * `cooldown_expired`, which then writes this slice with
33058
- * `detected: false` (`handlePhaseChanged` in
33059
- * `pipeline-runner/index.ts`). It produces the FALLING edge, which
33060
- * matters most for the sources that only ever push a rising one:
33061
- * Reolink emits `MotionOnMotionChanged { detected: true }` and never
33062
- * a false.
33063
- * - **Sensors** (Home Assistant binary sensors, Homematic) — the
33064
- * provider pushes the false itself, from the upstream system's own
33065
- * state change. No phase machine is involved.
33066
- *
33067
- * ### The phase machine is CANONICAL, not sole — and that is a defect
33068
- *
33069
- * An earlier revision of this docblock (mine, 2026-09-12) claimed the
33070
- * phase machine is the sole writer for a camera. It is not.
33071
- * `hikvision-camera.ts:3464` and `amcrest-camera.ts:445` both call
33072
- * `setCapSlice(motionCapability, …)` on their own rising edge, and
33073
- * Hikvision's comment says why: it read THIS docblock, agreed the
33074
- * runner is canonical, and wrote anyway to avoid per-tick churn. So
33075
- * two authorities can disagree about one slice, which this repo
33076
- * forbids, and the doc said otherwise — which is worse than saying
33077
- * nothing, because it reads as verification.
33078
- *
33079
- * This predates D475 and is not fixed there: the fix touches every
33080
- * camera provider. Recorded in D475's Consequences. Do not restore the
33081
- * "sole writer" wording without also removing the other writers.
33059
+ * ## Who writes it (D696)
33060
+ *
33061
+ * - **Cameras** — the orchestrator, and nothing else. It writes the camera's
33062
+ * EFFECTIVE motion (`addon-pipeline-orchestrator`
33063
+ * `camera-sensors/motion-slice.ts`), alongside the effective
33064
+ * `MotionOnMotionChanged` it emits or receives: the camera-sensors bridge
33065
+ * for a split camera, an unsplit emitter's direct event, the analyzer and
33066
+ * device activity, as the camera's `motionSources` counts them. A source
33067
+ * that never sends a clear falls one window after its last `true`.
33068
+ * `lastDetectedAt` moves only on an effective rise. No camera provider
33069
+ * writes this slice (not even a boot seed), and neither does the runner's
33070
+ * phase machine: its phase is "a session is attached" for every on-motion
33071
+ * session, not motion, and it now has its own `DetectionPhaseTransition`.
33072
+ * A provider's `isDetected` answers from the hub's slice.
33073
+ * - **Sensors** (Home Assistant binary sensors, Homematic, Matter, Alexa
33074
+ * imports) — the provider pushes both edges itself, from the upstream
33075
+ * system's own state change. That is the sensor's own fact.
33076
+ *
33077
+ * `scripts/check-onboard-motion-emitters.ts` refuses any other writer of a
33078
+ * `motion` slice; each sensor writer is a named exemption.
33079
+ *
33080
+ * This replaces the D475 §4 rule ("the phase machine is the sole writer").
33081
+ * That rule was never true: Hikvision and Amcrest wrote the slice raw beside
33082
+ * it, every provider seeded it at boot, and every session left it
33083
+ * `detected: true` after its detach.
33082
33084
  */
33083
33085
  autoClearAfterMs: number().nullable()
33084
33086
  });
@@ -33150,11 +33152,12 @@ onMotionChanged: { data: MotionOnMotionChangedDataSchema } },
33150
33152
  */
33151
33153
  runtimeState: MotionStatusSchema,
33152
33154
  /**
33153
- * Runtime-state durability: **session** — every writer of this slice
33155
+ * Runtime-state durability: **session** — the writer of this slice
33154
33156
  * writes only on an EDGE, so a restored `detected: true` would stay
33155
33157
  * frozen until the next one instead of being corrected. The next edge
33156
- * re-publishes the real state. (On who the writers are, and why there
33157
- * is more than one, see `autoClearAfterMs` above.)
33158
+ * re-publishes the real state, and the orchestrator re-publishes every
33159
+ * camera when it starts writing (D696; on who writes it, see
33160
+ * `autoClearAfterMs` above).
33158
33161
  *
33159
33162
  * See `RuntimeStateDurability`. Enforced by
33160
33163
  * `scripts/check-runtime-state-durability.ts`.
@@ -35695,8 +35698,7 @@ var ptzAutotrackCapability = {
35695
35698
  deviceNative: true,
35696
35699
  mode: "singleton",
35697
35700
  /**
35698
- * Two kinds of provider behind one name, the same shape `snapshot` and
35699
- * `doorbell` use:
35701
+ * Two kinds of provider behind one name, the same shape `snapshot` uses:
35700
35702
  *
35701
35703
  * - **Native**: the camera's own firmware autotrack, registered per device by
35702
35704
  * the driver when the probe says it exists (Reolink: yes; Hikvision:
@@ -35704,7 +35706,7 @@ var ptzAutotrackCapability = {
35704
35706
  * - **Wrapper**: the emulated implementation (`@camstack/system`'s `autotrack` builtin),
35705
35707
  * which follows a subject with `ptz.move` pulses driven by the detection
35706
35708
  * pipeline. `defaultActive: false` — the operator binds it per camera in
35707
- * the bindings UI, exactly as `virtual-doorbell` is bound.
35709
+ * the bindings UI.
35708
35710
  *
35709
35711
  * The binding chooses WHICH implementation answers; `setEnabled` stays the
35710
35712
  * one switch for the function either way. A camera never has both driving its
@@ -53298,6 +53300,25 @@ TimelapseRuleInputSchema.extend({
53298
53300
  createdAt: number(),
53299
53301
  updatedAt: number()
53300
53302
  });
53303
+ async function readHubMotionDetected(deviceState, deviceId) {
53304
+ let slice;
53305
+ try {
53306
+ slice = await deviceState.getCapSlice.query({
53307
+ deviceId,
53308
+ capName: "motion"
53309
+ });
53310
+ } catch (err) {
53311
+ const reason = err instanceof Error ? err.message : String(err);
53312
+ throw new Error(`motion state of device ${deviceId} is unreadable: ${reason}`, { cause: err });
53313
+ }
53314
+ const detected = slice?.["detected"];
53315
+ if (typeof detected !== "boolean") throw new Error(`motion state of device ${deviceId} is not published yet (unknown)`);
53316
+ return detected;
53317
+ }
53318
+ MotionOnMotionChangedDataSchema.omit({ triggeredBy: true });
53319
+ function providerMotionEvent(source, data) {
53320
+ return createEvent(EventCategory.ProviderMotion, source, data);
53321
+ }
53301
53322
  object({
53302
53323
  /**
53303
53324
  * Fraction of the box's own size added on EACH side before cutting.
@@ -63110,15 +63131,7 @@ var HikvisionCamera = class HikvisionCamera extends BaseDevice {
63110
63131
  host
63111
63132
  };
63112
63133
  } });
63113
- this.ctx.registerNativeCap(motionCapability, { isDetected: async ({ deviceId }) => {
63114
- if (deviceId !== this.id) throw new Error(`HikvisionCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
63115
- return this.state.motion?.detected ?? false;
63116
- } });
63117
- this.setCapSlice(motionCapability, {
63118
- detected: false,
63119
- lastDetectedAt: null,
63120
- autoClearAfterMs: null
63121
- });
63134
+ this.registerMotionCap();
63122
63135
  this.registerIntercomIfSupported();
63123
63136
  this.registerOsdCap(1);
63124
63137
  this.registerStreamParamsCap(1);
@@ -65587,43 +65600,41 @@ var HikvisionCamera = class HikvisionCamera extends BaseDevice {
65587
65600
  deviceId: this.id
65588
65601
  };
65589
65602
  }
65603
+ /**
65604
+ * The native `motion` cap. Its presence is what defaults the camera to
65605
+ * `motionSources: ['onboard']`. This provider writes NO `motion` slice (D696):
65606
+ * the orchestrator is its only writer, with the EFFECTIVE motion, on the hub.
65607
+ * `isDetected` therefore answers from the hub's slice; an unreadable hub, or
65608
+ * a slice nobody has published since the hub started, makes the call fail.
65609
+ * It never answers `false` for "unknown" (D49, D393).
65610
+ */
65611
+ registerMotionCap() {
65612
+ this.ctx.registerNativeCap(motionCapability, { isDetected: async ({ deviceId }) => {
65613
+ if (deviceId !== this.id) throw new Error(`HikvisionCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
65614
+ return readHubMotionDetected(this.ctx.api.deviceState, this.id);
65615
+ } });
65616
+ }
65590
65617
  handleMotionEvent(ev, camStreamId) {
65591
65618
  const now = ev.observedAt;
65592
- const wasInactive = (this.lastMotionAt.get(camStreamId) ?? 0) === 0;
65593
65619
  this.lastMotionAt.set(camStreamId, now);
65594
- this.ctx.eventBus.emit(createEvent(EventCategory.MotionOnMotionChanged, this.eventSource, {
65620
+ this.ctx.eventBus.emit(providerMotionEvent(this.eventSource, {
65595
65621
  deviceId: this.id,
65596
65622
  detected: true,
65597
65623
  timestamp: now,
65598
65624
  source: "onboard"
65599
65625
  }));
65600
- if (wasInactive) try {
65601
- this.setCapSlice(motionCapability, {
65602
- detected: true,
65603
- lastDetectedAt: now,
65604
- autoClearAfterMs: MOTION_CLOSE_AFTER_MS
65605
- });
65606
- } catch {}
65607
65626
  const existing = this.motionInactiveTimers.get(camStreamId);
65608
65627
  if (existing) clearTimeout(existing);
65609
65628
  const timer = setTimeout(() => {
65610
65629
  const clearedAt = Date.now();
65611
65630
  this.lastMotionAt.set(camStreamId, 0);
65612
65631
  this.motionInactiveTimers.delete(camStreamId);
65613
- this.ctx.eventBus.emit(createEvent(EventCategory.MotionOnMotionChanged, this.eventSource, {
65632
+ this.ctx.eventBus.emit(providerMotionEvent(this.eventSource, {
65614
65633
  deviceId: this.id,
65615
65634
  detected: false,
65616
65635
  timestamp: clearedAt,
65617
65636
  source: "onboard"
65618
65637
  }));
65619
- try {
65620
- const lastDetectedAt = this.state.motion?.lastDetectedAt ?? clearedAt;
65621
- this.setCapSlice(motionCapability, {
65622
- detected: false,
65623
- lastDetectedAt,
65624
- autoClearAfterMs: null
65625
- });
65626
- } catch {}
65627
65638
  }, HikvisionCamera.MOTION_INACTIVE_AFTER_MS);
65628
65639
  this.motionInactiveTimers.set(camStreamId, timer);
65629
65640
  }