mirror of
https://github.com/mtan93/homebridge.git
synced 2026-05-21 06:08:54 +01:00
Added support for Fibaro Outlet
This commit is contained in:
+35
-59
@@ -64,10 +64,20 @@ FibaroHC2Platform.prototype = {
|
|||||||
accessory = new FibaroDoorSensorAccessory(that, s);
|
accessory = new FibaroDoorSensorAccessory(that, s);
|
||||||
else if (s.type == "com.fibaro.lightSensor")
|
else if (s.type == "com.fibaro.lightSensor")
|
||||||
accessory = new FibaroLightSensorAccessory(that, s);
|
accessory = new FibaroLightSensorAccessory(that, s);
|
||||||
|
else if (s.type == "com.fibaro.FGWP101")
|
||||||
|
accessory = new FibaroOutletAccessory(that, s);
|
||||||
|
|
||||||
if (accessory != null) {
|
if (accessory != null) {
|
||||||
accessory.getServices = function() {
|
accessory.getServices = function() {
|
||||||
return that.getServices(accessory);
|
return that.getServices(accessory);
|
||||||
};
|
};
|
||||||
|
accessory.platform = that;
|
||||||
|
accessory.remoteAccessory = s;
|
||||||
|
accessory.id = s.id;
|
||||||
|
accessory.name = s.name;
|
||||||
|
accessory.model = s.type;
|
||||||
|
accessory.manufacturer = "Fibaro";
|
||||||
|
accessory.serialNumber = "<unknown>";
|
||||||
foundAccessories.push(accessory);
|
foundAccessories.push(accessory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,23 +113,30 @@ FibaroHC2Platform.prototype = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getAccessoryValue: function(callback, returnBoolean, that) {
|
getAccessoryValue: function(callback, returnBoolean, homebridgeAccessory, powerValue) {
|
||||||
var url = "http://"+that.platform.host+"/api/devices/"+that.id+"/properties/value";
|
var url = "http://"+homebridgeAccessory.platform.host+"/api/devices/"+homebridgeAccessory.id+"/properties/";
|
||||||
|
if (powerValue)
|
||||||
|
url = url + "power";
|
||||||
|
else
|
||||||
|
url = url + "value";
|
||||||
|
|
||||||
request.get({
|
request.get({
|
||||||
headers : {
|
headers : {
|
||||||
"Authorization" : that.platform.auth
|
"Authorization" : homebridgeAccessory.platform.auth
|
||||||
},
|
},
|
||||||
json: true,
|
json: true,
|
||||||
url: url
|
url: url
|
||||||
}, function(err, response, json) {
|
}, function(err, response, json) {
|
||||||
that.platform.log(url);
|
homebridgeAccessory.platform.log(url);
|
||||||
if (!err && response.statusCode == 200) {
|
if (!err && response.statusCode == 200) {
|
||||||
if (returnBoolean)
|
if (powerValue) {
|
||||||
|
callback(undefined, parseFloat(json.value) > 1.0 ? true : false);
|
||||||
|
} else if (returnBoolean)
|
||||||
callback(undefined, json.value == 0 ? 0 : 1);
|
callback(undefined, json.value == 0 ? 0 : 1);
|
||||||
else
|
else
|
||||||
callback(undefined, json.value);
|
callback(undefined, json.value);
|
||||||
} else {
|
} else {
|
||||||
that.platform.log("There was a problem getting value from" + that.id);
|
homebridgeAccessory.platform.log("There was a problem getting value from" + homebridgeAccessory.id);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -135,6 +152,7 @@ FibaroHC2Platform.prototype = {
|
|||||||
bindCharacteristicEvents: function(characteristic, homebridgeAccessory) {
|
bindCharacteristicEvents: function(characteristic, homebridgeAccessory) {
|
||||||
var onOff = characteristic.format == "bool" ? true : false;
|
var onOff = characteristic.format == "bool" ? true : false;
|
||||||
var readOnly = characteristic.writable == undefined || characteristic.writable == false ? true : false;
|
var readOnly = characteristic.writable == undefined || characteristic.writable == false ? true : false;
|
||||||
|
var powerValue = (characteristic.UUID == "00000026-0000-1000-8000-0026BB765291") ? true : false;
|
||||||
subscribeUpdate(characteristic, homebridgeAccessory, onOff);
|
subscribeUpdate(characteristic, homebridgeAccessory, onOff);
|
||||||
if (!readOnly) {
|
if (!readOnly) {
|
||||||
characteristic
|
characteristic
|
||||||
@@ -150,7 +168,7 @@ FibaroHC2Platform.prototype = {
|
|||||||
}
|
}
|
||||||
characteristic
|
characteristic
|
||||||
.on('get', function(callback) {
|
.on('get', function(callback) {
|
||||||
homebridgeAccessory.platform.getAccessoryValue(callback, onOff, homebridgeAccessory);
|
homebridgeAccessory.platform.getAccessoryValue(callback, onOff, homebridgeAccessory, powerValue);
|
||||||
}.bind(this) );
|
}.bind(this) );
|
||||||
},
|
},
|
||||||
getServices: function(homebridgeAccessory) {
|
getServices: function(homebridgeAccessory) {
|
||||||
@@ -167,89 +185,45 @@ FibaroHC2Platform.prototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function FibaroDimmerAccessory(platform, s) {
|
function FibaroDimmerAccessory(platform, s) {
|
||||||
this.platform = platform;
|
|
||||||
this.remoteAccessory = s;
|
|
||||||
this.id = s.id;
|
|
||||||
this.name = s.name;
|
|
||||||
this.model = s.type;
|
|
||||||
this.manufacturer = "Fibaro";
|
|
||||||
this.serialNumber = "<unknown>";
|
|
||||||
this.controlService = new Service.Lightbulb(this.name);
|
this.controlService = new Service.Lightbulb(this.name);
|
||||||
this.characteristics = [Characteristic.On, Characteristic.Brightness];
|
this.characteristics = [Characteristic.On, Characteristic.Brightness];
|
||||||
}
|
}
|
||||||
|
|
||||||
function FibaroRollerShutterAccessory(platform, s) {
|
function FibaroRollerShutterAccessory(platform, s) {
|
||||||
this.platform = platform;
|
|
||||||
this.remoteAccessory = s;
|
|
||||||
this.id = s.id;
|
|
||||||
this.name = s.name;
|
|
||||||
this.model = s.type;
|
|
||||||
this.manufacturer = "Fibaro";
|
|
||||||
this.serialNumber = "<unknown>";
|
|
||||||
this.controlService = new Service.WindowCovering(this.name);
|
this.controlService = new Service.WindowCovering(this.name);
|
||||||
this.characteristics = [Characteristic.CurrentPosition, Characteristic.TargetPosition, Characteristic.PositionState];
|
this.characteristics = [Characteristic.CurrentPosition, Characteristic.TargetPosition, Characteristic.PositionState];
|
||||||
}
|
}
|
||||||
|
|
||||||
function FibaroBinarySwitchAccessory(platform, s) {
|
function FibaroBinarySwitchAccessory(platform, s) {
|
||||||
this.platform = platform;
|
|
||||||
this.remoteAccessory = s;
|
|
||||||
this.id = s.id;
|
|
||||||
this.name = s.name;
|
|
||||||
this.model = s.type;
|
|
||||||
this.manufacturer = "Fibaro";
|
|
||||||
this.serialNumber = "<unknown>";
|
|
||||||
this.controlService = new Service.Switch(this.name);
|
this.controlService = new Service.Switch(this.name);
|
||||||
this.characteristics = [Characteristic.On];
|
this.characteristics = [Characteristic.On];
|
||||||
}
|
}
|
||||||
|
|
||||||
function FibaroMotionSensorAccessory(platform, s) {
|
function FibaroMotionSensorAccessory(platform, s) {
|
||||||
this.platform = platform;
|
|
||||||
this.remoteAccessory = s;
|
|
||||||
this.id = s.id;
|
|
||||||
this.name = s.name;
|
|
||||||
this.model = "Motion Sensor";
|
|
||||||
this.manufacturer = "Fibaro";
|
|
||||||
this.serialNumber = "<unknown>";
|
|
||||||
this.controlService = new Service.MotionSensor(this.name);
|
this.controlService = new Service.MotionSensor(this.name);
|
||||||
this.characteristics = [Characteristic.MotionDetected];
|
this.characteristics = [Characteristic.MotionDetected];
|
||||||
}
|
}
|
||||||
|
|
||||||
function FibaroTemperatureSensorAccessory(platform, s) {
|
function FibaroTemperatureSensorAccessory(platform, s) {
|
||||||
this.platform = platform;
|
|
||||||
this.remoteAccessory = s;
|
|
||||||
this.id = s.id;
|
|
||||||
this.name = s.name;
|
|
||||||
this.model = s.type;
|
|
||||||
this.manufacturer = "Fibaro";
|
|
||||||
this.serialNumber = "<unknown>";
|
|
||||||
this.controlService = new Service.TemperatureSensor(this.name);
|
this.controlService = new Service.TemperatureSensor(this.name);
|
||||||
this.characteristics = [Characteristic.CurrentTemperature];
|
this.characteristics = [Characteristic.CurrentTemperature];
|
||||||
}
|
}
|
||||||
|
|
||||||
function FibaroDoorSensorAccessory(platform, s) {
|
function FibaroDoorSensorAccessory(platform, s) {
|
||||||
this.platform = platform;
|
|
||||||
this.remoteAccessory = s;
|
|
||||||
this.id = s.id;
|
|
||||||
this.name = s.name;
|
|
||||||
this.model = s.type;
|
|
||||||
this.manufacturer = "Fibaro";
|
|
||||||
this.serialNumber = "<unknown>";
|
|
||||||
this.controlService = new Service.ContactSensor(this.name);
|
this.controlService = new Service.ContactSensor(this.name);
|
||||||
this.characteristics = [Characteristic.ContactSensorState];
|
this.characteristics = [Characteristic.ContactSensorState];
|
||||||
}
|
}
|
||||||
|
|
||||||
function FibaroLightSensorAccessory(platform, s) {
|
function FibaroLightSensorAccessory(platform, s) {
|
||||||
this.platform = platform;
|
|
||||||
this.remoteAccessory = s;
|
|
||||||
this.id = s.id;
|
|
||||||
this.name = s.name;
|
|
||||||
this.model = s.type;
|
|
||||||
this.manufacturer = "Fibaro";
|
|
||||||
this.serialNumber = "<unknown>";
|
|
||||||
this.controlService = new Service.LightSensor(this.name);
|
this.controlService = new Service.LightSensor(this.name);
|
||||||
this.characteristics = [Characteristic.CurrentAmbientLightLevel];
|
this.characteristics = [Characteristic.CurrentAmbientLightLevel];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function FibaroOutletAccessory(platform, s) {
|
||||||
|
this.controlService = new Service.Outlet(this.name);
|
||||||
|
this.characteristics = [Characteristic.On, Characteristic.OutletInUse];
|
||||||
|
}
|
||||||
|
|
||||||
var lastPoll=0;
|
var lastPoll=0;
|
||||||
var pollingUpdateRunning = false;
|
var pollingUpdateRunning = false;
|
||||||
|
|
||||||
@@ -281,10 +255,12 @@ function startPollingUpdate( platform )
|
|||||||
for (i=0;i<updateSubscriptions.length; i++) {
|
for (i=0;i<updateSubscriptions.length; i++) {
|
||||||
var subscription = updateSubscriptions[i];
|
var subscription = updateSubscriptions[i];
|
||||||
if (subscription.id == s.id) {
|
if (subscription.id == s.id) {
|
||||||
if ((subscription.onOff && typeof(value) == "boolean") || !subscription.onOff)
|
if (s.power != undefined && subscription.characteristic.UUID == "00000026-0000-1000-8000-0026BB765291") {
|
||||||
subscription.characteristic.setValue(value, undefined, 'fromFibaro');
|
subscription.characteristic.setValue(parseFloat(s.power) > 1.0 ? true : false, undefined, 'fromFibaro');
|
||||||
|
} else if ((subscription.onOff && typeof(value) == "boolean") || !subscription.onOff)
|
||||||
|
subscription.characteristic.setValue(value, undefined, 'fromFibaro');
|
||||||
else
|
else
|
||||||
subscription.characteristic.setValue(value == 0 ? false : true, undefined, 'fromFibaro');
|
subscription.characteristic.setValue(value == 0 ? false : true, undefined, 'fromFibaro');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user