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

View File

@ -167,6 +167,10 @@ SmartHomeNGAccessory.prototype = {
myServices.push(this.getWindowService(this.config)); myServices.push(this.getWindowService(this.config));
break; break;
case 'switch':
myServices.push(this.getSwitchService(this.config));
break;
case 'windowcovering': case 'windowcovering':
myServices.push(this.getWindowCoveringService(this.config)); myServices.push(this.getWindowCoveringService(this.config));
break; break;
@ -243,9 +247,7 @@ SmartHomeNGAccessory.prototype = {
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) {
this.log("[" + this.name + "] callback for " + characteristic.displayName + " with value " + value); //this.log("[" + this.name + "] callback for " + characteristic.displayName + " with value " + value);
if (value == true) value = 100;
else if (value == false) value = 0;
characteristic.setValue(inverted ? 100 - value : value, undefined, 'fromSHNG'); characteristic.setValue(inverted ? 100 - value : value, undefined, 'fromSHNG');
}.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});
@ -612,4 +614,19 @@ SmartHomeNGAccessory.prototype = {
return myService; 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", "name": "homebridge-smarthomeng",
"version": "1.1.5", "version": "1.3.6",
"description": "Platform plugin for SmartHomeNG: https://github.com/smarthomeNG/smarthome", "description": "Platform plugin for SmartHomeNG: https://github.com/smarthomeNG/smarthome",
"license": "GPL", "license": "GPL",
"keywords": [ "keywords": [