@camstack/addon-export-hap 1.2.111 → 1.2.113

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.
@@ -5431,7 +5431,7 @@ var ZodIssueCode = {
5431
5431
  var ZodFirstPartyTypeKind;
5432
5432
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5433
5433
  //#endregion
5434
- //#region ../types/dist/sleep-CnLyvg3w.mjs
5434
+ //#region ../types/dist/sleep-DBKu2-U5.mjs
5435
5435
  /**
5436
5436
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5437
5437
  * window to float samples (D455).
@@ -7432,7 +7432,7 @@ method(object({ deviceId: number() }), array(StreamSourceEntrySchema)), method(o
7432
7432
  input: unknown()
7433
7433
  }), unknown(), { kind: "mutation" }), method(object({ deviceId: number() }), _void(), { kind: "mutation" }), method(object({ deviceId: number() }), unknown().nullable()), method(object({ deviceId: number() }), RawStateResultSchema.nullable(), { auth: "protected" });
7434
7434
  //#endregion
7435
- //#region ../types/dist/canonical-hash-rO1sRmEK.mjs
7435
+ //#region ../types/dist/canonical-hash-Ch5bSjFG.mjs
7436
7436
  var AUDIO_ENCODER_BY_CODEC = {
7437
7437
  opus: "libopus",
7438
7438
  aac: "aac",
@@ -7535,6 +7535,7 @@ function buildVideoArgs(video, outputArgs) {
7535
7535
  ];
7536
7536
  if (video.preset !== void 0) args.push("-preset", video.preset);
7537
7537
  if (video.tune !== void 0) args.push("-tune", video.tune);
7538
+ if (video.singleSlicePerFrame === true && video.encoder === "libx264") args.push("-x264-params", "sliced-threads=0");
7538
7539
  if (video.profile !== void 0) args.push("-profile:v", video.profile);
7539
7540
  if (video.level !== void 0) args.push("-level", video.level);
7540
7541
  if (video.pixelFormat !== void 0) args.push("-pix_fmt", video.pixelFormat);
@@ -7936,7 +7937,7 @@ import { errMsg } from '@camstack/types'
7936
7937
  * Extract a human-readable message from an unknown error value.
7937
7938
  * Replaces the ubiquitous `errMsg(err)` pattern.
7938
7939
  */
7939
- function errMsg$15(err) {
7940
+ function errMsg$16(err) {
7940
7941
  if (err instanceof Error) return err.message;
7941
7942
  if (typeof err === "string") return err;
7942
7943
  return String(err);
@@ -8013,7 +8014,23 @@ var EncodeProfileSchema = object({
8013
8014
  "zerolatency",
8014
8015
  "film",
8015
8016
  "animation"
8016
- ]).optional()
8017
+ ]).optional(),
8018
+ /**
8019
+ * ONE slice per access unit.
8020
+ *
8021
+ * `-tune zerolatency` turns on x264's sliced threads, and a frame then leaves
8022
+ * the encoder as five NAL slices that share one RTP timestamp and carry one
8023
+ * marker bit. A libwebrtc depacketiser sees five frame-starts and one
8024
+ * frame-end per frame: the first pictures render and the video then freezes
8025
+ * for good while the audio, on its own plane, plays on. Measured on this hub
8026
+ * 2026-09-13 against the Echo, and reduced to one slice by this flag alone.
8027
+ *
8028
+ * A NAMED field and not a raw flag, because {@link EgressEncodeSchema} omits
8029
+ * `outputArgs` on purpose: an opaque array is part of the sharing key, so two
8030
+ * consumers meaning the same thing spelled differently would stop sharing one
8031
+ * child. Absent means "whatever the encoder does" — today's behaviour.
8032
+ */
8033
+ singleSlicePerFrame: boolean().optional()
8017
8034
  }),
8018
8035
  audio: union([literal("passthrough"), object({
8019
8036
  codec: _enum([
@@ -8063,7 +8080,7 @@ var BASE_LIVE_EGRESS_PROFILE = {
8063
8080
  audio: "passthrough"
8064
8081
  };
8065
8082
  ({ ...BASE_LIVE_EGRESS_PROFILE }), { ...BASE_LIVE_EGRESS_PROFILE.video };
8066
- ({ ...BASE_LIVE_EGRESS_PROFILE });
8083
+ ({ ...BASE_LIVE_EGRESS_PROFILE }), { ...BASE_LIVE_EGRESS_PROFILE.video };
8067
8084
  /** VBV window for a consumer whose budget is enforced per second (HomeKit). */
8068
8085
  var RATE_CONTROL_TIGHT = {
8069
8086
  kind: "cbr",
@@ -16986,7 +17003,7 @@ var AlarmArmModeSchema = _enum([
16986
17003
  "vacation",
16987
17004
  "custom_bypass"
16988
17005
  ]);
16989
- object({
17006
+ var AlarmPanelStatusSchema = object({
16990
17007
  /** Current lifecycle state. */
16991
17008
  state: AlarmStateSchema,
16992
17009
  /** Subset of arm modes the panel accepts. UI renders one button per
@@ -20563,13 +20580,109 @@ var SummariesQueryInput = object({
20563
20580
  deviceIds: array(number()).min(1),
20564
20581
  since: number().optional(),
20565
20582
  until: number().optional(),
20566
- limit: number().int().min(1).max(200).default(50)
20583
+ limit: number().int().min(1).max(200).default(50),
20584
+ /** The same member-wise filter {@link listRecentSummaries} takes — one
20585
+ * meaning of "dog" on every summary surface. */
20586
+ classes: array(string().min(1).max(60)).max(40).optional()
20567
20587
  });
20568
- var SummariesPageSchema = object({ summaries: array(SummarySchema).readonly() });
20569
20588
  var SummaryDetailSchema = object({
20570
20589
  summary: SummarySchema,
20571
- /** Member track ids, in absorption order. */
20572
- trackIds: array(string()).readonly()
20590
+ /** Members in absorption order, oldest join first. */
20591
+ members: array(object({
20592
+ trackId: string(),
20593
+ /**
20594
+ * The track's class at the time it JOINED, or `null` when it was unresolved
20595
+ * and the track no longer exists to fill it.
20596
+ *
20597
+ * The join, not the latest opinion: class voting can re-decide a track's
20598
+ * class afterwards, and a group's composition is the history of who came
20599
+ * together. A consumer counts these to badge a thumbnail — "two people and a
20600
+ * dog" — rather than being handed a second, denormalised tally that would
20601
+ * drift from the members it claims to describe.
20602
+ */
20603
+ className: string().nullable(),
20604
+ /** `primary` is the one member that carries the group's identity. */
20605
+ role: _enum([
20606
+ "primary",
20607
+ "sibling",
20608
+ "child"
20609
+ ]).nullable(),
20610
+ joinedAt: number(),
20611
+ /** Tier 1 — the sub-class (`dog`, `van`), resolved from the member's track
20612
+ * at read time. Absent when nothing resolved, never an empty string. */
20613
+ label: string().optional(),
20614
+ /** Tier 2 — the instance: a person's name, a plate. Absent when the pipeline
20615
+ * recognised nobody, and absent for a member whose track has been pruned —
20616
+ * a thumbnail that names the wrong person is worse than one naming nobody. */
20617
+ subLabel: string().optional()
20618
+ })).readonly()
20619
+ });
20620
+ /**
20621
+ * What a LIST of groups carries: the envelope plus what it is MADE OF.
20622
+ *
20623
+ * Coarse on purpose — the operator's rule is "only the rough data on the list,
20624
+ * we extend when we notice we need more". Enough to draw the card ("two people
20625
+ * and a dog") and no more. The MEMBERS, their names and the per-member links
20626
+ * are on {@link getSummary}: shipping every member of every group so a client
20627
+ * can count them turns a page of two hundred groups into a thousand records to
20628
+ * draw two hundred badges.
20629
+ */
20630
+ var SummaryListItemSchema = object({
20631
+ summary: SummarySchema,
20632
+ /** Class counts, most numerous first; `className: null` is a member whose
20633
+ * class never resolved, counted so the counts add up to `memberCount`. */
20634
+ classes: array(object({
20635
+ className: string().nullable(),
20636
+ count: number().int().positive()
20637
+ })).readonly()
20638
+ });
20639
+ var SummariesPageSchema = object({ summaries: array(SummaryListItemSchema).readonly() });
20640
+ /**
20641
+ * The paged feed, deliberately the SAME shape as {@link RecentTracksQueryInput}.
20642
+ *
20643
+ * The reel on the cameras page and the Events gallery both ride a cursor, so a
20644
+ * summaries feed that could only answer "the last N for these cameras"
20645
+ * (`listSummaries`) would make groups available in the timeline and nowhere
20646
+ * else. Two feeds with different ordering contracts would be two ideas of what
20647
+ * "newest" means, on one screen.
20648
+ */
20649
+ var RecentSummariesQueryInput = object({
20650
+ /** Devices to merge. An empty array yields an empty page. */
20651
+ deviceIds: array(number()),
20652
+ /** Window lower bound on `lastActiveAt` (inclusive). */
20653
+ since: number().optional(),
20654
+ /** Window upper bound on `lastActiveAt` (inclusive). */
20655
+ until: number().optional(),
20656
+ limit: number().int().min(1).max(500).default(100),
20657
+ /** Opaque continuation cursor from a previous page's `nextCursor`. */
20658
+ cursor: string().optional(),
20659
+ /**
20660
+ * Restrict to these classes — THE SAME FIELD `listRecentTracks` takes, and
20661
+ * deliberately the same name: the events filter tree emits one list of ticked
20662
+ * taxonomy nodes, and a summaries feed that called it something else would
20663
+ * make the operator's one filter component produce two shapes.
20664
+ *
20665
+ * A question about the MEMBERS: a group matches when ANY of them does. "Show
20666
+ * me the arrivals with a dog" has to return the group of four people who had
20667
+ * one with them; a filter on the group's own fields could only ever answer
20668
+ * about its primary.
20669
+ *
20670
+ * Matched against all THREE tiers of a member — the class (`animal`), the
20671
+ * sub-class (`dog`) and the instance (a name, a plate) — because which tier a
20672
+ * ticked node lives on is the taxonomy's business, not the caller's. `dog` is
20673
+ * an event kind in the tree and a tier-1 label on an `animal` track; a filter
20674
+ * that read only the class would answer "animal" and never "dog".
20675
+ *
20676
+ * ABSENT or EMPTY means no filter — absent is not a selection of none.
20677
+ */
20678
+ classes: array(string().min(1).max(60)).max(40).optional()
20679
+ });
20680
+ var RecentSummariesPageSchema = object({
20681
+ /** Ordered by (`lastActiveAt` DESC, id DESC). Same light item as
20682
+ * {@link listSummaries} — one list shape, so a card renders the same
20683
+ * whichever feed drew it. */
20684
+ summaries: array(SummaryListItemSchema).readonly(),
20685
+ nextCursor: string().nullable()
20573
20686
  });
20574
20687
  var RecentTracksPageSchema = object({
20575
20688
  /** Merged page, ordered by (`lastSeen` DESC, `trackId` DESC). */
@@ -20983,7 +21096,7 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
20983
21096
  classes: array(string()).optional(),
20984
21097
  /** See {@link ExcludeSourcesDoc}. */
20985
21098
  excludeSources: array(TrackSourceSchema).optional()
20986
- }), array(TrackSchema).readonly()), method(RecentTracksQueryInput, RecentTracksPageSchema), method(SummariesQueryInput, SummariesPageSchema), method(object({ id: string() }), SummaryDetailSchema.nullable()), method(object({ deviceId: number() }), _void(), {
21099
+ }), array(TrackSchema).readonly()), method(RecentTracksQueryInput, RecentTracksPageSchema), method(SummariesQueryInput, SummariesPageSchema), method(RecentSummariesQueryInput, RecentSummariesPageSchema), method(object({ id: string() }), SummaryDetailSchema.nullable()), method(object({ deviceId: number() }), _void(), {
20987
21100
  kind: "mutation",
20988
21101
  auth: "admin"
20989
21102
  }), method(DeviceEventQueryInput, array(MotionEventSchema).readonly()), method(ObjectEventQueryInput, array(ObjectEventSchema).readonly()), method(DeviceEventQueryInput, array(AudioEventSchema).readonly()), method(object({ deviceId: number() }), array(EventKindDescriptorSchema).readonly()), method(object({ deviceIds: array(number()).min(1).max(200) }), array(EventKindsForDeviceSchema).readonly()), method(object({
@@ -30634,7 +30747,29 @@ var LoggingSettingsPatchSchema = object({
30634
30747
  * disarmed the channels it did not mention would make the Levels page and
30635
30748
  * the Diagnostics page fight over the same value.
30636
30749
  */
30637
- channels: array(LogChannelWindowPatchSchema).readonly().optional()
30750
+ channels: array(LogChannelWindowPatchSchema).readonly().optional(),
30751
+ /**
30752
+ * How many days the analytics OPS LOG is kept — the audit trail of what
30753
+ * retention actually deleted.
30754
+ *
30755
+ * It lives HERE, on the logging document, and not on the analytics addon's
30756
+ * settings form, on the operator's instruction: every other log-ish window in
30757
+ * this system is configured through this one document, and a retention audit
30758
+ * configured somewhere else is a second place to look when the question is
30759
+ * "what happened to my data".
30760
+ *
30761
+ * That placement has a cost worth stating: this document ships in the
30762
+ * framework closure, so this knob needs a published `@camstack/server` while
30763
+ * the four windows beside it (D485) reach a node on `camstack deploy`.
30764
+ *
30765
+ * `retention-model.ts` argued this one must NOT follow a device window,
30766
+ * because the audit trail is the history of the SWEEP and not of the camera.
30767
+ * That argument stands and is untouched — what changes is that 30 days stops
30768
+ * being a constant nobody can reach. `0` keeps it forever. The floor is 1 day
30769
+ * rather than 0-as-delete: an audit log truncated to nothing is precisely the
30770
+ * state in which the next 9.5 GiB leak cannot be explained.
30771
+ */
30772
+ opsLogRetentionDays: number().int().min(0).max(3650).optional()
30638
30773
  });
30639
30774
  /**
30640
30775
  * Which LAYER of the hierarchy is addressed. Absent = the cluster layer.
@@ -30707,6 +30842,14 @@ var LoggingSettingsStateSchema = object({
30707
30842
  channels: array(LogChannelDescriptorSchema).readonly(),
30708
30843
  /** The channels ARMED right now, each with its deadline. */
30709
30844
  activeChannels: array(LogChannelWindowStateSchema).readonly(),
30845
+ /**
30846
+ * The ops-log window in days, as it is in force. `0` = kept forever.
30847
+ *
30848
+ * Reported rather than left to the caller's memory of what it wrote: this is
30849
+ * the value the analytics sweep will actually use, and an operator asking how
30850
+ * long their audit trail lives should not have to infer it from a default.
30851
+ */
30852
+ opsLogRetentionDays: number().int().min(0),
30710
30853
  persisted: boolean()
30711
30854
  });
30712
30855
  method(_void(), FeatureManifestSchema), method(_void(), HealthStatusSchema), method(_void(), FeatureManifestSchema), method(_void(), array(NetworkAddressSchema).readonly()), method(_void(), unknown().nullable(), { auth: "admin" }), method(record(string(), unknown()), _null(), {
@@ -34882,6 +35025,12 @@ Object.freeze({
34882
35025
  addonId: null,
34883
35026
  access: "view"
34884
35027
  },
35028
+ "pipelineAnalytics.listRecentSummaries": {
35029
+ capName: "pipeline-analytics",
35030
+ capScope: "device",
35031
+ addonId: null,
35032
+ access: "view"
35033
+ },
34885
35034
  "pipelineAnalytics.listRecentTracks": {
34886
35035
  capName: "pipeline-analytics",
34887
35036
  capScope: "device",
@@ -38709,6 +38858,11 @@ Object.freeze({
38709
38858
  form: "single",
38710
38859
  optional: true
38711
38860
  }],
38861
+ "pipelineAnalytics.listRecentSummaries": [{
38862
+ name: "deviceIds",
38863
+ form: "array",
38864
+ optional: false
38865
+ }],
38712
38866
  "pipelineAnalytics.listRecentTracks": [{
38713
38867
  name: "deviceIds",
38714
38868
  form: "array",
@@ -40083,7 +40237,7 @@ var Fmp4FragmentChild = class {
40083
40237
  meta: {
40084
40238
  sourceId: this.args.sourceId,
40085
40239
  decodeHwAccel: requested,
40086
- error: errMsg$15(err)
40240
+ error: errMsg$16(err)
40087
40241
  }
40088
40242
  });
40089
40243
  this.killChild();
@@ -40262,7 +40416,7 @@ var Fmp4FragmentChild = class {
40262
40416
  tags: { deviceId: this.args.deviceId },
40263
40417
  meta: {
40264
40418
  sourceId: this.args.sourceId,
40265
- error: errMsg$15(err)
40419
+ error: errMsg$16(err)
40266
40420
  }
40267
40421
  });
40268
40422
  }
@@ -86918,7 +87072,7 @@ function clearPairingFiles(accessoryUuid, logger) {
86918
87072
  }
86919
87073
  //#endregion
86920
87074
  //#region src/hap-setup-uri.ts
86921
- function errMsg$14(e) {
87075
+ function errMsg$15(e) {
86922
87076
  return e instanceof Error ? e.message : String(e);
86923
87077
  }
86924
87078
  /**
@@ -86945,7 +87099,7 @@ function firstExposedAccessorySetupUri(exposed, logger) {
86945
87099
  try {
86946
87100
  return first.setupURI();
86947
87101
  } catch (err) {
86948
- logger.debug("export-hap: setupURI failed on first exposed accessory", { meta: { error: errMsg$14(err) } });
87102
+ logger.debug("export-hap: setupURI failed on first exposed accessory", { meta: { error: errMsg$15(err) } });
86949
87103
  return;
86950
87104
  }
86951
87105
  }
@@ -87298,7 +87452,7 @@ async function buildBattery(bctx) {
87298
87452
  const status = await proxy.battery?.getStatus({});
87299
87453
  if (status !== void 0 && status !== null) applyToService(service, status);
87300
87454
  } catch (err) {
87301
- log.debug("export-hap: battery getStatus hydrate failed (non-fatal)", { meta: { error: errMsg$13(err) } });
87455
+ log.debug("export-hap: battery getStatus hydrate failed (non-fatal)", { meta: { error: errMsg$14(err) } });
87302
87456
  }
87303
87457
  const unsubscribes = [];
87304
87458
  if (proxy.state.battery) {
@@ -87317,7 +87471,7 @@ async function buildBattery(bctx) {
87317
87471
  function applyToService(service, status) {
87318
87472
  applyUpdates(service, batteryCharacteristicUpdates(status));
87319
87473
  }
87320
- function errMsg$13(err) {
87474
+ function errMsg$14(err) {
87321
87475
  return err instanceof Error ? err.message : String(err);
87322
87476
  }
87323
87477
  //#endregion
@@ -98069,7 +98223,7 @@ var VIDEO_LOOPBACK_RCVBUF_BYTES = 8 * 1024 * 1024;
98069
98223
  * not burst size.
98070
98224
  */
98071
98225
  var AUDIO_LOOPBACK_RCVBUF_BYTES = 1024 * 1024;
98072
- function errMsg$12(err) {
98226
+ function errMsg$13(err) {
98073
98227
  return err instanceof Error ? err.message : String(err);
98074
98228
  }
98075
98229
  /**
@@ -98084,13 +98238,13 @@ function applyReceiveBuffer(socket, requestedBytes) {
98084
98238
  try {
98085
98239
  socket.setRecvBufferSize(requestedBytes);
98086
98240
  } catch (err) {
98087
- error = errMsg$12(err);
98241
+ error = errMsg$13(err);
98088
98242
  }
98089
98243
  let effectiveBytes = null;
98090
98244
  try {
98091
98245
  effectiveBytes = socket.getRecvBufferSize();
98092
98246
  } catch (err) {
98093
- if (error === null) error = errMsg$12(err);
98247
+ if (error === null) error = errMsg$13(err);
98094
98248
  }
98095
98249
  return {
98096
98250
  requestedBytes,
@@ -98350,20 +98504,20 @@ function buildCameraStreamingDelegate(bctx, advertised) {
98350
98504
  delegate: {
98351
98505
  handleSnapshotRequest(request, callback) {
98352
98506
  handleSnapshot(bctx, request).then((buf) => callback(void 0, buf)).catch((err) => {
98353
- log.warn("export-hap: snapshot failed", { meta: { error: errMsg$11(err) } });
98354
- callback(err instanceof Error ? err : new Error(errMsg$11(err)));
98507
+ log.warn("export-hap: snapshot failed", { meta: { error: errMsg$12(err) } });
98508
+ callback(err instanceof Error ? err : new Error(errMsg$12(err)));
98355
98509
  });
98356
98510
  },
98357
98511
  prepareStream(request, callback) {
98358
98512
  prepareStream(request, sessions, bctx).then((resp) => callback(void 0, resp)).catch((err) => {
98359
- log.warn("export-hap: prepareStream failed", { meta: { error: errMsg$11(err) } });
98360
- callback(err instanceof Error ? err : new Error(errMsg$11(err)));
98513
+ log.warn("export-hap: prepareStream failed", { meta: { error: errMsg$12(err) } });
98514
+ callback(err instanceof Error ? err : new Error(errMsg$12(err)));
98361
98515
  });
98362
98516
  },
98363
98517
  handleStreamRequest(request, callback) {
98364
98518
  handleStreamRequest(request, sessions, bctx, advertised).then(() => callback()).catch((err) => {
98365
- log.warn("export-hap: handleStreamRequest failed", { meta: { error: errMsg$11(err) } });
98366
- callback(err instanceof Error ? err : new Error(errMsg$11(err)));
98519
+ log.warn("export-hap: handleStreamRequest failed", { meta: { error: errMsg$12(err) } });
98520
+ callback(err instanceof Error ? err : new Error(errMsg$12(err)));
98367
98521
  });
98368
98522
  }
98369
98523
  },
@@ -98479,7 +98633,7 @@ async function prepareStream(request, sessions, bctx) {
98479
98633
  closeSocket(audioUdp);
98480
98634
  closeSocket(videoLoopUdp);
98481
98635
  closeSocket(audioLoopUdp);
98482
- throw new Error(`export-hap: outbound SrtpSession init failed: ${errMsg$11(err)}`, { cause: err });
98636
+ throw new Error(`export-hap: outbound SrtpSession init failed: ${errMsg$12(err)}`, { cause: err });
98483
98637
  }
98484
98638
  let upstreamAudioSrtp = null;
98485
98639
  try {
@@ -98493,7 +98647,7 @@ async function prepareStream(request, sessions, bctx) {
98493
98647
  profile: import_src.ProtectionProfileAes128CmHmacSha1_80
98494
98648
  });
98495
98649
  } catch (err) {
98496
- bctx.ctx.logger.withTags({ deviceId: bctx.numericDeviceId }).warn("export-hap: SrtpSession init failed (upstream audio decrypt disabled)", { meta: { error: errMsg$11(err) } });
98650
+ bctx.ctx.logger.withTags({ deviceId: bctx.numericDeviceId }).warn("export-hap: SrtpSession init failed (upstream audio decrypt disabled)", { meta: { error: errMsg$12(err) } });
98497
98651
  }
98498
98652
  const videoSsrc = randomSsrc();
98499
98653
  const audioSsrc = randomSsrc();
@@ -98610,7 +98764,7 @@ async function prepareStream(request, sessions, bctx) {
98610
98764
  });
98611
98765
  audioUdp.on("message", (packet, rinfo) => {
98612
98766
  handleIncomingAudioRtp(session, packet, rinfo.address, bctx).catch((err) => {
98613
- bctx.ctx.logger.withTags({ deviceId: bctx.numericDeviceId }).debug("export-hap: incoming-audio handler error (dropped)", { meta: { error: errMsg$11(err) } });
98767
+ bctx.ctx.logger.withTags({ deviceId: bctx.numericDeviceId }).debug("export-hap: incoming-audio handler error (dropped)", { meta: { error: errMsg$12(err) } });
98614
98768
  });
98615
98769
  });
98616
98770
  logLoopbackBuffer(tagLog, request.sessionID, "video", videoLoop.buffer);
@@ -98806,7 +98960,7 @@ function readControllerRtcp(session, leg, packet, log) {
98806
98960
  } catch (err) {
98807
98961
  drop(session, "inbound-rtcp-decrypt-failed");
98808
98962
  storeReceiverReports(session, leg, recordUnreadableRtcp(tally));
98809
- logUnreadableRtcp(session, leg, `decrypt: ${errMsg$11(err)}`, log);
98963
+ logUnreadableRtcp(session, leg, `decrypt: ${errMsg$12(err)}`, log);
98810
98964
  return;
98811
98965
  }
98812
98966
  const outcome = ingestDecryptedRtcp(plaintext, tally);
@@ -99572,7 +99726,7 @@ async function handleIncomingAudioRtp(session, packet, sourceAddress, bctx) {
99572
99726
  session.upstreamRtpDecryptFailures += 1;
99573
99727
  if (session.upstreamRtpDecryptFailures % 100 === 1) log.debug("export-hap: SRTP decrypt failed (rate-limited)", { meta: {
99574
99728
  failures: session.upstreamRtpDecryptFailures,
99575
- error: errMsg$11(err)
99729
+ error: errMsg$12(err)
99576
99730
  } });
99577
99731
  return;
99578
99732
  }
@@ -99586,7 +99740,7 @@ async function handleIncomingAudioRtp(session, packet, sourceAddress, bctx) {
99586
99740
  rtpPayloadType = parsedRtp.header.payloadType;
99587
99741
  } catch (err) {
99588
99742
  drop(session, "upstream-parse-failed");
99589
- log.debug("export-hap: RTP parse failed after decrypt", { meta: { error: errMsg$11(err) } });
99743
+ log.debug("export-hap: RTP parse failed after decrypt", { meta: { error: errMsg$12(err) } });
99590
99744
  return;
99591
99745
  }
99592
99746
  const negotiatedAudioPt = session.lastStartParams?.audioPt;
@@ -99610,7 +99764,7 @@ async function handleIncomingAudioRtp(session, packet, sourceAddress, bctx) {
99610
99764
  if (session.intercomTalkSessionId === null) {
99611
99765
  session.intercomTalkSessionId = "";
99612
99766
  const opened = await openIntercomTalkSession(bctx).catch((err) => {
99613
- log.warn("export-hap: intercom.startTalkSession failed", { meta: { error: errMsg$11(err) } });
99767
+ log.warn("export-hap: intercom.startTalkSession failed", { meta: { error: errMsg$12(err) } });
99614
99768
  return null;
99615
99769
  });
99616
99770
  if (opened) {
@@ -99637,7 +99791,7 @@ async function handleIncomingAudioRtp(session, packet, sourceAddress, bctx) {
99637
99791
  drop(session, "upstream-push-failed");
99638
99792
  log.debug("export-hap: intercom.pushTalkAudio failed (will re-open on next frame)", { meta: {
99639
99793
  sequenceNumber: session.intercomPcmSequence,
99640
- error: errMsg$11(err)
99794
+ error: errMsg$12(err)
99641
99795
  } });
99642
99796
  session.intercomTalkSessionId = null;
99643
99797
  }
@@ -99669,7 +99823,7 @@ async function closeIntercomTalkSession(session, bctx) {
99669
99823
  } catch (err) {
99670
99824
  log.debug("export-hap: intercom.endTalkSession failed (continuing)", { meta: {
99671
99825
  sessionId,
99672
- error: errMsg$11(err)
99826
+ error: errMsg$12(err)
99673
99827
  } });
99674
99828
  }
99675
99829
  }
@@ -99694,7 +99848,7 @@ function closeSocket(udp) {
99694
99848
  function randomSsrc() {
99695
99849
  return Math.floor(Math.random() * 2147483646) + 1 | 0;
99696
99850
  }
99697
- function errMsg$11(err) {
99851
+ function errMsg$12(err) {
99698
99852
  return err instanceof Error ? err.message : String(err);
99699
99853
  }
99700
99854
  //#endregion
@@ -99778,14 +99932,14 @@ async function buildDoorbell(input) {
99778
99932
  }
99779
99933
  log.info("export-hap: doorbell SINGLE_PRESS pushed to HomeKit", { meta: { ...delivery } });
99780
99934
  } catch (err) {
99781
- log.warn("export-hap: ringDoorbell() failed", { meta: { error: errMsg$10(err) } });
99935
+ log.warn("export-hap: ringDoorbell() failed", { meta: { error: errMsg$11(err) } });
99782
99936
  }
99783
99937
  });
99784
99938
  return { async dispose() {
99785
99939
  unsubscribe();
99786
99940
  } };
99787
99941
  }
99788
- function errMsg$10(err) {
99942
+ function errMsg$11(err) {
99789
99943
  return err instanceof Error ? err.message : String(err);
99790
99944
  }
99791
99945
  //#endregion
@@ -99833,7 +99987,7 @@ async function buildMotionSensor(bctx, existing = null) {
99833
99987
  const detected = await proxy.motion?.isDetected({});
99834
99988
  if (typeof detected === "boolean") motionService.updateCharacteristic(import_dist.Characteristic.MotionDetected, detected);
99835
99989
  } catch (err) {
99836
- ctx.logger.withTags({ deviceId: numericDeviceId }).debug("export-hap: initial motion hydrate failed (non-fatal)", { meta: { error: errMsg$9(err) } });
99990
+ ctx.logger.withTags({ deviceId: numericDeviceId }).debug("export-hap: initial motion hydrate failed (non-fatal)", { meta: { error: errMsg$10(err) } });
99837
99991
  }
99838
99992
  let resetTimer = null;
99839
99993
  const armReset = () => {
@@ -99867,7 +100021,7 @@ async function buildMotionSensor(bctx, existing = null) {
99867
100021
  }
99868
100022
  } };
99869
100023
  }
99870
- function errMsg$9(err) {
100024
+ function errMsg$10(err) {
99871
100025
  return err instanceof Error ? err.message : String(err);
99872
100026
  }
99873
100027
  //#endregion
@@ -99898,7 +100052,7 @@ async function buildPrivacySwitch(bctx) {
99898
100052
  const status = await proxy.privacyMask?.getStatus({});
99899
100053
  if (status && typeof status.enabled === "boolean") service.updateCharacteristic(import_dist.Characteristic.On, status.enabled);
99900
100054
  } catch (err) {
99901
- log.debug("export-hap: privacy-mask getStatus hydrate failed (non-fatal)", { meta: { error: errMsg$8(err) } });
100055
+ log.debug("export-hap: privacy-mask getStatus hydrate failed (non-fatal)", { meta: { error: errMsg$9(err) } });
99902
100056
  }
99903
100057
  service.getCharacteristic(import_dist.Characteristic.On).onSet(async (value) => {
99904
100058
  const enabled = value === true;
@@ -99907,7 +100061,7 @@ async function buildPrivacySwitch(bctx) {
99907
100061
  } catch (err) {
99908
100062
  log.warn("export-hap: privacy-mask setMask failed", { meta: {
99909
100063
  enabled,
99910
- error: errMsg$8(err)
100064
+ error: errMsg$9(err)
99911
100065
  } });
99912
100066
  }
99913
100067
  });
@@ -99925,7 +100079,7 @@ async function buildPrivacySwitch(bctx) {
99925
100079
  } catch {}
99926
100080
  } };
99927
100081
  }
99928
- function errMsg$8(err) {
100082
+ function errMsg$9(err) {
99929
100083
  return err instanceof Error ? err.message : String(err);
99930
100084
  }
99931
100085
  //#endregion
@@ -100016,7 +100170,7 @@ async function buildPtz(bctx) {
100016
100170
  } catch (err) {
100017
100171
  log.warn("export-hap: ptz.goToPreset failed", { meta: {
100018
100172
  presetId: preset.id,
100019
- error: errMsg$7(err)
100173
+ error: errMsg$8(err)
100020
100174
  } });
100021
100175
  }
100022
100176
  armReset(() => service.updateCharacteristic(import_dist.Characteristic.On, false), MOMENTARY_RESET_MS);
@@ -100034,14 +100188,14 @@ async function buildPtz(bctx) {
100034
100188
  try {
100035
100189
  await proxy.ptz?.stop({});
100036
100190
  } catch (err) {
100037
- log.debug("export-hap: ptz.stop failed (non-fatal)", { meta: { error: errMsg$7(err) } });
100191
+ log.debug("export-hap: ptz.stop failed (non-fatal)", { meta: { error: errMsg$8(err) } });
100038
100192
  }
100039
100193
  service.updateCharacteristic(import_dist.Characteristic.On, false);
100040
100194
  }, options.ptzPulseMs);
100041
100195
  } catch (err) {
100042
100196
  log.warn("export-hap: ptz.continuousMove failed", { meta: {
100043
100197
  dir: dir.label,
100044
- error: errMsg$7(err)
100198
+ error: errMsg$8(err)
100045
100199
  } });
100046
100200
  service.updateCharacteristic(import_dist.Characteristic.On, false);
100047
100201
  }
@@ -100064,7 +100218,7 @@ async function readPresets(bctx) {
100064
100218
  name: p.name
100065
100219
  }));
100066
100220
  } catch (err) {
100067
- ctx.logger.withTags({ deviceId: numericDeviceId }).debug("export-hap: ptz.getPresets failed (non-fatal)", { meta: { error: errMsg$7(err) } });
100221
+ ctx.logger.withTags({ deviceId: numericDeviceId }).debug("export-hap: ptz.getPresets failed (non-fatal)", { meta: { error: errMsg$8(err) } });
100068
100222
  return [];
100069
100223
  }
100070
100224
  }
@@ -100079,7 +100233,7 @@ async function tryBuildAutotrack(bctx) {
100079
100233
  const status = await proxy.ptzAutotrack.getStatus({});
100080
100234
  if (status && typeof status.enabled === "boolean") service.updateCharacteristic(import_dist.Characteristic.On, status.enabled);
100081
100235
  } catch (err) {
100082
- log.debug("export-hap: ptzAutotrack.getStatus failed (non-fatal)", { meta: { error: errMsg$7(err) } });
100236
+ log.debug("export-hap: ptzAutotrack.getStatus failed (non-fatal)", { meta: { error: errMsg$8(err) } });
100083
100237
  }
100084
100238
  service.getCharacteristic(import_dist.Characteristic.On).onSet(async (value) => {
100085
100239
  const enabled = value === true;
@@ -100088,13 +100242,13 @@ async function tryBuildAutotrack(bctx) {
100088
100242
  } catch (err) {
100089
100243
  log.warn("export-hap: ptzAutotrack.setEnabled failed", { meta: {
100090
100244
  enabled,
100091
- error: errMsg$7(err)
100245
+ error: errMsg$8(err)
100092
100246
  } });
100093
100247
  }
100094
100248
  });
100095
100249
  return { async dispose() {} };
100096
100250
  }
100097
- function errMsg$7(err) {
100251
+ function errMsg$8(err) {
100098
100252
  return err instanceof Error ? err.message : String(err);
100099
100253
  }
100100
100254
  //#endregion
@@ -101125,13 +101279,13 @@ async function buildChildSwitch(bctx, subtype, deviceType) {
101125
101279
  const switchStatus = await proxy.switch?.getStatus({});
101126
101280
  if (switchStatus && typeof switchStatus.on === "boolean") service.updateCharacteristic(import_dist.Characteristic.On, switchStatus.on);
101127
101281
  } catch (err) {
101128
- log.debug("export-hap: child switch.getStatus failed (non-fatal)", { meta: { error: errMsg$6(err) } });
101282
+ log.debug("export-hap: child switch.getStatus failed (non-fatal)", { meta: { error: errMsg$7(err) } });
101129
101283
  }
101130
101284
  if (useLightbulb) try {
101131
101285
  const status = await proxy.brightness?.getStatus({});
101132
101286
  if (status && typeof status.percentage === "number") service.updateCharacteristic(import_dist.Characteristic.Brightness, status.percentage);
101133
101287
  } catch (err) {
101134
- log.debug("export-hap: child brightness.getStatus failed (non-fatal)", { meta: { error: errMsg$6(err) } });
101288
+ log.debug("export-hap: child brightness.getStatus failed (non-fatal)", { meta: { error: errMsg$7(err) } });
101135
101289
  }
101136
101290
  if (hasSwitch) service.getCharacteristic(import_dist.Characteristic.On).onSet(async (value) => {
101137
101291
  const on = value === true;
@@ -101140,7 +101294,7 @@ async function buildChildSwitch(bctx, subtype, deviceType) {
101140
101294
  } catch (err) {
101141
101295
  log.warn("export-hap: child switch.setState failed", { meta: {
101142
101296
  on,
101143
- error: errMsg$6(err)
101297
+ error: errMsg$7(err)
101144
101298
  } });
101145
101299
  }
101146
101300
  });
@@ -101152,7 +101306,7 @@ async function buildChildSwitch(bctx, subtype, deviceType) {
101152
101306
  } catch (err) {
101153
101307
  log.warn("export-hap: child brightness.setBrightness failed", { meta: {
101154
101308
  percentage,
101155
- error: errMsg$6(err)
101309
+ error: errMsg$7(err)
101156
101310
  } });
101157
101311
  }
101158
101312
  });
@@ -101175,7 +101329,7 @@ async function buildChildSwitch(bctx, subtype, deviceType) {
101175
101329
  } catch {}
101176
101330
  } };
101177
101331
  }
101178
- function errMsg$6(err) {
101332
+ function errMsg$7(err) {
101179
101333
  return err instanceof Error ? err.message : String(err);
101180
101334
  }
101181
101335
  //#endregion
@@ -101202,7 +101356,7 @@ async function buildChildServicesFor(input) {
101202
101356
  for (const h of handles) try {
101203
101357
  await h.dispose();
101204
101358
  } catch (err) {
101205
- ctx.logger.withTags({ deviceId: parentNumericId }).debug("export-hap: child service dispose failed (continuing)", { meta: { error: errMsg$5(err) } });
101359
+ ctx.logger.withTags({ deviceId: parentNumericId }).debug("export-hap: child service dispose failed (continuing)", { meta: { error: errMsg$6(err) } });
101206
101360
  }
101207
101361
  } };
101208
101362
  }
@@ -101218,7 +101372,7 @@ async function listChildren(ctx, parentNumericId) {
101218
101372
  features: Array.isArray(c.features) ? c.features.filter((f) => typeof f === "string") : []
101219
101373
  }));
101220
101374
  } catch (err) {
101221
- ctx.logger.withTags({ deviceId: parentNumericId }).debug("export-hap: deviceManager.getChildren failed (non-fatal)", { meta: { error: errMsg$5(err) } });
101375
+ ctx.logger.withTags({ deviceId: parentNumericId }).debug("export-hap: deviceManager.getChildren failed (non-fatal)", { meta: { error: errMsg$6(err) } });
101222
101376
  return [];
101223
101377
  }
101224
101378
  }
@@ -101234,7 +101388,7 @@ function asDeviceType(raw) {
101234
101388
  for (const value of Object.values(DeviceType)) if (value === lower) return value;
101235
101389
  return DeviceType.Generic;
101236
101390
  }
101237
- function errMsg$5(err) {
101391
+ function errMsg$6(err) {
101238
101392
  return err instanceof Error ? err.message : String(err);
101239
101393
  }
101240
101394
  //#endregion
@@ -101256,12 +101410,18 @@ var SUPPORTED_MAPPER_KINDS = ["camera", "generic"];
101256
101410
  * doctrine the HA exporter writes down, and the thing that confined the
101257
101411
  * previous exporter to cameras when it was ignored.
101258
101412
  *
101259
- * Tier A: the types whose HomeKit services exist today and need no
101260
- * feature-dependent shape. `cover`, `climate`, `fan`, `valve`, `humidifier`,
101261
- * `water-heater`, `alarm-panel`, `button` and `media-player` are deliberately
101413
+ * Tier A plus `alarm-panel`: the types whose HomeKit services exist today and
101414
+ * need no feature-dependent shape. `cover`, `climate`, `fan`, `valve`,
101415
+ * `humidifier`, `water-heater`, `button` and `media-player` are deliberately
101262
101416
  * absent — each needs a service whose semantics the table cannot yet honour,
101263
101417
  * and offering the tab before the mapping exists is how an operator gets an
101264
101418
  * accessory that pairs and does nothing.
101419
+ *
101420
+ * `alarm-panel` is no longer one of them. It maps to `Service.SecuritySystem`
101421
+ * (`builders/generic/security-system.ts`), and the two things the table could
101422
+ * not previously honour are now honoured explicitly: HomeKit is only ever
101423
+ * offered the arm modes the panel accepts, and a panel that requires a PIN
101424
+ * refuses the write out loud instead of pretending to arm.
101265
101425
  */
101266
101426
  var HAP_EXPORTABLE_DEVICE_TYPES = [
101267
101427
  DeviceType.Camera,
@@ -101271,6 +101431,7 @@ var HAP_EXPORTABLE_DEVICE_TYPES = [
101271
101431
  DeviceType.Sensor,
101272
101432
  DeviceType.Lock,
101273
101433
  DeviceType.Presence,
101434
+ DeviceType.AlarmPanel,
101274
101435
  DeviceType.Generic
101275
101436
  ];
101276
101437
  /**
@@ -101396,17 +101557,17 @@ async function buildCameraAccessory(input) {
101396
101557
  for (const h of handles) try {
101397
101558
  await h.dispose();
101398
101559
  } catch (err) {
101399
- log.debug("export-hap: builder dispose failed (continuing)", { meta: { error: errMsg$4(err) } });
101560
+ log.debug("export-hap: builder dispose failed (continuing)", { meta: { error: errMsg$5(err) } });
101400
101561
  }
101401
101562
  try {
101402
101563
  await streams.dispose();
101403
101564
  } catch (err) {
101404
- log.debug("export-hap: streams dispose failed", { meta: { error: errMsg$4(err) } });
101565
+ log.debug("export-hap: streams dispose failed", { meta: { error: errMsg$5(err) } });
101405
101566
  }
101406
101567
  }
101407
101568
  };
101408
101569
  }
101409
- function errMsg$4(err) {
101570
+ function errMsg$5(err) {
101410
101571
  return err instanceof Error ? err.message : String(err);
101411
101572
  }
101412
101573
  //#endregion
@@ -101435,7 +101596,7 @@ function errMsg$4(err) {
101435
101596
  * counterpart on this service and is deliberately not wired — a Switch that
101436
101597
  * silently buzzes a door open would be a second knob nobody asked for.
101437
101598
  */
101438
- var SUBTYPE = "lock-control";
101599
+ var SUBTYPE$1 = "lock-control";
101439
101600
  var readLock = reader(LockControlStatusSchema.pick({ state: true }), (status) => {
101440
101601
  const current = status.state === "locked" ? import_dist.Characteristic.LockCurrentState.SECURED : status.state === "unlocked" ? import_dist.Characteristic.LockCurrentState.UNSECURED : status.state === "jammed" ? import_dist.Characteristic.LockCurrentState.JAMMED : import_dist.Characteristic.LockCurrentState.UNKNOWN;
101441
101602
  const target = status.state === "locked" || status.state === "locking" ? import_dist.Characteristic.LockTargetState.SECURED : status.state === "unlocked" || status.state === "unlocking" ? import_dist.Characteristic.LockTargetState.UNSECURED : null;
@@ -101451,7 +101612,7 @@ async function buildLockMechanism(bctx) {
101451
101612
  const { ctx, accessory, proxy, numericDeviceId, displayName } = bctx;
101452
101613
  const log = ctx.logger.withTags({ deviceId: numericDeviceId });
101453
101614
  const label = hapServiceName([displayName], `Lock ${numericDeviceId}`);
101454
- const service = accessory.addService(import_dist.Service.LockMechanism, label, SUBTYPE);
101615
+ const service = accessory.addService(import_dist.Service.LockMechanism, label, SUBTYPE$1);
101455
101616
  applyServiceLabel(service, label);
101456
101617
  const apply = (status, source) => {
101457
101618
  const updates = readLock(status);
@@ -101465,7 +101626,7 @@ async function buildLockMechanism(bctx) {
101465
101626
  const status = await proxy.lockControl?.getStatus({});
101466
101627
  if (status !== void 0 && status !== null) apply(status, "getStatus");
101467
101628
  } catch (err) {
101468
- log.debug("export-hap: lock getStatus hydrate failed (non-fatal)", { meta: { error: errMsg$3(err) } });
101629
+ log.debug("export-hap: lock getStatus hydrate failed (non-fatal)", { meta: { error: errMsg$4(err) } });
101469
101630
  }
101470
101631
  service.getCharacteristic(import_dist.Characteristic.LockTargetState).onSet(async (value) => {
101471
101632
  const secure = value === import_dist.Characteristic.LockTargetState.SECURED;
@@ -101475,7 +101636,7 @@ async function buildLockMechanism(bctx) {
101475
101636
  } catch (err) {
101476
101637
  log.warn("export-hap: lock command failed", { meta: {
101477
101638
  secure,
101478
- error: errMsg$3(err)
101639
+ error: errMsg$4(err)
101479
101640
  } });
101480
101641
  }
101481
101642
  });
@@ -101489,6 +101650,296 @@ async function buildLockMechanism(bctx) {
101489
101650
  } catch {}
101490
101651
  } };
101491
101652
  }
101653
+ function errMsg$4(err) {
101654
+ return err instanceof Error ? err.message : String(err);
101655
+ }
101656
+ //#endregion
101657
+ //#region src/mappers/builders/generic/security-state.ts
101658
+ /** Is this a settled arm state worth remembering? */
101659
+ function armedMemoOf(state) {
101660
+ return state === "armed_home" || state === "armed_away" || state === "armed_night" || state === "armed_vacation" || state === "armed_custom_bypass" ? state : null;
101661
+ }
101662
+ function currentForArmed(state) {
101663
+ switch (state) {
101664
+ case "armed_home":
101665
+ case "armed_custom_bypass": return import_dist.Characteristic.SecuritySystemCurrentState.STAY_ARM;
101666
+ case "armed_night": return import_dist.Characteristic.SecuritySystemCurrentState.NIGHT_ARM;
101667
+ default: return import_dist.Characteristic.SecuritySystemCurrentState.AWAY_ARM;
101668
+ }
101669
+ }
101670
+ function targetForArmed(state) {
101671
+ switch (state) {
101672
+ case "armed_home":
101673
+ case "armed_custom_bypass": return import_dist.Characteristic.SecuritySystemTargetState.STAY_ARM;
101674
+ case "armed_night": return import_dist.Characteristic.SecuritySystemTargetState.NIGHT_ARM;
101675
+ default: return import_dist.Characteristic.SecuritySystemTargetState.AWAY_ARM;
101676
+ }
101677
+ }
101678
+ function securityStateFor(state, memo) {
101679
+ const settled = armedMemoOf(state);
101680
+ if (settled !== null) return {
101681
+ current: currentForArmed(settled),
101682
+ target: targetForArmed(settled)
101683
+ };
101684
+ switch (state) {
101685
+ case "disarmed": return {
101686
+ current: import_dist.Characteristic.SecuritySystemCurrentState.DISARMED,
101687
+ target: import_dist.Characteristic.SecuritySystemTargetState.DISARM
101688
+ };
101689
+ case "arming": return {
101690
+ current: import_dist.Characteristic.SecuritySystemCurrentState.DISARMED,
101691
+ target: memo === null ? null : targetForArmed(memo)
101692
+ };
101693
+ case "disarming": return {
101694
+ current: memo === null ? import_dist.Characteristic.SecuritySystemCurrentState.DISARMED : currentForArmed(memo),
101695
+ target: import_dist.Characteristic.SecuritySystemTargetState.DISARM
101696
+ };
101697
+ case "pending": return {
101698
+ current: memo === null ? import_dist.Characteristic.SecuritySystemCurrentState.DISARMED : currentForArmed(memo),
101699
+ target: memo === null ? null : targetForArmed(memo)
101700
+ };
101701
+ default: return {
101702
+ current: import_dist.Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED,
101703
+ target: memo === null ? null : targetForArmed(memo)
101704
+ };
101705
+ }
101706
+ }
101707
+ /**
101708
+ * The arm mode behind a HomeKit target, or `null` for DISARM and for anything
101709
+ * outside the four values HomeKit defines.
101710
+ *
101711
+ * `null` is not an error the caller can ignore: DISARM is a different COMMAND,
101712
+ * and a value HomeKit never sends is a write this builder refuses to translate.
101713
+ */
101714
+ function alarmArmModeFor(target) {
101715
+ switch (target) {
101716
+ case import_dist.Characteristic.SecuritySystemTargetState.STAY_ARM: return "home";
101717
+ case import_dist.Characteristic.SecuritySystemTargetState.AWAY_ARM: return "away";
101718
+ case import_dist.Characteristic.SecuritySystemTargetState.NIGHT_ARM: return "night";
101719
+ default: return null;
101720
+ }
101721
+ }
101722
+ //#endregion
101723
+ //#region src/mappers/builders/generic/security-target.ts
101724
+ /**
101725
+ * The panel modes behind each HomeKit target, PRIMARY first.
101726
+ *
101727
+ * The primary is the mode `alarmArmModeFor` names; the secondary is the other
101728
+ * mode `security-state.ts` reports through the same HomeKit value, so the two
101729
+ * modules agree in both directions by construction.
101730
+ */
101731
+ var MODES_BY_TARGET = new Map([
101732
+ [import_dist.Characteristic.SecuritySystemTargetState.STAY_ARM, ["home", "custom_bypass"]],
101733
+ [import_dist.Characteristic.SecuritySystemTargetState.AWAY_ARM, ["away", "vacation"]],
101734
+ [import_dist.Characteristic.SecuritySystemTargetState.NIGHT_ARM, ["night"]]
101735
+ ]);
101736
+ /** Arm targets in the order HomeKit numbers them; DISARM is appended last. */
101737
+ var ARM_TARGETS = [
101738
+ import_dist.Characteristic.SecuritySystemTargetState.STAY_ARM,
101739
+ import_dist.Characteristic.SecuritySystemTargetState.AWAY_ARM,
101740
+ import_dist.Characteristic.SecuritySystemTargetState.NIGHT_ARM
101741
+ ];
101742
+ /**
101743
+ * The `validValues` for `SecuritySystemTargetState`, or `null` to leave
101744
+ * HomeKit's own four values in place.
101745
+ *
101746
+ * DISARM is always present: disarming is not one of the panel's arm modes and
101747
+ * a panel that cannot be disarmed is not a thing this cap can express.
101748
+ */
101749
+ function targetValidValuesFor(availableModes) {
101750
+ if (availableModes.length === 0) return null;
101751
+ return [...ARM_TARGETS.filter((target) => (MODES_BY_TARGET.get(target) ?? []).some((mode) => availableModes.includes(mode))), import_dist.Characteristic.SecuritySystemTargetState.DISARM];
101752
+ }
101753
+ /**
101754
+ * The arm mode to send for a HomeKit target, or `null` when there is none.
101755
+ *
101756
+ * `null` is not a shrug the caller may swallow: DISARM is a different command,
101757
+ * and an arm target the panel accepts no mode for is a write this module
101758
+ * refuses to translate rather than guess at.
101759
+ */
101760
+ function armModeForTarget(target, availableModes) {
101761
+ const primary = alarmArmModeFor(target);
101762
+ if (primary === null) return null;
101763
+ if (availableModes.length === 0) return primary;
101764
+ return (MODES_BY_TARGET.get(target) ?? [primary]).find((mode) => availableModes.includes(mode)) ?? null;
101765
+ }
101766
+ //#endregion
101767
+ //#region src/mappers/builders/generic/security-system.ts
101768
+ /**
101769
+ * `alarm-panel` → `Service.SecuritySystem`.
101770
+ *
101771
+ * The lock builder's shape (a current/target pair, a hydrate, an `onSet`, a
101772
+ * slice subscription, a dispose) applied to the one device on the fleet where
101773
+ * reporting a state that is not true has a consequence worse than a stalled
101774
+ * motor. The mapping itself is NOT here: `security-state.ts` owns what the
101775
+ * panel's state looks like to HomeKit and `security-target.ts` owns what
101776
+ * HomeKit may ask for, both pure and both tested on their own. This file is
101777
+ * the service around them.
101778
+ *
101779
+ * ## The memo
101780
+ *
101781
+ * `pending`, `disarming` and `triggered` do not carry the mode the panel was
101782
+ * armed to — only the last settled state knows it. This builder is the caller
101783
+ * `security-state.ts` describes: it remembers the last settled arm and forgets
101784
+ * it on `disarmed`, because a memo that outlives a disarm makes the next
101785
+ * `arming` claim a target nobody asked for.
101786
+ *
101787
+ * The memo is deliberately NOT seeded from the controller's own write. HomeKit
101788
+ * already holds the target the operator just set; not writing it back is
101789
+ * exactly right. The cost is a panel armed from its own keypad during an exit
101790
+ * delay, where the target stays at whatever HomeKit last knew — a stale target
101791
+ * for the length of the delay, against inventing an intent, and the invention
101792
+ * is worse.
101793
+ *
101794
+ * ## `requiresCode`: the arm is REFUSED, not attempted
101795
+ *
101796
+ * HomeKit's SecuritySystem has no PIN prompt — there is no characteristic for
101797
+ * it and no way to ask the operator mid-write. So a panel that requires a code
101798
+ * cannot be armed or disarmed from the Home app, and this builder says so
101799
+ * twice: the write fails with `INSUFFICIENT_AUTHORIZATION` (iOS renders the
101800
+ * tile's failure) and a WARN names the device, the command and the mode.
101801
+ *
101802
+ * Sending the command code-less and letting the panel reject it was the
101803
+ * alternative. It is worse: the refusal costs a round trip, it is
101804
+ * indistinguishable from a broken panel in the log, and repeated code-less
101805
+ * attempts are what locks a real alarm panel out.
101806
+ */
101807
+ var SUBTYPE = "alarm-panel";
101808
+ /** The subset of the status this builder reads. */
101809
+ var PanelReadSchema = AlarmPanelStatusSchema.pick({
101810
+ state: true,
101811
+ availableModes: true,
101812
+ requiresCode: true
101813
+ });
101814
+ /**
101815
+ * Turn a panel status into characteristic writes, folding the memo.
101816
+ *
101817
+ * A payload that does not match the cap's own schema yields NO updates and
101818
+ * leaves the memo alone — it is a status we could not read, not a panel that
101819
+ * changed. The caller logs the drop; a frozen characteristic is otherwise
101820
+ * indistinguishable from a quiet panel.
101821
+ */
101822
+ function securityUpdatesFor(status, memo) {
101823
+ const parsed = PanelReadSchema.safeParse(status);
101824
+ if (!parsed.success) return {
101825
+ updates: [],
101826
+ memo,
101827
+ panel: null
101828
+ };
101829
+ const nextMemo = parsed.data.state === "disarmed" ? null : armedMemoOf(parsed.data.state) ?? memo;
101830
+ const { current, target } = securityStateFor(parsed.data.state, nextMemo);
101831
+ return {
101832
+ updates: [{
101833
+ characteristic: import_dist.Characteristic.SecuritySystemCurrentState,
101834
+ value: current
101835
+ }, ...target === null ? [] : [{
101836
+ characteristic: import_dist.Characteristic.SecuritySystemTargetState,
101837
+ value: target
101838
+ }]],
101839
+ memo: nextMemo,
101840
+ panel: {
101841
+ availableModes: parsed.data.availableModes,
101842
+ requiresCode: parsed.data.requiresCode
101843
+ }
101844
+ };
101845
+ }
101846
+ async function buildSecuritySystem(bctx) {
101847
+ const { ctx, accessory, proxy, numericDeviceId, displayName } = bctx;
101848
+ const log = ctx.logger.withTags({ deviceId: numericDeviceId });
101849
+ const label = hapServiceName([displayName], `Alarm ${numericDeviceId}`);
101850
+ const service = accessory.addService(import_dist.Service.SecuritySystem, label, SUBTYPE);
101851
+ applyServiceLabel(service, label);
101852
+ let memo = null;
101853
+ let availableModes = [];
101854
+ let requiresCode = false;
101855
+ /** Only log the `validValues` narrowing when it actually changes. */
101856
+ let lastValidValues = "";
101857
+ const applyValidValues = () => {
101858
+ const validValues = targetValidValuesFor(availableModes);
101859
+ if (validValues === null) {
101860
+ if (lastValidValues !== "unconstrained") {
101861
+ lastValidValues = "unconstrained";
101862
+ log.info("export-hap: alarm panel named no arm modes — leaving HomeKit’s targets unconstrained", { meta: { subtype: SUBTYPE } });
101863
+ }
101864
+ return;
101865
+ }
101866
+ const key = validValues.join(",");
101867
+ if (key === lastValidValues) return;
101868
+ lastValidValues = key;
101869
+ service.getCharacteristic(import_dist.Characteristic.SecuritySystemTargetState).setProps({ validValues: [...validValues] });
101870
+ log.info("export-hap: alarm panel target constrained to the modes it accepts", { meta: {
101871
+ subtype: SUBTYPE,
101872
+ availableModes: [...availableModes],
101873
+ validValues
101874
+ } });
101875
+ };
101876
+ const apply = (status, source) => {
101877
+ const next = securityUpdatesFor(status, memo);
101878
+ if (next.updates.length === 0) {
101879
+ log.debug("export-hap: alarm panel status did not match the cap schema — no update", { meta: {
101880
+ subtype: SUBTYPE,
101881
+ source
101882
+ } });
101883
+ return;
101884
+ }
101885
+ memo = next.memo;
101886
+ if (next.panel !== null) {
101887
+ availableModes = next.panel.availableModes;
101888
+ requiresCode = next.panel.requiresCode;
101889
+ applyValidValues();
101890
+ }
101891
+ applyUpdates(service, next.updates);
101892
+ };
101893
+ try {
101894
+ const status = await proxy.alarmPanel?.getStatus({});
101895
+ if (status !== void 0 && status !== null) apply(status, "getStatus");
101896
+ } catch (err) {
101897
+ log.debug("export-hap: alarm panel getStatus hydrate failed (non-fatal)", { meta: { error: errMsg$3(err) } });
101898
+ }
101899
+ service.getCharacteristic(import_dist.Characteristic.SecuritySystemTargetState).onSet(async (value) => {
101900
+ const target = typeof value === "number" ? value : Number(value);
101901
+ const disarm = target === import_dist.Characteristic.SecuritySystemTargetState.DISARM;
101902
+ const mode = disarm ? null : armModeForTarget(target, availableModes);
101903
+ if (requiresCode) {
101904
+ log.warn("export-hap: alarm panel requires a PIN — HomeKit cannot supply one, command REFUSED", { meta: {
101905
+ subtype: SUBTYPE,
101906
+ command: disarm ? "disarm" : "arm",
101907
+ mode,
101908
+ target
101909
+ } });
101910
+ throw new import_dist.HapStatusError(import_dist.HAPStatus.INSUFFICIENT_AUTHORIZATION);
101911
+ }
101912
+ if (!disarm && mode === null) {
101913
+ log.warn("export-hap: alarm panel cannot honour this HomeKit arm target — REFUSED", { meta: {
101914
+ subtype: SUBTYPE,
101915
+ target,
101916
+ availableModes: [...availableModes]
101917
+ } });
101918
+ throw new import_dist.HapStatusError(import_dist.HAPStatus.INVALID_VALUE_IN_REQUEST);
101919
+ }
101920
+ try {
101921
+ if (mode === null) await proxy.alarmPanel?.disarm({});
101922
+ else await proxy.alarmPanel?.arm({ mode });
101923
+ } catch (err) {
101924
+ log.warn("export-hap: alarm panel command failed", { meta: {
101925
+ subtype: SUBTYPE,
101926
+ command: mode === null ? "disarm" : "arm",
101927
+ mode,
101928
+ error: errMsg$3(err)
101929
+ } });
101930
+ throw new import_dist.HapStatusError(import_dist.HAPStatus.SERVICE_COMMUNICATION_FAILURE);
101931
+ }
101932
+ });
101933
+ const unsubscribe = proxy.state.alarmPanel?.subscribe((value) => {
101934
+ if (value === void 0 || value === null) return;
101935
+ apply(value, "slice");
101936
+ }) ?? null;
101937
+ return { async dispose() {
101938
+ try {
101939
+ unsubscribe?.();
101940
+ } catch {}
101941
+ } };
101942
+ }
101492
101943
  function errMsg$3(err) {
101493
101944
  return err instanceof Error ? err.message : String(err);
101494
101945
  }
@@ -101563,11 +102014,16 @@ function errMsg$2(err) {
101563
102014
  *
101564
102015
  * ## Tier
101565
102016
  *
101566
- * Tier A only: the caps whose HomeKit service exists today and needs no
101567
- * feature-dependent shape (`cover` needs `cover-positionable`, `climate-control`
101568
- * needs the dual-setpoint split, `alarm-panel` must survive a refused `arm`).
101569
- * Those are a separate task; adding a row here must never mean adding a service
101570
- * whose semantics this file cannot fully honour.
102017
+ * Tier A, plus `alarm-panel`: the caps whose HomeKit service exists today and
102018
+ * needs no feature-dependent shape. `cover` still needs `cover-positionable`
102019
+ * and `climate-control` the dual-setpoint split; those are a separate task,
102020
+ * and adding a row here must never mean adding a service whose semantics this
102021
+ * file cannot fully honour.
102022
+ *
102023
+ * `alarm-panel` earned its row by answering the two questions that kept it
102024
+ * out: a target the panel would refuse is never offered (`availableModes` →
102025
+ * `validValues`, `security-target.ts`) and an arm a PIN-gated panel cannot
102026
+ * accept is refused out loud rather than attempted (`security-system.ts`).
101571
102027
  */
101572
102028
  /** HomeKit's floor for `CurrentAmbientLightLevel`; 0 lux is out of range. */
101573
102029
  var MIN_LUX = 1e-4;
@@ -101709,6 +102165,14 @@ var HAP_CAP_SERVICES = [
101709
102165
  displayName: name
101710
102166
  })
101711
102167
  },
102168
+ {
102169
+ caps: ["alarm-panel"],
102170
+ label: "Alarm",
102171
+ build: ({ bctx, name }) => buildSecuritySystem({
102172
+ ...bctx,
102173
+ displayName: name
102174
+ })
102175
+ },
101712
102176
  {
101713
102177
  caps: ["battery"],
101714
102178
  label: BATTERY_SPEC.label,
@@ -101746,7 +102210,8 @@ var ACCESSORY_CATEGORY_BY_TYPE = {
101746
102210
  [DeviceType.Siren]: import_dist.Categories.SWITCH,
101747
102211
  [DeviceType.Lock]: import_dist.Categories.DOOR_LOCK,
101748
102212
  [DeviceType.Sensor]: import_dist.Categories.SENSOR,
101749
- [DeviceType.Presence]: import_dist.Categories.SENSOR
102213
+ [DeviceType.Presence]: import_dist.Categories.SENSOR,
102214
+ [DeviceType.AlarmPanel]: import_dist.Categories.SECURITY_SYSTEM
101750
102215
  };
101751
102216
  function accessoryCategoryFor(deviceType) {
101752
102217
  return ACCESSORY_CATEGORY_BY_TYPE[deviceType] ?? import_dist.Categories.OTHER;