@camstack/addon-export-hap 1.2.201 → 1.2.202

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.
@@ -57801,6 +57801,15 @@ var HeroTextSchema = object({
57801
57801
  it: string()
57802
57802
  });
57803
57803
  /**
57804
+ * What a device that has not reported says in place of its value: an empty "—",
57805
+ * never a word like "Unknown" and never a 0 (D393). The card stays its normal
57806
+ * self; only the value is empty.
57807
+ */
57808
+ var NOT_REPORTED = {
57809
+ en: "—",
57810
+ it: "—"
57811
+ };
57812
+ /**
57804
57813
  * The ONE measurement a simple sensor shows (card wave, phase 1).
57805
57814
  *
57806
57815
  * A sensor that measures a single quantity (a temperature, a humidity, a power,
@@ -57917,6 +57926,62 @@ function textMeasurement(text, since) {
57917
57926
  historyKey: null
57918
57927
  };
57919
57928
  }
57929
+ /** What each quantity draws beside its value, reported or not. */
57930
+ var QUANTITY_FACE = {
57931
+ temperature: {
57932
+ icon: "thermometer",
57933
+ unit: "°C",
57934
+ sinceKind: "updated",
57935
+ historyKey: "cap:temperature-sensor.temperature"
57936
+ },
57937
+ humidity: {
57938
+ icon: "droplets",
57939
+ unit: "%",
57940
+ sinceKind: "updated",
57941
+ historyKey: "cap:humidity-sensor.humidity"
57942
+ },
57943
+ power: {
57944
+ icon: "zap",
57945
+ unit: "W",
57946
+ sinceKind: "updated",
57947
+ historyKey: "cap:power-meter.power"
57948
+ },
57949
+ contact: {
57950
+ icon: null,
57951
+ unit: null,
57952
+ sinceKind: "changed",
57953
+ historyKey: null
57954
+ },
57955
+ text: {
57956
+ icon: null,
57957
+ unit: null,
57958
+ sinceKind: "updated",
57959
+ historyKey: null
57960
+ }
57961
+ };
57962
+ /**
57963
+ * The measurement of a sensor that has not reported yet: its normal card with
57964
+ * an empty "—" value and its unit — never a placeholder, never a 0 (D393). The
57965
+ * reading is `null` (nothing to format), the scene does not move, and nothing
57966
+ * claims a moment.
57967
+ */
57968
+ function emptyMeasurement(quantity) {
57969
+ const face = QUANTITY_FACE[quantity];
57970
+ return {
57971
+ quantity,
57972
+ reading: null,
57973
+ icon: face.icon,
57974
+ value: NOT_REPORTED,
57975
+ unit: face.unit,
57976
+ band: null,
57977
+ level: null,
57978
+ word: NOT_REPORTED,
57979
+ tone: "muted",
57980
+ since: null,
57981
+ sinceKind: face.sinceKind,
57982
+ historyKey: face.historyKey
57983
+ };
57984
+ }
57920
57985
  /** The scene as the model carries it. `null` = the device did not say (never a guess). */
57921
57986
  var HeroSceneSchema = object({
57922
57987
  id: _enum([
@@ -81210,7 +81275,7 @@ var lockContribution = contribution("lock-control", LockControlStatusSchema, (sl
81210
81275
  const state = slice?.state ?? null;
81211
81276
  const words = state === null ? null : LOCK_WORDS[state];
81212
81277
  const since = slice === void 0 ? null : elapsedText(slice.lastChangedAt, ctx.now);
81213
- const title = words?.title ?? t("Unknown", "Sconosciuto");
81278
+ const title = words?.title ?? NOT_REPORTED;
81214
81279
  return {
81215
81280
  reading: reading("lock-control", words?.state ?? "unknown", false, words?.title),
81216
81281
  rows: [row$1("lock", state === "locked" || state === "locking" ? "lock" : "lock-open", joinText([title, since]), lockControls(state, ctx.features.includes(DeviceFeature.LockOpen)))],
@@ -81302,7 +81367,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81302
81367
  const modes = slice === void 0 ? ALARM_MODES : slice.availableModes;
81303
81368
  return {
81304
81369
  reading: reading("alarm-panel", words?.state ?? "unknown", false, words?.title),
81305
- rows: [row$1("alarm", state === "triggered" ? "shield-alert" : state === "disarmed" ? "shield-off" : "shield-check", joinText([words?.title ?? t("Unknown", "Sconosciuto"), since]), alarmControls(state, modes, slice?.requiresCode ?? false))],
81370
+ rows: [row$1("alarm", state === "triggered" ? "shield-alert" : state === "disarmed" ? "shield-off" : "shield-check", joinText([words?.title ?? NOT_REPORTED, since]), alarmControls(state, modes, slice?.requiresCode ?? false))],
81306
81371
  ...since === null || words === null ? {} : { facts: [fact("since", "clock", since, state === "triggered" ? "danger" : "muted")] },
81307
81372
  ...words === null ? {} : { tiles: {
81308
81373
  left: [{
@@ -81333,7 +81398,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81333
81398
  return {
81334
81399
  reading: reading("automation-control", state, false, title),
81335
81400
  rows: [row$1("automation", "workflow", joinText([
81336
- title ?? t("Unknown", "Sconosciuto"),
81401
+ title ?? NOT_REPORTED,
81337
81402
  last === null ? null : t(`Ran ${last.en}`, `Eseguita ${last.it}`),
81338
81403
  slice?.lastError == null ? null : t(slice.lastError, slice.lastError)
81339
81404
  ]), [asAction(run), toggle])],
@@ -81349,7 +81414,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81349
81414
  return {
81350
81415
  reading: reading("script-runner", state, false, title),
81351
81416
  rows: [row$1("script", "scroll-text", joinText([
81352
- title ?? t("Unknown", "Sconosciuto"),
81417
+ title ?? NOT_REPORTED,
81353
81418
  last === null ? null : t(`Ran ${last.en}`, `Eseguito ${last.it}`),
81354
81419
  slice?.lastError == null ? null : t(slice.lastError, slice.lastError)
81355
81420
  ]), [asAction(control)])],
@@ -81358,7 +81423,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81358
81423
  }),
81359
81424
  "do-not-disturb": contribution("do-not-disturb", DoNotDisturbStatusSchema, (slice) => {
81360
81425
  const on = slice?.enabled ?? null;
81361
- return { rows: [row$1("do-not-disturb", "bell-off", on === null ? t("Unknown", "Sconosciuto") : on ? t("Do not disturb on", "Non disturbare attivo") : t("Do not disturb off", "Non disturbare spento"), [{
81426
+ return { rows: [row$1("do-not-disturb", "bell-off", on === null ? NOT_REPORTED : on ? t("Do not disturb on", "Non disturbare attivo") : t("Do not disturb off", "Non disturbare spento"), [{
81362
81427
  kind: "toggle",
81363
81428
  id: "do-not-disturb.toggle",
81364
81429
  label: t("Do not disturb", "Non disturbare"),
@@ -81376,7 +81441,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81376
81441
  * is absent from the facts, never a zero (D393).
81377
81442
  */
81378
81443
  var has$3 = (ctx, f) => ctx.features.includes(f);
81379
- var unknownText = t("Unknown", "Sconosciuto");
81444
+ var unknownText = NOT_REPORTED;
81380
81445
  var pct$2 = (n) => t(`${Math.round(n)}%`, `${Math.round(n)}%`);
81381
81446
  var unit = (n) => Math.min(1, Math.max(0, n / 100));
81382
81447
  /** Battery as a fact, unless the device is also bound to the `battery` cap (it already says so). */
@@ -82782,13 +82847,13 @@ function sensorFragment(value, id, icon, en, it, text) {
82782
82847
  tiles: { right: [tile$1(en, it, text)] }
82783
82848
  };
82784
82849
  }
82785
- var temperatureContribution = contribution("temperature-sensor", TemperatureSensorStatusSchema, (slice) => measured(sensorFragment(slice?.temperature ?? null, "temperature", "thermometer", "Temperature", "Temperatura", formatDegrees(slice?.temperature ?? 0)), slice?.temperature == null ? void 0 : temperatureMeasurement(slice.temperature, slice.lastFetchedAt)));
82786
- var humidityContribution = contribution("humidity-sensor", HumiditySensorStatusSchema, (slice) => measured(sensorFragment(slice?.humidity ?? null, "humidity", "droplets", "Humidity", "Umidità", `${Math.round(slice?.humidity ?? 0)}%`), slice?.humidity == null ? void 0 : humidityMeasurement(slice.humidity, slice.lastFetchedAt)));
82850
+ var temperatureContribution = contribution("temperature-sensor", TemperatureSensorStatusSchema, (slice) => measured(sensorFragment(slice?.temperature ?? null, "temperature", "thermometer", "Temperature", "Temperatura", formatDegrees(slice?.temperature ?? 0)), slice?.temperature == null ? emptyMeasurement("temperature") : temperatureMeasurement(slice.temperature, slice.lastFetchedAt)));
82851
+ var humidityContribution = contribution("humidity-sensor", HumiditySensorStatusSchema, (slice) => measured(sensorFragment(slice?.humidity ?? null, "humidity", "droplets", "Humidity", "Umidità", `${Math.round(slice?.humidity ?? 0)}%`), slice?.humidity == null ? emptyMeasurement("humidity") : humidityMeasurement(slice.humidity, slice.lastFetchedAt)));
82787
82852
  var pressureContribution = contribution("pressure-sensor", PressureSensorStatusSchema, (slice) => sensorFragment(slice?.pressure ?? null, "pressure", "gauge", "Pressure", "Pressione", `${Math.round(slice?.pressure ?? 0)} hPa`));
82788
82853
  var illuminanceContribution = contribution("ambient-light-sensor", AmbientLightSensorStatusSchema, (slice) => sensorFragment(slice?.illuminance ?? null, "illuminance", "sun", "Light", "Luce", `${Math.round(slice?.illuminance ?? 0)} lx`));
82789
82854
  var numericContribution = contribution("numeric-sensor", NumericSensorStatusSchema, (slice) => sensorFragment(slice?.value ?? null, "reading", "gauge", "Value", "Valore", String(Number((slice?.value ?? 0).toFixed(2)))));
82790
82855
  var enumContribution = contribution("enum-sensor", EnumSensorStatusSchema, (slice) => {
82791
- if (slice === void 0 || slice.value === "") return { reading: reading("sensor", "unknown") };
82856
+ if (slice === void 0 || slice.value === "") return measured({ reading: reading("sensor", "unknown") }, emptyMeasurement("text"));
82792
82857
  if (slice.timestamp === true) return { reading: reading("sensor", "on") };
82793
82858
  return measured(sensorFragment(slice.value, "reading", "gauge", "State", "Stato", slice.value), textMeasurement(slice.value, slice.lastFetchedAt));
82794
82859
  });
@@ -82912,7 +82977,7 @@ function circuitControl(circuit) {
82912
82977
  return picker(`heat-pump.${circuit.id}.mode`, t("Mode", "Modalità"), circuit.operationMode, method, args);
82913
82978
  }
82914
82979
  /** A circuit with no reading is still a row: it shows that nothing is known, not nothing. */
82915
- var UNKNOWN_STATUS = same("—");
82980
+ var UNKNOWN_STATUS = NOT_REPORTED;
82916
82981
  function circuitRow(circuit) {
82917
82982
  const control = circuitControl(circuit);
82918
82983
  const status = thermalStatusText(circuit.targetTemp, circuit.currentTemp) ?? UNKNOWN_STATUS;
@@ -83136,9 +83201,8 @@ function look(icon, tone, background, animation) {
83136
83201
  animation
83137
83202
  };
83138
83203
  }
83139
- /** A state a device is in whatever it is: unreachable, or silent. Identical for every look. */
83204
+ /** Unreachable: identical for every look. */
83140
83205
  var OFFLINE = look("wifi-off", "muted", "plain", "none");
83141
- var UNKNOWN = look("circle-question-mark", "muted", "plain", "none");
83142
83206
  var ALERT = look("triangle-alert", "danger", "alert-wash", "pulse");
83143
83207
  function lookOf(spec) {
83144
83208
  const at = (s) => look(spec.icon, s[0], s[1], s[2]);
@@ -83150,7 +83214,7 @@ function lookOf(spec) {
83150
83214
  standby: at(spec.standby),
83151
83215
  alert: spec.alert ?? ALERT,
83152
83216
  offline: OFFLINE,
83153
- unknown: UNKNOWN
83217
+ unknown: look(spec.icon, "muted", "plain", "none")
83154
83218
  };
83155
83219
  }
83156
83220
  var MUTED = [
@@ -94240,6 +94304,10 @@ function applianceExport(ecosystem, deviceType) {
94240
94304
  if (!isPlugApplianceType(deviceType)) return null;
94241
94305
  return APPLIANCE_EXPORT[ecosystem][deviceType];
94242
94306
  }
94307
+ DeviceType.Camera, DeviceType.Hub, DeviceType.Light, DeviceType.Siren, DeviceType.Switch, DeviceType.Sensor, DeviceType.Climate, DeviceType.HeatPump, 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.Vacuum, DeviceType.LawnMower, DeviceType.Container, DeviceType.Image, DeviceType.PetFeeder, DeviceType.PetFountain, DeviceType.Dishwasher, DeviceType.Washer, DeviceType.Dryer, DeviceType.Gateway;
94308
+ DeviceRole.Siren, DeviceRole.Floodlight, DeviceRole.Spotlight, DeviceRole.PirSensor, DeviceRole.Chime, DeviceRole.Autotrack, DeviceRole.Nightvision, DeviceRole.PrivacyMask, DeviceRole.Doorbell, DeviceRole.CoverBlind, DeviceRole.CoverShutter, DeviceRole.CoverAwning, DeviceRole.CoverCurtain, DeviceRole.CoverGarage, DeviceRole.CoverGate, DeviceRole.CoverDoor, DeviceRole.CoverWindow, DeviceRole.BinaryHelper, DeviceRole.Outlet, DeviceRole.SwitchHeater, DeviceRole.SwitchFan, DeviceRole.SwitchLight, DeviceRole.ClimateAc, DeviceRole.ClimateThermostat, DeviceRole.ClimateFloor, DeviceRole.ClimateRadiator, DeviceRole.ClimateHeater, DeviceRole.ClimateHeatPumpCircuit, DeviceRole.MotionSensor, DeviceRole.ContactSensor, DeviceRole.LeakSensor, DeviceRole.SmokeSensor, DeviceRole.COSensor, DeviceRole.GasSensor, DeviceRole.TamperSensor, DeviceRole.VibrationSensor, DeviceRole.ConnectivitySensor, DeviceRole.SoundSensor, DeviceRole.BinarySensor, DeviceRole.TemperatureSensor, DeviceRole.HumiditySensor, DeviceRole.AmbientLightSensor, DeviceRole.PressureSensor, DeviceRole.WindSensor, DeviceRole.RainSensor, DeviceRole.UvSensor, DeviceRole.SolarRadiationSensor, DeviceRole.SoilMoistureSensor, DeviceRole.PowerSensor, DeviceRole.EnergySensor, DeviceRole.VoltageSensor, DeviceRole.CurrentSensor, DeviceRole.AirQualitySensor, DeviceRole.BatterySensor, DeviceRole.NumericSensor, DeviceRole.EnumSensor, DeviceRole.DateTimeSensor, DeviceRole.GenericSensor, DeviceRole.NumericControl, DeviceRole.SelectControl, DeviceRole.TextControl, DeviceRole.DateTimeControl, DeviceRole.MobilePushNotifier, DeviceRole.MessagingNotifier, DeviceRole.EmailNotifier, DeviceRole.GenericNotifier, DeviceRole.IrTransmitter;
94309
+ new Set(Object.values(DeviceType));
94310
+ new Set(Object.values(DeviceRole));
94243
94311
  Object.freeze({
94244
94312
  "accessories.getStatus": [{
94245
94313
  name: "deviceId",
@@ -146347,446 +146415,6 @@ async function resolveDefaultBridge(ports) {
146347
146415
  };
146348
146416
  }
146349
146417
  //#endregion
146350
- //#region src/migrations/hub-node-fields.ts
146351
- /**
146352
- * Fields stored once for the cluster that are facts of ONE node become node settings (D986): a
146353
- * node's row is `<addonId>.<key>@<nodeId>` carrying `nodeId`, and a node never falls back to a
146354
- * bare row. This owner is placed `hub-only`, so the one node that ever held a value is the hub:
146355
- * each bare row is COPIED to `<key>@hub`. The bare row stays for a release (a copy, not a move),
146356
- * and a value already on the node row is never overwritten (a seed never overwrites).
146357
- *
146358
- * A keychain marker is copied verbatim: it names the owner and the secret, not the row that
146359
- * points at it. Idempotent: with every bare row copied the plan is empty.
146360
- */
146361
- /** The canonical settings table: one row per key, id `<addonId>.<key>`. */
146362
- var ADDON_SETTINGS_TABLE = "addon-settings";
146363
- var nodeKeyOf = (key) => `${key}@hub`;
146364
- async function planHubNodeFields(addonId, keys, ports) {
146365
- const stored = await ports.readStored([...keys, ...keys.map(nodeKeyOf)]);
146366
- const pending = keys.filter((key) => key in stored && !(nodeKeyOf(key) in stored));
146367
- if (pending.length === 0) return { edits: [] };
146368
- const rowId = (key) => `${addonId}.${nodeKeyOf(key)}`;
146369
- return { edits: [{
146370
- op: "setKeys",
146371
- scope: ADDON_SETTINGS_TABLE,
146372
- values: Object.fromEntries(pending.map((key) => [rowId(key), {
146373
- addonId,
146374
- key: nodeKeyOf(key),
146375
- value: stored[key],
146376
- nodeId: "hub"
146377
- }])),
146378
- precondition: preconditionOf(Object.fromEntries(pending.map((key) => [rowId(key), null])))
146379
- }] };
146380
- }
146381
- /**
146382
- * The port's read over an addon's three-way key read: each of `keys` that has a row, raw. A key
146383
- * the store could not answer for throws, so the migration fails instead of treating a failed read
146384
- * as "nothing to copy".
146385
- */
146386
- async function readRawKeys(read, addonId, keys) {
146387
- const found = {};
146388
- for (const key of keys) {
146389
- const answer = await read(key);
146390
- if (answer.kind === "unreadable") throw new Error(`${addonId}: the setting ${key} cannot be read (${answer.reason})`);
146391
- if (answer.kind === "present") found[key] = answer.value;
146392
- }
146393
- return found;
146394
- }
146395
- //#endregion
146396
- //#region src/migrations/fixed-pin-to-keychain.ts
146397
- /**
146398
- * The fixed HomeKit setup code pairs a controller with the bridge: a credential. It was a plain
146399
- * text setting, stored inline in the settings row; it is a `password` field now (D783), and a
146400
- * password lives in the keychain with a marker in the row. This procedure moves a stored inline
146401
- * code there, through the operator write path (the one that stores an inline value of a
146402
- * pre-keychain addon as a keychain secret).
146403
- *
146404
- * Idempotent: an absent, empty or already marker-backed code is `already-done`, so a crash
146405
- * between the keychain write and the ledger row costs nothing on the rerun.
146406
- */
146407
- async function moveFixedPinToKeychain(ports) {
146408
- const stored = (await ports.readStored(["fixedPin"]))["fixedPin"];
146409
- if (typeof stored !== "string" || stored === "" || isSecretMarker(stored)) return {
146410
- outcome: "already-done",
146411
- summary: { moved: false }
146412
- };
146413
- await ports.storeFixedPin(stored);
146414
- return {
146415
- outcome: "done",
146416
- summary: { moved: true }
146417
- };
146418
- }
146419
- //#endregion
146420
- //#region src/migrations/exposure-to-record.ts
146421
- /**
146422
- * The exposure lists the addon kept in its settings (`exposed`: the devices it mirrors, with
146423
- * their per-device settings; `exposedActions`: the actions it publishes) move into the
146424
- * `hap-bridge-exports` record of the default instance (D985, D996). Two migrations, in order:
146425
- *
146426
- * 1. `moveExposureToRecord` (procedure): put the record with `ifRev: 0`, read it BACK and
146427
- * compare it with what the settings carried; a record that does not hold the same lists
146428
- * throws and the settings are kept. An existing record is never overwritten.
146429
- * 2. `planDropExposureKeys` (plan): the two keys are deleted from the canonical `addon-settings`
146430
- * rows, and only while the record holds exactly what they carry. A record that differs (the
146431
- * operator edited the lists since) keeps the old keys, which nothing reads any more.
146432
- *
146433
- * An entry the schema does not know (a mapper kind the addon no longer serves) is dropped on the
146434
- * way, which is what the boot sweep did to it anyway.
146435
- */
146436
- /** Key-order-independent JSON, so "identical" does not depend on how a store orders keys. */
146437
- function canonical(value) {
146438
- if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
146439
- if (typeof value === "object" && value !== null) return `{${Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(",")}}`;
146440
- return JSON.stringify(value) ?? "null";
146441
- }
146442
- function parsedList(value, parse) {
146443
- if (!Array.isArray(value)) return [];
146444
- const kept = [];
146445
- for (const entry of value) {
146446
- const parsed = parse(entry);
146447
- if (parsed.success) kept.push(parsed.data);
146448
- }
146449
- return kept;
146450
- }
146451
- /** The record body the legacy settings describe. */
146452
- function exposureBodyFrom(stored) {
146453
- return {
146454
- name: HAP_EXPOSURE_NAME,
146455
- devices: parsedList(stored["exposed"], (e) => ExposedConfigEntrySchema.safeParse(e)),
146456
- actions: parsedList(stored["exposedActions"], (e) => ActionExportEntrySchema.safeParse(e))
146457
- };
146458
- }
146459
- function sameLists(a, b) {
146460
- return canonical(a.devices) === canonical(b.devices) && canonical(a.actions) === canonical(b.actions);
146461
- }
146462
- async function moveExposureToRecord(ports) {
146463
- const stored = await ports.readStored(MOVED_EXPOSURE_KEYS);
146464
- if (!MOVED_EXPOSURE_KEYS.some((key) => key in stored)) return {
146465
- outcome: "already-done",
146466
- summary: { moved: false }
146467
- };
146468
- const body = exposureBodyFrom(stored);
146469
- const put = await ports.putExposure(body);
146470
- const held = await ports.readExposure();
146471
- if (held === null) throw new Error("the HomeKit exposure record cannot be read back");
146472
- if (put === "created" && !sameLists(held, body)) throw new Error("the HomeKit exposure record does not hold the lists it adopted");
146473
- return put === "created" ? {
146474
- outcome: "done",
146475
- summary: {
146476
- moved: true,
146477
- devices: body.devices.length
146478
- }
146479
- } : {
146480
- outcome: "already-done",
146481
- summary: { moved: false }
146482
- };
146483
- }
146484
- var rowId = (key) => `${HAP_DEFAULT_INSTANCE_ID}.${key}`;
146485
- async function planDropExposureKeys(ports) {
146486
- const stored = await ports.readStored(MOVED_EXPOSURE_KEYS);
146487
- const present = MOVED_EXPOSURE_KEYS.filter((key) => key in stored);
146488
- if (present.length === 0) return { edits: [] };
146489
- const held = await ports.readExposure();
146490
- if (held === null || !sameLists(held, exposureBodyFrom(stored))) return { edits: [] };
146491
- return { edits: [{
146492
- op: "deleteKeys",
146493
- scope: ADDON_SETTINGS_TABLE,
146494
- keys: present.map(rowId),
146495
- precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
146496
- addonId: HAP_DEFAULT_INSTANCE_ID,
146497
- key,
146498
- value: stored[key]
146499
- }])))
146500
- }] };
146501
- }
146502
- //#endregion
146503
- //#region src/migrations/identity-to-instance.ts
146504
- /**
146505
- * The bridge identity the addon kept in its settings (`identity`: username, uuid, pincode) moves
146506
- * into the default instance record (D985, D996). Paired controllers know the bridge by exactly
146507
- * these values, so the record is created with them UNCHANGED and the pass proves it by reading the
146508
- * record back and comparing, field by field, before it reports `done`.
146509
- *
146510
- * Only once the read-back matches is the old `identity` cleared (its keychain entry released with
146511
- * it), in this same pass: one path, no copy. An existing record is never overwritten; when it is
146512
- * already there and names the same bridge (username, uuid) the leftover old identity of an
146513
- * interrupted pass is cleared, and when it names another bridge the pass fails rather than guess.
146514
- * An incomplete or unreadable legacy identity is `already-done` or throws, and never mints a new
146515
- * one (a new identity unpairs every controller).
146516
- */
146517
- async function moveIdentityToDefaultInstance(ports) {
146518
- const legacy = await ports.readLegacyIdentity();
146519
- if (legacy === null) return {
146520
- outcome: "already-done",
146521
- summary: { moved: false }
146522
- };
146523
- const name = (await ports.readBridgeName()).trim();
146524
- const body = {
146525
- name: name.length > 0 ? name : "CamStack Bridge",
146526
- username: legacy.username,
146527
- uuid: legacy.uuid,
146528
- pincode: legacy.pincode
146529
- };
146530
- const put = await ports.putDefaultRecord(body);
146531
- const held = await ports.readDefaultRecord();
146532
- if (held === null) throw new Error("the HomeKit default instance record cannot be read back");
146533
- if (put === "exists") {
146534
- if (held.username !== body.username || held.uuid !== body.uuid) throw new Error("the HomeKit default instance is another bridge than the stored identity");
146535
- await ports.clearLegacyIdentity();
146536
- return {
146537
- outcome: "done",
146538
- summary: {
146539
- moved: false,
146540
- cleared: true
146541
- }
146542
- };
146543
- }
146544
- if (!sameIdentity(identityOfBody(held), identityOfBody(body))) throw new Error("the HomeKit default instance does not hold the identity it adopted");
146545
- await ports.clearLegacyIdentity();
146546
- return {
146547
- outcome: "done",
146548
- summary: { moved: true }
146549
- };
146550
- }
146551
- function sameIdentity(a, b) {
146552
- return a.username === b.username && a.uuid === b.uuid && a.pincode === b.pincode;
146553
- }
146554
- /**
146555
- * The identity a settings value describes, secrets resolved; null when it is not a complete
146556
- * identity (first boot, or the empty sentinel). A pincode still a keychain marker was not
146557
- * resolved: that throws, because treating "unreadable" as "absent" would mint a new identity.
146558
- */
146559
- function legacyIdentityOf(value) {
146560
- if (typeof value !== "object" || value === null) return null;
146561
- const username = Reflect.get(value, "username");
146562
- const uuid = Reflect.get(value, "uuid");
146563
- const pincode = Reflect.get(value, "pincode");
146564
- if (isSecretMarker(pincode)) throw new Error("the stored HomeKit setup code cannot be resolved");
146565
- if (typeof username !== "string" || typeof uuid !== "string" || typeof pincode !== "string" || username === "" || uuid === "" || pincode === "") return null;
146566
- return {
146567
- username,
146568
- uuid,
146569
- pincode
146570
- };
146571
- }
146572
- //#endregion
146573
- //#region src/migrations/bridge-name-to-instance.ts
146574
- async function moveBridgeNameToInstance(ports) {
146575
- const name = (await ports.readBridgeName()).trim();
146576
- if (name === "") return {
146577
- outcome: "already-done",
146578
- summary: { renamed: false }
146579
- };
146580
- const held = await ports.readDefaultRecord();
146581
- if (held === null || held.name === name) return {
146582
- outcome: "already-done",
146583
- summary: { renamed: false }
146584
- };
146585
- await ports.patchDefaultName(name);
146586
- const after = await ports.readDefaultRecord();
146587
- if (after === null || after.name !== name) throw new Error("the HomeKit default instance does not carry the name it adopted");
146588
- return {
146589
- outcome: "done",
146590
- summary: { renamed: true }
146591
- };
146592
- }
146593
- //#endregion
146594
- //#region src/migrations/drop-global-knobs.ts
146595
- /**
146596
- * The retired global knobs of the HomeKit export. `bridgeName` is the instance's name and
146597
- * `fixedPin` was an operator-typed setup code (a bridge's setup code is read-only now and changes
146598
- * only through Regenerate); the bare `interfaceName` is the cluster copy of a setting that is a
146599
- * fact of one node, which the node row carries since the per-node migration.
146600
- *
146601
- * Two bodies, in this order, because a secret must be released before its row goes (the
146602
- * keychain value would be orphaned otherwise):
146603
- * 1. `clearFixedPin` (procedure): the keychain value and marker of `fixedPin`;
146604
- * 2. `planDropGlobalKnobRows` (plan): the rows `bridgeName`, `fixedPin` and the bare
146605
- * `interfaceName`. The bare interfaceName goes only when the node row exists, so deleting it
146606
- * can never lose the value. A `@<nodeId>` row is never touched.
146607
- */
146608
- async function clearFixedPin(ports) {
146609
- if (!("fixedPin" in await ports.readStored(["fixedPin"]))) return {
146610
- outcome: "already-done",
146611
- summary: { cleared: false }
146612
- };
146613
- await ports.clearFixedPin();
146614
- return {
146615
- outcome: "done",
146616
- summary: { cleared: true }
146617
- };
146618
- }
146619
- async function planDropGlobalKnobRows(addonId, ports) {
146620
- const stored = await ports.readStored([
146621
- "bridgeName",
146622
- "fixedPin",
146623
- "interfaceName",
146624
- nodeKeyOf("interfaceName")
146625
- ]);
146626
- const present = [
146627
- "bridgeName",
146628
- "fixedPin",
146629
- "interfaceName"
146630
- ].filter((key) => key in stored && (key !== "interfaceName" || nodeKeyOf("interfaceName") in stored));
146631
- if (present.length === 0) return { edits: [] };
146632
- const rowId = (key) => `${addonId}.${key}`;
146633
- return { edits: [{
146634
- op: "deleteKeys",
146635
- scope: ADDON_SETTINGS_TABLE,
146636
- keys: present.map(rowId),
146637
- precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
146638
- addonId,
146639
- key,
146640
- value: stored[key]
146641
- }])))
146642
- }] };
146643
- }
146644
- //#endregion
146645
- //#region src/migrations/index.ts
146646
- var EXPORT_HAP_ID = "export-hap";
146647
- var INTERFACE_NAME_PER_NODE_ID = "export-hap/2026-11-03-interface-name-per-node";
146648
- var FIXED_PIN_TO_KEYCHAIN_ID = "export-hap/2026-11-03-fixed-pin-to-keychain";
146649
- var IDENTITY_TO_INSTANCE_ID = "export-hap/2026-11-04-identity-to-default-instance";
146650
- var EXPOSURE_TO_RECORD_ID = "export-hap/2026-11-04-exposure-to-record";
146651
- var DROP_EXPOSURE_KEYS_ID = "export-hap/2026-11-04-drop-exposure-keys";
146652
- var BRIDGE_NAME_TO_INSTANCE_ID = "export-hap/2026-11-04-bridge-name-to-instance";
146653
- var DROP_GLOBAL_KNOBS_ID = "export-hap/2026-11-04-drop-global-knobs";
146654
- /** The `export-hap` catalogue (D987): offered to the engine when the addon initialises. */
146655
- var ADDON_MIGRATIONS = [
146656
- {
146657
- meta: {
146658
- id: INTERFACE_NAME_PER_NODE_ID,
146659
- owner: EXPORT_HAP_ID,
146660
- level: "addon-state",
146661
- seq: 1,
146662
- dependsOn: [],
146663
- store: "settings",
146664
- scope: "per-node",
146665
- onFailure: "tolerate",
146666
- bodyKind: "plan",
146667
- description: "Copy the bare network interface setting to its hub node row; the bare row stays for a release",
146668
- fixtureMark: "the bridge name the migration does not know"
146669
- },
146670
- plan: (ports) => planHubNodeFields(EXPORT_HAP_ID, ["interfaceName"], ports)
146671
- },
146672
- {
146673
- meta: {
146674
- id: FIXED_PIN_TO_KEYCHAIN_ID,
146675
- owner: EXPORT_HAP_ID,
146676
- level: "addon-state",
146677
- seq: 2,
146678
- dependsOn: [],
146679
- store: "settings",
146680
- scope: "cluster",
146681
- onFailure: "tolerate",
146682
- bodyKind: "procedure",
146683
- description: "Move the fixed setup code from an inline setting into the keychain, where a password field keeps it",
146684
- fixtureMark: "the bridge name the migration does not know"
146685
- },
146686
- procedure: moveFixedPinToKeychain
146687
- },
146688
- {
146689
- meta: {
146690
- id: IDENTITY_TO_INSTANCE_ID,
146691
- owner: EXPORT_HAP_ID,
146692
- level: "addon-state",
146693
- seq: 3,
146694
- dependsOn: [],
146695
- store: "settings",
146696
- scope: "cluster",
146697
- onFailure: "block-owner",
146698
- bodyKind: "procedure",
146699
- description: "Move the bridge identity (username, uuid, setup code) into the default HomeKit instance record, unchanged, then clear the old setting and its keychain entry",
146700
- fixtureMark: "the bridge name the migration does not know"
146701
- },
146702
- procedure: moveIdentityToDefaultInstance
146703
- },
146704
- {
146705
- meta: {
146706
- id: EXPOSURE_TO_RECORD_ID,
146707
- owner: EXPORT_HAP_ID,
146708
- level: "addon-state",
146709
- seq: 4,
146710
- dependsOn: [IDENTITY_TO_INSTANCE_ID],
146711
- store: "settings",
146712
- scope: "cluster",
146713
- onFailure: "block-owner",
146714
- bodyKind: "procedure",
146715
- description: "Move the exposed devices and actions into the default bridge exposure record, verified by read-back",
146716
- fixtureMark: "the bridge name the migration does not know"
146717
- },
146718
- procedure: moveExposureToRecord
146719
- },
146720
- {
146721
- meta: {
146722
- id: DROP_EXPOSURE_KEYS_ID,
146723
- owner: EXPORT_HAP_ID,
146724
- level: "addon-state",
146725
- seq: 5,
146726
- dependsOn: [EXPOSURE_TO_RECORD_ID],
146727
- store: "settings",
146728
- scope: "cluster",
146729
- onFailure: "tolerate",
146730
- bodyKind: "plan",
146731
- description: "Delete the old exposed and exposedActions settings once the record holds exactly what they carried",
146732
- fixtureMark: "the bridge name the migration does not know"
146733
- },
146734
- plan: planDropExposureKeys
146735
- },
146736
- {
146737
- meta: {
146738
- id: BRIDGE_NAME_TO_INSTANCE_ID,
146739
- owner: EXPORT_HAP_ID,
146740
- level: "addon-state",
146741
- seq: 6,
146742
- dependsOn: [IDENTITY_TO_INSTANCE_ID],
146743
- store: "settings",
146744
- scope: "cluster",
146745
- onFailure: "block-owner",
146746
- bodyKind: "procedure",
146747
- description: "Make the installation name the name of the default HomeKit instance record, verified by read-back",
146748
- fixtureMark: "the bridge name the migration does not know"
146749
- },
146750
- procedure: moveBridgeNameToInstance
146751
- },
146752
- {
146753
- meta: {
146754
- id: DROP_GLOBAL_KNOBS_ID,
146755
- owner: EXPORT_HAP_ID,
146756
- level: "addon-state",
146757
- seq: 7,
146758
- dependsOn: [FIXED_PIN_TO_KEYCHAIN_ID, IDENTITY_TO_INSTANCE_ID],
146759
- store: "settings",
146760
- scope: "cluster",
146761
- onFailure: "tolerate",
146762
- bodyKind: "procedure",
146763
- description: "Release the retired fixed setup code from the keychain: a bridge setup code is read-only now",
146764
- fixtureMark: "the bridge name the migration does not know"
146765
- },
146766
- procedure: clearFixedPin
146767
- },
146768
- {
146769
- meta: {
146770
- id: "export-hap/2026-11-04-drop-global-knob-rows",
146771
- owner: EXPORT_HAP_ID,
146772
- level: "addon-state",
146773
- seq: 8,
146774
- dependsOn: [
146775
- BRIDGE_NAME_TO_INSTANCE_ID,
146776
- DROP_GLOBAL_KNOBS_ID,
146777
- INTERFACE_NAME_PER_NODE_ID
146778
- ],
146779
- store: "settings",
146780
- scope: "cluster",
146781
- onFailure: "tolerate",
146782
- bodyKind: "plan",
146783
- description: "Delete the retired bridgeName, fixedPin and cluster interfaceName rows; the node rows are untouched",
146784
- fixtureMark: "the bridge name the migration does not know"
146785
- },
146786
- plan: (ports) => planDropGlobalKnobRows(EXPORT_HAP_ID, ports)
146787
- }
146788
- ];
146789
- //#endregion
146790
146418
  //#region src/hap-setup-uri.ts
146791
146419
  function errMsg$15(e) {
146792
146420
  return e instanceof Error ? e.message : String(e);
@@ -148039,38 +147667,6 @@ function createClipThumbnailMinter(input) {
148039
147667
  };
148040
147668
  }
148041
147669
  //#endregion
148042
- //#region src/hksv/recording-active.ts
148043
- /**
148044
- * `true`/`false` as HomeKit holds it, or `null` when this accessory does not
148045
- * offer recording at all.
148046
- */
148047
- function readHomekitRecordingActive(accessories) {
148048
- for (const accessory of accessories) {
148049
- const service = accessory.getService(import_dist.Service.CameraRecordingManagement);
148050
- if (service === void 0) continue;
148051
- const value = service.getCharacteristic(import_dist.Characteristic.Active).value;
148052
- if (typeof value === "number") return value === 1;
148053
- if (typeof value === "boolean") return value;
148054
- return null;
148055
- }
148056
- return null;
148057
- }
148058
- /**
148059
- * One sentence for the settings page: what HomeKit says, or why it was never
148060
- * asked.
148061
- *
148062
- * The cost stays in the text even though the switch is gone. It is still the
148063
- * operator's to understand — a camera recording here runs a permanent ffmpeg —
148064
- * and a status line that reported only the state would have quietly dropped
148065
- * the one number that decides whether to turn it on.
148066
- */
148067
- function describeHomekitRecording(active, lastBuild) {
148068
- if (active === true) return "HomeKit is recording this camera. Turn it off in the Home app (Camera settings → “Stream”), not here — iOS owns this switch and keeps it across reboots. While it is on, this camera runs a permanent prebuffer (~0.7% of one CPU core on the copy branch).";
148069
- if (active === false) return "This camera offers recording and HomeKit has it off. Turn it on in the Home app (Camera settings → “Stream and Allow Recording”); it needs iCloud+ and a home hub. Nothing runs here until you do.";
148070
- if (lastBuild !== null && !lastBuild.advertised) return `Recording is not offered for this camera: ${lastBuild.detail ?? "the accessory could not advertise it"}.`;
148071
- return "Not known yet — this camera’s accessory has not published its recording service in this process. It appears once the accessory is built.";
148072
- }
148073
- //#endregion
148074
147670
  //#region src/hksv/recording-source.ts
148075
147671
  /** The tallest frame the recording path will hold in its prebuffer. */
148076
147672
  var MAX_RECORDING_HEIGHT = 1080;
@@ -148186,6 +147782,38 @@ function recordabilityTokenFor(input) {
148186
147782
  return recordabilityToken(input.entries, { allowTranscode: input.allowTranscode !== false });
148187
147783
  }
148188
147784
  //#endregion
147785
+ //#region src/hksv/recording-active.ts
147786
+ /**
147787
+ * `true`/`false` as HomeKit holds it, or `null` when this accessory does not
147788
+ * offer recording at all.
147789
+ */
147790
+ function readHomekitRecordingActive(accessories) {
147791
+ for (const accessory of accessories) {
147792
+ const service = accessory.getService(import_dist.Service.CameraRecordingManagement);
147793
+ if (service === void 0) continue;
147794
+ const value = service.getCharacteristic(import_dist.Characteristic.Active).value;
147795
+ if (typeof value === "number") return value === 1;
147796
+ if (typeof value === "boolean") return value;
147797
+ return null;
147798
+ }
147799
+ return null;
147800
+ }
147801
+ /**
147802
+ * One sentence for the settings page: what HomeKit says, or why it was never
147803
+ * asked.
147804
+ *
147805
+ * The cost stays in the text even though the switch is gone. It is still the
147806
+ * operator's to understand — a camera recording here runs a permanent ffmpeg —
147807
+ * and a status line that reported only the state would have quietly dropped
147808
+ * the one number that decides whether to turn it on.
147809
+ */
147810
+ function describeHomekitRecording(active, lastBuild) {
147811
+ if (active === true) return "HomeKit is recording this camera. Turn it off in the Home app (Camera settings → “Stream”), not here — iOS owns this switch and keeps it across reboots. While it is on, this camera runs a permanent prebuffer (~0.7% of one CPU core on the copy branch).";
147812
+ if (active === false) return "This camera offers recording and HomeKit has it off. Turn it on in the Home app (Camera settings → “Stream and Allow Recording”); it needs iCloud+ and a home hub. Nothing runs here until you do.";
147813
+ if (lastBuild !== null && !lastBuild.advertised) return `Recording is not offered for this camera: ${lastBuild.detail ?? "the accessory could not advertise it"}.`;
147814
+ return "Not known yet — this camera’s accessory has not published its recording service in this process. It appears once the accessory is built.";
147815
+ }
147816
+ //#endregion
148189
147817
  //#region src/hksv/videoclips-plane.ts
148190
147818
  /**
148191
147819
  * The two data-plane routes behind the HomeKit clip source.
@@ -165785,6 +165413,446 @@ function getMapperFactory(kind) {
165785
165413
  return factory;
165786
165414
  }
165787
165415
  //#endregion
165416
+ //#region src/migrations/hub-node-fields.ts
165417
+ /**
165418
+ * Fields stored once for the cluster that are facts of ONE node become node settings (D986): a
165419
+ * node's row is `<addonId>.<key>@<nodeId>` carrying `nodeId`, and a node never falls back to a
165420
+ * bare row. This owner is placed `hub-only`, so the one node that ever held a value is the hub:
165421
+ * each bare row is COPIED to `<key>@hub`. The bare row stays for a release (a copy, not a move),
165422
+ * and a value already on the node row is never overwritten (a seed never overwrites).
165423
+ *
165424
+ * A keychain marker is copied verbatim: it names the owner and the secret, not the row that
165425
+ * points at it. Idempotent: with every bare row copied the plan is empty.
165426
+ */
165427
+ /** The canonical settings table: one row per key, id `<addonId>.<key>`. */
165428
+ var ADDON_SETTINGS_TABLE = "addon-settings";
165429
+ var nodeKeyOf = (key) => `${key}@hub`;
165430
+ async function planHubNodeFields(addonId, keys, ports) {
165431
+ const stored = await ports.readStored([...keys, ...keys.map(nodeKeyOf)]);
165432
+ const pending = keys.filter((key) => key in stored && !(nodeKeyOf(key) in stored));
165433
+ if (pending.length === 0) return { edits: [] };
165434
+ const rowId = (key) => `${addonId}.${nodeKeyOf(key)}`;
165435
+ return { edits: [{
165436
+ op: "setKeys",
165437
+ scope: ADDON_SETTINGS_TABLE,
165438
+ values: Object.fromEntries(pending.map((key) => [rowId(key), {
165439
+ addonId,
165440
+ key: nodeKeyOf(key),
165441
+ value: stored[key],
165442
+ nodeId: "hub"
165443
+ }])),
165444
+ precondition: preconditionOf(Object.fromEntries(pending.map((key) => [rowId(key), null])))
165445
+ }] };
165446
+ }
165447
+ /**
165448
+ * The port's read over an addon's three-way key read: each of `keys` that has a row, raw. A key
165449
+ * the store could not answer for throws, so the migration fails instead of treating a failed read
165450
+ * as "nothing to copy".
165451
+ */
165452
+ async function readRawKeys(read, addonId, keys) {
165453
+ const found = {};
165454
+ for (const key of keys) {
165455
+ const answer = await read(key);
165456
+ if (answer.kind === "unreadable") throw new Error(`${addonId}: the setting ${key} cannot be read (${answer.reason})`);
165457
+ if (answer.kind === "present") found[key] = answer.value;
165458
+ }
165459
+ return found;
165460
+ }
165461
+ //#endregion
165462
+ //#region src/migrations/fixed-pin-to-keychain.ts
165463
+ /**
165464
+ * The fixed HomeKit setup code pairs a controller with the bridge: a credential. It was a plain
165465
+ * text setting, stored inline in the settings row; it is a `password` field now (D783), and a
165466
+ * password lives in the keychain with a marker in the row. This procedure moves a stored inline
165467
+ * code there, through the operator write path (the one that stores an inline value of a
165468
+ * pre-keychain addon as a keychain secret).
165469
+ *
165470
+ * Idempotent: an absent, empty or already marker-backed code is `already-done`, so a crash
165471
+ * between the keychain write and the ledger row costs nothing on the rerun.
165472
+ */
165473
+ async function moveFixedPinToKeychain(ports) {
165474
+ const stored = (await ports.readStored(["fixedPin"]))["fixedPin"];
165475
+ if (typeof stored !== "string" || stored === "" || isSecretMarker(stored)) return {
165476
+ outcome: "already-done",
165477
+ summary: { moved: false }
165478
+ };
165479
+ await ports.storeFixedPin(stored);
165480
+ return {
165481
+ outcome: "done",
165482
+ summary: { moved: true }
165483
+ };
165484
+ }
165485
+ //#endregion
165486
+ //#region src/migrations/exposure-to-record.ts
165487
+ /**
165488
+ * The exposure lists the addon kept in its settings (`exposed`: the devices it mirrors, with
165489
+ * their per-device settings; `exposedActions`: the actions it publishes) move into the
165490
+ * `hap-bridge-exports` record of the default instance (D985, D996). Two migrations, in order:
165491
+ *
165492
+ * 1. `moveExposureToRecord` (procedure): put the record with `ifRev: 0`, read it BACK and
165493
+ * compare it with what the settings carried; a record that does not hold the same lists
165494
+ * throws and the settings are kept. An existing record is never overwritten.
165495
+ * 2. `planDropExposureKeys` (plan): the two keys are deleted from the canonical `addon-settings`
165496
+ * rows, and only while the record holds exactly what they carry. A record that differs (the
165497
+ * operator edited the lists since) keeps the old keys, which nothing reads any more.
165498
+ *
165499
+ * An entry the schema does not know (a mapper kind the addon no longer serves) is dropped on the
165500
+ * way, which is what the boot sweep did to it anyway.
165501
+ */
165502
+ /** Key-order-independent JSON, so "identical" does not depend on how a store orders keys. */
165503
+ function canonical(value) {
165504
+ if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
165505
+ if (typeof value === "object" && value !== null) return `{${Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(",")}}`;
165506
+ return JSON.stringify(value) ?? "null";
165507
+ }
165508
+ function parsedList(value, parse) {
165509
+ if (!Array.isArray(value)) return [];
165510
+ const kept = [];
165511
+ for (const entry of value) {
165512
+ const parsed = parse(entry);
165513
+ if (parsed.success) kept.push(parsed.data);
165514
+ }
165515
+ return kept;
165516
+ }
165517
+ /** The record body the legacy settings describe. */
165518
+ function exposureBodyFrom(stored) {
165519
+ return {
165520
+ name: HAP_EXPOSURE_NAME,
165521
+ devices: parsedList(stored["exposed"], (e) => ExposedConfigEntrySchema.safeParse(e)),
165522
+ actions: parsedList(stored["exposedActions"], (e) => ActionExportEntrySchema.safeParse(e))
165523
+ };
165524
+ }
165525
+ function sameLists(a, b) {
165526
+ return canonical(a.devices) === canonical(b.devices) && canonical(a.actions) === canonical(b.actions);
165527
+ }
165528
+ async function moveExposureToRecord(ports) {
165529
+ const stored = await ports.readStored(MOVED_EXPOSURE_KEYS);
165530
+ if (!MOVED_EXPOSURE_KEYS.some((key) => key in stored)) return {
165531
+ outcome: "already-done",
165532
+ summary: { moved: false }
165533
+ };
165534
+ const body = exposureBodyFrom(stored);
165535
+ const put = await ports.putExposure(body);
165536
+ const held = await ports.readExposure();
165537
+ if (held === null) throw new Error("the HomeKit exposure record cannot be read back");
165538
+ if (put === "created" && !sameLists(held, body)) throw new Error("the HomeKit exposure record does not hold the lists it adopted");
165539
+ return put === "created" ? {
165540
+ outcome: "done",
165541
+ summary: {
165542
+ moved: true,
165543
+ devices: body.devices.length
165544
+ }
165545
+ } : {
165546
+ outcome: "already-done",
165547
+ summary: { moved: false }
165548
+ };
165549
+ }
165550
+ var rowId = (key) => `${HAP_DEFAULT_INSTANCE_ID}.${key}`;
165551
+ async function planDropExposureKeys(ports) {
165552
+ const stored = await ports.readStored(MOVED_EXPOSURE_KEYS);
165553
+ const present = MOVED_EXPOSURE_KEYS.filter((key) => key in stored);
165554
+ if (present.length === 0) return { edits: [] };
165555
+ const held = await ports.readExposure();
165556
+ if (held === null || !sameLists(held, exposureBodyFrom(stored))) return { edits: [] };
165557
+ return { edits: [{
165558
+ op: "deleteKeys",
165559
+ scope: ADDON_SETTINGS_TABLE,
165560
+ keys: present.map(rowId),
165561
+ precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
165562
+ addonId: HAP_DEFAULT_INSTANCE_ID,
165563
+ key,
165564
+ value: stored[key]
165565
+ }])))
165566
+ }] };
165567
+ }
165568
+ //#endregion
165569
+ //#region src/migrations/identity-to-instance.ts
165570
+ /**
165571
+ * The bridge identity the addon kept in its settings (`identity`: username, uuid, pincode) moves
165572
+ * into the default instance record (D985, D996). Paired controllers know the bridge by exactly
165573
+ * these values, so the record is created with them UNCHANGED and the pass proves it by reading the
165574
+ * record back and comparing, field by field, before it reports `done`.
165575
+ *
165576
+ * Only once the read-back matches is the old `identity` cleared (its keychain entry released with
165577
+ * it), in this same pass: one path, no copy. An existing record is never overwritten; when it is
165578
+ * already there and names the same bridge (username, uuid) the leftover old identity of an
165579
+ * interrupted pass is cleared, and when it names another bridge the pass fails rather than guess.
165580
+ * An incomplete or unreadable legacy identity is `already-done` or throws, and never mints a new
165581
+ * one (a new identity unpairs every controller).
165582
+ */
165583
+ async function moveIdentityToDefaultInstance(ports) {
165584
+ const legacy = await ports.readLegacyIdentity();
165585
+ if (legacy === null) return {
165586
+ outcome: "already-done",
165587
+ summary: { moved: false }
165588
+ };
165589
+ const name = (await ports.readBridgeName()).trim();
165590
+ const body = {
165591
+ name: name.length > 0 ? name : "CamStack Bridge",
165592
+ username: legacy.username,
165593
+ uuid: legacy.uuid,
165594
+ pincode: legacy.pincode
165595
+ };
165596
+ const put = await ports.putDefaultRecord(body);
165597
+ const held = await ports.readDefaultRecord();
165598
+ if (held === null) throw new Error("the HomeKit default instance record cannot be read back");
165599
+ if (put === "exists") {
165600
+ if (held.username !== body.username || held.uuid !== body.uuid) throw new Error("the HomeKit default instance is another bridge than the stored identity");
165601
+ await ports.clearLegacyIdentity();
165602
+ return {
165603
+ outcome: "done",
165604
+ summary: {
165605
+ moved: false,
165606
+ cleared: true
165607
+ }
165608
+ };
165609
+ }
165610
+ if (!sameIdentity(identityOfBody(held), identityOfBody(body))) throw new Error("the HomeKit default instance does not hold the identity it adopted");
165611
+ await ports.clearLegacyIdentity();
165612
+ return {
165613
+ outcome: "done",
165614
+ summary: { moved: true }
165615
+ };
165616
+ }
165617
+ function sameIdentity(a, b) {
165618
+ return a.username === b.username && a.uuid === b.uuid && a.pincode === b.pincode;
165619
+ }
165620
+ /**
165621
+ * The identity a settings value describes, secrets resolved; null when it is not a complete
165622
+ * identity (first boot, or the empty sentinel). A pincode still a keychain marker was not
165623
+ * resolved: that throws, because treating "unreadable" as "absent" would mint a new identity.
165624
+ */
165625
+ function legacyIdentityOf(value) {
165626
+ if (typeof value !== "object" || value === null) return null;
165627
+ const username = Reflect.get(value, "username");
165628
+ const uuid = Reflect.get(value, "uuid");
165629
+ const pincode = Reflect.get(value, "pincode");
165630
+ if (isSecretMarker(pincode)) throw new Error("the stored HomeKit setup code cannot be resolved");
165631
+ if (typeof username !== "string" || typeof uuid !== "string" || typeof pincode !== "string" || username === "" || uuid === "" || pincode === "") return null;
165632
+ return {
165633
+ username,
165634
+ uuid,
165635
+ pincode
165636
+ };
165637
+ }
165638
+ //#endregion
165639
+ //#region src/migrations/bridge-name-to-instance.ts
165640
+ async function moveBridgeNameToInstance(ports) {
165641
+ const name = (await ports.readBridgeName()).trim();
165642
+ if (name === "") return {
165643
+ outcome: "already-done",
165644
+ summary: { renamed: false }
165645
+ };
165646
+ const held = await ports.readDefaultRecord();
165647
+ if (held === null || held.name === name) return {
165648
+ outcome: "already-done",
165649
+ summary: { renamed: false }
165650
+ };
165651
+ await ports.patchDefaultName(name);
165652
+ const after = await ports.readDefaultRecord();
165653
+ if (after === null || after.name !== name) throw new Error("the HomeKit default instance does not carry the name it adopted");
165654
+ return {
165655
+ outcome: "done",
165656
+ summary: { renamed: true }
165657
+ };
165658
+ }
165659
+ //#endregion
165660
+ //#region src/migrations/drop-global-knobs.ts
165661
+ /**
165662
+ * The retired global knobs of the HomeKit export. `bridgeName` is the instance's name and
165663
+ * `fixedPin` was an operator-typed setup code (a bridge's setup code is read-only now and changes
165664
+ * only through Regenerate); the bare `interfaceName` is the cluster copy of a setting that is a
165665
+ * fact of one node, which the node row carries since the per-node migration.
165666
+ *
165667
+ * Two bodies, in this order, because a secret must be released before its row goes (the
165668
+ * keychain value would be orphaned otherwise):
165669
+ * 1. `clearFixedPin` (procedure): the keychain value and marker of `fixedPin`;
165670
+ * 2. `planDropGlobalKnobRows` (plan): the rows `bridgeName`, `fixedPin` and the bare
165671
+ * `interfaceName`. The bare interfaceName goes only when the node row exists, so deleting it
165672
+ * can never lose the value. A `@<nodeId>` row is never touched.
165673
+ */
165674
+ async function clearFixedPin(ports) {
165675
+ if (!("fixedPin" in await ports.readStored(["fixedPin"]))) return {
165676
+ outcome: "already-done",
165677
+ summary: { cleared: false }
165678
+ };
165679
+ await ports.clearFixedPin();
165680
+ return {
165681
+ outcome: "done",
165682
+ summary: { cleared: true }
165683
+ };
165684
+ }
165685
+ async function planDropGlobalKnobRows(addonId, ports) {
165686
+ const stored = await ports.readStored([
165687
+ "bridgeName",
165688
+ "fixedPin",
165689
+ "interfaceName",
165690
+ nodeKeyOf("interfaceName")
165691
+ ]);
165692
+ const present = [
165693
+ "bridgeName",
165694
+ "fixedPin",
165695
+ "interfaceName"
165696
+ ].filter((key) => key in stored && (key !== "interfaceName" || nodeKeyOf("interfaceName") in stored));
165697
+ if (present.length === 0) return { edits: [] };
165698
+ const rowId = (key) => `${addonId}.${key}`;
165699
+ return { edits: [{
165700
+ op: "deleteKeys",
165701
+ scope: ADDON_SETTINGS_TABLE,
165702
+ keys: present.map(rowId),
165703
+ precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
165704
+ addonId,
165705
+ key,
165706
+ value: stored[key]
165707
+ }])))
165708
+ }] };
165709
+ }
165710
+ //#endregion
165711
+ //#region src/migrations/index.ts
165712
+ var EXPORT_HAP_ID = "export-hap";
165713
+ var INTERFACE_NAME_PER_NODE_ID = "export-hap/2026-11-03-interface-name-per-node";
165714
+ var FIXED_PIN_TO_KEYCHAIN_ID = "export-hap/2026-11-03-fixed-pin-to-keychain";
165715
+ var IDENTITY_TO_INSTANCE_ID = "export-hap/2026-11-04-identity-to-default-instance";
165716
+ var EXPOSURE_TO_RECORD_ID = "export-hap/2026-11-04-exposure-to-record";
165717
+ var DROP_EXPOSURE_KEYS_ID = "export-hap/2026-11-04-drop-exposure-keys";
165718
+ var BRIDGE_NAME_TO_INSTANCE_ID = "export-hap/2026-11-04-bridge-name-to-instance";
165719
+ var DROP_GLOBAL_KNOBS_ID = "export-hap/2026-11-04-drop-global-knobs";
165720
+ /** The `export-hap` catalogue (D987): offered to the engine when the addon initialises. */
165721
+ var ADDON_MIGRATIONS = [
165722
+ {
165723
+ meta: {
165724
+ id: INTERFACE_NAME_PER_NODE_ID,
165725
+ owner: EXPORT_HAP_ID,
165726
+ level: "addon-state",
165727
+ seq: 1,
165728
+ dependsOn: [],
165729
+ store: "settings",
165730
+ scope: "per-node",
165731
+ onFailure: "tolerate",
165732
+ bodyKind: "plan",
165733
+ description: "Copy the bare network interface setting to its hub node row; the bare row stays for a release",
165734
+ fixtureMark: "the bridge name the migration does not know"
165735
+ },
165736
+ plan: (ports) => planHubNodeFields(EXPORT_HAP_ID, ["interfaceName"], ports)
165737
+ },
165738
+ {
165739
+ meta: {
165740
+ id: FIXED_PIN_TO_KEYCHAIN_ID,
165741
+ owner: EXPORT_HAP_ID,
165742
+ level: "addon-state",
165743
+ seq: 2,
165744
+ dependsOn: [],
165745
+ store: "settings",
165746
+ scope: "cluster",
165747
+ onFailure: "tolerate",
165748
+ bodyKind: "procedure",
165749
+ description: "Move the fixed setup code from an inline setting into the keychain, where a password field keeps it",
165750
+ fixtureMark: "the bridge name the migration does not know"
165751
+ },
165752
+ procedure: moveFixedPinToKeychain
165753
+ },
165754
+ {
165755
+ meta: {
165756
+ id: IDENTITY_TO_INSTANCE_ID,
165757
+ owner: EXPORT_HAP_ID,
165758
+ level: "addon-state",
165759
+ seq: 3,
165760
+ dependsOn: [],
165761
+ store: "settings",
165762
+ scope: "cluster",
165763
+ onFailure: "block-owner",
165764
+ bodyKind: "procedure",
165765
+ description: "Move the bridge identity (username, uuid, setup code) into the default HomeKit instance record, unchanged, then clear the old setting and its keychain entry",
165766
+ fixtureMark: "the bridge name the migration does not know"
165767
+ },
165768
+ procedure: moveIdentityToDefaultInstance
165769
+ },
165770
+ {
165771
+ meta: {
165772
+ id: EXPOSURE_TO_RECORD_ID,
165773
+ owner: EXPORT_HAP_ID,
165774
+ level: "addon-state",
165775
+ seq: 4,
165776
+ dependsOn: [IDENTITY_TO_INSTANCE_ID],
165777
+ store: "settings",
165778
+ scope: "cluster",
165779
+ onFailure: "block-owner",
165780
+ bodyKind: "procedure",
165781
+ description: "Move the exposed devices and actions into the default bridge exposure record, verified by read-back",
165782
+ fixtureMark: "the bridge name the migration does not know"
165783
+ },
165784
+ procedure: moveExposureToRecord
165785
+ },
165786
+ {
165787
+ meta: {
165788
+ id: DROP_EXPOSURE_KEYS_ID,
165789
+ owner: EXPORT_HAP_ID,
165790
+ level: "addon-state",
165791
+ seq: 5,
165792
+ dependsOn: [EXPOSURE_TO_RECORD_ID],
165793
+ store: "settings",
165794
+ scope: "cluster",
165795
+ onFailure: "tolerate",
165796
+ bodyKind: "plan",
165797
+ description: "Delete the old exposed and exposedActions settings once the record holds exactly what they carried",
165798
+ fixtureMark: "the bridge name the migration does not know"
165799
+ },
165800
+ plan: planDropExposureKeys
165801
+ },
165802
+ {
165803
+ meta: {
165804
+ id: BRIDGE_NAME_TO_INSTANCE_ID,
165805
+ owner: EXPORT_HAP_ID,
165806
+ level: "addon-state",
165807
+ seq: 6,
165808
+ dependsOn: [IDENTITY_TO_INSTANCE_ID],
165809
+ store: "settings",
165810
+ scope: "cluster",
165811
+ onFailure: "block-owner",
165812
+ bodyKind: "procedure",
165813
+ description: "Make the installation name the name of the default HomeKit instance record, verified by read-back",
165814
+ fixtureMark: "the bridge name the migration does not know"
165815
+ },
165816
+ procedure: moveBridgeNameToInstance
165817
+ },
165818
+ {
165819
+ meta: {
165820
+ id: DROP_GLOBAL_KNOBS_ID,
165821
+ owner: EXPORT_HAP_ID,
165822
+ level: "addon-state",
165823
+ seq: 7,
165824
+ dependsOn: [FIXED_PIN_TO_KEYCHAIN_ID, IDENTITY_TO_INSTANCE_ID],
165825
+ store: "settings",
165826
+ scope: "cluster",
165827
+ onFailure: "tolerate",
165828
+ bodyKind: "procedure",
165829
+ description: "Release the retired fixed setup code from the keychain: a bridge setup code is read-only now",
165830
+ fixtureMark: "the bridge name the migration does not know"
165831
+ },
165832
+ procedure: clearFixedPin
165833
+ },
165834
+ {
165835
+ meta: {
165836
+ id: "export-hap/2026-11-04-drop-global-knob-rows",
165837
+ owner: EXPORT_HAP_ID,
165838
+ level: "addon-state",
165839
+ seq: 8,
165840
+ dependsOn: [
165841
+ BRIDGE_NAME_TO_INSTANCE_ID,
165842
+ DROP_GLOBAL_KNOBS_ID,
165843
+ INTERFACE_NAME_PER_NODE_ID
165844
+ ],
165845
+ store: "settings",
165846
+ scope: "cluster",
165847
+ onFailure: "tolerate",
165848
+ bodyKind: "plan",
165849
+ description: "Delete the retired bridgeName, fixedPin and cluster interfaceName rows; the node rows are untouched",
165850
+ fixtureMark: "the bridge name the migration does not know"
165851
+ },
165852
+ plan: (ports) => planDropGlobalKnobRows(EXPORT_HAP_ID, ports)
165853
+ }
165854
+ ];
165855
+ //#endregion
165788
165856
  //#region src/reconcile/sync-state.ts
165789
165857
  function syncStateFromJson(json) {
165790
165858
  const map = /* @__PURE__ */ new Map();
@@ -167050,18 +167118,31 @@ var ExportHapAddon = class extends BaseAddon {
167050
167118
  async buildDeviceSettingsContribution(deviceId) {
167051
167119
  const kind = await this.resolveExportKind(deviceId);
167052
167120
  if (kind === null) return null;
167053
- const inst = this.instanceForDevice(deviceId);
167054
- if (inst === null) return null;
167121
+ const bridges = [...this.bridges.values()].toSorted((x, y) => Number(y.id === HAP_DEFAULT_INSTANCE_ID) - Number(x.id === HAP_DEFAULT_INSTANCE_ID));
167122
+ if (bridges.length === 0) return null;
167123
+ const named = bridges.length > 1;
167124
+ return {
167125
+ tabs: [{
167126
+ id: "export",
167127
+ label: "Export",
167128
+ icon: "share-2",
167129
+ order: 80
167130
+ }],
167131
+ sections: bridges.map((inst, index) => this.buildBridgeDeviceSection(inst, deviceId, kind, named, index))
167132
+ };
167133
+ }
167134
+ /** The Export section of one bridge for one device. Every key names the bridge. */
167135
+ buildBridgeDeviceSection(inst, deviceId, kind, named, index) {
167055
167136
  const entry = inst.findEntry(deviceId);
167056
167137
  const settings = entry?.settings ?? DEFAULT_DEVICE_SETTINGS;
167057
167138
  const enabled = entry !== null;
167058
- const enabledKey = `hap:${deviceId}:enabled`;
167059
- const streamPreferenceKey = `hap:${deviceId}:streamPreference`;
167060
- const multiTierKey = `hap:${deviceId}:multiTierService`;
167061
- const useBridgeKey = `hap:${deviceId}:useBridge`;
167062
- const allowTranscodeKey = `hap:${deviceId}:allowTranscode`;
167063
- const keepClipsKey = `hap:${deviceId}:keepClips`;
167064
- const clipRetentionKey = `hap:${deviceId}:clipRetentionDays`;
167139
+ const enabledKey = `hap:${inst.id}:${deviceId}:enabled`;
167140
+ const streamPreferenceKey = `hap:${inst.id}:${deviceId}:streamPreference`;
167141
+ const multiTierKey = `hap:${inst.id}:${deviceId}:multiTierService`;
167142
+ const useBridgeKey = `hap:${inst.id}:${deviceId}:useBridge`;
167143
+ const allowTranscodeKey = `hap:${inst.id}:${deviceId}:allowTranscode`;
167144
+ const keepClipsKey = `hap:${inst.id}:${deviceId}:keepClips`;
167145
+ const clipRetentionKey = `hap:${inst.id}:${deviceId}:clipRetentionDays`;
167065
167146
  const mapper = inst.exposed.get(String(deviceId)) ?? null;
167066
167147
  const paired = mapper ? accessoryPaired(mapper.accessory) : false;
167067
167148
  const bridged = mapper !== null && inst.bridgeHost.holds(mapper.accessory);
@@ -167108,7 +167189,7 @@ var ExportHapAddon = class extends BaseAddon {
167108
167189
  },
167109
167190
  {
167110
167191
  type: "info",
167111
- key: `hap:${deviceId}:hksvRecordingStatus`,
167192
+ key: `hap:${inst.id}:${deviceId}:hksvRecordingStatus`,
167112
167193
  label: "HomeKit recording (Secure Video)",
167113
167194
  content: describeHomekitRecording(readHomekitRecordingActive(inst.exposed.get(String(deviceId))?.accessories ?? []), this.hksvBuilds.lastFor(deviceId)),
167114
167195
  showWhen: {
@@ -167169,53 +167250,45 @@ var ExportHapAddon = class extends BaseAddon {
167169
167250
  }
167170
167251
  ];
167171
167252
  return {
167172
- tabs: [{
167173
- id: "export",
167174
- label: "Export",
167175
- icon: "share-2",
167176
- order: 80
167177
- }],
167178
- sections: [{
167179
- id: "export-hap",
167180
- title: "HomeKit Export",
167181
- description: kind === "camera" ? "Publish this camera as its own HomeKit accessory so iOS Home can pair with it." : "Publish this device as its own HomeKit accessory. Its capabilities decide which controls iOS Home shows.",
167182
- tab: "export",
167183
- columns: 1,
167184
- order: 10,
167185
- fields: [
167186
- {
167187
- type: "info",
167188
- key: "__hap-status",
167189
- label: "Status",
167190
- content: statusLabel,
167191
- variant: "info"
167192
- },
167193
- {
167194
- type: "qr-code",
167195
- key: "__hap-pair-qr",
167196
- label: paired ? "Pairing QR (already paired)" : "Pairing QR",
167197
- caption: paired ? `Already paired with at least one device. Scan from another iPhone / iPad to add it there too. Setup code: ${inst.pincode}.` : `Scan with the iOS Camera app to pair this accessory in HomeKit. Setup code: ${inst.pincode}.`,
167198
- value: qrValue,
167199
- size: 192,
167200
- alt: `HomeKit pairing QR for ${name}`,
167201
- showWhen: {
167202
- field: enabledKey,
167203
- equals: true
167204
- }
167205
- },
167206
- {
167207
- type: "boolean",
167208
- key: enabledKey,
167209
- label: "Expose to HomeKit",
167210
- description: "Toggle to publish this device as a HomeKit accessory.",
167211
- style: "switch",
167212
- value: enabled,
167213
- immediate: true
167214
- },
167215
- ...bridgeFields,
167216
- ...cameraFields
167217
- ]
167218
- }]
167253
+ id: `${EXPORT_HAP_ADDON_ID}:${inst.id}`,
167254
+ title: named ? `HomeKit Export — ${inst.name}` : "HomeKit Export",
167255
+ description: kind === "camera" ? "Publish this camera as its own HomeKit accessory so iOS Home can pair with it." : "Publish this device as its own HomeKit accessory. Its capabilities decide which controls iOS Home shows.",
167256
+ tab: "export",
167257
+ columns: 1,
167258
+ order: 10 + index,
167259
+ fields: [
167260
+ {
167261
+ type: "info",
167262
+ key: `__hap-status:${inst.id}`,
167263
+ label: "Status",
167264
+ content: statusLabel,
167265
+ variant: "info"
167266
+ },
167267
+ {
167268
+ type: "qr-code",
167269
+ key: `__hap-pair-qr:${inst.id}`,
167270
+ label: paired ? "Pairing QR (already paired)" : "Pairing QR",
167271
+ caption: paired ? `Already paired with at least one device. Scan from another iPhone / iPad to add it there too. Setup code: ${inst.pincode}.` : `Scan with the iOS Camera app to pair this accessory in HomeKit. Setup code: ${inst.pincode}.`,
167272
+ value: qrValue,
167273
+ size: 192,
167274
+ alt: `HomeKit pairing QR for ${name}`,
167275
+ showWhen: {
167276
+ field: enabledKey,
167277
+ equals: true
167278
+ }
167279
+ },
167280
+ {
167281
+ type: "boolean",
167282
+ key: enabledKey,
167283
+ label: "Expose to HomeKit",
167284
+ description: "Toggle to publish this device as a HomeKit accessory.",
167285
+ style: "switch",
167286
+ value: enabled,
167287
+ immediate: true
167288
+ },
167289
+ ...bridgeFields,
167290
+ ...cameraFields
167291
+ ]
167219
167292
  };
167220
167293
  }
167221
167294
  /**
@@ -167231,19 +167304,33 @@ var ExportHapAddon = class extends BaseAddon {
167231
167304
  * note in CLAUDE.md (Remaining work).
167232
167305
  */
167233
167306
  async applyDeviceSettingsPatch(deviceId, patch) {
167307
+ const instanceIds = bridgeIdsInPatch(deviceId, patch);
167308
+ if (instanceIds.length === 0) {
167309
+ const stale = Object.keys(patch).filter((k) => k.startsWith("hap:"));
167310
+ if (stale.length > 0) throw new Error(`export-hap: device ${deviceId} patch names no HomeKit bridge (${stale.join(", ")}) — reload the Export tab`);
167311
+ this.ctx.logger.warn("export-hap: a device patch carried no HomeKit key — nothing applied", {
167312
+ tags: { deviceId },
167313
+ meta: { keys: Object.keys(patch) }
167314
+ });
167315
+ return { success: true };
167316
+ }
167317
+ for (const instanceId of instanceIds) this.requireBridge(instanceId);
167318
+ for (const instanceId of instanceIds) await this.applyBridgeDevicePatch(this.requireBridge(instanceId), deviceId, patch);
167319
+ return { success: true };
167320
+ }
167321
+ /** Apply the keys of ONE bridge (`hap:<inst.id>:<deviceId>:…`) to that bridge. */
167322
+ async applyBridgeDevicePatch(inst, deviceId, patch) {
167234
167323
  const deviceIdStr = String(deviceId);
167235
167324
  const log = this.ctx.logger.withTags({ deviceId });
167236
- const inst = this.instanceForDevice(deviceId);
167237
- if (inst === null) throw new Error("export-hap: no HomeKit bridge is running — add or enable one first");
167238
167325
  const current = inst.findEntry(deviceId);
167239
167326
  const wasEnabled = inst.exposed.has(deviceIdStr);
167240
- const enabledKey = `hap:${deviceId}:enabled`;
167241
- const streamPreferenceKey = `hap:${deviceId}:streamPreference`;
167242
- const useBridgeKey = `hap:${deviceId}:useBridge`;
167243
- const allowTranscodeKey = `hap:${deviceId}:allowTranscode`;
167244
- const multiTierKey = `hap:${deviceId}:multiTierService`;
167245
- const keepClipsKey = `hap:${deviceId}:keepClips`;
167246
- const clipRetentionKey = `hap:${deviceId}:clipRetentionDays`;
167327
+ const enabledKey = `hap:${inst.id}:${deviceId}:enabled`;
167328
+ const streamPreferenceKey = `hap:${inst.id}:${deviceId}:streamPreference`;
167329
+ const useBridgeKey = `hap:${inst.id}:${deviceId}:useBridge`;
167330
+ const allowTranscodeKey = `hap:${inst.id}:${deviceId}:allowTranscode`;
167331
+ const multiTierKey = `hap:${inst.id}:${deviceId}:multiTierService`;
167332
+ const keepClipsKey = `hap:${inst.id}:${deviceId}:keepClips`;
167333
+ const clipRetentionKey = `hap:${inst.id}:${deviceId}:clipRetentionDays`;
167247
167334
  const enabledValue = enabledKey in patch ? Boolean(patch[enabledKey]) : wasEnabled;
167248
167335
  const streamPreferenceRaw = streamPreferenceKey in patch ? patch[streamPreferenceKey] : current?.settings?.streamPreference;
167249
167336
  const streamPreference = typeof streamPreferenceRaw === "string" && streamPreferenceRaw.trim().length > 0 ? streamPreferenceRaw : "auto";
@@ -167427,6 +167514,21 @@ var ExportHapAddon = class extends BaseAddon {
167427
167514
  await this.setExposedDevices(inst, next);
167428
167515
  }
167429
167516
  };
167517
+ /**
167518
+ * The bridges a device patch addresses, read from its keys (`hap:<instanceId>:<deviceId>:<setting>`),
167519
+ * in first-seen order. Keys of another device or another exporter are not this patch's.
167520
+ */
167521
+ function bridgeIdsInPatch(deviceId, patch) {
167522
+ const ids = /* @__PURE__ */ new Set();
167523
+ for (const key of Object.keys(patch)) {
167524
+ const match = HAP_DEVICE_KEY.exec(key);
167525
+ if (match === null || match[2] !== String(deviceId)) continue;
167526
+ const instanceId = match[1];
167527
+ if (instanceId !== void 0) ids.add(instanceId);
167528
+ }
167529
+ return [...ids];
167530
+ }
167531
+ var HAP_DEVICE_KEY = /^hap:([^:]+):(\d+):\w+$/;
167430
167532
  function errMsg(err) {
167431
167533
  return err instanceof Error ? err.message : String(err);
167432
167534
  }