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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Reauth flow to Wallbox integration #58743

Merged
merged 11 commits into from Nov 15, 2021

Conversation

hesselonline
Copy link
Contributor

@hesselonline hesselonline commented Oct 30, 2021

Proposed change

I'm adding a reauthentication flow to the wallbox component. It's triggered by an HTML 403 error (so that will usually be a password change). The flow is triggered by calling ConfigEntryAuthFailed from the authentication method of the Wallbox class.

Type of change

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

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • [X ] The code change is tested and works locally.
  • [X ] Local tests pass. Your PR cannot be merged unless tests pass
  • [X ] There is no commented out code in this PR.
  • [X ] I have followed the development checklist
  • [X ] The code has been formatted using Black (black --fast homeassistant tests)
  • [X ] 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:

  • [X ] 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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 馃 Silver
  • 馃 Gold
  • 馃弳 Platinum

To help with the load of incoming pull requests:

@project-bot project-bot bot added this to Needs review in Dev Oct 30, 2021
@project-bot project-bot bot moved this from Needs review to By Code Owner in Dev Oct 30, 2021
@hesselonline hesselonline marked this pull request as ready for review October 30, 2021 18:25
@hesselonline
Copy link
Contributor Author

@bdraco I added the discussed reauth flow to the wallbox component in this PR. Maybe you have time for a quick review? Thnx

Compensating for timedrift in my devcontainer,
making a new commit with the right date/time. Requested changes
were done in a previous commit.
Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Looks good. One small comment about how to tell the user the reauth doesn't match

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Please resolve conflicts. Thanks 馃憤

Dev automation moved this from By Code Owner to Review in progress Nov 2, 2021
@bdraco
Copy link
Member

bdraco commented Nov 2, 2021

Test failure is unrelated. I'll restart the CI

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

One small tweak, and this looks good to merge 馃憤

Co-authored-by: J. Nick Koston <nick@koston.org>
Dev automation moved this from Review in progress to Reviewer approved Nov 15, 2021
@bdraco bdraco merged commit a4208c0 into home-assistant:dev Nov 15, 2021
Dev automation moved this from Reviewer approved to Done Nov 15, 2021
natekspencer pushed a commit to natekspencer/home-assistant-core that referenced this pull request Nov 15, 2021
* Add Reauth flow to Wallbox integration

* Review comments processed

* Fixed tests

* Added test for reauth invalid

* Commit to compensate for timedrift, show changes
Compensating for timedrift in my devcontainer,
making a new commit with the right date/time. Requested changes
were done in a previous commit.

* remove reauth schema

* Update homeassistant/components/wallbox/__init__.py

Co-authored-by: J. Nick Koston <nick@koston.org>

Co-authored-by: J. Nick Koston <nick@koston.org>
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Please address the comments in a new PR. Thanks!

@@ -47,14 +59,27 @@ async def async_step_user(self, user_input=None):
errors = {}

try:
info = await validate_input(self.hass, user_input)
await self.async_set_unique_id(user_input["station"])
Copy link
Member

Choose a reason for hiding this comment

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

Please only wrap the lines that can raise in the try... except block.


return self.async_show_form(
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
step_id="user",
data_schema=STEP_USER_DATA_SCHEMA,
Copy link
Member

Choose a reason for hiding this comment

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

Normally we should only ask the user for the required info to re-authenticate in the reauth flow. We shouldn't ask the user again for info that should stay the same like station id.

info = await validate_input(self.hass, user_input)
return self.async_create_entry(title=info["title"], data=user_input)
if user_input["station"] == self._reauth_entry.data[CONF_STATION]:
self.hass.config_entries.async_update_entry(
Copy link
Member

Choose a reason for hiding this comment

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

We should validate the new credentials in the reauth flow before updating the config entry data.

@@ -7,15 +7,23 @@
"username": "[%key:common::config_flow::data::username%]",
"password": "[%key:common::config_flow::data::password%]"
}
},
"reauth_confirm": {
Copy link
Member

Choose a reason for hiding this comment

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

We're missing this step.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants