unifi-protect: added new smart event and updated snapshot to use login (#595)

This commit is contained in:
Nick Berardi
2023-03-01 23:13:01 -05:00
committed by GitHub
parent 69d7ff2ced
commit de0e6ee955
2 changed files with 12 additions and 6 deletions

View File

@@ -200,11 +200,17 @@ export class UnifiCamera extends ScryptedDeviceBase implements Notifier, Interco
await input.promise;
}
const url = `https://${this.protect.getSetting('ip')}/proxy/protect/api/events/${detectionId}/thumbnail`;
const response = await this.protect.api.fetch(url);
if (!response) {
throw new Error('Event snapshot unavailable.');
}
const data = await response.arrayBuffer();
const abort = new AbortController();
const timeout = setTimeout(() => abort.abort('Unifi Protect Snapshot timed out after 10 seconds. Aborted.'), 10000);
const response = await this.protect.loginFetch(url, {
signal: abort.signal,
responseType: 'arraybuffer',
});
clearTimeout(timeout);
if (!response)
throw new Error('event snapshot unavailable.');
const data = Buffer.from(response.data);
return this.createMediaObject(Buffer.from(data), 'image/jpeg');
}

View File

@@ -186,7 +186,7 @@ export class UnifiProtect extends ScryptedDeviceBase implements Settings, Device
let detections: ObjectDetectionResult[] = [];
if (payload.type === 'smartDetectZone') {
if (payload.type === 'smartDetectZone' || payload.type === 'smartDetectLine') {
unifiCamera.resetDetectionTimeout();
detections = payload.smartDetectTypes.map(type => ({