homebridge-syntex-webhooks
Advanced tools
Comparing version 1.0.5-b32 to 1.0.5-b33
128
index.js
@@ -5,4 +5,2 @@ var request = require('request'); | ||
var store = require('json-fs-store'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var Service, Characteristic; | ||
@@ -26,11 +24,11 @@ | ||
{ | ||
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"] || "./.node-persist/devices"; | ||
this.port = sconfig["port"] || 1710; | ||
log = slog; | ||
config = store(api.user.storagePath()); | ||
storage = store(this.cacheDirectory); | ||
@@ -146,25 +144,31 @@ } | ||
{ | ||
var id = urlParams.mac; | ||
if(urlParams.type) | ||
{ | ||
id += '-' + urlParams.type[0].toUpperCase(); | ||
var device = { | ||
mac: urlParams.mac, | ||
type: urlParams.type | ||
}; | ||
} | ||
else | ||
{ | ||
var device = { | ||
mac: urlParams.mac | ||
}; | ||
} | ||
storage.load(id, (err, obj) => { | ||
if(obj && !err) | ||
{ | ||
response.write(obj.value); | ||
readDevice(device).then(function(res) { | ||
if(!res) | ||
{ | ||
response.write("Es wurde kein passendes Gerät gefunden!"); | ||
response.end(); | ||
log('\x1b[36m%s\x1b[0m', "[READ]", "HomeKit Status für '" + urlParams.mac + "' ist '" + obj.value + "'"); | ||
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Es wurde kein passendes Gerät gefunden! (" + urlParams.mac + ")"); | ||
} | ||
if(err || !obj) | ||
else | ||
{ | ||
response.write("Es wurde kein passendes Gerät gefunden!"); | ||
response.write(res); | ||
response.end(); | ||
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Es wurde kein passendes Gerät gefunden! (" + urlParams.mac + ")"); | ||
log('\x1b[36m%s\x1b[0m', "[READ]", "HomeKit Status für '" + urlParams.mac + "' ist '" + res + "'"); | ||
} | ||
@@ -310,29 +314,26 @@ }); | ||
SynTexWebHookSensorAccessory.prototype.getState = function(callback) | ||
{ | ||
var state = null; | ||
var id = this.mac; | ||
{ | ||
if(this.type == 'rain' || this.type == 'light' || this.type == 'temperature' || this.type == 'humidity') | ||
{ | ||
id += '-' + this.type[0].toUpperCase(); | ||
var device = { | ||
mac: this.mac, | ||
type: this.type | ||
}; | ||
} | ||
storage.load(id, (err, obj) => { | ||
if(obj && !err) | ||
{ | ||
state = obj.value; | ||
log('\x1b[36m%s\x1b[0m', "[READ]", "HomeKit Status für '" + this.name + "' ist '" + state + "' ( " + this.mac + " )"); | ||
} | ||
else | ||
{ | ||
var device = { | ||
mac: this.mac | ||
}; | ||
} | ||
readDevice(device).then(function(state) { | ||
if(err || !obj) | ||
if(!state) | ||
{ | ||
log('\x1b[31m%s\x1b[0m', "[ERROR]", this.mac + ".json konnte nicht geladen werden!"); | ||
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Es wurde kein passendes Gerät gefunden! (" + this.mac + ")"); | ||
} | ||
if(state == null) | ||
else | ||
{ | ||
state = false; | ||
log('\x1b[36m%s\x1b[0m', "[READ]", "HomeKit Status für '" + this.name + "' ist '" + state + "'"); | ||
} | ||
@@ -365,3 +366,3 @@ | ||
callback(null, state); | ||
} | ||
} | ||
}); | ||
@@ -406,21 +407,15 @@ }; | ||
{ | ||
var state = null; | ||
storage.load(this.mac, (err, obj) => { | ||
if(obj && !err) | ||
{ | ||
state = obj.value; | ||
log('\x1b[36m%s\x1b[0m', "[READ]", "HomeKit Status für '" + this.name + "' ist '" + state + "' ( " + this.mac + " )"); | ||
} | ||
var device = { | ||
mac: this.mac | ||
}; | ||
readDevice(device).then(function(state) { | ||
if(err || !obj) | ||
if(!state) | ||
{ | ||
log('\x1b[31m%s\x1b[0m', "[ERROR]", this.mac + ".json konnte nicht geladen werden!"); | ||
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Es wurde kein passendes Gerät gefunden! (" + this.mac + ")"); | ||
} | ||
if(state == null) | ||
else | ||
{ | ||
state = false; | ||
log('\x1b[36m%s\x1b[0m', "[READ]", "HomeKit Status für '" + this.name + "' ist '" + state + "'"); | ||
} | ||
@@ -544,18 +539,23 @@ | ||
storage.load(obj.mac, (err, obj) => { | ||
var id = obj.mac; | ||
if(obj.type) | ||
{ | ||
id += '-' + obj.type[0].toUpperCase(); | ||
} | ||
if(obj && !err) | ||
storage.load(id, (err, device) => { | ||
if(device && !err) | ||
{ | ||
response.write(obj.value); | ||
response.end(); | ||
resolve(device.value); | ||
log('\x1b[36m%s\x1b[0m', "[READ]", "HomeKit Status für '" + this.name + "' ist '" + state + "' ( " + this.mac + " )"); | ||
log('\x1b[36m%s\x1b[0m', "[READ]", "HomeKit Status für '" + id + "' ist '" + device.value + "'"); | ||
} | ||
if(err || !obj) | ||
if(err || !device) | ||
{ | ||
response.write("Es wurde kein passendes Gerät gefunden!"); | ||
response.end(); | ||
resolve(false); | ||
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Es wurde kein passendes Gerät gefunden! (" + urlParams.mac + ")"); | ||
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Es wurde kein passendes Gerät gefunden! (" + id + ")"); | ||
} | ||
@@ -562,0 +562,0 @@ }); |
{ | ||
"name": "homebridge-syntex-webhooks", | ||
"version": "1.0.5-b32", | ||
"version": "1.0.5-b33", | ||
"description": "A webhook plugin for HTTP devices", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
56845
1113
1