Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions custom_components/aula/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
# schools that do not expose 0030 to guardians.
MU_OPGAVER_WIDGETS = ("0030", "0023")

# Widgets that can mint a token for the Min Uddannelse "ugebrev" endpoint,
# in order of preference. 0029 is the dedicated "Ugenoter" widget; 0023
# ("MinUddannelse - SSO") is accepted by the same endpoint and is available at
# schools that do not expose 0029 to guardians.
MU_UGEPLAN_WIDGETS = ("0029", "0023")

# Widgets that can mint a token for the EasyIQ Ugeplan endpoint,
# in order of preference.
EASYIQ_WIDGETS = ("0001", "0128", "00142", "0142")
Expand Down Expand Up @@ -1058,23 +1064,27 @@ def mu_opgaver(week, thisnext):

if len(self.widgets) == 0:
self.get_widgets()
mu_uge_widget = next(
(widget for widget in MU_UGEPLAN_WIDGETS if widget in self.widgets),
None,
)
if (
"0029" not in self.widgets
mu_uge_widget is None
and "0004" not in self.widgets
and "0062" not in self.widgets
and not any(widget in self.widgets for widget in EASYIQ_WIDGETS)
):
_LOGGER.error(
"You have enabled ugeplaner, but we cannot find any supported widgets (0029,0004,0062,EasyIQ) in Aula."
"You have enabled ugeplaner, but we cannot find any supported widgets (0029,0023,0004,0062,EasyIQ) in Aula."
)
if "0029" in self.widgets and "0004" in self.widgets:
if mu_uge_widget is not None and "0004" in self.widgets:
_LOGGER.warning(
"Multiple sources for ugeplaner is untested and might cause problems."
)

def ugeplan(week, thisnext):
if "0029" in self.widgets:
token = self.get_token("0029")
if mu_uge_widget is not None:
token = self.get_token(mu_uge_widget)
get_payload = (
"/ugebrev?assuranceLevel=2&childFilter="
+ childUserIds
Expand Down
23 changes: 23 additions & 0 deletions tests/test_mu_opgaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from custom_components.aula.client import (
MU_OPGAVER_WIDGETS,
MU_UGEPLAN_WIDGETS,
EASYIQ_WIDGETS,
decode_mu_deeplink,
format_mu_opgaver,
Expand Down Expand Up @@ -43,6 +44,28 @@ def test_widget_selection__none_available():
assert selected is None


def test_ugeplan_widget_preference_order():
assert MU_UGEPLAN_WIDGETS == ("0029", "0023")


def test_ugeplan_widget_selection__prefers_0029():
widgets = {"0023": "MinUddannelse - SSO", "0029": "MinUddannelse – Ugenoter"}
selected = next((w for w in MU_UGEPLAN_WIDGETS if w in widgets), None)
assert selected == "0029"


def test_ugeplan_widget_selection__falls_back_to_0023():
widgets = {"0023": "MinUddannelse - SSO", "0072": "MU Elev - fravær"}
selected = next((w for w in MU_UGEPLAN_WIDGETS if w in widgets), None)
assert selected == "0023"


def test_ugeplan_widget_selection__none_available():
widgets = {"0001": "EasyIQ"}
selected = next((w for w in MU_UGEPLAN_WIDGETS if w in widgets), None)
assert selected is None


def test_easyiq_widget_preference_order():
assert EASYIQ_WIDGETS == ("0001", "0128", "00142", "0142")

Expand Down
Loading