@camstack/addon-provider-reolink 1.2.258 → 1.2.259

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,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.259] - 2026-11-21
11
+
12
+ ### Changed
13
+
14
+ - Battery cameras without a PIR sensor no longer get a PIR switch, and a battery camera re-reads its accessories on a wake at most every 6 hours so a wrongly created accessory is removed without restarting the provider.
15
+
10
16
  ## [1.2.258] - 2026-11-21
11
17
 
12
18
  ### 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-BQPNG2XV.js
29168
+ //#region node_modules/@apocaliss92/nodelink-js/dist/chunk-2XVZ5ZZL.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) {
@@ -37540,7 +37540,7 @@ function computeDeviceCapabilities(params) {
37540
37540
  const hasZoomFromAbilities = ptzExplicitlyDisabledBySupportItem ? false : abilitiesHasAny(flat, /zoom|zoomFocus|StartZoomFocus/i);
37541
37541
  const hasPresetsFromAbilities = abilitiesHasAny(flat, /preset/i);
37542
37542
  const hasPirFromAbilities = abilitiesHasAny(flat, /(^|_)pir/i) || abilitiesHasAny(flat, /rfAlarm/i) || abilitiesHasAny(flat, /mdWithPir/i);
37543
- const hasPirFromSupport = supportItem ? isTruthyNumberLike(supportItem.rfCfg) || isTruthyNumberLike(supportItem.newRfCfg) || isTruthyNumberLike(supportItem.rfVersion) || isTruthyNumberLike(supportItem.battery) : false;
37543
+ const hasPirFromSupport = supportItem ? isTruthyNumberLike(supportItem.rfCfg) || isTruthyNumberLike(supportItem.newRfCfg) || isTruthyNumberLike(supportItem.rfVersion) : false;
37544
37544
  const hasAutotrackingFromSupport = supportItem ? isTruthyNumberLike(supportItem.autoPt) || isTruthyNumberLike(supportItem.smartAI) : false;
37545
37545
  const hasAutotrackingFromAbilities = abilitiesHasAny(flat, /smartTrack/i);
37546
37546
  const hasBattery = hasBatteryFromSupport || hasBatteryFromAbilities;
@@ -132837,16 +132837,6 @@ function buildPirPayload(enable, cfg) {
132837
132837
  ...typeof cfg.interval === "number" ? { interval: cfg.interval } : {}
132838
132838
  };
132839
132839
  }
132840
- /** Keep `enable` plus only the tuning fields the firmware reported on read. */
132841
- function reducePirPayload(payload, reported) {
132842
- const has = (key) => typeof reported?.[key] === "number";
132843
- return {
132844
- enable: payload.enable,
132845
- ...has("sensitive") && payload.sensitive !== void 0 ? { sensitive: payload.sensitive } : {},
132846
- ...has("reduceAlarm") && payload.reduceAlarm !== void 0 ? { reduceAlarm: payload.reduceAlarm } : {},
132847
- ...has("interval") && payload.interval !== void 0 ? { interval: payload.interval } : {}
132848
- };
132849
- }
132850
132840
  /** True for the firmware's `responseCode 400` refusal. */
132851
132841
  function isBaichuan400(err) {
132852
132842
  const message = err instanceof Error ? err.message : String(err);
@@ -133053,43 +133043,18 @@ var PirAccessory = class extends BaseDevice {
133053
133043
  });
133054
133044
  try {
133055
133045
  await api.setPirInfo(payload, this.channel);
133056
- return;
133057
133046
  } catch (err) {
133058
133047
  if (!isBaichuan400(err)) throw err;
133059
- this.ctx.logger.warn("pir setPirInfo answered 400 — retrying with the fields the read reports", {
133048
+ this.ctx.logger.warn("pir setPirInfo refused by the camera", {
133060
133049
  tags: { deviceId: this.id },
133061
133050
  meta: {
133062
133051
  channel: this.channel,
133063
- attempt: "full",
133064
133052
  payload,
133065
133053
  responseCode: 400,
133066
133054
  error: err instanceof Error ? err.message : String(err)
133067
133055
  }
133068
133056
  });
133069
- }
133070
- const reduced = reducePirPayload(payload, (await api.getPirInfo(this.channel)).state);
133071
- try {
133072
- await api.setPirInfo(reduced, this.channel);
133073
- this.ctx.logger.info("pir setPirInfo succeeded with the reduced payload", {
133074
- tags: { deviceId: this.id },
133075
- meta: {
133076
- channel: this.channel,
133077
- attempt: "reduced",
133078
- payload: reduced
133079
- }
133080
- });
133081
- } catch (err) {
133082
- this.ctx.logger.warn("pir setPirInfo failed on both attempts", {
133083
- tags: { deviceId: this.id },
133084
- meta: {
133085
- channel: this.channel,
133086
- attempt: "reduced",
133087
- payload: reduced,
133088
- responseCode: isBaichuan400(err) ? 400 : null,
133089
- error: err instanceof Error ? err.message : String(err)
133090
- }
133091
- });
133092
- throw new Error("The camera rejected the PIR settings (full and reduced request). Try again once it is awake, or change the PIR settings in the Reolink app.");
133057
+ throw new Error("The camera rejected the PIR settings. Try again once it is awake, or change the PIR settings in the Reolink app.");
133093
133058
  }
133094
133059
  }
133095
133060
  getSettingsUISchema() {
@@ -133921,6 +133886,35 @@ function accessoryChildrenAnswerFor(sliceProbed, sliceFlags, specs) {
133921
133886
  children: specs
133922
133887
  };
133923
133888
  }
133889
+ /**
133890
+ * A wake the camera itself (or our own look at it) reported. `hub-reconcile`
133891
+ * and `hub-summary` come from the parent's periodic sweep, which lags the real
133892
+ * state by minutes: a probe driven by one can log in and WAKE a standalone UDP
133893
+ * battery camera that fell asleep again, so they never trigger a re-probe.
133894
+ */
133895
+ function isFirstHandWake(reason) {
133896
+ return reason === "simple-event" || reason === "sleep-poll" || reason === "confirmed-wake";
133897
+ }
133898
+ var AccessoryReprobeWindow = class {
133899
+ #lastAttemptAt = 0;
133900
+ #inFlight = false;
133901
+ /**
133902
+ * True (and the attempt is recorded) when the last probe that ran is older
133903
+ * than the window, the last attempt is older than the retry gap, and none is
133904
+ * in flight.
133905
+ */
133906
+ tryBegin(now, lastProbedAt) {
133907
+ if (this.#inFlight) return false;
133908
+ if (now - lastProbedAt < 216e5) return false;
133909
+ if (this.#lastAttemptAt > 0 && now - this.#lastAttemptAt < 6e5) return false;
133910
+ this.#lastAttemptAt = now;
133911
+ this.#inFlight = true;
133912
+ return true;
133913
+ }
133914
+ end() {
133915
+ this.#inFlight = false;
133916
+ }
133917
+ };
133924
133918
  //#endregion
133925
133919
  //#region src/metadata-populator.ts
133926
133920
  var EXTENDED_INFO_TAGS = [
@@ -136451,6 +136445,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
136451
136445
  * `sleep-state-decision.ts` for the measurement (D603).
136452
136446
  */
136453
136447
  sleepStateChangedAt = 0;
136448
+ accessoryReprobeWindow = new AccessoryReprobeWindow();
136454
136449
  /**
136455
136450
  * Wall-clock ms of the last PROACTIVE wake — one we issued on our own
136456
136451
  * initiative (background snapshot refresh), not because the operator
@@ -141864,6 +141859,42 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
141864
141859
  networkLinkFailureWarned = false;
141865
141860
  static CONTACT_WRITE_QUANTUM_MS = 5 * 6e4;
141866
141861
  /**
141862
+ * A battery camera probes its abilities once, so an accessory the firmware
141863
+ * never really had (a PIR switch on a camera without a PIR) could not be
141864
+ * pruned: the kernel needs a second probe on a later `lastProbedAt`. A natural
141865
+ * wake is the free moment — at most once per `ACCESSORY_REPROBE_WINDOW_MS`
141866
+ * (measured from the last probe that ran), never overlapping.
141867
+ *
141868
+ * ONLY a first-hand awake observation may trigger it. The periodic hub sweep
141869
+ * (`hub-reconcile`, `hub-summary`) also drives `onWakeTransition` but lags the
141870
+ * real state by minutes, and `onProbe` is gated by that same lagging flag: a
141871
+ * probe from there could log in and WAKE a camera that already went back to sleep.
141872
+ */
141873
+ async reprobeAccessoriesIfStale(reason) {
141874
+ if (!this.isBattery || !isFirstHandWake(reason)) return;
141875
+ const lastProbedAt = this.runtimeState.getCapState("feature-probe")?.lastProbedAt ?? 0;
141876
+ const now = Date.now();
141877
+ if (!this.accessoryReprobeWindow.tryBegin(now, lastProbedAt)) return;
141878
+ this.ctx.logger.info("wake transition — accessory re-probe (last probe older than the window)", {
141879
+ tags: { deviceId: this.id },
141880
+ meta: {
141881
+ reason,
141882
+ lastProbedAt,
141883
+ ageMs: lastProbedAt > 0 ? now - lastProbedAt : null
141884
+ }
141885
+ });
141886
+ try {
141887
+ await this.reprobe();
141888
+ } catch (err) {
141889
+ this.ctx.logger.debug("onWakeTransition: accessory re-probe failed — a later first-hand wake retries", {
141890
+ tags: { deviceId: this.id },
141891
+ meta: { error: err instanceof Error ? err.message : String(err) }
141892
+ });
141893
+ } finally {
141894
+ this.accessoryReprobeWindow.end();
141895
+ }
141896
+ }
141897
+ /**
141867
141898
  * Shared wake-transition handler invoked by both the simpleEvent
141868
141899
  * `awake` push (canonical fast path) and the sleep poll's
141869
141900
  * `sleeping → awake` flip (backstop). Fan out the refreshes that
@@ -141904,6 +141935,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
141904
141935
  meta: { error: err instanceof Error ? err.message : String(err) }
141905
141936
  });
141906
141937
  }
141938
+ else await this.reprobeAccessoriesIfStale(reason);
141907
141939
  if (!(this.isBattery ? await this.getBatteryRefresh().noteAwake().catch(() => false) : false)) {
141908
141940
  await this.warmCapSlicesOnWake();
141909
141941
  await this.warmSnapshotOnWake();
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-BQPNG2XV.js
29162
+ //#region node_modules/@apocaliss92/nodelink-js/dist/chunk-2XVZ5ZZL.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) {
@@ -37534,7 +37534,7 @@ function computeDeviceCapabilities(params) {
37534
37534
  const hasZoomFromAbilities = ptzExplicitlyDisabledBySupportItem ? false : abilitiesHasAny(flat, /zoom|zoomFocus|StartZoomFocus/i);
37535
37535
  const hasPresetsFromAbilities = abilitiesHasAny(flat, /preset/i);
37536
37536
  const hasPirFromAbilities = abilitiesHasAny(flat, /(^|_)pir/i) || abilitiesHasAny(flat, /rfAlarm/i) || abilitiesHasAny(flat, /mdWithPir/i);
37537
- const hasPirFromSupport = supportItem ? isTruthyNumberLike(supportItem.rfCfg) || isTruthyNumberLike(supportItem.newRfCfg) || isTruthyNumberLike(supportItem.rfVersion) || isTruthyNumberLike(supportItem.battery) : false;
37537
+ const hasPirFromSupport = supportItem ? isTruthyNumberLike(supportItem.rfCfg) || isTruthyNumberLike(supportItem.newRfCfg) || isTruthyNumberLike(supportItem.rfVersion) : false;
37538
37538
  const hasAutotrackingFromSupport = supportItem ? isTruthyNumberLike(supportItem.autoPt) || isTruthyNumberLike(supportItem.smartAI) : false;
37539
37539
  const hasAutotrackingFromAbilities = abilitiesHasAny(flat, /smartTrack/i);
37540
37540
  const hasBattery = hasBatteryFromSupport || hasBatteryFromAbilities;
@@ -132831,16 +132831,6 @@ function buildPirPayload(enable, cfg) {
132831
132831
  ...typeof cfg.interval === "number" ? { interval: cfg.interval } : {}
132832
132832
  };
132833
132833
  }
132834
- /** Keep `enable` plus only the tuning fields the firmware reported on read. */
132835
- function reducePirPayload(payload, reported) {
132836
- const has = (key) => typeof reported?.[key] === "number";
132837
- return {
132838
- enable: payload.enable,
132839
- ...has("sensitive") && payload.sensitive !== void 0 ? { sensitive: payload.sensitive } : {},
132840
- ...has("reduceAlarm") && payload.reduceAlarm !== void 0 ? { reduceAlarm: payload.reduceAlarm } : {},
132841
- ...has("interval") && payload.interval !== void 0 ? { interval: payload.interval } : {}
132842
- };
132843
- }
132844
132834
  /** True for the firmware's `responseCode 400` refusal. */
132845
132835
  function isBaichuan400(err) {
132846
132836
  const message = err instanceof Error ? err.message : String(err);
@@ -133047,43 +133037,18 @@ var PirAccessory = class extends BaseDevice {
133047
133037
  });
133048
133038
  try {
133049
133039
  await api.setPirInfo(payload, this.channel);
133050
- return;
133051
133040
  } catch (err) {
133052
133041
  if (!isBaichuan400(err)) throw err;
133053
- this.ctx.logger.warn("pir setPirInfo answered 400 — retrying with the fields the read reports", {
133042
+ this.ctx.logger.warn("pir setPirInfo refused by the camera", {
133054
133043
  tags: { deviceId: this.id },
133055
133044
  meta: {
133056
133045
  channel: this.channel,
133057
- attempt: "full",
133058
133046
  payload,
133059
133047
  responseCode: 400,
133060
133048
  error: err instanceof Error ? err.message : String(err)
133061
133049
  }
133062
133050
  });
133063
- }
133064
- const reduced = reducePirPayload(payload, (await api.getPirInfo(this.channel)).state);
133065
- try {
133066
- await api.setPirInfo(reduced, this.channel);
133067
- this.ctx.logger.info("pir setPirInfo succeeded with the reduced payload", {
133068
- tags: { deviceId: this.id },
133069
- meta: {
133070
- channel: this.channel,
133071
- attempt: "reduced",
133072
- payload: reduced
133073
- }
133074
- });
133075
- } catch (err) {
133076
- this.ctx.logger.warn("pir setPirInfo failed on both attempts", {
133077
- tags: { deviceId: this.id },
133078
- meta: {
133079
- channel: this.channel,
133080
- attempt: "reduced",
133081
- payload: reduced,
133082
- responseCode: isBaichuan400(err) ? 400 : null,
133083
- error: err instanceof Error ? err.message : String(err)
133084
- }
133085
- });
133086
- throw new Error("The camera rejected the PIR settings (full and reduced request). Try again once it is awake, or change the PIR settings in the Reolink app.");
133051
+ throw new Error("The camera rejected the PIR settings. Try again once it is awake, or change the PIR settings in the Reolink app.");
133087
133052
  }
133088
133053
  }
133089
133054
  getSettingsUISchema() {
@@ -133915,6 +133880,35 @@ function accessoryChildrenAnswerFor(sliceProbed, sliceFlags, specs) {
133915
133880
  children: specs
133916
133881
  };
133917
133882
  }
133883
+ /**
133884
+ * A wake the camera itself (or our own look at it) reported. `hub-reconcile`
133885
+ * and `hub-summary` come from the parent's periodic sweep, which lags the real
133886
+ * state by minutes: a probe driven by one can log in and WAKE a standalone UDP
133887
+ * battery camera that fell asleep again, so they never trigger a re-probe.
133888
+ */
133889
+ function isFirstHandWake(reason) {
133890
+ return reason === "simple-event" || reason === "sleep-poll" || reason === "confirmed-wake";
133891
+ }
133892
+ var AccessoryReprobeWindow = class {
133893
+ #lastAttemptAt = 0;
133894
+ #inFlight = false;
133895
+ /**
133896
+ * True (and the attempt is recorded) when the last probe that ran is older
133897
+ * than the window, the last attempt is older than the retry gap, and none is
133898
+ * in flight.
133899
+ */
133900
+ tryBegin(now, lastProbedAt) {
133901
+ if (this.#inFlight) return false;
133902
+ if (now - lastProbedAt < 216e5) return false;
133903
+ if (this.#lastAttemptAt > 0 && now - this.#lastAttemptAt < 6e5) return false;
133904
+ this.#lastAttemptAt = now;
133905
+ this.#inFlight = true;
133906
+ return true;
133907
+ }
133908
+ end() {
133909
+ this.#inFlight = false;
133910
+ }
133911
+ };
133918
133912
  //#endregion
133919
133913
  //#region src/metadata-populator.ts
133920
133914
  var EXTENDED_INFO_TAGS = [
@@ -136445,6 +136439,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
136445
136439
  * `sleep-state-decision.ts` for the measurement (D603).
136446
136440
  */
136447
136441
  sleepStateChangedAt = 0;
136442
+ accessoryReprobeWindow = new AccessoryReprobeWindow();
136448
136443
  /**
136449
136444
  * Wall-clock ms of the last PROACTIVE wake — one we issued on our own
136450
136445
  * initiative (background snapshot refresh), not because the operator
@@ -141858,6 +141853,42 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
141858
141853
  networkLinkFailureWarned = false;
141859
141854
  static CONTACT_WRITE_QUANTUM_MS = 5 * 6e4;
141860
141855
  /**
141856
+ * A battery camera probes its abilities once, so an accessory the firmware
141857
+ * never really had (a PIR switch on a camera without a PIR) could not be
141858
+ * pruned: the kernel needs a second probe on a later `lastProbedAt`. A natural
141859
+ * wake is the free moment — at most once per `ACCESSORY_REPROBE_WINDOW_MS`
141860
+ * (measured from the last probe that ran), never overlapping.
141861
+ *
141862
+ * ONLY a first-hand awake observation may trigger it. The periodic hub sweep
141863
+ * (`hub-reconcile`, `hub-summary`) also drives `onWakeTransition` but lags the
141864
+ * real state by minutes, and `onProbe` is gated by that same lagging flag: a
141865
+ * probe from there could log in and WAKE a camera that already went back to sleep.
141866
+ */
141867
+ async reprobeAccessoriesIfStale(reason) {
141868
+ if (!this.isBattery || !isFirstHandWake(reason)) return;
141869
+ const lastProbedAt = this.runtimeState.getCapState("feature-probe")?.lastProbedAt ?? 0;
141870
+ const now = Date.now();
141871
+ if (!this.accessoryReprobeWindow.tryBegin(now, lastProbedAt)) return;
141872
+ this.ctx.logger.info("wake transition — accessory re-probe (last probe older than the window)", {
141873
+ tags: { deviceId: this.id },
141874
+ meta: {
141875
+ reason,
141876
+ lastProbedAt,
141877
+ ageMs: lastProbedAt > 0 ? now - lastProbedAt : null
141878
+ }
141879
+ });
141880
+ try {
141881
+ await this.reprobe();
141882
+ } catch (err) {
141883
+ this.ctx.logger.debug("onWakeTransition: accessory re-probe failed — a later first-hand wake retries", {
141884
+ tags: { deviceId: this.id },
141885
+ meta: { error: err instanceof Error ? err.message : String(err) }
141886
+ });
141887
+ } finally {
141888
+ this.accessoryReprobeWindow.end();
141889
+ }
141890
+ }
141891
+ /**
141861
141892
  * Shared wake-transition handler invoked by both the simpleEvent
141862
141893
  * `awake` push (canonical fast path) and the sleep poll's
141863
141894
  * `sleeping → awake` flip (backstop). Fan out the refreshes that
@@ -141898,6 +141929,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
141898
141929
  meta: { error: err instanceof Error ? err.message : String(err) }
141899
141930
  });
141900
141931
  }
141932
+ else await this.reprobeAccessoriesIfStale(reason);
141901
141933
  if (!(this.isBattery ? await this.getBatteryRefresh().noteAwake().catch(() => false) : false)) {
141902
141934
  await this.warmCapSlicesOnWake();
141903
141935
  await this.warmSnapshotOnWake();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-provider-reolink",
3
- "version": "1.2.258",
3
+ "version": "1.2.259",
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.931"
99
+ "server": ">=1.2.934"
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.12.5"
117
+ "@apocaliss92/nodelink-js": "^0.12.6"
118
118
  },
119
119
  "peerDependencies": {
120
120
  "@camstack/types": "*",