@camstack/addon-provider-hikvision 1.1.15 → 1.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/addon.js CHANGED
@@ -4635,7 +4635,7 @@ function _instanceof(cls, params = {}) {
4635
4635
  return inst;
4636
4636
  }
4637
4637
  //#endregion
4638
- //#region ../types/dist/sleep-BiDFW0E7.mjs
4638
+ //#region ../types/dist/sleep-CZDdRBua.mjs
4639
4639
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
4640
4640
  EventCategory["SystemBoot"] = "system.boot";
4641
4641
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -7409,7 +7409,16 @@ var DecoderStatsSchema = object({
7409
7409
  inputFps: number(),
7410
7410
  outputFps: number(),
7411
7411
  avgDecodeTimeMs: number(),
7412
- droppedFrames: number()
7412
+ droppedFrames: number(),
7413
+ /**
7414
+ * Pull-mode adaptive-fps telemetry (optional — only pull sessions run the
7415
+ * lag-driven controller; push sessions omit these). `lagMs` is the EWMA of
7416
+ * the decoder's real-time drift (rising = falling behind live); `adaptiveFps`
7417
+ * is the current lag-throttled emit rate (≤ `effectiveFps` ceiling).
7418
+ */
7419
+ lagMs: number().optional(),
7420
+ effectiveFps: number().optional(),
7421
+ adaptiveFps: number().optional()
7413
7422
  });
7414
7423
  var DecoderSessionConfigSchema = object({
7415
7424
  codec: string(),
@@ -7450,7 +7459,15 @@ var DecoderSessionConfigSchema = object({
7450
7459
  * other — `pullFrames` returns nothing for an `'shm'` session and
7451
7460
  * `pullHandles` returns nothing for a `'callback'` session.
7452
7461
  */
7453
- frameSink: _enum(["callback", "shm"]).default("callback")
7462
+ frameSink: _enum(["callback", "shm"]).default("callback"),
7463
+ /**
7464
+ * Per-camera decoder DEBUG facility. When `true`, a pull-mode session emits
7465
+ * a throttled (~1Hz) structured `decoder debug` line (effective/adaptive fps,
7466
+ * real-time lag, dropped-frame delta, avg decode time, hwaccel). Mirrors the
7467
+ * stream-broker's `streamingDebug` gate — off by default so production logs
7468
+ * stay quiet and the emit path pays zero per-frame cost when disabled.
7469
+ */
7470
+ debug: boolean().optional()
7454
7471
  });
7455
7472
  var EncodeProfileSchema = object({
7456
7473
  video: object({
@@ -10514,6 +10531,100 @@ var coverCapability = {
10514
10531
  runtimeState: CoverStatusSchema
10515
10532
  };
10516
10533
  /**
10534
+ * Vendor-neutral day/night (IR-cut) control — the per-camera config cap
10535
+ * shared by reolink / hikvision / amcrest. Models the common firmware
10536
+ * surface: the IR-cut switching MODE plus the two knobs that gate it
10537
+ * (photocell `sensitivity` + `switchDelaySec`). Each vendor maps these
10538
+ * onto its own ISAPI / Baichuan / Dahua-CGI fields; the cap standardises
10539
+ * the shape so ONE derived-form renders every camera.
10540
+ *
10541
+ * Follows the D14 `deviceConfig` archetype (see `stream-params.cap.ts`):
10542
+ * `getOptions` advertises per-camera availability, `getStatus` (auto-
10543
+ * injected from `status`) reports the live values, and a single
10544
+ * `setSettings` mutation applies a partial change. No hand-written
10545
+ * settings-contribution methods — the framework derives the UI + save
10546
+ * routing from this surface.
10547
+ */
10548
+ /** IR-cut switching mode. `schedule` = time-of-day table configured on the camera. */
10549
+ var DayNightModeSchema = _enum([
10550
+ "auto",
10551
+ "day",
10552
+ "night",
10553
+ "schedule"
10554
+ ]);
10555
+ /** Normalized numeric range descriptor — `{ min, max, step }` per the
10556
+ * getOptions availability convention. Normalized values are 0–100. */
10557
+ var NormalizedRangeSchema$1 = object({
10558
+ min: number(),
10559
+ max: number(),
10560
+ step: number()
10561
+ });
10562
+ /**
10563
+ * Current day/night state. Optional fields are absent when the camera
10564
+ * does not expose that knob (a photocell-less model reports no
10565
+ * `sensitivity`). `lastFetchedAt` feeds the runtime-state bridge.
10566
+ */
10567
+ var DayNightStatusSchema = object({
10568
+ mode: DayNightModeSchema,
10569
+ /** IR-cut trigger sensitivity, NORMALIZED 0–100 (higher = switches to night sooner). */
10570
+ sensitivity: number().optional(),
10571
+ /** Delay before the IR-cut filter flips, in seconds. */
10572
+ switchDelaySec: number().optional(),
10573
+ lastFetchedAt: number()
10574
+ });
10575
+ /**
10576
+ * Per-camera availability descriptor — drives which controls the admin UI
10577
+ * renders. Booleans as `supportsX`; numeric ranges as `{ min, max, step }`
10578
+ * (normalized 0–100); the mode choice-set as an array. A provider returns
10579
+ * honest, camera-probed values — never hardcoded.
10580
+ */
10581
+ var DayNightOptionsSchema = object({
10582
+ /** Modes this camera accepts. Empty → the camera has no configurable day/night mode. */
10583
+ modes: array(DayNightModeSchema),
10584
+ supportsSensitivity: boolean(),
10585
+ /** Present when `supportsSensitivity` — the normalized 0–100 range. */
10586
+ sensitivity: NormalizedRangeSchema$1.optional(),
10587
+ supportsSwitchDelay: boolean(),
10588
+ /** Present when `supportsSwitchDelay` — the allowed delay range in seconds. */
10589
+ switchDelaySec: NormalizedRangeSchema$1.optional()
10590
+ });
10591
+ /**
10592
+ * Partial change to the day/night config — every field optional. A
10593
+ * provider ignores fields it does not support.
10594
+ */
10595
+ var DayNightSettingsPatchSchema = object({
10596
+ mode: DayNightModeSchema.optional(),
10597
+ sensitivity: number().optional(),
10598
+ switchDelaySec: number().optional()
10599
+ });
10600
+ var dayNightCapability = {
10601
+ name: "day-night",
10602
+ scope: "device",
10603
+ deviceNative: true,
10604
+ mode: "singleton",
10605
+ deviceTypes: [DeviceType.Camera],
10606
+ deviceConfig: { ui: {
10607
+ kind: "derived-form",
10608
+ builderId: "day-night",
10609
+ tab: "image"
10610
+ } },
10611
+ methods: {
10612
+ getOptions: method(object({ deviceId: number() }), DayNightOptionsSchema),
10613
+ setSettings: method(object({
10614
+ deviceId: number(),
10615
+ settings: DayNightSettingsPatchSchema
10616
+ }), _void(), {
10617
+ kind: "mutation",
10618
+ auth: "admin"
10619
+ })
10620
+ },
10621
+ status: {
10622
+ schema: DayNightStatusSchema,
10623
+ kind: "poll"
10624
+ },
10625
+ runtimeState: DayNightStatusSchema
10626
+ };
10627
+ /**
10517
10628
  * Identity envelope for a device's upstream-system metadata.
10518
10629
  *
10519
10630
  * Two jobs:
@@ -11172,6 +11283,155 @@ var imageCapability = {
11172
11283
  runtimeState: ImageStatusSchema
11173
11284
  };
11174
11285
  /**
11286
+ * Vendor-neutral image / picture-adjustment cap — the per-camera config
11287
+ * cap shared by reolink / hikvision / amcrest. Models the common ISP
11288
+ * surface: the four picture sliders (brightness / contrast / saturation /
11289
+ * sharpness), orientation (mirror / flip / rotate), white-balance,
11290
+ * exposure and backlight-compensation modes.
11291
+ *
11292
+ * NORMALIZATION: every slider is a normalized int 0–100. Vendors expose
11293
+ * these natively as 0–100 or 0–255 (or other ranges); each provider maps
11294
+ * its native range to/from this normalized 0–100 space so the cap surface
11295
+ * (and the derived form) is identical across cameras. `warmth` (manual
11296
+ * white-balance) is likewise normalized 0–100.
11297
+ *
11298
+ * Follows the D14 `deviceConfig` archetype (see `stream-params.cap.ts`):
11299
+ * `getOptions` advertises per-camera availability, `getStatus` (auto-
11300
+ * injected from `status`) reports the live values, and a single
11301
+ * `setSettings` mutation applies a partial change. No hand-written
11302
+ * settings-contribution methods — the framework derives the UI + save
11303
+ * routing from this surface.
11304
+ */
11305
+ /** Sensor/image rotation, degrees clockwise. */
11306
+ var ImageRotateSchema = _enum([
11307
+ "0",
11308
+ "90",
11309
+ "180",
11310
+ "270"
11311
+ ]);
11312
+ /** White-balance mode. `manual` unlocks the normalized `warmth` knob. */
11313
+ var WhiteBalanceModeSchema = _enum(["auto", "manual"]);
11314
+ /** Exposure mode. */
11315
+ var ExposureModeSchema = _enum(["auto", "manual"]);
11316
+ /**
11317
+ * Backlight-compensation mode:
11318
+ * - `off` — disabled
11319
+ * - `blc` — backlight compensation
11320
+ * - `wdr` — wide dynamic range
11321
+ * - `hlc` — highlight compensation
11322
+ */
11323
+ var BacklightModeSchema = _enum([
11324
+ "off",
11325
+ "blc",
11326
+ "wdr",
11327
+ "hlc"
11328
+ ]);
11329
+ /** Normalized numeric range descriptor — `{ min, max, step }` per the
11330
+ * getOptions availability convention. Slider values are normalized 0–100. */
11331
+ var NormalizedRangeSchema = object({
11332
+ min: number(),
11333
+ max: number(),
11334
+ step: number()
11335
+ });
11336
+ /**
11337
+ * Current image-adjustment state. Every field optional — absent when the
11338
+ * camera does not expose that control. Slider values are NORMALIZED 0–100.
11339
+ * `lastFetchedAt` feeds the runtime-state bridge.
11340
+ */
11341
+ var ImageSettingsStatusSchema = object({
11342
+ /** Normalized 0–100. */
11343
+ brightness: number().optional(),
11344
+ /** Normalized 0–100. */
11345
+ contrast: number().optional(),
11346
+ /** Normalized 0–100. */
11347
+ saturation: number().optional(),
11348
+ /** Normalized 0–100. */
11349
+ sharpness: number().optional(),
11350
+ mirror: boolean().optional(),
11351
+ flip: boolean().optional(),
11352
+ rotate: ImageRotateSchema.optional(),
11353
+ whiteBalance: WhiteBalanceModeSchema.optional(),
11354
+ /** Manual white-balance warmth, NORMALIZED 0–100. Meaningful only when `whiteBalance === 'manual'`. */
11355
+ warmth: number().optional(),
11356
+ exposureMode: ExposureModeSchema.optional(),
11357
+ backlightMode: BacklightModeSchema.optional(),
11358
+ lastFetchedAt: number()
11359
+ });
11360
+ /**
11361
+ * Per-camera availability descriptor — drives which controls the admin UI
11362
+ * renders. Booleans as `supportsX`; numeric ranges as `{ min, max, step }`
11363
+ * (the normalized 0–100 range); enums as arrays of supported values (empty
11364
+ * array → control hidden). A provider returns honest, camera-probed values
11365
+ * — never hardcoded.
11366
+ */
11367
+ var ImageSettingsOptionsSchema = object({
11368
+ supportsBrightness: boolean(),
11369
+ brightness: NormalizedRangeSchema.optional(),
11370
+ supportsContrast: boolean(),
11371
+ contrast: NormalizedRangeSchema.optional(),
11372
+ supportsSaturation: boolean(),
11373
+ saturation: NormalizedRangeSchema.optional(),
11374
+ supportsSharpness: boolean(),
11375
+ sharpness: NormalizedRangeSchema.optional(),
11376
+ supportsMirror: boolean(),
11377
+ supportsFlip: boolean(),
11378
+ /** Supported rotation values. Empty → rotation not configurable. */
11379
+ rotateOptions: array(ImageRotateSchema),
11380
+ /** Supported white-balance modes. Empty → white-balance not configurable. */
11381
+ whiteBalanceModes: array(WhiteBalanceModeSchema),
11382
+ supportsWarmth: boolean(),
11383
+ /** Present when `supportsWarmth` — the normalized 0–100 range. */
11384
+ warmth: NormalizedRangeSchema.optional(),
11385
+ /** Supported exposure modes. Empty → exposure not configurable. */
11386
+ exposureModes: array(ExposureModeSchema),
11387
+ /** Supported backlight modes. Empty → backlight-compensation not configurable. */
11388
+ backlightModes: array(BacklightModeSchema)
11389
+ });
11390
+ /**
11391
+ * Partial change to the image config — every field optional. Slider values
11392
+ * are normalized 0–100. A provider ignores fields it does not support.
11393
+ */
11394
+ var ImageSettingsPatchSchema = object({
11395
+ brightness: number().optional(),
11396
+ contrast: number().optional(),
11397
+ saturation: number().optional(),
11398
+ sharpness: number().optional(),
11399
+ mirror: boolean().optional(),
11400
+ flip: boolean().optional(),
11401
+ rotate: ImageRotateSchema.optional(),
11402
+ whiteBalance: WhiteBalanceModeSchema.optional(),
11403
+ warmth: number().optional(),
11404
+ exposureMode: ExposureModeSchema.optional(),
11405
+ backlightMode: BacklightModeSchema.optional()
11406
+ });
11407
+ var imageSettingsCapability = {
11408
+ name: "image-settings",
11409
+ scope: "device",
11410
+ deviceNative: true,
11411
+ mode: "singleton",
11412
+ deviceTypes: [DeviceType.Camera],
11413
+ deviceConfig: { ui: {
11414
+ kind: "derived-form",
11415
+ builderId: "image-settings",
11416
+ tab: "image"
11417
+ } },
11418
+ methods: {
11419
+ getOptions: method(object({ deviceId: number() }), ImageSettingsOptionsSchema),
11420
+ setSettings: method(object({
11421
+ deviceId: number(),
11422
+ settings: ImageSettingsPatchSchema
11423
+ }), _void(), {
11424
+ kind: "mutation",
11425
+ auth: "admin"
11426
+ })
11427
+ },
11428
+ status: {
11429
+ schema: ImageSettingsStatusSchema,
11430
+ kind: "poll"
11431
+ },
11432
+ runtimeState: ImageSettingsStatusSchema
11433
+ };
11434
+ /**
11175
11435
  * Robotic lawn-mower cap. Models HA `lawn_mower.*` entities — anything
11176
11436
  * with a mowing lifecycle plus a dock action.
11177
11437
  *
@@ -12170,6 +12430,16 @@ var RunnerCameraConfigSchema = object({
12170
12430
  * this gate is bypassed.
12171
12431
  */
12172
12432
  onboardMotionDrivesAnalyzer: boolean().default(true),
12433
+ /**
12434
+ * Master toggle for the occupancy re-check. When `false` (DEFAULT) the runner
12435
+ * never arms the periodic recheck timer, regardless of `occupancyRecheckSec` —
12436
+ * this is off by default because the recheck re-subscribes a detection session
12437
+ * every N seconds while `watching`, a major source of pull-decoder re-dial
12438
+ * churn (each cycle creates+tears a session → RTSP re-dial → latency). The
12439
+ * `occupancyRecheckSec` / `occupancyRecheckFrames` sliders only take effect
12440
+ * (and only render) when this is enabled.
12441
+ */
12442
+ occupancyRecheckEnabled: boolean().default(false),
12173
12443
  occupancyRecheckSec: number().min(occupancyRecheckSecField.min).max(occupancyRecheckSecField.max).default(occupancyRecheckSecField.default),
12174
12444
  occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default),
12175
12445
  /**
@@ -14175,6 +14445,7 @@ var DEVICE_LOCAL_STATE_CAPS = {
14175
14445
  contact: contactCapability,
14176
14446
  control: controlCapability,
14177
14447
  cover: coverCapability,
14448
+ dayNight: dayNightCapability,
14178
14449
  deviceDiscovery: deviceDiscoveryCapability,
14179
14450
  deviceStatus: deviceStatusCapability,
14180
14451
  doorbell: doorbellCapability,
@@ -14187,6 +14458,7 @@ var DEVICE_LOCAL_STATE_CAPS = {
14187
14458
  humidifier: humidifierCapability,
14188
14459
  humiditySensor: humiditySensorCapability,
14189
14460
  image: imageCapability,
14461
+ imageSettings: imageSettingsCapability,
14190
14462
  lawnMowerControl: lawnMowerControlCapability,
14191
14463
  lockControl: lockControlCapability,
14192
14464
  mediaPlayer: mediaPlayerCapability,
@@ -16113,7 +16385,9 @@ method(object({ codec: string() }), boolean()), method(_void(), object({
16113
16385
  id: string(),
16114
16386
  name: string(),
16115
16387
  isPullMode: boolean().optional(),
16116
- priority: number().optional()
16388
+ priority: number().optional(),
16389
+ hwaccel: string().optional(),
16390
+ probedBestHwaccel: string().optional()
16117
16391
  })), method(DecoderSessionConfigSchema, object({
16118
16392
  sessionId: string(),
16119
16393
  nodeId: string()
@@ -18027,7 +18301,17 @@ var AgentAddonConfigSchema = object({
18027
18301
  });
18028
18302
  var AgentPipelineSettingsSchema = object({
18029
18303
  addonDefaults: record(string(), AgentAddonConfigSchema).readonly(),
18030
- maxCameras: number().int().nonnegative().nullable().default(null)
18304
+ maxCameras: number().int().nonnegative().nullable().default(null),
18305
+ /** Per-node detection weight (relative share for the quota balancer). */
18306
+ detectWeight: number().positive().optional(),
18307
+ /** Node is eligible to run the detection pipeline (decode + inference). */
18308
+ detect: boolean().optional(),
18309
+ /** Node is eligible to host decoder sessions. */
18310
+ decode: boolean().optional(),
18311
+ /** Node is eligible to run audio-analyzer sessions. */
18312
+ audio: boolean().optional(),
18313
+ /** Node is eligible to be the ingest / source-owner (serve the restream). */
18314
+ ingest: boolean().optional()
18031
18315
  });
18032
18316
  var CameraPipelineForAgentSchema = object({
18033
18317
  steps: array(PipelineStepInputSchema).readonly(),
@@ -18333,6 +18617,21 @@ method(object({
18333
18617
  }), object({ success: literal(true) }), {
18334
18618
  kind: "mutation",
18335
18619
  auth: "admin"
18620
+ }), method(object({
18621
+ agentNodeId: string(),
18622
+ detectWeight: number().positive().nullable()
18623
+ }), object({ success: literal(true) }), {
18624
+ kind: "mutation",
18625
+ auth: "admin"
18626
+ }), method(object({
18627
+ agentNodeId: string(),
18628
+ detect: boolean().nullable().optional(),
18629
+ decode: boolean().nullable().optional(),
18630
+ audio: boolean().nullable().optional(),
18631
+ ingest: boolean().nullable().optional()
18632
+ }), object({ success: literal(true) }), {
18633
+ kind: "mutation",
18634
+ auth: "admin"
18336
18635
  }), method(object({ deviceId: number() }), CameraPipelineSettingsSchema.nullable()), method(object({
18337
18636
  deviceId: number(),
18338
18637
  addonId: string(),
@@ -22498,6 +22797,18 @@ Object.freeze({
22498
22797
  addonId: null,
22499
22798
  access: "view"
22500
22799
  },
22800
+ "dayNight.getOptions": {
22801
+ capName: "day-night",
22802
+ capScope: "device",
22803
+ addonId: null,
22804
+ access: "view"
22805
+ },
22806
+ "dayNight.setSettings": {
22807
+ capName: "day-night",
22808
+ capScope: "device",
22809
+ addonId: null,
22810
+ access: "create"
22811
+ },
22501
22812
  "decoder.createSession": {
22502
22813
  capName: "decoder",
22503
22814
  capScope: "system",
@@ -23428,6 +23739,18 @@ Object.freeze({
23428
23739
  addonId: null,
23429
23740
  access: "create"
23430
23741
  },
23742
+ "imageSettings.getOptions": {
23743
+ capName: "image-settings",
23744
+ capScope: "device",
23745
+ addonId: null,
23746
+ access: "view"
23747
+ },
23748
+ "imageSettings.setSettings": {
23749
+ capName: "image-settings",
23750
+ capScope: "device",
23751
+ addonId: null,
23752
+ access: "create"
23753
+ },
23431
23754
  "integrations.create": {
23432
23755
  capName: "integrations",
23433
23756
  capScope: "system",
@@ -24610,6 +24933,18 @@ Object.freeze({
24610
24933
  addonId: null,
24611
24934
  access: "create"
24612
24935
  },
24936
+ "pipelineOrchestrator.setAgentCapabilities": {
24937
+ capName: "pipeline-orchestrator",
24938
+ capScope: "system",
24939
+ addonId: null,
24940
+ access: "create"
24941
+ },
24942
+ "pipelineOrchestrator.setAgentDetectWeight": {
24943
+ capName: "pipeline-orchestrator",
24944
+ capScope: "system",
24945
+ addonId: null,
24946
+ access: "create"
24947
+ },
24613
24948
  "pipelineOrchestrator.setAgentMaxCameras": {
24614
24949
  capName: "pipeline-orchestrator",
24615
24950
  capScope: "system",
@@ -29869,6 +30204,26 @@ async function withTimeout(promise, ms, label) {
29869
30204
  }
29870
30205
  }
29871
30206
  /**
30207
+ * Hikvision's `IrcutFilterType` enumerates the same four values as the
30208
+ * `day-night` cap's `DayNightMode` — no value mapping needed, only a
30209
+ * type-narrowing guard for the loosely-typed ISAPI response.
30210
+ */
30211
+ var HIKVISION_DAY_NIGHT_MODES = [
30212
+ "auto",
30213
+ "day",
30214
+ "night",
30215
+ "schedule"
30216
+ ];
30217
+ function isDayNightMode(mode) {
30218
+ return mode === "auto" || mode === "day" || mode === "night" || mode === "schedule";
30219
+ }
30220
+ /** Narrow the ISAPI `IrcutFilterType` string to `DayNightMode`, falling
30221
+ * back to `'auto'` for any value outside the known enum (defensive —
30222
+ * firmware is not expected to emit anything else). */
30223
+ function toDayNightMode(mode) {
30224
+ return isDayNightMode(mode) ? mode : "auto";
30225
+ }
30226
+ /**
29872
30227
  * Hikvision camera device — ISAPI control channel for snapshot, reboot,
29873
30228
  * and the alarm event stream; RTSP URLs handed to the broker for video
29874
30229
  * pull (the broker handles the actual TCP/UDP RTSP, codec negotiation,
@@ -29949,6 +30304,10 @@ var HikvisionCamera = class HikvisionCamera extends BaseDevice {
29949
30304
  motionZonesRefreshInFlight = null;
29950
30305
  /** Single-flight guard for the privacy-mask camera refresh. */
29951
30306
  privacyMaskRefreshInFlight = null;
30307
+ /** Single-flight guard for the day-night camera refresh. */
30308
+ dayNightRefreshInFlight = null;
30309
+ /** Single-flight guard for the image-settings camera refresh. */
30310
+ imageSettingsRefreshInFlight = null;
29952
30311
  /**
29953
30312
  * Single-flight guard for the v0.2 capability discovery probe. Reset
29954
30313
  * on settings patches that change credentials (`disconnectAll`) so
@@ -30036,6 +30395,8 @@ var HikvisionCamera = class HikvisionCamera extends BaseDevice {
30036
30395
  this.registerStreamParamsCap(1);
30037
30396
  this.registerMotionZonesCap(1);
30038
30397
  this.registerPrivacyMaskCap(1);
30398
+ this.registerDayNightCap(1);
30399
+ this.registerImageSettingsCap(1);
30039
30400
  this.registerStreamCatalogProvider();
30040
30401
  this.registerDeviceAction("syncTimeFromLocal", deviceCustomAction(object({}), object({ success: boolean() }), { kind: "mutation" }), async () => {
30041
30402
  try {
@@ -31507,6 +31868,222 @@ var HikvisionCamera = class HikvisionCamera extends BaseDevice {
31507
31868
  });
31508
31869
  }
31509
31870
  /**
31871
+ * Register the `day-night` native cap provider — the vendor-neutral
31872
+ * IR-cut mode control shared with reolink/amcrest. Hikvision exposes
31873
+ * IR-cut switching mode at `/ISAPI/Image/channels/{cam}/IrcutFilter`
31874
+ * (`IrcutFilterType`: auto/day/night/schedule) — the enum matches the
31875
+ * cap's `DayNightMode` one-for-one, so no value mapping is needed.
31876
+ *
31877
+ * TODO: photocell `sensitivity` and `switchDelaySec` have no wired
31878
+ * ISAPI equivalent in `HikvisionIsapiClient` yet — the existing
31879
+ * `IrcutFilter` parser only reads `IrcutFilterType`. Advertised as
31880
+ * unsupported (`false`) rather than guessing an undocumented XML tag;
31881
+ * revisit once a real-device capture confirms the sensitivity/delay
31882
+ * field names.
31883
+ */
31884
+ registerDayNightCap(cameraNumber) {
31885
+ const isapi = this.ensureClient();
31886
+ const CAP_NAME = "day-night";
31887
+ const STALE_MS = 1e4;
31888
+ /** Round-trip the IR-cut filter mode, map into the cap status, write slice. */
31889
+ const refreshFromCamera = async () => {
31890
+ if (this.dayNightRefreshInFlight) return this.dayNightRefreshInFlight;
31891
+ const promise = (async () => {
31892
+ try {
31893
+ const filter = await isapi.getIrcutFilter(cameraNumber);
31894
+ if (!filter) return;
31895
+ const next = {
31896
+ mode: toDayNightMode(filter.mode),
31897
+ lastFetchedAt: Date.now()
31898
+ };
31899
+ this.runtimeState.setCapState(CAP_NAME, next);
31900
+ } catch (err) {
31901
+ this.ctx.logger.debug("hikvision day-night refresh failed — keeping last slice", {
31902
+ tags: { deviceId: this.id },
31903
+ meta: { error: err instanceof Error ? err.message : String(err) }
31904
+ });
31905
+ }
31906
+ })();
31907
+ this.dayNightRefreshInFlight = promise;
31908
+ try {
31909
+ await promise;
31910
+ } finally {
31911
+ this.dayNightRefreshInFlight = null;
31912
+ }
31913
+ };
31914
+ const provider = {
31915
+ getStatus: createRuntimeStateBridge({
31916
+ runtimeState: this.runtimeState,
31917
+ cap: dayNightCapability,
31918
+ ownDeviceId: this.id,
31919
+ refresh: refreshFromCamera,
31920
+ staleMs: STALE_MS,
31921
+ empty: () => ({
31922
+ mode: "auto",
31923
+ lastFetchedAt: 0
31924
+ })
31925
+ }).getStatus,
31926
+ getOptions: async ({ deviceId }) => {
31927
+ const cold = {
31928
+ modes: [],
31929
+ supportsSensitivity: false,
31930
+ supportsSwitchDelay: false
31931
+ };
31932
+ if (deviceId !== this.id) return cold;
31933
+ if (!await isapi.getIrcutFilter(cameraNumber)) return cold;
31934
+ return {
31935
+ modes: [...HIKVISION_DAY_NIGHT_MODES],
31936
+ supportsSensitivity: false,
31937
+ supportsSwitchDelay: false
31938
+ };
31939
+ },
31940
+ setSettings: async ({ deviceId, settings }) => {
31941
+ if (deviceId !== this.id) return;
31942
+ if (settings.mode !== void 0) await isapi.setIrcutFilter(cameraNumber, { mode: settings.mode });
31943
+ await refreshFromCamera();
31944
+ }
31945
+ };
31946
+ this.ctx.registerNativeCap(dayNightCapability, provider);
31947
+ this.ctx.logger.info("hikvision: day-night cap registered", {
31948
+ tags: { deviceId: this.id },
31949
+ meta: { cameraNumber }
31950
+ });
31951
+ }
31952
+ /**
31953
+ * Register the `image-settings` native cap provider — vendor-neutral
31954
+ * picture-adjustment controls shared with reolink/amcrest. Hikvision's
31955
+ * `/ISAPI/Image/channels/{cam}` sub-resources map cleanly onto FOUR
31956
+ * of the cap's fields:
31957
+ * - brightness/contrast/saturation ← `/color` (`getImageColor`/`setImageColor`)
31958
+ * - sharpness ← `/sharpness` (separate endpoint)
31959
+ * - backlightMode `'off'`/`'wdr'` ← `/WDR` (`getImageWdr`/`setImageWdr`, open/close)
31960
+ * All four are ALREADY normalized 0..100 on the wire (the ISAPI
31961
+ * client's `setImageColor`/`setImageSharpness` clamp to that range),
31962
+ * so no unit conversion is needed for the cap's normalized-0-100
31963
+ * contract — the range descriptor is the identity `{0,100,1}`.
31964
+ *
31965
+ * TODO — no wired ISAPI equivalent in `HikvisionIsapiClient` yet, left
31966
+ * unsupported (honest `false`/`[]` in `getOptions`) rather than
31967
+ * guessing undocumented XML tags:
31968
+ * - mirror / flip / rotate
31969
+ * - white-balance mode + manual warmth
31970
+ * - exposure mode
31971
+ * - backlightMode `'blc'` / `'hlc'` (only the WDR on/off toggle is wired)
31972
+ */
31973
+ registerImageSettingsCap(cameraNumber) {
31974
+ const isapi = this.ensureClient();
31975
+ const CAP_NAME = "image-settings";
31976
+ const STALE_MS = 1e4;
31977
+ const NORMALIZED_RANGE = {
31978
+ min: 0,
31979
+ max: 100,
31980
+ step: 1
31981
+ };
31982
+ /** Round-trip color + sharpness + WDR, map into the cap status, write slice. */
31983
+ const refreshFromCamera = async () => {
31984
+ if (this.imageSettingsRefreshInFlight) return this.imageSettingsRefreshInFlight;
31985
+ const promise = (async () => {
31986
+ try {
31987
+ const [color, sharpness, wdr] = await Promise.all([
31988
+ isapi.getImageColor(cameraNumber),
31989
+ isapi.getImageSharpness(cameraNumber),
31990
+ isapi.getImageWdr(cameraNumber)
31991
+ ]);
31992
+ if (!color && sharpness === null && !wdr) return;
31993
+ const next = {
31994
+ brightness: color?.brightness ?? void 0,
31995
+ contrast: color?.contrast ?? void 0,
31996
+ saturation: color?.saturation ?? void 0,
31997
+ sharpness: sharpness ?? color?.sharpness ?? void 0,
31998
+ backlightMode: wdr ? wdr.enabled ? "wdr" : "off" : void 0,
31999
+ lastFetchedAt: Date.now()
32000
+ };
32001
+ this.runtimeState.setCapState(CAP_NAME, next);
32002
+ } catch (err) {
32003
+ this.ctx.logger.debug("hikvision image-settings refresh failed — keeping last slice", {
32004
+ tags: { deviceId: this.id },
32005
+ meta: { error: err instanceof Error ? err.message : String(err) }
32006
+ });
32007
+ }
32008
+ })();
32009
+ this.imageSettingsRefreshInFlight = promise;
32010
+ try {
32011
+ await promise;
32012
+ } finally {
32013
+ this.imageSettingsRefreshInFlight = null;
32014
+ }
32015
+ };
32016
+ const provider = {
32017
+ getStatus: createRuntimeStateBridge({
32018
+ runtimeState: this.runtimeState,
32019
+ cap: imageSettingsCapability,
32020
+ ownDeviceId: this.id,
32021
+ refresh: refreshFromCamera,
32022
+ staleMs: STALE_MS,
32023
+ empty: () => ({ lastFetchedAt: 0 })
32024
+ }).getStatus,
32025
+ getOptions: async ({ deviceId }) => {
32026
+ const cold = {
32027
+ supportsBrightness: false,
32028
+ supportsContrast: false,
32029
+ supportsSaturation: false,
32030
+ supportsSharpness: false,
32031
+ supportsMirror: false,
32032
+ supportsFlip: false,
32033
+ rotateOptions: [],
32034
+ whiteBalanceModes: [],
32035
+ supportsWarmth: false,
32036
+ exposureModes: [],
32037
+ backlightModes: []
32038
+ };
32039
+ if (deviceId !== this.id) return cold;
32040
+ const [color, sharpness, wdr] = await Promise.all([
32041
+ isapi.getImageColor(cameraNumber),
32042
+ isapi.getImageSharpness(cameraNumber),
32043
+ isapi.getImageWdr(cameraNumber)
32044
+ ]);
32045
+ const hasBrightness = color?.brightness !== null && color?.brightness !== void 0;
32046
+ const hasContrast = color?.contrast !== null && color?.contrast !== void 0;
32047
+ const hasSaturation = color?.saturation !== null && color?.saturation !== void 0;
32048
+ const hasSharpness = sharpness !== null;
32049
+ return {
32050
+ supportsBrightness: hasBrightness,
32051
+ brightness: hasBrightness ? NORMALIZED_RANGE : void 0,
32052
+ supportsContrast: hasContrast,
32053
+ contrast: hasContrast ? NORMALIZED_RANGE : void 0,
32054
+ supportsSaturation: hasSaturation,
32055
+ saturation: hasSaturation ? NORMALIZED_RANGE : void 0,
32056
+ supportsSharpness: hasSharpness,
32057
+ sharpness: hasSharpness ? NORMALIZED_RANGE : void 0,
32058
+ supportsMirror: false,
32059
+ supportsFlip: false,
32060
+ rotateOptions: [],
32061
+ whiteBalanceModes: [],
32062
+ supportsWarmth: false,
32063
+ exposureModes: [],
32064
+ backlightModes: wdr ? ["off", "wdr"] : []
32065
+ };
32066
+ },
32067
+ setSettings: async ({ deviceId, settings }) => {
32068
+ if (deviceId !== this.id) return;
32069
+ if (settings.brightness !== void 0 || settings.contrast !== void 0 || settings.saturation !== void 0) await isapi.setImageColor(cameraNumber, {
32070
+ brightness: settings.brightness,
32071
+ contrast: settings.contrast,
32072
+ saturation: settings.saturation
32073
+ });
32074
+ if (settings.sharpness !== void 0) await isapi.setImageSharpness(cameraNumber, settings.sharpness);
32075
+ if (settings.backlightMode === "wdr") await isapi.setImageWdr(cameraNumber, { enabled: true });
32076
+ else if (settings.backlightMode === "off") await isapi.setImageWdr(cameraNumber, { enabled: false });
32077
+ await refreshFromCamera();
32078
+ }
32079
+ };
32080
+ this.ctx.registerNativeCap(imageSettingsCapability, provider);
32081
+ this.ctx.logger.info("hikvision: image-settings cap registered", {
32082
+ tags: { deviceId: this.id },
32083
+ meta: { cameraNumber }
32084
+ });
32085
+ }
32086
+ /**
31510
32087
  * Translate a cap-layer `StreamProfilePatch` into the field set
31511
32088
  * `setStreamingChannel` accepts. `current` is the freshly-read
31512
32089
  * channel config — used to resolve which quality-mode field a