mirror of
https://github.com/home-assistant/core.git
synced 2026-10-06 22:38:02 -04:00
Add event status to remote_calendar (#183849)
Co-authored-by: 1358 <1583407+1358@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
),
|
||||
)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
'start': dict({
|
||||
'dateTime': '2024-04-26T14:00:00-06:00',
|
||||
}),
|
||||
'status': None,
|
||||
'status': 'confirmed',
|
||||
'summary': 'Uffe',
|
||||
'uid': '040000008200E00074C5B7101A82E00800000000687C546B5596DA01000000000000000010000000309AE93C8C3A94489F90ADBEA30C2F2B',
|
||||
}),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user