Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

homebridge-nest-cam2

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

homebridge-nest-cam2 - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

11

index.js

@@ -7,2 +7,4 @@ 'use strict';

const UPDATE_INTERVAL = 10000;
Promise.delay = function(time_ms) {

@@ -105,3 +107,3 @@ return new Promise(resolve => setTimeout(resolve, time_ms));

camera.checkMotion(accessory);
}, 10000);
}, UPDATE_INTERVAL);
}

@@ -117,2 +119,9 @@ //Add enabled/disabled service

});
//Check enabled/disabled state
setInterval(async function() {
await camera.updateInfo();
let service = accessory.getService(Service.Switch);
service.updateCharacteristic(Characteristic.On, camera.enabled);
}, UPDATE_INTERVAL);
accessory.configureCameraSource(camera);

@@ -119,0 +128,0 @@ configuredAccessories.push(accessory);

'use strict';
const https = require('https');
const axios = require('axios');

@@ -67,2 +68,51 @@ const EventEmitter = require('events');

}
/**
* Send a generic api request using promises
* @param hostname The base uri to send the request
* @param endpoint The endpoint to send the request
* @param method Usually "GET" or "POST"
* @param body The body of the request or null if a "GET"
*/
sendPromiseRequest(hostname, endpoint, method, body) {
let self = this;
return new Promise((resolve, reject) => {
let headers = {
'User-Agent': 'iPhone iPhone OS 11.0 Dropcam/5.14.0 com.nestlabs.jasper.release Darwin',
'Referer': 'https://home.nest.com/'
};
if (method === 'POST') {
headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';
}
if (self.accessToken !== undefined) {
headers['Cookie'] = 'user_token=' + self.accessToken;
}
let options = {
hostname: hostname,
path: endpoint,
method: method,
headers: headers
};
let req = https.request(options, (res) => {
if (res.statusCode < 200 || res.statusCode >= 300) {
let error = new Error('Unexpected API Error - ' + res.statusCode);
error.code = res.statusCode;
reject(error);
}
const resBody = [];
res.on('data', (chunk) => resBody.push(chunk));
res.on('end', () => resolve(Buffer.concat(resBody)));
});
req.on('error', (err) => reject(err));
if (body !== undefined) {
req.write(body);
}
req.end();
});
}
}

@@ -69,0 +119,0 @@

43

lib/nestcam.js

@@ -29,2 +29,27 @@ 'use strict';

async updateInfo() {
let self = this;
let query = querystring.stringify({
'uuid': self.uuid
});
try {
self.log.debug("Updating info for %s", self.name);
let response = await self.api.sendRequest(NestAPIHostname, '/api/cameras.get_with_properties?' + query, 'GET');
response.items.forEach((info) => {
self.name = info.name;
self.uuid = info.uuid;
self.enabled = info.is_streaming_enabled;
self.serialNumber = info.serial_number;
self.softwareVersion = info.combined_software_version;
self.detectors = info.detectors;
self.type = info.type;
self.nexusTalkHost = info.direct_nexustalk_host;
self.apiHost = info.nexus_api_http_server;
});
} catch(error) {
error.status = error.response && error.response.status;
self.log.error('Error fetching cameras - ' + error.status);
}
}
async toggleActive(enabled) {

@@ -155,3 +180,3 @@ let self = this;

async handleSnapshotRequest(request, callback) {
handleSnapshotRequest(request, callback) {
let self = this;

@@ -162,11 +187,9 @@ let query = querystring.stringify({

});
try {
let response = await self.api.sendRequest(self.apiHost, '/get_image?' + query, 'GET');
callback(undefined, response);
} catch(error) {
error.status = error.response && error.response.status;
if (error.status != 404) {
self.log.error('Error getting image - ' + error.status);
}
}
self.api.sendPromiseRequest(self.apiHost, '/get_image?' + query, 'GET')
.then((response) => {
callback(undefined, response);
})
.catch((err) => {
callback(err);
});
}

@@ -173,0 +196,0 @@

{
"name": "homebridge-nest-cam2",
"version": "1.1.0",
"version": "1.1.1",
"description": "Nest cam plugin for homebridge: https://homebridge.io/",

@@ -5,0 +5,0 @@ "license": "ISC",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc