Fix parent child timetable switching - #108
Conversation
3b18f4a to
b4ab5f0
Compare
|
Hi, can you provide me a step by step explanation where I find the line to change and what to change? |
I have updated example script, check it: examples/timetables.py |
|
don't get me wrong, I'm happy that you tried to help me, but I'm lost all the time. In file editor -> home assistant/custom components/homeassistantedupage/homeassistant_edupage.py ?? |
|
Hi @WernAir77, Here's what changed and a complete example you can use right away. What Was FixedThis PR fixes parent accounts with multiple children. The issue was that
Complete Example ScriptHere's a simple script showing exactly how to use it: from edupage_api import Edupage
import datetime
# 1. Log in
edupage = Edupage()
edupage.login("your_email@example.com", "your_password", "edupage_school_domain")
# 2. Get your children
students = edupage.get_students() or []
if not students:
print("No children found")
else:
print("Available children:")
for i, student in enumerate(students):
print(f" {i+1}. {student.name}")
# 3. User selects a child by number
try:
choice = int(input("\nSelect child number (1, 2, ...): "))
child = students[choice - 1]
except (ValueError, IndexError):
print("Invalid choice!")
exit()
# 4. Switch to the selected child
print(f"\nSwitching to: {child.name}")
edupage.switch_to_child(child)
# 5. Get the child's timetable
today = datetime.date.today()
timetable = edupage.get_my_timetable(today)
# 6. Display it
print(f"\nTimetable for {child.name} on {today}:")
print("-" * 50)
if timetable:
for lesson in timetable:
subject = lesson.subject.name if lesson.subject else "Unknown"
teacher = lesson.teachers[0].name if lesson.teachers else "?"
print(f"[Period {lesson.period}] {subject} ({teacher})")
else:
print("No lessons found")** How To Use It **##
This is NOT Home Assistant code - it's the edupage-api Python library. If you're using Home Assistant, this library runs behind the scenes. |
|
I will test it tomorrow. Know I understand were we lost each other...you where talking about the api and python and I was talking about Homeassistant. It would be great if it worked there too I tested it. For my problem it isn’t a solution, because I seems that the structure of the database at my school is different from the one the api expected. I‘m able to choose a child, but I can‘t get the timetable. |
Summary
Fix parent account timetable switching when working with multiple children.
Problem
switch_to_child()used an exact type comparison:This does not work correctly when an
EduStudentinstance is passed, even thoughEduStudentis a subclass ofEduAccount.Additionally,
get_my_timetable()did not retain information about the explicitly selected child and continued using the legacy timetable path.Changes
isinstance(child, EduAccount)inswitch_to_child().get_my_timetable()resolves that student and uses the newerget_timetable(student, date)implementation.Testing
Tested with a parent account containing multiple children. Switching between the children now returns the correct timetable for each selected child.
Addresses #106.
Related to #95: the newer timetable path also avoids the legacy
/gcallrequest that can fail for some accounts. This PR does not completely fix #95 becauseget_my_timetable()without an explicitly selected child still uses the legacy implementation.