Skip to content

Commit

Permalink
smll modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoduj committed Apr 25, 2020
1 parent acf9b65 commit fcb6697
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 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.3.1

- [FIX] code improvments

## 1.3.0

**You need to cleanCache if you had installed before, with option cleanCache . Remember to remove it after restart - sorry for that**
Expand Down
15 changes: 2 additions & 13 deletions autoMowerAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,13 @@ AutoMowerAPI.prototype = {
});
},

sendCommand: function (homebridgeAccessory, command, characteristic, callback) {
sendCommand: function (command, callback) {
const that = this;
var currentValue = characteristic.value;
var commandURL;

commandURL = this.trackApiUrl + 'mowers/' + homebridgeAccessory.mowerID + command;
var commandURL = this.trackApiUrl + 'mowers/' + command;

this.authenticate((error) => {
if (error) {
setTimeout(function () {
characteristic.updateValue(currentValue);
}, 200);
callback(error);
} else {
request(
Expand All @@ -163,15 +158,9 @@ AutoMowerAPI.prototype = {
that.log.debug('INFO - Body received : ' + JSON.stringify(body));
if (error) {
that.log(error.message);
setTimeout(function () {
characteristic.updateValue(currentValue);
}, 200);
callback(error);
} else if (response && response.statusCode !== 200) {
that.log('ERROR - sendCommand - No 200 return ' + response.statusCode);
setTimeout(function () {
characteristic.updateValue(currentValue);
}, 200);
callback(error);
} else {
callback();
Expand Down
35 changes: 27 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,20 @@ myAutoMowerPlatform.prototype = {
},
setSwitchOnCharacteristic: function (homebridgeAccessory, characteristic, value, callback) {
this.log.debug('INFO - setSwitchOnCharacteristic - ' + value);

var currentValue = characteristic.value;
callback();

this.autoMowerAPI.sendCommand(
homebridgeAccessory,
value ? AutoMowerConst.START_COMMAND : AutoMowerConst.PARK_COMMAND,
characteristic,
callback
homebridgeAccessory.mowerID +
(value ? AutoMowerConst.START_COMMAND : AutoMowerConst.PARK_COMMAND),
function (error) {
if (error) {
setTimeout(function () {
characteristic.updateValue(currentValue);
}, 200);
}
}
);
},

Expand All @@ -363,11 +372,21 @@ myAutoMowerPlatform.prototype = {
},
setMowerOnCharacteristic: function (homebridgeAccessory, characteristic, value, callback) {
this.log.debug('setMowerOnCharacteristic -' + value);

var currentValue = characteristic.value;

callback();

this.autoMowerAPI.sendCommand(
homebridgeAccessory,
value ? AutoMowerConst.START_COMMAND : AutoMowerConst.PAUSE_COMMAND,
characteristic,
callback
homebridgeAccessory.mowerID +
(value ? AutoMowerConst.START_COMMAND : AutoMowerConst.PAUSE_COMMAND),
function (error) {
if (error) {
setTimeout(function () {
characteristic.updateValue(currentValue);
}, 200);
}
}
);
},

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-automower",
"version": "1.3.0",
"version": "1.3.1",
"author": "Nicolas Dujardin",
"description": "Publish your automower as an homekit accessory",
"main": "index.js",
Expand Down

0 comments on commit fcb6697

Please sign in to comment.