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

Code before:

    async def _handle_token(self, token: str) -> str | None:
        """Handle the token input."""
        try:
            conn = Connection(url=HOST, token_b64=token)
        except ValueError:
            self.errors["base"] = "malformed_token"
            return None

        try:
            await conn.refresh_token()
        except ConnectionException:
            self.errors["base"] = "cannot_connect"
            return None
        except AuthenticationException:
            self.errors["base"] = "invalid_auth"
            return None

        return conn.token.serialNumber

    async def _validate_input(
        self, user_input: dict[str, Any] | None
    ) -> dict[str, Any] | None:
        """Validate the user input."""
        if user_input is None:
            return None

        token = user_input[CONF_ACCESS_TOKEN]
        serial_number = await self._handle_token(token=token)

        if serial_number is not None:
            await self.async_set_unique_id(serial_number)

            if self.source == SOURCE_REAUTH:
                self._abort_if_unique_id_mismatch()
            else:
                self._abort_if_unique_id_configured()

            return {"token": token, "serial_number": serial_number}

        return None

    async def async_step_user(
        self, user_input: dict[str, Any] | None = None
    ) -> ConfigFlowResult:
        """Handle the initial step."""
        validated_info = await self._validate_input(user_input)
        if validated_info is not None:
            return self.async_create_entry(
                title=validated_info["serial_number"],
                data={CONF_ACCESS_TOKEN: validated_info["token"]},

Review comment (suggestion):
```suggestion
        self, user_input: dict[str, Any]
    ) -> dict[str, Any] | None:
        """Validate the user input."""
```

Code after:

    async def _handle_token(self, token: str) -> str | None:
        """Handle the token input."""
        try:
            conn = Connection(url=HOST, token_b64=token)
        except ValueError:
            self.errors["base"] = "malformed_token"
            return None

        try:
            await conn.refresh_token()
        except ConnectionException:
            self.errors["base"] = "cannot_connect"
            return None
        except AuthenticationException:
            self.errors["base"] = "invalid_auth"
            return None

        return conn.token.serialNumber

    async def _validate_input(
        self, user_input: dict[str, Any]
    ) -> dict[str, Any] | None:
        """Validate the user input."""
        token = user_input[CONF_ACCESS_TOKEN]
        serial_number = await self._handle_token(token=token)

        if serial_number is not None:
            await self.async_set_unique_id(serial_number)

            if self.source == SOURCE_REAUTH:
                self._abort_if_unique_id_mismatch()
            else:
                self._abort_if_unique_id_configured()

            return {"token": token, "serial_number": serial_number}

        return None

    async def async_step_user(
        self, user_input: dict[str, Any] | None = None
    ) -> ConfigFlowResult:
        """Handle the initial step."""
        self.errors = {}
        if user_input is not None:
            validated_info = await self._validate_input(user_input)
            if validated_info is not None:
                return self.async_create_entry(
                    title=validated_info["serial_number"],
                    data={CONF_ACCESS_TOKEN: validated_info["token"]},
                )