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

homebridge-syntex-webhooks

Package Overview
Dependencies
Maintainers
1
Versions
1176
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

homebridge-syntex-webhooks - npm Package Compare versions

Comparing version 2.3.9-b5 to 2.3.9-b6

2

package.json
{
"name": "homebridge-syntex-webhooks",
"version": "2.3.9-b5",
"version": "2.3.9-b6",
"description": "A webhook plugin for HTTP devices",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -71,141 +71,92 @@ const convert = require('color-convert');

{
return new Promise(resolve => {
return new Promise((resolve) => {
var counter = 0, finished = 0, success = 0;
var promiseArray = [];
for(let i = 0; i < service.options.requests.length; i++)
if(Array.isArray(service.options.requests))
{
if(service.options.requests[i].trigger != null && state.value != null
&& (state.value && service.options.requests[i].trigger.toLowerCase() == 'on'
|| !state.value && service.options.requests[i].trigger.toLowerCase() == 'off'
|| service.options.requests[i].trigger.toLowerCase() == 'color'
|| service.options.requests[i].trigger.toLowerCase() == 'dimmer'))
for(const request of service.options.requests)
{
counter++;
}
}
for(let i = 0; i < service.options.requests.length; i++)
{
if(service.options.requests[i].trigger != null && state.value != null)
{
var urlMethod = service.options.requests[i].method || '';
var urlToCall = service.options.requests[i].url || '';
var urlBody = service.options.requests[i].body || '';
var urlForm = service.options.requests[i].form || '';
var urlHeaders = service.options.requests[i].body || '{}';
if(urlMethod != '' && urlToCall != '')
if(request.type != null && request.url != null)
{
var theRequest = {
timeout : 5000
};
var type = request.type.toLowerCase(), url = null;
try
if((type == 'on' && state.value == true) || (type == 'off' && state.value == false))
{
theRequest.headers = JSON.parse(urlHeaders);
url = request.url;
}
catch(e)
else if(type == 'dimmer')
{
this.logger.log('error', service.id, service.letters, 'Request Headers %json_parse_error%! ( ' + theRequest.headers + ')', e);
url = request.url + state.brightness;
}
else if(type == 'color')
{
var colors = [state.hue, state.saturation, state.brightness];
if(urlMethod === 'POST' || urlMethod === 'PUT')
{
if(urlForm)
if(service.options.spectrum == 'RGB')
{
try
{
theRequest.data = JSON.parse(urlForm);
}
catch(e)
{
this.logger.log('error', service.id, service.letters, 'Request Form %json_parse_error%! ( ' + theRequest.headers + ')', e);
}
colors = convert.hsv.rgb([state.hue, state.saturation, state.brightness]);
}
else if(urlBody)
if(!state.value)
{
theRequest.data = urlBody;
colors[2] = 0;
}
url = request.url + colors.join(',');
}
else if(state[type] != null)
{
url = request.url + (request.url.includes('?') ? '&' : '?') + request.type + '=' + state[request.type];
}
if(state.value && service.options.requests[i].trigger.toLowerCase() == 'on'
|| !state.value && service.options.requests[i].trigger.toLowerCase() == 'off')
if(url != null)
{
this.RequestManager.fetch(urlToCall, theRequest).then(function(response) {
const requestURL = url;
var options = {
method : request.method || 'GET',
body : request.body || '',
form : request.form || '',
headers : request.headers || '{}',
timeout : request.timeout || 5000
};
if(response.data != null)
{
success++;
}
this.logger.log(response.data != null ? 'success' : 'error', service.id, service.letters, '[' + service.name + '] %request_result[0]% [' + this.url + '] %request_result[1]% [' + (response.status || -1)+ '] %request_result[2]%: [' + (response.data || '') + ']', response.error || '');
try
{
options.headers = JSON.parse(options.headers);
}
catch(e)
{
this.logger.log('error', service.id, service.letters, 'Request Headers %json_parse_error%! ( ' + options.headers + ')', e);
}
finished++;
if(finished >= counter)
if(options.method == 'POST' || options.method == 'PUT')
{
if(options.form)
{
if(service.setConnectionState != null)
try
{
service.setConnectionState(success > 0, null, true);
options.data = JSON.parse(options.form);
}
if(success == 0 && this.TypeManager.letterToType(service.letters) == 'relais')
catch(e)
{
resolve(false);
this.logger.log('error', service.id, service.letters, 'Request Form %json_parse_error%! ( ' + options.form + ')', e);
}
else
{
resolve(true);
}
}
}.bind({ url : urlToCall, logger : this.logger, TypeManager : this.TypeManager }));
}
else if(service.options.requests[i].trigger.toLowerCase() == 'color')
{
var colors = [state.hue, state.saturation, state.brightness];
if(service.options.spectrum == 'RGB')
{
colors = convert.hsv.rgb([state.hue, state.saturation, state.brightness]);
}
this.RequestManager.fetch(urlToCall + colors[0] + ',' + colors[1] + ',' + (state.value ? colors[2] : 0), theRequest).then(function(response) {
this.logger.log(response.data != null ? 'success' : 'error', service.id, service.letters, '[' + service.name + '] %request_result[0]% [' + this.url + '] %request_result[1]% [' + (response.status || -1) + '] %request_result[2]%: [' + (response.data || '') + ']', response.error || '');
finished++;
if(finished >= counter)
else if(options.body)
{
if(service.setConnectionState != null)
{
service.setConnectionState(success > 0, null, true);
}
resolve(true);
options.data = options.body;
}
}.bind({ url : urlToCall + colors[0] + ',' + colors[1] + ',' + (state.value ? colors[2] : 0), logger : this.logger }));
}
else if(service.options.requests[i].trigger.toLowerCase() == 'dimmer')
{
this.RequestManager.fetch(urlToCall + state.brightness, theRequest).then(function(response) {
}
this.logger.log(response.data != null ? 'success' : 'error', service.id, service.letters, '[' + service.name + '] %request_result[0]% [' + this.url + '] %request_result[1]% [' + (response.status || -1) + '] %request_result[2]%: [' + (response.data || '') + ']', response.error || '');
promiseArray.push(new Promise((callback) => {
finished++;
if(finished >= counter)
{
if(service.setConnectionState != null)
{
service.setConnectionState(success > 0, null, true);
}
this.RequestManager.fetch(requestURL, options).then((response) => {
this.logger.log(response.data != null ? 'success' : 'error', service.id, service.letters, '[' + service.name + '] %request_result[0]% [' + requestURL + '] %request_result[1]% [' + (response.status || -1) + '] %request_result[2]%: [' + (response.data || '') + ']', response.error || '');
resolve(true);
}
}.bind({ url : urlToCall + state.brightness, logger : this.logger }));
callback(response.data != null);
});
}));
}

@@ -215,4 +166,18 @@ }

}
if(promiseArray.length > 0)
{
Promise.all(promiseArray).then((result) => {
if(counter == 0)
var type = this.TypeManager.letterToType(service.letters);
if(service.setConnectionState != null)
{
service.setConnectionState(result.includes(true), null, true);
}
resolve(type != 'relais' || result.includes(true));
});
}
else
{

@@ -219,0 +184,0 @@ resolve(true);

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