mirror of
https://github.com/mtan93/homebridge.git
synced 2026-04-06 06:13:12 +01: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.name = config["name"];
|
||||||
this.accessToken = config["api_token"];
|
this.accessToken = config["api_token"];
|
||||||
this.lockID = config["lock_id"];
|
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) {
|
LockitronAccessory.prototype.getState = function(callback) {
|
||||||
@@ -36,7 +47,7 @@ LockitronAccessory.prototype.getState = function(callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LockitronAccessory.prototype.setState = function(state, 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);
|
this.log("Set state to %s", lockitronState);
|
||||||
|
|
||||||
@@ -47,6 +58,14 @@ LockitronAccessory.prototype.setState = function(state, callback) {
|
|||||||
|
|
||||||
if (!err && response.statusCode == 200) {
|
if (!err && response.statusCode == 200) {
|
||||||
this.log("State change complete.");
|
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
|
callback(null); // success
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -57,17 +76,5 @@ LockitronAccessory.prototype.setState = function(state, callback) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
LockitronAccessory.prototype.getServices = function() {
|
LockitronAccessory.prototype.getServices = function() {
|
||||||
|
return [this.service];
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,6 +144,16 @@ WeMoAccessory.prototype.getServices = function() {
|
|||||||
|
|
||||||
return [garageDoorService];
|
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") {
|
else if (this.service == "MotionSensor") {
|
||||||
var motionSensorService = new Service.MotionSensor(this.name);
|
var motionSensorService = new Service.MotionSensor(this.name);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user