|
|
@@ -9,12 +9,29 @@ from room_cal._utils import EventSource, get_config, safe_json_loads, services a
|
|
|
|
|
|
_ROOM_CLOSED_TITLE = 'Room Closed'
|
|
|
|
|
|
+_user_calendar: Calendar | None = None
|
|
|
+
|
|
|
+
|
|
|
+def _get_user_calendar() -> Calendar:
|
|
|
+ """Shared Calendar for the user_cal connection, created on first call.
|
|
|
+
|
|
|
+ Memoized so the resolved calendar URL survives across UserCal()
|
|
|
+ constructions. The event cache is cleared per construction — the user
|
|
|
+ edits this calendar externally, so each operation must re-read.
|
|
|
+ """
|
|
|
+ global _user_calendar
|
|
|
+ if _user_calendar is None:
|
|
|
+ cfg = get_config().user_cal
|
|
|
+ _user_calendar = Calendar(cfg.calendar_name, url=cfg.url, username=cfg.username, password=cfg.password)
|
|
|
+ return _user_calendar
|
|
|
+
|
|
|
|
|
|
class UserCal(EventSource):
|
|
|
def __init__(self, *, backend=None):
|
|
|
if backend is None:
|
|
|
- cfg = get_config().user_cal
|
|
|
- backend = CalDAVBackend(Calendar(cfg.calendar_name, url=cfg.url, username=cfg.username, password=cfg.password))
|
|
|
+ cal = _get_user_calendar()
|
|
|
+ cal.clear_event_cache()
|
|
|
+ backend = CalDAVBackend(cal)
|
|
|
self._backend = backend
|
|
|
EventSource.__init__(self, 'user_cal')
|
|
|
|