From 7a0758f88370e1476ae98b57b22dc7abe3118086 Mon Sep 17 00:00:00 2001 From: Arne Blumentritt Date: Thu, 6 May 2021 10:15:53 +0200 Subject: [PATCH] Added retrying mechanism --- CHANGELOG.md | 6 +++--- package-lock.json | 2 +- package.json | 2 +- src/accessories/neatoVacuumRobot.ts | 4 +++- src/homebridgeNeatoPlatform.ts | 26 +++++++++++++++++++------- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35c8745..d2ded30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,10 +121,11 @@ ## 0.7.3 * Fixed warnings since homebridge 1.3.0 -## 1.0.0-beta.1 +## 1.0.0-beta.4 * Added bin full sensor * Added config-ui support for all options * Added config parameter **prefix** to use robot name as prefix for service names +* Retrying mechanism if a robot is not available on homebridge launch * Changed service names to not include robot name as prefix by default * Changed background update to use better default intervals (1 minute while cleaning, 30 minutes while idle) * Changed config parameter **refresh**. Renamed to **backgroundUpdate**, unit changed to minute and will only be used during idle @@ -135,5 +136,4 @@ ## TODO until 1.0.0 release * Room cleaning -* Spot size -* Retrying when no connection \ No newline at end of file +* Spot size \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 38ade6e..d41f284 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "homebridge-neato", - "version": "1.0.0-beta.1", + "version": "1.0.0-beta.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4439ac9..a3c0323 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "homebridge-neato", "displayName": "Homebridge Neato", - "version": "1.0.0-beta.3", + "version": "1.0.0-beta.4", "description": "A Neato vacuum robot plugin for homebridge.", "license": "MIT", "keywords": [ diff --git a/src/accessories/neatoVacuumRobot.ts b/src/accessories/neatoVacuumRobot.ts index 2e86e0b..9b79d6b 100644 --- a/src/accessories/neatoVacuumRobot.ts +++ b/src/accessories/neatoVacuumRobot.ts @@ -67,6 +67,8 @@ export class NeatoVacuumRobotAccessory // Identify this.accessory.on(PlatformAccessoryEvent.IDENTIFY, () => { + this.robot.findMe(); + this.robot.getState((error, result) => { this.log.info("[" + this.robot.name + "] Identified"); if (error) @@ -329,7 +331,7 @@ export class NeatoVacuumRobotAccessory { this.goToDockService.updateCharacteristic(this.platform.Characteristic.On, false); } - }, 1000); + }, 10000); try { diff --git a/src/homebridgeNeatoPlatform.ts b/src/homebridgeNeatoPlatform.ts index eb8ca7d..d4b9c7e 100644 --- a/src/homebridgeNeatoPlatform.ts +++ b/src/homebridgeNeatoPlatform.ts @@ -36,10 +36,11 @@ export class HomebridgeNeatoPlatform implements DynamicPlatformPlugin this.cachedRobotAccessories.push(accessory); } + discoverRobots() { const client = new NeatoApi.Client(); - + this.log.debug("blub"); try { @@ -47,9 +48,12 @@ export class HomebridgeNeatoPlatform implements DynamicPlatformPlugin client.authorize((this.config)["email"], (this.config)["password"], false, (error) => { if (error) { - this.log.warn("Cannot connect to neato server. No new robots will be found and existing robots will be unresponsive."); - this.log.warn(error); - // TODO retry after x min + this.log.error("Cannot connect to neato server. No new robots will be found and existing robots will be unresponsive. Retrying in 5 minutes."); + this.log.error("Error: " + error); + + setTimeout(() => { + this.discoverRobots(); + }, 5 * 60 * 1000); return; } @@ -57,8 +61,12 @@ export class HomebridgeNeatoPlatform implements DynamicPlatformPlugin client.getRobots((error, robots) => { if (error) { - this.log.error("Successful login but can't list your neato robots. Error: " + error); - // TODO retry after x min + this.log.error("Successful login but can't list the robots in your neato robots. Retrying in 5 minutes."); + this.log.error("Error: " + error); + + setTimeout(() => { + this.discoverRobots(); + }, 5 * 60 * 1000); return; } @@ -107,7 +115,11 @@ export class HomebridgeNeatoPlatform implements DynamicPlatformPlugin robot.getState((error, state) => { if (error) { - this.log.error("[" + robot.name + "] Cannot connect to robot. Is the robot connected to the internet? Error: " + error + ". State: " + state); + this.log.error("[" + robot.name + "] Cannot connect to robot. Is the robot connected to the internet? Retrying in 5 minutes."); + this.log.error("Error: " + error); + setTimeout(() => { + this.discoverRobots(); + }, 5 * 60 * 1000); } else {