From ec85614b51ba43ee76b0f972e9201b9ecb4fa365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Thu, 26 Oct 2023 19:04:26 +0200 Subject: [PATCH] refac: CalDAV.get_events --- api/ovdashboard_api/core/caldav.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/api/ovdashboard_api/core/caldav.py b/api/ovdashboard_api/core/caldav.py index 26d42fe..dca1c78 100644 --- a/api/ovdashboard_api/core/caldav.py +++ b/api/ovdashboard_api/core/caldav.py @@ -1,10 +1,11 @@ import logging from datetime import datetime, timedelta +from typing import cast from asyncify import asyncify from cache import AsyncTTL from caldav import Calendar, DAVClient, Event, Principal -from vobject.base import Component +from vobject.base import Component, toVName from .calevent import CalEvent from .config import Config @@ -73,15 +74,13 @@ class CalDAV: _logger.info(f"downloading {calendar_name!r} ...") - search_span = timedelta(days=cfg.calendar.future_days) - calendar = cls.principal.calendar(calendar_name) + dt_start = datetime.combine( + datetime.utcnow().date(), + datetime.min.time(), + ) + dt_end = dt_start + timedelta(days=cfg.calendar.future_days) - date_start = datetime.utcnow().date() - time_min = datetime.min.time() - dt_start = datetime.combine(date_start, time_min) - dt_end = dt_start + search_span - - search_result = calendar.search( + search_result = cls.principal.calendar(calendar_name).search( start=dt_start, end=dt_end, expand=True, @@ -91,7 +90,7 @@ class CalDAV: vevents = [] for event in search_result: - vobject: Component = event.vobject_instance # type: ignore - vevents.extend(vobject.vevent_list) + vobject = cast(Component, event.vobject_instance) + vevents.extend(vobject.contents[toVName("vevent")]) return sorted(CalEvent.from_vevent(vevent) for vevent in vevents)