Skip to content

Commit

Permalink
Exception handling in Vilfo Router config flow refactored to be more …
Browse files Browse the repository at this point in the history
…readable.
  • Loading branch information
ManneW committed Feb 12, 2020
1 parent 753fc1a commit 6cffd91
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions homeassistant/components/vilfo/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
import voluptuous as vol

from homeassistant import config_entries, core, data_entry_flow, exceptions
from homeassistant import config_entries, core, exceptions
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST, CONF_ID, CONF_MAC

from .const import DOMAIN # pylint:disable=unused-import
Expand Down Expand Up @@ -115,21 +115,20 @@ async def async_step_user(self, user_input=None):
if user_input is not None:
try:
info = await validate_input(self.hass, user_input)
await self.async_set_unique_id(info[CONF_ID])
self._abort_if_unique_id_configured()

return self.async_create_entry(title=info["title"], data=user_input)
except InvalidHost:
errors[CONF_HOST] = "wrong_host"
except CannotConnect:
errors["base"] = "cannot_connect"
except InvalidAuth:
errors["base"] = "invalid_auth"
except data_entry_flow.AbortFlow as abort_err:
raise abort_err
except Exception as err: # pylint: disable=broad-except
_LOGGER.error("Unexpected exception: %s", err)
errors["base"] = "unknown"
else:
await self.async_set_unique_id(info[CONF_ID])
self._abort_if_unique_id_configured()

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
Expand Down

0 comments on commit 6cffd91

Please sign in to comment.