You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jotting down a few notes for ways to make auth a bit better with the HA integration:
Fix where NotAuthorizedError is handled in config_flow. It's raised from the Auth class, but we're testing that it comes from the Hydrawise class. (PR sending soon)
Change the config entry unique_id to be based on user.id instead of user.customer_id. We can obtain user.id from the JWT's access_token using jwt.decode(access_token, "", verify=False, options={"verify_signature": False}, algorithms=["HS256"])["sub"]. This would remove a round-trip to the Hydrawise API for grabbing the user during config flow init. We'll need a config version migration to accomplish this, because we need to change the unique_id for the config entries.
Pass a ClientSession to the Hydrawise class. HA creates one that's meant to be used by all clients. We should make use of this instead of managing it ourselves.
Make the Auth class compliant with HA's OAuth refresh mechanism. I need to read through the code a bit more (because the documentation isn't great) but my understanding is that HA should be able to handle token refreshes on our behalf.
The text was updated successfully, but these errors were encountered:
Note that fixing (2) will help reduce the number of throttling errors--particularly on HA restarts where we need an extra call to initialize the integration.
Jotting down a few notes for ways to make auth a bit better with the HA integration:
NotAuthorizedError
is handled in config_flow. It's raised from theAuth
class, but we're testing that it comes from theHydrawise
class. (PR sending soon)unique_id
to be based onuser.id
instead ofuser.customer_id
. We can obtainuser.id
from the JWT's access_token usingjwt.decode(access_token, "", verify=False, options={"verify_signature": False}, algorithms=["HS256"])["sub"]
. This would remove a round-trip to the Hydrawise API for grabbing the user during config flow init. We'll need a config version migration to accomplish this, because we need to change theunique_id
for the config entries.ClientSession
to theHydrawise
class. HA creates one that's meant to be used by all clients. We should make use of this instead of managing it ourselves.Auth
class compliant with HA's OAuth refresh mechanism. I need to read through the code a bit more (because the documentation isn't great) but my understanding is that HA should be able to handle token refreshes on our behalf.The text was updated successfully, but these errors were encountered: