From 316dfa90363828de3443d1e56767ca3ac256c207 Mon Sep 17 00:00:00 2001 From: Jordy van den Aardweg Date: Tue, 24 Jan 2023 14:25:17 +0100 Subject: [PATCH] feat: return last known speed value when http api is not reachable --- src/fan-accessory.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/fan-accessory.ts b/src/fan-accessory.ts index f2d88a7..d8cefd1 100644 --- a/src/fan-accessory.ts +++ b/src/fan-accessory.ts @@ -530,12 +530,17 @@ export class FanAccessory { try { rotationSpeedNumber = await this.httpApiClient.getSpeed(); } catch (error) { + // If we can't get the speed from the Itho Wifi module, we'll return the last known speed + // This is to prevent HomeKit from showing an error when the Itho Wifi module is offline or the wifi connection is unstable + // Will default to 0 if no last known speed is available + const lastKnownSpeed = this.lastStatePayload || 0; + this.log.error( - 'Failed to get RotationSpeed from the Itho Wifi module. Make sure the Itho Wifi module has a stable wifi connection and try again. Will return 0 as the RotationSpeed for now.', + `Failed to get RotationSpeed from the Itho Wifi module. Make sure the Itho Wifi module has a stable wifi connection and try again. Will return the last known RotationSpeed of ${lastKnownSpeed} for now.`, JSON.stringify(error), ); - return 0; + rotationSpeedNumber = lastKnownSpeed; } }