Add support of file-config-flow

master
Matthieu DUVAL 5 years ago
parent 62dde71161
commit 04872ac973

@ -35,8 +35,8 @@ CONFIG_SCHEMA = vol.Schema(
) )
def setup(hass, config): async def async_setup(hass, config):
"""Initialize Georide component.""" """Setup Georide component."""
hass.data[DOMAIN] = {"config": config[DOMAIN], "devices": {}, "unsub": None} hass.data[DOMAIN] = {"config": config[DOMAIN], "devices": {}, "unsub": None}
hass.async_create_task( hass.async_create_task(
hass.config_entries.flow.async_init( 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: class GeorideContext:

@ -1,21 +1,51 @@
""" Georide config flow """ """ Georide config flow """
import logging
from homeassistant import config_entries from homeassistant import config_entries
import voluptuous as vol import voluptuous as vol
from .const import DOMAIN, CONF_EMAIL, CONF_PASSWORD from .const import DOMAIN, CONF_EMAIL, CONF_PASSWORD
_LOGGER = logging.getLogger(__name__)
STEP_ID = 'user' STEP_ID = 'user'
class GeorideConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): @config_entries.HANDLERS.register(DOMAIN)
"""Geride config flow """ class GeorideConfigFlow(config_entries.ConfigFlow):
"""Georide config flow """
async def async_step_user(self, user_input=None): async def async_step_user(self, user_input=None):
""" handle info to help to configure georide """ """ handle info to help to configure georide """
if self._async_current_entries():
return self.async_abort(reason="one_instance_allowed")
if user_input is None: 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({ 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_EMAIL): vol.All(str, vol.Length(min=3)),
vol.Required(CONF_PASSWORD): vol.All(str) vol.Required(CONF_PASSWORD): vol.All(str)
})) }))
# process info # 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"
},
)

@ -4,4 +4,6 @@ DOMAIN = "georide"
CONF_EMAIL = "email" CONF_EMAIL = "email"
CONF_PASSWORD = "password" CONF_PASSWORD = "password"
CONF_TOKEN = "token"
TRACKER_ID = "trackerId" TRACKER_ID = "trackerId"

@ -4,11 +4,17 @@
"step": { "step": {
"user": { "user": {
"title": "Set up Georide", "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": { "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": { "create_entry": {
"default": "\n\nJust give your credentials" "default": "\n\nJust give your credentials"

Loading…
Cancel
Save