Added window covering
This commit is contained in:
parent
65a8c20bfa
commit
c600b7eb89
21
README.md
21
README.md
@ -1,7 +1,11 @@
|
|||||||
#Attention: This software is not yet ready, it is in alpha state !!! Do not use it yet !!!
|
#Attention: This software is not ready for production use, consider it being in alpha state !!!
|
||||||
|
|
||||||
#homebridge-smarthomeng
|
#homebridge-smarthomeng
|
||||||
Homebridge plugin for SmartHomeNG
|
Homebridge plugin for SmartHomeNG
|
||||||
|
##Currently supported
|
||||||
|
This plugin currently supports:
|
||||||
|
* LightBulb with on/off and brightness characteristic
|
||||||
|
* Window Covering with currentposition and targetposition characteristic (state not yet supported)
|
||||||
##Requirements
|
##Requirements
|
||||||
SmartHomeNG: https://github.com/smarthomeNG/smarthome
|
SmartHomeNG: https://github.com/smarthomeNG/smarthome
|
||||||
homebridge: https://www.npmjs.com/package/homebridge
|
homebridge: https://www.npmjs.com/package/homebridge
|
||||||
@ -40,20 +44,15 @@ This is an example config file which just uses this plugin and some example Smar
|
|||||||
"host": "myshngserver.mydomain",
|
"host": "myshngserver.mydomain",
|
||||||
"accessories": [
|
"accessories": [
|
||||||
{
|
{
|
||||||
"name": "Bureaulicht",
|
"name": "Licht Büro",
|
||||||
"type": "Lightbulb",
|
"type": "Lightbulb",
|
||||||
"onoff": "EG.Buero.Licht"
|
"onoff": "EG.Buero.Licht"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Stubenlicht",
|
"name": "Rollladen Büro",
|
||||||
"type": "Lightbulb",
|
"type": "WindowCovering",
|
||||||
"onoff": "EG.Stube.Licht"
|
"currentposition": "EG.Buero.Rolladen.Position",
|
||||||
},
|
"targetposition": "EG.Buero.Rolladen.Position"
|
||||||
{
|
|
||||||
"name": "Schlafzimmerlicht",
|
|
||||||
"type": "Lightbulb",
|
|
||||||
"onoff": "OG.SZSS.Licht",
|
|
||||||
"brightness": "OG.SZSS.Licht.dimmen"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
59
index.js
59
index.js
@ -22,7 +22,7 @@ function SmartHomeNGPlatform(log, config, api) {
|
|||||||
this.log = log;
|
this.log = log;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.accessoriesCache = [];
|
this.accessoriesCache = [];
|
||||||
this.supportedFunctions = ['onoff', 'brightness'];
|
this.supportedFunctions = ['onoff', 'brightness', 'currentposition', 'targetposition'];
|
||||||
|
|
||||||
if (this.config["host"] != undefined) {
|
if (this.config["host"] != undefined) {
|
||||||
this.shng_host = this.config["host"];
|
this.shng_host = this.config["host"];
|
||||||
@ -44,10 +44,6 @@ function SmartHomeNGPlatform(log, config, api) {
|
|||||||
|
|
||||||
if (api) {
|
if (api) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
|
|
||||||
// Listen to event "didFinishLaunching", this means homebridge already finished loading cached accessories
|
|
||||||
// Platform Plugin should only register new accessory that doesn't exist in homebridge after this event.
|
|
||||||
// Or start discover new accessories
|
|
||||||
this.api.on('didFinishLaunching', function() {
|
this.api.on('didFinishLaunching', function() {
|
||||||
this.log("Finished loading " + this.accessoriesCache.length + " accessories");
|
this.log("Finished loading " + this.accessoriesCache.length + " accessories");
|
||||||
// Add supported SHNG items to monitoring
|
// Add supported SHNG items to monitoring
|
||||||
@ -56,10 +52,12 @@ function SmartHomeNGPlatform(log, config, api) {
|
|||||||
var device = this.accessoriesCache[i].device;
|
var device = this.accessoriesCache[i].device;
|
||||||
for (var key in device) {
|
for (var key in device) {
|
||||||
if (this.supportedFunctions.indexOf(key) >= 0) {
|
if (this.supportedFunctions.indexOf(key) >= 0) {
|
||||||
|
if(tomonitor.indexOf(device[key]) == -1) {
|
||||||
tomonitor.push(device[key]);
|
tomonitor.push(device[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.shngcon.tomonitor = tomonitor;
|
this.shngcon.tomonitor = tomonitor;
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
@ -74,6 +72,7 @@ function SmartHomeNGAccessory(log, device, shngcon) {
|
|||||||
this.log = log;
|
this.log = log;
|
||||||
this.shngcon = shngcon;
|
this.shngcon = shngcon;
|
||||||
this.value = undefined;
|
this.value = undefined;
|
||||||
|
this.manufacturername = 'SmartHomeNG';
|
||||||
/*this.log("CONSTRUCTOR: ");
|
/*this.log("CONSTRUCTOR: ");
|
||||||
this.log(device);
|
this.log(device);
|
||||||
this.log("------")*/
|
this.log("------")*/
|
||||||
@ -97,7 +96,6 @@ SmartHomeNGPlatform.prototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//this.log(foundAccessories)
|
//this.log(foundAccessories)
|
||||||
this.accessoriesCounter = foundAccessories.length;
|
|
||||||
this.accessoriesCache = foundAccessories;
|
this.accessoriesCache = foundAccessories;
|
||||||
callback(foundAccessories);
|
callback(foundAccessories);
|
||||||
},
|
},
|
||||||
@ -105,13 +103,21 @@ SmartHomeNGPlatform.prototype = {
|
|||||||
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 (i = 0; i < this.platform.accessoriesCache.length; i++) {
|
for (i = 0; i < this.platform.accessoriesCache.length; i++) {
|
||||||
accessory = this.platform.accessoriesCache[i].device;
|
accessory = this.platform.accessoriesCache[i];
|
||||||
|
//this.log(this.platform);
|
||||||
// loop through accessories and services to find modified one
|
// loop through accessories and services to find modified one
|
||||||
for (var key in accessory) {
|
for (var key in accessory.device) {
|
||||||
if (accessory[key] == item) {
|
if (accessory.device[key] == item) {
|
||||||
this.log("Updating item '" + item + "' with value " + value);
|
this.log("Updating item '" + item + "' characteristic " + key + " with value " + value);
|
||||||
accessory[key + '_value'] = value;
|
accessory.device[key + '_value'] = value;
|
||||||
break;
|
myCharacteristic = Characteristic.On;
|
||||||
|
//accessory.getService(Service.Lightbulb).getCharacteristic(myCharacteristic).setValue(value);
|
||||||
|
//this.log(this);
|
||||||
|
// var myService = accessory.getService(Service.Lightbulb)
|
||||||
|
// var myCharacteristic = myService.getCharacteristic(characteristicType);
|
||||||
|
// Characteristic.On - Characteristic.Brightness
|
||||||
|
// myCharacteristic.setValue(defaultValue);
|
||||||
|
//break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,6 +169,25 @@ SmartHomeNGAccessory.prototype = {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'windowcovering':
|
||||||
|
var myService = new Service.WindowCovering(this.name);
|
||||||
|
// Current position characteristic
|
||||||
|
if (this.device.currentposition) {
|
||||||
|
this.log("Adding 'CurrentPosition' characteristic to " + this.name);
|
||||||
|
myService
|
||||||
|
.getCharacteristic(Characteristic.CurrentPosition)
|
||||||
|
.on('get', function(callback) { that.getValue("currentposition", callback);});
|
||||||
|
}
|
||||||
|
// Target position characteristic
|
||||||
|
if (this.device.targetposition) {
|
||||||
|
this.log("Adding 'TargetPosition' characteristic to " + this.name);
|
||||||
|
myService
|
||||||
|
.getCharacteristic(Characteristic.TargetPosition)
|
||||||
|
.on('get', function(callback) { that.getValue("targetposition", callback);})
|
||||||
|
.on('set', function(value, callback) { that.setValue("targetposition", value, callback);});
|
||||||
|
}
|
||||||
|
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.device.type + "' is not supported !");
|
this.log("Ignoring '" + this.name + "' because device type '" + this.device.type + "' is not supported !");
|
||||||
@ -176,14 +201,17 @@ SmartHomeNGAccessory.prototype = {
|
|||||||
.setCharacteristic(Characteristic.Manufacturer, this.manufacturername)
|
.setCharacteristic(Characteristic.Manufacturer, this.manufacturername)
|
||||||
.setCharacteristic(Characteristic.Model, this.model)
|
.setCharacteristic(Characteristic.Model, this.model)
|
||||||
.setCharacteristic(Characteristic.SerialNumber, this.device.uniqueid);
|
.setCharacteristic(Characteristic.SerialNumber, this.device.uniqueid);
|
||||||
|
MyServices = [informationService, myService];
|
||||||
return [informationService, myService];
|
//this.toto = MyServices;
|
||||||
|
return MyServices;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Get value
|
// Get value
|
||||||
getValue: function(characteristic, callback) {
|
getValue: function(characteristic, callback) {
|
||||||
this.log("Get value for " + this.device.name + ", characteristic: " + characteristic + ".");
|
this.log("Get value for " + this.device.name + ", characteristic: " + characteristic + ".");
|
||||||
//this.log(this.device);
|
this.log(this.device);
|
||||||
|
if (characteristic == 'CurrentPosition') { characteristic = 'position'};
|
||||||
|
this.log("Looking for " + characteristic + "_value");
|
||||||
if (this.device[characteristic + "_value"] != undefined) {
|
if (this.device[characteristic + "_value"] != undefined) {
|
||||||
this.log("Found value '" + this.device[characteristic + "_value"] + "' for '" + characteristic + "' of device '" + this.device.name + "'.");
|
this.log("Found value '" + this.device[characteristic + "_value"] + "' for '" + characteristic + "' of device '" + this.device.name + "'.");
|
||||||
if (callback) callback(null, this.device[characteristic + "_value"]);
|
if (callback) callback(null, this.device[characteristic + "_value"]);
|
||||||
@ -208,5 +236,6 @@ SmartHomeNGAccessory.prototype = {
|
|||||||
// Respond to identify request
|
// Respond to identify request
|
||||||
identify: function(callback) {
|
identify: function(callback) {
|
||||||
this.log("Identify request for '" + this.device.name + "'.");
|
this.log("Identify request for '" + this.device.name + "'.");
|
||||||
|
callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user