nkgilley / python-ecobee-api

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

Add token_refresh logic to request calls #71

Closed bjpetit closed 2 years ago

bjpetit commented 2 years ago

I'd like to propose a change where refresh_tokens can be called from within the library's request calls. The following code will watch for an ExpiredTokenError. If this exception is seen the request call will kick the refresh_tokens and try the request again. If the second call fails the exception will be passed up the stack. This is handled by a wrapper function around the _request call. This way the authentication and token handling can still use the existing logic.

This change handles much of the token expiration behind the scenes, eliminating many of the issues when expired tokens can sit waiting until the next refresh to renew those tokens.

This PR also bumps up the requests version in the install_requires list. The existing version 2.0 is about 8 years old.

nkgilley commented 2 years ago

Thanks, @bjpetit!

I just pushed 0.2.14 to pypi. It includes this and the precision update.

bjpetit commented 2 years ago

Awesome. Thanks @nkgilley !