Skip to content

Commit

Permalink
show errors on notification setup
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasJoKuJonas committed Feb 29, 2024
1 parent 4f68e0e commit cbaa8e1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
27 changes: 19 additions & 8 deletions custom_components/webuntis/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ async def async_step_user(
except InvalidAuth:
errors["name"] = "invalid_auth"
except BadCredentials:
errors["password"] = "bad_credentials"
errors["name"] = "bad_credentials"
except SchoolNotFound:
errors["school"] = "school_not_found"
except NameSplitError:
Expand Down Expand Up @@ -404,12 +404,12 @@ async def async_step_backend(
not user_input["extended_timetable"]
and self.config_entry.options["filter_description"]
):
errors = {"base": "extended_timetable"}
errors = {"extended_timetable": "extended_timetable"}
elif (
user_input["extended_timetable"] is False
and self.config_entry.options["calendar_description"] == "Lesson Info"
):
errors = {"base": "extended_timetable"}
errors = {"extended_timetable": "extended_timetable"}
else:
return await self.save(user_input)
return self.async_show_form(
Expand Down Expand Up @@ -462,16 +462,27 @@ async def async_step_notify(
}
user_input["notify_options"] = notify_options

errors = {}

if "notify_entity_id" in user_input:
if not is_service(self.hass, user_input["notify_entity_id"]):
errors = {"base": "unknown_service"}
errors["base"] = "unknown_service"
else:
user_input["notify_entity_id"] = ""
if "notify_target" not in user_input:

if "notify_target" in user_input:
if not isinstance(user_input["notify_target"], dict):
errors["notify_target"] = "not_a_dict"
else:
user_input["notify_target"] = {}
if "notify_data" not in user_input:
if "notify_data" in user_input:
if not isinstance(user_input["notify_data"], dict):
errors["notify_data"] = "not_a_dict"
else:
user_input["notify_data"] = {}
return await self.save(user_input)

if not errors:
return await self.save(user_input)

schema_options = {
vol.Optional(
Expand All @@ -485,7 +496,7 @@ async def async_step_notify(
description={
"suggested_value": self.config_entry.options.get("notify_target")
},
): selector.ObjectSelector(),
): selector.ObjectSelector(selector.ObjectSelectorConfig()),
vol.Optional(
"notify_data",
description={
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 @@ -32,6 +32,7 @@
"error": {
"extended_timetable": "Für die Optionen \"Fächer Filter - Beschreibung\" und \"Kalender-Beschreibung\" (Lesson Info) wird \"Erweiterten Stundenplan anfordern\" benötigt",
"unknown_service": "Service-ID nicht gefunden.",
"not_a_dict": "Muss ein Dictionary sein",
"notification_invalid": "Benachrichtigung konnte nicht gesendet werden. Siehe Logs für mehr Infos.",
"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 @@ -32,6 +32,7 @@
"error": {
"extended_timetable": "\"Request extended timetable\" is required for the \"Subject Filter - Description\" and \"Calendar Description\" (Lesson Info) option",
"unknown_service": "Service ID not found.",
"not_a_dict": "Has to be a dictionary",
"notification_invalid": "Notification could not be sent. See logs for more information.",
"unknown": "Unexpected error"
},
Expand Down

0 comments on commit cbaa8e1

Please sign in to comment.