nkgilley / python-ecobee-api

Python API for controlling Ecobee Thermostats
MIT License
44 stars 40 forks source link

HASS config flow refactoring #41

Closed marthoc closed 5 years ago

marthoc commented 5 years ago

Here's a first wave of changes that I thought were needed to support the Home Assistant config flow. Mostly, I've added constants for some of the config dict keys and changed the auth methods (request_pin, request_tokens, and refresh_tokens) to return bool so we can easily test if the flow can continue. As mentioned in #40, I removed some of the stray sync calls from init and the request/refresh methods. I also added an exception called ExpiredTokenError that the get_thermostats() method raises if the response code indicates a possible expired token, so that in HASS we can catch it and attempt a refresh, then update the config entry with the new refresh_token if successful.

It also seemed to me that the make_request method was not testing for all response codes - in my testing the API may also return 400 when the token has become invalid and could be refreshed, not only 401, so I'm not sure if the retry code had previously been always working or not.

I don't care about the version number, you can make it whatever you like eventually, I just needed to change it for using in HASS.