This repository has been archived by the owner on Aug 14, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
901a988
commit 2bb37a6
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 []; | ||
} | ||
} |