Skip to content

Commit

Permalink
Rework user_input check in config flow scaffold (home-assistant#87820)
Browse files Browse the repository at this point in the history
Co-authored-by: epenet <[email protected]>
  • Loading branch information
Lash-L and epenet authored Feb 12, 2023
1 parent 65d7242 commit bb4d6c0
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions script/scaffold/templates/config_flow/integration/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,19 @@ async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle the initial step."""
if user_input is None:
return self.async_show_form(
step_id="user", data_schema=STEP_USER_DATA_SCHEMA
)

errors = {}

try:
info = await validate_input(self.hass, user_input)
except CannotConnect:
errors["base"] = "cannot_connect"
except InvalidAuth:
errors["base"] = "invalid_auth"
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
return self.async_create_entry(title=info["title"], data=user_input)
errors: dict[str, str] = {}
if user_input is not None:
try:
info = await validate_input(self.hass, user_input)
except CannotConnect:
errors["base"] = "cannot_connect"
except InvalidAuth:
errors["base"] = "invalid_auth"
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
return self.async_create_entry(title=info["title"], data=user_input)

return self.async_show_form(
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
Expand Down

0 comments on commit bb4d6c0

Please sign in to comment.