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

Code before:
                    vol.Optional(CONF_GROUP, default=self._data[CONF_GROUP]): vol.In(
                        GROUPS
                    ),
                    vol.Required(CONF_PASSWORD): cv.string,
                }
            ),
            errors=errors,
        )

    async def async_step_reconfigure(
        self, user_input: dict[str, Any] | None = None
    ) -> ConfigFlowResult:
        """Handle reconfiguration of the integration."""
        errors: dict[str, str] = {}
        reconf_entry = self._get_reconfigure_entry()
        suggested_values = {
            CONF_HOST: reconf_entry.data[CONF_HOST],
            CONF_SSL: reconf_entry.data[CONF_SSL],
            CONF_VERIFY_SSL: reconf_entry.data[CONF_VERIFY_SSL],
            CONF_GROUP: reconf_entry.data[CONF_GROUP],
        }

        if user_input is not None:
            # The password is not changed during reconfiguration, that is only triggered during reauth
            # Note to reviewer: I left out the abort if unique id configured here, since that's based on the serial
            # number. See comments in PR for my thoughts on a potential solution.
            errors, _ = await self._handle_user_input(
                user_input={
                    **reconf_entry.data,
                    **user_input,
                }
            )

            if not errors:
                return self.async_update_reload_and_abort(
                    reconf_entry,
                    data_updates={
                        CONF_HOST: user_input[CONF_HOST],
                        CONF_SSL: user_input[CONF_SSL],
                        CONF_VERIFY_SSL: user_input[CONF_VERIFY_SSL],
                        CONF_GROUP: user_input[CONF_GROUP],
                    },
                )

        return self.async_show_form(
            step_id="reconfigure",
            data_schema=self.add_suggested_values_to_schema(
                data_schema=vol.Schema(
                    {
                        vol.Required(CONF_HOST): cv.string,
                        vol.Optional(CONF_SSL): cv.boolean,

Review comment (suggestion):
for reconfigure flows we don't consider `self._abort_if_unique_id_configured`, but `self._abort_if_unique_id_mismatch()`, so a user can't use reconfiguration to configure to a different device. If needed in your validation you can check `self.source == SOURCE_USER:` and `if self.source == SOURCE_RECONFIGURE:`

Code after:
                    vol.Optional(CONF_GROUP, default=self._data[CONF_GROUP]): vol.In(
                        GROUPS
                    ),
                    vol.Required(CONF_PASSWORD): cv.string,
                }
            ),
            errors=errors,
        )

    async def async_step_reconfigure(
        self, user_input: dict[str, Any] | None = None
    ) -> ConfigFlowResult:
        """Handle reconfiguration of the integration."""
        errors: dict[str, str] = {}
        reconf_entry = self._get_reconfigure_entry()
        if user_input is not None:
            errors, device_info = await self._handle_user_input(
                user_input={
                    **reconf_entry.data,
                    **user_input,
                }
            )

            if not errors:
                await self.async_set_unique_id(
                    str(device_info["serial"]), raise_on_progress=False
                )
                self._abort_if_unique_id_mismatch()
                return self.async_update_reload_and_abort(
                    reconf_entry,
                    data_updates={
                        CONF_HOST: user_input[CONF_HOST],
                        CONF_SSL: user_input[CONF_SSL],
                        CONF_VERIFY_SSL: user_input[CONF_VERIFY_SSL],
                        CONF_GROUP: user_input[CONF_GROUP],
                    },
                )

        return self.async_show_form(
            step_id="reconfigure",
            data_schema=self.add_suggested_values_to_schema(
                data_schema=vol.Schema(
                    {
                        vol.Required(CONF_HOST): cv.string,
                        vol.Optional(CONF_SSL): cv.boolean,
                        vol.Optional(CONF_VERIFY_SSL): cv.boolean,
                        vol.Optional(CONF_GROUP): vol.In(GROUPS),
                    }
                ),
                suggested_values=user_input or dict(reconf_entry.data),
            ),