diff --git a/custom_components/georide/__init__.py b/custom_components/georide/__init__.py index 8e8e2f9..5394880 100644 --- a/custom_components/georide/__init__.py +++ b/custom_components/georide/__init__.py @@ -35,8 +35,8 @@ CONFIG_SCHEMA = vol.Schema( ) -def setup(hass, config): - """Initialize Georide component.""" +async def async_setup(hass, config): + """Setup Georide component.""" hass.data[DOMAIN] = {"config": config[DOMAIN], "devices": {}, "unsub": None} hass.async_create_task( hass.config_entries.flow.async_init( @@ -52,6 +52,18 @@ def setup(hass, config): +async def async_setup_entry(hass, entry): + """Set up OwnTracks entry.""" + config = hass.data[DOMAIN]["config"] + email = config.get(CONF_EMAIL) or entry.data[CONF_EMAIL] + password = config.get(CONF_EMAIL) or entry.data[CONF_EMAIL] + context = GeorideContext( + hass, + email, + password + ) + hass.data[DOMAIN]["context"] = context + return True class GeorideContext: diff --git a/custom_components/georide/config_flow.py b/custom_components/georide/config_flow.py index 7e55c0f..4d413b1 100644 --- a/custom_components/georide/config_flow.py +++ b/custom_components/georide/config_flow.py @@ -1,21 +1,51 @@ """ Georide config flow """ +import logging from homeassistant import config_entries import voluptuous as vol + from .const import DOMAIN, CONF_EMAIL, CONF_PASSWORD + +_LOGGER = logging.getLogger(__name__) + STEP_ID = 'user' -class GeorideConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): - """Geride config flow """ +@config_entries.HANDLERS.register(DOMAIN) +class GeorideConfigFlow(config_entries.ConfigFlow): + """Georide config flow """ async def async_step_user(self, user_input=None): """ handle info to help to configure georide """ - if user_input is None: + + if self._async_current_entries(): + return self.async_abort(reason="one_instance_allowed") + + if user_input is None: + _LOGGER.info("user email: %", str(user_input)) + 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) })) # process info + + return self.async_abort(reason="no_credentials") + + + + async def async_step_import(self, user_input): + """Import a config flow from configuration.""" + + _LOGGER.info("user email: %", str(user_input)) + + return self.async_create_entry( + title="Georide", + data={ + CONF_EMAIL: "un_emal", + CONF_PASSWORD: "un password" + }, + ) + \ No newline at end of file diff --git a/custom_components/georide/const.py b/custom_components/georide/const.py index 47970d5..2a5b44e 100644 --- a/custom_components/georide/const.py +++ b/custom_components/georide/const.py @@ -4,4 +4,6 @@ DOMAIN = "georide" CONF_EMAIL = "email" CONF_PASSWORD = "password" +CONF_TOKEN = "token" + TRACKER_ID = "trackerId" diff --git a/custom_components/georide/strings.json b/custom_components/georide/strings.json index ebc7b6d..4bae62f 100644 --- a/custom_components/georide/strings.json +++ b/custom_components/georide/strings.json @@ -4,11 +4,17 @@ "step": { "user": { "title": "Set up Georide", - "description": "Are you sure you want to set up OwnTracks?" + "description": "Are you sure you want to set up Georide?", + "data": { + "email": "email", + "password": "password" + } } }, "abort": { - "one_instance_allowed": "Only a single instance is allowed." + "one_instance_allowed": "Only a single instance is allowed.", + "no_credential": "You need to add your credentails." + }, "create_entry": { "default": "\n\nJust give your credentials"