homebridge-syntex-webhooks
Advanced tools
Comparing version 1.0.5-b1 to 1.0.5-b10
152
index.js
@@ -85,4 +85,49 @@ var request = require('request'); | ||
if(err) | ||
{ | ||
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Storage.json konnte nicht geladen werden! (err)", err); | ||
} | ||
else | ||
{ | ||
log('\x1b[32m%s\x1b[0m', "[SUCCESS]", "Keine Fehler beim Laden! (err)"); | ||
} | ||
if(obj) | ||
{ | ||
{ | ||
log('\x1b[32m%s\x1b[0m', "[SUCCESS]", "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; | ||
@@ -103,3 +148,3 @@ | ||
} | ||
else | ||
else if(!urlParams.type) | ||
{ | ||
@@ -133,29 +178,2 @@ obj.devices[i].value = urlParams.value; | ||
} | ||
else | ||
{ | ||
log('\x1b[31m%s\x1b[0m', "[ERROR 1]", "Storage.json konnte nicht geladen werden!"); | ||
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!"); | ||
} | ||
}); | ||
} | ||
@@ -196,5 +214,5 @@ for(var i = 0; i < accessories.length; i++) | ||
if(err) | ||
if(obj && obj.devices) | ||
{ | ||
log('\x1b[31m%s\x1b[0m', "[ERROR 2]", "Storage.json konnte nicht geladen werden!"); | ||
log(obj.devices); | ||
} | ||
@@ -210,3 +228,3 @@ }); | ||
if(obj) | ||
if(obj && !err) | ||
{ | ||
@@ -250,3 +268,3 @@ var found = false; | ||
{ | ||
log('\x1b[31m%s\x1b[0m', "[ERROR 3]", "Storage.json konnte nicht geladen werden!"); | ||
log('\x1b[31m%s\x1b[0m', "[ERROR]", "Storage.json konnte nicht geladen werden!"); | ||
} | ||
@@ -353,3 +371,2 @@ }); | ||
} | ||
/* | ||
@@ -359,11 +376,8 @@ else if(this.type === "occupancy") | ||
this.service = new Service.OccupancySensor(this.name); | ||
this.changeHandler = (function(newState) { | ||
this.changeHandler = (function(newState) | ||
{ | ||
this.service.getCharacteristic(Characteristic.OccupancyDetected).updateValue(newState ? Characteristic.OccupancyDetected.OCCUPANCY_DETECTED : Characteristic.OccupancyDetected.OCCUPANCY_NOT_DETECTED, undefined, CONTEXT_FROM_WEBHOOK); | ||
if (this.autoRelease) { | ||
setTimeout(function() { | ||
this.storage.setItemSync("http-webhook-" + this.id, false); | ||
this.service.getCharacteristic(Characteristic.OccupancyDetected).updateValue(Characteristic.OccupancyDetected.OCCUPANCY_NOT_DETECTED, undefined, CONTEXT_FROM_TIMEOUTCALL); | ||
}.bind(this), this.autoReleaseTime); | ||
} | ||
}).bind(this); | ||
this.service.getCharacteristic(Characteristic.OccupancyDetected).on('get', this.getState.bind(this)); | ||
@@ -374,6 +388,9 @@ } | ||
this.service = new Service.SmokeSensor(this.name); | ||
this.changeHandler = (function(newState) { | ||
this.changeHandler = (function(newState) | ||
{ | ||
log("Change HomeKit state for smoke sensor to '%s'.", newState); | ||
this.service.getCharacteristic(Characteristic.SmokeDetected).updateValue(newState ? Characteristic.SmokeDetected.SMOKE_DETECTED : Characteristic.SmokeDetected.SMOKE_NOT_DETECTED, undefined, CONTEXT_FROM_WEBHOOK); | ||
}).bind(this); | ||
this.service.getCharacteristic(Characteristic.SmokeDetected).on('get', this.getState.bind(this)); | ||
@@ -384,6 +401,9 @@ } | ||
this.service = new Service.AirQualitySensor(this.name); | ||
this.changeHandler = (function(newState) { | ||
this.changeHandler = (function(newState) | ||
{ | ||
log("Change HomeKit value for air quality sensor to '%s'.", newState); | ||
this.service.getCharacteristic(Characteristic.AirQuality).updateValue(newState, undefined, CONTEXT_FROM_WEBHOOK); | ||
}).bind(this); | ||
this.service.getCharacteristic(Characteristic.AirQuality).on('get', this.getState.bind(this)); | ||
@@ -400,3 +420,3 @@ } | ||
if(obj) | ||
if(obj && !err) | ||
{ | ||
@@ -450,2 +470,12 @@ for(var i = 0; i < obj.devices.length; i++) | ||
} | ||
/* | ||
else if(this.type === "smoke") | ||
{ | ||
callback(null, state ? Characteristic.SmokeDetected.SMOKE_DETECTED : Characteristic.SmokeDetected.SMOKE_NOT_DETECTED); | ||
} | ||
else if(this.type === "occupancy") | ||
{ | ||
callback(null, state ? Characteristic.OccupancyDetected.OCCUPANCY_DETECTED : Characteristic.OccupancyDetected.OCCUPANCY_NOT_DETECTED); | ||
} | ||
*/ | ||
else if(this.type === "light") | ||
@@ -462,13 +492,2 @@ { | ||
}); | ||
/* | ||
else if(this.type === "smoke") | ||
{ | ||
callback(null, state ? Characteristic.SmokeDetected.SMOKE_DETECTED : Characteristic.SmokeDetected.SMOKE_NOT_DETECTED); | ||
} | ||
else if(this.type === "occupancy") | ||
{ | ||
callback(null, state ? Characteristic.OccupancyDetected.OCCUPANCY_DETECTED : Characteristic.OccupancyDetected.OCCUPANCY_NOT_DETECTED); | ||
} | ||
*/ | ||
}; | ||
@@ -517,5 +536,4 @@ | ||
if(obj) | ||
if(obj && !err) | ||
{ | ||
for(var i = 0; i < obj.devices.length; i++) | ||
@@ -559,5 +577,14 @@ { | ||
if(!powerOn) | ||
{ | ||
urlToCall = this.offURL; | ||
urlMethod = this.offMethod; | ||
urlBody = this.offBody; | ||
urlForm = this.offForm; | ||
urlHeaders = this.offHeaders; | ||
} | ||
this.storage.load('storage', (err, obj) => { | ||
if(obj) | ||
if(obj && !err) | ||
{ | ||
@@ -606,11 +633,2 @@ var found = false; | ||
if(!powerOn) | ||
{ | ||
urlToCall = this.offURL; | ||
urlMethod = this.offMethod; | ||
urlBody = this.offBody; | ||
urlForm = this.offForm; | ||
urlHeaders = this.offHeaders; | ||
} | ||
if(urlToCall != "") | ||
@@ -617,0 +635,0 @@ { |
{ | ||
"name": "homebridge-syntex-webhooks", | ||
"version": "1.0.5-b1", | ||
"version": "1.0.5-b10", | ||
"description": "A webhook plugin for HTTP devices", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
31379
561