diff --git a/script/scaffold/templates/config_flow/integration/config_flow.py b/script/scaffold/templates/config_flow/integration/config_flow.py index bfa1d65c257d2fabd7055eceadf6397cbe60a75a..c9700463c86566c36f5caf8a6fcc241dc0200c80 100644 --- a/script/scaffold/templates/config_flow/integration/config_flow.py +++ b/script/scaffold/templates/config_flow/integration/config_flow.py @@ -10,7 +10,7 @@ from .const import DOMAIN # pylint:disable=unused-import _LOGGER = logging.getLogger(__name__) # TODO adjust the data schema to the data that you need -DATA_SCHEMA = vol.Schema({"host": str, "username": str, "password": str}) +STEP_USER_DATA_SCHEMA = vol.Schema({"host": str, "username": str, "password": str}) class PlaceholderHub: @@ -31,7 +31,7 @@ class PlaceholderHub: async def validate_input(hass: core.HomeAssistant, data): """Validate the user input allows us to connect. - Data has the keys from DATA_SCHEMA with values provided by the user. + Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user. """ # TODO validate the data can be used to set up a connection. @@ -64,22 +64,27 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): async def async_step_user(self, user_input=None): """Handle the initial step.""" + if user_input is None: + return self.async_show_form( + step_id="user", data_schema=STEP_USER_DATA_SCHEMA + ) + errors = {} - if user_input is not None: - try: - info = await validate_input(self.hass, user_input) - - return self.async_create_entry(title=info["title"], data=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" + + 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=DATA_SCHEMA, errors=errors + step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors )