Vortec4800 / homebridge-ecobee-away

Homebridge plugin to access or set the Ecobee's home and away status
Apache License 2.0
6 stars 5 forks source link

Harden plugin against Ecobee outages #14

Closed powellcj12 closed 2 years ago

powellcj12 commented 2 years ago

Earlier this week, there was an outage in Ecobee thermostat online services - see here. During the outage, this plugin was continually crashing and bringing down the entire Homebridge instance:

[Ecobee Away] Renewing auth token
TypeError: Cannot read properties of undefined
    <callstack>
Got SIGTERM, shutting down Homebridge...

These changes harden the plugin against such outages so that it doesn't crash and bring down all of Homebridge.

The original issue was that while an error was caught when attempting to renew the auth token, in the catch block it was expecting a certain type of object that wasn't always the case. I remedied this by just logging the entire error object instead of specific properties. While testing it also seemed that this could have the effect of replacing the refresh token with some undefined value so for that I figured we might as well keep the old refresh token around to use again later in the hopes that the Ecobee API starts responding again.

Beyond that, fetching the accessory status from the Ecobee API would also cause a crash because we'd again end up with unexpected types in the response data. I checked for that and opted to just return 'home' state though really I think it would be better for the accessory to claim it can't respond (for another change).

Testing:

powellcj12 commented 2 years ago

I'll likely submit another PR to resolve the build issues (unrelated to these changes, seemingly stem from the package log updates).

[Edit] See #15, that'll take precedence over at least one of the changes I have here so should wait to merge that in.

Vortec4800 commented 2 years ago

Now that #15 is merged, go ahead and update this with the remaining necessary part, I think just the old token fallback you have there. Then we can merge this one too and cut a new release.

powellcj12 commented 2 years ago

@Vortec4800 should be all set now - anything else you'd like?

Vortec4800 commented 2 years ago

Sorry, busy at work. We're good to go.