Improved refresh interval

This commit is contained in:
Arne 2018-11-13 21:47:39 +01:00
parent fbec31602f
commit 577e62ea32

View File

@ -19,12 +19,19 @@ function NeatoVacuumRobotPlatform(log, config) {
this.password = config['password']; this.password = config['password'];
this.hiddenServices = ('disabled' in config ? config['disabled'] : ''); this.hiddenServices = ('disabled' in config ? config['disabled'] : '');
// default off if ('refresh' in config && config['refresh'] !== 'auto') {
this.refresh = ('refresh' in config ? parseInt(config['refresh']) : 0); // parse config parameter
this.refresh = parseInt(config['refresh']);
// must be integer and positive // must be integer and positive
this.refresh = (typeof this.refresh !== 'number' || (this.refresh % 1) !== 0 || this.refresh < 0) ? 0 : this.refresh; this.refresh = (typeof this.refresh !== 'number' || (this.refresh % 1) !== 0 || this.refresh < 0) ? 60 : this.refresh;
// minimum 60s // minimum 60s to save some load on the neato servers
this.refresh = (this.refresh > 0 && this.refresh < 60) ? 60 : this.refresh; this.refresh = (this.refresh > 0 && this.refresh < 60) ? 60 : this.refresh;
}
// default auto
else {
this.refresh = 'auto';
}
debug("Refresh is set to: " + this.refresh);
} }
NeatoVacuumRobotPlatform.prototype = { NeatoVacuumRobotPlatform.prototype = {
@ -168,12 +175,14 @@ NeatoVacuumRobotAccessory.prototype = {
this.updateRobot(function (error, result) { this.updateRobot(function (error, result) {
if (on) { if (on) {
if (that.robot.canResume || that.robot.canStart) { if (that.robot.canResume || that.robot.canStart) {
// TODO
// start update robot timer if refresh ist "auto" // start extra update robot timer if refresh is set to "auto"
if (that.refresh === 'auto') {
setTimeout(function () { setTimeout(function () {
clearTimeout(that.timer); clearTimeout(that.timer);
that.updateRobotTimer(); that.updateRobotTimer();
}, 10000); }, 60 * 1000);
}
if (that.robot.canResume) { if (that.robot.canResume) {
debug(that.name + ": Resume cleaning"); debug(that.name + ": Resume cleaning");
@ -193,7 +202,7 @@ NeatoVacuumRobotAccessory.prototype = {
that.log.error(error + ": " + result); that.log.error(error + ": " + result);
callback(true); callback(true);
} }
else{ else {
callback(); callback();
} }
}); });
@ -388,11 +397,14 @@ NeatoVacuumRobotAccessory.prototype = {
that.vacuumRobotBatteryService.setCharacteristic(Characteristic.BatteryLevel, that.robot.charge); that.vacuumRobotBatteryService.setCharacteristic(Characteristic.BatteryLevel, that.robot.charge);
that.vacuumRobotBatteryService.setCharacteristic(Characteristic.ChargingState, that.robot.isCharging); that.vacuumRobotBatteryService.setCharacteristic(Characteristic.ChargingState, that.robot.isCharging);
if (that.robot.canPause) { // robot is currently cleaning, update if refresh is set to auto or a specific interval
debug("Updating state in background every 30 seconds while cleaning"); if (that.robot.canPause && that.refresh !== 0) {
that.timer = setTimeout(that.updateRobotTimer.bind(that), 30 * 1000); let refreshTime = that.refresh === 'auto' ? 60 : that.refresh
debug("Updating state in background every " + refreshTime + " seconds while cleaning");
that.timer = setTimeout(that.updateRobotTimer.bind(that), refreshTime * 1000);
} }
else if (that.refresh != 0) { // robot is not cleaning, but a specific refresh interval is set
else if (that.refresh !== 'auto' && that.refresh !== 0) {
debug("Updating state in background every " + that.refresh + " seconds (user setting)"); debug("Updating state in background every " + that.refresh + " seconds (user setting)");
that.timer = setTimeout(that.updateRobotTimer.bind(that), that.refresh * 1000); that.timer = setTimeout(that.updateRobotTimer.bind(that), that.refresh * 1000);
} }