Skip to content

Wallbox Integration, Reduce API impact by limiting the amount of API calls made #147618

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

Merged
merged 17 commits into from
Jun 30, 2025

Conversation

hesselonline
Copy link
Contributor

@hesselonline hesselonline commented Jun 26, 2025

Proposed change

After a meeting with the Wallbox software team, it was agreed upon that we would try to limit the no of API requests necessary in the integration. This PR does so by:

  1. re-using the response of post requests, thus removing the need for an update_data call
  2. removing some pre-setup checks, these were always nice-to-have at best.

Resulting test errors have been fixed, also, a missing mock for both the select and switch test has been added to ensure code coverage.

  • 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

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft June 27, 2025 17:47
@frenck frenck requested a review from Copilot June 27, 2025 17:47
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR reduces the number of API calls made by the Wallbox integration by reusing post request responses and removing redundant pre-setup checks. Key changes include updating the API call handling in the coordinator, revising the post response handling for number and lock entities, and adjusting tests to match the new API interaction patterns.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/components/wallbox/test_switch.py Added patch for getChargerStatus to support reusing API post responses.
tests/components/wallbox/test_select.py Updated tests to patch getChargerStatus with new response structures based on mode.
tests/components/wallbox/test_number.py Modified mocks to reflect nested response structures and updated test function naming.
tests/components/wallbox/test_lock.py Updated lock tests to match the new response format from lockCharger and unlockCharger.
homeassistant/components/wallbox/number.py Removed redundant pre-setup checks and streamlined error handling.
homeassistant/components/wallbox/lock.py Removed pre-setup authorization checks for lock actions.
homeassistant/components/wallbox/coordinator.py Refactored setter methods to return updated data and use async_set_updated_data; revised error handling.
homeassistant/components/wallbox/const.py Added new keys for parsing nested post responses.
Comments suppressed due to low confidence (1)

tests/components/wallbox/test_number.py:293

  • [nitpick] Ensure consistent naming for tests and API method references. The switch from 'setIcpMaxCurrent' to 'setMaxChargingCurrent' in test names might confuse readers; consider aligning the naming consistently across tests to reflect the unified API.
async def test_wallbox_number_class_icp_energy_auth_error(

@hesselonline hesselonline marked this pull request as ready for review June 27, 2025 18:36
@home-assistant home-assistant bot requested a review from frenck June 27, 2025 18:36
Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Thanks, @hesselonline 👍

../Frenck

@frenck frenck merged commit 90cbe27 into home-assistant:dev Jun 30, 2025
34 checks passed
frenck pushed a commit that referenced this pull request Jun 30, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jul 1, 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.

2 participants