Added switch, adhered to SHNG version numbering

This commit is contained in:
Foxi352 2017-05-30 19:48:12 +02:00
parent aee98eeb6b
commit 801d10c35e
3 changed files with 30 additions and 6 deletions

View File

@ -1,5 +1,5 @@
# homebridge-smarthomeng
Homebridge plugin for SmartHomeNG. This is work in progress and all devices are supported.
Homebridge plugin for SmartHomeNG. This is work in progress and not all devices are supported yet.
## Currently supported
This plugin currently supports the following services (and characteristics):
@ -8,10 +8,12 @@ This plugin currently supports the following services (and characteristics):
* Fan (on/off)
* Temperature sensor (current temperature)
* Thermostat (current- / target temperature)
* Window (current- / target position)
* Window Covering (current- / target position)
* Motion sensor (motion detected)
* Occupancy sensor (motion detected)
* Contact Sensor (contact state)
* Switch (on/off)
## Requirements
* [SmartHomeNG](https://github.com/smarthomeNG/smarthome)
@ -66,7 +68,7 @@ You have to create a config.json in .homebridge directory. You'll find that dire
"platform": "SmartHomeNG",
"name": "SmartHomeNG",
"host": "srvsmarthome.xxxx.lu",
"host": "srvsmarthome.xxx.lu",
"accessories": [
{
"name": "Temperatur Stube",
@ -86,6 +88,11 @@ You have to create a config.json in .homebridge directory. You'll find that dire
"type": "Fan",
"onoff": "OG.Bad.Ventilator"
},
{
"name": "Schaltsteckdose",
"type": "Switch",
"onoff": "EG.Esszimmer.Steckdose"
},
{
"name": "Bürolicht",
"type": "Lightbulb",

View File

@ -167,6 +167,10 @@ SmartHomeNGAccessory.prototype = {
myServices.push(this.getWindowService(this.config));
break;
case 'switch':
myServices.push(this.getSwitchService(this.config));
break;
case 'windowcovering':
myServices.push(this.getWindowCoveringService(this.config));
break;
@ -243,9 +247,7 @@ SmartHomeNGAccessory.prototype = {
shngregister_percent: function(name, shngitem, characteristic, inverted) {
this.log("[" + name + "] Registering callback for '" + shngitem + "'.");
var callback = function (shngitem, value, inverted) {
this.log("[" + this.name + "] callback for " + characteristic.displayName + " with value " + value);
if (value == true) value = 100;
else if (value == false) value = 0;
//this.log("[" + this.name + "] callback for " + characteristic.displayName + " with value " + value);
characteristic.setValue(inverted ? 100 - value : value, undefined, 'fromSHNG');
}.bind(this);
monitoring.push({name: name, characteristic: characteristic.displayName, item: shngitem, callback: callback, inverted: inverted});
@ -612,4 +614,19 @@ SmartHomeNGAccessory.prototype = {
return myService;
},
// Create Switch service
getSwitchService: function(config) {
var myService = new Service.Switch(config.name,config.name);
var inverted = false;
if (config.inverted) {
inverted = true;
}
// On (and Off)
if (config.onoff) {
this.log("["+ this.name +"] Switch on/off characteristic enabled");
this.bindCharacteristic(myService, Characteristic.On, "Bool", config.onoff, inverted);
}
return myService;
},
}

View File

@ -1,6 +1,6 @@
{
"name": "homebridge-smarthomeng",
"version": "1.1.5",
"version": "1.3.6",
"description": "Platform plugin for SmartHomeNG: https://github.com/smarthomeNG/smarthome",
"license": "GPL",
"keywords": [