Rework user_input check in config flow scaffold (#87820)
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
65d7242c22
commit
bb4d6c0d2c
1 changed files with 13 additions and 18 deletions
|
@ -76,24 +76,19 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
if user_input is None:
|
errors: dict[str, str] = {}
|
||||||
return self.async_show_form(
|
if user_input is not None:
|
||||||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA
|
try:
|
||||||
)
|
info = await validate_input(self.hass, user_input)
|
||||||
|
except CannotConnect:
|
||||||
errors = {}
|
errors["base"] = "cannot_connect"
|
||||||
|
except InvalidAuth:
|
||||||
try:
|
errors["base"] = "invalid_auth"
|
||||||
info = await validate_input(self.hass, user_input)
|
except Exception: # pylint: disable=broad-except
|
||||||
except CannotConnect:
|
_LOGGER.exception("Unexpected exception")
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "unknown"
|
||||||
except InvalidAuth:
|
else:
|
||||||
errors["base"] = "invalid_auth"
|
return self.async_create_entry(title=info["title"], data=user_input)
|
||||||
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(
|
return self.async_show_form(
|
||||||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
|
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
|
||||||
|
|
Loading…
Add table
Reference in a new issue