Skip to content

Commit

Permalink
Enable recurrence delete via calendar UI
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Mar 7, 2023
1 parent af1c4b0 commit 028c276
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 10 additions & 3 deletions custom_components/o365/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ async def async_delete_event(
recurrence_range: str | None = None,
) -> None:
"""Delete an event on the calendar."""
await self.hass.async_add_executor_job(self.remove_calendar_event, uid)
await self.hass.async_add_executor_job(
self.remove_calendar_event, uid, recurrence_id, recurrence_range
)

def create_calendar_event(
self,
Expand Down Expand Up @@ -436,7 +438,7 @@ def modify_calendar_event(
event.save()
self._raise_event(EVENT_MODIFY_CALENDAR_EVENT, event_id)

def remove_calendar_event(self, event_id):
def remove_calendar_event(self, event_id, recurrence_id, recurrence_range):
"""Remove the event."""
if not self._validate_permissions("delete"):
return
Expand All @@ -445,7 +447,10 @@ def remove_calendar_event(self, event_id):
_group_calendar_log(self.entity_id)
return

event = self._get_event_from_calendar(event_id)
if recurrence_range:
event = self._get_event_from_calendar(recurrence_id)
else:
event = self._get_event_from_calendar(event_id)
event.delete()
self._raise_event(EVENT_REMOVE_CALENDAR_EVENT, event_id)

Expand Down Expand Up @@ -601,6 +606,8 @@ async def async_get_events(self, hass, start_date, end_date):
vevent.location["displayName"],
uid=vevent.object_id,
)
if vevent.series_master_id:
event.recurrence_id = vevent.series_master_id
event_list.append(event)

return event_list
Expand Down
4 changes: 3 additions & 1 deletion docs/calendar_panel.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ title: Calendar Panel
nav_order: 11
---

Creation and deletion of events is possible via the Calendar Panel introduced in HA 2023.1. This UI allows you to create recurring events, which is not possible via the HA services methods. However, it is not possible to delete all occurrences of a recurring event through this method due to the way recurring events are handled in O365 compared to the iCal standard (which underpins the HA calendars). Either delete individually, or via an alternate method such as Outlook.
Creation and deletion of events is possible via the Calendar Panel introduced in HA 2023.1. This UI allows you to create recurring events, which is not possible via the HA services methods.

If you choose to delete 'Delete All Future Events', it will delete the whole series not just future events. This is due to the differences between O365 and the iCal specification that the core calendar is built on.

0 comments on commit 028c276

Please sign in to comment.