@camstack/addon-provider-reolink 1.2.250 → 1.2.252

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/dist/addon.mjs CHANGED
@@ -129602,6 +129602,16 @@ var RecordingBandTriggersSchema = RecordingTriggersSchema;
129602
129602
  * question to answer as a continuous one.
129603
129603
  */
129604
129604
  var RecordingBandAudioSchema = _enum(["on", "muted"]);
129605
+ /**
129606
+ * A battery condition on a band: the band covers a charge level only when
129607
+ * `min <= level < max` (half-open; a missing bound is unbounded). OPTIONAL —
129608
+ * an absent key means "any charge", which is what every config written before
129609
+ * it meant. A band WITH a condition is never met while the charge is unknown.
129610
+ */
129611
+ var RecordingBandBatterySchema = object({
129612
+ min: number$1().min(0).max(100).optional(),
129613
+ max: number$1().min(0).max(100).optional()
129614
+ });
129605
129615
  var RecordingBandSchema = object({
129606
129616
  days: array(RecordingWeekdaySchema),
129607
129617
  start: string().regex(HHMM),
@@ -129613,6 +129623,7 @@ var RecordingBandSchema = object({
129613
129623
  * missing must keep meaning what it meant. See {@link RecordingBandAudioSchema}.
129614
129624
  */
129615
129625
  audio: RecordingBandAudioSchema.optional(),
129626
+ battery: RecordingBandBatterySchema.optional(),
129616
129627
  triggers: RecordingBandTriggersSchema.optional(),
129617
129628
  /**
129618
129629
  * RETIRED (D381). A band no longer carries a pre-buffer of its own.
@@ -162517,7 +162528,7 @@ var HISTORY_PRIMARY = {
162517
162528
  }
162518
162529
  };
162519
162530
  DeviceFeature.LightColorRgb, DeviceFeature.LightColorHsv, DeviceFeature.LightColorMired;
162520
- var PowerSourceRefusalReasonSchema = _enum([
162531
+ var PowerSourceRefusalReasonSchema$1 = _enum([
162521
162532
  "no-power-source",
162522
162533
  "switch-missing",
162523
162534
  "switch-offline",
@@ -162532,7 +162543,7 @@ var PowerSourceRefusalReasonSchema = _enum([
162532
162543
  ]);
162533
162544
  var PowerSourceActionResultSchema = discriminatedUnion("accepted", [object({ accepted: literal(true) }), object({
162534
162545
  accepted: literal(false),
162535
- reason: PowerSourceRefusalReasonSchema,
162546
+ reason: PowerSourceRefusalReasonSchema$1,
162536
162547
  /** One line for the operator, naming the switch. */
162537
162548
  message: string()
162538
162549
  })]);
@@ -228563,46 +228574,6 @@ var IntercomFailureReport = class {
228563
228574
  /** The process-wide instance every camera in this addon notes into. */
228564
228575
  var intercomFailureReport = new IntercomFailureReport();
228565
228576
  //#endregion
228566
- //#region src/clips/clip-time-zone.ts
228567
- function isUsableTimeZone(timeZone) {
228568
- try {
228569
- new Intl.DateTimeFormat("en-US", { timeZone });
228570
- return true;
228571
- } catch {
228572
- return false;
228573
- }
228574
- }
228575
- /**
228576
- * @param candidate the zone the process reports
228577
- * @param cameraZone a zone derived from the camera's reported UTC offset, if any
228578
- */
228579
- function resolveClipTimeZone(candidate, cameraZone) {
228580
- if (isUsableTimeZone(candidate)) return { timeZone: candidate };
228581
- if (cameraZone !== void 0 && isUsableTimeZone(cameraZone)) return {
228582
- timeZone: cameraZone,
228583
- rejected: candidate
228584
- };
228585
- return {
228586
- timeZone: "UTC",
228587
- rejected: candidate
228588
- };
228589
- }
228590
- /** Resolve and, when the candidate was refused, warn ONCE per `warned` holder. */
228591
- function resolveClipTimeZoneOnce(candidate, cameraZone, logger, deviceId, warned) {
228592
- const res = resolveClipTimeZone(candidate, cameraZone);
228593
- if (res.rejected !== void 0 && !warned.done) {
228594
- warned.done = true;
228595
- logger.warn("clip catalog: the process time zone is not usable, using a fallback", {
228596
- tags: { deviceId },
228597
- meta: {
228598
- rejectedTimeZone: res.rejected,
228599
- fallbackTimeZone: res.timeZone
228600
- }
228601
- });
228602
- }
228603
- return res.timeZone;
228604
- }
228605
- //#endregion
228606
228577
  //#region src/baichuan-webhook-shared.ts
228607
228578
  /** The data-plane prefix this addon serves the camera push on: `/addon/<addonId>/webhook/<stableId>`. */
228608
228579
  var BAICHUAN_WEBHOOK_PREFIX = "webhook";
@@ -229002,6 +228973,46 @@ async function refreshSnapshotCacheOnce(input) {
229002
228973
  return true;
229003
228974
  }
229004
228975
  //#endregion
228976
+ //#region src/clips/clip-time-zone.ts
228977
+ function isUsableTimeZone(timeZone) {
228978
+ try {
228979
+ new Intl.DateTimeFormat("en-US", { timeZone });
228980
+ return true;
228981
+ } catch {
228982
+ return false;
228983
+ }
228984
+ }
228985
+ /**
228986
+ * @param candidate the zone the process reports
228987
+ * @param cameraZone a zone derived from the camera's reported UTC offset, if any
228988
+ */
228989
+ function resolveClipTimeZone(candidate, cameraZone) {
228990
+ if (isUsableTimeZone(candidate)) return { timeZone: candidate };
228991
+ if (cameraZone !== void 0 && isUsableTimeZone(cameraZone)) return {
228992
+ timeZone: cameraZone,
228993
+ rejected: candidate
228994
+ };
228995
+ return {
228996
+ timeZone: "UTC",
228997
+ rejected: candidate
228998
+ };
228999
+ }
229000
+ /** Resolve and, when the candidate was refused, warn ONCE per `warned` holder. */
229001
+ function resolveClipTimeZoneOnce(candidate, cameraZone, logger, deviceId, warned) {
229002
+ const res = resolveClipTimeZone(candidate, cameraZone);
229003
+ if (res.rejected !== void 0 && !warned.done) {
229004
+ warned.done = true;
229005
+ logger.warn("clip catalog: the process time zone is not usable, using a fallback", {
229006
+ tags: { deviceId },
229007
+ meta: {
229008
+ rejectedTimeZone: res.rejected,
229009
+ fallbackTimeZone: res.timeZone
229010
+ }
229011
+ });
229012
+ }
229013
+ return res.timeZone;
229014
+ }
229015
+ //#endregion
229005
229016
  //#region src/day-night-mapping.ts
229006
229017
  /**
229007
229018
  * Maps between the vendor-neutral `day-night` cap's `DayNightMode` and
@@ -229104,6 +229115,114 @@ function deriveReolinkCameraFeatures(inputs) {
229104
229115
  return out;
229105
229116
  }
229106
229117
  //#endregion
229118
+ //#region src/hub-child-settings.ts
229119
+ /**
229120
+ * A camera adopted under an NVR / Home Hub dials through the integration's session: the address
229121
+ * and the credentials belong to the integration, never to the camera. These are the per-camera
229122
+ * keys a hub child must refuse to change.
229123
+ */
229124
+ var HUB_CHILD_CONNECTION_KEYS = [
229125
+ "host",
229126
+ "port",
229127
+ "username",
229128
+ "password"
229129
+ ];
229130
+ /**
229131
+ * Sections that act on the hub itself (no channel in the call) or on the per-camera connection,
229132
+ * hidden for a hub child:
229133
+ * - `connection`: the per-camera address and credentials (the integration owns them);
229134
+ * - `network-ports`: `setPortConfig` rewrites the NVR's own service ports;
229135
+ * - `time-ntp`: `setNtp` / `setSystemGeneral` / `setDst` rewrite the NVR's clock.
229136
+ */
229137
+ var HUB_CHILD_HIDDEN_SECTION_IDS = [
229138
+ "connection",
229139
+ "network-ports",
229140
+ "time-ntp"
229141
+ ];
229142
+ /** Thrown by `applySettingsPatch` for a refused hub-child patch; carries the typed reason. */
229143
+ var HubChildPatchRefusedError = class extends Error {
229144
+ refusal;
229145
+ constructor(refusal) {
229146
+ super(describeRefusal(refusal));
229147
+ this.refusal = refusal;
229148
+ this.name = "HubChildPatchRefusedError";
229149
+ }
229150
+ };
229151
+ function describeRefusal(refusal) {
229152
+ switch (refusal.reason) {
229153
+ case "connection-owned-by-integration": return `This camera is connected through its NVR / Home Hub integration: ${refusal.keys.join(", ")} can only be changed on the integration`;
229154
+ case "channel-not-an-integer": return `The hub channel must be a whole number, got ${String(refusal.value)}`;
229155
+ case "channel-out-of-range": return `Channel ${refusal.value} is not one of the hub's channels (${refusal.channels.join(", ")})`;
229156
+ }
229157
+ }
229158
+ /**
229159
+ * Judge a settings patch against the hub-child rules. `channels` is the hub's last good channel
229160
+ * list (empty when unknown — then only the integer rule applies).
229161
+ */
229162
+ function judgeHubChildPatch(patch, channels) {
229163
+ const touched = HUB_CHILD_CONNECTION_KEYS.filter((k) => patch[k] !== void 0);
229164
+ if (touched.length > 0) return {
229165
+ reason: "connection-owned-by-integration",
229166
+ keys: touched
229167
+ };
229168
+ if (patch["channel"] === void 0) return null;
229169
+ const value = patch["channel"];
229170
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) return {
229171
+ reason: "channel-not-an-integer",
229172
+ value
229173
+ };
229174
+ if (channels.length > 0 && !channels.includes(value)) return {
229175
+ reason: "channel-out-of-range",
229176
+ value,
229177
+ channels
229178
+ };
229179
+ return null;
229180
+ }
229181
+ /** What a hub child shows before its session has read the hub's channel list. */
229182
+ var EMPTY_HUB_CHANNEL_SNAPSHOT = {
229183
+ channels: [],
229184
+ lastRefreshAt: null,
229185
+ lastError: null
229186
+ };
229187
+ /** The hub-child "Hub" section: which hub, and the one editable connection field, the channel. */
229188
+ function buildHubChildSection(snapshot) {
229189
+ return {
229190
+ id: "hub",
229191
+ tab: "general",
229192
+ title: "Hub",
229193
+ titleKey: "provider-reolink:schema.s_hub.title",
229194
+ description: "This camera is connected through its NVR / Home Hub. Address and credentials belong to that integration; the channel is kept in line with the hub automatically.",
229195
+ descriptionKey: "provider-reolink:schema.s_hub.description",
229196
+ columns: 2,
229197
+ fields: [{
229198
+ type: "text",
229199
+ key: "hubName",
229200
+ label: "Connected to",
229201
+ labelKey: "provider-reolink:schema.s_hub.hubName.label",
229202
+ disabled: true
229203
+ }, {
229204
+ type: "number",
229205
+ key: "channel",
229206
+ label: "Hub channel",
229207
+ labelKey: "provider-reolink:schema.s_hub.channel.label",
229208
+ min: 0,
229209
+ ...snapshot.channels.length > 0 ? { max: Math.max(...snapshot.channels.map((c) => c.channel)) } : {},
229210
+ step: 1
229211
+ }]
229212
+ };
229213
+ }
229214
+ /** Replace the connection/hub-acting sections of a standalone schema with the Hub section. */
229215
+ function applyHubChildSections(sections, snapshot) {
229216
+ const kept = sections.filter((s) => !HUB_CHILD_HIDDEN_SECTION_IDS.includes(s.id));
229217
+ const at = kept.findIndex((s) => s.id === "driver-refresh");
229218
+ const hub = buildHubChildSection(snapshot);
229219
+ return at < 0 ? [hub, ...kept] : [
229220
+ ...kept.slice(0, at + 1),
229221
+ hub,
229222
+ ...kept.slice(at + 1)
229223
+ ];
229224
+ }
229225
+ //#endregion
229107
229226
  //#region src/image-settings-mapping.ts
229108
229227
  /**
229109
229228
  * Reolink's `InputAdvanceCfg.Exposure.mode` (Baichuan cmdId 25/26, via
@@ -230890,114 +231009,6 @@ function registerHubChildStateRefresh(target) {
230890
231009
  }, { stateRefresh: hubChildRefreshPolicy(integrationId) });
230891
231010
  }
230892
231011
  //#endregion
230893
- //#region src/hub-child-settings.ts
230894
- /**
230895
- * A camera adopted under an NVR / Home Hub dials through the integration's session: the address
230896
- * and the credentials belong to the integration, never to the camera. These are the per-camera
230897
- * keys a hub child must refuse to change.
230898
- */
230899
- var HUB_CHILD_CONNECTION_KEYS = [
230900
- "host",
230901
- "port",
230902
- "username",
230903
- "password"
230904
- ];
230905
- /**
230906
- * Sections that act on the hub itself (no channel in the call) or on the per-camera connection,
230907
- * hidden for a hub child:
230908
- * - `connection`: the per-camera address and credentials (the integration owns them);
230909
- * - `network-ports`: `setPortConfig` rewrites the NVR's own service ports;
230910
- * - `time-ntp`: `setNtp` / `setSystemGeneral` / `setDst` rewrite the NVR's clock.
230911
- */
230912
- var HUB_CHILD_HIDDEN_SECTION_IDS = [
230913
- "connection",
230914
- "network-ports",
230915
- "time-ntp"
230916
- ];
230917
- /** Thrown by `applySettingsPatch` for a refused hub-child patch; carries the typed reason. */
230918
- var HubChildPatchRefusedError = class extends Error {
230919
- refusal;
230920
- constructor(refusal) {
230921
- super(describeRefusal(refusal));
230922
- this.refusal = refusal;
230923
- this.name = "HubChildPatchRefusedError";
230924
- }
230925
- };
230926
- function describeRefusal(refusal) {
230927
- switch (refusal.reason) {
230928
- case "connection-owned-by-integration": return `This camera is connected through its NVR / Home Hub integration: ${refusal.keys.join(", ")} can only be changed on the integration`;
230929
- case "channel-not-an-integer": return `The hub channel must be a whole number, got ${String(refusal.value)}`;
230930
- case "channel-out-of-range": return `Channel ${refusal.value} is not one of the hub's channels (${refusal.channels.join(", ")})`;
230931
- }
230932
- }
230933
- /**
230934
- * Judge a settings patch against the hub-child rules. `channels` is the hub's last good channel
230935
- * list (empty when unknown — then only the integer rule applies).
230936
- */
230937
- function judgeHubChildPatch(patch, channels) {
230938
- const touched = HUB_CHILD_CONNECTION_KEYS.filter((k) => patch[k] !== void 0);
230939
- if (touched.length > 0) return {
230940
- reason: "connection-owned-by-integration",
230941
- keys: touched
230942
- };
230943
- if (patch["channel"] === void 0) return null;
230944
- const value = patch["channel"];
230945
- if (typeof value !== "number" || !Number.isInteger(value) || value < 0) return {
230946
- reason: "channel-not-an-integer",
230947
- value
230948
- };
230949
- if (channels.length > 0 && !channels.includes(value)) return {
230950
- reason: "channel-out-of-range",
230951
- value,
230952
- channels
230953
- };
230954
- return null;
230955
- }
230956
- /** What a hub child shows before its session has read the hub's channel list. */
230957
- var EMPTY_HUB_CHANNEL_SNAPSHOT = {
230958
- channels: [],
230959
- lastRefreshAt: null,
230960
- lastError: null
230961
- };
230962
- /** The hub-child "Hub" section: which hub, and the one editable connection field, the channel. */
230963
- function buildHubChildSection(snapshot) {
230964
- return {
230965
- id: "hub",
230966
- tab: "general",
230967
- title: "Hub",
230968
- titleKey: "provider-reolink:schema.s_hub.title",
230969
- description: "This camera is connected through its NVR / Home Hub. Address and credentials belong to that integration; the channel is kept in line with the hub automatically.",
230970
- descriptionKey: "provider-reolink:schema.s_hub.description",
230971
- columns: 2,
230972
- fields: [{
230973
- type: "text",
230974
- key: "hubName",
230975
- label: "Connected to",
230976
- labelKey: "provider-reolink:schema.s_hub.hubName.label",
230977
- disabled: true
230978
- }, {
230979
- type: "number",
230980
- key: "channel",
230981
- label: "Hub channel",
230982
- labelKey: "provider-reolink:schema.s_hub.channel.label",
230983
- min: 0,
230984
- ...snapshot.channels.length > 0 ? { max: Math.max(...snapshot.channels.map((c) => c.channel)) } : {},
230985
- step: 1
230986
- }]
230987
- };
230988
- }
230989
- /** Replace the connection/hub-acting sections of a standalone schema with the Hub section. */
230990
- function applyHubChildSections(sections, snapshot) {
230991
- const kept = sections.filter((s) => !HUB_CHILD_HIDDEN_SECTION_IDS.includes(s.id));
230992
- const at = kept.findIndex((s) => s.id === "driver-refresh");
230993
- const hub = buildHubChildSection(snapshot);
230994
- return at < 0 ? [hub, ...kept] : [
230995
- ...kept.slice(0, at + 1),
230996
- hub,
230997
- ...kept.slice(at + 1)
230998
- ];
230999
- }
231000
- //#endregion
231001
231012
  //#region src/sleep-state-decision.ts
231002
231013
  /**
231003
231014
  * Hysteresis is ASYMMETRIC, because the two directions have very different
@@ -231073,16 +231084,6 @@ function decideSleepCommit(input) {
231073
231084
  stampFirstHand: source !== "hub-reconcile"
231074
231085
  };
231075
231086
  }
231076
- /**
231077
- * A firmware `sleeping` push is ignored while a consumer (the recorder,
231078
- * a live view) holds an RFC 4571 server on the camera. Teardown on that
231079
- * push is what cut a recorded battery camera into 40–110 s gaps: the
231080
- * broker only re-dialled ~20 s after we closed the stream. With no
231081
- * consumer the push is acted on exactly as before.
231082
- */
231083
- function shouldIgnoreSleepPush(input) {
231084
- return input.activeStreams > 0;
231085
- }
231086
231087
  //#endregion
231087
231088
  //#region src/snapshot-wake-gate.ts
231088
231089
  /**
@@ -233635,6 +233636,160 @@ function buildSupportedNativeClasses(aiDetectTypes, isSupportedClass) {
233635
233636
  }
233636
233637
  return classes;
233637
233638
  }
233639
+ var PowerSourceModeSchema = _enum(["adapter", "battery"]);
233640
+ /** What a read says: a mode, or `unknown` when the read failed or the firmware is silent. */
233641
+ var PowerSourceReadingSchema = _enum([
233642
+ "adapter",
233643
+ "battery",
233644
+ "unknown"
233645
+ ]);
233646
+ var ReadPowerSourceResultSchema = object({ source: PowerSourceReadingSchema });
233647
+ /** The device (or this code) declined before any real write was sent. */
233648
+ var PowerSourceRefusalReasonSchema = _enum(["dry-run-refused", "dry-run-failed"]);
233649
+ var SwitchPowerSourceResultSchema = discriminatedUnion("outcome", [
233650
+ object({
233651
+ outcome: literal("refused"),
233652
+ mode: PowerSourceModeSchema,
233653
+ reason: PowerSourceRefusalReasonSchema,
233654
+ before: PowerSourceReadingSchema
233655
+ }),
233656
+ object({
233657
+ outcome: literal("sent"),
233658
+ mode: PowerSourceModeSchema,
233659
+ /** The firmware accepted the command. NOT proof it took effect. */
233660
+ accepted: boolean(),
233661
+ before: PowerSourceReadingSchema,
233662
+ after: PowerSourceReadingSchema,
233663
+ /** True only when the read-back after the write equals the requested mode. */
233664
+ applied: boolean()
233665
+ }),
233666
+ object({
233667
+ outcome: literal("failed"),
233668
+ mode: PowerSourceModeSchema,
233669
+ /** The real write threw. It was sent once and is not retried. */
233670
+ error: string(),
233671
+ before: PowerSourceReadingSchema
233672
+ })
233673
+ ]);
233674
+ function errorMessage(error) {
233675
+ return error instanceof Error ? error.message : String(error);
233676
+ }
233677
+ /** Read the power source; a failed or silent read is `unknown`. */
233678
+ async function readPowerSource(target) {
233679
+ const { api, channel, deviceId, logger } = target;
233680
+ try {
233681
+ const mode = await api.getPowerSource(channel);
233682
+ if (mode === void 0) {
233683
+ logger.info("power source: the firmware does not report it", {
233684
+ tags: { deviceId },
233685
+ meta: { channel }
233686
+ });
233687
+ return "unknown";
233688
+ }
233689
+ return mode;
233690
+ } catch (error) {
233691
+ logger.warn("power source: read failed, reporting unknown", {
233692
+ tags: { deviceId },
233693
+ meta: {
233694
+ channel,
233695
+ error: errorMessage(error)
233696
+ }
233697
+ });
233698
+ return "unknown";
233699
+ }
233700
+ }
233701
+ /**
233702
+ * Switch the power source: read, dry run, one real write, read back.
233703
+ * The write is sent at most once and never retried.
233704
+ */
233705
+ async function switchPowerSourceTo(target, mode) {
233706
+ const { api, channel, deviceId, logger } = target;
233707
+ const before = await readPowerSource(target);
233708
+ logger.info("power source: switch requested", {
233709
+ tags: { deviceId },
233710
+ meta: {
233711
+ mode,
233712
+ before,
233713
+ channel
233714
+ }
233715
+ });
233716
+ let supported;
233717
+ try {
233718
+ supported = await api.probePowerSourceSwitchSupport(mode, { channel });
233719
+ } catch (error) {
233720
+ logger.warn("power source: dry run failed, no switch sent", {
233721
+ tags: { deviceId },
233722
+ meta: {
233723
+ mode,
233724
+ error: errorMessage(error)
233725
+ }
233726
+ });
233727
+ return {
233728
+ outcome: "refused",
233729
+ mode,
233730
+ reason: "dry-run-failed",
233731
+ before
233732
+ };
233733
+ }
233734
+ if (!supported) {
233735
+ logger.warn("power source: the device refused the dry run, no switch sent", {
233736
+ tags: { deviceId },
233737
+ meta: {
233738
+ mode,
233739
+ before
233740
+ }
233741
+ });
233742
+ return {
233743
+ outcome: "refused",
233744
+ mode,
233745
+ reason: "dry-run-refused",
233746
+ before
233747
+ };
233748
+ }
233749
+ let result;
233750
+ try {
233751
+ result = await api.switchPowerSource(mode, { channel });
233752
+ } catch (error) {
233753
+ logger.error("power source: the switch threw; it is not retried", {
233754
+ tags: { deviceId },
233755
+ meta: {
233756
+ mode,
233757
+ error: errorMessage(error)
233758
+ }
233759
+ });
233760
+ return {
233761
+ outcome: "failed",
233762
+ mode,
233763
+ error: errorMessage(error),
233764
+ before
233765
+ };
233766
+ }
233767
+ const after = await readPowerSource(target);
233768
+ const applied = result.accepted && after === mode;
233769
+ const meta = {
233770
+ mode,
233771
+ before,
233772
+ after,
233773
+ accepted: result.accepted,
233774
+ rspCode: result.rspCode
233775
+ };
233776
+ if (applied) logger.info("power source: switched", {
233777
+ tags: { deviceId },
233778
+ meta
233779
+ });
233780
+ else logger.warn("power source: the switch was sent but the read-back does not show it", {
233781
+ tags: { deviceId },
233782
+ meta
233783
+ });
233784
+ return {
233785
+ outcome: "sent",
233786
+ mode,
233787
+ accepted: result.accepted,
233788
+ before,
233789
+ after,
233790
+ applied
233791
+ };
233792
+ }
233638
233793
  //#endregion
233639
233794
  //#region src/ptz-zoom.ts
233640
233795
  /**
@@ -234624,6 +234779,8 @@ var RefreshSettingsResultSchema = object({
234624
234779
  capsWarmed: number$1(),
234625
234780
  capsTotal: number$1()
234626
234781
  });
234782
+ /** The two switch actions, one implementation each way. */
234783
+ var POWER_SWITCH_ACTIONS = [["switch-to-wired-power", "adapter"], ["switch-to-battery-power", "battery"]];
234627
234784
  /** The uid out of a device's metadata bag, or nothing. Never a cast. */
234628
234785
  function metaUid(metadata) {
234629
234786
  if (metadata === null) return void 0;
@@ -234796,8 +234953,6 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
234796
234953
  * `sleep-state-decision.ts` for the measurement (D603).
234797
234954
  */
234798
234955
  sleepStateChangedAt = 0;
234799
- /** True once the 'sleep push ignored' line was logged for the current consumer-attached stretch. */
234800
- sleepPushIgnoreLogged = false;
234801
234956
  /**
234802
234957
  * Wall-clock ms of the last PROACTIVE wake — one we issued on our own
234803
234958
  * initiative (background snapshot refresh), not because the operator
@@ -236011,6 +236166,16 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
236011
236166
  capsTotal
236012
236167
  };
236013
236168
  });
236169
+ if (this.isBattery) {
236170
+ this.registerDeviceAction("read-power-source", deviceCustomAction(unknown(), ReadPowerSourceResultSchema, { kind: "mutation" }), async () => {
236171
+ await this.wakeIfSleeping();
236172
+ return { source: await readPowerSource(await this.powerSourceTarget()) };
236173
+ });
236174
+ for (const [action, mode] of POWER_SWITCH_ACTIONS) this.registerDeviceAction(action, deviceCustomAction(unknown(), SwitchPowerSourceResultSchema, { kind: "mutation" }), async () => {
236175
+ await this.wakeIfSleeping();
236176
+ return switchPowerSourceTo(await this.powerSourceTarget(), mode);
236177
+ });
236178
+ }
236014
236179
  this.registerDeviceAction("refresh-sessions", deviceCustomAction(unknown(), _void(), { kind: "mutation" }), async () => {
236015
236180
  await this.refreshSessionsSnapshot();
236016
236181
  });
@@ -236550,6 +236715,65 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
236550
236715
  autoRefreshes: !this.isBattery
236551
236716
  });
236552
236717
  }
236718
+ /** The hub API for a child, the camera's own otherwise, plus the channel to address. */
236719
+ async powerSourceTarget() {
236720
+ return {
236721
+ api: await this.ensureApi(),
236722
+ channel: this.getChannel(),
236723
+ deviceId: this.id,
236724
+ logger: this.ctx.logger
236725
+ };
236726
+ }
236727
+ /**
236728
+ * Battery-cam power-source section (General tab): read the source, switch to
236729
+ * wired or back to battery. Returns `[]` for a wired-only camera. The buttons
236730
+ * dispatch the `read-power-source` / `switch-to-*-power` device actions.
236731
+ */
236732
+ buildPowerSourceSection() {
236733
+ if (!this.isBattery) return [];
236734
+ const switchMessage = "Switch {outcome} · before: {before} · after: {after} · applied: {applied}";
236735
+ return [{
236736
+ id: "power-source",
236737
+ tab: "general",
236738
+ title: "Power source",
236739
+ titleKey: "provider-reolink:schema.s_power-source.title",
236740
+ description: "Only switch to wired power when the adapter meets the camera's spec.",
236741
+ descriptionKey: "provider-reolink:schema.s_power-source.description",
236742
+ columns: 1,
236743
+ fields: [
236744
+ {
236745
+ type: "device-action-button",
236746
+ key: "_readPowerSource",
236747
+ label: "Power source",
236748
+ labelKey: "provider-reolink:schema.s_power-source._readPowerSource.label",
236749
+ buttonLabel: "Read power source",
236750
+ action: "read-power-source",
236751
+ variant: "default",
236752
+ successMessage: "Power source: {source}"
236753
+ },
236754
+ {
236755
+ type: "device-action-button",
236756
+ key: "_switchToWiredPower",
236757
+ label: "Wired power",
236758
+ labelKey: "provider-reolink:schema.s_power-source._switchToWiredPower.label",
236759
+ buttonLabel: "Switch to wired power",
236760
+ action: "switch-to-wired-power",
236761
+ variant: "default",
236762
+ successMessage: switchMessage
236763
+ },
236764
+ {
236765
+ type: "device-action-button",
236766
+ key: "_switchToBatteryPower",
236767
+ label: "Battery power",
236768
+ labelKey: "provider-reolink:schema.s_power-source._switchToBatteryPower.label",
236769
+ buttonLabel: "Switch to battery power",
236770
+ action: "switch-to-battery-power",
236771
+ variant: "default",
236772
+ successMessage: switchMessage
236773
+ }
236774
+ ]
236775
+ }];
236776
+ }
236553
236777
  /**
236554
236778
  * Battery-cam Email Push auto-configure section. Returns `[]` for any
236555
236779
  * camera that wouldn't benefit (wired cams keep a live socket for
@@ -241462,6 +241686,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
241462
241686
  }),
241463
241687
  ...this.buildSessionsTabSections(),
241464
241688
  ...this.buildEmailPushSection(),
241689
+ ...this.buildPowerSourceSection(),
241465
241690
  ...this.buildEmailTabSections(),
241466
241691
  ...buildClipRefreshDeviceSection({
241467
241692
  isHubChild: this.isHubChild(),
@@ -242317,17 +242542,6 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
242317
242542
  return;
242318
242543
  }
242319
242544
  if (event.type === "sleeping") {
242320
- if (this.isBattery && shouldIgnoreSleepPush({ activeStreams: this.active.size })) {
242321
- if (!this.sleepPushIgnoreLogged) {
242322
- this.sleepPushIgnoreLogged = true;
242323
- this.ctx.logger.info(`sleep push ignored: ${this.active.size} active stream consumer(s)`, {
242324
- tags: { deviceId: this.id },
242325
- meta: { activeStreams: this.active.size }
242326
- });
242327
- }
242328
- return;
242329
- }
242330
- this.sleepPushIgnoreLogged = false;
242331
242545
  const wasSleeping = this.sleeping;
242332
242546
  if (!this.commitSleepState(true, "simple-event")) return;
242333
242547
  if (!wasSleeping) this.ctx.eventBus.emit(createEvent(EventCategory.DeviceSleeping, eventSource, {
package/i18n/en.json CHANGED
@@ -208,5 +208,20 @@
208
208
  "schema.s_hub.title": "Hub",
209
209
  "schema.s_hub.description": "This camera is connected through its NVR / Home Hub. Address and credentials belong to that integration; the channel is kept in line with the hub automatically.",
210
210
  "schema.s_hub.hubName.label": "Connected to",
211
- "schema.s_hub.channel.label": "Hub channel"
211
+ "schema.s_hub.channel.label": "Hub channel",
212
+ "schema": {
213
+ "s_power-source": {
214
+ "title": "Power source",
215
+ "description": "Only switch to wired power when the adapter meets the camera's spec.",
216
+ "_readPowerSource": {
217
+ "label": "Power source"
218
+ },
219
+ "_switchToWiredPower": {
220
+ "label": "Wired power"
221
+ },
222
+ "_switchToBatteryPower": {
223
+ "label": "Battery power"
224
+ }
225
+ }
226
+ }
212
227
  }