Use ConfigFlow.has_matching_flow to deduplicate gogogate2 flows (#126892)

This commit is contained in:
Erik Montnemery 2024-09-27 11:45:17 +02:00 committed by GitHub
parent 8bdd909351
commit b34f3ad5c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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:
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: