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):
"""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:

@ -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"
},
)

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

@ -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"

Loading…
Cancel
Save