From bef37d88c8c6bd51ac93f6cc237cc4ee486e8e71 Mon Sep 17 00:00:00 2001 From: Arne Date: Tue, 24 Sep 2019 20:06:04 +0200 Subject: [PATCH] Fixed a bug that crashed the plugin on devices with zone cleaning Fixed a bug in the update cache timing --- accessories/neatoVacuumRobot.js | 18 +++++++++--------- index.js | 9 +++++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/accessories/neatoVacuumRobot.js b/accessories/neatoVacuumRobot.js index da9df69..3adcef3 100644 --- a/accessories/neatoVacuumRobot.js +++ b/accessories/neatoVacuumRobot.js @@ -35,10 +35,6 @@ function NeatoVacuumRobotAccessory(platform, robotObject, boundary = undefined) this.boundary = boundary; this.nextRoom = null; - SpotWidthCharacteristic = require('../characteristics/spotWidth')(Characteristic, CustomUUID); - SpotHeightCharacteristic = require('../characteristics/spotHeight')(Characteristic, CustomUUID); - SpotRepeatCharacteristic = require('../characteristics/spotRepeat')(Characteristic, CustomUUID); - if (typeof boundary === 'undefined') { this.name = this.robot.name; @@ -78,6 +74,10 @@ function NeatoVacuumRobotAccessory(platform, robotObject, boundary = undefined) this.scheduleService = new Service.Switch(this.name + " Schedule", "schedule"); this.findMeService = new Service.Switch(this.name + " Find Me", "findMe"); + SpotWidthCharacteristic = require('../characteristics/spotWidth')(Characteristic, CustomUUID); + SpotHeightCharacteristic = require('../characteristics/spotHeight')(Characteristic, CustomUUID); + SpotRepeatCharacteristic = require('../characteristics/spotRepeat')(Characteristic, CustomUUID); + // Spot cleaning with advanced options if ((typeof this.availableServices.spotCleaning !== 'undefined') && this.availableServices.spotCleaning.includes("basic")) { @@ -92,6 +92,7 @@ function NeatoVacuumRobotAccessory(platform, robotObject, boundary = undefined) this.spotCleanSimpleService = new Service.Switch(this.name + " Clean Spot", "cleanSpot"); this.spotCleanSimpleService.addCharacteristic(SpotRepeatCharacteristic); } + this.log("Added default cleaning device named: " + this.name); } else { @@ -101,9 +102,8 @@ function NeatoVacuumRobotAccessory(platform, robotObject, boundary = undefined) { serviceName = "Clean " + boundary.name; } - this.cleanBoundaryService = - new Service.Switch(serviceName, "cleanBoundary:" + boundary.id); - this.log("Adding zone cleaning for: " + boundary.name); + this.cleanBoundaryService = new Service.Switch(serviceName, "cleanBoundary:" + boundary.id); + this.log("Added zone cleaning for: " + boundary.name); } } @@ -632,7 +632,7 @@ NeatoVacuumRobotAccessory.prototype = { { this.platform.updateRobot(this.robot._serial, () => { - debug(this.name + ": The Dock is " + (this.robot.isDocked ? '' : 'un ') + "occupied"); + debug(this.name + ": The Dock is " + (this.robot.isDocked ? '' : 'NOT ') + "OCCUPIED"); callback(false, this.robot.isDocked ? 1 : 0); }); }, @@ -650,7 +650,7 @@ NeatoVacuumRobotAccessory.prototype = { { this.platform.updateRobot(this.robot._serial, () => { - debug(this.name + ": Battery is " + (this.robot.isCharging ? '' : 'not ') + "charging"); + debug(this.name + ": Battery is " + (this.robot.isCharging ? '' : 'NOT ') + "CHARGING"); callback(false, this.robot.isCharging); }); }, diff --git a/index.js b/index.js index 5cfb093..f0e316b 100644 --- a/index.js +++ b/index.js @@ -55,7 +55,7 @@ NeatoVacuumRobotPlatform.prototype = { { this.robots.forEach((robot, i) => { - this.log("Found robot #" + (i + 1) + " named \"" + robot.device.name + "\" with serial \"" + robot.device._serial + "\""); + this.log("Found robot #" + (i + 1) + " named \"" + robot.device.name + "\" with serial \"" + robot.device._serial.substring(0,9) + "XXXXXXXXXXXX\""); // Start Update Intervall this.updateRobotTimer(robot.device._serial); @@ -67,6 +67,11 @@ NeatoVacuumRobotPlatform.prototype = { robot.mainAccessory = mainAccessory; robot.roomAccessories = []; + // For testing purposes only + // let roomAccessory = new NeatoVacuumRobotAccessory(this, robot, {name: "Testzimmer", id: "1"}); + // accessories.push(roomAccessory); + // robot.roomAccessories.push(roomAccessory); + if (robot.device.maps) { robot.device.maps.forEach((map) => @@ -206,13 +211,13 @@ NeatoVacuumRobotPlatform.prototype = { else { debug(robot.device.name + ": ++ Updating robot state"); + robot.lastUpdate = new Date(); robot.device.getState((error, result) => { if (error) { this.log.error("Cannot update robot. Check if robot is online. " + error); } - robot.lastUpdate = new Date(); callback(); }); }