@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.mjs CHANGED
@@ -12,7 +12,7 @@ import { networkInterfaces } from "node:os";
12
12
  var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
13
13
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
14
14
  //#endregion
15
- //#region ../types/dist/event-category-C5xZWqz6.mjs
15
+ //#region ../types/dist/event-category-BGmz_oxW.mjs
16
16
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
17
17
  EventCategory["SystemBoot"] = "system.boot";
18
18
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -545,6 +545,15 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
545
545
  */
546
546
  EventCategory["PipelineAudioInferenceResult"] = "pipeline.audio-inference-result";
547
547
  EventCategory["DetectionPhaseTransition"] = "detection.phase-transition";
548
+ /**
549
+ * A camera provider's RAW onboard motion push (D673): the `MotionOnMotionChanged`
550
+ * data shape without `triggeredBy`, built by `providerMotionEvent`. Its one
551
+ * consumer is the orchestrator's camera-sensors bridge, which re-emits the
552
+ * camera's EFFECTIVE onboard motion as `MotionOnMotionChanged` (a pass-through
553
+ * for a camera with no attached sensor). Providers must not emit
554
+ * `MotionOnMotionChanged` themselves; `scripts/check-onboard-motion-emitters.ts`
555
+ * keeps it so (camera-grid is a named, deferred exception).
556
+ */
548
557
  EventCategory["ProviderMotion"] = "provider.motion";
549
558
  EventCategory["ProviderDetection"] = "provider.detection";
550
559
  EventCategory["EnrichmentEmbeddingStored"] = "enrichment.embedding.stored";
@@ -5383,7 +5392,7 @@ var ZodIssueCode = {
5383
5392
  var ZodFirstPartyTypeKind;
5384
5393
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5385
5394
  //#endregion
5386
- //#region ../types/dist/sleep-gU6hqv4_.mjs
5395
+ //#region ../types/dist/sleep-CDCONfkt.mjs
5387
5396
  /**
5388
5397
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5389
5398
  * window to float samples (D455).
@@ -7428,7 +7437,7 @@ var DeviceRole = /* @__PURE__ */ function(DeviceRole) {
7428
7437
  return DeviceRole;
7429
7438
  }({});
7430
7439
  //#endregion
7431
- //#region ../types/dist/composition-Dq42XWp0.mjs
7440
+ //#region ../types/dist/composition-43aqsZQj.mjs
7432
7441
  /**
7433
7442
  * The ffmpeg build every CamStack node downloads, per platform and arch.
7434
7443
  *
@@ -7485,13 +7494,12 @@ portable("linux64"), portable("linuxarm64"), portable("macarm64"), portable("mac
7485
7494
  * LA tabella "quale booleano di questo tipo di device conta come ALTO", e il
7486
7495
  * valutatore puro del suo FRONTE.
7487
7496
  *
7488
- * Viveva dentro il builtin virtual-doorbell
7489
- * (`@camstack/system` — `builtins/doorbell/trigger-engine.ts`) e i suoi
7490
- * predicati erano privati al modulo. Il recorder ne ha bisogno per il trigger
7491
- * `RecordingTriggers.sensorDeviceIds`: copiarla avrebbe creato la SECONDA
7492
- * tabella, che diverge alla prima cap aggiunta e il cui sintomo — "il sensore
7493
- * fa suonare il campanello ma non registra" — è esattamente D62. Quindi si
7494
- * SPOSTA qui e il doorbell la ri-esporta.
7497
+ * UNA tabella per tutti quelli che chiedono "questo device è ALTO?": il
7498
+ * trigger `RecordingTriggers.sensorDeviceIds` del recorder, i marker dei
7499
+ * sensori della post-analysis, il bridge camera-sensors dell'orchestratore e
7500
+ * le sorgenti di un campanello composto (`doorbellFeatureSources`, D671).
7501
+ * Una seconda copia divergerebbe alla prima cap aggiunta, e il sintomo — "il
7502
+ * sensore fa suonare il campanello ma non registra" — è esattamente D62.
7495
7503
  *
7496
7504
  * ⚠ NON è `DEVICE_STATE_READERS` (`catalogs/device-state-vocabulary.ts`), e le
7497
7505
  * due non vanno unificate: quella risponde a "qual è la PAROLA di stato per una
@@ -7517,8 +7525,6 @@ var SOURCE_CAP_ACTIVE_FIELD = {
7517
7525
  vibration: "detected",
7518
7526
  tamper: "tampered"
7519
7527
  };
7520
- /** Cap names whose presence in a device's bindings qualify it as a source. */
7521
- var SOURCE_CAPS = Object.keys(SOURCE_CAP_ACTIVE_FIELD);
7522
7528
  /**
7523
7529
  * Error types for the safe expression engine. Two distinct classes so callers
7524
7530
  * can tell a compile-time (grammar) failure from a runtime (evaluation)
@@ -9248,7 +9254,7 @@ var RecordingTriggersSchema = object({
9248
9254
  *
9249
9255
  * Cosa vuol dire "alto" dipende dal TIPO di device e non è deciso qui:
9250
9256
  * `SOURCE_CAP_ACTIVE_FIELD` (`catalogs/sensor-active-state.ts`) è LA tabella,
9251
- * la stessa che il virtual-doorbell usa dal 2026-08-05. Ed è il FRONTE, non
9257
+ * la stessa del campanello composto (D671). Ed è il FRONTE, non
9252
9258
  * il livello: un contatto trovato già aperto al riavvio del runner non fa
9253
9259
  * registrare.
9254
9260
  */
@@ -16018,109 +16024,10 @@ method(object({
16018
16024
  deviceIds: array(number()).readonly(),
16019
16025
  caps: array(string()).readonly().optional()
16020
16026
  }), record(string(), record(string(), unknown().nullable())));
16021
- /**
16022
- * Doorbell button cap. Two kinds of providers coexist behind this cap
16023
- * name (same pattern as `snapshot`):
16024
- *
16025
- * - **Native** providers: registered per-device by device-driver
16026
- * addons via `ctx.registerNativeCap` — either on a
16027
- * `DeviceType.Button` accessory with `role: DeviceRole.Doorbell`,
16028
- * or directly on the camera (Reolink registers at camera level).
16029
- * Emits an `onPressed` event every time the firmware pushes a
16030
- * ring; status tracks the last press and a pressCount since start
16031
- * (diagnostic).
16032
- *
16033
- * - **Wrapper** provider: the `virtual-doorbell` system builtin
16034
- * (`@camstack/system/builtins/doorbell`). Turns ANY binary-ish
16035
- * device (contact / switch / event-emitter …) into a doorbell for
16036
- * a camera. `defaultActive: false` — the operator explicitly binds
16037
- * it per camera in the device-bindings UI, then picks the source
16038
- * device + trigger in the per-device settings.
16039
- *
16040
- * The DeviceEventPropagator re-emits `onPressed` on the camera parent
16041
- * — subscribers listening at the camera level receive ring events
16042
- * with `via[]` populated. No code on the parent needed.
16043
- */
16044
- var DoorbellStatusSchema = object({
16045
- /** Ms epoch of the last press. null = never observed since this provider started. */
16046
- lastPressedAt: number().nullable(),
16047
- /** Counter since provider start. Resets on reboot. Useful for metrics/debug. */
16048
- pressCountSinceStart: number()
16049
- });
16050
- var DoorbellPressEventSchema = object({
16051
- deviceId: number(),
16052
- timestamp: number()
16053
- });
16054
- /**
16055
- * The `doorbell-source` extension slot's editable value (D648): the camera's
16056
- * virtual-doorbell trigger devices, exactly what the wrapper's
16057
- * `doorbellSources` persists (as `{ deviceId }` records).
16058
- */
16059
- var DoorbellSourceSlotValueSchema = object({ deviceIds: array(number().int().positive()) });
16060
- /**
16061
- * The `doorbell-source` slot — which devices ring this camera's VIRTUAL
16062
- * doorbell, owned by the `virtual-doorbell` wrapper over its
16063
- * `doorbellSources` store (D648). A source rings when one of its
16064
- * `SOURCE_CAPS` rises. Whether the wrapper is bound to the camera at all is a
16065
- * different authority (`deviceManager.setWrapperActive`, D62) — the slot
16066
- * reports it, it never writes it.
16067
- */
16068
- var DOORBELL_SOURCE_SLOT = {
16069
- id: "doorbell-source",
16070
- label: "Doorbell trigger devices",
16071
- 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.",
16072
- shape: "association",
16073
- hostDeviceTypes: [DeviceType.Camera],
16074
- sourceCaps: SOURCE_CAPS,
16075
- cardinality: "many",
16076
- value: DoorbellSourceSlotValueSchema
16077
- };
16078
- var doorbellCapability = {
16079
- name: "doorbell",
16080
- scope: "device",
16081
- deviceNative: true,
16082
- mode: "singleton",
16083
- kind: "wrapper",
16084
- defaultActive: false,
16085
- deviceTypes: [DeviceType.Button, DeviceType.Camera],
16086
- extensionSlots: [DOORBELL_SOURCE_SLOT],
16087
- methods: {},
16088
- events: {
16089
- /**
16090
- * Fires once per physical press. Reolink delivers via Baichuan
16091
- * push (`ReolinkSimpleEvent.type === 'doorbell'`). There is no
16092
- * release/duration — it's a pulse.
16093
- */
16094
- onPressed: {
16095
- data: DoorbellPressEventSchema,
16096
- fromState: {
16097
- field: "lastPressedAt",
16098
- on: "advance"
16099
- }
16100
- } },
16101
- status: {
16102
- schema: DoorbellStatusSchema,
16103
- kind: "push"
16104
- },
16105
- /**
16106
- * Runtime-state slice — last press timestamp + lifetime press count.
16107
- * Mirrored by the kernel and readable via
16108
- * `device.state.doorbell.value`. UIs can show "last ring 5m ago"
16109
- * without subscribing.
16110
- */
16111
- runtimeState: DoorbellStatusSchema,
16112
- /**
16113
- * 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.
16114
- *
16115
- * See `RuntimeStateDurability`. Enforced by
16116
- * `scripts/check-runtime-state-durability.ts`.
16117
- */
16118
- durability: "restored"
16119
- };
16120
- var ExtensionSlotIdSchema = _enum(["doorbell-source", "linked-devices"]);
16121
- DeviceType.Camera, DeviceType.Camera;
16027
+ var ExtensionSlotIdSchema = _enum(["linked-devices"]);
16028
+ DeviceType.Camera;
16122
16029
  /** A slot's editable value, discriminated on `slot`. */
16123
- var ExtensionSlotValueSchema = discriminatedUnion("slot", [DoorbellSourceSlotValueSchema.extend({ slot: literal("doorbell-source") }), LinkedDevicesSlotValueSchema.extend({ slot: literal("linked-devices") })]);
16030
+ var ExtensionSlotValueSchema = discriminatedUnion("slot", [LinkedDevicesSlotValueSchema.extend({ slot: literal("linked-devices") })]);
16124
16031
  DeviceType.Camera;
16125
16032
  var ExtensionSourceAvailabilitySchema = discriminatedUnion("state", [object({ state: literal("ok") }), object({
16126
16033
  state: literal("unreachable"),
@@ -16157,10 +16064,11 @@ var ExtensionSlotSourceSchema = object({
16157
16064
  });
16158
16065
  /**
16159
16066
  * A DIFFERENT authority that gates whether the slot's sources do anything —
16160
- * reported read-only, named, never written through this contract (D62). The
16161
- * virtual doorbell's sources ring only while the wrapper is bound to the
16162
- * camera, and that binding belongs to `deviceManager.setWrapperActive`.
16163
- * `unknown` means the gate could not be read; it is not "inactive" (D315).
16067
+ * reported read-only, named, never written through this contract (D62) — e.g.
16068
+ * a slot whose sources act only while a wrapper is bound to the host, a
16069
+ * binding that belongs to `deviceManager.setWrapperActive`. No slot reports
16070
+ * one today (`linked-devices` answers `null`). `unknown` means the gate could
16071
+ * not be read; it is not "inactive" (D315).
16164
16072
  */
16165
16073
  var ExtensionSlotActivationSchema = object({
16166
16074
  state: _enum([
@@ -16176,7 +16084,7 @@ var ExtensionSlotRowSchema = discriminatedUnion("state", [object({
16176
16084
  /** `<source>:<slotId>` — the routing key for `listCandidates` / `setSlot`. */
16177
16085
  slotRef: string(),
16178
16086
  slot: ExtensionSlotIdSchema,
16179
- /** Names the store written (D62), e.g. `virtual-doorbell:doorbellSources`. */
16087
+ /** Names the store written (D62), e.g. `device-manager:_linkedDeviceIds`. */
16180
16088
  authority: string(),
16181
16089
  activation: ExtensionSlotActivationSchema.nullable(),
16182
16090
  value: ExtensionSlotValueSchema,
@@ -21317,12 +21225,26 @@ var CameraSensorRefSchema = object({
21317
21225
  function cameraSensorRefKey(ref) {
21318
21226
  return `${ref.addonId}/${ref.stableId}`;
21319
21227
  }
21320
- /** CS-1 accepts exactly one mode; CS-2 (D673) widens it to confirm / replace. */
21321
- var CameraSensorsModeSchema = _enum(["in-addition"]);
21322
- var CameraSensorsConfigSchema = object({
21323
- mode: CameraSensorsModeSchema,
21324
- sensors: array(CameraSensorRefSchema).min(1).max(8)
21325
- }).superRefine((value, ctx) => {
21228
+ /**
21229
+ * A sensor's mode (D673). `in-addition`: its motion is the camera's motion too.
21230
+ * `replace`: its motion is the camera's, and while one is READY the camera's
21231
+ * own motion no longer counts on its own. `confirm`: while one is READY the
21232
+ * camera's own motion counts only while a confirm sensor is active — with or
21233
+ * without a replace sensor (spec C2, the controller's ruling on Q1).
21234
+ */
21235
+ var CameraSensorModeSchema = _enum([
21236
+ "in-addition",
21237
+ "confirm",
21238
+ "replace"
21239
+ ]);
21240
+ /** A stored sensor with no mode — every CS-1 row — is in addition. */
21241
+ var DEFAULT_CAMERA_SENSOR_MODE = "in-addition";
21242
+ /**
21243
+ * A camera's attached sensors. A CS-1 row carried an envelope
21244
+ * `mode: 'in-addition'`: `z.object` drops it on parse, and the PARSED value is
21245
+ * what the write stores (D672 rule 3), so it is never written again.
21246
+ */
21247
+ var CameraSensorsConfigSchema = object({ sensors: array(CameraSensorRefSchema.extend({ mode: CameraSensorModeSchema.default(DEFAULT_CAMERA_SENSOR_MODE) })).min(1).max(8) }).superRefine((value, ctx) => {
21326
21248
  const seen = /* @__PURE__ */ new Set();
21327
21249
  value.sensors.forEach((ref, index) => {
21328
21250
  const key = cameraSensorRefKey(ref);
@@ -21334,39 +21256,41 @@ var CameraSensorsConfigSchema = object({
21334
21256
  seen.add(key);
21335
21257
  });
21336
21258
  });
21337
- var RefFields = {
21259
+ /** Every attachment names its mode; an older orchestrator that does not is in addition. */
21260
+ var AttachmentFields = {
21338
21261
  addonId: string(),
21339
- stableId: string()
21262
+ stableId: string(),
21263
+ mode: CameraSensorModeSchema.default(DEFAULT_CAMERA_SENSOR_MODE)
21340
21264
  };
21341
21265
  var CameraSensorAttachmentSchema = discriminatedUnion("state", [
21342
21266
  object({
21343
- ...RefFields,
21267
+ ...AttachmentFields,
21344
21268
  state: literal("ready"),
21345
21269
  deviceId: number(),
21346
21270
  name: string(),
21347
21271
  caps: array(string()).readonly()
21348
21272
  }),
21349
21273
  object({
21350
- ...RefFields,
21274
+ ...AttachmentFields,
21351
21275
  state: literal("offline"),
21352
21276
  deviceId: number(),
21353
21277
  name: string(),
21354
21278
  reason: _enum(["offline", "disabled"])
21355
21279
  }),
21356
21280
  object({
21357
- ...RefFields,
21281
+ ...AttachmentFields,
21358
21282
  state: literal("missing"),
21359
21283
  reason: string()
21360
21284
  }),
21361
21285
  object({
21362
- ...RefFields,
21286
+ ...AttachmentFields,
21363
21287
  state: literal("unsupported"),
21364
21288
  deviceId: number(),
21365
21289
  name: string(),
21366
21290
  reason: string()
21367
21291
  }),
21368
21292
  object({
21369
- ...RefFields,
21293
+ ...AttachmentFields,
21370
21294
  state: literal("unreadable"),
21371
21295
  reason: string()
21372
21296
  })
@@ -21379,17 +21303,49 @@ var CameraSensorAttachmentSchema = discriminatedUnion("state", [
21379
21303
  * say.
21380
21304
  */
21381
21305
  var CameraSensorsNotForwardedSchema = _enum(["onboard-not-listed", "no-active-detection"]);
21306
+ /** Whether the camera's OWN motion counts on its own (D673 C2), from its READY sensors (C3). */
21307
+ var CameraOwnMotionSchema = _enum([
21308
+ "always",
21309
+ "when-confirmed",
21310
+ "never"
21311
+ ]);
21312
+ /** Confirm / Replace cannot suppress this camera's motion: its provider still emits it directly (D673 C13). */
21313
+ var CameraSensorsNotEnforcedSchema = _enum(["provider-not-split"]);
21314
+ /**
21315
+ * The camera's OWN onboard motion (D696): the raw input the bridge combines,
21316
+ * never the effective value. The camera's `motion` slice is the effective one,
21317
+ * so a view of the camera's own row reads this.
21318
+ * - `atMs`: when the bridge received the camera's last own edge.
21319
+ * - `detected`: evaluated WHEN THE STATUS IS ASKED — the last edge said `true`
21320
+ * AND it is younger than the window the bridge counts the camera's own motion
21321
+ * for (`motionCooldownMs`, floored at two sustain ticks). A camera that never
21322
+ * sends a clear (heartbeats only) therefore reads `false` once no push came
21323
+ * within the window; a status read is a snapshot, so a live view re-asks.
21324
+ * Absent = this orchestrator has not received the camera's own motion since it
21325
+ * started (unknown, never "quiet"), or an orchestrator older than D696.
21326
+ */
21327
+ var CameraRawLevelSchema = object({
21328
+ detected: boolean(),
21329
+ atMs: number()
21330
+ });
21382
21331
  var CameraSensorsStatusSchema = discriminatedUnion("state", [
21383
- object({ state: literal("not-configured") }),
21332
+ object({
21333
+ state: literal("not-configured"),
21334
+ cameraLevel: CameraRawLevelSchema.optional()
21335
+ }),
21384
21336
  object({
21385
21337
  state: literal("unreadable"),
21386
- reason: string()
21338
+ reason: string(),
21339
+ cameraLevel: CameraRawLevelSchema.optional()
21387
21340
  }),
21388
21341
  object({
21389
21342
  state: literal("configured"),
21390
- mode: CameraSensorsModeSchema,
21343
+ cameraLevel: CameraRawLevelSchema.optional(),
21391
21344
  sensors: array(CameraSensorAttachmentSchema).readonly(),
21392
- notForwarded: CameraSensorsNotForwardedSchema.optional()
21345
+ /** Absent = an orchestrator older than CS-2: it does not say (D315). */
21346
+ cameraMotion: CameraOwnMotionSchema.optional(),
21347
+ notForwarded: CameraSensorsNotForwardedSchema.optional(),
21348
+ notEnforced: CameraSensorsNotEnforcedSchema.optional()
21393
21349
  })
21394
21350
  ]);
21395
21351
  Object.freeze({
@@ -24620,8 +24576,10 @@ var RunnerCameraConfigSchema = object({
24620
24576
  * - `analyzer`: ML/frame-diff motion detection (motion-wasm or other
24621
24577
  * analyzer providers) running on decoded frames in this runner.
24622
24578
  * - `onboard`: camera-native motion pushes (Reolink Baichuan, ONVIF
24623
- * analytics). The provider emits ProviderMotion
24624
- * events; the orchestrator forwards to `reportMotion`.
24579
+ * analytics). The provider emits its raw push as `ProviderMotion`
24580
+ * (D673); the orchestrator's camera-sensors bridge re-emits the camera's
24581
+ * effective motion as `MotionOnMotionChanged`, which is what reaches
24582
+ * `reportMotion`.
24625
24583
  */
24626
24584
  motionSources: MotionSourcesSchema.default(["analyzer"]),
24627
24585
  /**
@@ -24798,7 +24756,15 @@ var RunnerLocalLoadSchema = object({
24798
24756
  hasGpu: boolean(),
24799
24757
  inferenceBackend: string().optional(),
24800
24758
  cpuCores: number().optional()
24801
- })
24759
+ }),
24760
+ /**
24761
+ * Who writes a camera's `motion` runtime slice (D696). `'orchestrator'`: this
24762
+ * runner never writes it. ABSENT = a runner older than D696, which still
24763
+ * writes the slice from its phase machine; the orchestrator does not write
24764
+ * while any runner node is absent-or-unanswered, so one slice never has two
24765
+ * writers.
24766
+ */
24767
+ motionSliceWriter: literal("orchestrator").optional()
24802
24768
  });
24803
24769
  /**
24804
24770
  * Aggregate runtime metrics for the runner's whole local pool. Mirrors the
@@ -30841,6 +30807,70 @@ onStatusChanged: { data: object({
30841
30807
  * whether persisting is worth a SQLite commit. */
30842
30808
  volatileStateFields: ["lastChangedAt"]
30843
30809
  };
30810
+ var DoorbellStatusSchema = object({
30811
+ /** Ms epoch of the last press. null = never observed since this provider started. */
30812
+ lastPressedAt: number().nullable(),
30813
+ /** Counter since provider start. Resets on reboot. Useful for metrics/debug. */
30814
+ pressCountSinceStart: number()
30815
+ });
30816
+ var DoorbellPressEventSchema = object({
30817
+ deviceId: number(),
30818
+ timestamp: number()
30819
+ });
30820
+ /**
30821
+ * Doorbell button cap. Two kinds of provider serve it, and to every consumer
30822
+ * they are the same cap:
30823
+ *
30824
+ * - **Native** providers, registered per device by a driver addon through
30825
+ * `ctx.registerNativeCap` — a `DeviceType.Button` accessory with
30826
+ * `role: DeviceRole.Doorbell`, or the camera itself (Reolink registers at
30827
+ * camera level). They emit `onPressed` on every firmware ring.
30828
+ * - **A composed doorbell** (D670, D671): a camera's customization gives it
30829
+ * the cap, its `lastPressedAt` rising from the sources the operator
30830
+ * assigned in Customize → Doorbell, and the composer emits `onPressed`
30831
+ * from that field's advance (`fromState`).
30832
+ *
30833
+ * The DeviceEventPropagator re-emits `onPressed` on the camera parent.
30834
+ */
30835
+ var doorbellCapability = {
30836
+ name: "doorbell",
30837
+ scope: "device",
30838
+ deviceNative: true,
30839
+ mode: "singleton",
30840
+ deviceTypes: [DeviceType.Button, DeviceType.Camera],
30841
+ methods: {},
30842
+ events: {
30843
+ /**
30844
+ * Fires once per physical press. Reolink delivers via Baichuan
30845
+ * push (`ReolinkSimpleEvent.type === 'doorbell'`). There is no
30846
+ * release/duration — it's a pulse.
30847
+ */
30848
+ onPressed: {
30849
+ data: DoorbellPressEventSchema,
30850
+ fromState: {
30851
+ field: "lastPressedAt",
30852
+ on: "advance"
30853
+ }
30854
+ } },
30855
+ status: {
30856
+ schema: DoorbellStatusSchema,
30857
+ kind: "push"
30858
+ },
30859
+ /**
30860
+ * Runtime-state slice — last press timestamp + lifetime press count.
30861
+ * Mirrored by the kernel and readable via
30862
+ * `device.state.doorbell.value`. UIs can show "last ring 5m ago"
30863
+ * without subscribing.
30864
+ */
30865
+ runtimeState: DoorbellStatusSchema,
30866
+ /**
30867
+ * 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.
30868
+ *
30869
+ * See `RuntimeStateDurability`. Enforced by
30870
+ * `scripts/check-runtime-state-durability.ts`.
30871
+ */
30872
+ durability: "restored"
30873
+ };
30844
30874
  /**
30845
30875
  * Enum-state sensor — a string value picked from a finite option set.
30846
30876
  * Drives HA `sensor` entries with `state_class: enum` (HVAC action
@@ -32980,39 +33010,14 @@ authKey: string().optional() }), object({
32980
33010
  /** Human-readable error when `ok: false`. */
32981
33011
  error: string().optional()
32982
33012
  }), { kind: "mutation" });
32983
- /**
32984
- * Hardware / firmware motion sensor cap — binary detected state plus
32985
- * a timestamp of the last observation. Distinct from
32986
- * `motion-detection.cap.ts` which owns the LOCAL ML motion pipeline;
32987
- * `motion` is the lightweight readout from on-camera motion (Reolink
32988
- * `GetMdState`, Baichuan push `type: motion`, ONVIF analytics).
32989
- *
32990
- * Native-motion providers also fan out to `detection.camera-native`
32991
- * with `source: 'onboard'` so cross-cutting system services
32992
- * (alert-center, advanced-notifier) can subscribe once and receive
32993
- * motion from every camera.
32994
- */
32995
- /**
32996
- * How long after a camera's last rising edge `pipeline-analytics` closes the
32997
- * motion EPISODE row it kept open for it (D475) — "il delay della cap", in
32998
- * the operator's words. One authority for the whole system: every provider
32999
- * that seeds `autoClearAfterMs` on a `Camera` device writes this SAME
33000
- * constant while `detected: true` (never its own number — Hikvision used to
33001
- * seed its internal 3 s inactivity timer here, which is a different clock for
33002
- * a different purpose), and `MotionEpisodeTracker` imports it directly rather
33003
- * than reading the live cap value on the hot path. A `Sensor` device (HA
33004
- * binary sensor, Homematic) gets a genuine push both ways and has no episode
33005
- * to close on a timer, so it writes `null`, never this constant.
33006
- */
33007
- var MOTION_CLOSE_AFTER_MS = 15e3;
33008
33013
  var MotionStatusSchema = object({
33009
33014
  detected: boolean(),
33010
33015
  /** Ms epoch of the last detected-true observation. Null if never detected. */
33011
33016
  lastDetectedAt: number().nullable(),
33012
33017
  /**
33013
- * `MOTION_CLOSE_AFTER_MS` while `detected: true` on a `Camera` device,
33014
- * `null` while false and on every `Sensor` device (D475) — see that
33015
- * constant's doc for the one-authority rule.
33018
+ * `MOTION_CLOSE_AFTER_MS` while `detected: true` on a `Camera` device (the
33019
+ * orchestrator writes it, D696), `null` while false and on every `Sensor`
33020
+ * device (D475) — see that constant's doc for the one-authority rule.
33016
33021
  *
33017
33022
  * ## Reading this field still arms nothing
33018
33023
  *
@@ -33030,34 +33035,31 @@ var MotionStatusSchema = object({
33030
33035
  * `addon-export-alexa/src/motion-clear-hold.ts` and
33031
33036
  * `addon-export-hap`'s `RESET_DEBOUNCE_MS` both do.
33032
33037
  *
33033
- * ## Who writes it
33034
- *
33035
- * - **Cameras** — the runner's phase machine, `active → watching` on
33036
- * `cooldown_expired`, which then writes this slice with
33037
- * `detected: false` (`handlePhaseChanged` in
33038
- * `pipeline-runner/index.ts`). It produces the FALLING edge, which
33039
- * matters most for the sources that only ever push a rising one:
33040
- * Reolink emits `MotionOnMotionChanged { detected: true }` and never
33041
- * a false.
33042
- * - **Sensors** (Home Assistant binary sensors, Homematic) — the
33043
- * provider pushes the false itself, from the upstream system's own
33044
- * state change. No phase machine is involved.
33045
- *
33046
- * ### The phase machine is CANONICAL, not sole — and that is a defect
33047
- *
33048
- * An earlier revision of this docblock (mine, 2026-09-12) claimed the
33049
- * phase machine is the sole writer for a camera. It is not.
33050
- * `hikvision-camera.ts:3464` and `amcrest-camera.ts:445` both call
33051
- * `setCapSlice(motionCapability, …)` on their own rising edge, and
33052
- * Hikvision's comment says why: it read THIS docblock, agreed the
33053
- * runner is canonical, and wrote anyway to avoid per-tick churn. So
33054
- * two authorities can disagree about one slice, which this repo
33055
- * forbids, and the doc said otherwise — which is worse than saying
33056
- * nothing, because it reads as verification.
33057
- *
33058
- * This predates D475 and is not fixed there: the fix touches every
33059
- * camera provider. Recorded in D475's Consequences. Do not restore the
33060
- * "sole writer" wording without also removing the other writers.
33038
+ * ## Who writes it (D696)
33039
+ *
33040
+ * - **Cameras** — the orchestrator, and nothing else. It writes the camera's
33041
+ * EFFECTIVE motion (`addon-pipeline-orchestrator`
33042
+ * `camera-sensors/motion-slice.ts`), alongside the effective
33043
+ * `MotionOnMotionChanged` it emits or receives: the camera-sensors bridge
33044
+ * for a split camera, an unsplit emitter's direct event, the analyzer and
33045
+ * device activity, as the camera's `motionSources` counts them. A source
33046
+ * that never sends a clear falls one window after its last `true`.
33047
+ * `lastDetectedAt` moves only on an effective rise. No camera provider
33048
+ * writes this slice (not even a boot seed), and neither does the runner's
33049
+ * phase machine: its phase is "a session is attached" for every on-motion
33050
+ * session, not motion, and it now has its own `DetectionPhaseTransition`.
33051
+ * A provider's `isDetected` answers from the hub's slice.
33052
+ * - **Sensors** (Home Assistant binary sensors, Homematic, Matter, Alexa
33053
+ * imports) — the provider pushes both edges itself, from the upstream
33054
+ * system's own state change. That is the sensor's own fact.
33055
+ *
33056
+ * `scripts/check-onboard-motion-emitters.ts` refuses any other writer of a
33057
+ * `motion` slice; each sensor writer is a named exemption.
33058
+ *
33059
+ * This replaces the D475 §4 rule ("the phase machine is the sole writer").
33060
+ * That rule was never true: Hikvision and Amcrest wrote the slice raw beside
33061
+ * it, every provider seeded it at boot, and every session left it
33062
+ * `detected: true` after its detach.
33061
33063
  */
33062
33064
  autoClearAfterMs: number().nullable()
33063
33065
  });
@@ -33129,11 +33131,12 @@ onMotionChanged: { data: MotionOnMotionChangedDataSchema } },
33129
33131
  */
33130
33132
  runtimeState: MotionStatusSchema,
33131
33133
  /**
33132
- * Runtime-state durability: **session** — every writer of this slice
33134
+ * Runtime-state durability: **session** — the writer of this slice
33133
33135
  * writes only on an EDGE, so a restored `detected: true` would stay
33134
33136
  * frozen until the next one instead of being corrected. The next edge
33135
- * re-publishes the real state. (On who the writers are, and why there
33136
- * is more than one, see `autoClearAfterMs` above.)
33137
+ * re-publishes the real state, and the orchestrator re-publishes every
33138
+ * camera when it starts writing (D696; on who writes it, see
33139
+ * `autoClearAfterMs` above).
33137
33140
  *
33138
33141
  * See `RuntimeStateDurability`. Enforced by
33139
33142
  * `scripts/check-runtime-state-durability.ts`.
@@ -35674,8 +35677,7 @@ var ptzAutotrackCapability = {
35674
35677
  deviceNative: true,
35675
35678
  mode: "singleton",
35676
35679
  /**
35677
- * Two kinds of provider behind one name, the same shape `snapshot` and
35678
- * `doorbell` use:
35680
+ * Two kinds of provider behind one name, the same shape `snapshot` uses:
35679
35681
  *
35680
35682
  * - **Native**: the camera's own firmware autotrack, registered per device by
35681
35683
  * the driver when the probe says it exists (Reolink: yes; Hikvision:
@@ -35683,7 +35685,7 @@ var ptzAutotrackCapability = {
35683
35685
  * - **Wrapper**: the emulated implementation (`@camstack/system`'s `autotrack` builtin),
35684
35686
  * which follows a subject with `ptz.move` pulses driven by the detection
35685
35687
  * pipeline. `defaultActive: false` — the operator binds it per camera in
35686
- * the bindings UI, exactly as `virtual-doorbell` is bound.
35688
+ * the bindings UI.
35687
35689
  *
35688
35690
  * The binding chooses WHICH implementation answers; `setEnabled` stays the
35689
35691
  * one switch for the function either way. A camera never has both driving its
@@ -53277,6 +53279,25 @@ TimelapseRuleInputSchema.extend({
53277
53279
  createdAt: number(),
53278
53280
  updatedAt: number()
53279
53281
  });
53282
+ async function readHubMotionDetected(deviceState, deviceId) {
53283
+ let slice;
53284
+ try {
53285
+ slice = await deviceState.getCapSlice.query({
53286
+ deviceId,
53287
+ capName: "motion"
53288
+ });
53289
+ } catch (err) {
53290
+ const reason = err instanceof Error ? err.message : String(err);
53291
+ throw new Error(`motion state of device ${deviceId} is unreadable: ${reason}`, { cause: err });
53292
+ }
53293
+ const detected = slice?.["detected"];
53294
+ if (typeof detected !== "boolean") throw new Error(`motion state of device ${deviceId} is not published yet (unknown)`);
53295
+ return detected;
53296
+ }
53297
+ MotionOnMotionChangedDataSchema.omit({ triggeredBy: true });
53298
+ function providerMotionEvent(source, data) {
53299
+ return createEvent(EventCategory.ProviderMotion, source, data);
53300
+ }
53280
53301
  object({
53281
53302
  /**
53282
53303
  * Fraction of the box's own size added on EACH side before cutting.
@@ -63089,15 +63110,7 @@ var HikvisionCamera = class HikvisionCamera extends BaseDevice {
63089
63110
  host
63090
63111
  };
63091
63112
  } });
63092
- this.ctx.registerNativeCap(motionCapability, { isDetected: async ({ deviceId }) => {
63093
- if (deviceId !== this.id) throw new Error(`HikvisionCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
63094
- return this.state.motion?.detected ?? false;
63095
- } });
63096
- this.setCapSlice(motionCapability, {
63097
- detected: false,
63098
- lastDetectedAt: null,
63099
- autoClearAfterMs: null
63100
- });
63113
+ this.registerMotionCap();
63101
63114
  this.registerIntercomIfSupported();
63102
63115
  this.registerOsdCap(1);
63103
63116
  this.registerStreamParamsCap(1);
@@ -65566,43 +65579,41 @@ var HikvisionCamera = class HikvisionCamera extends BaseDevice {
65566
65579
  deviceId: this.id
65567
65580
  };
65568
65581
  }
65582
+ /**
65583
+ * The native `motion` cap. Its presence is what defaults the camera to
65584
+ * `motionSources: ['onboard']`. This provider writes NO `motion` slice (D696):
65585
+ * the orchestrator is its only writer, with the EFFECTIVE motion, on the hub.
65586
+ * `isDetected` therefore answers from the hub's slice; an unreadable hub, or
65587
+ * a slice nobody has published since the hub started, makes the call fail.
65588
+ * It never answers `false` for "unknown" (D49, D393).
65589
+ */
65590
+ registerMotionCap() {
65591
+ this.ctx.registerNativeCap(motionCapability, { isDetected: async ({ deviceId }) => {
65592
+ if (deviceId !== this.id) throw new Error(`HikvisionCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
65593
+ return readHubMotionDetected(this.ctx.api.deviceState, this.id);
65594
+ } });
65595
+ }
65569
65596
  handleMotionEvent(ev, camStreamId) {
65570
65597
  const now = ev.observedAt;
65571
- const wasInactive = (this.lastMotionAt.get(camStreamId) ?? 0) === 0;
65572
65598
  this.lastMotionAt.set(camStreamId, now);
65573
- this.ctx.eventBus.emit(createEvent(EventCategory.MotionOnMotionChanged, this.eventSource, {
65599
+ this.ctx.eventBus.emit(providerMotionEvent(this.eventSource, {
65574
65600
  deviceId: this.id,
65575
65601
  detected: true,
65576
65602
  timestamp: now,
65577
65603
  source: "onboard"
65578
65604
  }));
65579
- if (wasInactive) try {
65580
- this.setCapSlice(motionCapability, {
65581
- detected: true,
65582
- lastDetectedAt: now,
65583
- autoClearAfterMs: MOTION_CLOSE_AFTER_MS
65584
- });
65585
- } catch {}
65586
65605
  const existing = this.motionInactiveTimers.get(camStreamId);
65587
65606
  if (existing) clearTimeout(existing);
65588
65607
  const timer = setTimeout(() => {
65589
65608
  const clearedAt = Date.now();
65590
65609
  this.lastMotionAt.set(camStreamId, 0);
65591
65610
  this.motionInactiveTimers.delete(camStreamId);
65592
- this.ctx.eventBus.emit(createEvent(EventCategory.MotionOnMotionChanged, this.eventSource, {
65611
+ this.ctx.eventBus.emit(providerMotionEvent(this.eventSource, {
65593
65612
  deviceId: this.id,
65594
65613
  detected: false,
65595
65614
  timestamp: clearedAt,
65596
65615
  source: "onboard"
65597
65616
  }));
65598
- try {
65599
- const lastDetectedAt = this.state.motion?.lastDetectedAt ?? clearedAt;
65600
- this.setCapSlice(motionCapability, {
65601
- detected: false,
65602
- lastDetectedAt,
65603
- autoClearAfterMs: null
65604
- });
65605
- } catch {}
65606
65617
  }, HikvisionCamera.MOTION_INACTIVE_AFTER_MS);
65607
65618
  this.motionInactiveTimers.set(camStreamId, timer);
65608
65619
  }