From c43a666378689a1857424c836d5cc846c7053601 Mon Sep 17 00:00:00 2001 From: Arne Date: Wed, 14 Aug 2019 23:06:03 +0200 Subject: [PATCH] Fixed homebridge crash when homebridge has no internet connection or the neato servers are offline --- index.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index bb7ea5c..55fac75 100644 --- a/index.js +++ b/index.js @@ -40,21 +40,23 @@ NeatoVacuumRobotPlatform.prototype = { let that = this; this.getRobots(function () { - for (let i = 0; i < that.robots.length; i++) { - that.log("Found robot #" + (i + 1) + " named \"" + that.robots[i].name + "\" with serial \"" + that.robots[i]._serial + "\""); - let robotAccessory = new NeatoVacuumRobotAccessory(that.robots[i], that); - accessories.push(robotAccessory); - if (that.robots[i].maps) { - that.robots[i].maps.forEach((map) => { - if (map.boundaries) { - map.boundaries.forEach((boundary) => { - if (boundary.type === "polygon") { - accessories.push(new NeatoVacuumRobotAccessory(that.robots[i], that, boundary)) - } - }) - } - }) - } + if (that.robots) { + that.robots.forEach((robot, i) => { + that.log("Found robot #" + (i + 1) + " named \"" + robot.name + "\" with serial \"" + robot._serial + "\""); + let robotAccessory = new NeatoVacuumRobotAccessory(robot, that); + accessories.push(robotAccessory); + if (robot.maps) { + robot.maps.forEach((map) => { + if (map.boundaries) { + map.boundaries.forEach((boundary) => { + if (boundary.type === "polygon") { + accessories.push(new NeatoVacuumRobotAccessory(robot, that, boundary)) + } + }) + } + }) + } + }) } callback(accessories); }); @@ -67,7 +69,7 @@ NeatoVacuumRobotPlatform.prototype = { client.authorize(this.email, this.password, false, (error) => { if (error) { that.log(error); - that.log.error("Can't log on to neato cloud. Please check your credentials."); + that.log.error("Can't log on to neato cloud. Please check your internet connection and your credentials. Try again later if the neato servers have issues."); callback(); } else { client.getRobots((error, robots) => {