Skip to content

Commit

Permalink
add QCM error
Browse files Browse the repository at this point in the history
  • Loading branch information
Giga77 committed Apr 21, 2024
1 parent 288cbaa commit 333d0c2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions custom_components/ecole_directe/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from homeassistant.core import callback

from .ecole_directe_helper import (
QCMError,
get_ecoledirecte_session,
)

Expand Down Expand Up @@ -60,6 +61,8 @@ async def async_step_user(self, user_input: dict | None = None) -> FlowResult:
return self.async_create_entry(
title=session.identifiant, data=self._user_inputs
)
except QCMError:
errors["base"] = "double_auth"
except InvalidAuth:
errors["base"] = "invalid_auth"

Expand Down
3 changes: 3 additions & 0 deletions custom_components/ecole_directe/ecole_directe_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ def get_ecoledirecte_session(data, config_path) -> EDSession | None:
question = base64.b64decode(qcm["question"]).decode("utf-8")

if qcm_json is not None and question in qcm_json:
if len(qcm_json[question]) > 1:
try_login -= 1
continue
reponse = base64.b64encode(
bytes(qcm_json[question][0], "utf-8")
).decode("ascii")
Expand Down
1 change: 1 addition & 0 deletions custom_components/ecole_directe/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"double_auth": "[%key:common::config_flow::error::double_auth%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
Expand Down
1 change: 1 addition & 0 deletions custom_components/ecole_directe/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"error": {
"cannot_connect": "Failed to connect",
"invalid_auth": "Invalid authentication",
"double_auth": "Check the file qcm.json",
"unknown": "Unexpected error"
},
"step": {
Expand Down
1 change: 1 addition & 0 deletions custom_components/ecole_directe/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"error": {
"cannot_connect": "Impossible de se connecter",
"invalid_auth": "Erreur d'authentification",
"double_auth": "Vérifier le fichier qcm.json",
"unknown": "Une erreur est survenue"
},
"step": {
Expand Down

0 comments on commit 333d0c2

Please sign in to comment.