apetrycki / daikinskyport

API for accessing a DaikinOne+ Thermostat
59 stars 26 forks source link

Quick for issue #89 #92

Closed ufodone closed 5 months ago

ufodone commented 5 months ago

Catch token expiry exceptions during startup and ensure that it retries until the token is able to be refreshed.

I think there is some other cleanup that could happen in terms of how token refreshes and state updates are handles that would prevent this situation but this PR will at least catch the scenario and ensure the HA will keep retrying setup of the integration until the the Daikin servers are responding successfully.

The issue appears to be triggered when the Daikin servers return multiple error responses (e.g. 500 errors when their servers are having troubles or undergoing maintenance). In this scenario, the token refresh and integration reload that happens in the exception handler of _async_update_data will itself throw an exception and prevent async_setup_entry from succeeding.

This change catches that exception and re-throws a ConfigEntryNotReady exception which tells HA core to re-attempt setup in the future.