homebridge-syntex-webhooks
Advanced tools
Comparing version 2.0.7-b2 to 2.0.7-b20
105
index.js
@@ -57,3 +57,3 @@ var request = require('request'); | ||
{ | ||
var Light = new SynTexWebHookSwitchAccessory(this.lights[i]); | ||
var Light = new SynTexWebHookStripeRGBAccessory(this.lights[i]); | ||
accessories.push(Light); | ||
@@ -192,3 +192,2 @@ } | ||
this.mac = sensorConfig["mac"]; | ||
this.id = sensorConfig["id"]; | ||
this.name = sensorConfig["name"]; | ||
@@ -377,3 +376,2 @@ this.type = sensorConfig["type"]; | ||
this.type = switchConfig["type"]; | ||
this.id = switchConfig["id"]; | ||
this.name = switchConfig["name"]; | ||
@@ -499,3 +497,2 @@ this.onURL = switchConfig["on_url"] || ""; | ||
this.type = switchConfig["type"]; | ||
this.id = switchConfig["id"]; | ||
this.name = switchConfig["name"]; | ||
@@ -515,2 +512,3 @@ this.onURL = switchConfig["on_url"] || ""; | ||
/* | ||
this.changeHandler = (function(newState) | ||
@@ -521,5 +519,8 @@ { | ||
}).bind(this); | ||
*/ | ||
this.service.getCharacteristic(Characteristic.On).on('get', this.getState.bind(this)).on('set', this.setState.bind(this)); | ||
this.service.addCharacteristic(new Characteristic.Hue()).on('get', this.getHue.bind(this)).on('set', this.setHue.bind(this)); | ||
this.service.addCharacteristic(new Characteristic.Brightness())/*.on('get', this.getBrightness.bind(this)).on('set', this.setBrightness.bind(this))*/; | ||
this.service.addCharacteristic(new Characteristic.Hue())/*.on('get', this.getHue.bind(this))*/.on('set', this.setHue.bind(this)); | ||
this.service.addCharacteristic(new Characteristic.Saturation())/*.on('get', this.getSaturation.bind(this)).on('set', this.setSaturation.bind(this))*/; | ||
} | ||
@@ -539,2 +540,27 @@ | ||
state = (res == 'true' || res); | ||
log('\x1b[36m%s\x1b[0m', "[READ]", "HomeKit Status für '" + name + "' ist '" + state + "'"); | ||
callback(null, state); | ||
}); | ||
}; | ||
SynTexWebHookStripeRGBAccessory.prototype.setState = function(powerOn, callback, context) | ||
{ | ||
callback(null); | ||
}; | ||
SynTexWebHookStripeRGBAccessory.prototype.getHue = function(callback) | ||
{ | ||
var device = { | ||
mac: this.mac, | ||
name: this.name | ||
}; | ||
var name = this.name; | ||
var mac = this.mac; | ||
readDevice(device).then(function(res) { | ||
state = 210; | ||
@@ -548,2 +574,69 @@ | ||
SynTexWebHookStripeRGBAccessory.prototype.setHue = function(level, callback) | ||
{ | ||
log("LEVEL", level); | ||
var h = level, s = 100, l = 100; | ||
var r, g, b; | ||
s /= 100; | ||
l /= 100; | ||
let c = (1 - Math.abs(2 * l - 1)) * s, | ||
x = c * (1 - Math.abs((h / 60) % 2 - 1)), | ||
m = l - c/2, | ||
r = 0, | ||
g = 0, | ||
b = 0; | ||
if (0 <= h && h < 60) { | ||
r = c; g = x; b = 0; | ||
} else if (60 <= h && h < 120) { | ||
r = x; g = c; b = 0; | ||
} else if (120 <= h && h < 180) { | ||
r = 0; g = c; b = x; | ||
} else if (180 <= h && h < 240) { | ||
r = 0; g = x; b = c; | ||
} else if (240 <= h && h < 300) { | ||
r = x; g = 0; b = c; | ||
} else if (300 <= h && h < 360) { | ||
r = c; g = 0; b = x; | ||
} | ||
r = Math.round((r + m) * 255); | ||
g = Math.round((g + m) * 255); | ||
b = Math.round((b + m) * 255); | ||
log('R:', r); | ||
log('G:', g); | ||
log('B:', b); | ||
var theRequest = { | ||
method : "GET", | ||
url : "http://192.168.188.155/color?r=" + r + "&g=" + g + "&b=" + b, | ||
timeout : 5000 | ||
}; | ||
request(theRequest, (function(err, response, body) | ||
{ | ||
var statusCode = response && response.statusCode ? response.statusCode : -1; | ||
log("Anfrage zu '%s' wurde mit dem Status Code '%s' beendet: '%s'", 'URL', statusCode, body, err); | ||
if(!err && statusCode == 200) | ||
{ | ||
callback(null); | ||
} | ||
else | ||
{ | ||
callback(err || new Error("Request to 'URL' was not succesful.")); | ||
} | ||
}).bind(this)); | ||
}; | ||
SynTexWebHookStripeRGBAccessory.prototype.getServices = function() | ||
{ | ||
return [this.service]; | ||
}; | ||
async function updateDevice(obj) | ||
@@ -550,0 +643,0 @@ { |
{ | ||
"name": "homebridge-syntex-webhooks", | ||
"version": "2.0.7-b2", | ||
"version": "2.0.7-b20", | ||
"description": "A webhook plugin for HTTP devices", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
28192
581