From 6e5b0d522ccee56c7fc6be7d5d9d8e305c018277 Mon Sep 17 00:00:00 2001 From: Arne Date: Mon, 14 Oct 2019 12:47:52 +0200 Subject: [PATCH] Fixed robot not shown before setting up a floor plan --- CHANGELOG.md | 5 +++- index.js | 66 +++++++++++++++++++++++++++++----------------------- package.json | 2 +- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7669d94..c41318c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -110,4 +110,7 @@ * Added logic to be able to change the currently cleaned room * Improved number of requests when having multiple rooms * Fixed room switches not taking eco and extraCare mode into account -* Fixed room switches to support pause/resume \ No newline at end of file +* Fixed room switches not supporting pause/resume + +## 0.7.1 +* Fixed robot not shown before setting up a floor plan \ No newline at end of file diff --git a/index.js b/index.js index 8aff74b..9a1f1e1 100644 --- a/index.js +++ b/index.js @@ -116,7 +116,7 @@ NeatoVacuumRobotPlatform.prototype = { } else { - // Get robots + // Get all robots client.getRobots((error, robots) => { if (error) @@ -133,11 +133,11 @@ NeatoVacuumRobotPlatform.prototype = { else { debug("Found " + robots.length + " robots"); - let requestedRobot = 0; + let loadedRobots = 0; robots.forEach((robot) => { - // Get Maps for each robot + // Get all maps for each robot robot.getPersistentMaps((error, result) => { if (error) @@ -145,18 +145,20 @@ NeatoVacuumRobotPlatform.prototype = { this.log.error("Error updating persistent maps: " + error + ": " + result); callback(); } + // Robot has no maps else if (result.length === 0) { robot.maps = []; - callback(); + this.saveRobot(robot, loadedRobots, robots.length, callback); } + // Robot has maps else { robot.maps = result; - let requestedMap = 0; + let loadedMaps = 0; robot.maps.forEach((map) => { - // Get Map Boundary Lines + // Save zones in each map robot.getMapBoundaries(map.id, (error, result) => { if (error) @@ -167,31 +169,12 @@ NeatoVacuumRobotPlatform.prototype = { { map.boundaries = result.boundaries; } - requestedMap++; + loadedMaps++; - // Robot is completely requested if all maps are requested - if (requestedMap === robot.maps.length) + // Robot is completely requested if zones for all maps are loaded + if (loadedMaps === robot.maps.length) { - // Get additional information - robot.getState((error, result) => - { - if (error) - { - this.log.error("Error getting robot meta information: " + error + ": " + result); - callback(); - } - else - { - this.robots.push({device: robot, meta: result.meta, availableServices: result.availableServices}); - requestedRobot++; - - // Initial request is complete if all robots are requested. - if (requestedRobot === robots.length) - { - callback(); - } - } - }); + this.saveRobot(robot, loadedRobots, robots.length, callback); } }) }); @@ -204,6 +187,31 @@ NeatoVacuumRobotPlatform.prototype = { }); }, + saveRobot: function (robot, loadedRobots, size, callback) + { + // Get additional information for the robot + robot.getState((error, result) => + { + if (error) + { + this.log.error("Error getting robot meta information: " + error + ": " + result); + callback(); + } + else + { + // Store the robot with his information, maps and zones + this.robots.push({device: robot, meta: result.meta, availableServices: result.availableServices}); + loadedRobots++; + + // Initial request is complete if all robots are loaded. + if (loadedRobots === size) + { + callback(); + } + } + }); + }, + updateRobot: function (serial, callback) { let robot = this.getRobot(serial); diff --git a/package.json b/package.json index 72b925b..178fd63 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-neato", - "version": "0.7.0", + "version": "0.7.1-beta.1", "description": "A Neato vacuum robot plugin for homebridge.", "license": "MIT", "keywords": [