Skip to content
This repository has been archived by the owner on Jul 22, 2021. It is now read-only.

Commit

Permalink
version with VALIDATION on SCHEMA
Browse files Browse the repository at this point in the history
  • Loading branch information
xlcnd committed Mar 4, 2021
1 parent 8416e22 commit 1794aab
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions custom_components/meteoalarmeu/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,7 @@ async def async_step_other(self, user_input=None):
),
errors=errors,
)
try:
# Set 'unique_id' and abort flow if already configured
await self.async_set_unique_id(DEFAULT_NAME)
self._abort_if_unique_id_configured()
except exceptions.HomeAssistantError:
return self.async_abort(reason="already_configured")

# Convert 'country' and 'language' to ISO
self._data[CONF_COUNTRY] = cmap(self._data[CONF_COUNTRY])
if self._data[CONF_LANGUAGE]:
self._data[CONF_LANGUAGE] = lmap(self._data[CONF_LANGUAGE])

# Create new entry in 'core.config_entries'
return self.async_create_entry(title=self._data[CONF_NAME], data=self._data)
return await self.async_handle_create_entry()

return self.async_show_form(
step_id="other",
Expand All @@ -151,6 +138,22 @@ async def async_step_other(self, user_input=None):
errors=errors,
)

async def async_handle_create_entry(self):
try:
# Set 'unique_id' and abort flow if already configured
await self.async_set_unique_id(DEFAULT_NAME)
self._abort_if_unique_id_configured()
except exceptions.HomeAssistantError:
return self.async_abort(reason="already_configured")

# Convert 'country' and 'language' to ISO
self._data[CONF_COUNTRY] = cmap(self._data[CONF_COUNTRY])
if self._data[CONF_LANGUAGE]:
self._data[CONF_LANGUAGE] = lmap(self._data[CONF_LANGUAGE])

# Create new entry in 'core.config_entries'
return self.async_create_entry(title=self._data[CONF_NAME], data=self._data)

async def async_get_languages(self):
"""Get available languages for country if possible."""
if self._data[CONF_COUNTRY]:
Expand Down

0 comments on commit 1794aab

Please sign in to comment.