Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Commit

Permalink
create nest structure for cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandawg93 committed Aug 3, 2020
1 parent 901a988 commit 2bb37a6
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/nest-structure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Logging, PlatformConfig } from 'homebridge';
import { NestEndpoints, handleError } from './nest-endpoints';
import { Face } from './models/structure-info';
import { CameraInfo } from './models/camera-info';

export class NestStructure {
private config: PlatformConfig;
private readonly log: Logging;
public id = '';
private apiHost = '';
private endpoints: NestEndpoints;
private faces: Array<Face> = [];

constructor(cameraInfo: CameraInfo, config: PlatformConfig, log: Logging) {
this.id = cameraInfo.nest_structure_id.replace('structure.', '');
this.apiHost = cameraInfo.nexus_api_nest_domain_host;
this.config = config;
this.log = log;
this.endpoints = new NestEndpoints(config.fieldTest);
}

async getFaces(): Promise<Array<Face>> {
if (this.faces.length > 0) {
return this.faces;
}
try {
const response = await this.endpoints.sendRequest(
this.config.access_token,
`https://${this.apiHost}`,
`/faces/${this.id}`,
'GET',
);
if (response && response.length > 0) {
this.faces = response;
return response;
}
} catch (error) {
handleError(this.log, error, 'Error getting faces');
}
return [];
}
}

0 comments on commit 2bb37a6

Please sign in to comment.