From 87446d7a1941dd9afa47126dac70afa99d0e106b Mon Sep 17 00:00:00 2001 From: Casper Biering Date: Fri, 14 Aug 2026 18:20:50 +0200 Subject: [PATCH] Fix ugeplan when Min Uddannelse Ugenoter widget is not exposed. Use widget 0023 (SSO) as a token fallback for /ugebrev, matching the existing MU Opgaver pattern. --- custom_components/aula/client.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/custom_components/aula/client.py b/custom_components/aula/client.py index c9168cd..a31f362 100644 --- a/custom_components/aula/client.py +++ b/custom_components/aula/client.py @@ -29,6 +29,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") + def decode_mu_deeplink(url): """Return the MinUddannelse page URL embedded in an opgave "url" field. @@ -1020,23 +1026,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 "0001" not in self.widgets ): _LOGGER.error( - "You have enabled ugeplaner, but we cannot find any supported widgets (0029,0004,0001) in Aula." + "You have enabled ugeplaner, but we cannot find any supported widgets (0029,0023,0004,0001) 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