Fix setting login credentials using config_flow and fix mistakes in spelling

master
Kévin SIMON-QUESNEL 5 years ago
parent e5bd90ae6f
commit cbed2cebb3

@ -16,10 +16,10 @@
"unknown": "Unknown error"
},
"abort": {
"one_instance_allowed": "Only a single instance is allowed."
"one_instance_allowed": "Only one instance is allowed."
},
"create_entry": {
"default": "\n\nLogin succes"
"default": "\n\nLogin success"
}
}
}

@ -4,7 +4,7 @@
"step": {
"georide_login": {
"title": "Configuration de GeoRide",
"description": "T'es un mortard ! V",
"description": "T'es un motard ! V",
"data": {
"email": "email",
"password": "password"
@ -12,14 +12,14 @@
}
},
"error": {
"faulty_credentials": "Connexion \u00e9chou\u00e9",
"unkonwn": "Erreur inconue"
"faulty_credentials": "Connexion \u00e9chou\u00e9e",
"unkonwn": "Erreur inconnue"
},
"abort": {
"one_instance_allowed": "Seulement un instance est authoris\u00e9e"
"one_instance_allowed": "Seulement une instance est autoris\u00e9e"
},
"create_entry": {
"default": "\n\nConnexion r\u00e9ussie!"
"default": "\n\nConnexion r\u00e9ussie !"
}
}
}

@ -41,27 +41,32 @@ class GeorideConfigFlow(config_entries.ConfigFlow):
async def async_step_georide_login(self, user_input):
""" try to seupt GeoRide Account """
errors = {}
schema = vol.Schema({
vol.Required(CONF_EMAIL): vol.All(str, vol.Length(min=3)),
vol.Required(CONF_PASSWORD): vol.All(str)
})
if user_input is None:
return self.async_show_form(step_id='georide_login', data_schema=schema)
email = user_input[CONF_EMAIL]
password = user_input[CONF_PASSWORD]
try:
account = GeorideApi.get_authorisation_token(
user_input[CONF_EMAIL],
user_input[CONF_PASSWORD])
return self.async_create_entry(
title=user_input[CONF_EMAIL],
data={
CONF_EMAIL: user_input[CONF_EMAIL],
CONF_PASSWORD: user_input[CONF_PASSWORD],
CONF_TOKEN: account.auth_token
}
)
account = GeorideApi.get_authorisation_token(email, password)
data = {
CONF_EMAIL: email,
CONF_PASSWORD: password,
CONF_TOKEN: account.auth_token
}
return self.async_create_entry(title=email, data=data)
except (GeorideException.SeverException, GeorideException.LoginException):
_LOGGER.error("Invalid credentials provided, config not created")
errors["base"] = "faulty_credentials"
return self.async_show_form(step_id="georide_login", errors=errors)
errors = {"base": "faulty_credentials"}
return self.async_show_form(step_id="georide_login", data_schema=schema, errors=errors)
except:
_LOGGER.error("Unknown error")
errors["base"] = "faulty_credentials"
return self.async_show_form(step_id="georide_login", errors=errors)
errors = {"base": "unkonwn"}
return self.async_show_form(step_id="georide_login", data_schema=schema, errors=errors)
Loading…
Cancel
Save