Fix whitespace

This commit is contained in:
Sebastian Maier 2020-10-13 04:08:26 +02:00
parent 0155a5557e
commit 988d2ada35
2 changed files with 103 additions and 104 deletions

View File

@ -5,38 +5,37 @@ var colorOn = "\x1b[30;47m";
var colorOff = "\x1b[0m"; var colorOff = "\x1b[0m";
function SmartHomeNGConnection(platform, log, host, port) { function SmartHomeNGConnection(platform, log, host, port) {
this.log = log; this.log = log;
this.platform = platform; this.platform = platform;
this.connected = false; this.connected = false;
this.updateCallback = undefined; this.updateCallback = undefined;
this.tomonitor = []; this.tomonitor = [];
this.retryTimer = 10; this.retryTimer = 10;
this.shng_host = host; this.shng_host = host;
this.shng_port = port; this.shng_port = port;
} }
SmartHomeNGConnection.prototype.init = function () { SmartHomeNGConnection.prototype.init = function () {
var that = this; var that = this;
this.shng_ws = new WebSocketClient(); this.shng_ws = new WebSocketClient();
this.shng_ws.on('connect', function(connection) { this.shng_ws.on('connect', function(connection) {
that.log('[SmartHomeNGConnection] connected to server!'); that.log('[SmartHomeNGConnection] connected to server!');
that.connected = true; that.connected = true;
that.connection = connection; that.connection = connection;
that.idenfityMyself(); that.idenfityMyself();
that.startMonitoring(); that.startMonitoring();
connection.on('message', function(message) { that.receive(message); }); connection.on('message', function(message) { that.receive(message); });
connection.on('error', function(error) { connection.on('error', function(error) {
that.log(colorOn + '[SmartHomeNGConnection] WebSocket error: ' + error.toString() + colorOff) that.log(colorOn + '[SmartHomeNGConnection] WebSocket error: ' + error.toString() + colorOff)
}); });
connection.on('close', function(code, description) { connection.on('close', function(code, description) {
that.log(colorOn + '[SmartHomeNGConnection] Connection to smarthome lost, retrying in ' + that.retryTimer + ' seconds. ' + description + colorOff); that.log(colorOn + '[SmartHomeNGConnection] Connection to smarthome lost, retrying in ' + that.retryTimer + ' seconds. ' + description + colorOff);
that.connected = false; that.connected = false;
setTimeout(that.connect.bind(that), that.retryTimer * 1000); setTimeout(that.connect.bind(that), that.retryTimer * 1000);
}); });
}); });
this.shng_ws.on('connectFailed', function(errorDescription) { this.shng_ws.on('connectFailed', function(errorDescription) {
@ -49,13 +48,13 @@ SmartHomeNGConnection.prototype.init = function () {
} }
SmartHomeNGConnection.prototype.connect = function(host, ip) { SmartHomeNGConnection.prototype.connect = function(host, ip) {
this.log("[SmartHomeNGConnection] Connecting to SmartHomeNG @ " + this.shng_host); this.log("[SmartHomeNGConnection] Connecting to SmartHomeNG @ " + this.shng_host);
this.shng_ws.connect('ws://' + this.shng_host + ':' + this.shng_port + '/'); this.shng_ws.connect('ws://' + this.shng_host + ':' + this.shng_port + '/');
} }
SmartHomeNGConnection.prototype.receive = function(message) { SmartHomeNGConnection.prototype.receive = function(message) {
var msg = JSON.parse(message.utf8Data); var msg = JSON.parse(message.utf8Data);
//this.log(msg); //this.log(msg);
if (msg.items) { if (msg.items) {
for (int = 0; int < msg.items.length; int++) { for (int = 0; int < msg.items.length; int++) {
@ -91,7 +90,7 @@ SmartHomeNGConnection.prototype.idenfityMyself = function() {
} }
} }
SmartHomeNGConnection.prototype.startMonitoring = function() { SmartHomeNGConnection.prototype.startMonitoring = function() {
if (this.connected && this.tomonitor.length > 0) { if (this.connected && this.tomonitor.length > 0) {
var buffer = {}; var buffer = {};
this.log("[SmartHomeNGConnection] Start monitoring " + this.tomonitor); this.log("[SmartHomeNGConnection] Start monitoring " + this.tomonitor);
@ -105,6 +104,6 @@ SmartHomeNGConnection.prototype.startMonitoring = function() {
} }
module.exports = { module.exports = {
SmartHomeNGConnection: SmartHomeNGConnection SmartHomeNGConnection: SmartHomeNGConnection
} }

166
index.js
View File

@ -1,7 +1,7 @@
/***** /*****
* SmartHomeNG platform shim for use with nfarina's homebridge plugin system * SmartHomeNG platform shim for use with nfarina's homebridge plugin system
* This work has been inspired by the homebridge-knx platform shim. Credits to snowdd1 ! * This work has been inspired by the homebridge-knx platform shim. Credits to snowdd1 !
* *
*/ */
var Accessory, Service, Characteristic, UUIDGen; var Accessory, Service, Characteristic, UUIDGen;
@ -22,7 +22,7 @@ module.exports = function(homebridge) {
Service = homebridge.hap.Service; Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic; Characteristic = homebridge.hap.Characteristic;
UUIDGen = homebridge.hap.uuid; UUIDGen = homebridge.hap.uuid;
homebridge.registerPlatform("homebridge-smarthomeng", "SmartHomeNG", SmartHomeNGPlatform); homebridge.registerPlatform("homebridge-smarthomeng", "SmartHomeNG", SmartHomeNGPlatform);
} }
@ -32,26 +32,26 @@ function SmartHomeNGPlatform(log, config, api) {
this.config = config; this.config = config;
this.accessoriesCache = []; this.accessoriesCache = [];
this.supportedFunctions = ['onoff', 'brightness', 'hue', 'saturation', 'currentposition', 'targetposition', 'motiondetected']; this.supportedFunctions = ['onoff', 'brightness', 'hue', 'saturation', 'currentposition', 'targetposition', 'motiondetected'];
if (this.config["host"] != undefined) { if (this.config["host"] != undefined) {
this.shng_host = this.config["host"]; this.shng_host = this.config["host"];
} else { } else {
this.shng_host = "localhost"; this.shng_host = "localhost";
} }
if (this.config["port"] != undefined) { if (this.config["port"] != undefined) {
this.shng_port = this.config["port"]; this.shng_port = this.config["port"];
} else { } else {
this.shng_port = 2424; this.shng_port = 2424;
} }
var that = this; var that = this;
this.version = this.getVersion(); this.version = this.getVersion();
this.log("SmartHomeNG Platform Plugin Version " + this.version) this.log("SmartHomeNG Platform Plugin Version " + this.version)
this.shngcon = new SmartHomeNGConnection(this, this.log, this.shng_host, this.shng_port); this.shngcon = new SmartHomeNGConnection(this, this.log, this.shng_host, this.shng_port);
this.shngcon.updateCallback = this.update; this.shngcon.updateCallback = this.update;
if (api) { if (api) {
this.api = api; this.api = api;
this.api.on('didFinishLaunching', function() { this.api.on('didFinishLaunching', function() {
@ -63,7 +63,7 @@ function SmartHomeNGPlatform(log, config, api) {
var device = monitoring[i]; var device = monitoring[i];
if(tomonitor.indexOf(device.item) == -1) { if(tomonitor.indexOf(device.item) == -1) {
tomonitor.push(device.item); tomonitor.push(device.item);
} }
} }
this.shngcon.tomonitor = tomonitor; this.shngcon.tomonitor = tomonitor;
}.bind(this)); }.bind(this));
@ -85,27 +85,27 @@ function SmartHomeNGAccessory(log, config, shngcon) {
} }
SmartHomeNGPlatform.prototype = { SmartHomeNGPlatform.prototype = {
// Return our accessories to homebridge // Return our accessories to homebridge
accessories: function(callback) { accessories: function(callback) {
var that = this; var that = this;
var foundAccessories = []; var foundAccessories = [];
this.log("Building list of accessories"); this.log("Building list of accessories");
var configAccessories = this.config.accessories; var configAccessories = this.config.accessories;
for (var i = 0; i < configAccessories.length; i++) { for (var i = 0; i < configAccessories.length; i++) {
this.log("Parsing accessory: '" + configAccessories[i].name + "'."); this.log("Parsing accessory: '" + configAccessories[i].name + "'.");
var accessory = new SmartHomeNGAccessory(that.log, configAccessories[i], that.shngcon); var accessory = new SmartHomeNGAccessory(that.log, configAccessories[i], that.shngcon);
foundAccessories.push(accessory); foundAccessories.push(accessory);
} }
//this.log(foundAccessories) //this.log(foundAccessories)
this.accessoriesCache = foundAccessories; this.accessoriesCache = foundAccessories;
callback(foundAccessories); callback(foundAccessories);
}, },
update: function (item, value) { update: function (item, value) {
//this.log("CALLBACK: item " + item + " with value " + value); //this.log("CALLBACK: item " + item + " with value " + value);
for (var i = 0; i < monitoring.length; i++) { for (var i = 0; i < monitoring.length; i++) {
@ -127,14 +127,14 @@ SmartHomeNGPlatform.prototype = {
} }
SmartHomeNGAccessory.prototype = { SmartHomeNGAccessory.prototype = {
// Enumerate accessory services and characteristics // Enumerate accessory services and characteristics
getServices: function() { getServices: function() {
var that = this; var that = this;
var myServices = []; var myServices = [];
this.log("["+ this.name +"] Setting up services."); this.log("["+ this.name +"] Setting up services.");
// check if device type is set in config // check if device type is set in config
if (!this.config.type) { if (!this.config.type) {
this.log("Ignoring '" + this.name + "' because no device type found, make sure to have the 'type' parameter in your config.json !"); this.log("Ignoring '" + this.name + "' because no device type found, make sure to have the 'type' parameter in your config.json !");
@ -143,17 +143,17 @@ SmartHomeNGAccessory.prototype = {
// construct service and characteristics according to device type // construct service and characteristics according to device type
var serial = "unknown"; var serial = "unknown";
switch (this.config.type.toLowerCase()) { switch (this.config.type.toLowerCase()) {
// Lightbulb service // Lightbulb service
case 'fan': case 'fan':
myServices.push(this.getFanService(this.config)); myServices.push(this.getFanService(this.config));
serial = this.config.onoff; serial = this.config.onoff;
break; break;
case 'temperaturesensor': case 'temperaturesensor':
myServices.push(this.getTemperatureSensorService(this.config)); myServices.push(this.getTemperatureSensorService(this.config));
break; break;
case 'thermostat': case 'thermostat':
myServices.push(this.getThermostatService(this.config)); myServices.push(this.getThermostatService(this.config));
break; break;
@ -162,7 +162,7 @@ SmartHomeNGAccessory.prototype = {
myServices.push(this.getLightbulbService(this.config)); myServices.push(this.getLightbulbService(this.config));
serial = this.config.onoff; serial = this.config.onoff;
break; break;
case 'window': case 'window':
myServices.push(this.getWindowService(this.config)); myServices.push(this.getWindowService(this.config));
break; break;
@ -193,14 +193,14 @@ SmartHomeNGAccessory.prototype = {
myServices.push(this.getContactSensorService(this.config)); myServices.push(this.getContactSensorService(this.config));
serial = this.config.contactsensorstate; serial = this.config.contactsensorstate;
break; break;
// If no supported type is found warn user and return empty services // If no supported type is found warn user and return empty services
default: default:
this.log("Ignoring '" + this.name + "' because device type '" + this.config.type + "' is not supported !"); this.log("Ignoring '" + this.name + "' because device type '" + this.config.type + "' is not supported !");
return []; return [];
break; break;
} }
// device information service // device information service
var informationService = new Service.AccessoryInformation(); var informationService = new Service.AccessoryInformation();
informationService informationService
@ -208,18 +208,18 @@ SmartHomeNGAccessory.prototype = {
.setCharacteristic(Characteristic.Model, "SmartHomeNG device") .setCharacteristic(Characteristic.Model, "SmartHomeNG device")
.setCharacteristic(Characteristic.SerialNumber, serial); .setCharacteristic(Characteristic.SerialNumber, serial);
myServices.push(informationService); myServices.push(informationService);
return myServices; return myServices;
}, },
// Respond to identify request // Respond to identify request
identify: function(callback) { identify: function(callback) {
this.log("Identify request for '" + this.name + "'."); this.log("Identify request for '" + this.name + "'.");
callback(); callback();
}, },
/** Registering routines /** Registering routines
* *
*/ */
shngregister_int: function(name, shngitem, characteristic) { shngregister_int: function(name, shngitem, characteristic) {
this.log("[" + name + "] Registering callback for '" + shngitem + "'."); this.log("[" + name + "] Registering callback for '" + shngitem + "'.");
@ -229,7 +229,7 @@ SmartHomeNGAccessory.prototype = {
}.bind(this); }.bind(this);
monitoring.push({name: name, characteristic: characteristic.displayName, item: shngitem, callback: callback, inverted: false}); monitoring.push({name: name, characteristic: characteristic.displayName, item: shngitem, callback: callback, inverted: false});
}, },
shngregister_float: function(name, shngitem, characteristic) { shngregister_float: function(name, shngitem, characteristic) {
this.log("[" + name + "] Registering callback for '" + shngitem + "'."); this.log("[" + name + "] Registering callback for '" + shngitem + "'.");
var callback = function (shngitem, value) { var callback = function (shngitem, value) {
@ -247,7 +247,7 @@ SmartHomeNGAccessory.prototype = {
}.bind(this); }.bind(this);
monitoring.push({name: name, characteristic: characteristic.displayName, item: shngitem, callback: callback, inverted: inverted}); monitoring.push({name: name, characteristic: characteristic.displayName, item: shngitem, callback: callback, inverted: inverted});
}, },
shngregister_percent: function(name, shngitem, characteristic, inverted) { shngregister_percent: function(name, shngitem, characteristic, inverted) {
this.log("[" + name + "] Registering callback for '" + shngitem + "'."); this.log("[" + name + "] Registering callback for '" + shngitem + "'.");
var callback = function (shngitem, value, inverted) { var callback = function (shngitem, value, inverted) {
@ -256,7 +256,7 @@ SmartHomeNGAccessory.prototype = {
}.bind(this); }.bind(this);
monitoring.push({name: name, characteristic: characteristic.displayName, item: shngitem, callback: callback, inverted: inverted}); monitoring.push({name: name, characteristic: characteristic.displayName, item: shngitem, callback: callback, inverted: inverted});
}, },
shngregister_angle: function(name, shngitem, characteristic, inverted) { shngregister_angle: function(name, shngitem, characteristic, inverted) {
this.log("[" + name + "] Registering callback for '" + shngitem + "'."); this.log("[" + name + "] Registering callback for '" + shngitem + "'.");
var callback = function (shngitem, value, inverted) { var callback = function (shngitem, value, inverted) {
@ -266,8 +266,8 @@ SmartHomeNGAccessory.prototype = {
}.bind(this); }.bind(this);
monitoring.push({name: name, characteristic: characteristic.displayName, item: shngitem, callback: callback, inverted: inverted}); monitoring.push({name: name, characteristic: characteristic.displayName, item: shngitem, callback: callback, inverted: inverted});
}, },
/** get methods /** get methods
* *
*/ */
getState: function(callback, shngitem, inverted) { getState: function(callback, shngitem, inverted) {
@ -305,17 +305,17 @@ SmartHomeNGAccessory.prototype = {
if (callback) callback(); if (callback) callback();
} }
}, },
setPercentage: function(value, callback, context, shngitem, inverted) { setPercentage: function(value, callback, context, shngitem, inverted) {
if (context === 'fromSHNG') { if (context === 'fromSHNG') {
if (callback) { if (callback) {
callback(); callback();
} }
} else { } else {
var numericValue = 0; var numericValue = 0;
value = ( value>=0 ? (value<=100 ? value:100):0 ); //ensure range 0..100 value = ( value>=0 ? (value<=100 ? value:100):0 ); //ensure range 0..100
if (inverted) { if (inverted) {
numericValue = 100 - value; numericValue = 100 - value;
} else { } else {
numericValue = value; numericValue = value;
} }
@ -330,11 +330,11 @@ SmartHomeNGAccessory.prototype = {
if (callback) { if (callback) {
callback(); callback();
} }
} else { } else {
var numericValue = 0; var numericValue = 0;
value = ( value>=0 ? (value<=360 ? value:360):0 ); //ensure range 0..360 value = ( value>=0 ? (value<=360 ? value:360):0 ); //ensure range 0..360
if (inverted) { if (inverted) {
numericValue = 360 - value; numericValue = 360 - value;
} else { } else {
numericValue = value; numericValue = value;
} }
@ -348,40 +348,40 @@ SmartHomeNGAccessory.prototype = {
}, },
setInt: function(value, callback, context, shngitem) { setInt: function(value, callback, context, shngitem) {
if (context === 'fromSHNG') { if (context === 'fromSHNG') {
if (callback) { if (callback) {
callback(); callback();
} }
} else { } else {
var numericValue = 0; var numericValue = 0;
if (value && value>=0) { if (value && value>=0) {
numericValue = value; numericValue = value;
} }
this.log("["+ this.name +"] Setting " + shngitem + " int to %s", numericValue); this.log("["+ this.name +"] Setting " + shngitem + " int to %s", numericValue);
this.shngcon.setValue(shngitem, numericValue); this.shngcon.setValue(shngitem, numericValue);
if (callback) callback(); if (callback) callback();
} }
}, },
setFloat: function(value, callback, context, shngitem) { setFloat: function(value, callback, context, shngitem) {
if (context === 'fromSHNG') { if (context === 'fromSHNG') {
if (callback) { if (callback) {
callback(); callback();
} }
} else { } else {
var numericValue = 0; var numericValue = 0;
if (value && value>=0) { if (value && value>=0) {
numericValue = value; numericValue = value;
} }
this.log("["+ this.name +"] Setting " + shngitem + " float to %s", numericValue); this.log("["+ this.name +"] Setting " + shngitem + " float to %s", numericValue);
this.shngcon.setValue(shngitem, numericValue); this.shngcon.setValue(shngitem, numericValue);
if (callback) callback(); if (callback) callback();
} }
}, },
/** bindCharacteristic /** bindCharacteristic
* initializes callbacks for 'set' events (from HK) and for SmartHomeNG monitoring events (to HK) * initializes callbacks for 'set' events (from HK) and for SmartHomeNG monitoring events (to HK)
*/ */
// Bind characteristic to service during startup // Bind characteristic to service during startup
bindCharacteristic: function(myService, characteristicType, valueType, shngitem, inverted, defaultValue) { bindCharacteristic: function(myService, characteristicType, valueType, shngitem, inverted, defaultValue) {
var myCharacteristic = myService.getCharacteristic(characteristicType); var myCharacteristic = myService.getCharacteristic(characteristicType);
@ -398,7 +398,7 @@ SmartHomeNGAccessory.prototype = {
this.getState(callback, shngitem, inverted); this.getState(callback, shngitem, inverted);
}.bind(this)); }.bind(this));
this.shngregister_int(this.name, shngitem, myCharacteristic); this.shngregister_int(this.name, shngitem, myCharacteristic);
break; break;
case "Float": case "Float":
myCharacteristic.on('set', function(value, callback, context) { myCharacteristic.on('set', function(value, callback, context) {
this.setFloat(value, callback, context, shngitem); this.setFloat(value, callback, context, shngitem);
@ -407,7 +407,7 @@ SmartHomeNGAccessory.prototype = {
this.getState(callback, shngitem, inverted); this.getState(callback, shngitem, inverted);
}.bind(this)); }.bind(this));
this.shngregister_float(this.name, shngitem, myCharacteristic); this.shngregister_float(this.name, shngitem, myCharacteristic);
break; break;
case "Bool": case "Bool":
myCharacteristic.on('set', function(value, callback, context) { myCharacteristic.on('set', function(value, callback, context) {
this.setBooleanState(value, callback, context, shngitem, inverted); this.setBooleanState(value, callback, context, shngitem, inverted);
@ -416,12 +416,12 @@ SmartHomeNGAccessory.prototype = {
this.getState(callback, shngitem, inverted); this.getState(callback, shngitem, inverted);
}.bind(this)); }.bind(this));
this.shngregister_bool(this.name, shngitem, myCharacteristic, inverted); this.shngregister_bool(this.name, shngitem, myCharacteristic, inverted);
break; break;
case "Percent": case "Percent":
myCharacteristic.on('set', function(value, callback, context) { myCharacteristic.on('set', function(value, callback, context) {
this.setPercentage(value, callback, context, shngitem, inverted); this.setPercentage(value, callback, context, shngitem, inverted);
//myCharacteristic.timeout = Date.now()+milliTimeout; //myCharacteristic.timeout = Date.now()+milliTimeout;
}.bind(this)); }.bind(this));
myCharacteristic.on('get', function(callback, context) { myCharacteristic.on('get', function(callback, context) {
this.getState(callback, shngitem, inverted); this.getState(callback, shngitem, inverted);
}.bind(this)); }.bind(this));
@ -431,7 +431,7 @@ SmartHomeNGAccessory.prototype = {
myCharacteristic.on('set', function(value, callback, context) { myCharacteristic.on('set', function(value, callback, context) {
this.setAngle(value, callback, context, shngitem, inverted); this.setAngle(value, callback, context, shngitem, inverted);
//myCharacteristic.timeout = Date.now()+milliTimeout; //myCharacteristic.timeout = Date.now()+milliTimeout;
}.bind(this)); }.bind(this));
myCharacteristic.on('get', function(callback, context) { myCharacteristic.on('get', function(callback, context) {
this.getState(callback, shngitem, inverted); this.getState(callback, shngitem, inverted);
}.bind(this)); }.bind(this));
@ -439,7 +439,7 @@ SmartHomeNGAccessory.prototype = {
break; break;
default: default:
this.log(colorOn + "[ERROR] unknown type passed: [" + valueType+"]"+ colorOff); this.log(colorOn + "[ERROR] unknown type passed: [" + valueType+"]"+ colorOff);
} }
return myCharacteristic; return myCharacteristic;
}, },
@ -447,7 +447,7 @@ SmartHomeNGAccessory.prototype = {
* function getXXXXXXXService(config) * function getXXXXXXXService(config)
* returns a configured service object to the caller (accessory/device) * returns a configured service object to the caller (accessory/device)
* *
*/ */
// Create Temperature Sensor service // Create Temperature Sensor service
getTemperatureSensorService: function(config) { getTemperatureSensorService: function(config) {
var myService = new Service.TemperatureSensor(config.name,config.name); var myService = new Service.TemperatureSensor(config.name,config.name);
@ -471,10 +471,10 @@ SmartHomeNGAccessory.prototype = {
// Target temperature // Target temperature
if (config.targettemperature) { if (config.targettemperature) {
this.log("["+ this.name +"] TemperatureSensor TargetTemperature characteristic enabled"); this.log("["+ this.name +"] TemperatureSensor TargetTemperature characteristic enabled");
myService.getCharacteristic(Characteristic.TargetTemperature).setProps({ myService.getCharacteristic(Characteristic.TargetTemperature).setProps({
minValue: config.targettemperatureminimum || 0, minValue: config.targettemperatureminimum || 0,
maxValue: config.targettemperaturemaximum || 40 maxValue: config.targettemperaturemaximum || 40
}); });
this.bindCharacteristic(myService, Characteristic.TargetTemperature, "Float", config.targettemperature, false); this.bindCharacteristic(myService, Characteristic.TargetTemperature, "Float", config.targettemperature, false);
} }
/* /*
@ -485,7 +485,7 @@ SmartHomeNGAccessory.prototype = {
}*/ }*/
return myService; return myService;
}, },
// Create Fan service // Create Fan service
getFanService: function(config) { getFanService: function(config) {
var myService = new Service.Fan(config.name,config.name); var myService = new Service.Fan(config.name,config.name);
@ -500,7 +500,7 @@ SmartHomeNGAccessory.prototype = {
} }
return myService; return myService;
}, },
// Create Lightbulb service // Create Lightbulb service
getLightbulbService: function(config) { getLightbulbService: function(config) {
var myService = new Service.Lightbulb(config.name,config.name); var myService = new Service.Lightbulb(config.name,config.name);
@ -533,7 +533,7 @@ SmartHomeNGAccessory.prototype = {
} }
return myService; return myService;
}, },
// Create Window service // Create Window service
getWindowService: function(config) { getWindowService: function(config) {
//this.log(config); //this.log(config);
@ -545,11 +545,11 @@ SmartHomeNGAccessory.prototype = {
if (config.currentposition) { if (config.currentposition) {
this.log("["+ this.name +"] Window CurrentPosition characteristic enabled"); this.log("["+ this.name +"] Window CurrentPosition characteristic enabled");
this.bindCharacteristic(myService, Characteristic.CurrentPosition, "Percent", config.currentposition, inverted); this.bindCharacteristic(myService, Characteristic.CurrentPosition, "Percent", config.currentposition, inverted);
} }
if (config.targetposition) { if (config.targetposition) {
this.log("["+ this.name +"] Window TargetPosition characteristic enabled"); this.log("["+ this.name +"] Window TargetPosition characteristic enabled");
this.bindCharacteristic(myService, Characteristic.TargetPosition, "Percent", config.targetposition, inverted); this.bindCharacteristic(myService, Characteristic.TargetPosition, "Percent", config.targetposition, inverted);
} }
this.log("["+ this.name +"] Window PositionState characteristic enabled"); this.log("["+ this.name +"] Window PositionState characteristic enabled");
this.bindCharacteristic(myService, Characteristic.PositionState, "Int", config.positionstate, inverted, Characteristic.PositionState.STOPPED); this.bindCharacteristic(myService, Characteristic.PositionState, "Int", config.positionstate, inverted, Characteristic.PositionState.STOPPED);
return myService; return myService;
@ -566,16 +566,16 @@ SmartHomeNGAccessory.prototype = {
if (config.currentposition) { if (config.currentposition) {
this.log("["+ this.name +"] WindowCovering CurrentPosition characteristic enabled"); this.log("["+ this.name +"] WindowCovering CurrentPosition characteristic enabled");
this.bindCharacteristic(myService, Characteristic.CurrentPosition, "Percent", config.currentposition, inverted); this.bindCharacteristic(myService, Characteristic.CurrentPosition, "Percent", config.currentposition, inverted);
} }
if (config.targetposition) { if (config.targetposition) {
this.log("["+ this.name +"] WindowCovering TargetPosition characteristic enabled"); this.log("["+ this.name +"] WindowCovering TargetPosition characteristic enabled");
this.bindCharacteristic(myService, Characteristic.TargetPosition, "Percent", config.targetposition, inverted); this.bindCharacteristic(myService, Characteristic.TargetPosition, "Percent", config.targetposition, inverted);
} }
this.log("["+ this.name +"] WindowCovering PositionState characteristic enabled"); this.log("["+ this.name +"] WindowCovering PositionState characteristic enabled");
this.bindCharacteristic(myService, Characteristic.PositionState, "Int", config.positionstate, inverted, Characteristic.PositionState.STOPPED); this.bindCharacteristic(myService, Characteristic.PositionState, "Int", config.positionstate, inverted, Characteristic.PositionState.STOPPED);
return myService; return myService;
}, },
// Create OccupancySensor service // Create OccupancySensor service
getOccupancySensorService: function(config) { getOccupancySensorService: function(config) {
var myService = new Service.OccupancySensor(config.name,config.name); var myService = new Service.OccupancySensor(config.name,config.name);
@ -586,7 +586,7 @@ SmartHomeNGAccessory.prototype = {
if (config.motiondetected) { if (config.motiondetected) {
this.log("["+ this.name +"] OccupancySensor OccupancyDetected characteristic enabled"); this.log("["+ this.name +"] OccupancySensor OccupancyDetected characteristic enabled");
this.bindCharacteristic(myService, Characteristic.OccupancyDetected, "Bool", config.motiondetected, inverted); this.bindCharacteristic(myService, Characteristic.OccupancyDetected, "Bool", config.motiondetected, inverted);
} }
return myService; return myService;
}, },
@ -600,10 +600,10 @@ SmartHomeNGAccessory.prototype = {
if (config.motiondetected) { if (config.motiondetected) {
this.log("["+ this.name +"] MotionSensor MotionDetected characteristic enabled"); this.log("["+ this.name +"] MotionSensor MotionDetected characteristic enabled");
this.bindCharacteristic(myService, Characteristic.MotionDetected, "Bool", config.motiondetected, inverted); this.bindCharacteristic(myService, Characteristic.MotionDetected, "Bool", config.motiondetected, inverted);
} }
return myService; return myService;
}, },
// Create ContactSensor service // Create ContactSensor service
getContactSensorService: function(config) { getContactSensorService: function(config) {
var myService = new Service.ContactSensor(config.name,config.name); var myService = new Service.ContactSensor(config.name,config.name);
@ -614,7 +614,7 @@ SmartHomeNGAccessory.prototype = {
if (config.contactsensorstate) { if (config.contactsensorstate) {
this.log("["+ this.name +"] ContactSensor ContactSensorState characteristic enabled"); this.log("["+ this.name +"] ContactSensor ContactSensorState characteristic enabled");
this.bindCharacteristic(myService, Characteristic.ContactSensorState, "Bool", config.contactsensorstate, inverted); this.bindCharacteristic(myService, Characteristic.ContactSensorState, "Bool", config.contactsensorstate, inverted);
} }
return myService; return myService;
}, },