homebridge-nest-cam-ft
Version:
Nest cam plugin for homebridge: https://homebridge.io/
58 lines • 2.21 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NestStructure = void 0;
const endpoints_1 = require("./endpoints");
const axios_1 = __importDefault(require("axios"));
class NestStructure {
constructor(cameraInfo, config, log) {
var _a;
this.id = '';
this.apiHost = '';
this.faces = [];
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 endpoints_1.NestEndpoints((_a = config.options) === null || _a === void 0 ? void 0 : _a.fieldTest);
}
async getFaces() {
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) {
(0, endpoints_1.handleError)(this.log, error, 'Error getting faces');
}
return [];
}
async getMembers() {
try {
const req = {
method: 'GET',
url: `${this.endpoints.NEST_API_HOSTNAME}/api/0.1/structure/${this.id}/members`,
headers: {
Authorization: 'Basic ' + this.config.access_token,
'User-Agent': endpoints_1.NestEndpoints.USER_AGENT_STRING,
Referer: this.endpoints.NEST_API_HOSTNAME,
Cookie: `user_token=${this.config.access_token}`,
},
};
return (await (0, axios_1.default)(req)).data.members;
}
catch (error) {
(0, endpoints_1.handleError)(this.log, error, 'Error getting members');
}
return [];
}
}
exports.NestStructure = NestStructure;
//# sourceMappingURL=structure.js.map