Use ConfigFlow.has_matching_flow to deduplicate webostv flows (#126898)

This commit is contained in:
Erik Montnemery 2024-09-27 23:11:15 +02:00 committed by GitHub
parent 1044345587
commit 6c1167df4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from collections.abc import Mapping from collections.abc import Mapping
import logging import logging
from typing import Any from typing import Any, Self
from urllib.parse import urlparse from urllib.parse import urlparse
from aiowebostv import WebOsTvPairError from aiowebostv import WebOsTvPairError
@ -92,7 +92,6 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
"""Display pairing form.""" """Display pairing form."""
self._async_check_configured_entry() self._async_check_configured_entry()
self.context[CONF_HOST] = self._host
self.context["title_placeholders"] = {"name": self._name} self.context["title_placeholders"] = {"name": self._name}
errors = {} errors = {}
@ -130,13 +129,16 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
await self.async_set_unique_id(uuid) await self.async_set_unique_id(uuid)
self._abort_if_unique_id_configured({CONF_HOST: self._host}) self._abort_if_unique_id_configured({CONF_HOST: self._host})
for progress in self._async_in_progress(): if self.hass.config_entries.flow.async_has_matching_flow(self):
if progress.get("context", {}).get(CONF_HOST) == self._host:
return self.async_abort(reason="already_in_progress") return self.async_abort(reason="already_in_progress")
self._uuid = uuid self._uuid = uuid
return await self.async_step_pairing() return await self.async_step_pairing()
def is_matching(self, other_flow: Self) -> bool:
"""Return True if other_flow is matching this flow."""
return other_flow._host == self._host # noqa: SLF001
async def async_step_reauth( async def async_step_reauth(
self, entry_data: Mapping[str, Any] self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult: ) -> ConfigFlowResult: