Skip to content

Commit

Permalink
calendar async_setup_entry cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrfilipmarek committed Dec 17, 2024
1 parent 2ec4b0d commit 4918b90
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions custom_components/homeassistantedupage/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from homeassistant.components.calendar import CalendarEntity, CalendarEvent
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from .const import DOMAIN
from zoneinfo import ZoneInfo
from edupage_api.timetables import Lesson
Expand All @@ -13,22 +15,26 @@
_LOGGER = logging.getLogger("custom_components.homeassistant_edupage")
_LOGGER.debug("CALENDAR Edupage calendar.py is being loaded")

async def async_setup_entry(hass, entry, async_add_entities: AddEntitiesCallback) -> None:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> None:
"""Set up Edupage calendar entities."""
_LOGGER.debug("CALENDAR called async_setup_entry")

coordinator = hass.data[DOMAIN][entry.entry_id]

calendars = []

edupage_calendar = EdupageCalendar(coordinator, entry.data)
async_add_entities([edupage_calendar])
calendars.append(edupage_calendar)

if coordinator.data.get("canteen_calendar_enabled", {}):
edupage_canteen_calendar = EdupageCanteenCalendar(coordinator, entry.data)
async_add_entities([edupage_canteen_calendar])
calendars.append(edupage_canteen_calendar)
_LOGGER.debug("Canteen calendar added")
else:
_LOGGER.debug("Canteen calendar skipped, calendar disabled due to exceptions")

async_add_entities(calendars)

_LOGGER.debug("CALENDAR async_setup_entry finished.")

async def async_added_to_hass(self) -> None:
Expand Down

0 comments on commit 4918b90

Please sign in to comment.