Fix setting login credentials using config_flow and fix mistakes in spelling
This commit is contained in:
@@ -16,10 +16,10 @@
|
|||||||
"unknown": "Unknown error"
|
"unknown": "Unknown error"
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
"one_instance_allowed": "Only a single instance is allowed."
|
"one_instance_allowed": "Only one instance is allowed."
|
||||||
},
|
},
|
||||||
"create_entry": {
|
"create_entry": {
|
||||||
"default": "\n\nLogin succes"
|
"default": "\n\nLogin success"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
"step": {
|
"step": {
|
||||||
"georide_login": {
|
"georide_login": {
|
||||||
"title": "Configuration de GeoRide",
|
"title": "Configuration de GeoRide",
|
||||||
"description": "T'es un mortard ! V",
|
"description": "T'es un motard ! V",
|
||||||
"data": {
|
"data": {
|
||||||
"email": "email",
|
"email": "email",
|
||||||
"password": "password"
|
"password": "password"
|
||||||
@@ -12,14 +12,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"faulty_credentials": "Connexion \u00e9chou\u00e9",
|
"faulty_credentials": "Connexion \u00e9chou\u00e9e",
|
||||||
"unkonwn": "Erreur inconue"
|
"unkonwn": "Erreur inconnue"
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
"one_instance_allowed": "Seulement un instance est authoris\u00e9e"
|
"one_instance_allowed": "Seulement une instance est autoris\u00e9e"
|
||||||
},
|
},
|
||||||
"create_entry": {
|
"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):
|
async def async_step_georide_login(self, user_input):
|
||||||
""" try to seupt GeoRide Account """
|
""" 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:
|
try:
|
||||||
account = GeorideApi.get_authorisation_token(
|
account = GeorideApi.get_authorisation_token(email, password)
|
||||||
user_input[CONF_EMAIL],
|
data = {
|
||||||
user_input[CONF_PASSWORD])
|
CONF_EMAIL: email,
|
||||||
return self.async_create_entry(
|
CONF_PASSWORD: password,
|
||||||
title=user_input[CONF_EMAIL],
|
CONF_TOKEN: account.auth_token
|
||||||
data={
|
}
|
||||||
CONF_EMAIL: user_input[CONF_EMAIL],
|
return self.async_create_entry(title=email, data=data)
|
||||||
CONF_PASSWORD: user_input[CONF_PASSWORD],
|
|
||||||
CONF_TOKEN: account.auth_token
|
|
||||||
}
|
|
||||||
)
|
|
||||||
except (GeorideException.SeverException, GeorideException.LoginException):
|
except (GeorideException.SeverException, GeorideException.LoginException):
|
||||||
_LOGGER.error("Invalid credentials provided, config not created")
|
_LOGGER.error("Invalid credentials provided, config not created")
|
||||||
errors["base"] = "faulty_credentials"
|
errors = {"base": "faulty_credentials"}
|
||||||
return self.async_show_form(step_id="georide_login", errors=errors)
|
return self.async_show_form(step_id="georide_login", data_schema=schema, errors=errors)
|
||||||
except:
|
except:
|
||||||
_LOGGER.error("Unknown error")
|
_LOGGER.error("Unknown error")
|
||||||
errors["base"] = "faulty_credentials"
|
errors = {"base": "unkonwn"}
|
||||||
return self.async_show_form(step_id="georide_login", errors=errors)
|
return self.async_show_form(step_id="georide_login", data_schema=schema, errors=errors)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user