@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.
@@ -57811,6 +57811,15 @@ var HeroTextSchema = object({
57811
57811
  it: string()
57812
57812
  });
57813
57813
  /**
57814
+ * What a device that has not reported says in place of its value: an empty "—",
57815
+ * never a word like "Unknown" and never a 0 (D393). The card stays its normal
57816
+ * self; only the value is empty.
57817
+ */
57818
+ var NOT_REPORTED = {
57819
+ en: "—",
57820
+ it: "—"
57821
+ };
57822
+ /**
57814
57823
  * The ONE measurement a simple sensor shows (card wave, phase 1).
57815
57824
  *
57816
57825
  * A sensor that measures a single quantity (a temperature, a humidity, a power,
@@ -57927,6 +57936,62 @@ function textMeasurement(text, since) {
57927
57936
  historyKey: null
57928
57937
  };
57929
57938
  }
57939
+ /** What each quantity draws beside its value, reported or not. */
57940
+ var QUANTITY_FACE = {
57941
+ temperature: {
57942
+ icon: "thermometer",
57943
+ unit: "°C",
57944
+ sinceKind: "updated",
57945
+ historyKey: "cap:temperature-sensor.temperature"
57946
+ },
57947
+ humidity: {
57948
+ icon: "droplets",
57949
+ unit: "%",
57950
+ sinceKind: "updated",
57951
+ historyKey: "cap:humidity-sensor.humidity"
57952
+ },
57953
+ power: {
57954
+ icon: "zap",
57955
+ unit: "W",
57956
+ sinceKind: "updated",
57957
+ historyKey: "cap:power-meter.power"
57958
+ },
57959
+ contact: {
57960
+ icon: null,
57961
+ unit: null,
57962
+ sinceKind: "changed",
57963
+ historyKey: null
57964
+ },
57965
+ text: {
57966
+ icon: null,
57967
+ unit: null,
57968
+ sinceKind: "updated",
57969
+ historyKey: null
57970
+ }
57971
+ };
57972
+ /**
57973
+ * The measurement of a sensor that has not reported yet: its normal card with
57974
+ * an empty "—" value and its unit — never a placeholder, never a 0 (D393). The
57975
+ * reading is `null` (nothing to format), the scene does not move, and nothing
57976
+ * claims a moment.
57977
+ */
57978
+ function emptyMeasurement(quantity) {
57979
+ const face = QUANTITY_FACE[quantity];
57980
+ return {
57981
+ quantity,
57982
+ reading: null,
57983
+ icon: face.icon,
57984
+ value: NOT_REPORTED,
57985
+ unit: face.unit,
57986
+ band: null,
57987
+ level: null,
57988
+ word: NOT_REPORTED,
57989
+ tone: "muted",
57990
+ since: null,
57991
+ sinceKind: face.sinceKind,
57992
+ historyKey: face.historyKey
57993
+ };
57994
+ }
57930
57995
  /** The scene as the model carries it. `null` = the device did not say (never a guess). */
57931
57996
  var HeroSceneSchema = object({
57932
57997
  id: _enum([
@@ -81220,7 +81285,7 @@ var lockContribution = contribution("lock-control", LockControlStatusSchema, (sl
81220
81285
  const state = slice?.state ?? null;
81221
81286
  const words = state === null ? null : LOCK_WORDS[state];
81222
81287
  const since = slice === void 0 ? null : elapsedText(slice.lastChangedAt, ctx.now);
81223
- const title = words?.title ?? t("Unknown", "Sconosciuto");
81288
+ const title = words?.title ?? NOT_REPORTED;
81224
81289
  return {
81225
81290
  reading: reading("lock-control", words?.state ?? "unknown", false, words?.title),
81226
81291
  rows: [row$1("lock", state === "locked" || state === "locking" ? "lock" : "lock-open", joinText([title, since]), lockControls(state, ctx.features.includes(DeviceFeature.LockOpen)))],
@@ -81312,7 +81377,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81312
81377
  const modes = slice === void 0 ? ALARM_MODES : slice.availableModes;
81313
81378
  return {
81314
81379
  reading: reading("alarm-panel", words?.state ?? "unknown", false, words?.title),
81315
- 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))],
81380
+ 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))],
81316
81381
  ...since === null || words === null ? {} : { facts: [fact("since", "clock", since, state === "triggered" ? "danger" : "muted")] },
81317
81382
  ...words === null ? {} : { tiles: {
81318
81383
  left: [{
@@ -81343,7 +81408,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81343
81408
  return {
81344
81409
  reading: reading("automation-control", state, false, title),
81345
81410
  rows: [row$1("automation", "workflow", joinText([
81346
- title ?? t("Unknown", "Sconosciuto"),
81411
+ title ?? NOT_REPORTED,
81347
81412
  last === null ? null : t(`Ran ${last.en}`, `Eseguita ${last.it}`),
81348
81413
  slice?.lastError == null ? null : t(slice.lastError, slice.lastError)
81349
81414
  ]), [asAction(run), toggle])],
@@ -81359,7 +81424,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81359
81424
  return {
81360
81425
  reading: reading("script-runner", state, false, title),
81361
81426
  rows: [row$1("script", "scroll-text", joinText([
81362
- title ?? t("Unknown", "Sconosciuto"),
81427
+ title ?? NOT_REPORTED,
81363
81428
  last === null ? null : t(`Ran ${last.en}`, `Eseguito ${last.it}`),
81364
81429
  slice?.lastError == null ? null : t(slice.lastError, slice.lastError)
81365
81430
  ]), [asAction(control)])],
@@ -81368,7 +81433,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81368
81433
  }),
81369
81434
  "do-not-disturb": contribution("do-not-disturb", DoNotDisturbStatusSchema, (slice) => {
81370
81435
  const on = slice?.enabled ?? null;
81371
- 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"), [{
81436
+ 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"), [{
81372
81437
  kind: "toggle",
81373
81438
  id: "do-not-disturb.toggle",
81374
81439
  label: t("Do not disturb", "Non disturbare"),
@@ -81386,7 +81451,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81386
81451
  * is absent from the facts, never a zero (D393).
81387
81452
  */
81388
81453
  var has$3 = (ctx, f) => ctx.features.includes(f);
81389
- var unknownText = t("Unknown", "Sconosciuto");
81454
+ var unknownText = NOT_REPORTED;
81390
81455
  var pct$2 = (n) => t(`${Math.round(n)}%`, `${Math.round(n)}%`);
81391
81456
  var unit = (n) => Math.min(1, Math.max(0, n / 100));
81392
81457
  /** Battery as a fact, unless the device is also bound to the `battery` cap (it already says so). */
@@ -82792,13 +82857,13 @@ function sensorFragment(value, id, icon, en, it, text) {
82792
82857
  tiles: { right: [tile$1(en, it, text)] }
82793
82858
  };
82794
82859
  }
82795
- 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)));
82796
- 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)));
82860
+ 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)));
82861
+ 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)));
82797
82862
  var pressureContribution = contribution("pressure-sensor", PressureSensorStatusSchema, (slice) => sensorFragment(slice?.pressure ?? null, "pressure", "gauge", "Pressure", "Pressione", `${Math.round(slice?.pressure ?? 0)} hPa`));
82798
82863
  var illuminanceContribution = contribution("ambient-light-sensor", AmbientLightSensorStatusSchema, (slice) => sensorFragment(slice?.illuminance ?? null, "illuminance", "sun", "Light", "Luce", `${Math.round(slice?.illuminance ?? 0)} lx`));
82799
82864
  var numericContribution = contribution("numeric-sensor", NumericSensorStatusSchema, (slice) => sensorFragment(slice?.value ?? null, "reading", "gauge", "Value", "Valore", String(Number((slice?.value ?? 0).toFixed(2)))));
82800
82865
  var enumContribution = contribution("enum-sensor", EnumSensorStatusSchema, (slice) => {
82801
- if (slice === void 0 || slice.value === "") return { reading: reading("sensor", "unknown") };
82866
+ if (slice === void 0 || slice.value === "") return measured({ reading: reading("sensor", "unknown") }, emptyMeasurement("text"));
82802
82867
  if (slice.timestamp === true) return { reading: reading("sensor", "on") };
82803
82868
  return measured(sensorFragment(slice.value, "reading", "gauge", "State", "Stato", slice.value), textMeasurement(slice.value, slice.lastFetchedAt));
82804
82869
  });
@@ -82922,7 +82987,7 @@ function circuitControl(circuit) {
82922
82987
  return picker(`heat-pump.${circuit.id}.mode`, t("Mode", "Modalità"), circuit.operationMode, method, args);
82923
82988
  }
82924
82989
  /** A circuit with no reading is still a row: it shows that nothing is known, not nothing. */
82925
- var UNKNOWN_STATUS = same("—");
82990
+ var UNKNOWN_STATUS = NOT_REPORTED;
82926
82991
  function circuitRow(circuit) {
82927
82992
  const control = circuitControl(circuit);
82928
82993
  const status = thermalStatusText(circuit.targetTemp, circuit.currentTemp) ?? UNKNOWN_STATUS;
@@ -83146,9 +83211,8 @@ function look(icon, tone, background, animation) {
83146
83211
  animation
83147
83212
  };
83148
83213
  }
83149
- /** A state a device is in whatever it is: unreachable, or silent. Identical for every look. */
83214
+ /** Unreachable: identical for every look. */
83150
83215
  var OFFLINE = look("wifi-off", "muted", "plain", "none");
83151
- var UNKNOWN = look("circle-question-mark", "muted", "plain", "none");
83152
83216
  var ALERT = look("triangle-alert", "danger", "alert-wash", "pulse");
83153
83217
  function lookOf(spec) {
83154
83218
  const at = (s) => look(spec.icon, s[0], s[1], s[2]);
@@ -83160,7 +83224,7 @@ function lookOf(spec) {
83160
83224
  standby: at(spec.standby),
83161
83225
  alert: spec.alert ?? ALERT,
83162
83226
  offline: OFFLINE,
83163
- unknown: UNKNOWN
83227
+ unknown: look(spec.icon, "muted", "plain", "none")
83164
83228
  };
83165
83229
  }
83166
83230
  var MUTED = [
@@ -94250,6 +94314,10 @@ function applianceExport(ecosystem, deviceType) {
94250
94314
  if (!isPlugApplianceType(deviceType)) return null;
94251
94315
  return APPLIANCE_EXPORT[ecosystem][deviceType];
94252
94316
  }
94317
+ 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;
94318
+ 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;
94319
+ new Set(Object.values(DeviceType));
94320
+ new Set(Object.values(DeviceRole));
94253
94321
  Object.freeze({
94254
94322
  "accessories.getStatus": [{
94255
94323
  name: "deviceId",
@@ -146357,446 +146425,6 @@ async function resolveDefaultBridge(ports) {
146357
146425
  };
146358
146426
  }
146359
146427
  //#endregion
146360
- //#region src/migrations/hub-node-fields.ts
146361
- /**
146362
- * Fields stored once for the cluster that are facts of ONE node become node settings (D986): a
146363
- * node's row is `<addonId>.<key>@<nodeId>` carrying `nodeId`, and a node never falls back to a
146364
- * bare row. This owner is placed `hub-only`, so the one node that ever held a value is the hub:
146365
- * each bare row is COPIED to `<key>@hub`. The bare row stays for a release (a copy, not a move),
146366
- * and a value already on the node row is never overwritten (a seed never overwrites).
146367
- *
146368
- * A keychain marker is copied verbatim: it names the owner and the secret, not the row that
146369
- * points at it. Idempotent: with every bare row copied the plan is empty.
146370
- */
146371
- /** The canonical settings table: one row per key, id `<addonId>.<key>`. */
146372
- var ADDON_SETTINGS_TABLE = "addon-settings";
146373
- var nodeKeyOf = (key) => `${key}@hub`;
146374
- async function planHubNodeFields(addonId, keys, ports) {
146375
- const stored = await ports.readStored([...keys, ...keys.map(nodeKeyOf)]);
146376
- const pending = keys.filter((key) => key in stored && !(nodeKeyOf(key) in stored));
146377
- if (pending.length === 0) return { edits: [] };
146378
- const rowId = (key) => `${addonId}.${nodeKeyOf(key)}`;
146379
- return { edits: [{
146380
- op: "setKeys",
146381
- scope: ADDON_SETTINGS_TABLE,
146382
- values: Object.fromEntries(pending.map((key) => [rowId(key), {
146383
- addonId,
146384
- key: nodeKeyOf(key),
146385
- value: stored[key],
146386
- nodeId: "hub"
146387
- }])),
146388
- precondition: preconditionOf(Object.fromEntries(pending.map((key) => [rowId(key), null])))
146389
- }] };
146390
- }
146391
- /**
146392
- * The port's read over an addon's three-way key read: each of `keys` that has a row, raw. A key
146393
- * the store could not answer for throws, so the migration fails instead of treating a failed read
146394
- * as "nothing to copy".
146395
- */
146396
- async function readRawKeys(read, addonId, keys) {
146397
- const found = {};
146398
- for (const key of keys) {
146399
- const answer = await read(key);
146400
- if (answer.kind === "unreadable") throw new Error(`${addonId}: the setting ${key} cannot be read (${answer.reason})`);
146401
- if (answer.kind === "present") found[key] = answer.value;
146402
- }
146403
- return found;
146404
- }
146405
- //#endregion
146406
- //#region src/migrations/fixed-pin-to-keychain.ts
146407
- /**
146408
- * The fixed HomeKit setup code pairs a controller with the bridge: a credential. It was a plain
146409
- * text setting, stored inline in the settings row; it is a `password` field now (D783), and a
146410
- * password lives in the keychain with a marker in the row. This procedure moves a stored inline
146411
- * code there, through the operator write path (the one that stores an inline value of a
146412
- * pre-keychain addon as a keychain secret).
146413
- *
146414
- * Idempotent: an absent, empty or already marker-backed code is `already-done`, so a crash
146415
- * between the keychain write and the ledger row costs nothing on the rerun.
146416
- */
146417
- async function moveFixedPinToKeychain(ports) {
146418
- const stored = (await ports.readStored(["fixedPin"]))["fixedPin"];
146419
- if (typeof stored !== "string" || stored === "" || isSecretMarker(stored)) return {
146420
- outcome: "already-done",
146421
- summary: { moved: false }
146422
- };
146423
- await ports.storeFixedPin(stored);
146424
- return {
146425
- outcome: "done",
146426
- summary: { moved: true }
146427
- };
146428
- }
146429
- //#endregion
146430
- //#region src/migrations/exposure-to-record.ts
146431
- /**
146432
- * The exposure lists the addon kept in its settings (`exposed`: the devices it mirrors, with
146433
- * their per-device settings; `exposedActions`: the actions it publishes) move into the
146434
- * `hap-bridge-exports` record of the default instance (D985, D996). Two migrations, in order:
146435
- *
146436
- * 1. `moveExposureToRecord` (procedure): put the record with `ifRev: 0`, read it BACK and
146437
- * compare it with what the settings carried; a record that does not hold the same lists
146438
- * throws and the settings are kept. An existing record is never overwritten.
146439
- * 2. `planDropExposureKeys` (plan): the two keys are deleted from the canonical `addon-settings`
146440
- * rows, and only while the record holds exactly what they carry. A record that differs (the
146441
- * operator edited the lists since) keeps the old keys, which nothing reads any more.
146442
- *
146443
- * An entry the schema does not know (a mapper kind the addon no longer serves) is dropped on the
146444
- * way, which is what the boot sweep did to it anyway.
146445
- */
146446
- /** Key-order-independent JSON, so "identical" does not depend on how a store orders keys. */
146447
- function canonical(value) {
146448
- if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
146449
- 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(",")}}`;
146450
- return JSON.stringify(value) ?? "null";
146451
- }
146452
- function parsedList(value, parse) {
146453
- if (!Array.isArray(value)) return [];
146454
- const kept = [];
146455
- for (const entry of value) {
146456
- const parsed = parse(entry);
146457
- if (parsed.success) kept.push(parsed.data);
146458
- }
146459
- return kept;
146460
- }
146461
- /** The record body the legacy settings describe. */
146462
- function exposureBodyFrom(stored) {
146463
- return {
146464
- name: HAP_EXPOSURE_NAME,
146465
- devices: parsedList(stored["exposed"], (e) => ExposedConfigEntrySchema.safeParse(e)),
146466
- actions: parsedList(stored["exposedActions"], (e) => ActionExportEntrySchema.safeParse(e))
146467
- };
146468
- }
146469
- function sameLists(a, b) {
146470
- return canonical(a.devices) === canonical(b.devices) && canonical(a.actions) === canonical(b.actions);
146471
- }
146472
- async function moveExposureToRecord(ports) {
146473
- const stored = await ports.readStored(MOVED_EXPOSURE_KEYS);
146474
- if (!MOVED_EXPOSURE_KEYS.some((key) => key in stored)) return {
146475
- outcome: "already-done",
146476
- summary: { moved: false }
146477
- };
146478
- const body = exposureBodyFrom(stored);
146479
- const put = await ports.putExposure(body);
146480
- const held = await ports.readExposure();
146481
- if (held === null) throw new Error("the HomeKit exposure record cannot be read back");
146482
- if (put === "created" && !sameLists(held, body)) throw new Error("the HomeKit exposure record does not hold the lists it adopted");
146483
- return put === "created" ? {
146484
- outcome: "done",
146485
- summary: {
146486
- moved: true,
146487
- devices: body.devices.length
146488
- }
146489
- } : {
146490
- outcome: "already-done",
146491
- summary: { moved: false }
146492
- };
146493
- }
146494
- var rowId = (key) => `${HAP_DEFAULT_INSTANCE_ID}.${key}`;
146495
- async function planDropExposureKeys(ports) {
146496
- const stored = await ports.readStored(MOVED_EXPOSURE_KEYS);
146497
- const present = MOVED_EXPOSURE_KEYS.filter((key) => key in stored);
146498
- if (present.length === 0) return { edits: [] };
146499
- const held = await ports.readExposure();
146500
- if (held === null || !sameLists(held, exposureBodyFrom(stored))) return { edits: [] };
146501
- return { edits: [{
146502
- op: "deleteKeys",
146503
- scope: ADDON_SETTINGS_TABLE,
146504
- keys: present.map(rowId),
146505
- precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
146506
- addonId: HAP_DEFAULT_INSTANCE_ID,
146507
- key,
146508
- value: stored[key]
146509
- }])))
146510
- }] };
146511
- }
146512
- //#endregion
146513
- //#region src/migrations/identity-to-instance.ts
146514
- /**
146515
- * The bridge identity the addon kept in its settings (`identity`: username, uuid, pincode) moves
146516
- * into the default instance record (D985, D996). Paired controllers know the bridge by exactly
146517
- * these values, so the record is created with them UNCHANGED and the pass proves it by reading the
146518
- * record back and comparing, field by field, before it reports `done`.
146519
- *
146520
- * Only once the read-back matches is the old `identity` cleared (its keychain entry released with
146521
- * it), in this same pass: one path, no copy. An existing record is never overwritten; when it is
146522
- * already there and names the same bridge (username, uuid) the leftover old identity of an
146523
- * interrupted pass is cleared, and when it names another bridge the pass fails rather than guess.
146524
- * An incomplete or unreadable legacy identity is `already-done` or throws, and never mints a new
146525
- * one (a new identity unpairs every controller).
146526
- */
146527
- async function moveIdentityToDefaultInstance(ports) {
146528
- const legacy = await ports.readLegacyIdentity();
146529
- if (legacy === null) return {
146530
- outcome: "already-done",
146531
- summary: { moved: false }
146532
- };
146533
- const name = (await ports.readBridgeName()).trim();
146534
- const body = {
146535
- name: name.length > 0 ? name : "CamStack Bridge",
146536
- username: legacy.username,
146537
- uuid: legacy.uuid,
146538
- pincode: legacy.pincode
146539
- };
146540
- const put = await ports.putDefaultRecord(body);
146541
- const held = await ports.readDefaultRecord();
146542
- if (held === null) throw new Error("the HomeKit default instance record cannot be read back");
146543
- if (put === "exists") {
146544
- if (held.username !== body.username || held.uuid !== body.uuid) throw new Error("the HomeKit default instance is another bridge than the stored identity");
146545
- await ports.clearLegacyIdentity();
146546
- return {
146547
- outcome: "done",
146548
- summary: {
146549
- moved: false,
146550
- cleared: true
146551
- }
146552
- };
146553
- }
146554
- if (!sameIdentity(identityOfBody(held), identityOfBody(body))) throw new Error("the HomeKit default instance does not hold the identity it adopted");
146555
- await ports.clearLegacyIdentity();
146556
- return {
146557
- outcome: "done",
146558
- summary: { moved: true }
146559
- };
146560
- }
146561
- function sameIdentity(a, b) {
146562
- return a.username === b.username && a.uuid === b.uuid && a.pincode === b.pincode;
146563
- }
146564
- /**
146565
- * The identity a settings value describes, secrets resolved; null when it is not a complete
146566
- * identity (first boot, or the empty sentinel). A pincode still a keychain marker was not
146567
- * resolved: that throws, because treating "unreadable" as "absent" would mint a new identity.
146568
- */
146569
- function legacyIdentityOf(value) {
146570
- if (typeof value !== "object" || value === null) return null;
146571
- const username = Reflect.get(value, "username");
146572
- const uuid = Reflect.get(value, "uuid");
146573
- const pincode = Reflect.get(value, "pincode");
146574
- if (isSecretMarker(pincode)) throw new Error("the stored HomeKit setup code cannot be resolved");
146575
- if (typeof username !== "string" || typeof uuid !== "string" || typeof pincode !== "string" || username === "" || uuid === "" || pincode === "") return null;
146576
- return {
146577
- username,
146578
- uuid,
146579
- pincode
146580
- };
146581
- }
146582
- //#endregion
146583
- //#region src/migrations/bridge-name-to-instance.ts
146584
- async function moveBridgeNameToInstance(ports) {
146585
- const name = (await ports.readBridgeName()).trim();
146586
- if (name === "") return {
146587
- outcome: "already-done",
146588
- summary: { renamed: false }
146589
- };
146590
- const held = await ports.readDefaultRecord();
146591
- if (held === null || held.name === name) return {
146592
- outcome: "already-done",
146593
- summary: { renamed: false }
146594
- };
146595
- await ports.patchDefaultName(name);
146596
- const after = await ports.readDefaultRecord();
146597
- if (after === null || after.name !== name) throw new Error("the HomeKit default instance does not carry the name it adopted");
146598
- return {
146599
- outcome: "done",
146600
- summary: { renamed: true }
146601
- };
146602
- }
146603
- //#endregion
146604
- //#region src/migrations/drop-global-knobs.ts
146605
- /**
146606
- * The retired global knobs of the HomeKit export. `bridgeName` is the instance's name and
146607
- * `fixedPin` was an operator-typed setup code (a bridge's setup code is read-only now and changes
146608
- * only through Regenerate); the bare `interfaceName` is the cluster copy of a setting that is a
146609
- * fact of one node, which the node row carries since the per-node migration.
146610
- *
146611
- * Two bodies, in this order, because a secret must be released before its row goes (the
146612
- * keychain value would be orphaned otherwise):
146613
- * 1. `clearFixedPin` (procedure): the keychain value and marker of `fixedPin`;
146614
- * 2. `planDropGlobalKnobRows` (plan): the rows `bridgeName`, `fixedPin` and the bare
146615
- * `interfaceName`. The bare interfaceName goes only when the node row exists, so deleting it
146616
- * can never lose the value. A `@<nodeId>` row is never touched.
146617
- */
146618
- async function clearFixedPin(ports) {
146619
- if (!("fixedPin" in await ports.readStored(["fixedPin"]))) return {
146620
- outcome: "already-done",
146621
- summary: { cleared: false }
146622
- };
146623
- await ports.clearFixedPin();
146624
- return {
146625
- outcome: "done",
146626
- summary: { cleared: true }
146627
- };
146628
- }
146629
- async function planDropGlobalKnobRows(addonId, ports) {
146630
- const stored = await ports.readStored([
146631
- "bridgeName",
146632
- "fixedPin",
146633
- "interfaceName",
146634
- nodeKeyOf("interfaceName")
146635
- ]);
146636
- const present = [
146637
- "bridgeName",
146638
- "fixedPin",
146639
- "interfaceName"
146640
- ].filter((key) => key in stored && (key !== "interfaceName" || nodeKeyOf("interfaceName") in stored));
146641
- if (present.length === 0) return { edits: [] };
146642
- const rowId = (key) => `${addonId}.${key}`;
146643
- return { edits: [{
146644
- op: "deleteKeys",
146645
- scope: ADDON_SETTINGS_TABLE,
146646
- keys: present.map(rowId),
146647
- precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
146648
- addonId,
146649
- key,
146650
- value: stored[key]
146651
- }])))
146652
- }] };
146653
- }
146654
- //#endregion
146655
- //#region src/migrations/index.ts
146656
- var EXPORT_HAP_ID = "export-hap";
146657
- var INTERFACE_NAME_PER_NODE_ID = "export-hap/2026-11-03-interface-name-per-node";
146658
- var FIXED_PIN_TO_KEYCHAIN_ID = "export-hap/2026-11-03-fixed-pin-to-keychain";
146659
- var IDENTITY_TO_INSTANCE_ID = "export-hap/2026-11-04-identity-to-default-instance";
146660
- var EXPOSURE_TO_RECORD_ID = "export-hap/2026-11-04-exposure-to-record";
146661
- var DROP_EXPOSURE_KEYS_ID = "export-hap/2026-11-04-drop-exposure-keys";
146662
- var BRIDGE_NAME_TO_INSTANCE_ID = "export-hap/2026-11-04-bridge-name-to-instance";
146663
- var DROP_GLOBAL_KNOBS_ID = "export-hap/2026-11-04-drop-global-knobs";
146664
- /** The `export-hap` catalogue (D987): offered to the engine when the addon initialises. */
146665
- var ADDON_MIGRATIONS = [
146666
- {
146667
- meta: {
146668
- id: INTERFACE_NAME_PER_NODE_ID,
146669
- owner: EXPORT_HAP_ID,
146670
- level: "addon-state",
146671
- seq: 1,
146672
- dependsOn: [],
146673
- store: "settings",
146674
- scope: "per-node",
146675
- onFailure: "tolerate",
146676
- bodyKind: "plan",
146677
- description: "Copy the bare network interface setting to its hub node row; the bare row stays for a release",
146678
- fixtureMark: "the bridge name the migration does not know"
146679
- },
146680
- plan: (ports) => planHubNodeFields(EXPORT_HAP_ID, ["interfaceName"], ports)
146681
- },
146682
- {
146683
- meta: {
146684
- id: FIXED_PIN_TO_KEYCHAIN_ID,
146685
- owner: EXPORT_HAP_ID,
146686
- level: "addon-state",
146687
- seq: 2,
146688
- dependsOn: [],
146689
- store: "settings",
146690
- scope: "cluster",
146691
- onFailure: "tolerate",
146692
- bodyKind: "procedure",
146693
- description: "Move the fixed setup code from an inline setting into the keychain, where a password field keeps it",
146694
- fixtureMark: "the bridge name the migration does not know"
146695
- },
146696
- procedure: moveFixedPinToKeychain
146697
- },
146698
- {
146699
- meta: {
146700
- id: IDENTITY_TO_INSTANCE_ID,
146701
- owner: EXPORT_HAP_ID,
146702
- level: "addon-state",
146703
- seq: 3,
146704
- dependsOn: [],
146705
- store: "settings",
146706
- scope: "cluster",
146707
- onFailure: "block-owner",
146708
- bodyKind: "procedure",
146709
- 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",
146710
- fixtureMark: "the bridge name the migration does not know"
146711
- },
146712
- procedure: moveIdentityToDefaultInstance
146713
- },
146714
- {
146715
- meta: {
146716
- id: EXPOSURE_TO_RECORD_ID,
146717
- owner: EXPORT_HAP_ID,
146718
- level: "addon-state",
146719
- seq: 4,
146720
- dependsOn: [IDENTITY_TO_INSTANCE_ID],
146721
- store: "settings",
146722
- scope: "cluster",
146723
- onFailure: "block-owner",
146724
- bodyKind: "procedure",
146725
- description: "Move the exposed devices and actions into the default bridge exposure record, verified by read-back",
146726
- fixtureMark: "the bridge name the migration does not know"
146727
- },
146728
- procedure: moveExposureToRecord
146729
- },
146730
- {
146731
- meta: {
146732
- id: DROP_EXPOSURE_KEYS_ID,
146733
- owner: EXPORT_HAP_ID,
146734
- level: "addon-state",
146735
- seq: 5,
146736
- dependsOn: [EXPOSURE_TO_RECORD_ID],
146737
- store: "settings",
146738
- scope: "cluster",
146739
- onFailure: "tolerate",
146740
- bodyKind: "plan",
146741
- description: "Delete the old exposed and exposedActions settings once the record holds exactly what they carried",
146742
- fixtureMark: "the bridge name the migration does not know"
146743
- },
146744
- plan: planDropExposureKeys
146745
- },
146746
- {
146747
- meta: {
146748
- id: BRIDGE_NAME_TO_INSTANCE_ID,
146749
- owner: EXPORT_HAP_ID,
146750
- level: "addon-state",
146751
- seq: 6,
146752
- dependsOn: [IDENTITY_TO_INSTANCE_ID],
146753
- store: "settings",
146754
- scope: "cluster",
146755
- onFailure: "block-owner",
146756
- bodyKind: "procedure",
146757
- description: "Make the installation name the name of the default HomeKit instance record, verified by read-back",
146758
- fixtureMark: "the bridge name the migration does not know"
146759
- },
146760
- procedure: moveBridgeNameToInstance
146761
- },
146762
- {
146763
- meta: {
146764
- id: DROP_GLOBAL_KNOBS_ID,
146765
- owner: EXPORT_HAP_ID,
146766
- level: "addon-state",
146767
- seq: 7,
146768
- dependsOn: [FIXED_PIN_TO_KEYCHAIN_ID, IDENTITY_TO_INSTANCE_ID],
146769
- store: "settings",
146770
- scope: "cluster",
146771
- onFailure: "tolerate",
146772
- bodyKind: "procedure",
146773
- description: "Release the retired fixed setup code from the keychain: a bridge setup code is read-only now",
146774
- fixtureMark: "the bridge name the migration does not know"
146775
- },
146776
- procedure: clearFixedPin
146777
- },
146778
- {
146779
- meta: {
146780
- id: "export-hap/2026-11-04-drop-global-knob-rows",
146781
- owner: EXPORT_HAP_ID,
146782
- level: "addon-state",
146783
- seq: 8,
146784
- dependsOn: [
146785
- BRIDGE_NAME_TO_INSTANCE_ID,
146786
- DROP_GLOBAL_KNOBS_ID,
146787
- INTERFACE_NAME_PER_NODE_ID
146788
- ],
146789
- store: "settings",
146790
- scope: "cluster",
146791
- onFailure: "tolerate",
146792
- bodyKind: "plan",
146793
- description: "Delete the retired bridgeName, fixedPin and cluster interfaceName rows; the node rows are untouched",
146794
- fixtureMark: "the bridge name the migration does not know"
146795
- },
146796
- plan: (ports) => planDropGlobalKnobRows(EXPORT_HAP_ID, ports)
146797
- }
146798
- ];
146799
- //#endregion
146800
146428
  //#region src/hap-setup-uri.ts
146801
146429
  function errMsg$15(e) {
146802
146430
  return e instanceof Error ? e.message : String(e);
@@ -148049,38 +147677,6 @@ function createClipThumbnailMinter(input) {
148049
147677
  };
148050
147678
  }
148051
147679
  //#endregion
148052
- //#region src/hksv/recording-active.ts
148053
- /**
148054
- * `true`/`false` as HomeKit holds it, or `null` when this accessory does not
148055
- * offer recording at all.
148056
- */
148057
- function readHomekitRecordingActive(accessories) {
148058
- for (const accessory of accessories) {
148059
- const service = accessory.getService(import_dist.Service.CameraRecordingManagement);
148060
- if (service === void 0) continue;
148061
- const value = service.getCharacteristic(import_dist.Characteristic.Active).value;
148062
- if (typeof value === "number") return value === 1;
148063
- if (typeof value === "boolean") return value;
148064
- return null;
148065
- }
148066
- return null;
148067
- }
148068
- /**
148069
- * One sentence for the settings page: what HomeKit says, or why it was never
148070
- * asked.
148071
- *
148072
- * The cost stays in the text even though the switch is gone. It is still the
148073
- * operator's to understand — a camera recording here runs a permanent ffmpeg —
148074
- * and a status line that reported only the state would have quietly dropped
148075
- * the one number that decides whether to turn it on.
148076
- */
148077
- function describeHomekitRecording(active, lastBuild) {
148078
- 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).";
148079
- 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.";
148080
- if (lastBuild !== null && !lastBuild.advertised) return `Recording is not offered for this camera: ${lastBuild.detail ?? "the accessory could not advertise it"}.`;
148081
- return "Not known yet — this camera’s accessory has not published its recording service in this process. It appears once the accessory is built.";
148082
- }
148083
- //#endregion
148084
147680
  //#region src/hksv/recording-source.ts
148085
147681
  /** The tallest frame the recording path will hold in its prebuffer. */
148086
147682
  var MAX_RECORDING_HEIGHT = 1080;
@@ -148196,6 +147792,38 @@ function recordabilityTokenFor(input) {
148196
147792
  return recordabilityToken(input.entries, { allowTranscode: input.allowTranscode !== false });
148197
147793
  }
148198
147794
  //#endregion
147795
+ //#region src/hksv/recording-active.ts
147796
+ /**
147797
+ * `true`/`false` as HomeKit holds it, or `null` when this accessory does not
147798
+ * offer recording at all.
147799
+ */
147800
+ function readHomekitRecordingActive(accessories) {
147801
+ for (const accessory of accessories) {
147802
+ const service = accessory.getService(import_dist.Service.CameraRecordingManagement);
147803
+ if (service === void 0) continue;
147804
+ const value = service.getCharacteristic(import_dist.Characteristic.Active).value;
147805
+ if (typeof value === "number") return value === 1;
147806
+ if (typeof value === "boolean") return value;
147807
+ return null;
147808
+ }
147809
+ return null;
147810
+ }
147811
+ /**
147812
+ * One sentence for the settings page: what HomeKit says, or why it was never
147813
+ * asked.
147814
+ *
147815
+ * The cost stays in the text even though the switch is gone. It is still the
147816
+ * operator's to understand — a camera recording here runs a permanent ffmpeg —
147817
+ * and a status line that reported only the state would have quietly dropped
147818
+ * the one number that decides whether to turn it on.
147819
+ */
147820
+ function describeHomekitRecording(active, lastBuild) {
147821
+ 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).";
147822
+ 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.";
147823
+ if (lastBuild !== null && !lastBuild.advertised) return `Recording is not offered for this camera: ${lastBuild.detail ?? "the accessory could not advertise it"}.`;
147824
+ return "Not known yet — this camera’s accessory has not published its recording service in this process. It appears once the accessory is built.";
147825
+ }
147826
+ //#endregion
148199
147827
  //#region src/hksv/videoclips-plane.ts
148200
147828
  /**
148201
147829
  * The two data-plane routes behind the HomeKit clip source.
@@ -165795,6 +165423,446 @@ function getMapperFactory(kind) {
165795
165423
  return factory;
165796
165424
  }
165797
165425
  //#endregion
165426
+ //#region src/migrations/hub-node-fields.ts
165427
+ /**
165428
+ * Fields stored once for the cluster that are facts of ONE node become node settings (D986): a
165429
+ * node's row is `<addonId>.<key>@<nodeId>` carrying `nodeId`, and a node never falls back to a
165430
+ * bare row. This owner is placed `hub-only`, so the one node that ever held a value is the hub:
165431
+ * each bare row is COPIED to `<key>@hub`. The bare row stays for a release (a copy, not a move),
165432
+ * and a value already on the node row is never overwritten (a seed never overwrites).
165433
+ *
165434
+ * A keychain marker is copied verbatim: it names the owner and the secret, not the row that
165435
+ * points at it. Idempotent: with every bare row copied the plan is empty.
165436
+ */
165437
+ /** The canonical settings table: one row per key, id `<addonId>.<key>`. */
165438
+ var ADDON_SETTINGS_TABLE = "addon-settings";
165439
+ var nodeKeyOf = (key) => `${key}@hub`;
165440
+ async function planHubNodeFields(addonId, keys, ports) {
165441
+ const stored = await ports.readStored([...keys, ...keys.map(nodeKeyOf)]);
165442
+ const pending = keys.filter((key) => key in stored && !(nodeKeyOf(key) in stored));
165443
+ if (pending.length === 0) return { edits: [] };
165444
+ const rowId = (key) => `${addonId}.${nodeKeyOf(key)}`;
165445
+ return { edits: [{
165446
+ op: "setKeys",
165447
+ scope: ADDON_SETTINGS_TABLE,
165448
+ values: Object.fromEntries(pending.map((key) => [rowId(key), {
165449
+ addonId,
165450
+ key: nodeKeyOf(key),
165451
+ value: stored[key],
165452
+ nodeId: "hub"
165453
+ }])),
165454
+ precondition: preconditionOf(Object.fromEntries(pending.map((key) => [rowId(key), null])))
165455
+ }] };
165456
+ }
165457
+ /**
165458
+ * The port's read over an addon's three-way key read: each of `keys` that has a row, raw. A key
165459
+ * the store could not answer for throws, so the migration fails instead of treating a failed read
165460
+ * as "nothing to copy".
165461
+ */
165462
+ async function readRawKeys(read, addonId, keys) {
165463
+ const found = {};
165464
+ for (const key of keys) {
165465
+ const answer = await read(key);
165466
+ if (answer.kind === "unreadable") throw new Error(`${addonId}: the setting ${key} cannot be read (${answer.reason})`);
165467
+ if (answer.kind === "present") found[key] = answer.value;
165468
+ }
165469
+ return found;
165470
+ }
165471
+ //#endregion
165472
+ //#region src/migrations/fixed-pin-to-keychain.ts
165473
+ /**
165474
+ * The fixed HomeKit setup code pairs a controller with the bridge: a credential. It was a plain
165475
+ * text setting, stored inline in the settings row; it is a `password` field now (D783), and a
165476
+ * password lives in the keychain with a marker in the row. This procedure moves a stored inline
165477
+ * code there, through the operator write path (the one that stores an inline value of a
165478
+ * pre-keychain addon as a keychain secret).
165479
+ *
165480
+ * Idempotent: an absent, empty or already marker-backed code is `already-done`, so a crash
165481
+ * between the keychain write and the ledger row costs nothing on the rerun.
165482
+ */
165483
+ async function moveFixedPinToKeychain(ports) {
165484
+ const stored = (await ports.readStored(["fixedPin"]))["fixedPin"];
165485
+ if (typeof stored !== "string" || stored === "" || isSecretMarker(stored)) return {
165486
+ outcome: "already-done",
165487
+ summary: { moved: false }
165488
+ };
165489
+ await ports.storeFixedPin(stored);
165490
+ return {
165491
+ outcome: "done",
165492
+ summary: { moved: true }
165493
+ };
165494
+ }
165495
+ //#endregion
165496
+ //#region src/migrations/exposure-to-record.ts
165497
+ /**
165498
+ * The exposure lists the addon kept in its settings (`exposed`: the devices it mirrors, with
165499
+ * their per-device settings; `exposedActions`: the actions it publishes) move into the
165500
+ * `hap-bridge-exports` record of the default instance (D985, D996). Two migrations, in order:
165501
+ *
165502
+ * 1. `moveExposureToRecord` (procedure): put the record with `ifRev: 0`, read it BACK and
165503
+ * compare it with what the settings carried; a record that does not hold the same lists
165504
+ * throws and the settings are kept. An existing record is never overwritten.
165505
+ * 2. `planDropExposureKeys` (plan): the two keys are deleted from the canonical `addon-settings`
165506
+ * rows, and only while the record holds exactly what they carry. A record that differs (the
165507
+ * operator edited the lists since) keeps the old keys, which nothing reads any more.
165508
+ *
165509
+ * An entry the schema does not know (a mapper kind the addon no longer serves) is dropped on the
165510
+ * way, which is what the boot sweep did to it anyway.
165511
+ */
165512
+ /** Key-order-independent JSON, so "identical" does not depend on how a store orders keys. */
165513
+ function canonical(value) {
165514
+ if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
165515
+ 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(",")}}`;
165516
+ return JSON.stringify(value) ?? "null";
165517
+ }
165518
+ function parsedList(value, parse) {
165519
+ if (!Array.isArray(value)) return [];
165520
+ const kept = [];
165521
+ for (const entry of value) {
165522
+ const parsed = parse(entry);
165523
+ if (parsed.success) kept.push(parsed.data);
165524
+ }
165525
+ return kept;
165526
+ }
165527
+ /** The record body the legacy settings describe. */
165528
+ function exposureBodyFrom(stored) {
165529
+ return {
165530
+ name: HAP_EXPOSURE_NAME,
165531
+ devices: parsedList(stored["exposed"], (e) => ExposedConfigEntrySchema.safeParse(e)),
165532
+ actions: parsedList(stored["exposedActions"], (e) => ActionExportEntrySchema.safeParse(e))
165533
+ };
165534
+ }
165535
+ function sameLists(a, b) {
165536
+ return canonical(a.devices) === canonical(b.devices) && canonical(a.actions) === canonical(b.actions);
165537
+ }
165538
+ async function moveExposureToRecord(ports) {
165539
+ const stored = await ports.readStored(MOVED_EXPOSURE_KEYS);
165540
+ if (!MOVED_EXPOSURE_KEYS.some((key) => key in stored)) return {
165541
+ outcome: "already-done",
165542
+ summary: { moved: false }
165543
+ };
165544
+ const body = exposureBodyFrom(stored);
165545
+ const put = await ports.putExposure(body);
165546
+ const held = await ports.readExposure();
165547
+ if (held === null) throw new Error("the HomeKit exposure record cannot be read back");
165548
+ if (put === "created" && !sameLists(held, body)) throw new Error("the HomeKit exposure record does not hold the lists it adopted");
165549
+ return put === "created" ? {
165550
+ outcome: "done",
165551
+ summary: {
165552
+ moved: true,
165553
+ devices: body.devices.length
165554
+ }
165555
+ } : {
165556
+ outcome: "already-done",
165557
+ summary: { moved: false }
165558
+ };
165559
+ }
165560
+ var rowId = (key) => `${HAP_DEFAULT_INSTANCE_ID}.${key}`;
165561
+ async function planDropExposureKeys(ports) {
165562
+ const stored = await ports.readStored(MOVED_EXPOSURE_KEYS);
165563
+ const present = MOVED_EXPOSURE_KEYS.filter((key) => key in stored);
165564
+ if (present.length === 0) return { edits: [] };
165565
+ const held = await ports.readExposure();
165566
+ if (held === null || !sameLists(held, exposureBodyFrom(stored))) return { edits: [] };
165567
+ return { edits: [{
165568
+ op: "deleteKeys",
165569
+ scope: ADDON_SETTINGS_TABLE,
165570
+ keys: present.map(rowId),
165571
+ precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
165572
+ addonId: HAP_DEFAULT_INSTANCE_ID,
165573
+ key,
165574
+ value: stored[key]
165575
+ }])))
165576
+ }] };
165577
+ }
165578
+ //#endregion
165579
+ //#region src/migrations/identity-to-instance.ts
165580
+ /**
165581
+ * The bridge identity the addon kept in its settings (`identity`: username, uuid, pincode) moves
165582
+ * into the default instance record (D985, D996). Paired controllers know the bridge by exactly
165583
+ * these values, so the record is created with them UNCHANGED and the pass proves it by reading the
165584
+ * record back and comparing, field by field, before it reports `done`.
165585
+ *
165586
+ * Only once the read-back matches is the old `identity` cleared (its keychain entry released with
165587
+ * it), in this same pass: one path, no copy. An existing record is never overwritten; when it is
165588
+ * already there and names the same bridge (username, uuid) the leftover old identity of an
165589
+ * interrupted pass is cleared, and when it names another bridge the pass fails rather than guess.
165590
+ * An incomplete or unreadable legacy identity is `already-done` or throws, and never mints a new
165591
+ * one (a new identity unpairs every controller).
165592
+ */
165593
+ async function moveIdentityToDefaultInstance(ports) {
165594
+ const legacy = await ports.readLegacyIdentity();
165595
+ if (legacy === null) return {
165596
+ outcome: "already-done",
165597
+ summary: { moved: false }
165598
+ };
165599
+ const name = (await ports.readBridgeName()).trim();
165600
+ const body = {
165601
+ name: name.length > 0 ? name : "CamStack Bridge",
165602
+ username: legacy.username,
165603
+ uuid: legacy.uuid,
165604
+ pincode: legacy.pincode
165605
+ };
165606
+ const put = await ports.putDefaultRecord(body);
165607
+ const held = await ports.readDefaultRecord();
165608
+ if (held === null) throw new Error("the HomeKit default instance record cannot be read back");
165609
+ if (put === "exists") {
165610
+ if (held.username !== body.username || held.uuid !== body.uuid) throw new Error("the HomeKit default instance is another bridge than the stored identity");
165611
+ await ports.clearLegacyIdentity();
165612
+ return {
165613
+ outcome: "done",
165614
+ summary: {
165615
+ moved: false,
165616
+ cleared: true
165617
+ }
165618
+ };
165619
+ }
165620
+ if (!sameIdentity(identityOfBody(held), identityOfBody(body))) throw new Error("the HomeKit default instance does not hold the identity it adopted");
165621
+ await ports.clearLegacyIdentity();
165622
+ return {
165623
+ outcome: "done",
165624
+ summary: { moved: true }
165625
+ };
165626
+ }
165627
+ function sameIdentity(a, b) {
165628
+ return a.username === b.username && a.uuid === b.uuid && a.pincode === b.pincode;
165629
+ }
165630
+ /**
165631
+ * The identity a settings value describes, secrets resolved; null when it is not a complete
165632
+ * identity (first boot, or the empty sentinel). A pincode still a keychain marker was not
165633
+ * resolved: that throws, because treating "unreadable" as "absent" would mint a new identity.
165634
+ */
165635
+ function legacyIdentityOf(value) {
165636
+ if (typeof value !== "object" || value === null) return null;
165637
+ const username = Reflect.get(value, "username");
165638
+ const uuid = Reflect.get(value, "uuid");
165639
+ const pincode = Reflect.get(value, "pincode");
165640
+ if (isSecretMarker(pincode)) throw new Error("the stored HomeKit setup code cannot be resolved");
165641
+ if (typeof username !== "string" || typeof uuid !== "string" || typeof pincode !== "string" || username === "" || uuid === "" || pincode === "") return null;
165642
+ return {
165643
+ username,
165644
+ uuid,
165645
+ pincode
165646
+ };
165647
+ }
165648
+ //#endregion
165649
+ //#region src/migrations/bridge-name-to-instance.ts
165650
+ async function moveBridgeNameToInstance(ports) {
165651
+ const name = (await ports.readBridgeName()).trim();
165652
+ if (name === "") return {
165653
+ outcome: "already-done",
165654
+ summary: { renamed: false }
165655
+ };
165656
+ const held = await ports.readDefaultRecord();
165657
+ if (held === null || held.name === name) return {
165658
+ outcome: "already-done",
165659
+ summary: { renamed: false }
165660
+ };
165661
+ await ports.patchDefaultName(name);
165662
+ const after = await ports.readDefaultRecord();
165663
+ if (after === null || after.name !== name) throw new Error("the HomeKit default instance does not carry the name it adopted");
165664
+ return {
165665
+ outcome: "done",
165666
+ summary: { renamed: true }
165667
+ };
165668
+ }
165669
+ //#endregion
165670
+ //#region src/migrations/drop-global-knobs.ts
165671
+ /**
165672
+ * The retired global knobs of the HomeKit export. `bridgeName` is the instance's name and
165673
+ * `fixedPin` was an operator-typed setup code (a bridge's setup code is read-only now and changes
165674
+ * only through Regenerate); the bare `interfaceName` is the cluster copy of a setting that is a
165675
+ * fact of one node, which the node row carries since the per-node migration.
165676
+ *
165677
+ * Two bodies, in this order, because a secret must be released before its row goes (the
165678
+ * keychain value would be orphaned otherwise):
165679
+ * 1. `clearFixedPin` (procedure): the keychain value and marker of `fixedPin`;
165680
+ * 2. `planDropGlobalKnobRows` (plan): the rows `bridgeName`, `fixedPin` and the bare
165681
+ * `interfaceName`. The bare interfaceName goes only when the node row exists, so deleting it
165682
+ * can never lose the value. A `@<nodeId>` row is never touched.
165683
+ */
165684
+ async function clearFixedPin(ports) {
165685
+ if (!("fixedPin" in await ports.readStored(["fixedPin"]))) return {
165686
+ outcome: "already-done",
165687
+ summary: { cleared: false }
165688
+ };
165689
+ await ports.clearFixedPin();
165690
+ return {
165691
+ outcome: "done",
165692
+ summary: { cleared: true }
165693
+ };
165694
+ }
165695
+ async function planDropGlobalKnobRows(addonId, ports) {
165696
+ const stored = await ports.readStored([
165697
+ "bridgeName",
165698
+ "fixedPin",
165699
+ "interfaceName",
165700
+ nodeKeyOf("interfaceName")
165701
+ ]);
165702
+ const present = [
165703
+ "bridgeName",
165704
+ "fixedPin",
165705
+ "interfaceName"
165706
+ ].filter((key) => key in stored && (key !== "interfaceName" || nodeKeyOf("interfaceName") in stored));
165707
+ if (present.length === 0) return { edits: [] };
165708
+ const rowId = (key) => `${addonId}.${key}`;
165709
+ return { edits: [{
165710
+ op: "deleteKeys",
165711
+ scope: ADDON_SETTINGS_TABLE,
165712
+ keys: present.map(rowId),
165713
+ precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
165714
+ addonId,
165715
+ key,
165716
+ value: stored[key]
165717
+ }])))
165718
+ }] };
165719
+ }
165720
+ //#endregion
165721
+ //#region src/migrations/index.ts
165722
+ var EXPORT_HAP_ID = "export-hap";
165723
+ var INTERFACE_NAME_PER_NODE_ID = "export-hap/2026-11-03-interface-name-per-node";
165724
+ var FIXED_PIN_TO_KEYCHAIN_ID = "export-hap/2026-11-03-fixed-pin-to-keychain";
165725
+ var IDENTITY_TO_INSTANCE_ID = "export-hap/2026-11-04-identity-to-default-instance";
165726
+ var EXPOSURE_TO_RECORD_ID = "export-hap/2026-11-04-exposure-to-record";
165727
+ var DROP_EXPOSURE_KEYS_ID = "export-hap/2026-11-04-drop-exposure-keys";
165728
+ var BRIDGE_NAME_TO_INSTANCE_ID = "export-hap/2026-11-04-bridge-name-to-instance";
165729
+ var DROP_GLOBAL_KNOBS_ID = "export-hap/2026-11-04-drop-global-knobs";
165730
+ /** The `export-hap` catalogue (D987): offered to the engine when the addon initialises. */
165731
+ var ADDON_MIGRATIONS = [
165732
+ {
165733
+ meta: {
165734
+ id: INTERFACE_NAME_PER_NODE_ID,
165735
+ owner: EXPORT_HAP_ID,
165736
+ level: "addon-state",
165737
+ seq: 1,
165738
+ dependsOn: [],
165739
+ store: "settings",
165740
+ scope: "per-node",
165741
+ onFailure: "tolerate",
165742
+ bodyKind: "plan",
165743
+ description: "Copy the bare network interface setting to its hub node row; the bare row stays for a release",
165744
+ fixtureMark: "the bridge name the migration does not know"
165745
+ },
165746
+ plan: (ports) => planHubNodeFields(EXPORT_HAP_ID, ["interfaceName"], ports)
165747
+ },
165748
+ {
165749
+ meta: {
165750
+ id: FIXED_PIN_TO_KEYCHAIN_ID,
165751
+ owner: EXPORT_HAP_ID,
165752
+ level: "addon-state",
165753
+ seq: 2,
165754
+ dependsOn: [],
165755
+ store: "settings",
165756
+ scope: "cluster",
165757
+ onFailure: "tolerate",
165758
+ bodyKind: "procedure",
165759
+ description: "Move the fixed setup code from an inline setting into the keychain, where a password field keeps it",
165760
+ fixtureMark: "the bridge name the migration does not know"
165761
+ },
165762
+ procedure: moveFixedPinToKeychain
165763
+ },
165764
+ {
165765
+ meta: {
165766
+ id: IDENTITY_TO_INSTANCE_ID,
165767
+ owner: EXPORT_HAP_ID,
165768
+ level: "addon-state",
165769
+ seq: 3,
165770
+ dependsOn: [],
165771
+ store: "settings",
165772
+ scope: "cluster",
165773
+ onFailure: "block-owner",
165774
+ bodyKind: "procedure",
165775
+ 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",
165776
+ fixtureMark: "the bridge name the migration does not know"
165777
+ },
165778
+ procedure: moveIdentityToDefaultInstance
165779
+ },
165780
+ {
165781
+ meta: {
165782
+ id: EXPOSURE_TO_RECORD_ID,
165783
+ owner: EXPORT_HAP_ID,
165784
+ level: "addon-state",
165785
+ seq: 4,
165786
+ dependsOn: [IDENTITY_TO_INSTANCE_ID],
165787
+ store: "settings",
165788
+ scope: "cluster",
165789
+ onFailure: "block-owner",
165790
+ bodyKind: "procedure",
165791
+ description: "Move the exposed devices and actions into the default bridge exposure record, verified by read-back",
165792
+ fixtureMark: "the bridge name the migration does not know"
165793
+ },
165794
+ procedure: moveExposureToRecord
165795
+ },
165796
+ {
165797
+ meta: {
165798
+ id: DROP_EXPOSURE_KEYS_ID,
165799
+ owner: EXPORT_HAP_ID,
165800
+ level: "addon-state",
165801
+ seq: 5,
165802
+ dependsOn: [EXPOSURE_TO_RECORD_ID],
165803
+ store: "settings",
165804
+ scope: "cluster",
165805
+ onFailure: "tolerate",
165806
+ bodyKind: "plan",
165807
+ description: "Delete the old exposed and exposedActions settings once the record holds exactly what they carried",
165808
+ fixtureMark: "the bridge name the migration does not know"
165809
+ },
165810
+ plan: planDropExposureKeys
165811
+ },
165812
+ {
165813
+ meta: {
165814
+ id: BRIDGE_NAME_TO_INSTANCE_ID,
165815
+ owner: EXPORT_HAP_ID,
165816
+ level: "addon-state",
165817
+ seq: 6,
165818
+ dependsOn: [IDENTITY_TO_INSTANCE_ID],
165819
+ store: "settings",
165820
+ scope: "cluster",
165821
+ onFailure: "block-owner",
165822
+ bodyKind: "procedure",
165823
+ description: "Make the installation name the name of the default HomeKit instance record, verified by read-back",
165824
+ fixtureMark: "the bridge name the migration does not know"
165825
+ },
165826
+ procedure: moveBridgeNameToInstance
165827
+ },
165828
+ {
165829
+ meta: {
165830
+ id: DROP_GLOBAL_KNOBS_ID,
165831
+ owner: EXPORT_HAP_ID,
165832
+ level: "addon-state",
165833
+ seq: 7,
165834
+ dependsOn: [FIXED_PIN_TO_KEYCHAIN_ID, IDENTITY_TO_INSTANCE_ID],
165835
+ store: "settings",
165836
+ scope: "cluster",
165837
+ onFailure: "tolerate",
165838
+ bodyKind: "procedure",
165839
+ description: "Release the retired fixed setup code from the keychain: a bridge setup code is read-only now",
165840
+ fixtureMark: "the bridge name the migration does not know"
165841
+ },
165842
+ procedure: clearFixedPin
165843
+ },
165844
+ {
165845
+ meta: {
165846
+ id: "export-hap/2026-11-04-drop-global-knob-rows",
165847
+ owner: EXPORT_HAP_ID,
165848
+ level: "addon-state",
165849
+ seq: 8,
165850
+ dependsOn: [
165851
+ BRIDGE_NAME_TO_INSTANCE_ID,
165852
+ DROP_GLOBAL_KNOBS_ID,
165853
+ INTERFACE_NAME_PER_NODE_ID
165854
+ ],
165855
+ store: "settings",
165856
+ scope: "cluster",
165857
+ onFailure: "tolerate",
165858
+ bodyKind: "plan",
165859
+ description: "Delete the retired bridgeName, fixedPin and cluster interfaceName rows; the node rows are untouched",
165860
+ fixtureMark: "the bridge name the migration does not know"
165861
+ },
165862
+ plan: (ports) => planDropGlobalKnobRows(EXPORT_HAP_ID, ports)
165863
+ }
165864
+ ];
165865
+ //#endregion
165798
165866
  //#region src/reconcile/sync-state.ts
165799
165867
  function syncStateFromJson(json) {
165800
165868
  const map = /* @__PURE__ */ new Map();
@@ -167060,18 +167128,31 @@ var ExportHapAddon = class extends BaseAddon {
167060
167128
  async buildDeviceSettingsContribution(deviceId) {
167061
167129
  const kind = await this.resolveExportKind(deviceId);
167062
167130
  if (kind === null) return null;
167063
- const inst = this.instanceForDevice(deviceId);
167064
- if (inst === null) return null;
167131
+ const bridges = [...this.bridges.values()].toSorted((x, y) => Number(y.id === HAP_DEFAULT_INSTANCE_ID) - Number(x.id === HAP_DEFAULT_INSTANCE_ID));
167132
+ if (bridges.length === 0) return null;
167133
+ const named = bridges.length > 1;
167134
+ return {
167135
+ tabs: [{
167136
+ id: "export",
167137
+ label: "Export",
167138
+ icon: "share-2",
167139
+ order: 80
167140
+ }],
167141
+ sections: bridges.map((inst, index) => this.buildBridgeDeviceSection(inst, deviceId, kind, named, index))
167142
+ };
167143
+ }
167144
+ /** The Export section of one bridge for one device. Every key names the bridge. */
167145
+ buildBridgeDeviceSection(inst, deviceId, kind, named, index) {
167065
167146
  const entry = inst.findEntry(deviceId);
167066
167147
  const settings = entry?.settings ?? DEFAULT_DEVICE_SETTINGS;
167067
167148
  const enabled = entry !== null;
167068
- const enabledKey = `hap:${deviceId}:enabled`;
167069
- const streamPreferenceKey = `hap:${deviceId}:streamPreference`;
167070
- const multiTierKey = `hap:${deviceId}:multiTierService`;
167071
- const useBridgeKey = `hap:${deviceId}:useBridge`;
167072
- const allowTranscodeKey = `hap:${deviceId}:allowTranscode`;
167073
- const keepClipsKey = `hap:${deviceId}:keepClips`;
167074
- const clipRetentionKey = `hap:${deviceId}:clipRetentionDays`;
167149
+ const enabledKey = `hap:${inst.id}:${deviceId}:enabled`;
167150
+ const streamPreferenceKey = `hap:${inst.id}:${deviceId}:streamPreference`;
167151
+ const multiTierKey = `hap:${inst.id}:${deviceId}:multiTierService`;
167152
+ const useBridgeKey = `hap:${inst.id}:${deviceId}:useBridge`;
167153
+ const allowTranscodeKey = `hap:${inst.id}:${deviceId}:allowTranscode`;
167154
+ const keepClipsKey = `hap:${inst.id}:${deviceId}:keepClips`;
167155
+ const clipRetentionKey = `hap:${inst.id}:${deviceId}:clipRetentionDays`;
167075
167156
  const mapper = inst.exposed.get(String(deviceId)) ?? null;
167076
167157
  const paired = mapper ? accessoryPaired(mapper.accessory) : false;
167077
167158
  const bridged = mapper !== null && inst.bridgeHost.holds(mapper.accessory);
@@ -167118,7 +167199,7 @@ var ExportHapAddon = class extends BaseAddon {
167118
167199
  },
167119
167200
  {
167120
167201
  type: "info",
167121
- key: `hap:${deviceId}:hksvRecordingStatus`,
167202
+ key: `hap:${inst.id}:${deviceId}:hksvRecordingStatus`,
167122
167203
  label: "HomeKit recording (Secure Video)",
167123
167204
  content: describeHomekitRecording(readHomekitRecordingActive(inst.exposed.get(String(deviceId))?.accessories ?? []), this.hksvBuilds.lastFor(deviceId)),
167124
167205
  showWhen: {
@@ -167179,53 +167260,45 @@ var ExportHapAddon = class extends BaseAddon {
167179
167260
  }
167180
167261
  ];
167181
167262
  return {
167182
- tabs: [{
167183
- id: "export",
167184
- label: "Export",
167185
- icon: "share-2",
167186
- order: 80
167187
- }],
167188
- sections: [{
167189
- id: "export-hap",
167190
- title: "HomeKit Export",
167191
- 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.",
167192
- tab: "export",
167193
- columns: 1,
167194
- order: 10,
167195
- fields: [
167196
- {
167197
- type: "info",
167198
- key: "__hap-status",
167199
- label: "Status",
167200
- content: statusLabel,
167201
- variant: "info"
167202
- },
167203
- {
167204
- type: "qr-code",
167205
- key: "__hap-pair-qr",
167206
- label: paired ? "Pairing QR (already paired)" : "Pairing QR",
167207
- 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}.`,
167208
- value: qrValue,
167209
- size: 192,
167210
- alt: `HomeKit pairing QR for ${name}`,
167211
- showWhen: {
167212
- field: enabledKey,
167213
- equals: true
167214
- }
167215
- },
167216
- {
167217
- type: "boolean",
167218
- key: enabledKey,
167219
- label: "Expose to HomeKit",
167220
- description: "Toggle to publish this device as a HomeKit accessory.",
167221
- style: "switch",
167222
- value: enabled,
167223
- immediate: true
167224
- },
167225
- ...bridgeFields,
167226
- ...cameraFields
167227
- ]
167228
- }]
167263
+ id: `${EXPORT_HAP_ADDON_ID}:${inst.id}`,
167264
+ title: named ? `HomeKit Export — ${inst.name}` : "HomeKit Export",
167265
+ 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.",
167266
+ tab: "export",
167267
+ columns: 1,
167268
+ order: 10 + index,
167269
+ fields: [
167270
+ {
167271
+ type: "info",
167272
+ key: `__hap-status:${inst.id}`,
167273
+ label: "Status",
167274
+ content: statusLabel,
167275
+ variant: "info"
167276
+ },
167277
+ {
167278
+ type: "qr-code",
167279
+ key: `__hap-pair-qr:${inst.id}`,
167280
+ label: paired ? "Pairing QR (already paired)" : "Pairing QR",
167281
+ 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}.`,
167282
+ value: qrValue,
167283
+ size: 192,
167284
+ alt: `HomeKit pairing QR for ${name}`,
167285
+ showWhen: {
167286
+ field: enabledKey,
167287
+ equals: true
167288
+ }
167289
+ },
167290
+ {
167291
+ type: "boolean",
167292
+ key: enabledKey,
167293
+ label: "Expose to HomeKit",
167294
+ description: "Toggle to publish this device as a HomeKit accessory.",
167295
+ style: "switch",
167296
+ value: enabled,
167297
+ immediate: true
167298
+ },
167299
+ ...bridgeFields,
167300
+ ...cameraFields
167301
+ ]
167229
167302
  };
167230
167303
  }
167231
167304
  /**
@@ -167241,19 +167314,33 @@ var ExportHapAddon = class extends BaseAddon {
167241
167314
  * note in CLAUDE.md (Remaining work).
167242
167315
  */
167243
167316
  async applyDeviceSettingsPatch(deviceId, patch) {
167317
+ const instanceIds = bridgeIdsInPatch(deviceId, patch);
167318
+ if (instanceIds.length === 0) {
167319
+ const stale = Object.keys(patch).filter((k) => k.startsWith("hap:"));
167320
+ if (stale.length > 0) throw new Error(`export-hap: device ${deviceId} patch names no HomeKit bridge (${stale.join(", ")}) — reload the Export tab`);
167321
+ this.ctx.logger.warn("export-hap: a device patch carried no HomeKit key — nothing applied", {
167322
+ tags: { deviceId },
167323
+ meta: { keys: Object.keys(patch) }
167324
+ });
167325
+ return { success: true };
167326
+ }
167327
+ for (const instanceId of instanceIds) this.requireBridge(instanceId);
167328
+ for (const instanceId of instanceIds) await this.applyBridgeDevicePatch(this.requireBridge(instanceId), deviceId, patch);
167329
+ return { success: true };
167330
+ }
167331
+ /** Apply the keys of ONE bridge (`hap:<inst.id>:<deviceId>:…`) to that bridge. */
167332
+ async applyBridgeDevicePatch(inst, deviceId, patch) {
167244
167333
  const deviceIdStr = String(deviceId);
167245
167334
  const log = this.ctx.logger.withTags({ deviceId });
167246
- const inst = this.instanceForDevice(deviceId);
167247
- if (inst === null) throw new Error("export-hap: no HomeKit bridge is running — add or enable one first");
167248
167335
  const current = inst.findEntry(deviceId);
167249
167336
  const wasEnabled = inst.exposed.has(deviceIdStr);
167250
- const enabledKey = `hap:${deviceId}:enabled`;
167251
- const streamPreferenceKey = `hap:${deviceId}:streamPreference`;
167252
- const useBridgeKey = `hap:${deviceId}:useBridge`;
167253
- const allowTranscodeKey = `hap:${deviceId}:allowTranscode`;
167254
- const multiTierKey = `hap:${deviceId}:multiTierService`;
167255
- const keepClipsKey = `hap:${deviceId}:keepClips`;
167256
- const clipRetentionKey = `hap:${deviceId}:clipRetentionDays`;
167337
+ const enabledKey = `hap:${inst.id}:${deviceId}:enabled`;
167338
+ const streamPreferenceKey = `hap:${inst.id}:${deviceId}:streamPreference`;
167339
+ const useBridgeKey = `hap:${inst.id}:${deviceId}:useBridge`;
167340
+ const allowTranscodeKey = `hap:${inst.id}:${deviceId}:allowTranscode`;
167341
+ const multiTierKey = `hap:${inst.id}:${deviceId}:multiTierService`;
167342
+ const keepClipsKey = `hap:${inst.id}:${deviceId}:keepClips`;
167343
+ const clipRetentionKey = `hap:${inst.id}:${deviceId}:clipRetentionDays`;
167257
167344
  const enabledValue = enabledKey in patch ? Boolean(patch[enabledKey]) : wasEnabled;
167258
167345
  const streamPreferenceRaw = streamPreferenceKey in patch ? patch[streamPreferenceKey] : current?.settings?.streamPreference;
167259
167346
  const streamPreference = typeof streamPreferenceRaw === "string" && streamPreferenceRaw.trim().length > 0 ? streamPreferenceRaw : "auto";
@@ -167437,6 +167524,21 @@ var ExportHapAddon = class extends BaseAddon {
167437
167524
  await this.setExposedDevices(inst, next);
167438
167525
  }
167439
167526
  };
167527
+ /**
167528
+ * The bridges a device patch addresses, read from its keys (`hap:<instanceId>:<deviceId>:<setting>`),
167529
+ * in first-seen order. Keys of another device or another exporter are not this patch's.
167530
+ */
167531
+ function bridgeIdsInPatch(deviceId, patch) {
167532
+ const ids = /* @__PURE__ */ new Set();
167533
+ for (const key of Object.keys(patch)) {
167534
+ const match = HAP_DEVICE_KEY.exec(key);
167535
+ if (match === null || match[2] !== String(deviceId)) continue;
167536
+ const instanceId = match[1];
167537
+ if (instanceId !== void 0) ids.add(instanceId);
167538
+ }
167539
+ return [...ids];
167540
+ }
167541
+ var HAP_DEVICE_KEY = /^hap:([^:]+):(\d+):\w+$/;
167440
167542
  function errMsg(err) {
167441
167543
  return err instanceof Error ? err.message : String(err);
167442
167544
  }