Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use the new hybrid Hydrawise client #136522

Merged
merged 3 commits into from
Jan 29, 2025

Conversation

dknowles2
Copy link
Contributor

Breaking change

Hydrawise now requires an API key for authentication.

In order to alleviate API throttling issues, we now fall back on the REST API when polling for status updates. This requires an API key, which can be generated under the "Account Details" section of the Hydrawise app.

Proposed change

After a lot of back-and-forth with a Hydrawise Product Manager, we have determined that we cannot poll the newer GraphQL API for updates, as it's not able to handle the load. (See #130857 (comment) for a snippet of the conversation)

This PR changes the Hydrawise client to the new "hybrid" approach added in pydrawise 2025.1.0 (see dknowles2/pydrawise#257 for details). This new client hides the details of which API we need to use for fetching data, allowing Home Assistant to use the same client interface. This should be a drop-in replacement, except for now requiring an API key for authenticating with the REST API.

The transition should be relatively smooth for a user: we simply trigger a reauth flow if the user is missing an API key, after which the integration should continue working normally.

(Note: I haven't updated the docs yet, I'll do that soon)

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @thomaskistler, @ptcryan, mind taking a look at this pull request as it has been labeled with an integration (hydrawise) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of hydrawise can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign hydrawise Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@@ -63,7 +63,7 @@ def mock_pydrawise(
controller_water_use_summary: ControllerWaterUseSummary,
) -> Generator[AsyncMock]:
"""Mock Hydrawise."""
with patch("pydrawise.client.Hydrawise", autospec=True) as mock_pydrawise:
with patch("pydrawise.hybrid.HybridClient", autospec=True) as mock_pydrawise:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we start patching this where we use the objects? so homeassistant.components.hydrawise.....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a big change because every test that uses the mock would need to do its own patching. (we import the pydrawise client in both __init__.py and config_flow.py)

Mind if I send a separate cleanup PR for that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but you can just create a way to mock both with the same mock. Check airgradient for example

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
@dknowles2 dknowles2 requested a review from joostlek January 29, 2025 01:25
@joostlek joostlek merged commit b73203f into home-assistant:dev Jan 29, 2025
32 checks passed
@wgumaa
Copy link

wgumaa commented Jan 29, 2025

Thanks for this. Will this be in the next core update?

zxdavb pushed a commit to zxdavb/hass that referenced this pull request Jan 29, 2025
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hydrawise still giving error 429 - too many poll requests
3 participants