mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix timezones used in list events (#95804)
* Fix timezones used in list events * Add additional tests that catch floating vs timezone datetime comparisons
This commit is contained in:
parent
60e2ee86b2
commit
26f2fabd85
@ -793,7 +793,9 @@ async def async_list_events_service(
|
|||||||
end = start + service_call.data[EVENT_DURATION]
|
end = start + service_call.data[EVENT_DURATION]
|
||||||
else:
|
else:
|
||||||
end = service_call.data[EVENT_END_DATETIME]
|
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)
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
"events": [
|
"events": [
|
||||||
dataclasses.asdict(event, dict_factory=_list_events_dict_factory)
|
dataclasses.asdict(event, dict_factory=_list_events_dict_factory)
|
||||||
|
@ -67,14 +67,6 @@ class DemoCalendar(CalendarEntity):
|
|||||||
end_date: datetime.datetime,
|
end_date: datetime.datetime,
|
||||||
) -> list[CalendarEvent]:
|
) -> list[CalendarEvent]:
|
||||||
"""Return calendar events within a datetime range."""
|
"""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
|
assert start_date < end_date
|
||||||
if self._event.start_datetime_local >= end_date:
|
if self._event.start_datetime_local >= end_date:
|
||||||
return []
|
return []
|
||||||
|
@ -388,7 +388,17 @@ async def test_create_event_service_invalid_params(
|
|||||||
|
|
||||||
|
|
||||||
@freeze_time("2023-06-22 10:30:00+00:00")
|
@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.
|
"""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
|
This test uses a fixed date/time so that it can deterministically test the
|
||||||
@ -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 async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
start = dt_util.now()
|
|
||||||
end = start + timedelta(days=1)
|
|
||||||
|
|
||||||
response = await hass.services.async_call(
|
response = await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_LIST_EVENTS,
|
SERVICE_LIST_EVENTS,
|
||||||
{
|
{
|
||||||
"entity_id": "calendar.calendar_1",
|
"entity_id": "calendar.calendar_1",
|
||||||
"start_date_time": start,
|
"start_date_time": start_time,
|
||||||
"end_date_time": end,
|
"end_date_time": end_time,
|
||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
return_response=True,
|
return_response=True,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user