diff --git a/homeassistant/components/remote_calendar/calendar.py b/homeassistant/components/remote_calendar/calendar.py index a5bfbab09546..7e10612a0559 100644 --- a/homeassistant/components/remote_calendar/calendar.py +++ b/homeassistant/components/remote_calendar/calendar.py @@ -7,7 +7,11 @@ from typing import override from ical.event import Event, EventStatus from ical.timeline import Timeline, materialize_timeline -from homeassistant.components.calendar import CalendarEntity, CalendarEvent +from homeassistant.components.calendar import ( + CalendarEntity, + CalendarEvent, + CalendarEventStatus, +) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -170,4 +174,10 @@ def _get_calendar_event(event: Event) -> CalendarEvent: rrule=event.rrule.as_rrule_str() if event.rrule else None, recurrence_id=event.recurrence_id, location=event.location, + # Callers drop cancelled events, the one status CalendarEventStatus lacks. + status=( + CalendarEventStatus(event.status.value.lower()) + if event.status is not None + else None + ), ) diff --git a/tests/components/remote_calendar/snapshots/test_calendar.ambr b/tests/components/remote_calendar/snapshots/test_calendar.ambr index 470e3d08d221..a07883fb37d4 100644 --- a/tests/components/remote_calendar/snapshots/test_calendar.ambr +++ b/tests/components/remote_calendar/snapshots/test_calendar.ambr @@ -12,7 +12,7 @@ 'start': dict({ 'dateTime': '2024-04-26T14:00:00-06:00', }), - 'status': None, + 'status': 'confirmed', 'summary': 'Uffe', 'uid': '040000008200E00074C5B7101A82E00800000000687C546B5596DA01000000000000000010000000309AE93C8C3A94489F90ADBEA30C2F2B', }), diff --git a/tests/components/remote_calendar/test_calendar.py b/tests/components/remote_calendar/test_calendar.py index 954b43e67b7c..66e91d858c82 100644 --- a/tests/components/remote_calendar/test_calendar.py +++ b/tests/components/remote_calendar/test_calendar.py @@ -213,6 +213,51 @@ async def test_api_date_event( assert len(events) == 1 +STATUS_EVENT_ICS = textwrap.dedent( + """\ + BEGIN:VCALENDAR + VERSION:2.0 + BEGIN:VEVENT + SUMMARY:Bastille Day Party + DTSTART:19970714 + DTEND:19970715 + {status} + END:VEVENT + END:VCALENDAR + """ +) + + +@pytest.mark.parametrize( + ("status", "expected_status"), + [ + pytest.param("STATUS:TENTATIVE", "tentative", id="tentative"), + pytest.param("STATUS:CONFIRMED", "confirmed", id="confirmed"), + pytest.param("", None, id="no_status"), + ], +) +@respx.mock +async def test_event_status( + hass: HomeAssistant, + config_entry: MockConfigEntry, + get_events: GetEventsFn, + status: str, + expected_status: str | None, +) -> None: + """Test that the rfc5545 STATUS property is returned by the API.""" + respx.get(CALENDER_URL).mock( + return_value=Response( + status_code=200, text=STATUS_EVENT_ICS.format(status=status) + ) + ) + await setup_integration(hass, config_entry) + + events = await get_events("1997-07-13T00:00:00", "1997-07-16T00:00:00") + + assert len(events) == 1 + assert events[0]["status"] == expected_status + + CANCELLED_EVENT_ICS = textwrap.dedent( """\ BEGIN:VCALENDAR