mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Fix google calendar recurrence rule create and view (#84330)
* Fix bug in google calendar recurrence rule handling * Convert multiline ternary operator expressions to if block
This commit is contained in:
parent
06b4c82a37
commit
4e1b399efd
@ -89,6 +89,10 @@ SYNC_EVENT_MIN_TIME = timedelta(days=-90)
|
||||
# are not opaque are ignored by default.
|
||||
OPAQUE = "opaque"
|
||||
|
||||
# Google calendar prefixes recurrence rules with RRULE: which
|
||||
# we need to strip when working with the frontend recurrence rule values
|
||||
RRULE_PREFIX = "RRULE:"
|
||||
|
||||
_EVENT_IN_TYPES = vol.Schema(
|
||||
{
|
||||
vol.Exclusive(EVENT_IN_DAYS, EVENT_TYPES_CONF): cv.positive_int,
|
||||
@ -526,7 +530,7 @@ class GoogleCalendarEntity(CoordinatorEntity, CalendarEntity):
|
||||
}
|
||||
)
|
||||
if rrule := kwargs.get(EVENT_RRULE):
|
||||
event.recurrence = [rrule]
|
||||
event.recurrence = [f"{RRULE_PREFIX}{rrule}"]
|
||||
|
||||
await self.coordinator.sync.store_service.async_add_event(event)
|
||||
await self.coordinator.async_refresh()
|
||||
@ -551,10 +555,13 @@ class GoogleCalendarEntity(CoordinatorEntity, CalendarEntity):
|
||||
|
||||
def _get_calendar_event(event: Event) -> CalendarEvent:
|
||||
"""Return a CalendarEvent from an API event."""
|
||||
rrule: str | None = None
|
||||
if len(event.recurrence) == 1:
|
||||
rrule = event.recurrence[0].lstrip(RRULE_PREFIX)
|
||||
return CalendarEvent(
|
||||
uid=event.ical_uuid,
|
||||
recurrence_id=event.id if event.recurring_event_id else None,
|
||||
rrule=event.recurrence[0] if len(event.recurrence) == 1 else None,
|
||||
rrule=rrule,
|
||||
summary=event.summary,
|
||||
start=event.start.value,
|
||||
end=event.end.value,
|
||||
|
@ -915,7 +915,7 @@ async def test_websocket_create_all_day(
|
||||
"date": "1997-07-14",
|
||||
},
|
||||
"end": {"date": "1997-07-15"},
|
||||
"recurrence": ["FREQ=YEARLY"],
|
||||
"recurrence": ["RRULE:FREQ=YEARLY"],
|
||||
}
|
||||
|
||||
|
||||
@ -1001,6 +1001,7 @@ async def test_websocket_delete_recurring_event_instance(
|
||||
event = events[1]
|
||||
assert event["uid"] == "event-id-1@google.com"
|
||||
assert event["recurrence_id"] == "event-id-1_20221015"
|
||||
assert event["rrule"] == "FREQ=WEEKLY"
|
||||
|
||||
# Expect a delete request as well as a follow up to sync state from server
|
||||
aioclient_mock.clear_requests()
|
||||
|
Loading…
x
Reference in New Issue
Block a user