@camstack/addon-export-hap 1.2.200 → 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.
@@ -861,7 +861,7 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
861
861
  return EventCategory;
862
862
  }({});
863
863
  //#endregion
864
- //#region ../types/dist/composed-stable-id-CPp3votu.mjs
864
+ //#region ../types/dist/composed-stable-id-iddnCQ51.mjs
865
865
  /**
866
866
  import { errMsg } from '@camstack/types'
867
867
  * Extract a human-readable message from an unknown error value.
@@ -1203,6 +1203,11 @@ var DeviceRole = /* @__PURE__ */ function(DeviceRole) {
1203
1203
  * with the switch's on/off only. Speed or oscillation appear only when the
1204
1204
  * device also has a fan cap (D1033). */
1205
1205
  DeviceRole["SwitchFan"] = "switch-fan";
1206
+ /** A relay driving an on/off-only lamp: drawn as a light (bulb and glow, no
1207
+ * slider), presented to the exports as a light with power only. Not a
1208
+ * `light` type: the provider owns the type, and a light implies brightness
1209
+ * or colour this relay lacks. */
1210
+ DeviceRole["SwitchLight"] = "switch-light";
1206
1211
  /** Air conditioner / split unit: cooling, fan speed, louvres. */
1207
1212
  DeviceRole["ClimateAc"] = "climate-ac";
1208
1213
  /** Room thermostat: a setpoint and a room temperature. The default. */
@@ -6103,7 +6108,7 @@ var ZodIssueCode = {
6103
6108
  var ZodFirstPartyTypeKind;
6104
6109
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
6105
6110
  //#endregion
6106
- //#region ../types/dist/sleep-DyIxjZZt.mjs
6111
+ //#region ../types/dist/sleep-BvVGLl30.mjs
6107
6112
  /**
6108
6113
  * The audio chunk plane's byte format, and the ONE expansion from a coded
6109
6114
  * window to float samples (D455).
@@ -10816,6 +10821,13 @@ var ACTUATOR_CAP_VOCABULARY = {
10816
10821
  },
10817
10822
  state: { on: { icon: "lightbulb" } }
10818
10823
  },
10824
+ [DeviceRole.SwitchLight]: {
10825
+ actions: {
10826
+ "switch.on": { icon: "lightbulb" },
10827
+ "switch.off": { icon: "lightbulb-off" }
10828
+ },
10829
+ state: { on: { icon: "lightbulb" } }
10830
+ },
10819
10831
  [DeviceRole.Chime]: { actions: {
10820
10832
  "switch.on": {
10821
10833
  label: t("Enable chime", "Attiva il campanello"),
@@ -17595,7 +17607,7 @@ Object.freeze({
17595
17607
  }
17596
17608
  });
17597
17609
  //#endregion
17598
- //#region ../types/dist/implemented-methods-5YMDeE3f.mjs
17610
+ //#region ../types/dist/implemented-methods-CSTk6zYK.mjs
17599
17611
  var AUDIO_ENCODER_BY_CODEC = {
17600
17612
  opus: "libopus",
17601
17613
  aac: "aac",
@@ -18245,6 +18257,60 @@ function portable(target) {
18245
18257
  }
18246
18258
  portable("linux64"), portable("linuxarm64"), portable("macarm64"), portable("mac64"), `${BASE}${FFMPEG_RELEASE}`;
18247
18259
  /**
18260
+ * A device's KIND is its type plus its role (D1033): the type is the set of
18261
+ * controls it has, the role says which thing it is among the devices that
18262
+ * share those controls. A plug-in heater is a `switch` with role
18263
+ * `switch-heater`; an air conditioner and a radiator valve are both `climate`,
18264
+ * told apart by their `climate-*` role.
18265
+ */
18266
+ /**
18267
+ * Type values a persisted row may still carry after the type was retired, and
18268
+ * the type each one is read as. The row is rewritten by the next registration
18269
+ * of the device (its provider stamps the live type), so this is a read alias,
18270
+ * not a migration.
18271
+ *
18272
+ * `heater` is deliberately absent: the only heaters were composed devices the
18273
+ * operator deletes. Such a row stays an unknown type, which every reader
18274
+ * treats as a generic device.
18275
+ */
18276
+ var RETIRED_DEVICE_TYPES = { thermostat: DeviceType.Climate };
18277
+ /** The live type a stored `type` value stands for (itself unless retired). */
18278
+ function canonicalStoredDeviceType(stored) {
18279
+ return RETIRED_DEVICE_TYPES[stored] ?? stored;
18280
+ }
18281
+ preprocess((value) => typeof value === "string" ? canonicalStoredDeviceType(value) : value, _enum(DeviceType));
18282
+ DeviceRole.ClimateThermostat, DeviceRole.ClimateAc, DeviceRole.ClimateRadiator, DeviceRole.ClimateFloor, DeviceRole.ClimateHeater, DeviceRole.ClimateHeatPumpCircuit;
18283
+ /**
18284
+ * A relay driving an on/off-only lamp (a `switch` with role `switch-light`):
18285
+ * drawn and exported as a light, with the switch's power only. The one place
18286
+ * that reads the role for it — a consumer asks this, never the role string.
18287
+ */
18288
+ function isSwitchLight(type, role) {
18289
+ return type === DeviceType.Switch && role === DeviceRole.SwitchLight;
18290
+ }
18291
+ /**
18292
+ * A smart plug (a `switch` with role `outlet`, D875): exported as a plug /
18293
+ * outlet. Exports ask this, never the role string.
18294
+ */
18295
+ function isOutlet(type, role) {
18296
+ return type === DeviceType.Switch && role === DeviceRole.Outlet;
18297
+ }
18298
+ /**
18299
+ * A plain fan behind a switch (a `switch` with role `switch-fan`): exported as
18300
+ * a fan with the switch's on/off only — no speed it does not have.
18301
+ */
18302
+ function isSwitchFan(type, role) {
18303
+ return type === DeviceType.Switch && role === DeviceRole.SwitchFan;
18304
+ }
18305
+ /**
18306
+ * A plug-in heater behind a switch (a `switch` with role `switch-heater`): it
18307
+ * has power only, no setpoint and no room temperature, so an export never
18308
+ * presents it as a thermostat.
18309
+ */
18310
+ function isSwitchHeater(type, role) {
18311
+ return type === DeviceType.Switch && role === DeviceRole.SwitchHeater;
18312
+ }
18313
+ /**
18248
18314
  * THE table "which boolean of this device type counts as HIGH", and the
18249
18315
  * pure evaluator of its EDGE.
18250
18316
  *
@@ -24172,7 +24238,7 @@ var DeviceTokenScopeSchema = object({
24172
24238
  function migrateLegacyTokenScope(raw) {
24173
24239
  if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
24174
24240
  if (Reflect.get(raw, "type") !== "device") return raw;
24175
- if (Reflect.get(raw, "selector") !== void 0) return raw;
24241
+ if (Reflect.get(raw, "selector") !== void 0) return canonicalSelectorTypes(raw);
24176
24242
  const targets = Reflect.get(raw, "targets");
24177
24243
  if (!Array.isArray(targets)) return raw;
24178
24244
  return {
@@ -24184,6 +24250,27 @@ function migrateLegacyTokenScope(raw) {
24184
24250
  access: Reflect.get(raw, "access")
24185
24251
  };
24186
24252
  }
24253
+ /**
24254
+ * A stored `types` selector may name a type D1033 retired (`thermostat`). The
24255
+ * grant is read back through this same preprocess, so the retired name is
24256
+ * rewritten to its canonical type here and {@link DeviceSelectorSchema} itself
24257
+ * stays a strict enum on the wire.
24258
+ */
24259
+ function canonicalSelectorTypes(raw) {
24260
+ const selector = Reflect.get(raw, "selector");
24261
+ if (selector === null || typeof selector !== "object") return raw;
24262
+ if (Reflect.get(selector, "kind") !== "types") return raw;
24263
+ const types = Reflect.get(selector, "types");
24264
+ if (!Array.isArray(types)) return raw;
24265
+ const canonical = types.map((t) => typeof t === "string" ? canonicalStoredDeviceType(t) : t);
24266
+ return {
24267
+ ...raw,
24268
+ selector: {
24269
+ ...selector,
24270
+ types: canonical
24271
+ }
24272
+ };
24273
+ }
24187
24274
  var TokenScopeSchema = preprocess(migrateLegacyTokenScope, discriminatedUnion("type", [
24188
24275
  object({
24189
24276
  type: literal("category"),
@@ -52238,8 +52325,8 @@ function actuator(input) {
52238
52325
  };
52239
52326
  }
52240
52327
  new Map(GROUP_TEMPLATES.map((template) => [template.id, template]));
52241
- DeviceFeature.LightColorRgb, DeviceFeature.LightColorHsv, DeviceFeature.LightColorMired;
52242
52328
  DeviceType.Camera;
52329
+ DeviceFeature.LightColorRgb, DeviceFeature.LightColorHsv, DeviceFeature.LightColorMired;
52243
52330
  var PowerSourceRefusalReasonSchema = _enum([
52244
52331
  "no-power-source",
52245
52332
  "switch-missing",
@@ -57724,6 +57811,15 @@ var HeroTextSchema = object({
57724
57811
  it: string()
57725
57812
  });
57726
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
+ /**
57727
57823
  * The ONE measurement a simple sensor shows (card wave, phase 1).
57728
57824
  *
57729
57825
  * A sensor that measures a single quantity (a temperature, a humidity, a power,
@@ -57840,6 +57936,62 @@ function textMeasurement(text, since) {
57840
57936
  historyKey: null
57841
57937
  };
57842
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
+ }
57843
57995
  /** The scene as the model carries it. `null` = the device did not say (never a guess). */
57844
57996
  var HeroSceneSchema = object({
57845
57997
  id: _enum([
@@ -57890,7 +58042,7 @@ var HeroSceneSchema = object({
57890
58042
  level: number$1().min(0).max(1).nullable()
57891
58043
  });
57892
58044
  DeviceType.Camera, DeviceType.Hub, DeviceType.Light, DeviceType.Siren, DeviceType.Switch, DeviceType.Sensor, DeviceType.Climate, DeviceType.Button, DeviceType.EventEmitter, DeviceType.Update, DeviceType.Generic, DeviceType.Notifier, DeviceType.Script, DeviceType.Automation, DeviceType.Lock, DeviceType.Cover, DeviceType.Valve, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.HeatPump, 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;
57893
- 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.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;
58045
+ 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;
57894
58046
  var HeroRowIdSchema = _enum([
57895
58047
  "progress",
57896
58048
  "run-for",
@@ -80995,8 +81147,6 @@ var AccessoryKind = {
80995
81147
  };
80996
81148
  AccessoryKind.Siren, AccessoryKind.Floodlight, AccessoryKind.Spotlight, AccessoryKind.PirSensor, AccessoryKind.Chime, AccessoryKind.Autotrack, AccessoryKind.Nightvision, AccessoryKind.PrivacyMask;
80997
81149
  DeviceType.HeatPump;
80998
- DeviceType.Climate;
80999
- DeviceRole.ClimateThermostat, DeviceRole.ClimateAc, DeviceRole.ClimateRadiator, DeviceRole.ClimateFloor, DeviceRole.ClimateHeater, DeviceRole.ClimateHeatPumpCircuit;
81000
81150
  DeviceType.Cover, DeviceType.Valve, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.HeatPump, DeviceType.Camera, DeviceType.Hub, DeviceType.Switch, DeviceType.Siren, DeviceType.Light, DeviceType.Fan, DeviceType.Sensor, DeviceType.Climate, DeviceType.Button, DeviceType.EventEmitter, DeviceType.Update, DeviceType.Generic, DeviceType.Notifier, DeviceType.Script, DeviceType.Automation, DeviceType.Lock, 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;
81001
81151
  new Set(Object.values(DeviceType));
81002
81152
  /** Parses the raw slice with the cap's own schema; `undefined` when it does not parse. */
@@ -81135,7 +81285,7 @@ var lockContribution = contribution("lock-control", LockControlStatusSchema, (sl
81135
81285
  const state = slice?.state ?? null;
81136
81286
  const words = state === null ? null : LOCK_WORDS[state];
81137
81287
  const since = slice === void 0 ? null : elapsedText(slice.lastChangedAt, ctx.now);
81138
- const title = words?.title ?? t("Unknown", "Sconosciuto");
81288
+ const title = words?.title ?? NOT_REPORTED;
81139
81289
  return {
81140
81290
  reading: reading("lock-control", words?.state ?? "unknown", false, words?.title),
81141
81291
  rows: [row$1("lock", state === "locked" || state === "locking" ? "lock" : "lock-open", joinText([title, since]), lockControls(state, ctx.features.includes(DeviceFeature.LockOpen)))],
@@ -81227,7 +81377,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81227
81377
  const modes = slice === void 0 ? ALARM_MODES : slice.availableModes;
81228
81378
  return {
81229
81379
  reading: reading("alarm-panel", words?.state ?? "unknown", false, words?.title),
81230
- 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))],
81231
81381
  ...since === null || words === null ? {} : { facts: [fact("since", "clock", since, state === "triggered" ? "danger" : "muted")] },
81232
81382
  ...words === null ? {} : { tiles: {
81233
81383
  left: [{
@@ -81258,7 +81408,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81258
81408
  return {
81259
81409
  reading: reading("automation-control", state, false, title),
81260
81410
  rows: [row$1("automation", "workflow", joinText([
81261
- title ?? t("Unknown", "Sconosciuto"),
81411
+ title ?? NOT_REPORTED,
81262
81412
  last === null ? null : t(`Ran ${last.en}`, `Eseguita ${last.it}`),
81263
81413
  slice?.lastError == null ? null : t(slice.lastError, slice.lastError)
81264
81414
  ]), [asAction(run), toggle])],
@@ -81274,7 +81424,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81274
81424
  return {
81275
81425
  reading: reading("script-runner", state, false, title),
81276
81426
  rows: [row$1("script", "scroll-text", joinText([
81277
- title ?? t("Unknown", "Sconosciuto"),
81427
+ title ?? NOT_REPORTED,
81278
81428
  last === null ? null : t(`Ran ${last.en}`, `Eseguito ${last.it}`),
81279
81429
  slice?.lastError == null ? null : t(slice.lastError, slice.lastError)
81280
81430
  ]), [asAction(control)])],
@@ -81283,7 +81433,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81283
81433
  }),
81284
81434
  "do-not-disturb": contribution("do-not-disturb", DoNotDisturbStatusSchema, (slice) => {
81285
81435
  const on = slice?.enabled ?? null;
81286
- 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"), [{
81287
81437
  kind: "toggle",
81288
81438
  id: "do-not-disturb.toggle",
81289
81439
  label: t("Do not disturb", "Non disturbare"),
@@ -81301,7 +81451,7 @@ var ACCESS_FAMILY_CONTRIBUTIONS = {
81301
81451
  * is absent from the facts, never a zero (D393).
81302
81452
  */
81303
81453
  var has$3 = (ctx, f) => ctx.features.includes(f);
81304
- var unknownText = t("Unknown", "Sconosciuto");
81454
+ var unknownText = NOT_REPORTED;
81305
81455
  var pct$2 = (n) => t(`${Math.round(n)}%`, `${Math.round(n)}%`);
81306
81456
  var unit = (n) => Math.min(1, Math.max(0, n / 100));
81307
81457
  /** Battery as a fact, unless the device is also bound to the `battery` cap (it already says so). */
@@ -82707,13 +82857,13 @@ function sensorFragment(value, id, icon, en, it, text) {
82707
82857
  tiles: { right: [tile$1(en, it, text)] }
82708
82858
  };
82709
82859
  }
82710
- 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)));
82711
- 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)));
82712
82862
  var pressureContribution = contribution("pressure-sensor", PressureSensorStatusSchema, (slice) => sensorFragment(slice?.pressure ?? null, "pressure", "gauge", "Pressure", "Pressione", `${Math.round(slice?.pressure ?? 0)} hPa`));
82713
82863
  var illuminanceContribution = contribution("ambient-light-sensor", AmbientLightSensorStatusSchema, (slice) => sensorFragment(slice?.illuminance ?? null, "illuminance", "sun", "Light", "Luce", `${Math.round(slice?.illuminance ?? 0)} lx`));
82714
82864
  var numericContribution = contribution("numeric-sensor", NumericSensorStatusSchema, (slice) => sensorFragment(slice?.value ?? null, "reading", "gauge", "Value", "Valore", String(Number((slice?.value ?? 0).toFixed(2)))));
82715
82865
  var enumContribution = contribution("enum-sensor", EnumSensorStatusSchema, (slice) => {
82716
- 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"));
82717
82867
  if (slice.timestamp === true) return { reading: reading("sensor", "on") };
82718
82868
  return measured(sensorFragment(slice.value, "reading", "gauge", "State", "Stato", slice.value), textMeasurement(slice.value, slice.lastFetchedAt));
82719
82869
  });
@@ -82837,7 +82987,7 @@ function circuitControl(circuit) {
82837
82987
  return picker(`heat-pump.${circuit.id}.mode`, t("Mode", "Modalità"), circuit.operationMode, method, args);
82838
82988
  }
82839
82989
  /** A circuit with no reading is still a row: it shows that nothing is known, not nothing. */
82840
- var UNKNOWN_STATUS = same("—");
82990
+ var UNKNOWN_STATUS = NOT_REPORTED;
82841
82991
  function circuitRow(circuit) {
82842
82992
  const control = circuitControl(circuit);
82843
82993
  const status = thermalStatusText(circuit.targetTemp, circuit.currentTemp) ?? UNKNOWN_STATUS;
@@ -83061,9 +83211,8 @@ function look(icon, tone, background, animation) {
83061
83211
  animation
83062
83212
  };
83063
83213
  }
83064
- /** A state a device is in whatever it is: unreachable, or silent. Identical for every look. */
83214
+ /** Unreachable: identical for every look. */
83065
83215
  var OFFLINE = look("wifi-off", "muted", "plain", "none");
83066
- var UNKNOWN = look("circle-question-mark", "muted", "plain", "none");
83067
83216
  var ALERT = look("triangle-alert", "danger", "alert-wash", "pulse");
83068
83217
  function lookOf(spec) {
83069
83218
  const at = (s) => look(spec.icon, s[0], s[1], s[2]);
@@ -83075,7 +83224,7 @@ function lookOf(spec) {
83075
83224
  standby: at(spec.standby),
83076
83225
  alert: spec.alert ?? ALERT,
83077
83226
  offline: OFFLINE,
83078
- unknown: UNKNOWN
83227
+ unknown: look(spec.icon, "muted", "plain", "none")
83079
83228
  };
83080
83229
  }
83081
83230
  var MUTED = [
@@ -83684,7 +83833,7 @@ lookOf({
83684
83833
  });
83685
83834
  DeviceType.Climate;
83686
83835
  DeviceType.Camera, DeviceType.Hub, DeviceType.Light, DeviceType.Siren, DeviceType.Switch, DeviceType.Sensor, DeviceType.Climate, DeviceType.Button, DeviceType.EventEmitter, DeviceType.Update, DeviceType.Generic, DeviceType.Notifier, DeviceType.Script, DeviceType.Automation, DeviceType.Lock, DeviceType.Cover, DeviceType.Valve, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.HeatPump, 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;
83687
- 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.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;
83836
+ 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;
83688
83837
  Object.freeze({
83689
83838
  "accessories.getStatus": {
83690
83839
  capName: "accessories",
@@ -94165,6 +94314,10 @@ function applianceExport(ecosystem, deviceType) {
94165
94314
  if (!isPlugApplianceType(deviceType)) return null;
94166
94315
  return APPLIANCE_EXPORT[ecosystem][deviceType];
94167
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));
94168
94321
  Object.freeze({
94169
94322
  "accessories.getStatus": [{
94170
94323
  name: "deviceId",
@@ -146272,446 +146425,6 @@ async function resolveDefaultBridge(ports) {
146272
146425
  };
146273
146426
  }
146274
146427
  //#endregion
146275
- //#region src/migrations/hub-node-fields.ts
146276
- /**
146277
- * Fields stored once for the cluster that are facts of ONE node become node settings (D986): a
146278
- * node's row is `<addonId>.<key>@<nodeId>` carrying `nodeId`, and a node never falls back to a
146279
- * bare row. This owner is placed `hub-only`, so the one node that ever held a value is the hub:
146280
- * each bare row is COPIED to `<key>@hub`. The bare row stays for a release (a copy, not a move),
146281
- * and a value already on the node row is never overwritten (a seed never overwrites).
146282
- *
146283
- * A keychain marker is copied verbatim: it names the owner and the secret, not the row that
146284
- * points at it. Idempotent: with every bare row copied the plan is empty.
146285
- */
146286
- /** The canonical settings table: one row per key, id `<addonId>.<key>`. */
146287
- var ADDON_SETTINGS_TABLE = "addon-settings";
146288
- var nodeKeyOf = (key) => `${key}@hub`;
146289
- async function planHubNodeFields(addonId, keys, ports) {
146290
- const stored = await ports.readStored([...keys, ...keys.map(nodeKeyOf)]);
146291
- const pending = keys.filter((key) => key in stored && !(nodeKeyOf(key) in stored));
146292
- if (pending.length === 0) return { edits: [] };
146293
- const rowId = (key) => `${addonId}.${nodeKeyOf(key)}`;
146294
- return { edits: [{
146295
- op: "setKeys",
146296
- scope: ADDON_SETTINGS_TABLE,
146297
- values: Object.fromEntries(pending.map((key) => [rowId(key), {
146298
- addonId,
146299
- key: nodeKeyOf(key),
146300
- value: stored[key],
146301
- nodeId: "hub"
146302
- }])),
146303
- precondition: preconditionOf(Object.fromEntries(pending.map((key) => [rowId(key), null])))
146304
- }] };
146305
- }
146306
- /**
146307
- * The port's read over an addon's three-way key read: each of `keys` that has a row, raw. A key
146308
- * the store could not answer for throws, so the migration fails instead of treating a failed read
146309
- * as "nothing to copy".
146310
- */
146311
- async function readRawKeys(read, addonId, keys) {
146312
- const found = {};
146313
- for (const key of keys) {
146314
- const answer = await read(key);
146315
- if (answer.kind === "unreadable") throw new Error(`${addonId}: the setting ${key} cannot be read (${answer.reason})`);
146316
- if (answer.kind === "present") found[key] = answer.value;
146317
- }
146318
- return found;
146319
- }
146320
- //#endregion
146321
- //#region src/migrations/fixed-pin-to-keychain.ts
146322
- /**
146323
- * The fixed HomeKit setup code pairs a controller with the bridge: a credential. It was a plain
146324
- * text setting, stored inline in the settings row; it is a `password` field now (D783), and a
146325
- * password lives in the keychain with a marker in the row. This procedure moves a stored inline
146326
- * code there, through the operator write path (the one that stores an inline value of a
146327
- * pre-keychain addon as a keychain secret).
146328
- *
146329
- * Idempotent: an absent, empty or already marker-backed code is `already-done`, so a crash
146330
- * between the keychain write and the ledger row costs nothing on the rerun.
146331
- */
146332
- async function moveFixedPinToKeychain(ports) {
146333
- const stored = (await ports.readStored(["fixedPin"]))["fixedPin"];
146334
- if (typeof stored !== "string" || stored === "" || isSecretMarker(stored)) return {
146335
- outcome: "already-done",
146336
- summary: { moved: false }
146337
- };
146338
- await ports.storeFixedPin(stored);
146339
- return {
146340
- outcome: "done",
146341
- summary: { moved: true }
146342
- };
146343
- }
146344
- //#endregion
146345
- //#region src/migrations/exposure-to-record.ts
146346
- /**
146347
- * The exposure lists the addon kept in its settings (`exposed`: the devices it mirrors, with
146348
- * their per-device settings; `exposedActions`: the actions it publishes) move into the
146349
- * `hap-bridge-exports` record of the default instance (D985, D996). Two migrations, in order:
146350
- *
146351
- * 1. `moveExposureToRecord` (procedure): put the record with `ifRev: 0`, read it BACK and
146352
- * compare it with what the settings carried; a record that does not hold the same lists
146353
- * throws and the settings are kept. An existing record is never overwritten.
146354
- * 2. `planDropExposureKeys` (plan): the two keys are deleted from the canonical `addon-settings`
146355
- * rows, and only while the record holds exactly what they carry. A record that differs (the
146356
- * operator edited the lists since) keeps the old keys, which nothing reads any more.
146357
- *
146358
- * An entry the schema does not know (a mapper kind the addon no longer serves) is dropped on the
146359
- * way, which is what the boot sweep did to it anyway.
146360
- */
146361
- /** Key-order-independent JSON, so "identical" does not depend on how a store orders keys. */
146362
- function canonical(value) {
146363
- if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
146364
- 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(",")}}`;
146365
- return JSON.stringify(value) ?? "null";
146366
- }
146367
- function parsedList(value, parse) {
146368
- if (!Array.isArray(value)) return [];
146369
- const kept = [];
146370
- for (const entry of value) {
146371
- const parsed = parse(entry);
146372
- if (parsed.success) kept.push(parsed.data);
146373
- }
146374
- return kept;
146375
- }
146376
- /** The record body the legacy settings describe. */
146377
- function exposureBodyFrom(stored) {
146378
- return {
146379
- name: HAP_EXPOSURE_NAME,
146380
- devices: parsedList(stored["exposed"], (e) => ExposedConfigEntrySchema.safeParse(e)),
146381
- actions: parsedList(stored["exposedActions"], (e) => ActionExportEntrySchema.safeParse(e))
146382
- };
146383
- }
146384
- function sameLists(a, b) {
146385
- return canonical(a.devices) === canonical(b.devices) && canonical(a.actions) === canonical(b.actions);
146386
- }
146387
- async function moveExposureToRecord(ports) {
146388
- const stored = await ports.readStored(MOVED_EXPOSURE_KEYS);
146389
- if (!MOVED_EXPOSURE_KEYS.some((key) => key in stored)) return {
146390
- outcome: "already-done",
146391
- summary: { moved: false }
146392
- };
146393
- const body = exposureBodyFrom(stored);
146394
- const put = await ports.putExposure(body);
146395
- const held = await ports.readExposure();
146396
- if (held === null) throw new Error("the HomeKit exposure record cannot be read back");
146397
- if (put === "created" && !sameLists(held, body)) throw new Error("the HomeKit exposure record does not hold the lists it adopted");
146398
- return put === "created" ? {
146399
- outcome: "done",
146400
- summary: {
146401
- moved: true,
146402
- devices: body.devices.length
146403
- }
146404
- } : {
146405
- outcome: "already-done",
146406
- summary: { moved: false }
146407
- };
146408
- }
146409
- var rowId = (key) => `${HAP_DEFAULT_INSTANCE_ID}.${key}`;
146410
- async function planDropExposureKeys(ports) {
146411
- const stored = await ports.readStored(MOVED_EXPOSURE_KEYS);
146412
- const present = MOVED_EXPOSURE_KEYS.filter((key) => key in stored);
146413
- if (present.length === 0) return { edits: [] };
146414
- const held = await ports.readExposure();
146415
- if (held === null || !sameLists(held, exposureBodyFrom(stored))) return { edits: [] };
146416
- return { edits: [{
146417
- op: "deleteKeys",
146418
- scope: ADDON_SETTINGS_TABLE,
146419
- keys: present.map(rowId),
146420
- precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
146421
- addonId: HAP_DEFAULT_INSTANCE_ID,
146422
- key,
146423
- value: stored[key]
146424
- }])))
146425
- }] };
146426
- }
146427
- //#endregion
146428
- //#region src/migrations/identity-to-instance.ts
146429
- /**
146430
- * The bridge identity the addon kept in its settings (`identity`: username, uuid, pincode) moves
146431
- * into the default instance record (D985, D996). Paired controllers know the bridge by exactly
146432
- * these values, so the record is created with them UNCHANGED and the pass proves it by reading the
146433
- * record back and comparing, field by field, before it reports `done`.
146434
- *
146435
- * Only once the read-back matches is the old `identity` cleared (its keychain entry released with
146436
- * it), in this same pass: one path, no copy. An existing record is never overwritten; when it is
146437
- * already there and names the same bridge (username, uuid) the leftover old identity of an
146438
- * interrupted pass is cleared, and when it names another bridge the pass fails rather than guess.
146439
- * An incomplete or unreadable legacy identity is `already-done` or throws, and never mints a new
146440
- * one (a new identity unpairs every controller).
146441
- */
146442
- async function moveIdentityToDefaultInstance(ports) {
146443
- const legacy = await ports.readLegacyIdentity();
146444
- if (legacy === null) return {
146445
- outcome: "already-done",
146446
- summary: { moved: false }
146447
- };
146448
- const name = (await ports.readBridgeName()).trim();
146449
- const body = {
146450
- name: name.length > 0 ? name : "CamStack Bridge",
146451
- username: legacy.username,
146452
- uuid: legacy.uuid,
146453
- pincode: legacy.pincode
146454
- };
146455
- const put = await ports.putDefaultRecord(body);
146456
- const held = await ports.readDefaultRecord();
146457
- if (held === null) throw new Error("the HomeKit default instance record cannot be read back");
146458
- if (put === "exists") {
146459
- if (held.username !== body.username || held.uuid !== body.uuid) throw new Error("the HomeKit default instance is another bridge than the stored identity");
146460
- await ports.clearLegacyIdentity();
146461
- return {
146462
- outcome: "done",
146463
- summary: {
146464
- moved: false,
146465
- cleared: true
146466
- }
146467
- };
146468
- }
146469
- if (!sameIdentity(identityOfBody(held), identityOfBody(body))) throw new Error("the HomeKit default instance does not hold the identity it adopted");
146470
- await ports.clearLegacyIdentity();
146471
- return {
146472
- outcome: "done",
146473
- summary: { moved: true }
146474
- };
146475
- }
146476
- function sameIdentity(a, b) {
146477
- return a.username === b.username && a.uuid === b.uuid && a.pincode === b.pincode;
146478
- }
146479
- /**
146480
- * The identity a settings value describes, secrets resolved; null when it is not a complete
146481
- * identity (first boot, or the empty sentinel). A pincode still a keychain marker was not
146482
- * resolved: that throws, because treating "unreadable" as "absent" would mint a new identity.
146483
- */
146484
- function legacyIdentityOf(value) {
146485
- if (typeof value !== "object" || value === null) return null;
146486
- const username = Reflect.get(value, "username");
146487
- const uuid = Reflect.get(value, "uuid");
146488
- const pincode = Reflect.get(value, "pincode");
146489
- if (isSecretMarker(pincode)) throw new Error("the stored HomeKit setup code cannot be resolved");
146490
- if (typeof username !== "string" || typeof uuid !== "string" || typeof pincode !== "string" || username === "" || uuid === "" || pincode === "") return null;
146491
- return {
146492
- username,
146493
- uuid,
146494
- pincode
146495
- };
146496
- }
146497
- //#endregion
146498
- //#region src/migrations/bridge-name-to-instance.ts
146499
- async function moveBridgeNameToInstance(ports) {
146500
- const name = (await ports.readBridgeName()).trim();
146501
- if (name === "") return {
146502
- outcome: "already-done",
146503
- summary: { renamed: false }
146504
- };
146505
- const held = await ports.readDefaultRecord();
146506
- if (held === null || held.name === name) return {
146507
- outcome: "already-done",
146508
- summary: { renamed: false }
146509
- };
146510
- await ports.patchDefaultName(name);
146511
- const after = await ports.readDefaultRecord();
146512
- if (after === null || after.name !== name) throw new Error("the HomeKit default instance does not carry the name it adopted");
146513
- return {
146514
- outcome: "done",
146515
- summary: { renamed: true }
146516
- };
146517
- }
146518
- //#endregion
146519
- //#region src/migrations/drop-global-knobs.ts
146520
- /**
146521
- * The retired global knobs of the HomeKit export. `bridgeName` is the instance's name and
146522
- * `fixedPin` was an operator-typed setup code (a bridge's setup code is read-only now and changes
146523
- * only through Regenerate); the bare `interfaceName` is the cluster copy of a setting that is a
146524
- * fact of one node, which the node row carries since the per-node migration.
146525
- *
146526
- * Two bodies, in this order, because a secret must be released before its row goes (the
146527
- * keychain value would be orphaned otherwise):
146528
- * 1. `clearFixedPin` (procedure): the keychain value and marker of `fixedPin`;
146529
- * 2. `planDropGlobalKnobRows` (plan): the rows `bridgeName`, `fixedPin` and the bare
146530
- * `interfaceName`. The bare interfaceName goes only when the node row exists, so deleting it
146531
- * can never lose the value. A `@<nodeId>` row is never touched.
146532
- */
146533
- async function clearFixedPin(ports) {
146534
- if (!("fixedPin" in await ports.readStored(["fixedPin"]))) return {
146535
- outcome: "already-done",
146536
- summary: { cleared: false }
146537
- };
146538
- await ports.clearFixedPin();
146539
- return {
146540
- outcome: "done",
146541
- summary: { cleared: true }
146542
- };
146543
- }
146544
- async function planDropGlobalKnobRows(addonId, ports) {
146545
- const stored = await ports.readStored([
146546
- "bridgeName",
146547
- "fixedPin",
146548
- "interfaceName",
146549
- nodeKeyOf("interfaceName")
146550
- ]);
146551
- const present = [
146552
- "bridgeName",
146553
- "fixedPin",
146554
- "interfaceName"
146555
- ].filter((key) => key in stored && (key !== "interfaceName" || nodeKeyOf("interfaceName") in stored));
146556
- if (present.length === 0) return { edits: [] };
146557
- const rowId = (key) => `${addonId}.${key}`;
146558
- return { edits: [{
146559
- op: "deleteKeys",
146560
- scope: ADDON_SETTINGS_TABLE,
146561
- keys: present.map(rowId),
146562
- precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
146563
- addonId,
146564
- key,
146565
- value: stored[key]
146566
- }])))
146567
- }] };
146568
- }
146569
- //#endregion
146570
- //#region src/migrations/index.ts
146571
- var EXPORT_HAP_ID = "export-hap";
146572
- var INTERFACE_NAME_PER_NODE_ID = "export-hap/2026-11-03-interface-name-per-node";
146573
- var FIXED_PIN_TO_KEYCHAIN_ID = "export-hap/2026-11-03-fixed-pin-to-keychain";
146574
- var IDENTITY_TO_INSTANCE_ID = "export-hap/2026-11-04-identity-to-default-instance";
146575
- var EXPOSURE_TO_RECORD_ID = "export-hap/2026-11-04-exposure-to-record";
146576
- var DROP_EXPOSURE_KEYS_ID = "export-hap/2026-11-04-drop-exposure-keys";
146577
- var BRIDGE_NAME_TO_INSTANCE_ID = "export-hap/2026-11-04-bridge-name-to-instance";
146578
- var DROP_GLOBAL_KNOBS_ID = "export-hap/2026-11-04-drop-global-knobs";
146579
- /** The `export-hap` catalogue (D987): offered to the engine when the addon initialises. */
146580
- var ADDON_MIGRATIONS = [
146581
- {
146582
- meta: {
146583
- id: INTERFACE_NAME_PER_NODE_ID,
146584
- owner: EXPORT_HAP_ID,
146585
- level: "addon-state",
146586
- seq: 1,
146587
- dependsOn: [],
146588
- store: "settings",
146589
- scope: "per-node",
146590
- onFailure: "tolerate",
146591
- bodyKind: "plan",
146592
- description: "Copy the bare network interface setting to its hub node row; the bare row stays for a release",
146593
- fixtureMark: "the bridge name the migration does not know"
146594
- },
146595
- plan: (ports) => planHubNodeFields(EXPORT_HAP_ID, ["interfaceName"], ports)
146596
- },
146597
- {
146598
- meta: {
146599
- id: FIXED_PIN_TO_KEYCHAIN_ID,
146600
- owner: EXPORT_HAP_ID,
146601
- level: "addon-state",
146602
- seq: 2,
146603
- dependsOn: [],
146604
- store: "settings",
146605
- scope: "cluster",
146606
- onFailure: "tolerate",
146607
- bodyKind: "procedure",
146608
- description: "Move the fixed setup code from an inline setting into the keychain, where a password field keeps it",
146609
- fixtureMark: "the bridge name the migration does not know"
146610
- },
146611
- procedure: moveFixedPinToKeychain
146612
- },
146613
- {
146614
- meta: {
146615
- id: IDENTITY_TO_INSTANCE_ID,
146616
- owner: EXPORT_HAP_ID,
146617
- level: "addon-state",
146618
- seq: 3,
146619
- dependsOn: [],
146620
- store: "settings",
146621
- scope: "cluster",
146622
- onFailure: "block-owner",
146623
- bodyKind: "procedure",
146624
- 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",
146625
- fixtureMark: "the bridge name the migration does not know"
146626
- },
146627
- procedure: moveIdentityToDefaultInstance
146628
- },
146629
- {
146630
- meta: {
146631
- id: EXPOSURE_TO_RECORD_ID,
146632
- owner: EXPORT_HAP_ID,
146633
- level: "addon-state",
146634
- seq: 4,
146635
- dependsOn: [IDENTITY_TO_INSTANCE_ID],
146636
- store: "settings",
146637
- scope: "cluster",
146638
- onFailure: "block-owner",
146639
- bodyKind: "procedure",
146640
- description: "Move the exposed devices and actions into the default bridge exposure record, verified by read-back",
146641
- fixtureMark: "the bridge name the migration does not know"
146642
- },
146643
- procedure: moveExposureToRecord
146644
- },
146645
- {
146646
- meta: {
146647
- id: DROP_EXPOSURE_KEYS_ID,
146648
- owner: EXPORT_HAP_ID,
146649
- level: "addon-state",
146650
- seq: 5,
146651
- dependsOn: [EXPOSURE_TO_RECORD_ID],
146652
- store: "settings",
146653
- scope: "cluster",
146654
- onFailure: "tolerate",
146655
- bodyKind: "plan",
146656
- description: "Delete the old exposed and exposedActions settings once the record holds exactly what they carried",
146657
- fixtureMark: "the bridge name the migration does not know"
146658
- },
146659
- plan: planDropExposureKeys
146660
- },
146661
- {
146662
- meta: {
146663
- id: BRIDGE_NAME_TO_INSTANCE_ID,
146664
- owner: EXPORT_HAP_ID,
146665
- level: "addon-state",
146666
- seq: 6,
146667
- dependsOn: [IDENTITY_TO_INSTANCE_ID],
146668
- store: "settings",
146669
- scope: "cluster",
146670
- onFailure: "block-owner",
146671
- bodyKind: "procedure",
146672
- description: "Make the installation name the name of the default HomeKit instance record, verified by read-back",
146673
- fixtureMark: "the bridge name the migration does not know"
146674
- },
146675
- procedure: moveBridgeNameToInstance
146676
- },
146677
- {
146678
- meta: {
146679
- id: DROP_GLOBAL_KNOBS_ID,
146680
- owner: EXPORT_HAP_ID,
146681
- level: "addon-state",
146682
- seq: 7,
146683
- dependsOn: [FIXED_PIN_TO_KEYCHAIN_ID, IDENTITY_TO_INSTANCE_ID],
146684
- store: "settings",
146685
- scope: "cluster",
146686
- onFailure: "tolerate",
146687
- bodyKind: "procedure",
146688
- description: "Release the retired fixed setup code from the keychain: a bridge setup code is read-only now",
146689
- fixtureMark: "the bridge name the migration does not know"
146690
- },
146691
- procedure: clearFixedPin
146692
- },
146693
- {
146694
- meta: {
146695
- id: "export-hap/2026-11-04-drop-global-knob-rows",
146696
- owner: EXPORT_HAP_ID,
146697
- level: "addon-state",
146698
- seq: 8,
146699
- dependsOn: [
146700
- BRIDGE_NAME_TO_INSTANCE_ID,
146701
- DROP_GLOBAL_KNOBS_ID,
146702
- INTERFACE_NAME_PER_NODE_ID
146703
- ],
146704
- store: "settings",
146705
- scope: "cluster",
146706
- onFailure: "tolerate",
146707
- bodyKind: "plan",
146708
- description: "Delete the retired bridgeName, fixedPin and cluster interfaceName rows; the node rows are untouched",
146709
- fixtureMark: "the bridge name the migration does not know"
146710
- },
146711
- plan: (ports) => planDropGlobalKnobRows(EXPORT_HAP_ID, ports)
146712
- }
146713
- ];
146714
- //#endregion
146715
146428
  //#region src/hap-setup-uri.ts
146716
146429
  function errMsg$15(e) {
146717
146430
  return e instanceof Error ? e.message : String(e);
@@ -147964,38 +147677,6 @@ function createClipThumbnailMinter(input) {
147964
147677
  };
147965
147678
  }
147966
147679
  //#endregion
147967
- //#region src/hksv/recording-active.ts
147968
- /**
147969
- * `true`/`false` as HomeKit holds it, or `null` when this accessory does not
147970
- * offer recording at all.
147971
- */
147972
- function readHomekitRecordingActive(accessories) {
147973
- for (const accessory of accessories) {
147974
- const service = accessory.getService(import_dist.Service.CameraRecordingManagement);
147975
- if (service === void 0) continue;
147976
- const value = service.getCharacteristic(import_dist.Characteristic.Active).value;
147977
- if (typeof value === "number") return value === 1;
147978
- if (typeof value === "boolean") return value;
147979
- return null;
147980
- }
147981
- return null;
147982
- }
147983
- /**
147984
- * One sentence for the settings page: what HomeKit says, or why it was never
147985
- * asked.
147986
- *
147987
- * The cost stays in the text even though the switch is gone. It is still the
147988
- * operator's to understand — a camera recording here runs a permanent ffmpeg —
147989
- * and a status line that reported only the state would have quietly dropped
147990
- * the one number that decides whether to turn it on.
147991
- */
147992
- function describeHomekitRecording(active, lastBuild) {
147993
- 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).";
147994
- 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.";
147995
- if (lastBuild !== null && !lastBuild.advertised) return `Recording is not offered for this camera: ${lastBuild.detail ?? "the accessory could not advertise it"}.`;
147996
- return "Not known yet — this camera’s accessory has not published its recording service in this process. It appears once the accessory is built.";
147997
- }
147998
- //#endregion
147999
147680
  //#region src/hksv/recording-source.ts
148000
147681
  /** The tallest frame the recording path will hold in its prebuffer. */
148001
147682
  var MAX_RECORDING_HEIGHT = 1080;
@@ -148111,6 +147792,38 @@ function recordabilityTokenFor(input) {
148111
147792
  return recordabilityToken(input.entries, { allowTranscode: input.allowTranscode !== false });
148112
147793
  }
148113
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
148114
147827
  //#region src/hksv/videoclips-plane.ts
148115
147828
  /**
148116
147829
  * The two data-plane routes behind the HomeKit clip source.
@@ -148892,7 +148605,8 @@ function errMsg$14(err) {
148892
148605
  * hands this builder the PARENT accessory + the CHILD's proxy + a
148893
148606
  * unique subtype so each service round-trips deterministically through
148894
148607
  * HAP serialisation. The builder:
148895
- * - Maps `switch` cap → `Service.Switch`.
148608
+ * - Maps `switch` cap → `Service.Switch`, or the service the device's switch
148609
+ * sub-role names (`onOffServiceKind`).
148896
148610
  * - Maps `switch` + `brightness` cap → `Service.Lightbulb` with
148897
148611
  * Brightness characteristic (lighting devices only — see below).
148898
148612
  * - Hydrates initial state from `getStatus({})`.
@@ -148914,7 +148628,21 @@ function errMsg$14(err) {
148914
148628
  * Child devices without `switch` / `brightness` cap (status sensors,
148915
148629
  * IR LED, etc.) return a no-op handle.
148916
148630
  */
148917
- async function buildChildSwitch(bctx, subtype, deviceType) {
148631
+ function onOffServiceKind(deviceType, role, hasBrightness) {
148632
+ const isLightingDevice = deviceType === DeviceType.Light || deviceType === DeviceType.Generic;
148633
+ if (hasBrightness && isLightingDevice) return "dimmable-lightbulb";
148634
+ if (isSwitchLight(deviceType, role)) return "lightbulb";
148635
+ if (isOutlet(deviceType, role)) return "outlet";
148636
+ if (isSwitchFan(deviceType, role)) return "fan";
148637
+ return "switch";
148638
+ }
148639
+ function addOnOffService(accessory, kind, displayName, subtype) {
148640
+ if (kind === "dimmable-lightbulb" || kind === "lightbulb") return accessory.addService(import_dist.Service.Lightbulb, displayName, subtype);
148641
+ if (kind === "outlet") return accessory.addService(import_dist.Service.Outlet, displayName, subtype);
148642
+ if (kind === "fan") return accessory.addService(import_dist.Service.Fan, displayName, subtype);
148643
+ return accessory.addService(import_dist.Service.Switch, displayName, subtype);
148644
+ }
148645
+ async function buildChildSwitch(bctx, subtype, deviceType, role = null) {
148918
148646
  const { ctx, accessory, proxy, numericDeviceId, displayName } = bctx;
148919
148647
  const log = ctx.logger.withTags({ deviceId: numericDeviceId });
148920
148648
  const hasSwitch = !!proxy.switch;
@@ -148923,17 +148651,21 @@ async function buildChildSwitch(bctx, subtype, deviceType) {
148923
148651
  log.debug("export-hap: child has no switch/brightness cap — skipping");
148924
148652
  return { async dispose() {} };
148925
148653
  }
148926
- const isLightingDevice = deviceType === DeviceType.Light || deviceType === DeviceType.Generic;
148927
- const useLightbulb = hasBrightness && isLightingDevice;
148928
- const service = useLightbulb ? accessory.addService(import_dist.Service.Lightbulb, displayName, subtype) : accessory.addService(import_dist.Service.Switch, displayName, subtype);
148654
+ const kind = onOffServiceKind(deviceType, role, hasBrightness);
148655
+ const dimmable = kind === "dimmable-lightbulb";
148656
+ const service = addOnOffService(accessory, kind, displayName, subtype);
148929
148657
  applyServiceLabel(service, displayName);
148658
+ const setOn = (on) => {
148659
+ service.updateCharacteristic(import_dist.Characteristic.On, on);
148660
+ if (kind === "outlet") service.updateCharacteristic(import_dist.Characteristic.OutletInUse, on);
148661
+ };
148930
148662
  try {
148931
148663
  const switchStatus = await proxy.switch?.getStatus({});
148932
- if (switchStatus && typeof switchStatus.on === "boolean") service.updateCharacteristic(import_dist.Characteristic.On, switchStatus.on);
148664
+ if (switchStatus && typeof switchStatus.on === "boolean") setOn(switchStatus.on);
148933
148665
  } catch (err) {
148934
148666
  log.debug("export-hap: child switch.getStatus failed (non-fatal)", { meta: { error: errMsg$13(err) } });
148935
148667
  }
148936
- if (useLightbulb) try {
148668
+ if (dimmable) try {
148937
148669
  const status = await proxy.brightness?.getStatus({});
148938
148670
  if (status && typeof status.level === "number") service.updateCharacteristic(import_dist.Characteristic.Brightness, status.level);
148939
148671
  } catch (err) {
@@ -148950,7 +148682,7 @@ async function buildChildSwitch(bctx, subtype, deviceType) {
148950
148682
  } });
148951
148683
  }
148952
148684
  });
148953
- if (useLightbulb) service.getCharacteristic(import_dist.Characteristic.Brightness).onSet(async (value) => {
148685
+ if (dimmable) service.getCharacteristic(import_dist.Characteristic.Brightness).onSet(async (value) => {
148954
148686
  const percentage = typeof value === "number" ? value : Number(value);
148955
148687
  if (!Number.isFinite(percentage)) return;
148956
148688
  try {
@@ -148965,11 +148697,11 @@ async function buildChildSwitch(bctx, subtype, deviceType) {
148965
148697
  const unsubscribes = [];
148966
148698
  if (proxy.state.switch) {
148967
148699
  const unsubSwitch = proxy.state.switch.subscribe((value) => {
148968
- if (value && typeof value.on === "boolean") service.updateCharacteristic(import_dist.Characteristic.On, value.on);
148700
+ if (value && typeof value.on === "boolean") setOn(value.on);
148969
148701
  });
148970
148702
  unsubscribes.push(unsubSwitch);
148971
148703
  }
148972
- if (useLightbulb && proxy.state.brightness) {
148704
+ if (dimmable && proxy.state.brightness) {
148973
148705
  const unsubBrightness = proxy.state.brightness.subscribe((value) => {
148974
148706
  if (value && typeof value.level === "number") service.updateCharacteristic(import_dist.Characteristic.Brightness, value.level);
148975
148707
  });
@@ -149577,10 +149309,10 @@ var HAP_CAP_SERVICES = [
149577
149309
  {
149578
149310
  caps: ["switch", "brightness"],
149579
149311
  label: "Power",
149580
- build: ({ bctx, name, deviceType }) => buildChildSwitch({
149312
+ build: ({ bctx, name, deviceType, role }) => buildChildSwitch({
149581
149313
  ...bctx,
149582
149314
  displayName: name
149583
- }, "switch", deviceType)
149315
+ }, "switch", deviceType, role)
149584
149316
  },
149585
149317
  {
149586
149318
  caps: ["lock-control"],
@@ -149638,7 +149370,17 @@ var ACCESSORY_CATEGORY_BY_TYPE = {
149638
149370
  [DeviceType.Presence]: import_dist.Categories.SENSOR,
149639
149371
  [DeviceType.AlarmPanel]: import_dist.Categories.SECURITY_SYSTEM
149640
149372
  };
149641
- function accessoryCategoryFor(deviceType) {
149373
+ /**
149374
+ * The category, by type and then by the switch's sub-role (read only through
149375
+ * the `@camstack/types` accessors). A heater keeps a Switch service (see
149376
+ * `onOffServiceKind`) and takes HomeKit's heater category, which is an icon
149377
+ * and promises no characteristic. A helper boolean stays a SWITCH.
149378
+ */
149379
+ function accessoryCategoryFor(deviceType, role) {
149380
+ if (isSwitchLight(deviceType, role)) return import_dist.Categories.LIGHTBULB;
149381
+ if (isOutlet(deviceType, role)) return import_dist.Categories.OUTLET;
149382
+ if (isSwitchFan(deviceType, role)) return import_dist.Categories.FAN;
149383
+ if (isSwitchHeater(deviceType, role)) return import_dist.Categories.AIR_HEATER;
149642
149384
  return ACCESSORY_CATEGORY_BY_TYPE[deviceType] ?? import_dist.Categories.OTHER;
149643
149385
  }
149644
149386
  //#endregion
@@ -164625,7 +164367,7 @@ async function buildChildServicesFor(input) {
164625
164367
  options
164626
164368
  };
164627
164369
  const subtype = `child-${child.id}`;
164628
- handles.push(await buildChildSwitch(childCtx, subtype, asDeviceType(child.type)));
164370
+ handles.push(await buildChildSwitch(childCtx, subtype, asDeviceType(child.type), child.role ?? null));
164629
164371
  }
164630
164372
  return { async dispose() {
164631
164373
  for (const h of handles) try {
@@ -165603,9 +165345,9 @@ async function buildGenericAccessory(input) {
165603
165345
  const capNames = new Set(proxy.binding?.entries.map((e) => e.capName) ?? []);
165604
165346
  const rows = rowsForCaps(capNames);
165605
165347
  if (rows.length === 0) throw new Error(`export-hap: device ${numericId} carries no capability HomeKit can export (bound: ${[...capNames].toSorted().join(", ") || "none"})`);
165606
- const deviceType = await resolveDeviceType(proxy);
165348
+ const { type: deviceType, role } = await resolveDeviceKind(proxy);
165607
165349
  const accessory = new import_dist.Accessory(displayName, accessoryUuidFor("generic", numericId, options.instanceId));
165608
- accessory.category = accessoryCategoryFor(deviceType);
165350
+ accessory.category = accessoryCategoryFor(deviceType, role);
165609
165351
  await populateAccessoryInfo(accessory, proxy, displayName, "Accessory");
165610
165352
  const bctx = {
165611
165353
  ctx,
@@ -165621,11 +165363,13 @@ async function buildGenericAccessory(input) {
165621
165363
  handles.push(await row.build({
165622
165364
  bctx,
165623
165365
  name,
165624
- deviceType
165366
+ deviceType,
165367
+ role
165625
165368
  }));
165626
165369
  }
165627
165370
  log.info("export-hap: built generic accessory", { meta: {
165628
165371
  deviceType,
165372
+ role,
165629
165373
  services: rows.map((row) => row.caps[0]).join(",")
165630
165374
  } });
165631
165375
  return {
@@ -165641,20 +165385,27 @@ async function buildGenericAccessory(input) {
165641
165385
  };
165642
165386
  }
165643
165387
  /**
165644
- * The device's own type, or `Generic`.
165388
+ * The device's own type, or `Generic`, and its role (null when unread).
165645
165389
  *
165646
165390
  * Used ONLY where one capability has two HomeKit shapes — a siren's
165647
- * `brightness` is alarm volume, not luminosity — and for the accessory's icon.
165391
+ * `brightness` is alarm volume, not luminosity; a `switch-light` relay is a
165392
+ * Lightbulb, not a Switch — and for the accessory's icon.
165648
165393
  * `Generic` is the safe reading: it is the shape `child-switch.ts` already
165649
165394
  * treats as "a lamp if it dims, a switch otherwise".
165650
165395
  */
165651
- async function resolveDeviceType(proxy) {
165396
+ async function resolveDeviceKind(proxy) {
165652
165397
  try {
165653
165398
  const device = await proxy.deviceManager?.getDevice({});
165654
165399
  const raw = typeof device?.type === "string" ? device.type.toLowerCase() : "";
165655
- return Object.values(DeviceType).find((value) => value === raw) ?? DeviceType.Generic;
165400
+ return {
165401
+ type: Object.values(DeviceType).find((value) => value === raw) ?? DeviceType.Generic,
165402
+ role: typeof device?.role === "string" ? device.role : null
165403
+ };
165656
165404
  } catch {
165657
- return DeviceType.Generic;
165405
+ return {
165406
+ type: DeviceType.Generic,
165407
+ role: null
165408
+ };
165658
165409
  }
165659
165410
  }
165660
165411
  function errMsg$1(err) {
@@ -165672,6 +165423,446 @@ function getMapperFactory(kind) {
165672
165423
  return factory;
165673
165424
  }
165674
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
165675
165866
  //#region src/reconcile/sync-state.ts
165676
165867
  function syncStateFromJson(json) {
165677
165868
  const map = /* @__PURE__ */ new Map();
@@ -166937,18 +167128,31 @@ var ExportHapAddon = class extends BaseAddon {
166937
167128
  async buildDeviceSettingsContribution(deviceId) {
166938
167129
  const kind = await this.resolveExportKind(deviceId);
166939
167130
  if (kind === null) return null;
166940
- const inst = this.instanceForDevice(deviceId);
166941
- 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) {
166942
167146
  const entry = inst.findEntry(deviceId);
166943
167147
  const settings = entry?.settings ?? DEFAULT_DEVICE_SETTINGS;
166944
167148
  const enabled = entry !== null;
166945
- const enabledKey = `hap:${deviceId}:enabled`;
166946
- const streamPreferenceKey = `hap:${deviceId}:streamPreference`;
166947
- const multiTierKey = `hap:${deviceId}:multiTierService`;
166948
- const useBridgeKey = `hap:${deviceId}:useBridge`;
166949
- const allowTranscodeKey = `hap:${deviceId}:allowTranscode`;
166950
- const keepClipsKey = `hap:${deviceId}:keepClips`;
166951
- 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`;
166952
167156
  const mapper = inst.exposed.get(String(deviceId)) ?? null;
166953
167157
  const paired = mapper ? accessoryPaired(mapper.accessory) : false;
166954
167158
  const bridged = mapper !== null && inst.bridgeHost.holds(mapper.accessory);
@@ -166995,7 +167199,7 @@ var ExportHapAddon = class extends BaseAddon {
166995
167199
  },
166996
167200
  {
166997
167201
  type: "info",
166998
- key: `hap:${deviceId}:hksvRecordingStatus`,
167202
+ key: `hap:${inst.id}:${deviceId}:hksvRecordingStatus`,
166999
167203
  label: "HomeKit recording (Secure Video)",
167000
167204
  content: describeHomekitRecording(readHomekitRecordingActive(inst.exposed.get(String(deviceId))?.accessories ?? []), this.hksvBuilds.lastFor(deviceId)),
167001
167205
  showWhen: {
@@ -167056,53 +167260,45 @@ var ExportHapAddon = class extends BaseAddon {
167056
167260
  }
167057
167261
  ];
167058
167262
  return {
167059
- tabs: [{
167060
- id: "export",
167061
- label: "Export",
167062
- icon: "share-2",
167063
- order: 80
167064
- }],
167065
- sections: [{
167066
- id: "export-hap",
167067
- title: "HomeKit Export",
167068
- 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.",
167069
- tab: "export",
167070
- columns: 1,
167071
- order: 10,
167072
- fields: [
167073
- {
167074
- type: "info",
167075
- key: "__hap-status",
167076
- label: "Status",
167077
- content: statusLabel,
167078
- variant: "info"
167079
- },
167080
- {
167081
- type: "qr-code",
167082
- key: "__hap-pair-qr",
167083
- label: paired ? "Pairing QR (already paired)" : "Pairing QR",
167084
- 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}.`,
167085
- value: qrValue,
167086
- size: 192,
167087
- alt: `HomeKit pairing QR for ${name}`,
167088
- showWhen: {
167089
- field: enabledKey,
167090
- equals: true
167091
- }
167092
- },
167093
- {
167094
- type: "boolean",
167095
- key: enabledKey,
167096
- label: "Expose to HomeKit",
167097
- description: "Toggle to publish this device as a HomeKit accessory.",
167098
- style: "switch",
167099
- value: enabled,
167100
- immediate: true
167101
- },
167102
- ...bridgeFields,
167103
- ...cameraFields
167104
- ]
167105
- }]
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
+ ]
167106
167302
  };
167107
167303
  }
167108
167304
  /**
@@ -167118,19 +167314,33 @@ var ExportHapAddon = class extends BaseAddon {
167118
167314
  * note in CLAUDE.md (Remaining work).
167119
167315
  */
167120
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) {
167121
167333
  const deviceIdStr = String(deviceId);
167122
167334
  const log = this.ctx.logger.withTags({ deviceId });
167123
- const inst = this.instanceForDevice(deviceId);
167124
- if (inst === null) throw new Error("export-hap: no HomeKit bridge is running — add or enable one first");
167125
167335
  const current = inst.findEntry(deviceId);
167126
167336
  const wasEnabled = inst.exposed.has(deviceIdStr);
167127
- const enabledKey = `hap:${deviceId}:enabled`;
167128
- const streamPreferenceKey = `hap:${deviceId}:streamPreference`;
167129
- const useBridgeKey = `hap:${deviceId}:useBridge`;
167130
- const allowTranscodeKey = `hap:${deviceId}:allowTranscode`;
167131
- const multiTierKey = `hap:${deviceId}:multiTierService`;
167132
- const keepClipsKey = `hap:${deviceId}:keepClips`;
167133
- 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`;
167134
167344
  const enabledValue = enabledKey in patch ? Boolean(patch[enabledKey]) : wasEnabled;
167135
167345
  const streamPreferenceRaw = streamPreferenceKey in patch ? patch[streamPreferenceKey] : current?.settings?.streamPreference;
167136
167346
  const streamPreference = typeof streamPreferenceRaw === "string" && streamPreferenceRaw.trim().length > 0 ? streamPreferenceRaw : "auto";
@@ -167314,6 +167524,21 @@ var ExportHapAddon = class extends BaseAddon {
167314
167524
  await this.setExposedDevices(inst, next);
167315
167525
  }
167316
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+$/;
167317
167542
  function errMsg(err) {
167318
167543
  return err instanceof Error ? err.message : String(err);
167319
167544
  }