@camstack/addon-provider-reolink 1.2.261 → 1.2.263

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.263] - 2026-11-25
11
+
12
+ ### Changed
13
+
14
+ - A stream that stalls because one packet never arrived is now logged with the missing packet and how long media was withheld
15
+
16
+ ## [1.2.262] - 2026-11-25
17
+
18
+ ### Changed
19
+
20
+ - Reolink: an awake camera that drops its connection (D2C_DISC) is redialled after a short capped backoff instead of a long wait, so recording resumes sooner.
21
+
10
22
  ## [1.2.261] - 2026-11-24
11
23
 
12
24
  ### Changed
package/dist/addon.js CHANGED
@@ -29165,7 +29165,7 @@ var require_lz4 = /* @__PURE__ */ require_chunk.__commonJSMin(((exports) => {
29165
29165
  };
29166
29166
  }));
29167
29167
  //#endregion
29168
- //#region node_modules/@apocaliss92/nodelink-js/dist/chunk-MC2CLGY2.js
29168
+ //#region node_modules/@apocaliss92/nodelink-js/dist/chunk-7P5XTMMX.js
29169
29169
  var import_fxp = require_fxp();
29170
29170
  var import_lz4 = /* @__PURE__ */ require_chunk.__toESM(require_lz4(), 1);
29171
29171
  function bcHeaderLen(messageClass, buf, bodyLen) {
@@ -29990,6 +29990,9 @@ var BcUdpStream = class extends events.EventEmitter {
29990
29990
  received = /* @__PURE__ */ new Map();
29991
29991
  sent = /* @__PURE__ */ new Map();
29992
29992
  ackTimer;
29993
+ /** When delivery first became blocked by a missing packet (head-of-line). */
29994
+ holSinceMs;
29995
+ holStallLogged = false;
29993
29996
  resendTimer;
29994
29997
  hbTimer;
29995
29998
  discoveryTid;
@@ -30922,7 +30925,12 @@ var BcUdpStream = class extends events.EventEmitter {
30922
30925
  lastAckRxAgoMs: this.lastAckRxAtMs !== void 0 ? now - this.lastAckRxAtMs : void 0,
30923
30926
  unackedPackets: this.sent.size,
30924
30927
  ...oldestUnackedAgeMs !== void 0 ? { oldestUnackedAgeMs } : {},
30925
- discFromCamera: this.discFromCameraAtMs !== void 0
30928
+ discFromCamera: this.discFromCameraAtMs !== void 0,
30929
+ ...this.holSinceMs !== void 0 && this.received.size > 0 ? {
30930
+ holBlockedMs: now - this.holSinceMs,
30931
+ holMissingPacketId: this.packetsWant
30932
+ } : {},
30933
+ holBufferedPackets: this.received.size
30926
30934
  };
30927
30935
  }
30928
30936
  /**
@@ -30933,6 +30941,12 @@ var BcUdpStream = class extends events.EventEmitter {
30933
30941
  checkStalls(now) {
30934
30942
  const age = this.connectedAtMs !== void 0 ? now - this.connectedAtMs : void 0;
30935
30943
  const diag = this.getSessionDiagnostics(now);
30944
+ const holStalled = diag.holBlockedMs !== void 0 && diag.holBlockedMs >= 1500;
30945
+ if (holStalled && !this.holStallLogged) {
30946
+ this.holStallLogged = true;
30947
+ this.discoveryLogger?.warn?.(`[BcUdpStream] head-of-line stall: packet ${diag.holMissingPacketId} missing for ${diag.holBlockedMs}ms, ${diag.holBufferedPackets} later packet(s) withheld, lastDataRxAgoMs=${diag.lastDataRxAgoMs ?? "none"} sessionAgeMs=${age}`);
30948
+ this.emit("debug", "hol_stall", { ...diag });
30949
+ } else if (!holStalled) this.holStallLogged = false;
30936
30950
  const ackStalled = diag.oldestUnackedAgeMs !== void 0 && diag.oldestUnackedAgeMs >= 5e3;
30937
30951
  if (ackStalled && !this.ackWindowStallLogged) {
30938
30952
  this.ackWindowStallLogged = true;
@@ -30977,6 +30991,10 @@ var BcUdpStream = class extends events.EventEmitter {
30977
30991
  }
30978
30992
  });
30979
30993
  }
30994
+ trackHeadOfLine(now) {
30995
+ if (!(this.received.size > 0 && !this.received.has(this.packetsWant))) this.holSinceMs = void 0;
30996
+ else if (this.holSinceMs === void 0) this.holSinceMs = now;
30997
+ }
30980
30998
  flushReceived() {
30981
30999
  while (this.received.has(this.packetsWant)) {
30982
31000
  const chunk = this.received.get(this.packetsWant);
@@ -31019,6 +31037,7 @@ var BcUdpStream = class extends events.EventEmitter {
31019
31037
  if (p.packetId >= this.packetsWant) {
31020
31038
  this.received.set(p.packetId, p.payload);
31021
31039
  this.flushReceived();
31040
+ this.trackHeadOfLine(Date.now());
31022
31041
  this.updateAckPacket();
31023
31042
  if (this.packetsWant % 100 === 0) this.emit("debug", "udp_progress", { packetsWant: this.packetsWant });
31024
31043
  }
@@ -39257,6 +39276,31 @@ function mapBaichuanWebhookParsedToSimpleEvents(parsed) {
39257
39276
  if (parsed.cmdId === 33) return mapBaichuanWebhookAlarmXmlToSimpleEvents(parsed.xml);
39258
39277
  return [];
39259
39278
  }
39279
+ var D2C_DISC_AWAKE_FIRST_BACKOFF_MS = 1e4;
39280
+ var D2C_DISC_AWAKE_MAX_BACKOFF_MS = 3e4;
39281
+ var D2C_DISC_YOUNG_SESSION_MS = 6e4;
39282
+ var D2C_DISC_AWAKE_STREAK_RESET_MS = 12e4;
39283
+ function isAwakeFlap(input) {
39284
+ return input.camState === "awake" && input.sessionAgeMs < D2C_DISC_YOUNG_SESSION_MS;
39285
+ }
39286
+ var AwakeDiscBackoff = class {
39287
+ streak = 0;
39288
+ lastAtMs = 0;
39289
+ /** Records an awake drop at `nowMs`; returns its refusal duration. */
39290
+ next(nowMs) {
39291
+ if (this.lastAtMs === 0 || nowMs - this.lastAtMs > D2C_DISC_AWAKE_STREAK_RESET_MS) this.streak = 0;
39292
+ this.streak += 1;
39293
+ this.lastAtMs = nowMs;
39294
+ return this.streak === 1 ? D2C_DISC_AWAKE_FIRST_BACKOFF_MS : D2C_DISC_AWAKE_MAX_BACKOFF_MS;
39295
+ }
39296
+ };
39297
+ function describeCooldownReason(reason) {
39298
+ switch (reason) {
39299
+ case "d2c-disc-awake-backoff": return "cooldown after disconnect (camera awake, link unstable)";
39300
+ case "d2c-disc-sleep": return "D2C_DISC (camera sleeping)";
39301
+ case "login-failures": return "repeated login failures";
39302
+ }
39303
+ }
39260
39304
  var parser = new import_fxp.XMLParser({
39261
39305
  ignoreAttributes: false,
39262
39306
  attributeNamePrefix: "@_",
@@ -41800,6 +41844,7 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
41800
41844
  * Value: object with failureCount, lastFailureAt, cooldownUntil
41801
41845
  */
41802
41846
  socketPoolCooldowns = /* @__PURE__ */ new Map();
41847
+ awakeDiscBackoff = new AwakeDiscBackoff();
41803
41848
  /** Base cooldown duration (ms) for socket failures. */
41804
41849
  static SOCKET_POOL_BASE_COOLDOWN_MS = 5e3;
41805
41850
  /** Max cooldown duration (ms) - caps exponential backoff. */
@@ -42185,7 +42230,8 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
42185
42230
  * pool socket receives the disconnect.
42186
42231
  */
42187
42232
  attachD2cDiscListener(client) {
42188
- client.on("d2c_disc", () => this.notifyD2cDisc());
42233
+ const sessionStartedAtMs = Date.now();
42234
+ client.on("d2c_disc", () => this.notifyD2cDisc(Date.now() - sessionStartedAtMs));
42189
42235
  client.on("error", () => {});
42190
42236
  }
42191
42237
  /**
@@ -42206,7 +42252,8 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
42206
42252
  log?.debug?.(`[SocketPool] Cooldown reset for host=${this.host} (no failures for ${_ReolinkBaichuanApi.SOCKET_POOL_FAILURE_WINDOW_MS}ms)`);
42207
42253
  } else if (now < cooldownEntry.cooldownUntil) {
42208
42254
  const remainingMs = cooldownEntry.cooldownUntil - now;
42209
- const reason = this.lastD2cDiscAtMs > 0 && now - this.lastD2cDiscAtMs < 12e4 ? "D2C_DISC (camera sleeping)" : "repeated login failures";
42255
+ const isD2cDisc = this.lastD2cDiscAtMs > 0 && now - this.lastD2cDiscAtMs < 12e4;
42256
+ const reason = describeCooldownReason(cooldownEntry.reason ?? (isD2cDisc ? "d2c-disc-sleep" : "login-failures"));
42210
42257
  const error = /* @__PURE__ */ new Error(`[SocketPool] Host ${this.host} is in cooldown for ${Math.ceil(remainingMs / 1e3)}s due to ${reason}. tag=${tag2}`);
42211
42258
  log?.debug?.(error.message);
42212
42259
  throw error;
@@ -47765,26 +47812,46 @@ ${stderr}`));
47765
47812
  /**
47766
47813
  * Called when any BaichuanClient for this device receives a D2C_DISC.
47767
47814
  *
47768
- * Two-tier response:
47815
+ * An AWAKE camera whose young session was dropped (flapping link) gets a
47816
+ * short capped backoff (10 s, then 30 s) and never the storm cooldown.
47817
+ * Anything else (asleep, unknown, old session) keeps the sleep-safe tiers:
47769
47818
  * 1. **Immediate**: every D2C_DISC applies a short socket pool cooldown
47770
47819
  * (10 s) to prevent reconnect attempts while the camera transitions to sleep.
47771
47820
  * 2. **Storm**: ≥3 D2C_DISCs within 60 s triggers extended cooldown (120 s).
47772
47821
  */
47773
- notifyD2cDisc() {
47822
+ notifyD2cDisc(sessionAgeMs) {
47774
47823
  const now = Date.now();
47824
+ const awakeFlap = isAwakeFlap({
47825
+ camState: this.getSleepStatus().state,
47826
+ sessionAgeMs
47827
+ });
47775
47828
  this.lastD2cDiscAtMs = now;
47776
47829
  const streamingTags = Array.from(this.socketPool.keys()).filter((tag2) => tag2.startsWith("streaming:"));
47777
47830
  if (streamingTags.length > 0) {
47778
47831
  this.logger?.log?.(`[D2C_DISC] Force-closing ${streamingTags.length} streaming socket(s): ${streamingTags.join(", ")}`);
47779
47832
  for (const tag2 of streamingTags) this.forceClosePooledSocket(tag2, this.logger).catch(() => {});
47780
47833
  }
47834
+ if (awakeFlap) {
47835
+ const backoffMs = this.awakeDiscBackoff.next(now);
47836
+ const awakeUntil = now + backoffMs;
47837
+ const prev = this.socketPoolCooldowns.get(this.host);
47838
+ if (!prev || prev.cooldownUntil <= awakeUntil) this.socketPoolCooldowns.set(this.host, {
47839
+ failureCount: prev?.failureCount ?? 1,
47840
+ lastFailureAt: now,
47841
+ cooldownUntil: awakeUntil,
47842
+ reason: "d2c-disc-awake-backoff"
47843
+ });
47844
+ this.logger?.log?.(`[D2C_DISC] Awake camera, young session (${Math.round(sessionAgeMs / 1e3)}s): redial backoff ${backoffMs / 1e3}s`);
47845
+ return;
47846
+ }
47781
47847
  const immediateCooldownUntil = now + _ReolinkBaichuanApi.D2C_DISC_IMMEDIATE_COOLDOWN_MS;
47782
47848
  const existing = this.socketPoolCooldowns.get(this.host);
47783
47849
  if (!existing || existing.cooldownUntil < immediateCooldownUntil) {
47784
47850
  this.socketPoolCooldowns.set(this.host, {
47785
47851
  failureCount: existing?.failureCount ?? 1,
47786
47852
  lastFailureAt: now,
47787
- cooldownUntil: immediateCooldownUntil
47853
+ cooldownUntil: immediateCooldownUntil,
47854
+ reason: "d2c-disc-sleep"
47788
47855
  });
47789
47856
  this.logger?.log?.(`[D2C_DISC] Immediate cooldown: socket pool blocked for ${_ReolinkBaichuanApi.D2C_DISC_IMMEDIATE_COOLDOWN_MS / 1e3}s`);
47790
47857
  }
@@ -47798,7 +47865,8 @@ ${stderr}`));
47798
47865
  this.socketPoolCooldowns.set(this.host, {
47799
47866
  failureCount: this.d2cDiscTimestamps.length,
47800
47867
  lastFailureAt: now,
47801
- cooldownUntil: stormCooldownUntil
47868
+ cooldownUntil: stormCooldownUntil,
47869
+ reason: "d2c-disc-sleep"
47802
47870
  });
47803
47871
  this.logger?.warn?.(`[D2C_DISC] Storm detected: ${this.d2cDiscTimestamps.length} disconnects in ${_ReolinkBaichuanApi.D2C_DISC_STORM_WINDOW_MS / 1e3}s \u2192 socket pool cooldown ${_ReolinkBaichuanApi.D2C_DISC_STORM_COOLDOWN_MS / 1e3}s`);
47804
47872
  }
@@ -113603,6 +113671,8 @@ onStatusChanged: {
113603
113671
  * History (D850): recorded series. The generic capture replaces the `battery` series of `pipeline-analytics:stats-5m`.
113604
113672
  */
113605
113673
  history: { fields: {
113674
+ charging: { kind: "enum" },
113675
+ chargeState: { kind: "enum" },
113606
113676
  level: {
113607
113677
  kind: "gauge",
113608
113678
  unit: "%"
@@ -114159,6 +114229,9 @@ var DiscoveredChildDeviceSchema = /* @__PURE__ */ lazy(() => object({
114159
114229
  model: string().optional(),
114160
114230
  serialNumber: string().optional(),
114161
114231
  uid: string().optional(),
114232
+ /** The device's hardware MAC, any separator or case. The Add device list matches it to a
114233
+ * scan hit's `sourceInfo.uniqueId`, so one physical device is one row. */
114234
+ mac: string().optional(),
114162
114235
  /** Reolink: 0-based channel index inside the parent NVR. */
114163
114236
  rtspChannel: number().int().nonnegative().optional(),
114164
114237
  isBattery: boolean().optional(),
@@ -114991,7 +115064,14 @@ var DeviceStatusSchema = /* @__PURE__ */ object({
114991
115064
  online: /* @__PURE__ */ boolean(),
114992
115065
  /** Ms epoch of the last `online` transition. Lets consumers tell
114993
115066
  * apart "just came online" from "still online". */
114994
- lastChangedAt: /* @__PURE__ */ number()
115067
+ lastChangedAt: /* @__PURE__ */ number(),
115068
+ /**
115069
+ * D1099: the provider has not answered since the (re)start, so `online` is a
115070
+ * placeholder (the last known value) and NOT a fact. Absent means answered.
115071
+ * "Not yet known" must never read as offline: a consumer that judges
115072
+ * liveness ignores a slice carrying it.
115073
+ */
115074
+ unknown: /* @__PURE__ */ literal(true).optional()
114995
115075
  });
114996
115076
  var deviceStatusCapability = {
114997
115077
  name: "device-status",
@@ -116251,7 +116331,7 @@ var intercomCapability = {
116251
116331
  /**
116252
116332
  * History (D850): none — talk sessions are a ledger concern, not a trend.
116253
116333
  */
116254
- history: "none",
116334
+ history: { fields: { talking: { kind: "boolean" } } },
116255
116335
  vocabulary: {
116256
116336
  noun: /* @__PURE__ */ t("Intercom", "Citofono"),
116257
116337
  order: 3150,
@@ -116420,8 +116500,8 @@ wakeUp: /* @__PURE__ */ method(/* @__PURE__ */ object({
116420
116500
  * the presence derivation have (the same argument as `battery`).
116421
116501
  */
116422
116502
  durability: "restored",
116423
- /** History (D850): none — battery never recorded a sleep series either. */
116424
- history: "none",
116503
+ /** History (D850): the awake / asleep timeline of a battery camera. */
116504
+ history: { fields: { sleeping: { kind: "boolean" } } },
116425
116505
  volatileStateFields: ["lastUpdated"],
116426
116506
  vocabulary: {
116427
116507
  noun: /* @__PURE__ */ t("Low-power sleep", "Sospensione a basso consumo"),
@@ -117644,6 +117724,7 @@ onStatusChanged: {
117644
117724
  * History (D850): recorded series.
117645
117725
  */
117646
117726
  history: { fields: {
117727
+ type: { kind: "enum" },
117647
117728
  signal: {
117648
117729
  kind: "gauge",
117649
117730
  unit: "%",
@@ -122759,7 +122840,8 @@ var BaseDevice = class {
122759
122840
  if (!this.statusIsExternal) {
122760
122841
  const seed = {
122761
122842
  online: true,
122762
- lastChangedAt: Date.now()
122843
+ lastChangedAt: Date.now(),
122844
+ unknown: true
122763
122845
  };
122764
122846
  this.runtimeState.setCapState("device-status", seed);
122765
122847
  }
@@ -122801,10 +122883,13 @@ var BaseDevice = class {
122801
122883
  * override to gate side effects on the transition.
122802
122884
  */
122803
122885
  markOnline(online) {
122804
- if (this.statusIsExternal || this.online === online) return;
122886
+ if (this.statusIsExternal) return;
122887
+ const prior = this.runtimeState.getCapState("device-status");
122888
+ const presumed = prior?.unknown === true;
122889
+ if (this.online === online && !presumed) return;
122805
122890
  const next = {
122806
122891
  online,
122807
- lastChangedAt: Date.now()
122892
+ lastChangedAt: prior !== void 0 && prior.online === online ? prior.lastChangedAt : Date.now()
122808
122893
  };
122809
122894
  this.runtimeState.setCapState("device-status", next);
122810
122895
  }
package/dist/addon.mjs CHANGED
@@ -29159,7 +29159,7 @@ var require_lz4 = /* @__PURE__ */ __commonJSMin(((exports) => {
29159
29159
  };
29160
29160
  }));
29161
29161
  //#endregion
29162
- //#region node_modules/@apocaliss92/nodelink-js/dist/chunk-MC2CLGY2.js
29162
+ //#region node_modules/@apocaliss92/nodelink-js/dist/chunk-7P5XTMMX.js
29163
29163
  var import_fxp = require_fxp();
29164
29164
  var import_lz4 = /* @__PURE__ */ __toESM(require_lz4(), 1);
29165
29165
  function bcHeaderLen(messageClass, buf, bodyLen) {
@@ -29984,6 +29984,9 @@ var BcUdpStream = class extends EventEmitter {
29984
29984
  received = /* @__PURE__ */ new Map();
29985
29985
  sent = /* @__PURE__ */ new Map();
29986
29986
  ackTimer;
29987
+ /** When delivery first became blocked by a missing packet (head-of-line). */
29988
+ holSinceMs;
29989
+ holStallLogged = false;
29987
29990
  resendTimer;
29988
29991
  hbTimer;
29989
29992
  discoveryTid;
@@ -30916,7 +30919,12 @@ var BcUdpStream = class extends EventEmitter {
30916
30919
  lastAckRxAgoMs: this.lastAckRxAtMs !== void 0 ? now - this.lastAckRxAtMs : void 0,
30917
30920
  unackedPackets: this.sent.size,
30918
30921
  ...oldestUnackedAgeMs !== void 0 ? { oldestUnackedAgeMs } : {},
30919
- discFromCamera: this.discFromCameraAtMs !== void 0
30922
+ discFromCamera: this.discFromCameraAtMs !== void 0,
30923
+ ...this.holSinceMs !== void 0 && this.received.size > 0 ? {
30924
+ holBlockedMs: now - this.holSinceMs,
30925
+ holMissingPacketId: this.packetsWant
30926
+ } : {},
30927
+ holBufferedPackets: this.received.size
30920
30928
  };
30921
30929
  }
30922
30930
  /**
@@ -30927,6 +30935,12 @@ var BcUdpStream = class extends EventEmitter {
30927
30935
  checkStalls(now) {
30928
30936
  const age = this.connectedAtMs !== void 0 ? now - this.connectedAtMs : void 0;
30929
30937
  const diag = this.getSessionDiagnostics(now);
30938
+ const holStalled = diag.holBlockedMs !== void 0 && diag.holBlockedMs >= 1500;
30939
+ if (holStalled && !this.holStallLogged) {
30940
+ this.holStallLogged = true;
30941
+ this.discoveryLogger?.warn?.(`[BcUdpStream] head-of-line stall: packet ${diag.holMissingPacketId} missing for ${diag.holBlockedMs}ms, ${diag.holBufferedPackets} later packet(s) withheld, lastDataRxAgoMs=${diag.lastDataRxAgoMs ?? "none"} sessionAgeMs=${age}`);
30942
+ this.emit("debug", "hol_stall", { ...diag });
30943
+ } else if (!holStalled) this.holStallLogged = false;
30930
30944
  const ackStalled = diag.oldestUnackedAgeMs !== void 0 && diag.oldestUnackedAgeMs >= 5e3;
30931
30945
  if (ackStalled && !this.ackWindowStallLogged) {
30932
30946
  this.ackWindowStallLogged = true;
@@ -30971,6 +30985,10 @@ var BcUdpStream = class extends EventEmitter {
30971
30985
  }
30972
30986
  });
30973
30987
  }
30988
+ trackHeadOfLine(now) {
30989
+ if (!(this.received.size > 0 && !this.received.has(this.packetsWant))) this.holSinceMs = void 0;
30990
+ else if (this.holSinceMs === void 0) this.holSinceMs = now;
30991
+ }
30974
30992
  flushReceived() {
30975
30993
  while (this.received.has(this.packetsWant)) {
30976
30994
  const chunk = this.received.get(this.packetsWant);
@@ -31013,6 +31031,7 @@ var BcUdpStream = class extends EventEmitter {
31013
31031
  if (p.packetId >= this.packetsWant) {
31014
31032
  this.received.set(p.packetId, p.payload);
31015
31033
  this.flushReceived();
31034
+ this.trackHeadOfLine(Date.now());
31016
31035
  this.updateAckPacket();
31017
31036
  if (this.packetsWant % 100 === 0) this.emit("debug", "udp_progress", { packetsWant: this.packetsWant });
31018
31037
  }
@@ -39251,6 +39270,31 @@ function mapBaichuanWebhookParsedToSimpleEvents(parsed) {
39251
39270
  if (parsed.cmdId === 33) return mapBaichuanWebhookAlarmXmlToSimpleEvents(parsed.xml);
39252
39271
  return [];
39253
39272
  }
39273
+ var D2C_DISC_AWAKE_FIRST_BACKOFF_MS = 1e4;
39274
+ var D2C_DISC_AWAKE_MAX_BACKOFF_MS = 3e4;
39275
+ var D2C_DISC_YOUNG_SESSION_MS = 6e4;
39276
+ var D2C_DISC_AWAKE_STREAK_RESET_MS = 12e4;
39277
+ function isAwakeFlap(input) {
39278
+ return input.camState === "awake" && input.sessionAgeMs < D2C_DISC_YOUNG_SESSION_MS;
39279
+ }
39280
+ var AwakeDiscBackoff = class {
39281
+ streak = 0;
39282
+ lastAtMs = 0;
39283
+ /** Records an awake drop at `nowMs`; returns its refusal duration. */
39284
+ next(nowMs) {
39285
+ if (this.lastAtMs === 0 || nowMs - this.lastAtMs > D2C_DISC_AWAKE_STREAK_RESET_MS) this.streak = 0;
39286
+ this.streak += 1;
39287
+ this.lastAtMs = nowMs;
39288
+ return this.streak === 1 ? D2C_DISC_AWAKE_FIRST_BACKOFF_MS : D2C_DISC_AWAKE_MAX_BACKOFF_MS;
39289
+ }
39290
+ };
39291
+ function describeCooldownReason(reason) {
39292
+ switch (reason) {
39293
+ case "d2c-disc-awake-backoff": return "cooldown after disconnect (camera awake, link unstable)";
39294
+ case "d2c-disc-sleep": return "D2C_DISC (camera sleeping)";
39295
+ case "login-failures": return "repeated login failures";
39296
+ }
39297
+ }
39254
39298
  var parser = new import_fxp.XMLParser({
39255
39299
  ignoreAttributes: false,
39256
39300
  attributeNamePrefix: "@_",
@@ -41794,6 +41838,7 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
41794
41838
  * Value: object with failureCount, lastFailureAt, cooldownUntil
41795
41839
  */
41796
41840
  socketPoolCooldowns = /* @__PURE__ */ new Map();
41841
+ awakeDiscBackoff = new AwakeDiscBackoff();
41797
41842
  /** Base cooldown duration (ms) for socket failures. */
41798
41843
  static SOCKET_POOL_BASE_COOLDOWN_MS = 5e3;
41799
41844
  /** Max cooldown duration (ms) - caps exponential backoff. */
@@ -42179,7 +42224,8 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
42179
42224
  * pool socket receives the disconnect.
42180
42225
  */
42181
42226
  attachD2cDiscListener(client) {
42182
- client.on("d2c_disc", () => this.notifyD2cDisc());
42227
+ const sessionStartedAtMs = Date.now();
42228
+ client.on("d2c_disc", () => this.notifyD2cDisc(Date.now() - sessionStartedAtMs));
42183
42229
  client.on("error", () => {});
42184
42230
  }
42185
42231
  /**
@@ -42200,7 +42246,8 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
42200
42246
  log?.debug?.(`[SocketPool] Cooldown reset for host=${this.host} (no failures for ${_ReolinkBaichuanApi.SOCKET_POOL_FAILURE_WINDOW_MS}ms)`);
42201
42247
  } else if (now < cooldownEntry.cooldownUntil) {
42202
42248
  const remainingMs = cooldownEntry.cooldownUntil - now;
42203
- const reason = this.lastD2cDiscAtMs > 0 && now - this.lastD2cDiscAtMs < 12e4 ? "D2C_DISC (camera sleeping)" : "repeated login failures";
42249
+ const isD2cDisc = this.lastD2cDiscAtMs > 0 && now - this.lastD2cDiscAtMs < 12e4;
42250
+ const reason = describeCooldownReason(cooldownEntry.reason ?? (isD2cDisc ? "d2c-disc-sleep" : "login-failures"));
42204
42251
  const error = /* @__PURE__ */ new Error(`[SocketPool] Host ${this.host} is in cooldown for ${Math.ceil(remainingMs / 1e3)}s due to ${reason}. tag=${tag2}`);
42205
42252
  log?.debug?.(error.message);
42206
42253
  throw error;
@@ -47759,26 +47806,46 @@ ${stderr}`));
47759
47806
  /**
47760
47807
  * Called when any BaichuanClient for this device receives a D2C_DISC.
47761
47808
  *
47762
- * Two-tier response:
47809
+ * An AWAKE camera whose young session was dropped (flapping link) gets a
47810
+ * short capped backoff (10 s, then 30 s) and never the storm cooldown.
47811
+ * Anything else (asleep, unknown, old session) keeps the sleep-safe tiers:
47763
47812
  * 1. **Immediate**: every D2C_DISC applies a short socket pool cooldown
47764
47813
  * (10 s) to prevent reconnect attempts while the camera transitions to sleep.
47765
47814
  * 2. **Storm**: ≥3 D2C_DISCs within 60 s triggers extended cooldown (120 s).
47766
47815
  */
47767
- notifyD2cDisc() {
47816
+ notifyD2cDisc(sessionAgeMs) {
47768
47817
  const now = Date.now();
47818
+ const awakeFlap = isAwakeFlap({
47819
+ camState: this.getSleepStatus().state,
47820
+ sessionAgeMs
47821
+ });
47769
47822
  this.lastD2cDiscAtMs = now;
47770
47823
  const streamingTags = Array.from(this.socketPool.keys()).filter((tag2) => tag2.startsWith("streaming:"));
47771
47824
  if (streamingTags.length > 0) {
47772
47825
  this.logger?.log?.(`[D2C_DISC] Force-closing ${streamingTags.length} streaming socket(s): ${streamingTags.join(", ")}`);
47773
47826
  for (const tag2 of streamingTags) this.forceClosePooledSocket(tag2, this.logger).catch(() => {});
47774
47827
  }
47828
+ if (awakeFlap) {
47829
+ const backoffMs = this.awakeDiscBackoff.next(now);
47830
+ const awakeUntil = now + backoffMs;
47831
+ const prev = this.socketPoolCooldowns.get(this.host);
47832
+ if (!prev || prev.cooldownUntil <= awakeUntil) this.socketPoolCooldowns.set(this.host, {
47833
+ failureCount: prev?.failureCount ?? 1,
47834
+ lastFailureAt: now,
47835
+ cooldownUntil: awakeUntil,
47836
+ reason: "d2c-disc-awake-backoff"
47837
+ });
47838
+ this.logger?.log?.(`[D2C_DISC] Awake camera, young session (${Math.round(sessionAgeMs / 1e3)}s): redial backoff ${backoffMs / 1e3}s`);
47839
+ return;
47840
+ }
47775
47841
  const immediateCooldownUntil = now + _ReolinkBaichuanApi.D2C_DISC_IMMEDIATE_COOLDOWN_MS;
47776
47842
  const existing = this.socketPoolCooldowns.get(this.host);
47777
47843
  if (!existing || existing.cooldownUntil < immediateCooldownUntil) {
47778
47844
  this.socketPoolCooldowns.set(this.host, {
47779
47845
  failureCount: existing?.failureCount ?? 1,
47780
47846
  lastFailureAt: now,
47781
- cooldownUntil: immediateCooldownUntil
47847
+ cooldownUntil: immediateCooldownUntil,
47848
+ reason: "d2c-disc-sleep"
47782
47849
  });
47783
47850
  this.logger?.log?.(`[D2C_DISC] Immediate cooldown: socket pool blocked for ${_ReolinkBaichuanApi.D2C_DISC_IMMEDIATE_COOLDOWN_MS / 1e3}s`);
47784
47851
  }
@@ -47792,7 +47859,8 @@ ${stderr}`));
47792
47859
  this.socketPoolCooldowns.set(this.host, {
47793
47860
  failureCount: this.d2cDiscTimestamps.length,
47794
47861
  lastFailureAt: now,
47795
- cooldownUntil: stormCooldownUntil
47862
+ cooldownUntil: stormCooldownUntil,
47863
+ reason: "d2c-disc-sleep"
47796
47864
  });
47797
47865
  this.logger?.warn?.(`[D2C_DISC] Storm detected: ${this.d2cDiscTimestamps.length} disconnects in ${_ReolinkBaichuanApi.D2C_DISC_STORM_WINDOW_MS / 1e3}s \u2192 socket pool cooldown ${_ReolinkBaichuanApi.D2C_DISC_STORM_COOLDOWN_MS / 1e3}s`);
47798
47866
  }
@@ -113597,6 +113665,8 @@ onStatusChanged: {
113597
113665
  * History (D850): recorded series. The generic capture replaces the `battery` series of `pipeline-analytics:stats-5m`.
113598
113666
  */
113599
113667
  history: { fields: {
113668
+ charging: { kind: "enum" },
113669
+ chargeState: { kind: "enum" },
113600
113670
  level: {
113601
113671
  kind: "gauge",
113602
113672
  unit: "%"
@@ -114153,6 +114223,9 @@ var DiscoveredChildDeviceSchema = /* @__PURE__ */ lazy(() => object({
114153
114223
  model: string().optional(),
114154
114224
  serialNumber: string().optional(),
114155
114225
  uid: string().optional(),
114226
+ /** The device's hardware MAC, any separator or case. The Add device list matches it to a
114227
+ * scan hit's `sourceInfo.uniqueId`, so one physical device is one row. */
114228
+ mac: string().optional(),
114156
114229
  /** Reolink: 0-based channel index inside the parent NVR. */
114157
114230
  rtspChannel: number().int().nonnegative().optional(),
114158
114231
  isBattery: boolean().optional(),
@@ -114985,7 +115058,14 @@ var DeviceStatusSchema = /* @__PURE__ */ object({
114985
115058
  online: /* @__PURE__ */ boolean(),
114986
115059
  /** Ms epoch of the last `online` transition. Lets consumers tell
114987
115060
  * apart "just came online" from "still online". */
114988
- lastChangedAt: /* @__PURE__ */ number()
115061
+ lastChangedAt: /* @__PURE__ */ number(),
115062
+ /**
115063
+ * D1099: the provider has not answered since the (re)start, so `online` is a
115064
+ * placeholder (the last known value) and NOT a fact. Absent means answered.
115065
+ * "Not yet known" must never read as offline: a consumer that judges
115066
+ * liveness ignores a slice carrying it.
115067
+ */
115068
+ unknown: /* @__PURE__ */ literal(true).optional()
114989
115069
  });
114990
115070
  var deviceStatusCapability = {
114991
115071
  name: "device-status",
@@ -116245,7 +116325,7 @@ var intercomCapability = {
116245
116325
  /**
116246
116326
  * History (D850): none — talk sessions are a ledger concern, not a trend.
116247
116327
  */
116248
- history: "none",
116328
+ history: { fields: { talking: { kind: "boolean" } } },
116249
116329
  vocabulary: {
116250
116330
  noun: /* @__PURE__ */ t("Intercom", "Citofono"),
116251
116331
  order: 3150,
@@ -116414,8 +116494,8 @@ wakeUp: /* @__PURE__ */ method(/* @__PURE__ */ object({
116414
116494
  * the presence derivation have (the same argument as `battery`).
116415
116495
  */
116416
116496
  durability: "restored",
116417
- /** History (D850): none — battery never recorded a sleep series either. */
116418
- history: "none",
116497
+ /** History (D850): the awake / asleep timeline of a battery camera. */
116498
+ history: { fields: { sleeping: { kind: "boolean" } } },
116419
116499
  volatileStateFields: ["lastUpdated"],
116420
116500
  vocabulary: {
116421
116501
  noun: /* @__PURE__ */ t("Low-power sleep", "Sospensione a basso consumo"),
@@ -117638,6 +117718,7 @@ onStatusChanged: {
117638
117718
  * History (D850): recorded series.
117639
117719
  */
117640
117720
  history: { fields: {
117721
+ type: { kind: "enum" },
117641
117722
  signal: {
117642
117723
  kind: "gauge",
117643
117724
  unit: "%",
@@ -122753,7 +122834,8 @@ var BaseDevice = class {
122753
122834
  if (!this.statusIsExternal) {
122754
122835
  const seed = {
122755
122836
  online: true,
122756
- lastChangedAt: Date.now()
122837
+ lastChangedAt: Date.now(),
122838
+ unknown: true
122757
122839
  };
122758
122840
  this.runtimeState.setCapState("device-status", seed);
122759
122841
  }
@@ -122795,10 +122877,13 @@ var BaseDevice = class {
122795
122877
  * override to gate side effects on the transition.
122796
122878
  */
122797
122879
  markOnline(online) {
122798
- if (this.statusIsExternal || this.online === online) return;
122880
+ if (this.statusIsExternal) return;
122881
+ const prior = this.runtimeState.getCapState("device-status");
122882
+ const presumed = prior?.unknown === true;
122883
+ if (this.online === online && !presumed) return;
122799
122884
  const next = {
122800
122885
  online,
122801
- lastChangedAt: Date.now()
122886
+ lastChangedAt: prior !== void 0 && prior.online === online ? prior.lastChangedAt : Date.now()
122802
122887
  };
122803
122888
  this.runtimeState.setCapState("device-status", next);
122804
122889
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-provider-reolink",
3
- "version": "1.2.261",
3
+ "version": "1.2.263",
4
4
  "description": "Reolink camera device provider addon for CamStack — native Baichuan protocol",
5
5
  "keywords": [
6
6
  "camstack",
@@ -96,7 +96,7 @@
96
96
  "werift"
97
97
  ],
98
98
  "requires": {
99
- "server": ">=1.2.944"
99
+ "server": ">=1.2.960"
100
100
  }
101
101
  },
102
102
  "files": [
@@ -114,7 +114,7 @@
114
114
  "publish:npm": "npm publish --access public"
115
115
  },
116
116
  "dependencies": {
117
- "@apocaliss92/nodelink-js": "^0.14.0"
117
+ "@apocaliss92/nodelink-js": "^0.14.2"
118
118
  },
119
119
  "peerDependencies": {
120
120
  "@camstack/types": "*",