@camstack/addon-provider-reolink 1.2.226 → 1.2.228

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,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.228] - 2026-11-05
11
+
12
+ ### Fixed
13
+
14
+ - A deleted camera stops its timers at once instead of polling until the worker restarts
15
+
16
+ ## [1.2.227] - 2026-11-05
17
+
18
+ ### Changed
19
+
20
+ - Reolink clip catalog refresh default is declared on the fleet-default hook; the form and stored value are unchanged.
21
+ - A camera adopted under an NVR / Home Hub now shows its hub and channel in settings, no longer lets you edit its address or credentials (they belong to the integration), and hides the hub-wide ports and time sections.
22
+
10
23
  ## [1.2.226] - 2026-11-05
11
24
 
12
25
  ### Changed
package/dist/addon.js CHANGED
@@ -106677,7 +106677,7 @@ var ZodIssueCode = {
106677
106677
  var ZodFirstPartyTypeKind;
106678
106678
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
106679
106679
  //#endregion
106680
- //#region ../types/dist/sleep-9TIHFj1w.mjs
106680
+ //#region ../types/dist/sleep-DEZaLbiu.mjs
106681
106681
  /**
106682
106682
  * The audio chunk plane's byte format, and the ONE expansion from a coded
106683
106683
  * window to float samples (D455).
@@ -107486,6 +107486,12 @@ function projectStore(store, perNodeKeys, nodeId) {
107486
107486
  }
107487
107487
  return out;
107488
107488
  }
107489
+ /** Every scope, in the order the guard and the docs list them. */
107490
+ var SCOPED_SETTINGS_SCOPES = [
107491
+ "cluster",
107492
+ "device-defaults",
107493
+ "node"
107494
+ ];
107489
107495
  /**
107490
107496
  * The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
107491
107497
  *
@@ -108377,6 +108383,13 @@ var BaseAddon = class {
108377
108383
  */
108378
108384
  secretStatePaths = [];
108379
108385
  _addonSecretTree = null;
108386
+ /**
108387
+ * D986 M4: the scoped schemas this addon declared, resolved once per capability
108388
+ * (`loadScopedSchemas`) so the sync readers (`perNodeKeys`, the secret tree, the restart check)
108389
+ * see them. Empty until loaded: the readers then fall back to {@link globalSettingsSchema}.
108390
+ */
108391
+ _scopedByCap = /* @__PURE__ */ new Map();
108392
+ _nodeKeysByCap = /* @__PURE__ */ new Map();
108380
108393
  _deviceSecretTree = null;
108381
108394
  /** Refs the last resolved config pointed at — a change to one re-resolves. */
108382
108395
  _configSecretRefs = /* @__PURE__ */ new Set();
@@ -108446,6 +108459,7 @@ var BaseAddon = class {
108446
108459
  this._ctx = context;
108447
108460
  this._secretSettings = null;
108448
108461
  }
108462
+ await this.loadScopedSchemas();
108449
108463
  await this.resolveConfig();
108450
108464
  if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
108451
108465
  if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
@@ -108455,6 +108469,7 @@ var BaseAddon = class {
108455
108469
  const normalized = normalizeAddonInitResult(result);
108456
108470
  const providers = normalized && "providers" in normalized && normalized.providers ? normalized.providers : [];
108457
108471
  this._registeredCapNames = providers.map((p) => p.capability.name);
108472
+ await this.loadScopedSchemas();
108458
108473
  return normalized;
108459
108474
  }
108460
108475
  /**
@@ -108543,6 +108558,16 @@ var BaseAddon = class {
108543
108558
  schema(schema) {
108544
108559
  return schema;
108545
108560
  }
108561
+ /**
108562
+ * The capability names whose scoped settings schemas ({@link clusterSettingsSchema},
108563
+ * {@link nodeSettingsSchema}, {@link deviceDefaultsSchema}) this addon declares. Read BEFORE
108564
+ * `onInitialize`, when the providers it registers are not known yet: the first config resolve
108565
+ * must already know which keys are per node. Names the providers register at init are added
108566
+ * once known.
108567
+ */
108568
+ scopedSettingsCapabilities() {
108569
+ return [];
108570
+ }
108546
108571
  /** Override to provide global-level settings UI schema. */
108547
108572
  globalSettingsSchema(_cap) {
108548
108573
  return null;
@@ -108586,7 +108611,8 @@ var BaseAddon = class {
108586
108611
  return [];
108587
108612
  }
108588
108613
  async getGlobalSettings(overlay, cap, nodeId) {
108589
- const schema = this.globalSettingsSchema(cap);
108614
+ await this.loadScopedSchemas(cap);
108615
+ const schema = this.globalSettingsSchema(cap) ?? this.scopedFormSchema(cap);
108590
108616
  if (!schema) return { sections: [] };
108591
108617
  const projected = await this.readRawProjectedStore(nodeId, cap);
108592
108618
  return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(projected, overlay) : projected, { inlineSecretsAsViews: true });
@@ -108717,6 +108743,7 @@ var BaseAddon = class {
108717
108743
  * resolved blob back is a no-op for every unchanged secret.
108718
108744
  */
108719
108745
  async resolveGlobalStore(nodeId, cap) {
108746
+ await this.loadScopedSchemas(cap);
108720
108747
  const raw = await this._ctx?.settings?.readAddonStore() ?? {};
108721
108748
  return this.projectForNode(raw, nodeId, cap);
108722
108749
  }
@@ -108727,6 +108754,7 @@ var BaseAddon = class {
108727
108754
  }
108728
108755
  /** The PROJECTED store with its markers — the form hydrate only (D798). */
108729
108756
  async readRawProjectedStore(nodeId, cap) {
108757
+ await this.loadScopedSchemas(cap);
108730
108758
  const raw = await this.rawSettings()?.readAddonStore() ?? {};
108731
108759
  return this.projectForNode(raw, nodeId, cap);
108732
108760
  }
@@ -108829,6 +108857,7 @@ var BaseAddon = class {
108829
108857
  await this.applyGlobalPatch(patch, nodeId);
108830
108858
  }
108831
108859
  async applyGlobalPatch(barePatch, nodeId) {
108860
+ await this.loadScopedSchemas();
108832
108861
  const keys = this.perNodeKeys();
108833
108862
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
108834
108863
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
@@ -108842,7 +108871,8 @@ var BaseAddon = class {
108842
108871
  await this.resolveConfig();
108843
108872
  await this.onConfigChanged();
108844
108873
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
108845
- this.maybeAutoRestart(Object.keys(barePatch), this.globalSettingsSchema());
108874
+ const legacy = this.globalSettingsSchema();
108875
+ this.maybeAutoRestart(Object.keys(barePatch), [...legacy === null ? [] : [legacy], ...this.loadedScopedSchemas().map((entry) => entry.schema)]);
108846
108876
  }
108847
108877
  /**
108848
108878
  * The set of field keys the global settings schema declares `perNode: true`
@@ -108850,14 +108880,67 @@ var BaseAddon = class {
108850
108880
  * declarations). Empty set ⇒ every per-node code path is bypassed and the
108851
108881
  * settings API behaves exactly like the legacy node-agnostic one.
108852
108882
  */
108853
- _perNodeKeysCache = /* @__PURE__ */ new Map();
108883
+ /**
108884
+ * Load the scoped schemas of every capability this addon declares (the override and the
108885
+ * providers registered at init, plus `extraCap`) that is not loaded yet, then drop what was
108886
+ * derived from the previous set. Idempotent.
108887
+ */
108888
+ async loadScopedSchemas(extraCap) {
108889
+ const caps = new Set([
108890
+ ...this.scopedSettingsCapabilities(),
108891
+ ...this._registeredCapNames,
108892
+ ...extraCap === void 0 ? [] : [extraCap]
108893
+ ]);
108894
+ let added = false;
108895
+ for (const cap of caps) {
108896
+ if (this._scopedByCap.has(cap)) continue;
108897
+ const loaded = [];
108898
+ for (const scope of SCOPED_SETTINGS_SCOPES) {
108899
+ const schema = await this.getScopedSettingsSchema(scope, cap);
108900
+ if (schema !== null) loaded.push({
108901
+ scope,
108902
+ schema
108903
+ });
108904
+ }
108905
+ this._scopedByCap.set(cap, loaded);
108906
+ added = true;
108907
+ }
108908
+ if (!added) return;
108909
+ this._nodeKeysByCap = /* @__PURE__ */ new Map();
108910
+ this._addonSecretTree = null;
108911
+ }
108912
+ /**
108913
+ * The form the settings API serves while an addon declares no {@link globalSettingsSchema}: the
108914
+ * sections of its scoped schemas, so dropping the old hook does not blank the form.
108915
+ */
108916
+ scopedFormSchema(cap) {
108917
+ const byId = /* @__PURE__ */ new Map();
108918
+ for (const entry of this.loadedScopedSchemas(cap)) for (const section of entry.schema.sections) if (!byId.has(section.id)) byId.set(section.id, section);
108919
+ return byId.size === 0 ? null : { sections: [...byId.values()] };
108920
+ }
108921
+ /** Every loaded scoped schema of `cap`, or of every loaded capability. */
108922
+ loadedScopedSchemas(cap) {
108923
+ if (cap !== void 0) return this._scopedByCap.get(cap) ?? [];
108924
+ return [...this._scopedByCap.values()].flat();
108925
+ }
108926
+ /**
108927
+ * The field keys that are stored per node: every field of a {@link nodeSettingsSchema}, plus
108928
+ * the fields the legacy {@link globalSettingsSchema} still marks `perNode: true`. Derived once
108929
+ * per `cap` argument and memoized (schemas are static declarations). Empty set ⇒ every
108930
+ * per-node code path is bypassed and the settings API behaves like the node-agnostic one.
108931
+ * Call {@link loadScopedSchemas} first (the async seams do).
108932
+ */
108854
108933
  perNodeKeys(cap) {
108855
108934
  const cacheKey = cap ?? "";
108856
- const cached = this._perNodeKeysCache.get(cacheKey);
108935
+ const cached = this._nodeKeysByCap.get(cacheKey);
108857
108936
  if (cached) return cached;
108858
- const schema = this.globalSettingsSchema(cap);
108859
- const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
108860
- this._perNodeKeysCache.set(cacheKey, keys);
108937
+ const legacy = this.globalSettingsSchema(cap);
108938
+ const keys = new Set(legacy ? legacy.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
108939
+ for (const { scope, schema } of this.loadedScopedSchemas(cap)) {
108940
+ if (scope !== "node") continue;
108941
+ for (const section of schema.sections) for (const key of collectValueFieldKeys(section.fields)) keys.add(key);
108942
+ }
108943
+ this._nodeKeysByCap.set(cacheKey, keys);
108861
108944
  return keys;
108862
108945
  }
108863
108946
  /**
@@ -108867,10 +108950,9 @@ var BaseAddon = class {
108867
108950
  * time to return its response before the addon is torn down and
108868
108951
  * re-initialised by `AddonRegistryService.restartAddon`.
108869
108952
  */
108870
- maybeAutoRestart(patchKeys, schema) {
108871
- if (!schema) return;
108953
+ maybeAutoRestart(patchKeys, schemas) {
108872
108954
  const restartKeys = /* @__PURE__ */ new Set();
108873
- for (const section of schema.sections) for (const field of section.fields) {
108955
+ for (const schema of schemas) for (const section of schema.sections) for (const field of section.fields) {
108874
108956
  if (field.type === "separator" || field.type === "info") continue;
108875
108957
  if (field.requiresRestart) restartKeys.add(field.key);
108876
108958
  }
@@ -109066,12 +109148,14 @@ var BaseAddon = class {
109066
109148
  * here, in the addon's own process, so the hub keeps no copy of it.
109067
109149
  */
109068
109150
  async getDeclaredSettingsKeys() {
109151
+ await this.loadScopedSchemas();
109069
109152
  return { keys: [...this.declaredKeySet()].toSorted() };
109070
109153
  }
109071
109154
  declaredKeySet() {
109072
109155
  const keys = new Set(Object.keys(this.defaults));
109073
109156
  const schema = this.globalSettingsSchema();
109074
109157
  if (schema) for (const section of schema.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
109158
+ for (const { schema: scoped } of this.loadedScopedSchemas()) for (const section of scoped.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
109075
109159
  for (const key of this._declaredStateKeys) keys.add(key);
109076
109160
  for (const path of this.secretStatePaths) {
109077
109161
  const root = path.split(/[.[]/, 1)[0];
@@ -109167,7 +109251,11 @@ var BaseAddon = class {
109167
109251
  }
109168
109252
  /** The addon store's secret tree: schema fields by TYPE, plus `secretStatePaths`. */
109169
109253
  addonSecretTree() {
109170
- this._addonSecretTree ??= mergeSecretStatePaths(secretTreeFromSchema(this.globalSettingsSchema()), this.secretStatePaths);
109254
+ if (this._addonSecretTree === null) {
109255
+ const tree = new Map(secretTreeFromSchema(this.globalSettingsSchema()));
109256
+ for (const { schema } of this.loadedScopedSchemas()) for (const [key, node] of secretTreeFromSchema(schema)) tree.set(key, node);
109257
+ this._addonSecretTree = mergeSecretStatePaths(tree, this.secretStatePaths);
109258
+ }
109171
109259
  return this._addonSecretTree;
109172
109260
  }
109173
109261
  deviceSecretTree() {
@@ -109417,6 +109505,23 @@ function dropPerNodeFields(fields) {
109417
109505
  }
109418
109506
  return kept;
109419
109507
  }
109508
+ /** The keys of the value-holding fields, recursing into layout containers. */
109509
+ function collectValueFieldKeys(fields) {
109510
+ const collected = [];
109511
+ for (const field of fields) {
109512
+ if (field.type === "group") {
109513
+ collected.push(...collectValueFieldKeys(field.fields));
109514
+ continue;
109515
+ }
109516
+ if (field.type === "sub-tabs") {
109517
+ for (const tab of field.tabs) collected.push(...collectValueFieldKeys(tab.fields));
109518
+ continue;
109519
+ }
109520
+ if (field.type === "separator" || field.type === "info") continue;
109521
+ if ("key" in field && typeof field.key === "string") collected.push(field.key);
109522
+ }
109523
+ return collected;
109524
+ }
109420
109525
  function collectFieldKeys(fields) {
109421
109526
  const collected = [];
109422
109527
  for (const field of fields) {
@@ -208980,6 +209085,114 @@ async function connectReolinkHub(connection) {
208980
209085
  return api;
208981
209086
  }
208982
209087
  //#endregion
209088
+ //#region src/hub-child-settings.ts
209089
+ /**
209090
+ * A camera adopted under an NVR / Home Hub dials through the integration's session: the address
209091
+ * and the credentials belong to the integration, never to the camera. These are the per-camera
209092
+ * keys a hub child must refuse to change.
209093
+ */
209094
+ var HUB_CHILD_CONNECTION_KEYS = [
209095
+ "host",
209096
+ "port",
209097
+ "username",
209098
+ "password"
209099
+ ];
209100
+ /**
209101
+ * Sections that act on the hub itself (no channel in the call) or on the per-camera connection,
209102
+ * hidden for a hub child:
209103
+ * - `connection`: the per-camera address and credentials (the integration owns them);
209104
+ * - `network-ports`: `setPortConfig` rewrites the NVR's own service ports;
209105
+ * - `time-ntp`: `setNtp` / `setSystemGeneral` / `setDst` rewrite the NVR's clock.
209106
+ */
209107
+ var HUB_CHILD_HIDDEN_SECTION_IDS = [
209108
+ "connection",
209109
+ "network-ports",
209110
+ "time-ntp"
209111
+ ];
209112
+ /** Thrown by `applySettingsPatch` for a refused hub-child patch; carries the typed reason. */
209113
+ var HubChildPatchRefusedError = class extends Error {
209114
+ refusal;
209115
+ constructor(refusal) {
209116
+ super(describeRefusal(refusal));
209117
+ this.refusal = refusal;
209118
+ this.name = "HubChildPatchRefusedError";
209119
+ }
209120
+ };
209121
+ function describeRefusal(refusal) {
209122
+ switch (refusal.reason) {
209123
+ 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`;
209124
+ case "channel-not-an-integer": return `The hub channel must be a whole number, got ${String(refusal.value)}`;
209125
+ case "channel-out-of-range": return `Channel ${refusal.value} is not one of the hub's channels (${refusal.channels.join(", ")})`;
209126
+ }
209127
+ }
209128
+ /**
209129
+ * Judge a settings patch against the hub-child rules. `channels` is the hub's last good channel
209130
+ * list (empty when unknown — then only the integer rule applies).
209131
+ */
209132
+ function judgeHubChildPatch(patch, channels) {
209133
+ const touched = HUB_CHILD_CONNECTION_KEYS.filter((k) => patch[k] !== void 0);
209134
+ if (touched.length > 0) return {
209135
+ reason: "connection-owned-by-integration",
209136
+ keys: touched
209137
+ };
209138
+ if (patch["channel"] === void 0) return null;
209139
+ const value = patch["channel"];
209140
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) return {
209141
+ reason: "channel-not-an-integer",
209142
+ value
209143
+ };
209144
+ if (channels.length > 0 && !channels.includes(value)) return {
209145
+ reason: "channel-out-of-range",
209146
+ value,
209147
+ channels
209148
+ };
209149
+ return null;
209150
+ }
209151
+ /** What a hub child shows before its session has read the hub's channel list. */
209152
+ var EMPTY_HUB_CHANNEL_SNAPSHOT = {
209153
+ channels: [],
209154
+ lastRefreshAt: null,
209155
+ lastError: null
209156
+ };
209157
+ /** The hub-child "Hub" section: which hub, and the one editable connection field, the channel. */
209158
+ function buildHubChildSection(snapshot) {
209159
+ return {
209160
+ id: "hub",
209161
+ tab: "general",
209162
+ title: "Hub",
209163
+ titleKey: "provider-reolink:schema.s_hub.title",
209164
+ 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.",
209165
+ descriptionKey: "provider-reolink:schema.s_hub.description",
209166
+ columns: 2,
209167
+ fields: [{
209168
+ type: "text",
209169
+ key: "hubName",
209170
+ label: "Connected to",
209171
+ labelKey: "provider-reolink:schema.s_hub.hubName.label",
209172
+ disabled: true
209173
+ }, {
209174
+ type: "number",
209175
+ key: "channel",
209176
+ label: "Hub channel",
209177
+ labelKey: "provider-reolink:schema.s_hub.channel.label",
209178
+ min: 0,
209179
+ ...snapshot.channels.length > 0 ? { max: Math.max(...snapshot.channels.map((c) => c.channel)) } : {},
209180
+ step: 1
209181
+ }]
209182
+ };
209183
+ }
209184
+ /** Replace the connection/hub-acting sections of a standalone schema with the Hub section. */
209185
+ function applyHubChildSections(sections, snapshot) {
209186
+ const kept = sections.filter((s) => !HUB_CHILD_HIDDEN_SECTION_IDS.includes(s.id));
209187
+ const at = kept.findIndex((s) => s.id === "driver-refresh");
209188
+ const hub = buildHubChildSection(snapshot);
209189
+ return at < 0 ? [hub, ...kept] : [
209190
+ ...kept.slice(0, at + 1),
209191
+ hub,
209192
+ ...kept.slice(at + 1)
209193
+ ];
209194
+ }
209195
+ //#endregion
208983
209196
  //#region src/sleep-state-decision.ts
208984
209197
  /**
208985
209198
  * Hysteresis is ASYMMETRIC, because the two directions have very different
@@ -212572,6 +212785,8 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
212572
212785
  * Mirrors the reference's `batteryUpdateTimer`: fires every hour,
212573
212786
  * passively checks sleep state, and short-circuits if sleeping. */
212574
212787
  batteryUpdateTimer = null;
212788
+ /** Set by `removeDevice`: nothing may re-arm a timer on a removed camera. */
212789
+ removed = false;
212575
212790
  /** Single-flight gate so two interval fires can't overlap. */
212576
212791
  /** Aux accessory references registered by spawned children
212577
212792
  * (siren / floodlight / pir). The parent's centralised align
@@ -212687,6 +212902,18 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
212687
212902
  isHubChild() {
212688
212903
  return this.hubIntegrationId() !== null && typeof this.config.get("channel") === "number";
212689
212904
  }
212905
+ /**
212906
+ * The host this camera is reached at: the integration's for a hub child (the stored per-camera
212907
+ * `host` of a child is never read), the camera's own otherwise. `null` when there is none.
212908
+ */
212909
+ connectionHost() {
212910
+ if (this.isHubChild()) {
212911
+ const host = this.hubSession()?.relayEndpoint().host;
212912
+ return host !== void 0 && host.length > 0 ? host : null;
212913
+ }
212914
+ const host = this.config.get("host");
212915
+ return typeof host === "string" && host.length > 0 ? host : null;
212916
+ }
212690
212917
  /** The integration (one NVR / Home Hub, D985) this camera was adopted from, or `null`. */
212691
212918
  hubIntegrationId() {
212692
212919
  const id = this.config.get("integrationId");
@@ -213322,7 +213549,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
213322
213549
  isBattery: this.isBattery,
213323
213550
  sleeping: this.sleeping,
213324
213551
  timeZone: resolveClipTimeZoneOnce(Intl.DateTimeFormat().resolvedOptions().timeZone, reolinkTimeZoneToIana(this.config.get("deviceCache")?.systemGeneralSnapshot?.timeZone), this.ctx.logger, this.id, this.clipTimeZoneWarned),
213325
- hostKey: String(this.config.get("host") ?? `device-${this.id}`),
213552
+ hostKey: this.connectionHost() ?? `device-${this.id}`,
213326
213553
  getApi: () => this.ensureApi()
213327
213554
  };
213328
213555
  }
@@ -213655,7 +213882,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
213655
213882
  } });
213656
213883
  this.ctx.registerNativeCap(deviceAdminLinkCapability, { getAdminLink: async ({ deviceId }) => {
213657
213884
  if (deviceId !== this.id) throw new Error(`ReolinkCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
213658
- const host = this.config.get("host") ?? "";
213885
+ const host = this.connectionHost() ?? "";
213659
213886
  const built = buildDeviceAdminUrl({
213660
213887
  host,
213661
213888
  port: null,
@@ -217008,6 +217235,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
217008
217235
  * FLV publication for those devices rather than emitting a broken URL.
217009
217236
  */
217010
217237
  buildFlvUrl(channel, profile) {
217238
+ if (this.isHubChild()) return null;
217011
217239
  const host = this.config.get("host");
217012
217240
  if (typeof host !== "string" || host.length === 0) return null;
217013
217241
  return `http://${host}/flv?port=1935&app=bcs&stream=channel${channel}_${profile}.bcs&user=${encodeURIComponent(String(this.config.get("username") ?? ""))}&password=${encodeURIComponent(String(this.config.get("password") ?? ""))}`;
@@ -217358,6 +217586,11 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
217358
217586
  });
217359
217587
  }
217360
217588
  async removeDevice() {
217589
+ this.removed = true;
217590
+ this.stopSleepPoll();
217591
+ this.stopBatteryUpdatePolling();
217592
+ this.stopAlignAuxPolling();
217593
+ this.stopWatchdogs();
217361
217594
  this.detachFromHubSession();
217362
217595
  if (this.reconnectTimer) {
217363
217596
  clearTimeout(this.reconnectTimer);
@@ -217527,6 +217760,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
217527
217760
  * `sleeping`/`awake` transition (firmware quirks, NAT timeouts).
217528
217761
  */
217529
217762
  startSleepPoll() {
217763
+ if (this.removed) return;
217530
217764
  if (this.sleepPollTimer) return;
217531
217765
  if (!this.isBattery) return;
217532
217766
  if (this.isHubChild()) return;
@@ -217666,6 +217900,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
217666
217900
  /** Start periodic align for wired cams. No-op for battery cams (wake
217667
217901
  * path handles it). Idempotent. */
217668
217902
  startAlignAuxPolling() {
217903
+ if (this.removed) return;
217669
217904
  if (this.alignAuxTimer) return;
217670
217905
  if (this.isBattery) return;
217671
217906
  const POLL_MS = 1e4;
@@ -217746,6 +217981,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
217746
217981
  /** Arm the scheduled-refresh check. No-op for wired cams (their state is
217747
217982
  * kept fresh by the 10 s aux-align poll and push events). Idempotent. */
217748
217983
  startBatteryUpdatePolling() {
217984
+ if (this.removed) return;
217749
217985
  if (this.batteryUpdateTimer) return;
217750
217986
  if (!this.isBattery) return;
217751
217987
  this.batteryUpdateTimer = setInterval(() => {
@@ -217875,6 +218111,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
217875
218111
  * with parallel watchdogs after a reconnect cycle.
217876
218112
  */
217877
218113
  startWatchdogs() {
218114
+ if (this.removed) return;
217878
218115
  this.stopWatchdogs();
217879
218116
  this.watchdogStartedAt = Date.now();
217880
218117
  this.consecutivePingFailures = 0;
@@ -218139,6 +218376,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
218139
218376
  * re-subscribes the moment the socket comes back up.
218140
218377
  */
218141
218378
  startEventHealthCheck() {
218379
+ if (this.removed) return;
218142
218380
  this.stopEventHealthCheck();
218143
218381
  this.consecutiveStaleHealthChecks = 0;
218144
218382
  this.nextEventHealthCheckAt = 0;
@@ -219138,12 +219376,23 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
219138
219376
  ...buildBatteryRefreshDeviceSection({ isBattery: this.isBattery })
219139
219377
  ]
219140
219378
  };
219379
+ const hubChild = this.isHubChild();
219380
+ const hubSession = this.hubSession();
219381
+ const shownSchema = hubChild ? {
219382
+ ...schema,
219383
+ sections: applyHubChildSections(schema.sections, hubSession?.channelSnapshot() ?? EMPTY_HUB_CHANNEL_SNAPSHOT)
219384
+ } : schema;
219141
219385
  const emailSnap = cache?.emailConfigSnapshot;
219142
- return hydrateSchema(schema, {
219143
- host: this.config.get("host"),
219144
- port: this.config.get("port"),
219145
- username: this.config.get("username"),
219146
- password: this.config.get("password"),
219386
+ return hydrateSchema(shownSchema, {
219387
+ ...hubChild ? {
219388
+ hubName: hubSession?.name ?? this.hubIntegrationId() ?? "",
219389
+ channel: this.config.get("channel")
219390
+ } : {
219391
+ host: this.config.get("host"),
219392
+ port: this.config.get("port"),
219393
+ username: this.config.get("username"),
219394
+ password: this.config.get("password")
219395
+ },
219147
219396
  emailSmtpServer: emailSnap?.smtpServer ?? "",
219148
219397
  emailSmtpPort: emailSnap?.smtpPort ?? 587,
219149
219398
  emailUserName: emailSnap?.userName ?? "",
@@ -219224,8 +219473,26 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
219224
219473
  intercomGain: this.config.get("intercomGain") ?? 1
219225
219474
  });
219226
219475
  }
219476
+ /**
219477
+ * A hub child's connection belongs to its integration. A patch touching host / port /
219478
+ * username / password, or naming a channel the hub does not list, is refused with a typed,
219479
+ * logged reason — never silently dropped. The read-only `hubName` echo is not a setting.
219480
+ */
219481
+ refuseHubChildPatch(patch) {
219482
+ const refusal = judgeHubChildPatch(patch, (this.hubSession()?.channelSnapshot().channels ?? []).map((c) => c.channel));
219483
+ if (refusal === null) return;
219484
+ this.ctx.logger.warn("hub child settings patch refused", {
219485
+ tags: { deviceId: this.id },
219486
+ meta: {
219487
+ ...refusal,
219488
+ integrationId: this.hubIntegrationId()
219489
+ }
219490
+ });
219491
+ throw new HubChildPatchRefusedError(refusal);
219492
+ }
219227
219493
  async applySettingsPatch(patch) {
219228
- const { emailSmtpServer, emailSmtpPort, emailUserName, emailPassword, emailSsl, emailRecipient1, emailRecipient2, emailRecipient3, emailSendNickname, emailScheduleEnabled, osdChannelEnabled, osdChannelName, osdChannelPosition, osdTimeEnabled, osdTimePosition, osdWatermark, ...rest } = patch;
219494
+ if (this.isHubChild()) this.refuseHubChildPatch(patch);
219495
+ const { emailSmtpServer, emailSmtpPort, emailUserName, emailPassword, emailSsl, emailRecipient1, emailRecipient2, emailRecipient3, emailSendNickname, emailScheduleEnabled, osdChannelEnabled, osdChannelName, osdChannelPosition, osdTimeEnabled, osdTimePosition, osdWatermark, hubName: _hubName, ...rest } = patch;
219229
219496
  if ((osdChannelEnabled !== void 0 || osdChannelName !== void 0 || osdChannelPosition !== void 0 || osdTimeEnabled !== void 0 || osdTimePosition !== void 0 || osdWatermark !== void 0 || emailSmtpServer !== void 0 || emailRecipient1 !== void 0) && !await this.wakeIfSleeping()) this.ctx.logger.warn("settings write: battery cam did not wake — writing anyway", { tags: { deviceId: this.id } });
219230
219497
  const emailFields = {
219231
219498
  emailSmtpServer,
@@ -220245,6 +220512,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
220245
220512
  }
220246
220513
  });
220247
220514
  this.api = null;
220515
+ if (this.removed) return;
220248
220516
  this.reconnectTimer = setTimeout(() => {
220249
220517
  this.reconnectTimer = null;
220250
220518
  this.ctx.logger.debug("Baichuan reconnect window elapsed — ready for next demand", { tags: { deviceId: this.id } });
@@ -222634,11 +222902,17 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
222634
222902
  async onConfigChanged() {
222635
222903
  await this.refreshClipRefreshGlobalStore();
222636
222904
  }
222905
+ scopedSettingsCapabilities() {
222906
+ return ["videoclips"];
222907
+ }
222637
222908
  /**
222638
- * The addon's global settings schema: the clip-catalog refresh default. (The battery push has
222639
- * no addon-level setting: the mailbox is a broker and the webhook is a plane of the data plane.)
222909
+ * The fleet default of the clip-catalog refresh. (The battery push has no addon-level setting:
222910
+ * the mailbox is a broker and the webhook is a plane of the data plane.) Per-camera overrides
222911
+ * live on the device under the same key and resolve through `resolveClipCatalogRefreshMinutes`
222912
+ * — reset == unset == this value.
222640
222913
  */
222641
- globalSettingsSchema() {
222914
+ async deviceDefaultsSchema(cap) {
222915
+ if (cap !== "videoclips") return null;
222642
222916
  return { sections: [...buildClipRefreshSettingsSchema().sections] };
222643
222917
  }
222644
222918
  async onInitialize() {
package/dist/addon.mjs CHANGED
@@ -106669,7 +106669,7 @@ var ZodIssueCode = {
106669
106669
  var ZodFirstPartyTypeKind;
106670
106670
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
106671
106671
  //#endregion
106672
- //#region ../types/dist/sleep-9TIHFj1w.mjs
106672
+ //#region ../types/dist/sleep-DEZaLbiu.mjs
106673
106673
  /**
106674
106674
  * The audio chunk plane's byte format, and the ONE expansion from a coded
106675
106675
  * window to float samples (D455).
@@ -107478,6 +107478,12 @@ function projectStore(store, perNodeKeys, nodeId) {
107478
107478
  }
107479
107479
  return out;
107480
107480
  }
107481
+ /** Every scope, in the order the guard and the docs list them. */
107482
+ var SCOPED_SETTINGS_SCOPES = [
107483
+ "cluster",
107484
+ "device-defaults",
107485
+ "node"
107486
+ ];
107481
107487
  /**
107482
107488
  * The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
107483
107489
  *
@@ -108369,6 +108375,13 @@ var BaseAddon = class {
108369
108375
  */
108370
108376
  secretStatePaths = [];
108371
108377
  _addonSecretTree = null;
108378
+ /**
108379
+ * D986 M4: the scoped schemas this addon declared, resolved once per capability
108380
+ * (`loadScopedSchemas`) so the sync readers (`perNodeKeys`, the secret tree, the restart check)
108381
+ * see them. Empty until loaded: the readers then fall back to {@link globalSettingsSchema}.
108382
+ */
108383
+ _scopedByCap = /* @__PURE__ */ new Map();
108384
+ _nodeKeysByCap = /* @__PURE__ */ new Map();
108372
108385
  _deviceSecretTree = null;
108373
108386
  /** Refs the last resolved config pointed at — a change to one re-resolves. */
108374
108387
  _configSecretRefs = /* @__PURE__ */ new Set();
@@ -108438,6 +108451,7 @@ var BaseAddon = class {
108438
108451
  this._ctx = context;
108439
108452
  this._secretSettings = null;
108440
108453
  }
108454
+ await this.loadScopedSchemas();
108441
108455
  await this.resolveConfig();
108442
108456
  if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
108443
108457
  if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
@@ -108447,6 +108461,7 @@ var BaseAddon = class {
108447
108461
  const normalized = normalizeAddonInitResult(result);
108448
108462
  const providers = normalized && "providers" in normalized && normalized.providers ? normalized.providers : [];
108449
108463
  this._registeredCapNames = providers.map((p) => p.capability.name);
108464
+ await this.loadScopedSchemas();
108450
108465
  return normalized;
108451
108466
  }
108452
108467
  /**
@@ -108535,6 +108550,16 @@ var BaseAddon = class {
108535
108550
  schema(schema) {
108536
108551
  return schema;
108537
108552
  }
108553
+ /**
108554
+ * The capability names whose scoped settings schemas ({@link clusterSettingsSchema},
108555
+ * {@link nodeSettingsSchema}, {@link deviceDefaultsSchema}) this addon declares. Read BEFORE
108556
+ * `onInitialize`, when the providers it registers are not known yet: the first config resolve
108557
+ * must already know which keys are per node. Names the providers register at init are added
108558
+ * once known.
108559
+ */
108560
+ scopedSettingsCapabilities() {
108561
+ return [];
108562
+ }
108538
108563
  /** Override to provide global-level settings UI schema. */
108539
108564
  globalSettingsSchema(_cap) {
108540
108565
  return null;
@@ -108578,7 +108603,8 @@ var BaseAddon = class {
108578
108603
  return [];
108579
108604
  }
108580
108605
  async getGlobalSettings(overlay, cap, nodeId) {
108581
- const schema = this.globalSettingsSchema(cap);
108606
+ await this.loadScopedSchemas(cap);
108607
+ const schema = this.globalSettingsSchema(cap) ?? this.scopedFormSchema(cap);
108582
108608
  if (!schema) return { sections: [] };
108583
108609
  const projected = await this.readRawProjectedStore(nodeId, cap);
108584
108610
  return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(projected, overlay) : projected, { inlineSecretsAsViews: true });
@@ -108709,6 +108735,7 @@ var BaseAddon = class {
108709
108735
  * resolved blob back is a no-op for every unchanged secret.
108710
108736
  */
108711
108737
  async resolveGlobalStore(nodeId, cap) {
108738
+ await this.loadScopedSchemas(cap);
108712
108739
  const raw = await this._ctx?.settings?.readAddonStore() ?? {};
108713
108740
  return this.projectForNode(raw, nodeId, cap);
108714
108741
  }
@@ -108719,6 +108746,7 @@ var BaseAddon = class {
108719
108746
  }
108720
108747
  /** The PROJECTED store with its markers — the form hydrate only (D798). */
108721
108748
  async readRawProjectedStore(nodeId, cap) {
108749
+ await this.loadScopedSchemas(cap);
108722
108750
  const raw = await this.rawSettings()?.readAddonStore() ?? {};
108723
108751
  return this.projectForNode(raw, nodeId, cap);
108724
108752
  }
@@ -108821,6 +108849,7 @@ var BaseAddon = class {
108821
108849
  await this.applyGlobalPatch(patch, nodeId);
108822
108850
  }
108823
108851
  async applyGlobalPatch(barePatch, nodeId) {
108852
+ await this.loadScopedSchemas();
108824
108853
  const keys = this.perNodeKeys();
108825
108854
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
108826
108855
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
@@ -108834,7 +108863,8 @@ var BaseAddon = class {
108834
108863
  await this.resolveConfig();
108835
108864
  await this.onConfigChanged();
108836
108865
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
108837
- this.maybeAutoRestart(Object.keys(barePatch), this.globalSettingsSchema());
108866
+ const legacy = this.globalSettingsSchema();
108867
+ this.maybeAutoRestart(Object.keys(barePatch), [...legacy === null ? [] : [legacy], ...this.loadedScopedSchemas().map((entry) => entry.schema)]);
108838
108868
  }
108839
108869
  /**
108840
108870
  * The set of field keys the global settings schema declares `perNode: true`
@@ -108842,14 +108872,67 @@ var BaseAddon = class {
108842
108872
  * declarations). Empty set ⇒ every per-node code path is bypassed and the
108843
108873
  * settings API behaves exactly like the legacy node-agnostic one.
108844
108874
  */
108845
- _perNodeKeysCache = /* @__PURE__ */ new Map();
108875
+ /**
108876
+ * Load the scoped schemas of every capability this addon declares (the override and the
108877
+ * providers registered at init, plus `extraCap`) that is not loaded yet, then drop what was
108878
+ * derived from the previous set. Idempotent.
108879
+ */
108880
+ async loadScopedSchemas(extraCap) {
108881
+ const caps = new Set([
108882
+ ...this.scopedSettingsCapabilities(),
108883
+ ...this._registeredCapNames,
108884
+ ...extraCap === void 0 ? [] : [extraCap]
108885
+ ]);
108886
+ let added = false;
108887
+ for (const cap of caps) {
108888
+ if (this._scopedByCap.has(cap)) continue;
108889
+ const loaded = [];
108890
+ for (const scope of SCOPED_SETTINGS_SCOPES) {
108891
+ const schema = await this.getScopedSettingsSchema(scope, cap);
108892
+ if (schema !== null) loaded.push({
108893
+ scope,
108894
+ schema
108895
+ });
108896
+ }
108897
+ this._scopedByCap.set(cap, loaded);
108898
+ added = true;
108899
+ }
108900
+ if (!added) return;
108901
+ this._nodeKeysByCap = /* @__PURE__ */ new Map();
108902
+ this._addonSecretTree = null;
108903
+ }
108904
+ /**
108905
+ * The form the settings API serves while an addon declares no {@link globalSettingsSchema}: the
108906
+ * sections of its scoped schemas, so dropping the old hook does not blank the form.
108907
+ */
108908
+ scopedFormSchema(cap) {
108909
+ const byId = /* @__PURE__ */ new Map();
108910
+ for (const entry of this.loadedScopedSchemas(cap)) for (const section of entry.schema.sections) if (!byId.has(section.id)) byId.set(section.id, section);
108911
+ return byId.size === 0 ? null : { sections: [...byId.values()] };
108912
+ }
108913
+ /** Every loaded scoped schema of `cap`, or of every loaded capability. */
108914
+ loadedScopedSchemas(cap) {
108915
+ if (cap !== void 0) return this._scopedByCap.get(cap) ?? [];
108916
+ return [...this._scopedByCap.values()].flat();
108917
+ }
108918
+ /**
108919
+ * The field keys that are stored per node: every field of a {@link nodeSettingsSchema}, plus
108920
+ * the fields the legacy {@link globalSettingsSchema} still marks `perNode: true`. Derived once
108921
+ * per `cap` argument and memoized (schemas are static declarations). Empty set ⇒ every
108922
+ * per-node code path is bypassed and the settings API behaves like the node-agnostic one.
108923
+ * Call {@link loadScopedSchemas} first (the async seams do).
108924
+ */
108846
108925
  perNodeKeys(cap) {
108847
108926
  const cacheKey = cap ?? "";
108848
- const cached = this._perNodeKeysCache.get(cacheKey);
108927
+ const cached = this._nodeKeysByCap.get(cacheKey);
108849
108928
  if (cached) return cached;
108850
- const schema = this.globalSettingsSchema(cap);
108851
- const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
108852
- this._perNodeKeysCache.set(cacheKey, keys);
108929
+ const legacy = this.globalSettingsSchema(cap);
108930
+ const keys = new Set(legacy ? legacy.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
108931
+ for (const { scope, schema } of this.loadedScopedSchemas(cap)) {
108932
+ if (scope !== "node") continue;
108933
+ for (const section of schema.sections) for (const key of collectValueFieldKeys(section.fields)) keys.add(key);
108934
+ }
108935
+ this._nodeKeysByCap.set(cacheKey, keys);
108853
108936
  return keys;
108854
108937
  }
108855
108938
  /**
@@ -108859,10 +108942,9 @@ var BaseAddon = class {
108859
108942
  * time to return its response before the addon is torn down and
108860
108943
  * re-initialised by `AddonRegistryService.restartAddon`.
108861
108944
  */
108862
- maybeAutoRestart(patchKeys, schema) {
108863
- if (!schema) return;
108945
+ maybeAutoRestart(patchKeys, schemas) {
108864
108946
  const restartKeys = /* @__PURE__ */ new Set();
108865
- for (const section of schema.sections) for (const field of section.fields) {
108947
+ for (const schema of schemas) for (const section of schema.sections) for (const field of section.fields) {
108866
108948
  if (field.type === "separator" || field.type === "info") continue;
108867
108949
  if (field.requiresRestart) restartKeys.add(field.key);
108868
108950
  }
@@ -109058,12 +109140,14 @@ var BaseAddon = class {
109058
109140
  * here, in the addon's own process, so the hub keeps no copy of it.
109059
109141
  */
109060
109142
  async getDeclaredSettingsKeys() {
109143
+ await this.loadScopedSchemas();
109061
109144
  return { keys: [...this.declaredKeySet()].toSorted() };
109062
109145
  }
109063
109146
  declaredKeySet() {
109064
109147
  const keys = new Set(Object.keys(this.defaults));
109065
109148
  const schema = this.globalSettingsSchema();
109066
109149
  if (schema) for (const section of schema.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
109150
+ for (const { schema: scoped } of this.loadedScopedSchemas()) for (const section of scoped.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
109067
109151
  for (const key of this._declaredStateKeys) keys.add(key);
109068
109152
  for (const path of this.secretStatePaths) {
109069
109153
  const root = path.split(/[.[]/, 1)[0];
@@ -109159,7 +109243,11 @@ var BaseAddon = class {
109159
109243
  }
109160
109244
  /** The addon store's secret tree: schema fields by TYPE, plus `secretStatePaths`. */
109161
109245
  addonSecretTree() {
109162
- this._addonSecretTree ??= mergeSecretStatePaths(secretTreeFromSchema(this.globalSettingsSchema()), this.secretStatePaths);
109246
+ if (this._addonSecretTree === null) {
109247
+ const tree = new Map(secretTreeFromSchema(this.globalSettingsSchema()));
109248
+ for (const { schema } of this.loadedScopedSchemas()) for (const [key, node] of secretTreeFromSchema(schema)) tree.set(key, node);
109249
+ this._addonSecretTree = mergeSecretStatePaths(tree, this.secretStatePaths);
109250
+ }
109163
109251
  return this._addonSecretTree;
109164
109252
  }
109165
109253
  deviceSecretTree() {
@@ -109409,6 +109497,23 @@ function dropPerNodeFields(fields) {
109409
109497
  }
109410
109498
  return kept;
109411
109499
  }
109500
+ /** The keys of the value-holding fields, recursing into layout containers. */
109501
+ function collectValueFieldKeys(fields) {
109502
+ const collected = [];
109503
+ for (const field of fields) {
109504
+ if (field.type === "group") {
109505
+ collected.push(...collectValueFieldKeys(field.fields));
109506
+ continue;
109507
+ }
109508
+ if (field.type === "sub-tabs") {
109509
+ for (const tab of field.tabs) collected.push(...collectValueFieldKeys(tab.fields));
109510
+ continue;
109511
+ }
109512
+ if (field.type === "separator" || field.type === "info") continue;
109513
+ if ("key" in field && typeof field.key === "string") collected.push(field.key);
109514
+ }
109515
+ return collected;
109516
+ }
109412
109517
  function collectFieldKeys(fields) {
109413
109518
  const collected = [];
109414
109519
  for (const field of fields) {
@@ -208972,6 +209077,114 @@ async function connectReolinkHub(connection) {
208972
209077
  return api;
208973
209078
  }
208974
209079
  //#endregion
209080
+ //#region src/hub-child-settings.ts
209081
+ /**
209082
+ * A camera adopted under an NVR / Home Hub dials through the integration's session: the address
209083
+ * and the credentials belong to the integration, never to the camera. These are the per-camera
209084
+ * keys a hub child must refuse to change.
209085
+ */
209086
+ var HUB_CHILD_CONNECTION_KEYS = [
209087
+ "host",
209088
+ "port",
209089
+ "username",
209090
+ "password"
209091
+ ];
209092
+ /**
209093
+ * Sections that act on the hub itself (no channel in the call) or on the per-camera connection,
209094
+ * hidden for a hub child:
209095
+ * - `connection`: the per-camera address and credentials (the integration owns them);
209096
+ * - `network-ports`: `setPortConfig` rewrites the NVR's own service ports;
209097
+ * - `time-ntp`: `setNtp` / `setSystemGeneral` / `setDst` rewrite the NVR's clock.
209098
+ */
209099
+ var HUB_CHILD_HIDDEN_SECTION_IDS = [
209100
+ "connection",
209101
+ "network-ports",
209102
+ "time-ntp"
209103
+ ];
209104
+ /** Thrown by `applySettingsPatch` for a refused hub-child patch; carries the typed reason. */
209105
+ var HubChildPatchRefusedError = class extends Error {
209106
+ refusal;
209107
+ constructor(refusal) {
209108
+ super(describeRefusal(refusal));
209109
+ this.refusal = refusal;
209110
+ this.name = "HubChildPatchRefusedError";
209111
+ }
209112
+ };
209113
+ function describeRefusal(refusal) {
209114
+ switch (refusal.reason) {
209115
+ 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`;
209116
+ case "channel-not-an-integer": return `The hub channel must be a whole number, got ${String(refusal.value)}`;
209117
+ case "channel-out-of-range": return `Channel ${refusal.value} is not one of the hub's channels (${refusal.channels.join(", ")})`;
209118
+ }
209119
+ }
209120
+ /**
209121
+ * Judge a settings patch against the hub-child rules. `channels` is the hub's last good channel
209122
+ * list (empty when unknown — then only the integer rule applies).
209123
+ */
209124
+ function judgeHubChildPatch(patch, channels) {
209125
+ const touched = HUB_CHILD_CONNECTION_KEYS.filter((k) => patch[k] !== void 0);
209126
+ if (touched.length > 0) return {
209127
+ reason: "connection-owned-by-integration",
209128
+ keys: touched
209129
+ };
209130
+ if (patch["channel"] === void 0) return null;
209131
+ const value = patch["channel"];
209132
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) return {
209133
+ reason: "channel-not-an-integer",
209134
+ value
209135
+ };
209136
+ if (channels.length > 0 && !channels.includes(value)) return {
209137
+ reason: "channel-out-of-range",
209138
+ value,
209139
+ channels
209140
+ };
209141
+ return null;
209142
+ }
209143
+ /** What a hub child shows before its session has read the hub's channel list. */
209144
+ var EMPTY_HUB_CHANNEL_SNAPSHOT = {
209145
+ channels: [],
209146
+ lastRefreshAt: null,
209147
+ lastError: null
209148
+ };
209149
+ /** The hub-child "Hub" section: which hub, and the one editable connection field, the channel. */
209150
+ function buildHubChildSection(snapshot) {
209151
+ return {
209152
+ id: "hub",
209153
+ tab: "general",
209154
+ title: "Hub",
209155
+ titleKey: "provider-reolink:schema.s_hub.title",
209156
+ 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.",
209157
+ descriptionKey: "provider-reolink:schema.s_hub.description",
209158
+ columns: 2,
209159
+ fields: [{
209160
+ type: "text",
209161
+ key: "hubName",
209162
+ label: "Connected to",
209163
+ labelKey: "provider-reolink:schema.s_hub.hubName.label",
209164
+ disabled: true
209165
+ }, {
209166
+ type: "number",
209167
+ key: "channel",
209168
+ label: "Hub channel",
209169
+ labelKey: "provider-reolink:schema.s_hub.channel.label",
209170
+ min: 0,
209171
+ ...snapshot.channels.length > 0 ? { max: Math.max(...snapshot.channels.map((c) => c.channel)) } : {},
209172
+ step: 1
209173
+ }]
209174
+ };
209175
+ }
209176
+ /** Replace the connection/hub-acting sections of a standalone schema with the Hub section. */
209177
+ function applyHubChildSections(sections, snapshot) {
209178
+ const kept = sections.filter((s) => !HUB_CHILD_HIDDEN_SECTION_IDS.includes(s.id));
209179
+ const at = kept.findIndex((s) => s.id === "driver-refresh");
209180
+ const hub = buildHubChildSection(snapshot);
209181
+ return at < 0 ? [hub, ...kept] : [
209182
+ ...kept.slice(0, at + 1),
209183
+ hub,
209184
+ ...kept.slice(at + 1)
209185
+ ];
209186
+ }
209187
+ //#endregion
208975
209188
  //#region src/sleep-state-decision.ts
208976
209189
  /**
208977
209190
  * Hysteresis is ASYMMETRIC, because the two directions have very different
@@ -212564,6 +212777,8 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
212564
212777
  * Mirrors the reference's `batteryUpdateTimer`: fires every hour,
212565
212778
  * passively checks sleep state, and short-circuits if sleeping. */
212566
212779
  batteryUpdateTimer = null;
212780
+ /** Set by `removeDevice`: nothing may re-arm a timer on a removed camera. */
212781
+ removed = false;
212567
212782
  /** Single-flight gate so two interval fires can't overlap. */
212568
212783
  /** Aux accessory references registered by spawned children
212569
212784
  * (siren / floodlight / pir). The parent's centralised align
@@ -212679,6 +212894,18 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
212679
212894
  isHubChild() {
212680
212895
  return this.hubIntegrationId() !== null && typeof this.config.get("channel") === "number";
212681
212896
  }
212897
+ /**
212898
+ * The host this camera is reached at: the integration's for a hub child (the stored per-camera
212899
+ * `host` of a child is never read), the camera's own otherwise. `null` when there is none.
212900
+ */
212901
+ connectionHost() {
212902
+ if (this.isHubChild()) {
212903
+ const host = this.hubSession()?.relayEndpoint().host;
212904
+ return host !== void 0 && host.length > 0 ? host : null;
212905
+ }
212906
+ const host = this.config.get("host");
212907
+ return typeof host === "string" && host.length > 0 ? host : null;
212908
+ }
212682
212909
  /** The integration (one NVR / Home Hub, D985) this camera was adopted from, or `null`. */
212683
212910
  hubIntegrationId() {
212684
212911
  const id = this.config.get("integrationId");
@@ -213314,7 +213541,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
213314
213541
  isBattery: this.isBattery,
213315
213542
  sleeping: this.sleeping,
213316
213543
  timeZone: resolveClipTimeZoneOnce(Intl.DateTimeFormat().resolvedOptions().timeZone, reolinkTimeZoneToIana(this.config.get("deviceCache")?.systemGeneralSnapshot?.timeZone), this.ctx.logger, this.id, this.clipTimeZoneWarned),
213317
- hostKey: String(this.config.get("host") ?? `device-${this.id}`),
213544
+ hostKey: this.connectionHost() ?? `device-${this.id}`,
213318
213545
  getApi: () => this.ensureApi()
213319
213546
  };
213320
213547
  }
@@ -213647,7 +213874,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
213647
213874
  } });
213648
213875
  this.ctx.registerNativeCap(deviceAdminLinkCapability, { getAdminLink: async ({ deviceId }) => {
213649
213876
  if (deviceId !== this.id) throw new Error(`ReolinkCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
213650
- const host = this.config.get("host") ?? "";
213877
+ const host = this.connectionHost() ?? "";
213651
213878
  const built = buildDeviceAdminUrl({
213652
213879
  host,
213653
213880
  port: null,
@@ -217000,6 +217227,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
217000
217227
  * FLV publication for those devices rather than emitting a broken URL.
217001
217228
  */
217002
217229
  buildFlvUrl(channel, profile) {
217230
+ if (this.isHubChild()) return null;
217003
217231
  const host = this.config.get("host");
217004
217232
  if (typeof host !== "string" || host.length === 0) return null;
217005
217233
  return `http://${host}/flv?port=1935&app=bcs&stream=channel${channel}_${profile}.bcs&user=${encodeURIComponent(String(this.config.get("username") ?? ""))}&password=${encodeURIComponent(String(this.config.get("password") ?? ""))}`;
@@ -217350,6 +217578,11 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
217350
217578
  });
217351
217579
  }
217352
217580
  async removeDevice() {
217581
+ this.removed = true;
217582
+ this.stopSleepPoll();
217583
+ this.stopBatteryUpdatePolling();
217584
+ this.stopAlignAuxPolling();
217585
+ this.stopWatchdogs();
217353
217586
  this.detachFromHubSession();
217354
217587
  if (this.reconnectTimer) {
217355
217588
  clearTimeout(this.reconnectTimer);
@@ -217519,6 +217752,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
217519
217752
  * `sleeping`/`awake` transition (firmware quirks, NAT timeouts).
217520
217753
  */
217521
217754
  startSleepPoll() {
217755
+ if (this.removed) return;
217522
217756
  if (this.sleepPollTimer) return;
217523
217757
  if (!this.isBattery) return;
217524
217758
  if (this.isHubChild()) return;
@@ -217658,6 +217892,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
217658
217892
  /** Start periodic align for wired cams. No-op for battery cams (wake
217659
217893
  * path handles it). Idempotent. */
217660
217894
  startAlignAuxPolling() {
217895
+ if (this.removed) return;
217661
217896
  if (this.alignAuxTimer) return;
217662
217897
  if (this.isBattery) return;
217663
217898
  const POLL_MS = 1e4;
@@ -217738,6 +217973,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
217738
217973
  /** Arm the scheduled-refresh check. No-op for wired cams (their state is
217739
217974
  * kept fresh by the 10 s aux-align poll and push events). Idempotent. */
217740
217975
  startBatteryUpdatePolling() {
217976
+ if (this.removed) return;
217741
217977
  if (this.batteryUpdateTimer) return;
217742
217978
  if (!this.isBattery) return;
217743
217979
  this.batteryUpdateTimer = setInterval(() => {
@@ -217867,6 +218103,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
217867
218103
  * with parallel watchdogs after a reconnect cycle.
217868
218104
  */
217869
218105
  startWatchdogs() {
218106
+ if (this.removed) return;
217870
218107
  this.stopWatchdogs();
217871
218108
  this.watchdogStartedAt = Date.now();
217872
218109
  this.consecutivePingFailures = 0;
@@ -218131,6 +218368,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
218131
218368
  * re-subscribes the moment the socket comes back up.
218132
218369
  */
218133
218370
  startEventHealthCheck() {
218371
+ if (this.removed) return;
218134
218372
  this.stopEventHealthCheck();
218135
218373
  this.consecutiveStaleHealthChecks = 0;
218136
218374
  this.nextEventHealthCheckAt = 0;
@@ -219130,12 +219368,23 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
219130
219368
  ...buildBatteryRefreshDeviceSection({ isBattery: this.isBattery })
219131
219369
  ]
219132
219370
  };
219371
+ const hubChild = this.isHubChild();
219372
+ const hubSession = this.hubSession();
219373
+ const shownSchema = hubChild ? {
219374
+ ...schema,
219375
+ sections: applyHubChildSections(schema.sections, hubSession?.channelSnapshot() ?? EMPTY_HUB_CHANNEL_SNAPSHOT)
219376
+ } : schema;
219133
219377
  const emailSnap = cache?.emailConfigSnapshot;
219134
- return hydrateSchema(schema, {
219135
- host: this.config.get("host"),
219136
- port: this.config.get("port"),
219137
- username: this.config.get("username"),
219138
- password: this.config.get("password"),
219378
+ return hydrateSchema(shownSchema, {
219379
+ ...hubChild ? {
219380
+ hubName: hubSession?.name ?? this.hubIntegrationId() ?? "",
219381
+ channel: this.config.get("channel")
219382
+ } : {
219383
+ host: this.config.get("host"),
219384
+ port: this.config.get("port"),
219385
+ username: this.config.get("username"),
219386
+ password: this.config.get("password")
219387
+ },
219139
219388
  emailSmtpServer: emailSnap?.smtpServer ?? "",
219140
219389
  emailSmtpPort: emailSnap?.smtpPort ?? 587,
219141
219390
  emailUserName: emailSnap?.userName ?? "",
@@ -219216,8 +219465,26 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
219216
219465
  intercomGain: this.config.get("intercomGain") ?? 1
219217
219466
  });
219218
219467
  }
219468
+ /**
219469
+ * A hub child's connection belongs to its integration. A patch touching host / port /
219470
+ * username / password, or naming a channel the hub does not list, is refused with a typed,
219471
+ * logged reason — never silently dropped. The read-only `hubName` echo is not a setting.
219472
+ */
219473
+ refuseHubChildPatch(patch) {
219474
+ const refusal = judgeHubChildPatch(patch, (this.hubSession()?.channelSnapshot().channels ?? []).map((c) => c.channel));
219475
+ if (refusal === null) return;
219476
+ this.ctx.logger.warn("hub child settings patch refused", {
219477
+ tags: { deviceId: this.id },
219478
+ meta: {
219479
+ ...refusal,
219480
+ integrationId: this.hubIntegrationId()
219481
+ }
219482
+ });
219483
+ throw new HubChildPatchRefusedError(refusal);
219484
+ }
219219
219485
  async applySettingsPatch(patch) {
219220
- const { emailSmtpServer, emailSmtpPort, emailUserName, emailPassword, emailSsl, emailRecipient1, emailRecipient2, emailRecipient3, emailSendNickname, emailScheduleEnabled, osdChannelEnabled, osdChannelName, osdChannelPosition, osdTimeEnabled, osdTimePosition, osdWatermark, ...rest } = patch;
219486
+ if (this.isHubChild()) this.refuseHubChildPatch(patch);
219487
+ const { emailSmtpServer, emailSmtpPort, emailUserName, emailPassword, emailSsl, emailRecipient1, emailRecipient2, emailRecipient3, emailSendNickname, emailScheduleEnabled, osdChannelEnabled, osdChannelName, osdChannelPosition, osdTimeEnabled, osdTimePosition, osdWatermark, hubName: _hubName, ...rest } = patch;
219221
219488
  if ((osdChannelEnabled !== void 0 || osdChannelName !== void 0 || osdChannelPosition !== void 0 || osdTimeEnabled !== void 0 || osdTimePosition !== void 0 || osdWatermark !== void 0 || emailSmtpServer !== void 0 || emailRecipient1 !== void 0) && !await this.wakeIfSleeping()) this.ctx.logger.warn("settings write: battery cam did not wake — writing anyway", { tags: { deviceId: this.id } });
219222
219489
  const emailFields = {
219223
219490
  emailSmtpServer,
@@ -220237,6 +220504,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
220237
220504
  }
220238
220505
  });
220239
220506
  this.api = null;
220507
+ if (this.removed) return;
220240
220508
  this.reconnectTimer = setTimeout(() => {
220241
220509
  this.reconnectTimer = null;
220242
220510
  this.ctx.logger.debug("Baichuan reconnect window elapsed — ready for next demand", { tags: { deviceId: this.id } });
@@ -222626,11 +222894,17 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
222626
222894
  async onConfigChanged() {
222627
222895
  await this.refreshClipRefreshGlobalStore();
222628
222896
  }
222897
+ scopedSettingsCapabilities() {
222898
+ return ["videoclips"];
222899
+ }
222629
222900
  /**
222630
- * The addon's global settings schema: the clip-catalog refresh default. (The battery push has
222631
- * no addon-level setting: the mailbox is a broker and the webhook is a plane of the data plane.)
222901
+ * The fleet default of the clip-catalog refresh. (The battery push has no addon-level setting:
222902
+ * the mailbox is a broker and the webhook is a plane of the data plane.) Per-camera overrides
222903
+ * live on the device under the same key and resolve through `resolveClipCatalogRefreshMinutes`
222904
+ * — reset == unset == this value.
222632
222905
  */
222633
- globalSettingsSchema() {
222906
+ async deviceDefaultsSchema(cap) {
222907
+ if (cap !== "videoclips") return null;
222634
222908
  return { sections: [...buildClipRefreshSettingsSchema().sections] };
222635
222909
  }
222636
222910
  async onInitialize() {
package/i18n/en.json CHANGED
@@ -204,5 +204,17 @@
204
204
  "connection.s_hub-debug.debugSocketLogs.label": "Socket trace categories",
205
205
  "connection.s_hub-debug.debugSocketLogs.description": "Each area adds log volume.",
206
206
  "connection.s_hub-debug.debugSocketLogs.o_traceEvents.label": "Events (cmd 33 — AlarmEventList push)",
207
- "connection.s_connection.rtspPort.label": "RTSP port"
207
+ "connection.s_connection.rtspPort.label": "RTSP port",
208
+ "schema": {
209
+ "s_hub": {
210
+ "title": "Hub",
211
+ "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.",
212
+ "hubName": {
213
+ "label": "Connected to"
214
+ },
215
+ "channel": {
216
+ "label": "Hub channel"
217
+ }
218
+ }
219
+ }
208
220
  }
package/i18n/it.json CHANGED
@@ -204,5 +204,17 @@
204
204
  "connection.s_hub-debug.debugSocketLogs.label": "Categorie di trace del socket",
205
205
  "connection.s_hub-debug.debugSocketLogs.description": "Ogni area aumenta il volume dei log.",
206
206
  "connection.s_hub-debug.debugSocketLogs.o_traceEvents.label": "Eventi (cmd 33 — push AlarmEventList)",
207
- "connection.s_connection.rtspPort.label": "Porta RTSP"
207
+ "connection.s_connection.rtspPort.label": "Porta RTSP",
208
+ "schema": {
209
+ "s_hub": {
210
+ "title": "Hub",
211
+ "description": "Questa telecamera è collegata tramite il suo NVR / Home Hub. Indirizzo e credenziali appartengono a quell'integrazione; il canale resta allineato all'hub in automatico.",
212
+ "hubName": {
213
+ "label": "Collegata a"
214
+ },
215
+ "channel": {
216
+ "label": "Canale dell'hub"
217
+ }
218
+ }
219
+ }
208
220
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-provider-reolink",
3
- "version": "1.2.226",
3
+ "version": "1.2.228",
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.771"
99
+ "server": ">=1.2.776"
100
100
  }
101
101
  },
102
102
  "files": [