From 62dde71161a79263a8cf9ab6634ce5c2c963676a Mon Sep 17 00:00:00 2001 From: Matthieu Date: Sat, 26 Oct 2019 17:26:34 +0200 Subject: [PATCH] Add config step definition --- custom_components/georide/__init__.py | 4 ++-- custom_components/georide/config_flow.py | 21 +++++++++++++-------- custom_components/georide/strings.json | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 custom_components/georide/strings.json diff --git a/custom_components/georide/__init__.py b/custom_components/georide/__init__.py index 9f578e3..8e8e2f9 100644 --- a/custom_components/georide/__init__.py +++ b/custom_components/georide/__init__.py @@ -27,8 +27,8 @@ _LOGGER = logging.getLogger(__name__) CONFIG_SCHEMA = vol.Schema( { vol.Required(DOMAIN, default={}): { - vol.Required(CONF_EMAIL): vol.All(str, vol.Length(min=3)), - vol.Required(CONF_PASSWORD): vol.All(str) + vol.Optional(CONF_EMAIL): vol.All(str, vol.Length(min=3)), + vol.Optional(CONF_PASSWORD): vol.All(str) } }, extra=vol.ALLOW_EXTRA, diff --git a/custom_components/georide/config_flow.py b/custom_components/georide/config_flow.py index 4648701..7e55c0f 100644 --- a/custom_components/georide/config_flow.py +++ b/custom_components/georide/config_flow.py @@ -1,16 +1,21 @@ -""" Georide config flow file """ +""" Georide config flow """ from homeassistant import config_entries import voluptuous as vol -from .const import DOMAIN +from .const import DOMAIN, CONF_EMAIL, CONF_PASSWORD + +STEP_ID = 'user' class GeorideConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Geride config flow """ - async def async_step_user(self, info): - return self.async_show_form( - step_id='user', - data_schema=vol.Schema({ - vol.Required('password'): str + + async def async_step_user(self, user_input=None): + """ handle info to help to configure georide """ + if user_input is None: + return self.async_show_form(step_id=STEP_ID, data_schema=vol.Schema({ + vol.Required(CONF_EMAIL): vol.All(str, vol.Length(min=3)), + vol.Required(CONF_PASSWORD): vol.All(str) })) - \ No newline at end of file + # process info + diff --git a/custom_components/georide/strings.json b/custom_components/georide/strings.json new file mode 100644 index 0000000..ebc7b6d --- /dev/null +++ b/custom_components/georide/strings.json @@ -0,0 +1,17 @@ +{ + "config": { + "title": "Georide", + "step": { + "user": { + "title": "Set up Georide", + "description": "Are you sure you want to set up OwnTracks?" + } + }, + "abort": { + "one_instance_allowed": "Only a single instance is allowed." + }, + "create_entry": { + "default": "\n\nJust give your credentials" + } + } +} \ No newline at end of file