Skip to content

Commit

Permalink
choose location
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasJoKuJonas committed May 8, 2023
1 parent ab7c91b commit 3be8815
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
19 changes: 17 additions & 2 deletions custom_components/webuntis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry):

hass.config_entries.async_update_entry(config_entry, options=new_options)

if config_entry.version == 8:
new_options = {**config_entry.options}
new_options["calendar_room"] = "long name"
config_entry.version = 9

hass.config_entries.async_update_entry(config_entry, options=new_options)

_LOGGER.info("Migration to version %s successful", config_entry.version)

return True
Expand Down Expand Up @@ -171,6 +178,7 @@ def __init__(
"calendar_show_cancelled_lessons"
]
self.calendar_description = config.options["calendar_description"]
self.calendar_room = config.options["calendar_room"]

self.keep_loged_in = config.options["keep_loged_in"]

Expand Down Expand Up @@ -529,8 +537,15 @@ def _get_events(self):

# add Room as location
try:
if lesson.rooms:
event["location"] = lesson.rooms[0].long_name
if lesson.rooms and not self.calendar_room == "None":
if self.calendar_room == "Room long name":
event["location"] = lesson.rooms[0].long_name
elif self.calendar_room == "Room short name":
event["location"] = lesson.rooms[0].name
elif self.calendar_room == "Room short-long name":
event[
"location"
] = f"{lesson.rooms[0].name} - {lesson.rooms[0].long_name}"
except IndexError:
# server does not return rooms
pass
Expand Down
14 changes: 14 additions & 0 deletions custom_components/webuntis/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,20 @@ async def async_step_calendar(
mode="dropdown",
)
),
vol.Required(
"calendar_room",
default=str(self.config_entry.options.get("calendar_room")),
): selector.SelectSelector(
selector.SelectSelectorConfig(
options=[
"Room long name",
"Room short name",
"Room short-long name",
"None",
],
mode="dropdown",
)
),
}
),
)
Expand Down
3 changes: 2 additions & 1 deletion custom_components/webuntis/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Constants for the Web Untis integration."""
DOMAIN = "webuntis"

CONFIG_ENTRY_VERSION = 8
CONFIG_ENTRY_VERSION = 9

DEFAULT_OPTIONS = {
"calendar_long_name": True,
Expand All @@ -14,6 +14,7 @@
"filter_description": [],
"extended_timetable": False,
"calendar_description": "JSON",
"calendar_room": "long name",
}

ICON_STATUS = "mdi:school-outline"
Expand Down
6 changes: 4 additions & 2 deletions custom_components/webuntis/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@
"data": {
"calendar_long_name": "Kalender - langer Name",
"calendar_show_cancelled_lessons": "Kalender - ausfallende Stunden",
"calendar_description": "Kalender Beschreibung"
"calendar_description": "Kalender - Beschreibung",
"calendar_room": "Kalender - Ort"
},
"data_description": {
"calendar_long_name": "Verwende den langen Namen der Stunden im Kalender.",
"calendar_show_cancelled_lessons": "Zeige ausfallende Stunden im Kalender an.",
"calendar_description": "Bestimme, was in der Beschreibung eines Kalender-Events stehen soll."
"calendar_description": "Bestimme, was in der Beschreibung eines Kalender-Events stehen soll.",
"calendar_room": "Bestimme, was im Kalender als Ort angezeigt wirt."
}
},
"backend": {
Expand Down
6 changes: 4 additions & 2 deletions custom_components/webuntis/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@
"data": {
"calendar_long_name": "Calendar - long name",
"calendar_show_cancelled_lessons": "Calendar - cancelled lessons",
"calendar_description": "Calendar description"
"calendar_description": "Calendar - description",
"calendar_room": "Calendar - Location"
},
"data_description": {
"calendar_long_name": "Use the long name of the hours in the calendar.",
"calendar_show_cancelled_lessons": "Show cancelled lessons in the calendar.",
"calendar_description": "Determine what should be in the description of a calendar event."
"calendar_description": "Determine what should be in the description of a calendar event.",
"calendar_room": "Specify what to display location."
}
},
"backend": {
Expand Down

0 comments on commit 3be8815

Please sign in to comment.