Skip to content

Commit

Permalink
unifi-protect: added new smart event and updated snapshot to use login (
Browse files Browse the repository at this point in the history
  • Loading branch information
nberardi authored Mar 2, 2023
1 parent 69d7ff2 commit de0e6ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions plugins/unifi-protect/src/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/unifi-protect/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ({
Expand Down

0 comments on commit de0e6ee

Please sign in to comment.