New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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

to
1.0.5

index-old.js

419

index.js

@@ -19,15 +19,16 @@ var request = require('request');

var config;
var storage;
function SynTexWebHookPlatform(slog, sconfig, api)
{
config = store(api.user.storagePath());
log = slog;
var url = require('url');
this.sensors = sconfig["sensors"] || [];
this.switches = sconfig["switches"] || [];
this.cacheDirectory = sconfig["cache_directory"] || "./.node-persist/storage";
this.cacheDirectory = sconfig["cache_directory"] || "./SynTex";
this.port = sconfig["port"] || 1710;
this.storage = store(this.cacheDirectory);
log = slog;
config = store(api.user.storagePath());
storage = store(this.cacheDirectory);
}

@@ -43,3 +44,3 @@

{
var Sensor = new SynTexWebHookSensorAccessory(this.sensors[i], this.storage);
var Sensor = new SynTexWebHookSensorAccessory(this.sensors[i]);
accessories.push(Sensor);

@@ -50,3 +51,3 @@ }

{
var Switch = new SynTexWebHookSwitchAccessory(this.switches[i], this.storage);
var Switch = new SynTexWebHookSwitchAccessory(this.switches[i]);
accessories.push(Switch);

@@ -86,96 +87,20 @@ }

{
this.storage.load('storage', (err, obj) => {
if(err)
{
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Storage.json konnte nicht geladen werden! (err)", err);
}
else
{
log('\x1b[31m%s\x1b[0m', "[SUCCESS]", "Keine Fehler beim Laden! (err)");
}
if(urlParams.type)
{
var device = {
mac: urlParams.mac,
value: urlParams.value,
type: urlParams.type
};
}
else
{
var device = {
mac: urlParams.mac,
value: urlParams.value
};
}
updateDevice(device).then(function(res) {
if(obj)
{
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Keine Fehler beim Laden! (obj)");
}
else
{
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Storage.json konnte nicht geladen werden! (obj)");
}
if(!obj && !err)
{
log('\x1b[33m%s\x1b[0m', "[INFO]", "Storage.json wurde ohne Inhalt geladen!");
if(urlParams.type)
{
var device = {
id: "storage",
devices: [{mac: urlParams.mac, value: urlParams.value, type: urlParams.type}]
};
}
else
{
var device = {
id: "storage",
devices: [{mac: urlParams.mac, value: urlParams.value}]
};
}
this.storage.add(device, (err) => {
if(err)
{
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Storage.json konnte nicht aktualisiert werden!");
}
});
}
else if(obj && !err)
{
var found = false;
for(var i = 0; i < obj.devices.length; i++)
{
if(obj.devices[i].mac === urlParams.mac)
{
if(urlParams.type && obj.devices[i].type)
{
if(urlParams.type == obj.devices[i].type)
{
obj.devices[i].value = urlParams.value;
found = true;
}
}
else if(!urlParams.type)
{
obj.devices[i].value = urlParams.value;
found = true;
}
}
}
if(found == false)
{
if(urlParams.type)
{
obj.devices[obj.devices.length] = {mac: urlParams.mac, value: urlParams.value, type: urlParams.type};
}
else
{
obj.devices[obj.devices.length] = {mac: urlParams.mac, value: urlParams.value};
}
}
this.storage.add(obj, (err) => {
if(err)
{
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Storage.json konnte nicht aktualisiert werden!");
}
});
}
for(var i = 0; i < accessories.length; i++)

@@ -214,7 +139,2 @@ {

}
if(obj && obj.devices)
{
log(obj.devices);
}
});

@@ -227,45 +147,32 @@

{
this.storage.load('storage', (err, obj) => {
if(obj && !err)
{
var found = false;
for(var i = 0; i < obj.devices.length; i++)
{
if(obj.devices[i].mac === urlParams.mac)
{
if(urlParams.type && obj.devices[i].type)
{
if(urlParams.type == obj.devices[i].type)
{
response.write(obj.devices[i].value.toString());
response.end();
found = true;
}
}
else
{
response.write(obj.devices[i].value.toString());
response.end();
found = true;
}
}
}
if(!found)
{
response.write("Es wurde kein passendes Gerät gefunden!");
response.end();
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Es wurde kein passendes Gerät gefunden! (" + urlParams.mac + ")");
}
}
if(urlParams.type)
{
var device = {
mac: urlParams.mac,
type: urlParams.type
};
}
else
{
var device = {
mac: urlParams.mac
};
}
readDevice(device).then(function(res) {
if(err || !obj)
if(!res)
{
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Storage.json konnte nicht geladen werden!");
response.write("Es wurde kein passendes Gerät gefunden!");
response.end();
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Es wurde kein passendes Gerät gefunden! (" + urlParams.mac + ")");
}
else
{
response.write(res);
response.end();
log('\x1b[36m%s\x1b[0m', "[READ]", "HomeKit Status für '" + urlParams.mac + "' ist '" + res + "'");
}
});

@@ -290,3 +197,3 @@ }

function SynTexWebHookSensorAccessory(sensorConfig, storage)
function SynTexWebHookSensorAccessory(sensorConfig)
{

@@ -297,3 +204,2 @@ this.mac = sensorConfig["mac"];

this.type = sensorConfig["type"];
this.storage = storage;

@@ -413,46 +319,31 @@ if(this.type === "contact")

SynTexWebHookSensorAccessory.prototype.getState = function(callback)
{
var state = null;
{
if(this.type == 'rain' || this.type == 'light' || this.type == 'temperature' || this.type == 'humidity')
{
var device = {
mac: this.mac,
type: this.type,
name: this.name
};
}
else
{
var device = {
mac: this.mac,
name: this.name
};
}
this.storage.load('storage', (err, obj) => {
if(obj && !err)
{
for(var i = 0; i < obj.devices.length; i++)
{
if(obj.devices[i].mac === this.mac)
{
if(obj.devices[i].type)
{
if(obj.devices[i].type == this.type)
{
state = obj.devices[i].value;
if(state == 'true' || state == 'false')
{
state = (state === 'true');
}
}
}
else
{
state = obj.devices[i].value;
if(state == 'true' || state == 'false')
{
state = (state === 'true');
}
}
}
}
}
var name = this.name;
var mac = this.mac;
readDevice(device).then(function(state) {
if(err || !obj)
if(!state)
{
log('\x1b[31m%s\x1b[0m', "[ERROR 4]", "Storage.json konnte nicht geladen werden!");
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Es wurde kein passendes Gerät gefunden! (" + mac + ")");
}
if(state == null)
else
{
state = false;
log('\x1b[36m%s\x1b[0m', "[READ]", "HomeKit Status für '" + name + "' ist '" + state + "'");
}

@@ -486,4 +377,2 @@

}
log('\x1b[36m%s\x1b[0m', "[READ]", "HomeKit Status für '" + this.name + "' ist '" + state + "' ( " + this.mac + " )");
});

@@ -497,4 +386,3 @@ };

function SynTexWebHookSwitchAccessory(switchConfig, storage)
function SynTexWebHookSwitchAccessory(switchConfig)
{

@@ -515,3 +403,2 @@ this.mac = switchConfig["mac"];

this.offHeaders = switchConfig["off_headers"] || "{}";
this.storage = storage;

@@ -531,35 +418,17 @@ this.service = new Service.Switch(this.name);

{
var state = null;
var device = {
mac: this.mac,
name: this.name
};
this.storage.load('storage', (err, obj) => {
if(obj && !err)
{
for(var i = 0; i < obj.devices.length; i++)
{
if(obj.devices[i].mac === this.mac)
{
state = obj.devices[i].value;
if(state == 'true' || state == 'false')
{
state = (state === 'true');
}
}
}
}
var name = this.name;
var mac = this.mac;
readDevice(device).then(function(res) {
if(err || !obj)
{
log('\x1b[31m%s\x1b[0m', "[ERROR 5]", "Storage.json konnte nicht geladen werden!");
}
state = (res == 'true' || res);
if(state == null)
{
state = false;
}
log('\x1b[36m%s\x1b[0m', "[READ]", "HomeKit Status für '" + name + "' ist '" + state + "'");
callback(null, state);
log('\x1b[36m%s\x1b[0m', "[READ]", "HomeKit Status für '" + this.name + "' ist '" + state + "' ( " + this.mac + " )");
});

@@ -585,47 +454,8 @@ };

this.storage.load('storage', (err, obj) => {
if(obj && !err)
{
var found = false;
var device = {
mac: this.mac,
value: powerOn
};
for(var i = 0; i < obj.devices.length; i++)
{
if(obj.devices[i].mac === this.mac)
{
obj.devices[i].value = powerOn;
found = true;
}
}
if(found == false)
{
obj.devices[obj.devices.length] = {mac: this.mac, value: powerOn};
}
this.storage.add(obj, (err) => {
if(err)
{
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Storage.json konnte nicht aktualisiert werden!");
}
});
}
else
{
var device = {
id: "storage",
devices: [{mac: this.mac, value: powerOn}]
};
this.storage.add(device, (err) => {
if(err)
{
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Storage.json konnte nicht aktualisiert werden!");
}
});
}
});
updateDevice(device);

@@ -679,2 +509,63 @@ if(urlToCall != "")

return [this.service];
};
};
async function updateDevice(obj)
{
return new Promise(resolve => {
if(obj.type)
{
var device = {
id: obj.mac + '-' + obj.type[0].toUpperCase(),
value: obj.value,
type: obj.type
};
}
else
{
var device = {
id: obj.mac,
value: obj.value
};
}
storage.add(device, (err) => {
if(err)
{
log('\x1b[31m%s\x1b[0m', "[ERROR]", obj.mac + ".json konnte nicht aktualisiert werden!");
resolve(false);
}
else
{
resolve(true);
}
});
});
}
async function readDevice(obj)
{
return new Promise(resolve => {
var id = obj.mac;
if(obj.type)
{
id += '-' + obj.type[0].toUpperCase();
}
storage.load(id, (err, device) => {
if(device && !err)
{
resolve(device.value);
}
if(err || !device)
{
resolve(false);
}
});
});
}
{
"name": "homebridge-syntex-webhooks",
"version": "1.0.5-b9",
"version": "1.0.5",
"description": "A webhook plugin for HTTP devices",

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