Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Authentication Cleanups #242

Open
dknowles2 opened this issue Dec 9, 2024 · 2 comments
Open

Authentication Cleanups #242

dknowles2 opened this issue Dec 9, 2024 · 2 comments
Labels
cleanup Code hygiene improvement

Comments

@dknowles2
Copy link
Owner

Jotting down a few notes for ways to make auth a bit better with the HA integration:

  1. 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)
  2. 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.
  3. 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.
  4. 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.
@dknowles2 dknowles2 added the cleanup Code hygiene improvement label Dec 9, 2024
@dknowles2
Copy link
Owner Author

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.

@dknowles2
Copy link
Owner Author

Also, (3) needs to happen for both the Auth and Hydrawise classes, as they both use aiohttp.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
cleanup Code hygiene improvement
Projects
None yet
Development

No branches or pull requests

1 participant