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

Code before:

    return is_valid


class SRPEnergyConfigFlow(ConfigFlow, domain=DOMAIN):
    """Handle an SRP Energy config flow."""

    VERSION = 1

    async def async_step_user(
        self, user_input: dict[str, Any] | None = None
    ) -> ConfigFlowResult:
        """Handle a flow initialized by the user."""
        LOGGER.debug("Config entry")
        errors: dict[str, str] = {}
        if user_input:
            try:
                await validate_input(self.hass, user_input)
            except ValueError:
                # Thrown when the account id is malformed
                errors["base"] = "invalid_account"
            except InvalidAuth:
                errors["base"] = "invalid_auth"
            except Exception:  # noqa: BLE001
                LOGGER.exception("Unexpected exception")
                return self.async_abort(reason="unknown")
            else:
                await self.async_set_unique_id(user_input[CONF_ID])
                if self.source == SOURCE_USER:
                    self._abort_if_unique_id_configured()
                if self.source == SOURCE_RECONFIGURE:
                    self._abort_if_unique_id_mismatch()

                if self.source == SOURCE_USER:
                    return self.async_create_entry(
                        title=user_input[CONF_NAME],
                        data=user_input,
                    )
                return self.async_update_reload_and_abort(
                    self._get_reconfigure_entry(),
                    data=user_input,
                )
        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(

Review comment (suggestion):
A future improvement can be that we don't abort when this happens, but just show that there was an unknown error

Code after:

    return is_valid


class SRPEnergyConfigFlow(ConfigFlow, domain=DOMAIN):
    """Handle an SRP Energy config flow."""

    VERSION = 1

    async def async_step_user(
        self, user_input: dict[str, Any] | None = None
    ) -> ConfigFlowResult:
        """Handle a flow initialized by the user."""
        LOGGER.debug("Config entry")
        errors: dict[str, str] = {}
        if user_input:
            try:
                await validate_input(self.hass, user_input)
            except ValueError:
                # Thrown when the account id is malformed
                errors["base"] = "invalid_account"
            except InvalidAuth:
                errors["base"] = "invalid_auth"
            except Exception:  # noqa: BLE001
                LOGGER.exception("Unexpected exception")
                return self.async_abort(reason="unknown")
            else:
                await self.async_set_unique_id(user_input[CONF_ID])
                if self.source == SOURCE_USER:
                    self._abort_if_unique_id_configured()
                if self.source == SOURCE_RECONFIGURE:
                    self._abort_if_unique_id_mismatch()

                if self.source == SOURCE_USER:
                    return self.async_create_entry(
                        title=user_input[CONF_NAME],
                        data=user_input,
                    )
                return self.async_update_reload_and_abort(
                    self._get_reconfigure_entry(),
                    data=user_input,
                )
        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]