Skip to content

Commit

Permalink
feat: return last known speed value when http api is not reachable
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandenaardweg committed Jan 24, 2023
1 parent a4516fd commit 316dfa9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/fan-accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 316dfa9

Please sign in to comment.