Skip to content

Commit

Permalink
Merge pull request #62 from rine77/61-feature_request-cleanup-data-in…
Browse files Browse the repository at this point in the history
…-calendar-event

calendar data cleanup
  • Loading branch information
rine77 authored Dec 16, 2024
2 parents 9636b9b + 693d5d0 commit 7639ff6
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions custom_components/homeassistantedupage/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ async def async_added_to_hass(self) -> None:
self.coordinator.async_add_listener(
self._handle_coordinator_update, None
)
)
)

class EdupageCalendar(CoordinatorEntity, CalendarEntity):
"""Representation of an Edupage calendar entity."""

def __init__(self, coordinator, data):
super().__init__(coordinator)
self._data = data
self._data = data
self._events = []
self._attr_name = "Edupage Calendar"
_LOGGER.debug(f"CALENDAR Initialized EdupageCalendar with data: {data}")
Expand All @@ -57,7 +57,7 @@ def name(self):
"""Return the name of the calendar."""
student_name = self.coordinator.data.get("student", {}).get("name", "Unknown Student")
return f"Edupage - {student_name}"

@property
def extra_state_attributes(self):
"""Return the extra state attributes."""
Expand Down Expand Up @@ -115,23 +115,24 @@ def get_events(self, timetable, current_date):


def map_lesson_to_calender_event(self, lesson: Lesson, day: date) -> CalendarEvent:
room = "Unknown"
if lesson.classrooms:
room = lesson.classrooms[0].name

teacher_names = [teacher.name for teacher in lesson.teachers] if lesson.teachers else []

teachers = ", ".join(teacher_names) if teacher_names else "Unknown Teacher"
description=f"Teacher(s): {teachers}"
room = None
if lesson.classrooms:
room = lesson.classrooms[0].name
description += f"\nRoom: {room}"
local_tz = ZoneInfo(self.hass.config.time_zone)
start_time = datetime.combine(day, lesson.start_time).astimezone(local_tz)
end_time = datetime.combine(day, lesson.end_time).astimezone(local_tz)
lesson_subject = lesson.subject.name if lesson.subject else "Unknown Subject"
lesson_subject_prefix = "[Canceled] " if lesson.is_cancelled else ""

cal_event = CalendarEvent(
start=start_time,
end=end_time,
summary= lesson_subject_prefix + lesson_subject,
description=f"Room: {room}\nTeacher(s): {teachers}",
description=description,
location=room
)
return cal_event
Expand Down

0 comments on commit 7639ff6

Please sign in to comment.