Repository: home-assistant/core
File: homeassistant/components/homee/config_flow.py (Python)

Code before:
            errors=errors,
        )

    async def async_step_zeroconf(
        self, discovery_info: ZeroconfServiceInfo
    ) -> ConfigFlowResult:
        """Handle zeroconf discovery."""

        # Ensure that an IPv4 address is received
        self._host = discovery_info.host
        self._name = discovery_info.hostname[6:18]
        if discovery_info.ip_address.version == 6:
            return self.async_abort(reason="ipv6_address")

        # If an already configured homee reports with a second IP, abort.
        existing_entry: HomeeConfigEntry | None = await self.async_set_unique_id(
            self._name
        )
        if (
            existing_entry
            and existing_entry.runtime_data.connected
            and existing_entry.data[CONF_HOST] != self._host
        ):
            _LOGGER.debug(
                "Aborting config flow for discovered homee with IP %s"
                "since it is already configured at IP %s",
                self._host,
                existing_entry.data[CONF_HOST],
            )
            return self.async_abort(reason="2nd_ip_address")

        self._abort_if_unique_id_configured(updates={CONF_HOST: self._host})

        # Cause an auth-error to see if homee is reachable.
        self.homee = Homee(
            self._host,
            "dummy_username",
            "dummy_password",
        )
        errors = await self._connect_homee()
        if errors["base"] != RESULT_INVALID_AUTH:
            return self.async_abort(reason=RESULT_CANNOT_CONNECT)

        self.context["title_placeholders"] = {"name": self._name, "host": self._host}

        return await self.async_step_zeroconf_confirm()

    async def async_step_zeroconf_confirm(
        self, user_input: dict[str, Any] | None = None
    ) -> ConfigFlowResult:
        """Confirm the configuration of the device."""

Review comment (suggestion):
I think, instead of building your own logic, you could use maybe the `_async_abort_entries_match` method? It really does what the name of method calls it: aborting when entries match. For instance code can be made like such:

```py
self._async_abort_entries_match(
            {CONF_HOST: user_input[CONF_HOST]}
        )
```

If I understand your config flow well, this is basically what you want to prevent. If you this is applicable to you, please adapt your code and that will make it perfectly in line with other integrations and methods the Core has to offer. :)

Code after:

        return self.async_show_form(
            step_id="user",
            data_schema=AUTH_SCHEMA,
            errors=errors,
        )

    async def async_step_zeroconf(
        self, discovery_info: ZeroconfServiceInfo
    ) -> ConfigFlowResult:
        """Handle zeroconf discovery."""

        # Ensure that an IPv4 address is received
        self._host = discovery_info.host
        self._name = discovery_info.hostname[6:18]
        if discovery_info.ip_address.version == 6:
            return self.async_abort(reason="ipv6_address")

        # If an already configured homee reports with a second IP, abort.
        existing_entry = await self.async_set_unique_id(self._name)
        if (
            existing_entry
            and existing_entry.state == ConfigEntryState.LOADED
            and existing_entry.runtime_data.connected
            and existing_entry.data[CONF_HOST] != self._host
        ):
            _LOGGER.debug(
                "Aborting config flow for discovered homee with IP %s "
                "since it is already configured at IP %s",
                self._host,
                existing_entry.data[CONF_HOST],
            )
            return self.async_abort(reason="2nd_ip_address")

        self._abort_if_unique_id_configured(updates={CONF_HOST: self._host})

        # Cause an auth-error to see if homee is reachable.
        self.homee = Homee(
            self._host,
            "dummy_username",
            "dummy_password",
        )
        errors = await self._connect_homee()
        if errors["base"] != RESULT_INVALID_AUTH:
            return self.async_abort(reason=RESULT_CANNOT_CONNECT)

        self.context["title_placeholders"] = {"name": self._name, "host": self._host}

        return await self.async_step_zeroconf_confirm()

    async def async_step_zeroconf_confirm(