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

Code before:
                }
                if api_versions
                else None,
            )

        await self.async_set_unique_id(serial_number, raise_on_progress=False)
        self._abort_if_unique_id_configured()
        return self.async_create_entry(
            title=f"PoolDose {serial_number}",
            data={CONF_HOST: host},
        )

    async def async_step_reconfigure(
        self, user_input: dict[str, Any] | None = None
    ) -> ConfigFlowResult:
        """Handle reconfigure to change the device host/IP for an existing entry."""
        reconfigure_entry = self._get_reconfigure_entry()
        # Show form to enter new host
        if not user_input:
            # Pre-fill with current host from the entry being reconfigured
            return self.async_show_form(
                step_id="reconfigure",
                data_schema=vol.Schema(
                    {
                        vol.Required(
                            CONF_HOST, default=reconfigure_entry.data[CONF_HOST]
                        ): cv.string
                    }
                ),
            )

        host = user_input[CONF_HOST]
        serial_number, api_versions, errors = await self._validate_host(host)
        if errors:
            return self.async_show_form(
                step_id="reconfigure",
                data_schema=vol.Schema({vol.Required(CONF_HOST): cv.string}),
                errors=errors,
                description_placeholders={
                    "api_version_is": api_versions.get("api_version_is") or "",
                    "api_version_should": api_versions.get("api_version_should") or "",
                }
                if api_versions
                else None,
            )

        # Ensure new serial number matches the existing entry unique_id (serial number)
        if str(serial_number) != str(reconfigure_entry.unique_id):
            return self.async_abort(reason="wrong_device")

        # Update the existing config entry with the new host and schedule reload

Review comment (suggestion):
you can use `self.add_suggested_values_to_schema`, that will also accept `None`

Code after:

            await self.async_set_unique_id(serial_number, raise_on_progress=False)
            self._abort_if_unique_id_configured()
            return self.async_create_entry(
                title=f"PoolDose {serial_number}",
                data={CONF_HOST: host},
            )

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

    async def async_step_reconfigure(
        self, user_input: dict[str, Any] | None = None
    ) -> ConfigFlowResult:
        """Handle reconfigure to change the device host/IP for an existing entry."""
        if user_input is not None:
            host = user_input[CONF_HOST]
            serial_number, api_versions, errors = await self._validate_host(host)
            if errors:
                return self.async_show_form(
                    step_id="reconfigure",
                    data_schema=SCHEMA_DEVICE,
                    errors=errors,
                    # Handle API version info for error display identical to other steps
                    description_placeholders={
                        "api_version_is": api_versions.get("api_version_is") or "",
                        "api_version_should": api_versions.get("api_version_should")
                        or "",
                    }
                    if api_versions
                    else None,
                )

            # Ensure new serial number matches the existing entry unique_id (serial number)
            if serial_number != self._get_reconfigure_entry().unique_id:
                return self.async_abort(reason="wrong_device")

            # Update the existing config entry with the new host and schedule reload
            return self.async_update_reload_and_abort(
                self._get_reconfigure_entry(), data_updates={CONF_HOST: host}
            )

        return self.async_show_form(
            step_id="reconfigure",
            # Pre-fill with current host from the entry being reconfigured
            data_schema=self.add_suggested_values_to_schema(
                SCHEMA_DEVICE, self._get_reconfigure_entry().data
            ),
        )