Skip to content

Fix parent child timetable switching - #108

Open
sveco86 wants to merge 1 commit into
EdupageAPI:masterfrom
sveco86:fix/parent-child-timetable
Open

Fix parent child timetable switching#108
sveco86 wants to merge 1 commit into
EdupageAPI:masterfrom
sveco86:fix/parent-child-timetable

Conversation

@sveco86

@sveco86 sveco86 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix parent account timetable switching when working with multiple children.

Problem

switch_to_child() used an exact type comparison:

type(child) == EduAccount

This does not work correctly when an EduStudent instance is passed, even though EduStudent is a subclass of EduAccount.

Additionally, get_my_timetable() did not retain information about the explicitly selected child and continued using the legacy timetable path.

Changes

  • Use isinstance(child, EduAccount) in switch_to_child().
  • Store the selected child ID after a successful child switch.
  • Clear the selected child ID when switching back to the parent.
  • When a child is explicitly selected, get_my_timetable() resolves that student and uses the newer get_timetable(student, date) implementation.
  • Add an example demonstrating timetable retrieval for a selected child.

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 /gcall request that can fail for some accounts. This PR does not completely fix #95 because get_my_timetable() without an explicitly selected child still uses the legacy implementation.

@sveco86
sveco86 force-pushed the fix/parent-child-timetable branch from 3b18f4a to b4ab5f0 Compare September 1, 2026 10:13
@WernAir77

Copy link
Copy Markdown

Hi, can you provide me a step by step explanation where I find the line to change and what to change?
Maybe I will find the right lines at the PC, but at my mobile I don‘t

@sveco86

sveco86 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Hi, can you provide me a step by step explanation where I find the line to change and what to change? Maybe I will find the right lines at the PC, but at my mobile I don‘t

I have updated example script, check it: examples/timetables.py

@WernAir77

WernAir77 commented Sep 1, 2026

Copy link
Copy Markdown

don't get me wrong, I'm happy that you tried to help me, but I'm lost all the time.
Where do I have to change the code? Where do I find the right place for changing? Is the code in Homeassistant? When yes what folder?
With the help of google I found something according to the edupage api at the web access, but I don't have admin rights, because I'm just a simple dad...I will fix this problem, but I can't for my own...sorry

In file editor -> home assistant/custom components/homeassistantedupage/homeassistant_edupage.py ??

@sveco86

sveco86 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Hi @WernAir77,

Here's what changed and a complete example you can use right away.

What Was Fixed

This PR fixes parent accounts with multiple children. The issue was that switch_to_child() didn't work properly with EduStudent objects. Now it:

  1. Correctly recognizes EduStudent (subclass check instead of exact type)
  2. Remembers which child is selected
  3. Uses the newer, more reliable timetable path for that child

Complete Example Script

Here'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 **##

  1. Save this as a .py file
  2. Replace your_email@example.com, your_password and edupage_school_domain with your actual login data
  3. Run it: python script_name.py

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.

@WernAir77

WernAir77 commented Sep 1, 2026

Copy link
Copy Markdown

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.

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.

[Bug] get_my_timetable: Insuficient privileg

2 participants