Fix check for duplicate config entry reauth when context is passed or augmented (#81753)

fixes https://github.com/home-assistant/core/issues/77578
This commit is contained in:
J. Nick Koston
2022-11-07 21:19:57 -06:00
committed by GitHub
parent 785cf0e29c
commit c2c26e2608
2 changed files with 29 additions and 15 deletions

View File

@@ -660,24 +660,25 @@ class ConfigEntry:
data: dict[str, Any] | None = None,
) -> None:
"""Start a reauth flow."""
flow_context = {
"source": SOURCE_REAUTH,
"entry_id": self.entry_id,
"title_placeholders": {"name": self.title},
"unique_id": self.unique_id,
}
if context:
flow_context.update(context)
for flow in hass.config_entries.flow.async_progress_by_handler(self.domain):
if flow["context"] == flow_context:
return
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
):
# Reauth flow already in progress for this entry
return
hass.async_create_task(
hass.config_entries.flow.async_init(
self.domain,
context=flow_context,
context={
"source": SOURCE_REAUTH,
"entry_id": self.entry_id,
"title_placeholders": {"name": self.title},
"unique_id": self.unique_id,
}
| (context or {}),
data=self.data | (data or {}),
)
)