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

Code before:
                )
        return self.async_show_form(
            step_id="user",
            data_schema=self.add_suggested_values_to_schema(
                data_schema=vol.Schema(
                    {
                        vol.Required(CONF_ID): str
                        if self.source == SOURCE_USER
                        else self._get_reconfigure_entry().data[CONF_ID],
                        vol.Required(
                            CONF_NAME, default=self.hass.config.location_name
                        ): str,
                        vol.Required(CONF_USERNAME): str,
                        vol.Required(CONF_PASSWORD): str,
                        vol.Optional(CONF_IS_TOU, default=False): bool,
                    }
                ),
                suggested_values=user_input or self._get_reconfigure_entry().data
                if self.source == SOURCE_RECONFIGURE
                else None,
            ),
            errors=errors,
        )

    async def async_step_reconfigure(
        self, user_input: dict[str, Any]
    ) -> ConfigFlowResult:
        """Handle reconfiguration."""
        return await self.async_step_user()


class InvalidAuth(HomeAssistantError):
    """Error to indicate there is invalid auth."""


Review comment (refactor):
Okay so for reconfigure:

1. Can the username change?
2. The ID can't change I presume, I am not 100% sure if this code now hides it
3. We should not allow users to change the name. Nowadays we don't allow integrations to ask for a name unless its a helper. This is mostly because if every integration implemented something similar, it wouldn't be consistent (or as consistent as using the built in methods to rename devices/config entries)

Code after:
                )
        return self.async_show_form(
            step_id="user",
            data_schema=self.add_suggested_values_to_schema(
                data_schema=vol.Schema(
                    {
                        vol.Required(CONF_ID): (
                            str
                            if self.source == SOURCE_USER
                            else self._get_reconfigure_entry().data[CONF_ID]
                        ),
                        vol.Required(
                            CONF_NAME, default=self.hass.config.location_name
                        ): str,
                        vol.Required(CONF_USERNAME): str,
                        vol.Required(CONF_PASSWORD): str,
                        vol.Optional(CONF_IS_TOU, default=False): bool,
                    }
                ),
                suggested_values=(
                    user_input or self._get_reconfigure_entry().data
                    if self.source == SOURCE_RECONFIGURE
                    else None
                ),
            ),
            errors=errors,
        )

    async def async_step_reconfigure(
        self, user_input: dict[str, Any]
    ) -> ConfigFlowResult:
        """Handle reconfiguration."""
        return await self.async_step_user()


class InvalidAuth(HomeAssistantError):
    """Error to indicate there is invalid auth."""