Skip to content

Commit

Permalink
add no class found error message
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasJoKuJonas committed Nov 12, 2022
1 parent be8c852 commit 75a6065
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions custom_components/webuntis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
from typing import Any

# pylint: disable=import-self
import webuntis

from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -87,6 +88,7 @@ def __init__(
self.timetable_source = config_data["timetable_source"]
self.timetable_source_id = config_data["timetable_source_id"]

# pylint: disable=maybe-no-member
self.session = webuntis.Session(
username=self.username,
password=self.password,
Expand Down Expand Up @@ -139,6 +141,7 @@ async def _async_status_request(self) -> None:
self.next_class = None
self.next_lesson_to_wake_up = None

# pylint: disable=maybe-no-member
self.session = webuntis.Session(
username=self.username,
password=self.password,
Expand Down
18 changes: 15 additions & 3 deletions custom_components/webuntis/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ async def validate_input(
raise CannotConnect from exc

try:
# pylint: disable=maybe-no-member
session = webuntis.Session(
server=user_input["server"],
school=user_input["school"],
Expand All @@ -80,7 +81,7 @@ async def validate_input(
raise BadCredentials from ext
except requests.exceptions.ConnectionError as exc:
raise CannotConnect from exc
except webuntis.errors.RemoteError as exc:
except webuntis.errors.RemoteError as exc: # pylint: disable=no-member
raise SchoolNotFound from exc
except Exception as exc:
raise InvalidAuth from exc
Expand All @@ -97,7 +98,10 @@ async def validate_input(
raise StudentNotFound from exc
elif timetable_source == "klasse":
klassen = await hass.async_add_executor_job(session.klassen)
source = klassen.filter(name=timetable_source_id)[0]
try:
source = klassen.filter(name=timetable_source_id)[0]
except Exception as exc:
raise ClassNotFound from exc
elif timetable_source == "teacher":
try:
source = await hass.async_add_executor_job(
Expand Down Expand Up @@ -140,7 +144,9 @@ async def async_step_user(
step_id="user", data_schema=STEP_USER_DATA_SCHEMA
)
await self.async_set_unique_id(
"{username}@{school}".format(**user_input).lower().replace(" ", "-")
"{username}@{timetable_source_id}@{school}".format(**user_input)
.lower()
.replace(" ", "-")
)
self._abort_if_unique_id_configured()

Expand All @@ -166,6 +172,8 @@ async def async_step_user(
errors["base"] = "student_not_found"
except TeacherNotFound:
errors["base"] = "teacher_not_found"
except ClassNotFound:
errors["base"] = "class_not_found"
except NoRightsForTimetable:
errors["base"] = "no_rights_for_timetable"

Expand Down Expand Up @@ -238,5 +246,9 @@ class TeacherNotFound(HomeAssistantError):
"""Error to indicate there is no teacher with this name."""


class ClassNotFound(HomeAssistantError):
"""Error to indicate there is no class with this name."""


class NoRightsForTimetable(HomeAssistantError):
"""Error to indicate there is no right for timetable."""
1 change: 1 addition & 0 deletions custom_components/webuntis/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"name_split_error": "[%key:common::config_flow::error::name_split_error%]",
"student_not_found": "[%key:common::config_flow::error::student_not_found%]",
"teacher_not_found": "[%key:common::config_flow::error::teacher_not_found%]",
"class_not_found": "[%key:common::config_flow::error::class_not_found%]",
"no_rights_for_timetable": "[%key:common::config_flow::error::no_rights_for_timetable%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
},
Expand Down
1 change: 1 addition & 0 deletions custom_components/webuntis/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"name_split_error": "Ungültiger Name. Versuche \"vor_name, nach_name\".",
"student_not_found": "Schüler nicht gefunden. Überprüfen Sie den Namen oder wählen Sie eine andere Quelle.",
"teacher_not_found": "Lehrer nicht gefunden. Überprüfen Sie den Namen oder wählen Sie eine andere Quelle.",
"class_not_found": "Klasse nicht gefunden. Überprüfen Sie den Klasse oder wählen Sie eine andere Quelle.",
"no_rights_for_timetable": "Keine rechte für Stundenplan.",
"unknown": "Unerwarteter Fehler"
},
Expand Down
1 change: 1 addition & 0 deletions custom_components/webuntis/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"name_split_error": "Invalid name. Try \"first_name, last_name\".",
"student_not_found": "Student not found. Check the name or pick other source.",
"teacher_not_found": "Teacher not found. Check the name or pick other source.",
"class_not_found": "Class not found. Check the class or pick other source.",
"no_rights_for_timetable": "No rights for timetable.",
"unknown": "Unexpected error"
},
Expand Down

0 comments on commit 75a6065

Please sign in to comment.