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 re-auth flow for OpenUV #79691
Add re-auth flow for OpenUV #79691
Conversation
Marking as draft until #80705 is merged. |
ef564fd
to
db40d4a
Compare
@callback | ||
def _get_active_reauth_flow(self) -> FlowResult | None: | ||
"""Get an active reauth flow (if it exists).""" | ||
try: | ||
[reauth_flow] = [ | ||
flow | ||
for flow in self.hass.config_entries.flow.async_progress_by_handler( | ||
DOMAIN | ||
) | ||
if flow["context"]["source"] == "reauth" | ||
and flow["context"]["entry_id"] == self.entry.entry_id | ||
] | ||
except ValueError: | ||
return None | ||
|
||
return reauth_flow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like we could move this into the base config_entries class as #81753 will make it do the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a follow PR we could replace https://github.com/home-assistant/core/pull/81753/files#diff-bcb932c3549daf52e1d6d8b02211ed0cc15557f5d17968f33a9daacf7ddac81bR663 with something like this code that yielded matching config entries than we could call that new function from both places and eliminate the duplicate code between here and the config_entries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify the recommendation? Wait for #81753, roll forward with this, then do a follow-on PR with your second comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this now and and then in a followup it would be good to make a new function that in homeassistant/config_entries.py
that takes
if any(
flow
for flow in hass.config_entries.flow.async_progress()
if flow["context"].get("source") == SOURCE_REAUTH
and flow["context"].get("entry_id") == self.entry_id
)
and
try:
[reauth_flow] = [
flow
for flow in self.hass.config_entries.flow.async_progress_by_handler(
DOMAIN
)
if flow["context"]["source"] == "reauth"
and flow["context"]["entry_id"] == self.entry.entry_id
]
except ValueError:
return None
and makes a new function in homeassistant/config_entries.py
that yields matching flows (I should have left it as async_progress_by_handler as it would have been a bit more efficient) which both places can call instead of writing it out.
Proposed change
This PR adds a re-auth flow to OpenUV.
There is a peculiarity to keep in mind. The OpenUV API will, at times, return an
HTTP 401/403
instead of anHTTP 5xx
when there is a service issue (which eventually corrects itself). Thus, it isn't always clear whetherHTTP 401/403
represents a service issue or an invalid API key. Therefore, the PR does the following:HTTP 401/403
.HTTP 200
response after the re-auth flow has been created, we assume that the priorHTTP 401/403
responses were a service issue and abort the re-auth flow.Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: