Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion homeassistant/components/calendar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,9 @@ async def async_list_events_service(
end = start + service_call.data[EVENT_DURATION]
else:
end = service_call.data[EVENT_END_DATETIME]
calendar_event_list = await calendar.async_get_events(calendar.hass, start, end)
calendar_event_list = await calendar.async_get_events(
calendar.hass, dt_util.as_local(start), dt_util.as_local(end)
Comment thread
MartinHjelmare marked this conversation as resolved.
)
return {
"events": [
dataclasses.asdict(event, dict_factory=_list_events_dict_factory)
Expand Down
8 changes: 0 additions & 8 deletions homeassistant/components/demo/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ async def async_get_events(
end_date: datetime.datetime,
) -> list[CalendarEvent]:
"""Return calendar events within a datetime range."""
if start_date.tzinfo is None:
start_date = start_date.replace(
tzinfo=dt_util.get_time_zone(hass.config.time_zone)
)
if end_date.tzinfo is None:
end_date = end_date.replace(
tzinfo=dt_util.get_time_zone(hass.config.time_zone)
)
assert start_date < end_date
if self._event.start_datetime_local >= end_date:
return []
Expand Down
19 changes: 13 additions & 6 deletions tests/components/calendar/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,17 @@ async def test_create_event_service_invalid_params(


@freeze_time("2023-06-22 10:30:00+00:00")
async def test_list_events_service(hass: HomeAssistant, set_time_zone: None) -> None:
@pytest.mark.parametrize(
("start_time", "end_time"),
[
("2023-06-22T04:30:00-06:00", "2023-06-22T06:30:00-06:00"),
("2023-06-22T04:30:00", "2023-06-22T06:30:00"),
("2023-06-22T10:30:00Z", "2023-06-22T12:30:00Z"),
],
)
async def test_list_events_service(
hass: HomeAssistant, set_time_zone: None, start_time: str, end_time: str
) -> None:
"""Test listing events from the service call using exlplicit start and end time.

This test uses a fixed date/time so that it can deterministically test the
Expand All @@ -398,16 +408,13 @@ async def test_list_events_service(hass: HomeAssistant, set_time_zone: None) ->
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
await hass.async_block_till_done()

start = dt_util.now()
end = start + timedelta(days=1)

response = await hass.services.async_call(
DOMAIN,
SERVICE_LIST_EVENTS,
{
"entity_id": "calendar.calendar_1",
"start_date_time": start,
"end_date_time": end,
"start_date_time": start_time,
"end_date_time": end_time,
},
blocking=True,
return_response=True,
Expand Down