Fixed robot not shown before setting up a floor plan

This commit is contained in:
Arne 2019-10-14 12:47:52 +02:00
parent 9af5fe8a26
commit 6e5b0d522c
3 changed files with 42 additions and 31 deletions

View File

@ -110,4 +110,7 @@
* Added logic to be able to change the currently cleaned room * Added logic to be able to change the currently cleaned room
* Improved number of requests when having multiple rooms * Improved number of requests when having multiple rooms
* Fixed room switches not taking eco and extraCare mode into account * Fixed room switches not taking eco and extraCare mode into account
* Fixed room switches to support pause/resume * Fixed room switches not supporting pause/resume
## 0.7.1
* Fixed robot not shown before setting up a floor plan

View File

@ -116,7 +116,7 @@ NeatoVacuumRobotPlatform.prototype = {
} }
else else
{ {
// Get robots // Get all robots
client.getRobots((error, robots) => client.getRobots((error, robots) =>
{ {
if (error) if (error)
@ -133,11 +133,11 @@ NeatoVacuumRobotPlatform.prototype = {
else else
{ {
debug("Found " + robots.length + " robots"); debug("Found " + robots.length + " robots");
let requestedRobot = 0; let loadedRobots = 0;
robots.forEach((robot) => robots.forEach((robot) =>
{ {
// Get Maps for each robot // Get all maps for each robot
robot.getPersistentMaps((error, result) => robot.getPersistentMaps((error, result) =>
{ {
if (error) if (error)
@ -145,18 +145,20 @@ NeatoVacuumRobotPlatform.prototype = {
this.log.error("Error updating persistent maps: " + error + ": " + result); this.log.error("Error updating persistent maps: " + error + ": " + result);
callback(); callback();
} }
// Robot has no maps
else if (result.length === 0) else if (result.length === 0)
{ {
robot.maps = []; robot.maps = [];
callback(); this.saveRobot(robot, loadedRobots, robots.length, callback);
} }
// Robot has maps
else else
{ {
robot.maps = result; robot.maps = result;
let requestedMap = 0; let loadedMaps = 0;
robot.maps.forEach((map) => robot.maps.forEach((map) =>
{ {
// Get Map Boundary Lines // Save zones in each map
robot.getMapBoundaries(map.id, (error, result) => robot.getMapBoundaries(map.id, (error, result) =>
{ {
if (error) if (error)
@ -167,31 +169,12 @@ NeatoVacuumRobotPlatform.prototype = {
{ {
map.boundaries = result.boundaries; map.boundaries = result.boundaries;
} }
requestedMap++; loadedMaps++;
// Robot is completely requested if all maps are requested // Robot is completely requested if zones for all maps are loaded
if (requestedMap === robot.maps.length) if (loadedMaps === robot.maps.length)
{ {
// Get additional information this.saveRobot(robot, loadedRobots, robots.length, callback);
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();
}
}
});
} }
}) })
}); });
@ -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) updateRobot: function (serial, callback)
{ {
let robot = this.getRobot(serial); let robot = this.getRobot(serial);

View File

@ -1,6 +1,6 @@
{ {
"name": "homebridge-neato", "name": "homebridge-neato",
"version": "0.7.0", "version": "0.7.1-beta.1",
"description": "A Neato vacuum robot plugin for homebridge.", "description": "A Neato vacuum robot plugin for homebridge.",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [