@camstack/addon-provider-reolink 1.2.237 → 1.2.239

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.239] - 2026-11-11
11
+
12
+ ### Fixed
13
+
14
+ - A battery camera's own 0% read during a wake refresh, asleep, or on its adapter or panel no longer replaces the real level (no more false low-battery notifications)
15
+
16
+ ## [1.2.238] - 2026-11-11
17
+
18
+ ### Changed
19
+
20
+ - A battery camera asleep or on its adapter no longer reports a 0% level from the hub, which raised low/normal battery notification pairs; the last real level is kept.
21
+
10
22
  ## [1.2.237] - 2026-11-11
11
23
 
12
24
  ### Changed
package/dist/addon.js CHANGED
@@ -145619,6 +145619,13 @@ var AutomationConditionOperatorSchema = _enum([
145619
145619
  "in"
145620
145620
  ]);
145621
145621
  /**
145622
+ * The stable name of an event leaf. A path (`when.0.1`) moves when a row is
145623
+ * reordered; the id does not, so a `triggered-by` leaf keeps pointing at the
145624
+ * same row. Optional: a leaf nothing refers to needs none.
145625
+ */
145626
+ var EVENT_LEAF_ID_RE = /^[A-Za-z0-9_-]{1,40}$/;
145627
+ var eventLeafId = { id: string().regex(EVENT_LEAF_ID_RE).optional() };
145628
+ /**
145622
145629
  * D8 compliance, and it is the reason a "becomes" leaf is not merely an event
145623
145630
  * subscription: it evaluates against the **state mirror**, which is reconciled,
145624
145631
  * and an event only WAKES the evaluation. A dropped event therefore DELAYS a
@@ -145626,6 +145633,7 @@ var AutomationConditionOperatorSchema = _enum([
145626
145633
  */
145627
145634
  var DeviceBecomesLeafSchema = object({
145628
145635
  kind: literal("device-becomes"),
145636
+ ...eventLeafId,
145629
145637
  deviceId: number$1().int().nonnegative(),
145630
145638
  cap: string().min(1),
145631
145639
  fieldPath: string().min(1),
@@ -145678,6 +145686,7 @@ var DeviceBecomesLeafSchema = object({
145678
145686
  });
145679
145687
  var DeviceEventLeafSchema = object({
145680
145688
  kind: literal("device-event"),
145689
+ ...eventLeafId,
145681
145690
  /** An `EventCategory` value. */
145682
145691
  category: string().min(1),
145683
145692
  deviceId: number$1().int().nonnegative().optional()
@@ -145690,18 +145699,24 @@ var DeviceEventLeafSchema = object({
145690
145699
  */
145691
145700
  var ScheduleLeafSchema = object({
145692
145701
  kind: literal("schedule"),
145702
+ ...eventLeafId,
145693
145703
  at: TimeSpecSchema.optional(),
145694
145704
  days: array(WeekdayKeySchema).min(1).max(7).optional(),
145695
145705
  /** @deprecated legacy cron — new schedules use `at`. */
145696
145706
  cron: string().min(1).max(120).optional()
145697
145707
  }).refine((leaf) => leaf.at === void 0 !== (leaf.cron === void 0), { message: "a schedule names exactly one of `at` (a time spec) and `cron` (legacy)" }).refine((leaf) => leaf.days === void 0 || leaf.at !== void 0, { message: "`days` goes with `at`; a cron expression carries its own days" });
145698
- var ManualLeafSchema = object({ kind: literal("manual") });
145708
+ var ManualLeafSchema = object({
145709
+ kind: literal("manual"),
145710
+ ...eventLeafId
145711
+ });
145699
145712
  var IntervalLeafSchema = object({
145700
145713
  kind: literal("interval"),
145714
+ ...eventLeafId,
145701
145715
  minutes: number$1().int().min(1).max(1440)
145702
145716
  });
145703
145717
  var DetectionLeafSchema = object({
145704
145718
  kind: literal("detection"),
145719
+ ...eventLeafId,
145705
145720
  /** One macro class each, optionally narrowed by a label; a track of any listed subject fires. */
145706
145721
  subjects: array(DetectionSubjectSchema).min(1),
145707
145722
  deviceIds: array(number$1().int().nonnegative()).min(1),
@@ -145712,6 +145727,7 @@ var DetectionLeafSchema = object({
145712
145727
  });
145713
145728
  var StationaryLeafSchema = object({
145714
145729
  kind: literal("stationary"),
145730
+ ...eventLeafId,
145715
145731
  deviceIds: array(number$1().int().nonnegative()).min(1),
145716
145732
  subjects: array(StationarySubjectSchema).min(1).optional(),
145717
145733
  zones: array(string().min(1)).min(1).optional(),
@@ -145757,6 +145773,41 @@ var StationaryPresentLeafSchema = object({
145757
145773
  minCount: number$1().int().positive().optional()
145758
145774
  });
145759
145775
  /**
145776
+ * True while the site-local clock is inside a daily window and/or on one of
145777
+ * the named days. `days` names the local day a window STARTS on, so
145778
+ * 22:00-06:00 on weekdays is still inside at 01:00 Saturday. A one-date spec
145779
+ * (`kind: 'date'`) is refused: only a clock time or a sun event makes a window
145780
+ * that repeats every day.
145781
+ */
145782
+ var TimeIsLeafSchema = object({
145783
+ kind: literal("time-is"),
145784
+ between: object({
145785
+ from: TimeSpecSchema,
145786
+ to: TimeSpecSchema
145787
+ }).optional(),
145788
+ days: array(WeekdayKeySchema).min(1).max(7).optional()
145789
+ }).superRefine((leaf, ctx) => {
145790
+ if (leaf.between === void 0 && leaf.days === void 0) ctx.addIssue({
145791
+ code: "custom",
145792
+ message: "a time-is leaf needs a between window, days, or both"
145793
+ });
145794
+ for (const end of ["from", "to"]) if (leaf.between?.[end].kind === "date") ctx.addIssue({
145795
+ code: "custom",
145796
+ message: "a one-date time cannot bound a daily window: use a clock time or a sun event",
145797
+ path: ["between", end]
145798
+ });
145799
+ });
145800
+ /**
145801
+ * True for the run that one of the named event leaves started. It reads the
145802
+ * run, not a device: in the tree it is judged against the leaf that fired, in
145803
+ * a step guard against the trigger the run carries. A run no event leaf
145804
+ * started (a state-only tree becoming true) is false.
145805
+ */
145806
+ var TriggeredByLeafSchema = object({
145807
+ kind: literal("triggered-by"),
145808
+ leafIds: array(string().regex(EVENT_LEAF_ID_RE)).min(1).max(20)
145809
+ });
145810
+ /**
145760
145811
  * The escape hatch: the bounded expression engine over named device bindings.
145761
145812
  * Declared as a plain object so a discriminated union can read `kind`; the
145762
145813
  * author-time validation is the SAME function `ExpressionSourceSchema` runs.
@@ -145802,7 +145853,9 @@ var AutomationWhenSchema = lazy(() => discriminatedUnion("kind", [
145802
145853
  StationaryLeafSchema,
145803
145854
  DeviceIsLeafSchema,
145804
145855
  StationaryPresentLeafSchema,
145805
- ExpressionLeafSchema
145856
+ ExpressionLeafSchema,
145857
+ TimeIsLeafSchema,
145858
+ TriggeredByLeafSchema
145806
145859
  ]));
145807
145860
  var EVENT_KINDS = new Set([
145808
145861
  "device-becomes",
@@ -145856,6 +145909,28 @@ function hasEventLeaves(node) {
145856
145909
  });
145857
145910
  return found;
145858
145911
  }
145912
+ /** The event leaves of the tree that carry an id, in tree order. */
145913
+ function identifiedEventLeaves(when) {
145914
+ const found = [];
145915
+ forEachLeaf(when, (leaf, path) => {
145916
+ if (isEventLeaf(leaf) && leaf.id !== void 0) found.push({
145917
+ id: leaf.id,
145918
+ path,
145919
+ leaf
145920
+ });
145921
+ });
145922
+ return found;
145923
+ }
145924
+ /** Does the tree hold a `triggered-by` leaf? */
145925
+ function hasTriggeredByLeaves(when) {
145926
+ let found = false;
145927
+ forEachLeaf(when, (leaf) => {
145928
+ if (leaf.kind === "triggered-by") found = true;
145929
+ });
145930
+ return found;
145931
+ }
145932
+ /** Why a `triggered-by` leaf is refused outside an automation: there is no trigger row to name. */
145933
+ var TRIGGERED_BY_NEEDS_AUTOMATION = "\"triggered by\" reads which trigger started an automation — an action or a scheduler has no trigger rows, so it could never be true here";
145859
145934
  function hasEmptyContainer(node) {
145860
145935
  if (isLeaf(node)) return false;
145861
145936
  if (node.kind === "not") return hasEmptyContainer(node.child);
@@ -145914,6 +145989,11 @@ function validateWhenTree(when) {
145914
145989
  if (depth > 4) return `the rules nest ${depth} levels deep — the limit is 4. "not (any of …)" is the same as "all of (not …)", which is one level shallower`;
145915
145990
  const leaves = countWhenLeaves(when);
145916
145991
  if (leaves > 32) return `the rules use ${leaves} rows — the limit is 32`;
145992
+ const seen = /* @__PURE__ */ new Set();
145993
+ for (const entry of identifiedEventLeaves(when)) {
145994
+ if (seen.has(entry.id)) return `two trigger rows share the id "${entry.id}" — an id names one row`;
145995
+ seen.add(entry.id);
145996
+ }
145917
145997
  const need = eventNeed(when, "when", false);
145918
145998
  if ("error" in need) return need.error;
145919
145999
  const [first, second] = need.paths;
@@ -146204,7 +146284,18 @@ var GuardedCapStepSchema = AutomationCapStepBaseSchema.extend(stepGuardShape).re
146204
146284
  message: "a domain target needs the vocabulary action it applies to (actionId)",
146205
146285
  path: ["actionId"]
146206
146286
  }).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
146207
- var ActionStepSchema = discriminatedUnion("kind", [GuardedWaitStepSchema, GuardedCapStepSchema]);
146287
+ /**
146288
+ * A step of a STANDALONE list (an action, a scheduler point, a preset): the
146289
+ * same two step kinds an automation runs, minus a guard that reads the
146290
+ * automation's trigger, which such a list does not have.
146291
+ */
146292
+ var ActionStepSchema = discriminatedUnion("kind", [GuardedWaitStepSchema, GuardedCapStepSchema]).superRefine((step, ctx) => {
146293
+ if (step.if !== void 0 && hasTriggeredByLeaves(step.if)) ctx.addIssue({
146294
+ code: "custom",
146295
+ message: TRIGGERED_BY_NEEDS_AUTOMATION,
146296
+ path: ["if"]
146297
+ });
146298
+ });
146208
146299
  var AutomationActionSchema = discriminatedUnion("kind", [
146209
146300
  GuardedWaitStepSchema,
146210
146301
  GuardedCapStepSchema,
@@ -146301,6 +146392,11 @@ var STATIONARY_DESCRIPTIONS = {
146301
146392
  phase: "appeared or departed",
146302
146393
  entryId: "the stopped object"
146303
146394
  };
146395
+ var BECOMES_DESCRIPTIONS = {
146396
+ deviceId: "the device that changed",
146397
+ from: "the value before the change, empty when it is not known",
146398
+ to: "the value it changed to"
146399
+ };
146304
146400
  function describe$1(descriptions) {
146305
146401
  return Object.entries(descriptions).map(([name, description]) => ({
146306
146402
  name,
@@ -146309,6 +146405,10 @@ function describe$1(descriptions) {
146309
146405
  }
146310
146406
  describe$1(DETECTION_DESCRIPTIONS);
146311
146407
  describe$1(STATIONARY_DESCRIPTIONS);
146408
+ describe$1(BECOMES_DESCRIPTIONS).map((v) => v.name === "deviceId" ? {
146409
+ ...v,
146410
+ hintKey: "becomesDeviceId"
146411
+ } : v);
146312
146412
  new Set(Object.values(COCO_TO_MACRO.mapping));
146313
146413
  /**
146314
146414
  * Schedulers (D983) — an entity that performs actions over the day.
@@ -146333,6 +146433,13 @@ var SchedulerStateTreeSchema = AutomationWhenSchema.superRefine((when, ctx) => {
146333
146433
  });
146334
146434
  return;
146335
146435
  }
146436
+ if (hasTriggeredByLeaves(when)) {
146437
+ ctx.addIssue({
146438
+ code: "custom",
146439
+ message: TRIGGERED_BY_NEEDS_AUTOMATION
146440
+ });
146441
+ return;
146442
+ }
146336
146443
  const problem = validateWhenTree(when);
146337
146444
  if (problem !== null) ctx.addIssue({
146338
146445
  code: "custom",
@@ -146553,6 +146660,8 @@ var AutomationConditionTraceNodeSchema = object({
146553
146660
  "device-is",
146554
146661
  "expression",
146555
146662
  "stationary-present",
146663
+ "time-is",
146664
+ "triggered-by",
146556
146665
  "device-becomes",
146557
146666
  "device-event",
146558
146667
  "schedule",
@@ -211790,6 +211899,20 @@ function deriveChargingSource(adapterStatus, chargeStatus) {
211790
211899
  function reportsPowerSource(info) {
211791
211900
  return info.adapterStatus !== void 0 || info.chargeStatus !== void 0;
211792
211901
  }
211902
+ /**
211903
+ * Whether a level the CAMERA itself reported (push or direct read) is a
211904
+ * MEASUREMENT (D393). A battery camera answering a read on the way in or out of
211905
+ * sleep, or while on mains or a panel, reports `0` as a placeholder — device
211906
+ * 3628 sat at 100% on its adapter and raised a low-battery notification on
211907
+ * every hourly wake. Those zeros are UNMEASURED: the caller keeps the last real
211908
+ * level. A `0` from an awake camera running on its cell alone (or of unknown
211909
+ * source) is a genuine empty cell and passes, as does every non-zero level.
211910
+ */
211911
+ function isMeasuredCameraBatteryLevel(level, context) {
211912
+ if (level !== 0) return true;
211913
+ if (context.sleeping) return false;
211914
+ return context.charging !== "dc" && context.charging !== "solar";
211915
+ }
211793
211916
  /** The settings key, per device. */
211794
211917
  var BATTERY_REFRESH_MINUTES_KEY = "batteryRefreshMinutes";
211795
211918
  /** How often the in-memory check runs. Costs nothing: no I/O unless it fires. */
@@ -213127,6 +213250,20 @@ var UnmappedCodeLedger = class {
213127
213250
  return true;
213128
213251
  }
213129
213252
  };
213253
+ /**
213254
+ * Whether a hub per-channel battery level is a MEASUREMENT (D393). The hub's cached read of a
213255
+ * channel that is asleep reports `0` — and so does a read taken while the cell is on an adapter
213256
+ * (a powered camera at 0% is not a reading, it is a placeholder). Both are UNMEASURED: the caller
213257
+ * keeps the last real level. A `0` from an awake, unpowered channel is a genuine empty cell and
213258
+ * passes, as does every non-zero level.
213259
+ */
213260
+ function isMeasuredHubBatteryLevel(level, context) {
213261
+ if (typeof level !== "number") return false;
213262
+ if (level !== 0) return true;
213263
+ if (context.sleeping) return false;
213264
+ const { chargeStatus, adapterStatus } = context.power;
213265
+ return !(adapterStatus !== void 0 && adapterStatus !== "none" || chargeStatus === "charging" || chargeStatus === "chargeComplete");
213266
+ }
213130
213267
  //#endregion
213131
213268
  //#region src/hub-channel-reconcile.ts
213132
213269
  /**
@@ -213690,8 +213827,21 @@ var ReolinkHubSession = class {
213690
213827
  }
213691
213828
  });
213692
213829
  }
213830
+ const measured = isMeasuredHubBatteryLevel(info.batteryLevel, {
213831
+ sleeping: child.sleeping,
213832
+ power: power.fields
213833
+ });
213834
+ if (info.batteryLevel === 0) this.#logger.info("Reolink hub: battery entry reporting 0", {
213835
+ tags: { deviceId: child.id },
213836
+ meta: {
213837
+ channel: Number(chKey),
213838
+ sleeping: child.sleeping,
213839
+ measured,
213840
+ raw: info
213841
+ }
213842
+ });
213693
213843
  child.applyHubBatteryInfo({
213694
- batteryPercent: info.batteryLevel,
213844
+ ...measured ? { batteryPercent: info.batteryLevel } : {},
213695
213845
  ...power.fields
213696
213846
  });
213697
213847
  }
@@ -218800,10 +218950,26 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
218800
218950
  * tracker is more reliable.
218801
218951
  */
218802
218952
  mapBatteryInfo(info) {
218953
+ const charging = reportsPowerSource(info) ? deriveChargingSource(info.adapterStatus, info.chargeStatus) : this.state.battery.charging ?? "unknown";
218954
+ const sleeping = info.sleeping === true || this.sleeping;
218955
+ const reported = typeof info.batteryPercent === "number" ? Math.max(0, Math.min(100, Math.round(info.batteryPercent))) : void 0;
218956
+ const measured = reported !== void 0 && isMeasuredCameraBatteryLevel(reported, {
218957
+ sleeping,
218958
+ charging
218959
+ });
218960
+ if (reported === 0) this.ctx.logger.info("battery read reporting 0", {
218961
+ tags: { deviceId: this.id },
218962
+ meta: {
218963
+ measured,
218964
+ sleeping,
218965
+ charging,
218966
+ raw: info
218967
+ }
218968
+ });
218803
218969
  return {
218804
- level: typeof info.batteryPercent === "number" ? Math.max(0, Math.min(100, Math.round(info.batteryPercent))) : this.state.battery.level ?? null,
218805
- charging: reportsPowerSource(info) ? deriveChargingSource(info.adapterStatus, info.chargeStatus) : this.state.battery.charging ?? "unknown",
218806
- sleeping: info.sleeping === true || this.sleeping,
218970
+ level: reported !== void 0 && measured ? reported : this.state.battery.level ?? null,
218971
+ charging,
218972
+ sleeping,
218807
218973
  lastUpdated: Date.now()
218808
218974
  };
218809
218975
  }
package/dist/addon.mjs CHANGED
@@ -145611,6 +145611,13 @@ var AutomationConditionOperatorSchema = _enum([
145611
145611
  "in"
145612
145612
  ]);
145613
145613
  /**
145614
+ * The stable name of an event leaf. A path (`when.0.1`) moves when a row is
145615
+ * reordered; the id does not, so a `triggered-by` leaf keeps pointing at the
145616
+ * same row. Optional: a leaf nothing refers to needs none.
145617
+ */
145618
+ var EVENT_LEAF_ID_RE = /^[A-Za-z0-9_-]{1,40}$/;
145619
+ var eventLeafId = { id: string().regex(EVENT_LEAF_ID_RE).optional() };
145620
+ /**
145614
145621
  * D8 compliance, and it is the reason a "becomes" leaf is not merely an event
145615
145622
  * subscription: it evaluates against the **state mirror**, which is reconciled,
145616
145623
  * and an event only WAKES the evaluation. A dropped event therefore DELAYS a
@@ -145618,6 +145625,7 @@ var AutomationConditionOperatorSchema = _enum([
145618
145625
  */
145619
145626
  var DeviceBecomesLeafSchema = object({
145620
145627
  kind: literal("device-becomes"),
145628
+ ...eventLeafId,
145621
145629
  deviceId: number$1().int().nonnegative(),
145622
145630
  cap: string().min(1),
145623
145631
  fieldPath: string().min(1),
@@ -145670,6 +145678,7 @@ var DeviceBecomesLeafSchema = object({
145670
145678
  });
145671
145679
  var DeviceEventLeafSchema = object({
145672
145680
  kind: literal("device-event"),
145681
+ ...eventLeafId,
145673
145682
  /** An `EventCategory` value. */
145674
145683
  category: string().min(1),
145675
145684
  deviceId: number$1().int().nonnegative().optional()
@@ -145682,18 +145691,24 @@ var DeviceEventLeafSchema = object({
145682
145691
  */
145683
145692
  var ScheduleLeafSchema = object({
145684
145693
  kind: literal("schedule"),
145694
+ ...eventLeafId,
145685
145695
  at: TimeSpecSchema.optional(),
145686
145696
  days: array(WeekdayKeySchema).min(1).max(7).optional(),
145687
145697
  /** @deprecated legacy cron — new schedules use `at`. */
145688
145698
  cron: string().min(1).max(120).optional()
145689
145699
  }).refine((leaf) => leaf.at === void 0 !== (leaf.cron === void 0), { message: "a schedule names exactly one of `at` (a time spec) and `cron` (legacy)" }).refine((leaf) => leaf.days === void 0 || leaf.at !== void 0, { message: "`days` goes with `at`; a cron expression carries its own days" });
145690
- var ManualLeafSchema = object({ kind: literal("manual") });
145700
+ var ManualLeafSchema = object({
145701
+ kind: literal("manual"),
145702
+ ...eventLeafId
145703
+ });
145691
145704
  var IntervalLeafSchema = object({
145692
145705
  kind: literal("interval"),
145706
+ ...eventLeafId,
145693
145707
  minutes: number$1().int().min(1).max(1440)
145694
145708
  });
145695
145709
  var DetectionLeafSchema = object({
145696
145710
  kind: literal("detection"),
145711
+ ...eventLeafId,
145697
145712
  /** One macro class each, optionally narrowed by a label; a track of any listed subject fires. */
145698
145713
  subjects: array(DetectionSubjectSchema).min(1),
145699
145714
  deviceIds: array(number$1().int().nonnegative()).min(1),
@@ -145704,6 +145719,7 @@ var DetectionLeafSchema = object({
145704
145719
  });
145705
145720
  var StationaryLeafSchema = object({
145706
145721
  kind: literal("stationary"),
145722
+ ...eventLeafId,
145707
145723
  deviceIds: array(number$1().int().nonnegative()).min(1),
145708
145724
  subjects: array(StationarySubjectSchema).min(1).optional(),
145709
145725
  zones: array(string().min(1)).min(1).optional(),
@@ -145749,6 +145765,41 @@ var StationaryPresentLeafSchema = object({
145749
145765
  minCount: number$1().int().positive().optional()
145750
145766
  });
145751
145767
  /**
145768
+ * True while the site-local clock is inside a daily window and/or on one of
145769
+ * the named days. `days` names the local day a window STARTS on, so
145770
+ * 22:00-06:00 on weekdays is still inside at 01:00 Saturday. A one-date spec
145771
+ * (`kind: 'date'`) is refused: only a clock time or a sun event makes a window
145772
+ * that repeats every day.
145773
+ */
145774
+ var TimeIsLeafSchema = object({
145775
+ kind: literal("time-is"),
145776
+ between: object({
145777
+ from: TimeSpecSchema,
145778
+ to: TimeSpecSchema
145779
+ }).optional(),
145780
+ days: array(WeekdayKeySchema).min(1).max(7).optional()
145781
+ }).superRefine((leaf, ctx) => {
145782
+ if (leaf.between === void 0 && leaf.days === void 0) ctx.addIssue({
145783
+ code: "custom",
145784
+ message: "a time-is leaf needs a between window, days, or both"
145785
+ });
145786
+ for (const end of ["from", "to"]) if (leaf.between?.[end].kind === "date") ctx.addIssue({
145787
+ code: "custom",
145788
+ message: "a one-date time cannot bound a daily window: use a clock time or a sun event",
145789
+ path: ["between", end]
145790
+ });
145791
+ });
145792
+ /**
145793
+ * True for the run that one of the named event leaves started. It reads the
145794
+ * run, not a device: in the tree it is judged against the leaf that fired, in
145795
+ * a step guard against the trigger the run carries. A run no event leaf
145796
+ * started (a state-only tree becoming true) is false.
145797
+ */
145798
+ var TriggeredByLeafSchema = object({
145799
+ kind: literal("triggered-by"),
145800
+ leafIds: array(string().regex(EVENT_LEAF_ID_RE)).min(1).max(20)
145801
+ });
145802
+ /**
145752
145803
  * The escape hatch: the bounded expression engine over named device bindings.
145753
145804
  * Declared as a plain object so a discriminated union can read `kind`; the
145754
145805
  * author-time validation is the SAME function `ExpressionSourceSchema` runs.
@@ -145794,7 +145845,9 @@ var AutomationWhenSchema = lazy(() => discriminatedUnion("kind", [
145794
145845
  StationaryLeafSchema,
145795
145846
  DeviceIsLeafSchema,
145796
145847
  StationaryPresentLeafSchema,
145797
- ExpressionLeafSchema
145848
+ ExpressionLeafSchema,
145849
+ TimeIsLeafSchema,
145850
+ TriggeredByLeafSchema
145798
145851
  ]));
145799
145852
  var EVENT_KINDS = new Set([
145800
145853
  "device-becomes",
@@ -145848,6 +145901,28 @@ function hasEventLeaves(node) {
145848
145901
  });
145849
145902
  return found;
145850
145903
  }
145904
+ /** The event leaves of the tree that carry an id, in tree order. */
145905
+ function identifiedEventLeaves(when) {
145906
+ const found = [];
145907
+ forEachLeaf(when, (leaf, path) => {
145908
+ if (isEventLeaf(leaf) && leaf.id !== void 0) found.push({
145909
+ id: leaf.id,
145910
+ path,
145911
+ leaf
145912
+ });
145913
+ });
145914
+ return found;
145915
+ }
145916
+ /** Does the tree hold a `triggered-by` leaf? */
145917
+ function hasTriggeredByLeaves(when) {
145918
+ let found = false;
145919
+ forEachLeaf(when, (leaf) => {
145920
+ if (leaf.kind === "triggered-by") found = true;
145921
+ });
145922
+ return found;
145923
+ }
145924
+ /** Why a `triggered-by` leaf is refused outside an automation: there is no trigger row to name. */
145925
+ var TRIGGERED_BY_NEEDS_AUTOMATION = "\"triggered by\" reads which trigger started an automation — an action or a scheduler has no trigger rows, so it could never be true here";
145851
145926
  function hasEmptyContainer(node) {
145852
145927
  if (isLeaf(node)) return false;
145853
145928
  if (node.kind === "not") return hasEmptyContainer(node.child);
@@ -145906,6 +145981,11 @@ function validateWhenTree(when) {
145906
145981
  if (depth > 4) return `the rules nest ${depth} levels deep — the limit is 4. "not (any of …)" is the same as "all of (not …)", which is one level shallower`;
145907
145982
  const leaves = countWhenLeaves(when);
145908
145983
  if (leaves > 32) return `the rules use ${leaves} rows — the limit is 32`;
145984
+ const seen = /* @__PURE__ */ new Set();
145985
+ for (const entry of identifiedEventLeaves(when)) {
145986
+ if (seen.has(entry.id)) return `two trigger rows share the id "${entry.id}" — an id names one row`;
145987
+ seen.add(entry.id);
145988
+ }
145909
145989
  const need = eventNeed(when, "when", false);
145910
145990
  if ("error" in need) return need.error;
145911
145991
  const [first, second] = need.paths;
@@ -146196,7 +146276,18 @@ var GuardedCapStepSchema = AutomationCapStepBaseSchema.extend(stepGuardShape).re
146196
146276
  message: "a domain target needs the vocabulary action it applies to (actionId)",
146197
146277
  path: ["actionId"]
146198
146278
  }).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
146199
- var ActionStepSchema = discriminatedUnion("kind", [GuardedWaitStepSchema, GuardedCapStepSchema]);
146279
+ /**
146280
+ * A step of a STANDALONE list (an action, a scheduler point, a preset): the
146281
+ * same two step kinds an automation runs, minus a guard that reads the
146282
+ * automation's trigger, which such a list does not have.
146283
+ */
146284
+ var ActionStepSchema = discriminatedUnion("kind", [GuardedWaitStepSchema, GuardedCapStepSchema]).superRefine((step, ctx) => {
146285
+ if (step.if !== void 0 && hasTriggeredByLeaves(step.if)) ctx.addIssue({
146286
+ code: "custom",
146287
+ message: TRIGGERED_BY_NEEDS_AUTOMATION,
146288
+ path: ["if"]
146289
+ });
146290
+ });
146200
146291
  var AutomationActionSchema = discriminatedUnion("kind", [
146201
146292
  GuardedWaitStepSchema,
146202
146293
  GuardedCapStepSchema,
@@ -146293,6 +146384,11 @@ var STATIONARY_DESCRIPTIONS = {
146293
146384
  phase: "appeared or departed",
146294
146385
  entryId: "the stopped object"
146295
146386
  };
146387
+ var BECOMES_DESCRIPTIONS = {
146388
+ deviceId: "the device that changed",
146389
+ from: "the value before the change, empty when it is not known",
146390
+ to: "the value it changed to"
146391
+ };
146296
146392
  function describe$1(descriptions) {
146297
146393
  return Object.entries(descriptions).map(([name, description]) => ({
146298
146394
  name,
@@ -146301,6 +146397,10 @@ function describe$1(descriptions) {
146301
146397
  }
146302
146398
  describe$1(DETECTION_DESCRIPTIONS);
146303
146399
  describe$1(STATIONARY_DESCRIPTIONS);
146400
+ describe$1(BECOMES_DESCRIPTIONS).map((v) => v.name === "deviceId" ? {
146401
+ ...v,
146402
+ hintKey: "becomesDeviceId"
146403
+ } : v);
146304
146404
  new Set(Object.values(COCO_TO_MACRO.mapping));
146305
146405
  /**
146306
146406
  * Schedulers (D983) — an entity that performs actions over the day.
@@ -146325,6 +146425,13 @@ var SchedulerStateTreeSchema = AutomationWhenSchema.superRefine((when, ctx) => {
146325
146425
  });
146326
146426
  return;
146327
146427
  }
146428
+ if (hasTriggeredByLeaves(when)) {
146429
+ ctx.addIssue({
146430
+ code: "custom",
146431
+ message: TRIGGERED_BY_NEEDS_AUTOMATION
146432
+ });
146433
+ return;
146434
+ }
146328
146435
  const problem = validateWhenTree(when);
146329
146436
  if (problem !== null) ctx.addIssue({
146330
146437
  code: "custom",
@@ -146545,6 +146652,8 @@ var AutomationConditionTraceNodeSchema = object({
146545
146652
  "device-is",
146546
146653
  "expression",
146547
146654
  "stationary-present",
146655
+ "time-is",
146656
+ "triggered-by",
146548
146657
  "device-becomes",
146549
146658
  "device-event",
146550
146659
  "schedule",
@@ -211782,6 +211891,20 @@ function deriveChargingSource(adapterStatus, chargeStatus) {
211782
211891
  function reportsPowerSource(info) {
211783
211892
  return info.adapterStatus !== void 0 || info.chargeStatus !== void 0;
211784
211893
  }
211894
+ /**
211895
+ * Whether a level the CAMERA itself reported (push or direct read) is a
211896
+ * MEASUREMENT (D393). A battery camera answering a read on the way in or out of
211897
+ * sleep, or while on mains or a panel, reports `0` as a placeholder — device
211898
+ * 3628 sat at 100% on its adapter and raised a low-battery notification on
211899
+ * every hourly wake. Those zeros are UNMEASURED: the caller keeps the last real
211900
+ * level. A `0` from an awake camera running on its cell alone (or of unknown
211901
+ * source) is a genuine empty cell and passes, as does every non-zero level.
211902
+ */
211903
+ function isMeasuredCameraBatteryLevel(level, context) {
211904
+ if (level !== 0) return true;
211905
+ if (context.sleeping) return false;
211906
+ return context.charging !== "dc" && context.charging !== "solar";
211907
+ }
211785
211908
  /** The settings key, per device. */
211786
211909
  var BATTERY_REFRESH_MINUTES_KEY = "batteryRefreshMinutes";
211787
211910
  /** How often the in-memory check runs. Costs nothing: no I/O unless it fires. */
@@ -213119,6 +213242,20 @@ var UnmappedCodeLedger = class {
213119
213242
  return true;
213120
213243
  }
213121
213244
  };
213245
+ /**
213246
+ * Whether a hub per-channel battery level is a MEASUREMENT (D393). The hub's cached read of a
213247
+ * channel that is asleep reports `0` — and so does a read taken while the cell is on an adapter
213248
+ * (a powered camera at 0% is not a reading, it is a placeholder). Both are UNMEASURED: the caller
213249
+ * keeps the last real level. A `0` from an awake, unpowered channel is a genuine empty cell and
213250
+ * passes, as does every non-zero level.
213251
+ */
213252
+ function isMeasuredHubBatteryLevel(level, context) {
213253
+ if (typeof level !== "number") return false;
213254
+ if (level !== 0) return true;
213255
+ if (context.sleeping) return false;
213256
+ const { chargeStatus, adapterStatus } = context.power;
213257
+ return !(adapterStatus !== void 0 && adapterStatus !== "none" || chargeStatus === "charging" || chargeStatus === "chargeComplete");
213258
+ }
213122
213259
  //#endregion
213123
213260
  //#region src/hub-channel-reconcile.ts
213124
213261
  /**
@@ -213682,8 +213819,21 @@ var ReolinkHubSession = class {
213682
213819
  }
213683
213820
  });
213684
213821
  }
213822
+ const measured = isMeasuredHubBatteryLevel(info.batteryLevel, {
213823
+ sleeping: child.sleeping,
213824
+ power: power.fields
213825
+ });
213826
+ if (info.batteryLevel === 0) this.#logger.info("Reolink hub: battery entry reporting 0", {
213827
+ tags: { deviceId: child.id },
213828
+ meta: {
213829
+ channel: Number(chKey),
213830
+ sleeping: child.sleeping,
213831
+ measured,
213832
+ raw: info
213833
+ }
213834
+ });
213685
213835
  child.applyHubBatteryInfo({
213686
- batteryPercent: info.batteryLevel,
213836
+ ...measured ? { batteryPercent: info.batteryLevel } : {},
213687
213837
  ...power.fields
213688
213838
  });
213689
213839
  }
@@ -218792,10 +218942,26 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
218792
218942
  * tracker is more reliable.
218793
218943
  */
218794
218944
  mapBatteryInfo(info) {
218945
+ const charging = reportsPowerSource(info) ? deriveChargingSource(info.adapterStatus, info.chargeStatus) : this.state.battery.charging ?? "unknown";
218946
+ const sleeping = info.sleeping === true || this.sleeping;
218947
+ const reported = typeof info.batteryPercent === "number" ? Math.max(0, Math.min(100, Math.round(info.batteryPercent))) : void 0;
218948
+ const measured = reported !== void 0 && isMeasuredCameraBatteryLevel(reported, {
218949
+ sleeping,
218950
+ charging
218951
+ });
218952
+ if (reported === 0) this.ctx.logger.info("battery read reporting 0", {
218953
+ tags: { deviceId: this.id },
218954
+ meta: {
218955
+ measured,
218956
+ sleeping,
218957
+ charging,
218958
+ raw: info
218959
+ }
218960
+ });
218795
218961
  return {
218796
- level: typeof info.batteryPercent === "number" ? Math.max(0, Math.min(100, Math.round(info.batteryPercent))) : this.state.battery.level ?? null,
218797
- charging: reportsPowerSource(info) ? deriveChargingSource(info.adapterStatus, info.chargeStatus) : this.state.battery.charging ?? "unknown",
218798
- sleeping: info.sleeping === true || this.sleeping,
218962
+ level: reported !== void 0 && measured ? reported : this.state.battery.level ?? null,
218963
+ charging,
218964
+ sleeping,
218799
218965
  lastUpdated: Date.now()
218800
218966
  };
218801
218967
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-provider-reolink",
3
- "version": "1.2.237",
3
+ "version": "1.2.239",
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.834"
99
+ "server": ">=1.2.840"
100
100
  }
101
101
  },
102
102
  "files": [