Skip to content

Commit

Permalink
small improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoduj committed Apr 25, 2020
1 parent 158acbe commit f6e2494
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## 1.1.1

- [NEW] minor improvment in opening / closing process.

## 1.1.0

- [NEW] event based logic for faster refresh, speed improvments.
Expand Down
6 changes: 3 additions & 3 deletions gogogateAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ GogogateAPI.prototype = {
});
},

activateDoor: function (service, callback) {
let commandURL = 'http://' + this.gogogateIP + '/isg/opendoor.php?numdoor=' + service.gateId;
activateDoor: function (gateId, callback) {
let commandURL = 'http://' + this.gogogateIP + '/isg/opendoor.php?numdoor=' + gateId;

var that = this;

Expand All @@ -246,7 +246,7 @@ GogogateAPI.prototype = {

callback(true);
} else {
that.log.debug('INFO - activateDoor - Command sent to ' + service.subtype);
that.log.debug('INFO - activateDoor - Command sent');
callback(false);
}
});
Expand Down
40 changes: 19 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ Gogogate2Platform.prototype = {

HKService.gateId = i + 1;

this.bindCurrentDoorStateCharacteristic(HKService, myGogogateDoorAccessory);
this.bindTargetDoorStateCharacteristic(HKService, myGogogateDoorAccessory);
this.bindObstructionDetectedCharacteristic(HKService, myGogogateDoorAccessory);
this.bindCurrentDoorStateCharacteristic(HKService);
this.bindTargetDoorStateCharacteristic(HKService);
this.bindObstructionDetectedCharacteristic(HKService);

if (sensors[i] && !sensors[i].isEmpty()) {
this.log('INFO - Discovered sensor : ' + sensors[i]);
Expand Down Expand Up @@ -401,7 +401,7 @@ Gogogate2Platform.prototype = {
}
},

getCurrentDoorStateCharacteristic: function (homebridgeAccessory, service, callback) {
getCurrentDoorStateCharacteristic: function (service, callback) {
callback(undefined, service.getCharacteristic(Characteristic.CurrentDoorState).value);

//no operationInProgress, refresh current state
Expand All @@ -410,19 +410,18 @@ Gogogate2Platform.prototype = {
}
},

getTargetDoorStateCharacteristic: function (homebridgeAccessory, service, callback) {
callback(undefined, service.TargetDoorState);
getTargetDoorStateCharacteristic: function (service, callback) {
callback(undefined, service.getCharacteristic(Characteristic.TargetDoorState).value);

//no operationInProgress, refresh current state
if (service.TargetDoorStateOperationStart == undefined) {
this.gogogateAPI.refreshDoor(service.gateId);
}
//Target is updated through event
},

setTargetDoorStateCharacteristic: function (homebridgeAccessory, service, value, callback) {
setTargetDoorStateCharacteristic: function (service, value, callback) {
var currentValue = service.getCharacteristic(Characteristic.TargetDoorState).value;

var currentState = service.getCharacteristic(Characteristic.CurrentDoorState).value;

callback();

var that = this;

if (
Expand All @@ -437,13 +436,13 @@ Gogogate2Platform.prototype = {
this.gogogateAPI.getStateString(currentState)
);

this.gogogateAPI.activateDoor(service, function (error) {
this.gogogateAPI.activateDoor(service.gateId, function (error) {
if (error) {
that.endDoorOperation(service);
setImmediate(() => {
setTimeout(() => {
service.getCharacteristic(Characteristic.TargetDoorState).updateValue(currentValue);
service.getCharacteristic(Characteristic.CurrentDoorState).updateValue(currentState);
});
}, 500);
that.log.debug(
'ERROR - SET Characteristic.TargetDoorState - ' + service.subtype + ' error activating '
);
Expand All @@ -458,31 +457,30 @@ Gogogate2Platform.prototype = {
}
});
}
callback();
},

bindCurrentDoorStateCharacteristic: function (service, homebridgeAccessory) {
bindCurrentDoorStateCharacteristic: function (service) {
service.getCharacteristic(Characteristic.CurrentDoorState).on(
'get',
function (callback) {
this.getCurrentDoorStateCharacteristic(homebridgeAccessory, service, callback);
this.getCurrentDoorStateCharacteristic(service, callback);
}.bind(this)
);
},

bindTargetDoorStateCharacteristic: function (service, homebridgeAccessory) {
bindTargetDoorStateCharacteristic: function (service) {
service
.getCharacteristic(Characteristic.TargetDoorState)
.on(
'get',
function (callback) {
this.getTargetDoorStateCharacteristic(homebridgeAccessory, service, callback);
this.getTargetDoorStateCharacteristic(service, callback);
}.bind(this)
)
.on(
'set',
function (value, callback) {
this.setTargetDoorStateCharacteristic(homebridgeAccessory, service, value, callback);
this.setTargetDoorStateCharacteristic(service, value, callback);
}.bind(this)
);
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-gogogate2",
"version": "1.1.0",
"version": "1.1.1",
"author": "Nicolas Dujardin",
"description": "Publish your gogogate 2 to homebridge",
"main": "index.js",
Expand Down

0 comments on commit f6e2494

Please sign in to comment.