Compare commits

...

3 Commits
0.4.1 ... 0.4.3

Author SHA1 Message Date
ef783db79b HotFix deveice_tracker.py du to HA Update 2020-03-28 23:59:38 +01:00
18de851e4d Merge pull request #2 from limeryls/fix_login
Fix setting login credentials using config_flow and fix mistakes in spelling
2020-03-28 17:04:19 +01:00
Kévin SIMON-QUESNEL
cbed2cebb3 Fix setting login credentials using config_flow and fix mistakes in spelling 2020-03-28 04:38:52 +01:00
4 changed files with 33 additions and 28 deletions

View File

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

View File

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

View File

@@ -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],
data={
CONF_EMAIL: user_input[CONF_EMAIL],
CONF_PASSWORD: user_input[CONF_PASSWORD],
CONF_TOKEN: account.auth_token CONF_TOKEN: account.auth_token
} }
) return self.async_create_entry(title=email, data=data)
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)

View File

@@ -2,7 +2,7 @@
import logging import logging
from homeassistant.components.device_tracker.const import ENTITY_ID_FORMAT, SOURCE_TYPE_GPS from homeassistant.components.device_tracker.const import DOMAIN, SOURCE_TYPE_GPS
from homeassistant.components.device_tracker.config_entry import TrackerEntity from homeassistant.components.device_tracker.config_entry import TrackerEntity
import georideapilib.api as GeorideApi import georideapilib.api as GeorideApi
@@ -50,7 +50,7 @@ class GeorideTrackerEntity(TrackerEntity):
self._get_tracker_callback = get_tracker_callback self._get_tracker_callback = get_tracker_callback
self._name = tracker.tracker_name self._name = tracker.tracker_name
self._data = tracker or {} self._data = tracker or {}
self.entity_id = ENTITY_ID_FORMAT.format(tracker_id) self.entity_id = DOMAIN + ".{}".format(tracker_id)
@property @property
def unique_id(self): def unique_id(self):