UNPKG

homebridge-unifi-protect

Version:

Homebridge UniFi Protect plugin providing complete HomeKit integration for the entire UniFi Protect ecosystem with full support for most features including HomeKit Secure Video, multiple controllers, blazing fast performance, and much more.

75 lines 5.51 kB
/* Copyright(C) 2020-2026, HJD (https://github.com/hjdhjd). All rights reserved. * * types.ts: Interface and type definitions for UniFi Protect. */ // Compile-time exhaustiveness check for discriminated unions. When all cases of a union are handled in a switch statement, TypeScript narrows the remaining type to // `never`. Passing it to this function ensures the compiler will flag an error if a new variant is added to the union without a corresponding case. At runtime this is a // no-op...the call site is responsible for graceful degradation (logging, returning null, etc.). // eslint-disable-next-line @typescript-eslint/no-empty-function export function exhaustiveGuard(_value) { } const _deviceTypesExact = true; const _projectionMapExact = true; /* The package-camera identity suffixes. A doorbell's package camera is a synthetic HomeKit accessory derived from its parent doorbell, and its identity is carried in two * distinct representations that must never be conflated: a protocol marker and a user-visible label are different jobs for different strings, so each gets its own * constant rather than one string doing both. */ // The protocol and persistence suffix appended to the parent doorbell's MAC address to form the package camera's unique device id. This value is persistence-critical // identity: it seeds the package accessory's cached HomeKit UUID and keys the event dispatcher's per-device timers, so any drift here orphans every cached package camera // accessory on every install in the field. Treat it as immutable. export const PACKAGE_CAMERA_ID_SUFFIX = ".PackageCamera"; // Compose the unique package-camera device identifier from a parent camera's MAC address. This is the single identity derivation the package camera's id getter and // accessory-UUID seed consume, and that the doorbell capability's package lifecycle (configure, reconcile, detach) consumes as a pure consumer of the package's identity. // It lives here in the shared leaf - beside its persistence-critical suffix - rather than on the package class, so the doorbell capability can derive the id without a // value-import of its sibling package-camera class (which would close a module-initialization cycle); the package class re-exposes it as its own public identity API. export function packageCameraId(mac) { return mac + PACKAGE_CAMERA_ID_SUFFIX; } // Whether a persisted accessory context belongs to a package camera. The two identity forms are mutually exclusive by construction - seedContextIdentity seeds a real // device's bare MAC into `mac` and the package camera's parent MAC into `packageCamera`, never both - and this predicate is the single vocabulary every consumer uses // to branch on that distinction, so the exclusivity is asserted in exactly one place instead of being re-derived at each read site. export function isPackageCameraContext(context) { return !!context.packageCamera; } // The display suffix appended to the parent doorbell's name to form the package camera's user-visible HomeKit name. Purely presentational - the protocol id above never // derives from it, so the display suffix can evolve without touching persisted identity. export const PACKAGE_CAMERA_NAME_SUFFIX = " Package Camera"; // A frozen lookup of the reserved subtype identifiers the plugin assigns to the HomeKit services it synthesizes. Modeled as an "as const" object rather than a TypeScript // enum so the declaration is erasable...the project's test runner is "node --strip-types", which executes TypeScript by erasing types and cannot run a non-erasable // enum (the shared tsconfig's erasableSyntaxOnly flag enforces this). The object literal carries the identical string values at the identical keys, so every // ProtectReservedNames.X value read is unchanged; the companion type alias below preserves the type-position uses. export const ProtectReservedNames = { // Manage our contact sensor types. CONTACT_AUTHSENSOR: "ContactAuthSensor", CONTACT_MOTION_SMARTDETECT: "ContactMotionSmartDetect", CONTACT_MOTION_SMARTDETECT_LICENSE: "ContactMotionSmartDetectLicense", CONTACT_SENSOR: "ContactSensor", CONTACT_SENSOR_ALARM_SOUND: "ContactAlarmSound", CONTACT_SENSOR_GLASS_BREAK: "ContactGlassBreak", // Manage our leak sensor types. LEAKSENSOR_EXTERNAL: "External", LEAKSENSOR_INTERNAL: "Internal", // Manage our lightbulb types. LIGHTBULB_DOORBELL_VOLUME: "ChimeVolume", LIGHTBULB_NIGHTVISION: "NightVision", LIGHTBULB_PACKAGE_FLASHLIGHT: "PackageCamera.Flashlight", // Manage our lock types. LOCK_ACCESS: "Access", // Manage our switch types. SWITCH_DOORBELL_CHIME_BUZZER: "DoorbellChime.buzzer", SWITCH_DOORBELL_CHIME_DIGITAL: "DoorbellChime.digital", SWITCH_DOORBELL_CHIME_MECHANICAL: "DoorbellChime.mechanical", SWITCH_DOORBELL_CHIME_NONE: "DoorbellChime.none", SWITCH_DOORBELL_CHIME_SPEAKER: "DoorbellChime.speaker", SWITCH_DOORBELL_MUTE: "DoorbellMute", SWITCH_DOORBELL_TRIGGER: "DoorbellTrigger", SWITCH_FOB_BUTTON: "FobButton", SWITCH_HKSV_RECORDING: "HKSVRecordingSwitch", SWITCH_MOTION_SENSOR: "MotionSensorSwitch", SWITCH_MOTION_TRIGGER: "MotionSensorTrigger", SWITCH_RELAY_OUTPUT: "RelayOutput", SWITCH_STATUS_LED: "StatusLedSwitch", SWITCH_UFP_RECORDING_ALWAYS: "UFPRecordingSwitch.always", SWITCH_UFP_RECORDING_DETECTIONS: "UFPRecordingSwitch.detections", SWITCH_UFP_RECORDING_NEVER: "UFPRecordingSwitch.never" }; //# sourceMappingURL=types.js.map