@camstack/addon-provider-reolink 1.2.253 → 1.2.254

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.js CHANGED
@@ -162713,7 +162713,7 @@ var mediaPlayerCapability = {
162713
162713
  ]
162714
162714
  }
162715
162715
  };
162716
- DeviceType.Camera, DeviceType.Sensor, DeviceType.Button, DeviceType.Switch, DeviceType.PetFeeder, DeviceType.Container, DeviceType.Climate, DeviceType.EventEmitter, DeviceType.Climate, DeviceType.Climate, DeviceType.Camera, DeviceType.Light, DeviceType.Siren, DeviceType.Switch, DeviceType.Sensor, DeviceType.Climate, DeviceType.Button, DeviceType.EventEmitter, DeviceType.Update, DeviceType.Generic, DeviceType.Notifier, DeviceType.Script, DeviceType.Automation, DeviceType.Lock, DeviceType.Cover, DeviceType.Valve, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.Fan, DeviceType.MediaPlayer, DeviceType.AlarmPanel, DeviceType.Control, DeviceType.Presence, DeviceType.Weather, DeviceType.WeatherStation, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.Container, DeviceType.Image, DeviceType.PetFeeder, DeviceType.PetFountain, DeviceType.Dishwasher, DeviceType.Washer, DeviceType.Dryer, DeviceType.Gateway, DeviceType.HeatPump, DeviceType.EnergySystem, DeviceType.Workload, DeviceType.Camera, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Lock, DeviceType.Camera, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Workload, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Workload, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Workload, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Workload, DeviceType.Gateway, DeviceType.Camera, DeviceType.Sensor, DeviceType.MediaPlayer, DeviceType.Vacuum, DeviceType.Generic, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.PetFountain, DeviceType.Fan, DeviceType.Humidifier, DeviceType.Climate, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.MediaPlayer, DeviceType.WaterHeater, DeviceType.Humidifier, DeviceType.Fan, DeviceType.Climate, DeviceType.PetFeeder, DeviceType.MediaPlayer, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation;
162716
+ DeviceType.Camera, DeviceType.Sensor, DeviceType.Button, DeviceType.Switch, DeviceType.PetFeeder, DeviceType.Container, DeviceType.Climate, DeviceType.EventEmitter, DeviceType.Climate, DeviceType.Climate, DeviceType.Camera, DeviceType.Light, DeviceType.Siren, DeviceType.Switch, DeviceType.Sensor, DeviceType.Climate, DeviceType.Button, DeviceType.EventEmitter, DeviceType.Update, DeviceType.Generic, DeviceType.Notifier, DeviceType.Script, DeviceType.Automation, DeviceType.Lock, DeviceType.Cover, DeviceType.Valve, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.Fan, DeviceType.MediaPlayer, DeviceType.AlarmPanel, DeviceType.Control, DeviceType.Presence, DeviceType.Weather, DeviceType.WeatherStation, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.Container, DeviceType.Image, DeviceType.PetFeeder, DeviceType.PetFountain, DeviceType.Dishwasher, DeviceType.Washer, DeviceType.Dryer, DeviceType.Gateway, DeviceType.HeatPump, DeviceType.EnergySystem, DeviceType.Workload, DeviceType.Camera, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.Fan, DeviceType.HeatPump, DeviceType.HeatPump, DeviceType.Lock, DeviceType.Camera, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Workload, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Workload, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Workload, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Workload, DeviceType.Gateway, DeviceType.Camera, DeviceType.Sensor, DeviceType.MediaPlayer, DeviceType.Vacuum, DeviceType.Generic, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.PetFountain, DeviceType.Fan, DeviceType.Humidifier, DeviceType.Climate, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.MediaPlayer, DeviceType.WaterHeater, DeviceType.Humidifier, DeviceType.Fan, DeviceType.Climate, DeviceType.PetFeeder, DeviceType.MediaPlayer, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation, DeviceType.WeatherStation;
162717
162717
  var NUMBER = {
162718
162718
  kind: "fixed",
162719
162719
  result: ["number"]
@@ -171136,6 +171136,43 @@ function heatPumpInstantCop(power) {
171136
171136
  if (thermalW === null || electricalW === null || electricalW <= 0) return null;
171137
171137
  return thermalW / electricalW;
171138
171138
  }
171139
+ var HEAT_PUMP_CUSTOMIZE_DEVICE_TYPES = [DeviceType.HeatPump];
171140
+ /** One electrical reading the operator may take from a device they pick, unit checked. */
171141
+ function electricalTarget(id, path, unit) {
171142
+ return {
171143
+ id,
171144
+ cardinality: "scalar",
171145
+ vocabulary: { cap: "heat-pump-status" },
171146
+ deviceTypes: HEAT_PUMP_CUSTOMIZE_DEVICE_TYPES,
171147
+ apply: "replace",
171148
+ path,
171149
+ sources: [{
171150
+ kind: "numeric",
171151
+ requiredUnit: unit,
171152
+ transforms: [{ kind: "identity" }]
171153
+ }],
171154
+ sourceReport: { status: "assignment-status" }
171155
+ };
171156
+ }
171157
+ var HEAT_PUMP_TARGETS = [electricalTarget("electrical-power", "power.electricalW", "W"), electricalTarget("electrical-energy", "energy.electricalKwh", "kWh")];
171158
+ /**
171159
+ * Customize (D984, #476): a gateway that reports no instantaneous electrical
171160
+ * power (the cloud ones) or whose energy meter the operator trusts less than a
171161
+ * dedicated one lets the OPERATOR pick a device for `power.electricalW` and
171162
+ * `energy.electricalKwh` — a `replace` over a field listed in `overridable`,
171163
+ * nothing else. The replaced value IS the cap field, so the instant COP, the
171164
+ * hero pills and the history use it; nothing is linked by itself (D356), the
171165
+ * unit is checked, and a source that does not answer releases the field back to
171166
+ * the native reading (never a 0, D393).
171167
+ */
171168
+ var heatPumpStatusCustomize = {
171169
+ version: 1,
171170
+ overridable: HEAT_PUMP_TARGETS.map((target) => ({
171171
+ path: target.path,
171172
+ by: target.id
171173
+ })),
171174
+ targets: HEAT_PUMP_TARGETS
171175
+ };
171139
171176
  var heatPumpStatusCapability = {
171140
171177
  name: "heat-pump-status",
171141
171178
  scope: "device",
@@ -171154,6 +171191,7 @@ var heatPumpStatusCapability = {
171154
171191
  * (the series are recorded). See `RuntimeStateDurability`.
171155
171192
  */
171156
171193
  durability: "session",
171194
+ customize: heatPumpStatusCustomize,
171157
171195
  /**
171158
171196
  * History (D850, D917): `circuits[]` is a keyed array — one series per circuit and
171159
171197
  * field, named by the circuit's label. The mode is a state (D896); the energy
@@ -172945,6 +172983,8 @@ var IntegrationInstanceKindSchema = object({
172945
172983
  role: IntegrationInstanceRoleSchema.optional(),
172946
172984
  /** `testInstance` really probes the remote for this kind; absent takes the provider's `canTest`. */
172947
172985
  canTest: boolean().optional(),
172986
+ /** `false`: Add never offers this kind (the system creates its one instance, e.g. a default integration). Absent = creatable. */
172987
+ creatable: boolean().optional(),
172948
172988
  /** The kind signs in through a server-held interactive session. */
172949
172989
  signIn: object({
172950
172990
  basePath: string().min(1),
@@ -222678,6 +222718,19 @@ object({
222678
222718
  delay: number$1().nonnegative().optional(),
222679
222719
  commands: record(string(), unknown())
222680
222720
  });
222721
+ /** The `instance-select` field of a link, keyed like the body field it fills. */
222722
+ function linkFieldDescriptor(key, target, labels) {
222723
+ return {
222724
+ type: "instance-select",
222725
+ key,
222726
+ label: labels.label,
222727
+ ...labels.description !== void 0 ? { description: labels.description } : {},
222728
+ required: labels.required ?? true,
222729
+ ...labels.noneLabel !== void 0 ? { noneLabel: labels.noneLabel } : {},
222730
+ functionCap: target.cap,
222731
+ ...target.kind !== void 0 ? { kind: target.kind } : {}
222732
+ };
222733
+ }
222681
222734
  //#endregion
222682
222735
  //#region src/clips/clip-prefetch.ts
222683
222736
  /** The longest a device may stay quiet after refusals, whatever its interval. */
@@ -223177,6 +223230,11 @@ var reolinkCameraSchema = object({
223177
223230
  /** Empty for a camera adopted from an NVR / Home Hub: it borrows its integration's session. */
223178
223231
  password: string().default("").describe("Password").meta({ secret: true }),
223179
223232
  /**
223233
+ * The SMTP password last written to the camera on the Email tab (or by Auto-configure email
223234
+ * push). A keychain secret: the form shows set / not set, never the value.
223235
+ */
223236
+ emailPassword: string().default("").describe("Camera SMTP password").meta({ secret: true }),
223237
+ /**
223180
223238
  * Transport mode resolved at creation time by autodetect (Slice 15).
223181
223239
  * - `tcp` : standard TCP-based Baichuan (regular cameras, NVR/Hub)
223182
223240
  * - `udp` : BCUDP-based Baichuan (battery cams, UDP-only models like
@@ -223504,6 +223562,17 @@ var reolinkCameraSchema = object({
223504
223562
  supported: boolean().optional()
223505
223563
  }).optional(),
223506
223564
  /**
223565
+ * The power source of a battery camera (`getPowerSource`): `adapter`,
223566
+ * `battery`, or `unknown` when the read failed or the firmware is
223567
+ * silent. Drives the Advanced tab's "Power source" setting; `unknown`
223568
+ * hides it.
223569
+ */
223570
+ powerSourceSnapshot: object({ source: _enum([
223571
+ "adapter",
223572
+ "battery",
223573
+ "unknown"
223574
+ ]) }).optional(),
223575
+ /**
223507
223576
  * Snapshot of the camera's auto-reboot schedule from
223508
223577
  * `getAutoReboot` (cmd_id 101). Drives the "Auto reboot" section
223509
223578
  * defaults on the Advanced tab. `weekDay` is the lib's `DayOfWeek`
@@ -229785,6 +229854,17 @@ function deriveReolinkCameraFeatures(inputs) {
229785
229854
  return out;
229786
229855
  }
229787
229856
  //#endregion
229857
+ //#region src/email-smtp-password.ts
229858
+ /**
229859
+ * The camera SMTP password an operator wrote on the Email tab, when it is a real value to push
229860
+ * to the camera and keep: a non-empty string that is not a keychain marker. Blank means "keep
229861
+ * the stored one" and a marker is the form echoing back what it was shown; neither is a write.
229862
+ */
229863
+ function smtpPasswordToWrite(value) {
229864
+ if (typeof value !== "string" || value.length === 0) return null;
229865
+ return isSecretMarker(value) ? null : value;
229866
+ }
229867
+ //#endregion
229788
229868
  //#region src/hub-child-settings.ts
229789
229869
  /**
229790
229870
  * A camera adopted under an NVR / Home Hub dials through the integration's session: the address
@@ -232418,6 +232498,13 @@ var PirAccessory = class extends BaseDevice {
232418
232498
  * inverse `101 - userValue` (lower raw = more sensitive).
232419
232499
  * Mirrors `refreshSwitchFromExternal`'s reverse transform. */
232420
232500
  async pushConfigToFirmware(enable) {
232501
+ if (this.parent.wakeForWrite && !await this.parent.wakeForWrite()) {
232502
+ this.ctx.logger.warn("pir write not sent — the battery camera could not be woken", {
232503
+ tags: { deviceId: this.id },
232504
+ meta: { channel: this.channel }
232505
+ });
232506
+ throw new Error("The camera is asleep and could not be woken; try again in a moment.");
232507
+ }
232421
232508
  const api = await this.api;
232422
232509
  const sensitive = this.config.get("pirSensitive");
232423
232510
  const reduceAlarm = this.config.get("pirReduceAlarm");
@@ -234313,10 +234400,9 @@ var PowerSourceReadingSchema = _enum([
234313
234400
  "battery",
234314
234401
  "unknown"
234315
234402
  ]);
234316
- var ReadPowerSourceResultSchema = object({ source: PowerSourceReadingSchema });
234317
234403
  /** The device (or this code) declined before any real write was sent. */
234318
234404
  var PowerSourceRefusalReasonSchema = _enum(["dry-run-refused", "dry-run-failed"]);
234319
- var SwitchPowerSourceResultSchema = discriminatedUnion("outcome", [
234405
+ discriminatedUnion("outcome", [
234320
234406
  object({
234321
234407
  outcome: literal("refused"),
234322
234408
  mode: PowerSourceModeSchema,
@@ -234460,6 +234546,54 @@ async function switchPowerSourceTo(target, mode) {
234460
234546
  applied
234461
234547
  };
234462
234548
  }
234549
+ /** The settings key of the power source: an ordinary select, owned by the camera (never stored). */
234550
+ var POWER_SOURCE_SETTING_KEY = "powerSource";
234551
+ /**
234552
+ * The power source as a setting, in its own section of the Advanced tab.
234553
+ * Only a battery camera whose read ANSWERED with a mode has one: a camera that
234554
+ * was never asked, or that did not answer, shows nothing rather than a guess.
234555
+ */
234556
+ function buildPowerSourceSettingsSection(input) {
234557
+ const { isBattery, source } = input;
234558
+ if (!isBattery || source === void 0 || source === "unknown") return [];
234559
+ return [{
234560
+ id: "power-source",
234561
+ tab: "advanced",
234562
+ title: "Power source",
234563
+ titleKey: "provider-reolink:schema.s_power-source.title",
234564
+ description: "Only switch to wired power when the adapter meets the camera's spec.",
234565
+ descriptionKey: "provider-reolink:schema.s_power-source.description",
234566
+ columns: 1,
234567
+ fields: [{
234568
+ type: "select",
234569
+ key: POWER_SOURCE_SETTING_KEY,
234570
+ label: "Power source",
234571
+ labelKey: "provider-reolink:schema.s_power-source.powerSource.label",
234572
+ default: source,
234573
+ options: [{
234574
+ value: "adapter",
234575
+ label: "Wired power",
234576
+ labelKey: "provider-reolink:schema.s_power-source.powerSource.o_adapter.label"
234577
+ }, {
234578
+ value: "battery",
234579
+ label: "Battery power",
234580
+ labelKey: "provider-reolink:schema.s_power-source.powerSource.o_battery.label"
234581
+ }]
234582
+ }]
234583
+ }];
234584
+ }
234585
+ /**
234586
+ * Apply the setting: switch the camera and REFUSE to call a switch that did not
234587
+ * land a success — the settings form keeps the operator's edit, marked unsaved.
234588
+ */
234589
+ async function applyPowerSourceSetting(target, value) {
234590
+ const mode = PowerSourceModeSchema.safeParse(value);
234591
+ if (!mode.success) throw new Error(`Not a power source: ${String(value)}`);
234592
+ const outcome = await switchPowerSourceTo(target, mode.data);
234593
+ if (outcome.outcome === "refused") throw new Error(`The camera refused the power source switch (${outcome.reason})`);
234594
+ if (outcome.outcome === "failed") throw new Error(`The power source switch failed: ${outcome.error}`);
234595
+ if (!outcome.applied) throw new Error(`The camera did not take the power source switch (it reports ${outcome.after})`);
234596
+ }
234463
234597
  //#endregion
234464
234598
  //#region src/ptz-zoom.ts
234465
234599
  /**
@@ -235433,6 +235567,7 @@ function slicesForPatch(patch) {
235433
235567
  if (has("pirReduceFalseAlarm")) out.add("pir");
235434
235568
  if (has("autoRebootEnabled", "autoRebootWeekDay", "autoRebootHour", "autoRebootMinute")) out.add("autoReboot");
235435
235569
  if (has("timeZoneId")) out.add("systemGeneral");
235570
+ if (has("powerSource")) out.add("powerSource");
235436
235571
  return out;
235437
235572
  }
235438
235573
  /**
@@ -235449,8 +235584,6 @@ var RefreshSettingsResultSchema = object({
235449
235584
  capsWarmed: number$1(),
235450
235585
  capsTotal: number$1()
235451
235586
  });
235452
- /** The two switch actions, one implementation each way. */
235453
- var POWER_SWITCH_ACTIONS = [["switch-to-wired-power", "adapter"], ["switch-to-battery-power", "battery"]];
235454
235587
  /** The uid out of a device's metadata bag, or nothing. Never a cast. */
235455
235588
  function metaUid(metadata) {
235456
235589
  if (metadata === null) return void 0;
@@ -236258,6 +236391,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
236258
236391
  } catch (err) {
236259
236392
  this.ctx.logger.debug("reolink getPirInfo probe failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
236260
236393
  }
236394
+ if (want("powerSource") && this.isBattery) cacheUpdate.powerSourceSnapshot = { source: await readPowerSource(await this.powerSourceTarget()) };
236261
236395
  if (want("autoReboot")) try {
236262
236396
  const reboot = await api.getAutoReboot();
236263
236397
  cacheUpdate.autoRebootSnapshot = {
@@ -236610,6 +236744,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
236610
236744
  runTest: false
236611
236745
  }, this.getChannel());
236612
236746
  this.ctx.logger.info("email-push: camera auto-configure applied", { tags: { deviceId: this.id } });
236747
+ if (params.authPassword !== void 0) await this.config.setAll({ emailPassword: params.authPassword });
236613
236748
  await this.refreshCameraEmailConfig().catch(() => {});
236614
236749
  }
236615
236750
  /**
@@ -236836,16 +236971,6 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
236836
236971
  capsTotal
236837
236972
  };
236838
236973
  });
236839
- if (this.isBattery) {
236840
- this.registerDeviceAction("read-power-source", deviceCustomAction(unknown(), ReadPowerSourceResultSchema, { kind: "mutation" }), async () => {
236841
- await this.wakeIfSleeping();
236842
- return { source: await readPowerSource(await this.powerSourceTarget()) };
236843
- });
236844
- for (const [action, mode] of POWER_SWITCH_ACTIONS) this.registerDeviceAction(action, deviceCustomAction(unknown(), SwitchPowerSourceResultSchema, { kind: "mutation" }), async () => {
236845
- await this.wakeIfSleeping();
236846
- return switchPowerSourceTo(await this.powerSourceTarget(), mode);
236847
- });
236848
- }
236849
236974
  this.registerDeviceAction("refresh-sessions", deviceCustomAction(unknown(), _void(), { kind: "mutation" }), async () => {
236850
236975
  await this.refreshSessionsSnapshot();
236851
236976
  });
@@ -237395,56 +237520,6 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
237395
237520
  };
237396
237521
  }
237397
237522
  /**
237398
- * Battery-cam power-source section (General tab): read the source, switch to
237399
- * wired or back to battery. Returns `[]` for a wired-only camera. The buttons
237400
- * dispatch the `read-power-source` / `switch-to-*-power` device actions.
237401
- */
237402
- buildPowerSourceSection() {
237403
- if (!this.isBattery) return [];
237404
- const switchMessage = "Switch {outcome} · before: {before} · after: {after} · applied: {applied}";
237405
- return [{
237406
- id: "power-source",
237407
- tab: "general",
237408
- title: "Power source",
237409
- titleKey: "provider-reolink:schema.s_power-source.title",
237410
- description: "Only switch to wired power when the adapter meets the camera's spec.",
237411
- descriptionKey: "provider-reolink:schema.s_power-source.description",
237412
- columns: 1,
237413
- fields: [
237414
- {
237415
- type: "device-action-button",
237416
- key: "_readPowerSource",
237417
- label: "Power source",
237418
- labelKey: "provider-reolink:schema.s_power-source._readPowerSource.label",
237419
- buttonLabel: "Read power source",
237420
- action: "read-power-source",
237421
- variant: "default",
237422
- successMessage: "Power source: {source}"
237423
- },
237424
- {
237425
- type: "device-action-button",
237426
- key: "_switchToWiredPower",
237427
- label: "Wired power",
237428
- labelKey: "provider-reolink:schema.s_power-source._switchToWiredPower.label",
237429
- buttonLabel: "Switch to wired power",
237430
- action: "switch-to-wired-power",
237431
- variant: "default",
237432
- successMessage: switchMessage
237433
- },
237434
- {
237435
- type: "device-action-button",
237436
- key: "_switchToBatteryPower",
237437
- label: "Battery power",
237438
- labelKey: "provider-reolink:schema.s_power-source._switchToBatteryPower.label",
237439
- buttonLabel: "Switch to battery power",
237440
- action: "switch-to-battery-power",
237441
- variant: "default",
237442
- successMessage: switchMessage
237443
- }
237444
- ]
237445
- }];
237446
- }
237447
- /**
237448
237523
  * Battery-cam Email Push auto-configure section. Returns `[]` for any
237449
237524
  * camera that wouldn't benefit (wired cams keep a live socket for
237450
237525
  * native push; hub children have no independent email path). The
@@ -237635,7 +237710,8 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
237635
237710
  if (typeof fields.emailSmtpServer === "string") patch.smtpServer = fields.emailSmtpServer;
237636
237711
  if (typeof fields.emailSmtpPort === "number") patch.smtpPort = fields.emailSmtpPort;
237637
237712
  if (typeof fields.emailUserName === "string") patch.userName = fields.emailUserName;
237638
- if (typeof fields.emailPassword === "string" && fields.emailPassword.length > 0) patch.password = fields.emailPassword;
237713
+ const smtpPassword = smtpPasswordToWrite(fields.emailPassword);
237714
+ if (smtpPassword !== null) patch.password = smtpPassword;
237639
237715
  if (typeof fields.emailSsl === "boolean") patch.ssl = fields.emailSsl ? 1 : 0;
237640
237716
  if (typeof fields.emailRecipient1 === "string") patch.address1 = fields.emailRecipient1;
237641
237717
  if (typeof fields.emailRecipient2 === "string") patch.address2 = fields.emailRecipient2;
@@ -242356,7 +242432,10 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
242356
242432
  }),
242357
242433
  ...this.buildSessionsTabSections(),
242358
242434
  ...this.buildEmailPushSection(),
242359
- ...this.buildPowerSourceSection(),
242435
+ ...buildPowerSourceSettingsSection({
242436
+ isBattery: this.isBattery,
242437
+ source: cache?.powerSourceSnapshot?.source
242438
+ }),
242360
242439
  ...this.buildEmailTabSections(),
242361
242440
  ...buildClipRefreshDeviceSection({
242362
242441
  isHubChild: this.isHubChild(),
@@ -242385,7 +242464,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
242385
242464
  emailSmtpServer: emailSnap?.smtpServer ?? "",
242386
242465
  emailSmtpPort: emailSnap?.smtpPort ?? 587,
242387
242466
  emailUserName: emailSnap?.userName ?? "",
242388
- emailPassword: "",
242467
+ emailPassword: this.config.get("emailPassword"),
242389
242468
  emailSsl: emailSnap?.ssl ?? false,
242390
242469
  emailRecipient1: emailSnap?.recipients?.[0] ?? "",
242391
242470
  emailRecipient2: emailSnap?.recipients?.[1] ?? "",
@@ -242452,6 +242531,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
242452
242531
  audioNoiseLevel: this.config.get("audioNoiseLevel") ?? (cache?.audioNoiseSnapshot?.enabled ? cache.audioNoiseSnapshot?.level ?? 1 : 0),
242453
242532
  autoFocusEnabled: this.config.get("autoFocusEnabled") ?? cache?.autoFocusSnapshot?.enabled ?? true,
242454
242533
  pirReduceFalseAlarm: this.config.get("pirReduceFalseAlarm") ?? cache?.pirSnapshot?.reduceFalseAlarm ?? false,
242534
+ ...cache?.powerSourceSnapshot !== void 0 ? { [POWER_SOURCE_SETTING_KEY]: cache.powerSourceSnapshot.source } : {},
242455
242535
  gop: this.config.get("gop") ?? cache?.encSnapshot?.mainStream?.gop ?? 4,
242456
242536
  autoRebootEnabled: this.config.get("autoRebootEnabled") ?? cache?.autoRebootSnapshot?.enabled ?? false,
242457
242537
  autoRebootWeekDay: this.config.get("autoRebootWeekDay") ?? cache?.autoRebootSnapshot?.weekDay ?? "everyday",
@@ -242481,8 +242561,8 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
242481
242561
  }
242482
242562
  async applySettingsPatch(patch) {
242483
242563
  if (this.isHubChild()) this.refuseHubChildPatch(patch);
242484
- const { emailSmtpServer, emailSmtpPort, emailUserName, emailPassword, emailSsl, emailRecipient1, emailRecipient2, emailRecipient3, emailSendNickname, emailScheduleEnabled, osdChannelEnabled, osdChannelName, osdChannelPosition, osdTimeEnabled, osdTimePosition, osdWatermark, hubName: _hubName, ...rest } = patch;
242485
- 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 } });
242564
+ const { emailSmtpServer, emailSmtpPort, emailUserName, emailPassword, emailSsl, emailRecipient1, emailRecipient2, emailRecipient3, emailSendNickname, emailScheduleEnabled, osdChannelEnabled, osdChannelName, osdChannelPosition, osdTimeEnabled, osdTimePosition, osdWatermark, hubName: _hubName, [POWER_SOURCE_SETTING_KEY]: powerSource, ...rest } = patch;
242565
+ 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 || powerSource !== void 0) && !await this.wakeIfSleeping()) this.ctx.logger.warn("settings write: battery cam did not wake — writing anyway", { tags: { deviceId: this.id } });
242486
242566
  const emailFields = {
242487
242567
  emailSmtpServer,
242488
242568
  emailSmtpPort,
@@ -242495,12 +242575,18 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
242495
242575
  emailSendNickname,
242496
242576
  emailScheduleEnabled
242497
242577
  };
242498
- if (Object.values(emailFields).some((v) => v !== void 0)) await this.applyEmailConfigPatch(emailFields).catch((err) => {
242499
- this.ctx.logger.warn("email config write failed", {
242500
- tags: { deviceId: this.id },
242501
- meta: { error: err instanceof Error ? err.message : String(err) }
242578
+ if (Object.values(emailFields).some((v) => v !== void 0)) {
242579
+ let written = true;
242580
+ await this.applyEmailConfigPatch(emailFields).catch((err) => {
242581
+ written = false;
242582
+ this.ctx.logger.warn("email config write failed", {
242583
+ tags: { deviceId: this.id },
242584
+ meta: { error: err instanceof Error ? err.message : String(err) }
242585
+ });
242502
242586
  });
242503
- });
242587
+ const stored = smtpPasswordToWrite(emailPassword);
242588
+ if (written && stored !== null) await this.config.setAll({ emailPassword: stored });
242589
+ }
242504
242590
  const osdPatch = buildOsdPatch({
242505
242591
  osdChannelEnabled,
242506
242592
  osdChannelName,
@@ -242517,6 +242603,10 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
242517
242603
  osdTimePosition,
242518
242604
  osdWatermark
242519
242605
  ].some((v) => v !== void 0);
242606
+ if (powerSource !== void 0) {
242607
+ await applyPowerSourceSetting(await this.powerSourceTarget(), powerSource);
242608
+ await this.refreshParentSettingsSnapshot(new Set(["powerSource"]), "post-write");
242609
+ }
242520
242610
  if (Object.keys(rest).length === 0 && !hasOsdPatch) return;
242521
242611
  if (Object.keys(rest).length > 0) await this.config.setAll(rest);
242522
242612
  const typedPatch = patch;
@@ -242951,6 +243041,11 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
242951
243041
  isSleeping() {
242952
243042
  return this.sleeping;
242953
243043
  }
243044
+ /** Implements `ReolinkAccessoryHost.wakeForWrite`: an accessory's operator
243045
+ * write (PIR, ...) wakes a sleeping battery camera first. */
243046
+ wakeForWrite() {
243047
+ return this.wakeIfSleeping();
243048
+ }
242954
243049
  async ensureApi() {
242955
243050
  if (this.isHubChild()) {
242956
243051
  const session = this.hubSession();
@@ -243975,6 +244070,8 @@ var EmailPushBridge = class {
243975
244070
  /** The last failure that was reported, so a mailbox provider that stays away is said once. */
243976
244071
  lastFailure = null;
243977
244072
  chain = Promise.resolve();
244073
+ /** The integrations whose empty link this process filled (only those are released). */
244074
+ filled = /* @__PURE__ */ new Set();
243978
244075
  constructor(deps) {
243979
244076
  this.deps = deps;
243980
244077
  }
@@ -244045,43 +244142,104 @@ var EmailPushBridge = class {
244045
244142
  const recipients = this.recipients();
244046
244143
  if (recipients.length === 0) {
244047
244144
  if (this.brokerId !== null && this.subscriptionId !== null) await this.deps.port.unsubscribe(this.brokerId, this.subscriptionId);
244048
- if (this.brokerId !== null) await this.syncLinks(this.brokerId, /* @__PURE__ */ new Set());
244145
+ if (this.brokerId !== null) await this.syncLinks(this.brokerId, await this.tryDefaultId(), false);
244049
244146
  this.subscriptionId = null;
244050
244147
  this.declared = null;
244051
244148
  return;
244052
244149
  }
244053
- const owners = this.linkOwners();
244054
- const key = `${recipients.join(",")}|${[...owners].sort().join(",")}`;
244150
+ const { defaultId, complete } = await this.resolveDefault();
244151
+ const picked = await this.pickedMailbox(defaultId);
244152
+ const key = `${recipients.join(",")}|${defaultId ?? ""}|${picked ?? this.brokerId ?? ""}`;
244055
244153
  if (!force && this.declared === key && this.subscriptionId !== null) return;
244056
- const brokerId = await this.ensureMailbox();
244154
+ const brokerId = picked ?? await this.ensureMailbox();
244155
+ if (this.brokerId !== null && this.brokerId !== brokerId && this.subscriptionId !== null) {
244156
+ await this.deps.port.unsubscribe(this.brokerId, this.subscriptionId);
244157
+ this.subscriptionId = null;
244158
+ }
244057
244159
  await this.seedBaseline(brokerId);
244058
244160
  const { subscriptionId } = await this.deps.port.subscribe(brokerId, recipients);
244059
244161
  this.brokerId = brokerId;
244060
244162
  this.subscriptionId = subscriptionId;
244061
- this.declared = await this.syncLinks(brokerId, owners) ? key : null;
244163
+ const linked = await this.syncLinks(brokerId, defaultId, true);
244164
+ this.declared = linked && complete ? `${recipients.join(",")}|${defaultId ?? ""}|${brokerId}` : null;
244062
244165
  await this.reconcile();
244063
244166
  }
244064
- /** The integrations whose standalone cameras mail the mailbox: they link to it. */
244065
- linkOwners() {
244066
- const owners = /* @__PURE__ */ new Set();
244067
- for (const cam of this.deps.listCameras()) if (cam.isEmailPushEligible && cam.integrationId !== null) owners.add(cam.integrationId);
244068
- return owners;
244167
+ /**
244168
+ * The default integration holds the mailbox link for every email-push camera (a hub child's
244169
+ * integration carries none). `complete` is false when it could not be resolved: the caller
244170
+ * retries at the next sync.
244171
+ */
244172
+ async resolveDefault() {
244173
+ const cam = this.deps.listCameras().find((c) => c.isEmailPushEligible);
244174
+ const tags = cam === void 0 ? {} : { tags: { deviceId: cam.id } };
244175
+ let defaultId = null;
244176
+ try {
244177
+ defaultId = await this.deps.defaultIntegrationId();
244178
+ } catch (err) {
244179
+ this.deps.logger.warn("email-push: the default integration could not be read", {
244180
+ ...tags,
244181
+ meta: { error: errMsg(err) }
244182
+ });
244183
+ return {
244184
+ defaultId: null,
244185
+ complete: false
244186
+ };
244187
+ }
244188
+ if (defaultId === null) {
244189
+ this.deps.logger.warn("email-push: a camera uses the mailbox but the default integration is not resolved yet; retrying at the next sync", tags);
244190
+ return {
244191
+ defaultId: null,
244192
+ complete: false
244193
+ };
244194
+ }
244195
+ return {
244196
+ defaultId,
244197
+ complete: true
244198
+ };
244199
+ }
244200
+ async tryDefaultId() {
244201
+ try {
244202
+ return await this.deps.defaultIntegrationId();
244203
+ } catch {
244204
+ return null;
244205
+ }
244206
+ }
244207
+ /**
244208
+ * The mailbox the operator picked on the default integration, or null while none is picked.
244209
+ * A pick that no mailbox answers to throws: the bridge never swaps it for another one.
244210
+ */
244211
+ async pickedMailbox(defaultId) {
244212
+ if (defaultId === null) return null;
244213
+ const row = (await this.deps.links.list()).find((r) => r.id === defaultId);
244214
+ if (row === void 0 || row.mailboxId === "") return null;
244215
+ if (!(await this.deps.port.list()).some((m) => m.id === row.mailboxId)) throw new Error(`the camera mailbox picked on the default integration (${row.mailboxId}) does not exist`);
244216
+ return row.mailboxId;
244217
+ }
244218
+ /** The mailbox a camera is pointed at: the operator's pick, else the one this addon adopts or creates. */
244219
+ async resolveMailbox() {
244220
+ return await this.pickedMailbox(await this.tryDefaultId()) ?? await this.ensureMailbox();
244069
244221
  }
244070
244222
  /**
244071
- * Make the `mailboxId` links say who uses the mailbox: `owners` link to it, no other
244072
- * integration does. Idempotent, so an install whose mailbox already exists is filled from it
244073
- * (the mailbox is re-adopted by `ensureMailbox`) with nothing stored beforehand. False when the
244074
- * links could not be written: the caller retries at the next sync.
244223
+ * Make the `mailboxId` link of the DEFAULT integration say it uses the mailbox. It is filled only
244224
+ * while empty (a pick of the operator is never overwritten) and released only if this process
244225
+ * filled it. A hub integration carries no link: a stale one is cleared. With no default
244226
+ * resolved nothing is touched. False when the links could not be written.
244075
244227
  */
244076
- async syncLinks(brokerId, owners) {
244228
+ async syncLinks(brokerId, defaultId, inUse) {
244229
+ if (defaultId === null) return true;
244077
244230
  try {
244078
244231
  const rows = await this.deps.links.list();
244079
- for (const row of rows) {
244080
- const wanted = owners.has(row.id) ? brokerId : "";
244081
- if (row.mailboxId !== wanted) await this.deps.links.set(row.id, wanted);
244082
- }
244083
- for (const owner of owners) if (!rows.some((row) => row.id === owner)) this.deps.logger.warn("email-push: an integration with email-push cameras has no record to link the mailbox from", { meta: {
244084
- integrationId: owner,
244232
+ for (const row of rows) if (row.id !== defaultId) {
244233
+ if (row.mailboxId !== "") await this.deps.links.set(row.id, "");
244234
+ } else if (inUse && row.mailboxId === "") {
244235
+ await this.deps.links.set(row.id, brokerId);
244236
+ this.filled.add(row.id);
244237
+ } else if (!inUse && this.filled.has(row.id) && row.mailboxId === brokerId) {
244238
+ await this.deps.links.set(row.id, "");
244239
+ this.filled.delete(row.id);
244240
+ }
244241
+ if (inUse && !rows.some((row) => row.id === defaultId)) this.deps.logger.warn("email-push: the default integration has no record to link the mailbox from", { meta: {
244242
+ integrationId: defaultId,
244085
244243
  brokerId
244086
244244
  } });
244087
244245
  return true;
@@ -244220,7 +244378,7 @@ var EmailPushBridge = class {
244220
244378
  */
244221
244379
  async buildCameraSetupParams(cam) {
244222
244380
  if (!cam.isEmailPushEligible) return null;
244223
- const brokerId = await this.ensureMailbox();
244381
+ const brokerId = await this.resolveMailbox();
244224
244382
  const parsed = SmtpInboundConfigSchema.safeParse(await this.deps.port.getBrokerConfig(brokerId));
244225
244383
  if (!parsed.success) throw new Error("The camera mailbox answered a configuration this build cannot read");
244226
244384
  const config = parsed.data;
@@ -244242,6 +244400,60 @@ function pickMailbox(list) {
244242
244400
  return list.find((b) => b.id === "smtp-inbound-default")?.id ?? list[0]?.id ?? null;
244243
244401
  }
244244
244402
  //#endregion
244403
+ //#region src/email-push-removal-hook.ts
244404
+ /**
244405
+ * A removed camera leaves its `cam-<stableId>` recipient in the mailbox (D865). The addon holds
244406
+ * no per-device DATA for the intake (the mailbox is owned by the mail addon), so removal only
244407
+ * redeclares the recipient set without the camera. Driven by the tombstone, never by absence.
244408
+ */
244409
+ function createEmailPushRemovalHook(deps) {
244410
+ return {
244411
+ onDeviceRemoved: async () => {
244412
+ await deps.resync();
244413
+ return { counts: { "mailbox-recipients": 0 } };
244414
+ },
244415
+ listDeviceData: async () => []
244416
+ };
244417
+ }
244418
+ var LEGACY_PREFIX = "/webhook/";
244419
+ async function startLegacyWebhookIntake(deps) {
244420
+ const warned = /* @__PURE__ */ new Set();
244421
+ const server = (0, node_http.createServer)((req, res) => {
244422
+ const url = req.url ?? "";
244423
+ if (!url.startsWith(LEGACY_PREFIX)) {
244424
+ res.writeHead(404).end();
244425
+ return;
244426
+ }
244427
+ const rest = url.slice(8);
244428
+ req.url = rest;
244429
+ const id = decodeURIComponent(rest.replace(/^\//, "").split("?")[0] ?? "");
244430
+ const camera = deps.listCameras().find((c) => c.stableId === id);
244431
+ if (camera !== void 0 && !warned.has(id)) {
244432
+ warned.add(id);
244433
+ deps.logger.warn("legacy webhook port used — camera will be re-pointed", {
244434
+ tags: { deviceId: camera.id },
244435
+ meta: { port: deps.port ?? 9081 }
244436
+ });
244437
+ }
244438
+ Promise.resolve(deps.handler(req, res)).catch((err) => {
244439
+ deps.logger.error("legacy webhook intake failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
244440
+ if (!res.headersSent) res.writeHead(500);
244441
+ res.end();
244442
+ });
244443
+ });
244444
+ await new Promise((resolve, reject) => {
244445
+ server.once("error", reject);
244446
+ server.listen(deps.port ?? 9081, "0.0.0.0", () => {
244447
+ server.off("error", reject);
244448
+ resolve();
244449
+ });
244450
+ });
244451
+ return {
244452
+ server,
244453
+ close: () => new Promise((resolve) => server.close(() => resolve()))
244454
+ };
244455
+ }
244456
+ //#endregion
244245
244457
  //#region src/reolink-connection-test.ts
244246
244458
  /**
244247
244459
  * The Reolink NVR / Home Hub connection test (planning#581): log in over Baichuan with the
@@ -244349,6 +244561,28 @@ var reolinkConnectionsEntryKind = defineEntryKind("connections", {
244349
244561
  }),
244350
244562
  writeTrigger: "an operator adds, edits or removes a Reolink integration"
244351
244563
  });
244564
+ /** The kind of the default integration (standalone cameras): a name and the mailbox link, no Test. */
244565
+ var REOLINK_DEFAULT_KIND = "default";
244566
+ /** The kind of an NVR / Home Hub integration: its connection, with a Test. */
244567
+ var REOLINK_HUB_KIND = "connection";
244568
+ /** The form of the default integration: which camera mailbox its standalone cameras use. */
244569
+ function buildDefaultInstanceSchema() {
244570
+ return { sections: [{
244571
+ id: "mailbox",
244572
+ title: "Camera mailbox",
244573
+ titleKey: "provider-reolink:connection.s_mailbox.title",
244574
+ description: "The mailbox the standalone cameras send their email push to.",
244575
+ descriptionKey: "provider-reolink:connection.s_mailbox.description",
244576
+ columns: 1,
244577
+ fields: [{
244578
+ ...linkFieldDescriptor(MAILBOX_LINK_FIELD, SMTP_MAILBOX_LINK, {
244579
+ label: "Camera mailbox",
244580
+ required: false
244581
+ }),
244582
+ labelKey: "provider-reolink:connection.s_mailbox.mailboxId.label"
244583
+ }]
244584
+ }] };
244585
+ }
244352
244586
  /** Every kind this addon declares, keyed by its name. */
244353
244587
  var reolinkRecordKinds = { connections: reolinkConnectionsEntryKind };
244354
244588
  /**
@@ -244455,12 +244689,26 @@ function buildReolinkInstances(records, deps) {
244455
244689
  kind: "connection",
244456
244690
  canTest: true,
244457
244691
  kinds: [{
244458
- id: "connection",
244459
- label: "Reolink",
244692
+ id: REOLINK_DEFAULT_KIND,
244693
+ label: "Reolink standalone cameras",
244694
+ functionCap: "device-provider",
244695
+ role: "devices",
244696
+ canTest: false,
244697
+ creatable: false
244698
+ }, {
244699
+ id: REOLINK_HUB_KIND,
244700
+ label: "Reolink NVR / Home Hub",
244460
244701
  functionCap: "device-provider",
244461
- role: "devices"
244702
+ role: "devices",
244703
+ canTest: true
244704
+ }],
244705
+ links: [{
244706
+ kind: REOLINK_DEFAULT_KIND,
244707
+ field: MAILBOX_LINK_FIELD,
244708
+ to: SMTP_MAILBOX_LINK
244462
244709
  }]
244463
244710
  },
244711
+ kindOf: () => REOLINK_HUB_KIND,
244464
244712
  formSchema: () => buildHubInstanceSchema(),
244465
244713
  initialBody: (name) => ({ name }),
244466
244714
  configured: (body) => (body.host ?? "").length === 0 || (body.password ?? "").length > 0,
@@ -244474,10 +244722,15 @@ function buildReolinkInstances(records, deps) {
244474
244722
  */
244475
244723
  function reolinkInstancesProvider(instances, deps) {
244476
244724
  const base = instances.toProvider();
244477
- const withAddDevice = async (instance) => ({
244478
- ...instance,
244479
- addDevice: await integrationIsHubCached(instances, deps.evidenceCache, instance.id) ? "children" : "scan"
244480
- });
244725
+ const withAddDevice = async (instance) => {
244726
+ const isHub = await integrationIsHubCached(instances, deps.evidenceCache, instance.id);
244727
+ const known = deps.evidenceCache.get(instance.id) !== null;
244728
+ return {
244729
+ ...instance,
244730
+ kind: known && !isHub ? REOLINK_DEFAULT_KIND : REOLINK_HUB_KIND,
244731
+ addDevice: isHub ? "children" : "scan"
244732
+ };
244733
+ };
244481
244734
  return {
244482
244735
  ...base,
244483
244736
  listInstances: async (input) => Promise.all((await base.listInstances(input)).map(withAddDevice)),
@@ -244493,7 +244746,7 @@ function reolinkInstancesProvider(instances, deps) {
244493
244746
  originStableId: evidence.originStableId,
244494
244747
  info: evidence.info,
244495
244748
  settings: body === null ? {} : hubSettingsOf(body)
244496
- }) || body === null ? buildHubInstanceSchema() : { sections: [] };
244749
+ }) || body === null ? buildHubInstanceSchema() : buildDefaultInstanceSchema();
244497
244750
  }
244498
244751
  };
244499
244752
  }
@@ -244545,60 +244798,6 @@ function mailboxLinkStoreOver(records) {
244545
244798
  };
244546
244799
  }
244547
244800
  //#endregion
244548
- //#region src/email-push-removal-hook.ts
244549
- /**
244550
- * A removed camera leaves its `cam-<stableId>` recipient in the mailbox (D865). The addon holds
244551
- * no per-device DATA for the intake (the mailbox is owned by the mail addon), so removal only
244552
- * redeclares the recipient set without the camera. Driven by the tombstone, never by absence.
244553
- */
244554
- function createEmailPushRemovalHook(deps) {
244555
- return {
244556
- onDeviceRemoved: async () => {
244557
- await deps.resync();
244558
- return { counts: { "mailbox-recipients": 0 } };
244559
- },
244560
- listDeviceData: async () => []
244561
- };
244562
- }
244563
- var LEGACY_PREFIX = "/webhook/";
244564
- async function startLegacyWebhookIntake(deps) {
244565
- const warned = /* @__PURE__ */ new Set();
244566
- const server = (0, node_http.createServer)((req, res) => {
244567
- const url = req.url ?? "";
244568
- if (!url.startsWith(LEGACY_PREFIX)) {
244569
- res.writeHead(404).end();
244570
- return;
244571
- }
244572
- const rest = url.slice(8);
244573
- req.url = rest;
244574
- const id = decodeURIComponent(rest.replace(/^\//, "").split("?")[0] ?? "");
244575
- const camera = deps.listCameras().find((c) => c.stableId === id);
244576
- if (camera !== void 0 && !warned.has(id)) {
244577
- warned.add(id);
244578
- deps.logger.warn("legacy webhook port used — camera will be re-pointed", {
244579
- tags: { deviceId: camera.id },
244580
- meta: { port: deps.port ?? 9081 }
244581
- });
244582
- }
244583
- Promise.resolve(deps.handler(req, res)).catch((err) => {
244584
- deps.logger.error("legacy webhook intake failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
244585
- if (!res.headersSent) res.writeHead(500);
244586
- res.end();
244587
- });
244588
- });
244589
- await new Promise((resolve, reject) => {
244590
- server.once("error", reject);
244591
- server.listen(deps.port ?? 9081, "0.0.0.0", () => {
244592
- server.off("error", reject);
244593
- resolve();
244594
- });
244595
- });
244596
- return {
244597
- server,
244598
- close: () => new Promise((resolve) => server.close(() => resolve()))
244599
- };
244600
- }
244601
- //#endregion
244602
244801
  //#region src/migrations/drop-webhook-intake-settings.ts
244603
244802
  /**
244604
244803
  * The camera webhook is a plane of the addon's HTTP data plane, not a private listener
@@ -244819,6 +245018,14 @@ var REOLINK_MIGRATIONS = [{
244819
245018
  },
244820
245019
  plan: planDropWebhookIntakeSettings
244821
245020
  }];
245021
+ /** The date of the device claim (D1007). */
245022
+ var CLAIM_DEVICES_DATE = "2026-11-04";
245023
+ /**
245024
+ * Every persisted camera that names no integration is claimed to the addon's default one. The
245025
+ * integration a hub migration created is never the default, so it is not eligible. The integration
245026
+ * settings themselves stay where they are until this addon's own wave moves them.
245027
+ */
245028
+ var REOLINK_CLAIM_ELIGIBLE = (integration) => integration.info[MIGRATED_FROM_HUB_KEY] === void 0;
244822
245029
  /**
244823
245030
  * The integration wave (D1007) in declaration order, which must follow `seq`: the device claim
244824
245031
  * shipped first (seq 3) and the rows move follows it (seq 4). The engine refuses the whole
@@ -244826,10 +245033,10 @@ var REOLINK_MIGRATIONS = [{
244826
245033
  */
244827
245034
  var REOLINK_INTEGRATION_MIGRATIONS = [claimDevicesMigration({
244828
245035
  addonId: "provider-reolink",
244829
- date: "2026-11-04",
245036
+ date: CLAIM_DEVICES_DATE,
244830
245037
  seq: 3,
244831
245038
  dependsOn: [],
244832
- eligible: (integration) => integration.info[MIGRATED_FROM_HUB_KEY] === void 0
245039
+ eligible: REOLINK_CLAIM_ELIGIBLE
244833
245040
  }), REOLINK_ROWS_TO_RECORD_MIGRATION];
244834
245041
  //#endregion
244835
245042
  //#region src/reolink-adoption-provider.ts
@@ -245681,12 +245888,24 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
245681
245888
  if (records === void 0) throw new Error("provider-reolink: ctx.records is required (hub-only addon)");
245682
245889
  return records;
245683
245890
  }
245891
+ /**
245892
+ * The registry id of the default integration (standalone cameras): the lowest-numbered one this
245893
+ * addon owns that no hub migration created, the same rule as the device claim (D1007).
245894
+ */
245895
+ async resolveDefaultIntegrationId() {
245896
+ return defaultIntegrationOf((await this.ctx.api.integrations.list.query()).filter((i) => i.addonId === this.ctx.id).map((i) => ({
245897
+ id: i.id,
245898
+ name: i.name,
245899
+ info: { ...i.info }
245900
+ })), REOLINK_CLAIM_ELIGIBLE)?.id ?? null;
245901
+ }
245684
245902
  /** The camera mailbox bridge, built once. */
245685
245903
  ensureEmailBridge() {
245686
245904
  this.emailBridge ??= new EmailPushBridge({
245687
245905
  port: createBrokerPort(this.ctx.api),
245688
245906
  links: mailboxLinkStoreOver(this.requireRecords()),
245689
245907
  listCameras: () => this.listReolinkCameras(),
245908
+ defaultIntegrationId: () => this.resolveDefaultIntegrationId(),
245690
245909
  logger: this.ctx.logger.child("email-push"),
245691
245910
  pending: {
245692
245911
  read: () => this.readPendingMailbox(),