From b66610ce935e5d0660ba76e925a8eca282f338eb Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Mon, 5 Oct 2015 17:12:06 -0700 Subject: [PATCH 1/2] Update Lockitron state on successful change --- accessories/Lockitron.js | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/accessories/Lockitron.js b/accessories/Lockitron.js index 04414af..8088d14 100644 --- a/accessories/Lockitron.js +++ b/accessories/Lockitron.js @@ -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]; } From feca9fbf0d9418ea742bdf58aa9a71ef1b79776e Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Mon, 5 Oct 2015 17:29:53 -0700 Subject: [PATCH 2/2] Support WeMo "Light" services --- accessories/WeMo.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/accessories/WeMo.js b/accessories/WeMo.js index c19e19f..b97b041 100644 --- a/accessories/WeMo.js +++ b/accessories/WeMo.js @@ -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);