Skip to content

Commit

Permalink
save cancelled lesson in separate array
Browse files Browse the repository at this point in the history
  • Loading branch information
bbirnbach committed Dec 3, 2024
1 parent ea5901d commit 45c1861
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions custom_components/homeassistantedupage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import asyncio
from datetime import datetime, timedelta
from edupage_api.exceptions import BadCredentialsException, CaptchaException, SecondFactorFailedException
from edupage_api.exceptions import BadCredentialsException, CaptchaException
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
Expand Down Expand Up @@ -72,21 +72,32 @@ async def fetch_data():
notifications = await edupage.get_notifications()

timetable_data = {}
timetable_data_canceled = {}
today = datetime.now().date()
for offset in range(14):
current_date = today + timedelta(days=offset)
timetable = await edupage.get_timetable(student, current_date)
if timetable:
_LOGGER.debug(f"Timetable for {current_date}: {timetable}")
timetable_data[current_date] = timetable
lessons_to_add = []
canceled_lessons = []
for lesson in timetable:
if not lesson.is_cancelled:
lessons_to_add.append(lesson)
else:
canceled_lessons.append(lesson)
if lessons_to_add:
_LOGGER.debug(f"Timetable for {current_date}: {lessons_to_add}")
timetable_data[current_date] = lessons_to_add
else:
_LOGGER.warning(f"INIT No timetable found for {current_date}")
if canceled_lessons:
timetable_data_canceled[current_date] = canceled_lessons

return_data = {
"student": {"id": student.person_id, "name": student.name},
"grades": grades,
"subjects": subjects,
"timetable": timetable_data,
"cancelled_lessons": timetable_data_canceled,
"notifications": notifications,
}
_LOGGER.debug(f"INIT Coordinator fetch_data returning: {return_data}")
Expand Down

0 comments on commit 45c1861

Please sign in to comment.