mirror of
https://github.com/mtan93/homebridge.git
synced 2026-03-08 05:31:55 +00:00
Merge remote-tracking branch 'nfarina/master'
This commit is contained in:
@@ -11,6 +11,17 @@ function LockitronAccessory(log, config) {
|
||||
this.name = config["name"];
|
||||
this.accessToken = config["api_token"];
|
||||
this.lockID = config["lock_id"];
|
||||
|
||||
this.service = new Service.LockMechanism(this.name);
|
||||
|
||||
this.service
|
||||
.getCharacteristic(Characteristic.LockCurrentState)
|
||||
.on('get', this.getState.bind(this));
|
||||
|
||||
this.service
|
||||
.getCharacteristic(Characteristic.LockTargetState)
|
||||
.on('get', this.getState.bind(this))
|
||||
.on('set', this.setState.bind(this));
|
||||
}
|
||||
|
||||
LockitronAccessory.prototype.getState = function(callback) {
|
||||
@@ -36,7 +47,7 @@ LockitronAccessory.prototype.getState = function(callback) {
|
||||
}
|
||||
|
||||
LockitronAccessory.prototype.setState = function(state, callback) {
|
||||
var lockitronState = (state == 1) ? "lock" : "unlock";
|
||||
var lockitronState = (state == Characteristic.LockTargetState.SECURED) ? "lock" : "unlock";
|
||||
|
||||
this.log("Set state to %s", lockitronState);
|
||||
|
||||
@@ -47,6 +58,14 @@ LockitronAccessory.prototype.setState = function(state, callback) {
|
||||
|
||||
if (!err && response.statusCode == 200) {
|
||||
this.log("State change complete.");
|
||||
|
||||
// we succeeded, so update the "current" state as well
|
||||
var currentState = (state == Characteristic.LockTargetState.SECURED) ?
|
||||
Characteristic.LockCurrentState.SECURED : Characteristic.LockCurrentState.UNSECURED;
|
||||
|
||||
this.service
|
||||
.setCharacteristic(Characteristic.LockCurrentState, currentState);
|
||||
|
||||
callback(null); // success
|
||||
}
|
||||
else {
|
||||
@@ -57,17 +76,5 @@ LockitronAccessory.prototype.setState = function(state, callback) {
|
||||
},
|
||||
|
||||
LockitronAccessory.prototype.getServices = function() {
|
||||
|
||||
var service = new Service.LockMechanism(this.name);
|
||||
|
||||
service
|
||||
.getCharacteristic(Characteristic.LockCurrentState)
|
||||
.on('get', this.getState.bind(this));
|
||||
|
||||
service
|
||||
.getCharacteristic(Characteristic.LockTargetState)
|
||||
.on('get', this.getState.bind(this))
|
||||
.on('set', this.setState.bind(this));
|
||||
|
||||
return [service];
|
||||
return [this.service];
|
||||
}
|
||||
|
||||
@@ -144,6 +144,16 @@ WeMoAccessory.prototype.getServices = function() {
|
||||
|
||||
return [garageDoorService];
|
||||
}
|
||||
else if (this.service == "Light") {
|
||||
var lightbulbService = new Service.Lightbulb(this.name);
|
||||
|
||||
lightbulbService
|
||||
.getCharacteristic(Characteristic.On)
|
||||
.on('get', this.getPowerOn.bind(this))
|
||||
.on('set', this.setPowerOn.bind(this));
|
||||
|
||||
return [lightbulbService];
|
||||
}
|
||||
else if (this.service == "MotionSensor") {
|
||||
var motionSensorService = new Service.MotionSensor(this.name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user