Skip to content

Commit

Permalink
Handle start and end date in async_get_events
Browse files Browse the repository at this point in the history
When requesting events home assistant might specify a start and end
date that the events returned should be between (for example, if a
user has an automation that calls calendar.get_events). The previous
implementation ignored these values and so would always return a full
set of events. This adds simple handling of those values to skip
returning events that fall outside the range.

The range passed in by home assistant may include time data, but that
is not handled here because we count all pickup events as taking the
whole day.
  • Loading branch information
chamook committed Mar 25, 2024
1 parent 78b287b commit 23fcef6
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions custom_components/affalddk/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ async def async_get_events(self, hass: HomeAssistant, start_date: datetime.datet

_pickup_events: PickupType = self._coordinator.data.pickup_events.get(item) if self._coordinator.data.pickup_events else None

if start_date.date() > _pickup_events.date:
continue
if end_date.date() < _pickup_events.date:
continue

_summary = NAME_LIST.get(item)
_start: datetime.date = _pickup_events.date
_end: datetime.date = _start + timedelta(days=1)
Expand Down

0 comments on commit 23fcef6

Please sign in to comment.