@camstack/system 1.2.55 → 1.2.57

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 (52) hide show
  1. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  2. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  3. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  4. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  5. package/dist/builtins/alerts/alerts.addon.js +1 -1
  6. package/dist/builtins/alerts/alerts.addon.mjs +1 -1
  7. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +1 -1
  8. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
  9. package/dist/builtins/console-logging/index.js +1 -1
  10. package/dist/builtins/console-logging/index.mjs +1 -1
  11. package/dist/builtins/core-blocks/core-blocks.addon.js +1 -1
  12. package/dist/builtins/core-blocks/core-blocks.addon.mjs +1 -1
  13. package/dist/builtins/device-manager/device-manager.addon.js +1 -1
  14. package/dist/builtins/device-manager/device-manager.addon.mjs +1 -1
  15. package/dist/builtins/doorbell/binding-mirror.d.ts +50 -0
  16. package/dist/builtins/doorbell/trigger-engine.d.ts +85 -8
  17. package/dist/builtins/doorbell/virtual-doorbell.addon.d.ts +53 -11
  18. package/dist/builtins/doorbell/virtual-doorbell.addon.js +243 -42
  19. package/dist/builtins/doorbell/virtual-doorbell.addon.mjs +243 -42
  20. package/dist/builtins/hub-forwarder/index.js +1 -1
  21. package/dist/builtins/hub-forwarder/index.mjs +1 -1
  22. package/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  23. package/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  24. package/dist/builtins/local-auth/local-auth.addon.js +1 -1
  25. package/dist/builtins/local-auth/local-auth.addon.mjs +1 -1
  26. package/dist/builtins/local-network/local-network.addon.js +1 -1
  27. package/dist/builtins/local-network/local-network.addon.mjs +1 -1
  28. package/dist/builtins/loki-logging/index.js +1 -1
  29. package/dist/builtins/loki-logging/index.mjs +1 -1
  30. package/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  31. package/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  32. package/dist/builtins/platform-probe/index.js +1 -1
  33. package/dist/builtins/platform-probe/index.mjs +1 -1
  34. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  35. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  36. package/dist/builtins/snapshot/index.js +1 -1
  37. package/dist/builtins/snapshot/index.mjs +1 -1
  38. package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  39. package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  40. package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +1 -1
  41. package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +1 -1
  42. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  43. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  44. package/dist/builtins/system-config/system-config.addon.js +1 -1
  45. package/dist/builtins/system-config/system-config.addon.mjs +1 -1
  46. package/dist/builtins/winston-logging/index.js +1 -1
  47. package/dist/builtins/winston-logging/index.mjs +1 -1
  48. package/dist/{dist-CblJsHb-.js → dist-BupxnZOi.js} +66 -14
  49. package/dist/{dist-BOpRqInW.mjs → dist-DhL_zGRT.mjs} +66 -14
  50. package/dist/index.js +1 -1
  51. package/dist/index.mjs +1 -1
  52. package/package.json +1 -1
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CblJsHb-.js");
6
+ const require_dist = require("../../dist-BupxnZOi.js");
7
7
  //#region src/builtins/doorbell/trigger-engine.ts
8
8
  /**
9
9
  * Pure trigger logic for the virtual-doorbell builtin — edge detection over
@@ -37,6 +37,30 @@ var SOURCE_CAP_ACTIVE_FIELD = {
37
37
  vibration: "detected",
38
38
  tamper: "tampered"
39
39
  };
40
+ /**
41
+ * The same caps → the slice field carrying the ms-epoch timestamp of the
42
+ * last transition. Every source cap MUST appear here (guarded by a spec):
43
+ * without a transition timestamp the engine cannot tell a genuine press
44
+ * from a boot-time hydration when the FIRST slice it ever sees is already
45
+ * active, and errs towards silence — swallowing the press.
46
+ *
47
+ * These timestamps are UPSTREAM ones, not ingest ones: the Home Assistant
48
+ * provider derives them from `state.last_changed`, so they survive our own
49
+ * restarts and correctly read as "hours ago" for a state that has been
50
+ * active for hours. `motion` names its rise timestamp `lastDetectedAt`.
51
+ */
52
+ var SOURCE_CAP_CHANGED_AT_FIELD = {
53
+ contact: "lastChangedAt",
54
+ binary: "lastChangedAt",
55
+ switch: "lastChangedAt",
56
+ motion: "lastDetectedAt",
57
+ flood: "lastChangedAt",
58
+ gas: "lastChangedAt",
59
+ smoke: "lastChangedAt",
60
+ "carbon-monoxide": "lastChangedAt",
61
+ vibration: "lastChangedAt",
62
+ tamper: "lastChangedAt"
63
+ };
40
64
  /** Cap names whose presence in a device's bindings qualify it as a source. */
41
65
  var SOURCE_CAPS = Object.keys(SOURCE_CAP_ACTIVE_FIELD);
42
66
  /**
@@ -73,14 +97,46 @@ function sliceActiveValue(capName, slice) {
73
97
  const raw = slice[field];
74
98
  return typeof raw === "boolean" ? raw : null;
75
99
  }
100
+ /** Ms-epoch transition timestamp a source cap's slice carries, or null when
101
+ * it is absent, non-numeric or the zero "never observed" sentinel. */
102
+ function sliceChangedAt(capName, slice) {
103
+ const field = SOURCE_CAP_CHANGED_AT_FIELD[capName];
104
+ if (field === void 0) return null;
105
+ const raw = slice[field];
106
+ if (typeof raw !== "number" || !Number.isFinite(raw) || raw <= 0) return null;
107
+ return raw;
108
+ }
109
+ function ignoredResult(reason) {
110
+ return {
111
+ fired: [],
112
+ debounced: [],
113
+ ignored: reason
114
+ };
115
+ }
76
116
  /**
77
117
  * Stateful (but side-effect-free towards the outside) trigger engine.
78
118
  *
79
119
  * Tracks the last observed binary value per (sourceDevice, cap) so a
80
120
  * `DeviceStateChanged` re-emission (the slice's `lastChangedAt` moves while
81
- * the binary value does not) never double-fires, and the FIRST observation
82
- * after boot only seeds the baseline — a state hydration at startup must not
83
- * ring anybody's doorbell.
121
+ * the binary value does not) never double-fires.
122
+ *
123
+ * FIRST SIGHTINGS. Seeding the baseline and never firing was wrong for the
124
+ * one case that matters: a momentary source (a button wired to a Home
125
+ * Assistant switch) is NOT re-pushed in its resting `off` state after a hub
126
+ * restart, so after every restart — several a day — the first slice the
127
+ * engine ever sees for it is the PRESS ITSELF, already active. That press
128
+ * was eaten whole; a real one on 2026-08-05 left no trace anywhere.
129
+ *
130
+ * The discriminator is the source's own transition timestamp. A first
131
+ * sighting that is already active rings only when its transition can be
132
+ * proved to have happened AFTER this engine started watching AND within
133
+ * `firstSightingFreshnessMs`. Both halves earn their keep: freshness alone
134
+ * would ring on a boot hydration of a state that flipped seconds before the
135
+ * restart, and "after we started" alone would ring, on a long-lived
136
+ * process, for a source adopted today whose state flipped yesterday. An
137
+ * undateable first sighting (no timestamp, or a zero sentinel) does NOT
138
+ * ring — the ambiguous case errs towards silence, but reports
139
+ * `baseline-seeded-stale-active` so the caller can say so out loud.
84
140
  */
85
141
  var DoorbellTriggerEngine = class {
86
142
  assignments = [];
@@ -90,9 +146,14 @@ var DoorbellTriggerEngine = class {
90
146
  lastFiredAt = /* @__PURE__ */ new Map();
91
147
  debounceMs;
92
148
  now;
149
+ firstSightingFreshnessMs;
150
+ /** When this engine started watching — the floor for a first-sighting rise. */
151
+ startedAt;
93
152
  constructor(options) {
94
153
  this.debounceMs = options?.debounceMs ?? 2e3;
95
154
  this.now = options?.now ?? Date.now;
155
+ this.firstSightingFreshnessMs = options?.firstSightingFreshnessMs ?? 3e4;
156
+ this.startedAt = this.now();
96
157
  }
97
158
  /** Replace the full assignment set (rebuilt whenever settings change). */
98
159
  setAssignments(assignments) {
@@ -106,35 +167,77 @@ var DoorbellTriggerEngine = class {
106
167
  return this.assignments.some((a) => a.sourceDeviceId === deviceId);
107
168
  }
108
169
  /**
109
- * Feed one `DeviceStateChanged` slice. Returns the camera ids whose
110
- * doorbell should ring (already debounced). Only a false→true rise on a
111
- * recognised source cap fires; baseline-only sightings, re-emissions, and
112
- * the falling edge return an empty array.
170
+ * Feed one `DeviceStateChanged` slice. Reports which cameras should ring,
171
+ * which were suppressed by the debounce window, and when nothing was
172
+ * matched at all WHY. Only a rise to active on a recognised source cap
173
+ * can ring; re-emissions and the falling edge never do.
113
174
  */
114
175
  onStateSlice(deviceId, capName, slice) {
115
176
  const value = sliceActiveValue(capName, slice);
116
- if (value === null) return [];
177
+ if (value === null) return ignoredResult(isSourceCap(capName) ? "non-boolean-value" : "unknown-cap");
117
178
  const key = `${deviceId}:${capName}`;
118
179
  const prior = this.lastValues.get(key);
119
180
  this.lastValues.set(key, value);
120
- if (prior === void 0 || prior === value) return [];
121
- if (!value) return [];
122
- return this.matchAndDebounce((a) => a.sourceDeviceId === deviceId);
181
+ if (prior === void 0) {
182
+ if (!value) return ignoredResult("baseline-seeded-inactive");
183
+ if (!this.roseAfterWeStartedWatching(capName, slice)) return ignoredResult("baseline-seeded-stale-active");
184
+ return this.matchAndDebounce(deviceId);
185
+ }
186
+ if (prior === value) return ignoredResult("no-change");
187
+ if (!value) return ignoredResult("falling-edge");
188
+ return this.matchAndDebounce(deviceId);
123
189
  }
124
- matchAndDebounce(predicate) {
190
+ /**
191
+ * Can this slice PROVE its active state is a transition we would have
192
+ * witnessed had we been listening — i.e. recent, and after we started?
193
+ */
194
+ roseAfterWeStartedWatching(capName, slice) {
195
+ const changedAt = sliceChangedAt(capName, slice);
196
+ if (changedAt === null) return false;
197
+ return changedAt >= Math.max(this.startedAt, this.now() - this.firstSightingFreshnessMs);
198
+ }
199
+ matchAndDebounce(sourceDeviceId) {
125
200
  const now = this.now();
126
201
  const fired = [];
202
+ const debounced = [];
127
203
  for (const assignment of this.assignments) {
128
- if (!predicate(assignment)) continue;
204
+ if (assignment.sourceDeviceId !== sourceDeviceId) continue;
129
205
  const last = this.lastFiredAt.get(assignment.cameraId);
130
- if (last !== void 0 && now - last < this.debounceMs) continue;
206
+ if (last !== void 0 && now - last < this.debounceMs) {
207
+ debounced.push(assignment.cameraId);
208
+ continue;
209
+ }
131
210
  this.lastFiredAt.set(assignment.cameraId, now);
132
211
  fired.push(assignment.cameraId);
133
212
  }
134
- return fired;
213
+ if (fired.length === 0 && debounced.length === 0) return ignoredResult("no-assignment");
214
+ return {
215
+ fired,
216
+ debounced,
217
+ ignored: null
218
+ };
135
219
  }
136
220
  };
137
221
  //#endregion
222
+ //#region src/builtins/doorbell/binding-mirror.ts
223
+ /**
224
+ * Fold one SUCCESSFUL bindings read into the mirror. A read that failed must
225
+ * never reach this function — an unanswerable store carries no information
226
+ * and must leave the mirror exactly as it was.
227
+ */
228
+ function nextBindingState(previous, boundNow) {
229
+ if (boundNow) return "bound";
230
+ return previous === "unbind-pending" || previous === "unbound" ? "unbound" : "unbind-pending";
231
+ }
232
+ /** May a ring proceed? Only a corroborated unbind stops one. */
233
+ function allowsRing(state) {
234
+ return state !== "unbound";
235
+ }
236
+ /** True only when a read has positively confirmed the binding. */
237
+ function hasConfirmedBinding(state) {
238
+ return state === "bound";
239
+ }
240
+ //#endregion
138
241
  //#region src/builtins/doorbell/doorbell-settings.ts
139
242
  /**
140
243
  * Pure per-camera settings parsing/normalization for the virtual-doorbell
@@ -227,10 +330,6 @@ function applyDoorbellSourcesPatch(current, patchValue) {
227
330
  }
228
331
  //#endregion
229
332
  //#region src/builtins/doorbell/virtual-doorbell.addon.ts
230
- /** Reload the camera→source assignment map at most this often (lazily,
231
- * on trigger traffic). Covers devices/settings appearing after boot
232
- * without a settings save. */
233
- var ASSIGNMENTS_TTL_MS = 6e4;
234
333
  /** Structural narrowing helper for untrusted bus payloads. */
235
334
  function isRecord(value) {
236
335
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -286,19 +385,32 @@ function parseDoorbellSlice(slice) {
286
385
  * bumps the camera's `doorbell` runtime-state counters via the
287
386
  * standard `deviceState.setCapSlice` plumbing.
288
387
  *
289
- * Fires ONLY for cameras where the wrapper is BOUND (checked against
290
- * `deviceManager.getBindings`) and at least one source device is configured.
388
+ * Fires ONLY for cameras with at least one configured source device that
389
+ * this wrapper is BOUND to. The binding is NOT re-derived on the ring path:
390
+ * it is mirrored in memory (`binding-mirror.ts`) and refreshed on the
391
+ * assignment-reload cadence, because a fallible read must never be able to
392
+ * destroy a one-shot press.
291
393
  */
292
394
  var VirtualDoorbellAddon = class extends require_dist.BaseAddon {
293
395
  engine;
294
396
  /** Monotonic guard: assignments are reloaded lazily on trigger traffic. */
295
397
  assignmentsLoadedAt = 0;
296
398
  assignmentsLoading = null;
399
+ /**
400
+ * Per-camera mirror of "is this wrapper still the active doorbell
401
+ * binding". Written ONLY off the ring path; read on it. See
402
+ * `binding-mirror.ts` for why a single negative read is not believed.
403
+ */
404
+ bindingMirror = /* @__PURE__ */ new Map();
297
405
  constructor() {
298
- super({ debounceMs: 2e3 });
406
+ super({
407
+ debounceMs: 2e3,
408
+ assignmentsTtlMs: 6e4
409
+ });
299
410
  this.engine = new DoorbellTriggerEngine({ debounceMs: 2e3 });
300
411
  }
301
412
  async onInitialize() {
413
+ this.engine = new DoorbellTriggerEngine({ debounceMs: this.config.debounceMs });
302
414
  this.ctx.logger.info("Virtual doorbell wrapper initialized");
303
415
  this.subscribe({ category: require_dist.EventCategory.DeviceStateChanged }, (event) => {
304
416
  const data = parseDeviceStateChanged(event.data);
@@ -318,22 +430,62 @@ var VirtualDoorbellAddon = class extends require_dist.BaseAddon {
318
430
  async handleStateChanged(data) {
319
431
  if (!isSourceCap(data.capName)) return;
320
432
  await this.ensureAssignments();
321
- const cameraIds = this.engine.onStateSlice(data.deviceId, data.capName, data.slice);
322
- for (const cameraId of cameraIds) await this.fireDoorbell(cameraId, Date.now());
433
+ const result = this.engine.onStateSlice(data.deviceId, data.capName, data.slice);
434
+ this.logSuppressions(data, result);
435
+ for (const cameraId of result.fired) await this.fireDoorbell(cameraId, Date.now());
436
+ }
437
+ /**
438
+ * Say out loud every case where a rise did NOT become a ring. Silence
439
+ * reads as "never happened": three real presses on camera 615 produced
440
+ * zero operator-visible lines because the drop logged at `debug`.
441
+ */
442
+ logSuppressions(data, result) {
443
+ for (const cameraId of result.debounced) this.ctx.logger.info("virtual-doorbell: rise suppressed by the debounce window", {
444
+ tags: { deviceId: cameraId },
445
+ meta: {
446
+ sourceDeviceId: data.deviceId,
447
+ capName: data.capName
448
+ }
449
+ });
450
+ if (result.ignored === "baseline-seeded-stale-active") {
451
+ const message = "virtual-doorbell: first slice seen for this source is already ACTIVE but its transition could not be dated — seeded as baseline, a press may have been swallowed";
452
+ const options = {
453
+ tags: { deviceId: data.deviceId },
454
+ meta: { capName: data.capName }
455
+ };
456
+ if (this.engine.hasSource(data.deviceId)) this.ctx.logger.warn(message, options);
457
+ else this.ctx.logger.debug(message, options);
458
+ return;
459
+ }
460
+ if (result.ignored === "no-assignment") this.ctx.logger.debug("virtual-doorbell: rise on a source no camera is wired to", {
461
+ tags: { deviceId: data.deviceId },
462
+ meta: { capName: data.capName }
463
+ });
323
464
  }
324
465
  /**
325
- * Ring the camera's virtual doorbell: verify the wrapper is BOUND to
326
- * the camera, bump the `doorbell` runtime-state counters through the
327
- * canonical `deviceState.setCapSlice` write, and emit the typed
328
- * `DoorbellOnPressed` event with the CAMERA as source byte-shaped
329
- * like a native firmware ring so every downstream consumer (UI
330
- * toast, notifier rules, exporters) is agnostic to the origin.
466
+ * Ring the camera's virtual doorbell: bump the `doorbell` runtime-state
467
+ * counters through the canonical `deviceState.setCapSlice` write, and
468
+ * emit the typed `DoorbellOnPressed` event with the CAMERA as source —
469
+ * byte-shaped like a native firmware ring so every downstream consumer
470
+ * (UI toast, notifier rules, exporters) is agnostic to the origin.
471
+ *
472
+ * The binding gate here is a pure in-memory read. It performs NO I/O and
473
+ * cannot fail: the whole point of the mirror is that the ring path can no
474
+ * longer be talked out of ringing by a store that answered badly.
331
475
  */
332
476
  async fireDoorbell(cameraId, timestamp) {
333
- if (!await this.isWrapperBound(cameraId)) {
334
- this.ctx.logger.debug("virtual-doorbell: trigger matched but wrapper not bound — skipping", { tags: { deviceId: cameraId } });
477
+ const binding = this.bindingMirror.get(cameraId);
478
+ if (!allowsRing(binding)) {
479
+ this.ctx.logger.warn("virtual-doorbell: ring DROPPED — the wrapper is not bound to this camera, but a trigger source is still configured for it", {
480
+ tags: { deviceId: cameraId },
481
+ meta: { bindingState: binding }
482
+ });
335
483
  return;
336
484
  }
485
+ if (!hasConfirmedBinding(binding)) this.ctx.logger.warn("virtual-doorbell: ringing on an unconfirmed binding — the bindings store has not corroborated an unbind, and a one-shot press is never dropped on an unproven read", {
486
+ tags: { deviceId: cameraId },
487
+ meta: { bindingState: binding ?? "never-read" }
488
+ });
337
489
  try {
338
490
  const next = {
339
491
  lastPressedAt: timestamp,
@@ -367,17 +519,51 @@ var VirtualDoorbellAddon = class extends require_dist.BaseAddon {
367
519
  meta: { timestamp }
368
520
  });
369
521
  }
370
- /** True when THIS wrapper is the active `doorbell` binding for the camera. */
371
- async isWrapperBound(cameraId) {
522
+ /**
523
+ * Fold one bindings read for `cameraId` into the mirror. Runs on the
524
+ * assignment-reload cadence, never while firing.
525
+ *
526
+ * A read that THROWS carries no information and leaves the mirror exactly
527
+ * as it was — the previous verdict keeps standing. A read that succeeds
528
+ * but omits our activation only ARMS a revocation; `nextBindingState`
529
+ * requires a second consecutive negative before the camera goes silent,
530
+ * because a genuine unbind and a store answering from an empty snapshot
531
+ * (D44) are indistinguishable in a single response.
532
+ */
533
+ async refreshBindingMirror(cameraId) {
534
+ let entries;
372
535
  try {
373
- return (await this.ctx.api.deviceManager.getBindings.query({ deviceId: cameraId })).entries.some((entry) => entry.capName === require_dist.doorbellCapability.name && entry.kind === "wrapped" && entry.providerAddonId === this.ctx.id);
536
+ entries = (await this.ctx.api.deviceManager.getBindings.query({ deviceId: cameraId })).entries;
374
537
  } catch (err) {
375
- this.ctx.logger.debug("virtual-doorbell: getBindings failed — treating as unbound", {
538
+ this.ctx.logger.warn("virtual-doorbell: binding check failed — keeping the last known verdict, NOT treating this as an unbind", {
376
539
  tags: { deviceId: cameraId },
377
- meta: { error: require_dist.errMsg(err) }
540
+ meta: {
541
+ error: require_dist.errMsg(err),
542
+ bindingState: this.bindingMirror.get(cameraId)
543
+ }
378
544
  });
379
- return false;
545
+ return;
380
546
  }
547
+ const boundNow = entries.some((entry) => entry.capName === require_dist.doorbellCapability.name && entry.kind === "wrapped" && entry.providerAddonId === this.ctx.id);
548
+ const previous = this.bindingMirror.get(cameraId);
549
+ const next = nextBindingState(previous, boundNow);
550
+ this.bindingMirror.set(cameraId, next);
551
+ if (next !== previous && next !== "bound") this.ctx.logger.warn("virtual-doorbell: bindings read did not see this wrapper", {
552
+ tags: { deviceId: cameraId },
553
+ meta: {
554
+ from: previous ?? "never-read",
555
+ to: next
556
+ }
557
+ });
558
+ }
559
+ /**
560
+ * Record a binding we observed FIRST-HAND. Both callers are cap methods
561
+ * the router only reaches by resolving this wrapper for this device —
562
+ * which it can only do through the binding — so a call is direct evidence
563
+ * and outranks anything the store says.
564
+ */
565
+ confirmBindingFromCapCall(deviceId) {
566
+ this.bindingMirror.set(deviceId, nextBindingState(this.bindingMirror.get(deviceId), true));
381
567
  }
382
568
  /**
383
569
  * Lazily (re)build the camera→source assignment set from every
@@ -386,7 +572,8 @@ var VirtualDoorbellAddon = class extends require_dist.BaseAddon {
386
572
  * eagerly by `applyDeviceSettingsPatch`.
387
573
  */
388
574
  async ensureAssignments() {
389
- if (Date.now() - this.assignmentsLoadedAt < ASSIGNMENTS_TTL_MS) return;
575
+ const now = Date.now();
576
+ if (this.assignmentsLoadedAt > 0 && now - this.assignmentsLoadedAt < this.config.assignmentsTtlMs) return;
390
577
  if (this.assignmentsLoading) return this.assignmentsLoading;
391
578
  this.assignmentsLoading = this.loadAssignments().then(() => {
392
579
  this.assignmentsLoadedAt = Date.now();
@@ -398,17 +585,29 @@ var VirtualDoorbellAddon = class extends require_dist.BaseAddon {
398
585
  return this.assignmentsLoading;
399
586
  }
400
587
  async loadAssignments() {
588
+ if (!this.ctx.settings) {
589
+ this.ctx.logger.warn("virtual-doorbell: no settings store — every camera reads ZERO trigger sources, no doorbell can ring");
590
+ return;
591
+ }
401
592
  const cameras = (await this.ctx.api.deviceManager.listAll.query({})).filter((d) => d.type === require_dist.DeviceType.Camera);
402
593
  const assignments = [];
594
+ const configuredCameras = [];
403
595
  for (const camera of cameras) {
404
596
  const sources = await this.readDeviceSources(camera.id);
597
+ if (sources.length > 0) configuredCameras.push(camera.id);
405
598
  for (const source of sources) assignments.push({
406
599
  cameraId: camera.id,
407
600
  sourceDeviceId: source.deviceId
408
601
  });
409
602
  }
603
+ for (const cameraId of configuredCameras) await this.refreshBindingMirror(cameraId);
604
+ const hadAssignments = this.engine.getAssignments().length > 0;
410
605
  this.engine.setAssignments(assignments);
411
- this.ctx.logger.debug("virtual-doorbell: assignments loaded", { meta: { count: assignments.length } });
606
+ if (hadAssignments && assignments.length === 0) this.ctx.logger.warn("virtual-doorbell: assignment reload went from configured to EMPTY every camera just lost its trigger sources");
607
+ this.ctx.logger.debug("virtual-doorbell: assignments loaded", { meta: {
608
+ count: assignments.length,
609
+ configuredCameras: configuredCameras.length
610
+ } });
412
611
  }
413
612
  invalidateAssignments() {
414
613
  this.assignmentsLoadedAt = 0;
@@ -425,7 +624,7 @@ var VirtualDoorbellAddon = class extends require_dist.BaseAddon {
425
624
  capName: require_dist.doorbellCapability.name
426
625
  }));
427
626
  } catch (err) {
428
- this.ctx.logger.debug("virtual-doorbell: getCapSlice failed during getStatus", {
627
+ this.ctx.logger.warn("virtual-doorbell: getCapSlice failed during getStatus", {
429
628
  tags: { deviceId },
430
629
  meta: { error: require_dist.errMsg(err) }
431
630
  });
@@ -477,6 +676,7 @@ var VirtualDoorbellAddon = class extends require_dist.BaseAddon {
477
676
  async buildDeviceSettingsContribution(deviceId) {
478
677
  const device = await this.lookupDevice(deviceId);
479
678
  if (device && device.type !== require_dist.DeviceType.Camera) return null;
679
+ this.confirmBindingFromCapCall(deviceId);
480
680
  const sources = await this.readDeviceSources(deviceId);
481
681
  return { sections: [{
482
682
  id: "virtual-doorbell",
@@ -499,6 +699,7 @@ var VirtualDoorbellAddon = class extends require_dist.BaseAddon {
499
699
  }
500
700
  async saveDeviceSettingsPatch(deviceId, patch) {
501
701
  if (!this.ctx.settings) throw new Error("[virtual-doorbell] settings store unavailable — cannot persist per-device settings");
702
+ this.confirmBindingFromCapCall(deviceId);
502
703
  if ("doorbellSources" in patch) {
503
704
  const next = applyDoorbellSourcesPatch(await this.ctx.settings.readDeviceStore(deviceId), patch[KEY_SOURCES]);
504
705
  await this.ctx.settings.writeDeviceStore(deviceId, next);