1 """Calendar platform for Mealie."""
3 from __future__
import annotations
5 from datetime
import datetime
7 from aiomealie
import Mealplan, MealplanEntryType
13 from .coordinator
import MealieConfigEntry, MealieMealplanCoordinator
14 from .entity
import MealieEntity
19 entry: MealieConfigEntry,
20 async_add_entities: AddEntitiesCallback,
22 """Set up the calendar platform for entity."""
23 coordinator = entry.runtime_data.mealplan_coordinator
27 for entry_type
in MealplanEntryType
32 """Create a CalendarEvent from a Mealplan."""
33 description: str |
None = mealplan.description
34 name = mealplan.title
or "No recipe"
36 name = mealplan.recipe.name
37 description = mealplan.recipe.description
39 start=mealplan.mealplan_date,
40 end=mealplan.mealplan_date,
42 description=description,
47 """A calendar entity."""
50 self, coordinator: MealieMealplanCoordinator, entry_type: MealplanEntryType
52 """Create the Calendar entity."""
53 super().
__init__(coordinator, entry_type.name.lower())
58 def event(self) -> CalendarEvent | None:
59 """Return the next upcoming event."""
60 mealplans = self.coordinator.data[self.
_entry_type_entry_type]
63 sorted_mealplans = sorted(mealplans, key=
lambda x: x.mealplan_date)
67 self, hass: HomeAssistant, start_date: datetime, end_date: datetime
68 ) -> list[CalendarEvent]:
69 """Get all events in a specific time frame."""
71 await self.coordinator.client.get_mealplans(
72 start_date.date(), end_date.date()
77 for mealplan
in mealplans
78 if mealplan.entry_type
is self.
_entry_type_entry_type
None __init__(self, MealieMealplanCoordinator coordinator, MealplanEntryType entry_type)
list[CalendarEvent] async_get_events(self, HomeAssistant hass, datetime start_date, datetime end_date)
CalendarEvent|None event(self)
None async_setup_entry(HomeAssistant hass, MealieConfigEntry entry, AddEntitiesCallback async_add_entities)
CalendarEvent _get_event_from_mealplan(Mealplan mealplan)