From b34f3ad5c51b3409cd938a3a091244a42abde6b7 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Fri, 27 Sep 2024 11:45:17 +0200 Subject: [PATCH] Use ConfigFlow.has_matching_flow to deduplicate gogogate2 flows (#126892) --- homeassistant/components/gogogate2/config_flow.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/gogogate2/config_flow.py b/homeassistant/components/gogogate2/config_flow.py index cd9ca21b063..837c0454719 100644 --- a/homeassistant/components/gogogate2/config_flow.py +++ b/homeassistant/components/gogogate2/config_flow.py @@ -4,7 +4,7 @@ from __future__ import annotations import dataclasses import re -from typing import Any +from typing import Any, Self from ismartgate.common import AbstractInfoResponse, ApiError from ismartgate.const import GogoGate2ApiErrorCode, ISmartGateApiErrorCode @@ -57,19 +57,21 @@ class Gogogate2FlowHandler(ConfigFlow, domain=DOMAIN): async def _async_discovery_handler(self, ip_address: str) -> ConfigFlowResult: """Start the user flow from any discovery.""" - self.context[CONF_IP_ADDRESS] = ip_address self._abort_if_unique_id_configured({CONF_IP_ADDRESS: ip_address}) self._async_abort_entries_match({CONF_IP_ADDRESS: ip_address}) self._ip_address = ip_address - for progress in self._async_in_progress(): - if progress.get("context", {}).get(CONF_IP_ADDRESS) == self._ip_address: - raise AbortFlow("already_in_progress") + if self.hass.config_entries.flow.async_has_matching_flow(self): + raise AbortFlow("already_in_progress") self._device_type = DEVICE_TYPE_ISMARTGATE return await self.async_step_user() + def is_matching(self, other_flow: Self) -> bool: + """Return True if other_flow is matching this flow.""" + return other_flow._ip_address == self._ip_address # noqa: SLF001 + async def async_step_user( self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: