From 70a9c8f8aa91e2acd7cc6c6b16925c36a59ec397 Mon Sep 17 00:00:00 2001 From: Daniele Ricci Date: Mon, 23 Jan 2023 01:00:19 +0100 Subject: [PATCH] Upgrade caldav to 1.0.1 (#85536) Upgrade caldav (fix #40127) date_search was deprecated in favour of search which also implements client-side recurring events expansion --- homeassistant/components/caldav/calendar.py | 16 ++++++++++++++-- homeassistant/components/caldav/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/caldav/test_calendar.py | 6 +++--- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/caldav/calendar.py b/homeassistant/components/caldav/calendar.py index 3fe5aab59c8..ab3c47b9690 100644 --- a/homeassistant/components/caldav/calendar.py +++ b/homeassistant/components/caldav/calendar.py @@ -2,6 +2,7 @@ from __future__ import annotations from datetime import date, datetime, timedelta +from functools import partial import logging import re @@ -172,7 +173,13 @@ class WebDavCalendarData: """Get all events in a specific time frame.""" # Get event list from the current calendar vevent_list = await hass.async_add_executor_job( - self.calendar.date_search, start_date, end_date + partial( + self.calendar.search, + start=start_date, + end=end_date, + event=True, + expand=True, + ) ) event_list = [] for event in vevent_list: @@ -202,7 +209,12 @@ class WebDavCalendarData: # We have to retrieve the results for the whole day as the server # won't return events that have already started - results = self.calendar.date_search(start_of_today, start_of_tomorrow) + results = self.calendar.search( + start=start_of_today, + end=start_of_tomorrow, + event=True, + expand=True, + ) # Create new events for each recurrence of an event that happens today. # For recurring events, some servers return the original event with recurrence rules diff --git a/homeassistant/components/caldav/manifest.json b/homeassistant/components/caldav/manifest.json index dc34542dffa..9dbb2289f54 100644 --- a/homeassistant/components/caldav/manifest.json +++ b/homeassistant/components/caldav/manifest.json @@ -2,7 +2,7 @@ "domain": "caldav", "name": "CalDAV", "documentation": "https://www.home-assistant.io/integrations/caldav", - "requirements": ["caldav==0.9.1"], + "requirements": ["caldav==1.0.1"], "codeowners": [], "iot_class": "cloud_polling", "loggers": ["caldav", "vobject"] diff --git a/requirements_all.txt b/requirements_all.txt index 58d9f7efaee..a3ac45ebc48 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -507,7 +507,7 @@ btsmarthub_devicelist==0.2.3 buienradar==1.0.5 # homeassistant.components.caldav -caldav==0.9.1 +caldav==1.0.1 # homeassistant.components.circuit circuit-webhook==1.0.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 983eb5696a4..b1efede0cb4 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -408,7 +408,7 @@ bthome-ble==2.5.0 buienradar==1.0.5 # homeassistant.components.caldav -caldav==0.9.1 +caldav==1.0.1 # homeassistant.components.co2signal co2signal==0.4.2 diff --git a/tests/components/caldav/test_calendar.py b/tests/components/caldav/test_calendar.py index 60a560a94fe..522d5cb2e76 100644 --- a/tests/components/caldav/test_calendar.py +++ b/tests/components/caldav/test_calendar.py @@ -349,12 +349,12 @@ def _mocked_dav_client(*names, calendars=None): def _mock_calendar(name): + calendar = Mock() events = [] for idx, event in enumerate(EVENTS): - events.append(Event(None, "%d.ics" % idx, event, None, str(idx))) + events.append(Event(None, "%d.ics" % idx, event, calendar, str(idx))) - calendar = Mock() - calendar.date_search = MagicMock(return_value=events) + calendar.search = MagicMock(return_value=events) calendar.name = name return calendar