mirror of
https://github.com/mtan93/homebridge.git
synced 2026-04-15 14:23:09 +01:00
Added Fibaro Virtual devices management
This commit is contained in:
@@ -66,6 +66,29 @@ FibaroHC2Platform.prototype = {
|
|||||||
accessory = new FibaroAccessory(new Service.LightSensor(s.name), [Characteristic.CurrentAmbientLightLevel]);
|
accessory = new FibaroAccessory(new Service.LightSensor(s.name), [Characteristic.CurrentAmbientLightLevel]);
|
||||||
else if (s.type == "com.fibaro.FGWP101")
|
else if (s.type == "com.fibaro.FGWP101")
|
||||||
accessory = new FibaroAccessory(new Service.Outlet(s.name), [Characteristic.On, Characteristic.OutletInUse]);
|
accessory = new FibaroAccessory(new Service.Outlet(s.name), [Characteristic.On, Characteristic.OutletInUse]);
|
||||||
|
else if (s.type == "virtual_device") {
|
||||||
|
for (var r = 0; r < s.properties.rows.length; r++) {
|
||||||
|
if (s.properties.rows[r].type == "button") {
|
||||||
|
for (var e = 0; e < s.properties.rows[r].elements.length; e++) {
|
||||||
|
var name = s.properties.rows[r].elements[e].caption;
|
||||||
|
var virtualButton = new FibaroAccessory(new Service.Switch(name), [Characteristic.On]);
|
||||||
|
virtualButton.buttonId = s.properties.rows[r].elements[e].id;
|
||||||
|
virtualButton.getServices = function() {
|
||||||
|
return that.getServices(this);
|
||||||
|
};
|
||||||
|
virtualButton.platform = that;
|
||||||
|
virtualButton.remoteAccessory = s;
|
||||||
|
virtualButton.id = s.id;
|
||||||
|
virtualButton.name = name;
|
||||||
|
virtualButton.model = "Virtual Button";
|
||||||
|
virtualButton.manufacturer = "Fibaro";
|
||||||
|
virtualButton.serialNumber = "<unknown>";
|
||||||
|
foundAccessories.push(virtualButton);
|
||||||
|
that.log("Service name: " + virtualButton.controlService.displayName + ", Accessory name: " + virtualButton.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (accessory != null) {
|
if (accessory != null) {
|
||||||
accessory.getServices = function() {
|
accessory.getServices = function() {
|
||||||
return that.getServices(accessory);
|
return that.getServices(accessory);
|
||||||
@@ -159,18 +182,29 @@ FibaroHC2Platform.prototype = {
|
|||||||
if (!readOnly) {
|
if (!readOnly) {
|
||||||
characteristic
|
characteristic
|
||||||
.on('set', function(value, callback, context) {
|
.on('set', function(value, callback, context) {
|
||||||
if( context !== 'fromFibaro' ) {
|
if( context !== 'fromFibaro' && context !== 'fromSetValue') {
|
||||||
if (onOff)
|
if (homebridgeAccessory.buttonId != null) {
|
||||||
|
homebridgeAccessory.platform.command("pressButton", homebridgeAccessory.buttonId, homebridgeAccessory);
|
||||||
|
// In order to behave like a push button reset the status to off
|
||||||
|
setTimeout( function(){
|
||||||
|
characteristic.setValue(false, undefined, 'fromSetValue');
|
||||||
|
}, 100 );
|
||||||
|
} else if (onOff) {
|
||||||
homebridgeAccessory.platform.command(value == 0 ? "turnOff": "turnOn", null, homebridgeAccessory);
|
homebridgeAccessory.platform.command(value == 0 ? "turnOff": "turnOn", null, homebridgeAccessory);
|
||||||
else
|
} else
|
||||||
homebridgeAccessory.platform.command("setValue", value, homebridgeAccessory);
|
homebridgeAccessory.platform.command("setValue", value, homebridgeAccessory);
|
||||||
}
|
}
|
||||||
callback();
|
callback();
|
||||||
}.bind(this) );
|
}.bind(this) );
|
||||||
}
|
}
|
||||||
characteristic
|
characteristic
|
||||||
.on('get', function(callback) {
|
.on('get', function(callback) {
|
||||||
homebridgeAccessory.platform.getAccessoryValue(callback, onOff, homebridgeAccessory, powerValue);
|
if (homebridgeAccessory.buttonId != null) {
|
||||||
|
// a push button is normally off
|
||||||
|
callback(undefined, false);
|
||||||
|
} else {
|
||||||
|
homebridgeAccessory.platform.getAccessoryValue(callback, onOff, homebridgeAccessory, powerValue);
|
||||||
|
}
|
||||||
}.bind(this) );
|
}.bind(this) );
|
||||||
},
|
},
|
||||||
getServices: function(homebridgeAccessory) {
|
getServices: function(homebridgeAccessory) {
|
||||||
@@ -251,3 +285,4 @@ function subscribeUpdate(characteristic, accessory, onOff)
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.platform = FibaroHC2Platform;
|
module.exports.platform = FibaroHC2Platform;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user