Skip to content

Teacher access right fallback solution#269

Merged
JonasJoKuJonas merged 3 commits intoJonasJoKuJonas:mainfrom
Philip0606:feature_teacher_fallback_list
Apr 22, 2026
Merged

Teacher access right fallback solution#269
JonasJoKuJonas merged 3 commits intoJonasJoKuJonas:mainfrom
Philip0606:feature_teacher_fallback_list

Conversation

@Philip0606
Copy link
Copy Markdown
Contributor

Extend the webuntis session with a fallback solution to read a teacher list in case the user does not have access rights to the full teacher list.
In the case of missing access rights, the teacher list is created from the info that is provided in the lessons (id and a short 'name' of the teacher). This info is then used to create an internal teacher list, that is used by the teachers() method.
Since the teacher list is only created from the latest data, it will be updated every time the user is receiving a new timetable with previously unknown teachers.

To make it work in an existing configuration, the user has to delete the 'teachers' entry from his webuntis integration configuration (Backend->Exclude from requests) after updating the integration.

…r list in case the user does not have access rights to the full teacher list.

In the case of missing access rights, the teacher list is created from the info that is provided in the lessons (id and a short 'name' of the teacher).
This info is then used to create an internal teacher list, that is used by the teachers() method.

Since the teacher list is only created from the latest data, it will be updated every time the user is receiving a new timetable with previously unknown teachers.
@mrtncode
Copy link
Copy Markdown
Collaborator

mrtncode commented Mar 27, 2026

Thanks for contribution! But the sense of this change is not really clear :)
Why would you do this? The integration is to display the OWN timetable in Home Assistant. And when you are a teacher, you have the teacher rights :) Your change would add a lot of complexity.

@Philip0606
Copy link
Copy Markdown
Contributor Author

Without this change, I cannot see any information on teachers of my lessons in my own timetable, so I also cannot see when the teacher is changing.
With this change I get the teacher short name that the school provides together with the timetable.

@Philip0606
Copy link
Copy Markdown
Contributor Author

Should btw also fix issue #180, as I had the same problem, and it is gone now with this change.

@mrtncode
Copy link
Copy Markdown
Collaborator

mrtncode commented Apr 7, 2026

Ah, I understand.. Have you found out why you havent this permissions?
Though I think the solution to create an internal teacher list isnt perfect..

@mrtncode mrtncode requested a review from JonasJoKuJonas April 7, 2026 17:21
@Philip0606
Copy link
Copy Markdown
Contributor Author

Only employees of the school have the permission to get the Full teacher List. Students will only get the short name in their timetable.
Unfortunately the webuntis Python module up until now cannot handle this case well, so I implemented this Expansion of the Integration.
Technically, the home assistant integration is not changed, only the webuntis session class.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a fallback path for teacher lookup when the WebUntis server forbids direct teacher-list access, aiming to keep teacher-related features working by building a teacher list from timetable data.

Changes:

  • Extend ExtendedSession with a forbidden-teachers fallback that builds/updates an internal teacher mapping from getTimetable.
  • Update timetable calls to keep the fallback teacher mapping in sync with newly seen teachers.
  • Tighten compact_list merging so lessons with different rooms/teachers are no longer compacted together; improve debug logging around lesson JSON creation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
custom_components/webuntis/utils/web_untis_extended.py Adds teacher fallback mapping logic and hooks it into timetable retrieval / teachers() behavior.
custom_components/webuntis/utils/utils.py Prevents compaction across items that differ by rooms/teachers.
custom_components/webuntis/__init__.py Adds debug logs for failures when populating lesson JSON fields; minor formatting change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread custom_components/webuntis/utils/web_untis_extended.py
Comment thread custom_components/webuntis/utils/web_untis_extended.py
Comment thread custom_components/webuntis/__init__.py Outdated
@Philip0606
Copy link
Copy Markdown
Contributor Author

I just committed some changes based on the Copilot review results.

@Philip0606
Copy link
Copy Markdown
Contributor Author

@JonasJoKuJonas , could you have another look?
Do you have questions or suggestions?

@mrtncode
Copy link
Copy Markdown
Collaborator

mrtncode commented Apr 22, 2026

@Philip0606 Change looks solid for me. Altough I don‘t really get why you dont have permissions to fetch teachers. That doesnt make sense in my opinion :D
It is right that the problem is that you only get the teacher name in the lesson info but dont have permissions to fetch teacher. For what is the teacher list needed? Is it really important to have the teachers?

@JonasJoKuJonas JonasJoKuJonas merged commit 91637d3 into JonasJoKuJonas:main Apr 22, 2026
2 checks passed
@Philip0606
Copy link
Copy Markdown
Contributor Author

@mrtncode, without the teacher list, the Teachers() method fails for the session, so It will not get any information about changes in teachers (e.g. substitution teacher) in the timetable at all, as the python module is then just skipping all info (it could still just show the numeric id, but it won't....

@mrtncode
Copy link
Copy Markdown
Collaborator

@Philip0606 Ah great! Then I understood it right.
Thanks for contribution :)

JonasJoKuJonas added a commit that referenced this pull request Apr 24, 2026
…ack_list"

This reverts commit 91637d3, reversing
changes made to fff1c3b.

Pull request #269 introduced a bug that occurs when the timetable source is set to something other than the personal timetable and the account lacks teacher access rights.
Further testing showed that `timetable_source` is interpreted differently in `my_timetable` and `timetable_extended`. The method `_update_teacher_mapping` does not account for these differences and fails when calling `getTimetable`.

Until a proper fix is implemented and tested across different timetable sources for the “Teacher access right fallback solution,” these changes will be reverted to prevent the bug and keep the integration usable for affected users in the current version.
Philip0606 pushed a commit to Philip0606/homeassistant-WebUntis that referenced this pull request Apr 27, 2026
…_teacher_fallback_list"

This reverts commit 91637d3, reversing
changes made to fff1c3b.

Pull request JonasJoKuJonas#269 introduced a bug that occurs when the timetable source is set to something other than the personal timetable and the account lacks teacher access rights.
Further testing showed that `timetable_source` is interpreted differently in `my_timetable` and `timetable_extended`. The method `_update_teacher_mapping` does not account for these differences and fails when calling `getTimetable`.

Until a proper fix is implemented and tested across different timetable sources for the “Teacher access right fallback solution,” these changes will be reverted to prevent the bug and keep the integration usable for affected users in the current version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants