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.
48 lines • 2.65 kB
JavaScript
// Render a single "<label>: <value> [<confidence>% confidence]" fragment, the shared shape every rich attribute uses in the log line.
function attributeFragment(label, value, confidence) {
return label + ": " + value + " [" + String(confidence) + "% confidence]";
}
/* The vehicle enricher. UniFi Protect attaches a license plate (as the detection's `name`), a body color, and a body type to a vehicle smart detection, and these arrive
* progressively as the controller analyzes the clip. We surface whichever are present, in a stable order, so the log line and the MQTT payload grow coherently as the
* controller enriches the detection.
*/
const vehicleEnricher = {
attributes: (item) => {
const attributes = [];
// The license plate arrives as the detection's name, carrying the detection-level confidence.
if (item.name) {
attributes.push(attributeFragment("license plate", item.name, item.confidence ?? 0));
}
// Color and body type arrive as structured thumbnail attributes, each with its own confidence.
for (const attribute of ["color", "vehicleType"]) {
const detail = item.payload?.attributes?.[attribute];
if (detail) {
attributes.push(attributeFragment(attribute, detail.val ?? "", detail.confidence ?? 0));
}
}
return attributes;
},
mqtt: (item) => {
const color = item.payload?.attributes?.color;
const vehicleType = item.payload?.attributes?.vehicleType;
// With no plate, color, or body type there is nothing structured to publish.
if (!item.name?.length && !color && !vehicleType) {
return null;
}
return {
...(Number.isFinite(item.confidence) && { confidence: item.confidence }),
...(item.name?.length && { name: item.name }),
type: item.type,
...(color && { color }),
...(vehicleType && { vehicleType })
};
}
};
/* The registry mapping a smart-detection object type to its rich-metadata enricher. Today only vehicles carry structured telemetry; as UniFi Protect ships richer
* metadata for other smart-detection types (packages, animals, faces, ...), each becomes one new entry here and the event router's generic delivery picks it up with no
* further change. Types absent from this map are plain detections: the router coalesces them onto a single log line and never re-logs them within a motion window.
*/
export const SMART_DETECT_ENRICHERS = new Map([
["vehicle", vehicleEnricher]
]);
//# sourceMappingURL=smart-detect-metadata.js.map