Skip to content

Instantly share code, notes, and snippets.

@mweinelt
Created March 25, 2025 01:11
Show Gist options
  • Save mweinelt/67ac8e13ce861c099e8830680e8deb5c to your computer and use it in GitHub Desktop.
Save mweinelt/67ac8e13ce861c099e8830680e8deb5c to your computer and use it in GitHub Desktop.
diff --git a/custom_components/calendar_export/api.py b/custom_components/calendar_export/api.py
index e42a23c..21a941d 100644
--- a/custom_components/calendar_export/api.py
+++ b/custom_components/calendar_export/api.py
@@ -1,6 +1,7 @@
"""API for calendar export."""
from datetime import datetime, timedelta
+from hashlib import sha256
from http import HTTPStatus
import pytz
@@ -17,6 +18,13 @@ from homeassistant.components.todo import (
from icalendar import Calendar, Event, Todo
+def uid(*args):
+ m = sha256()
+ for arg in args:
+ m.update(str(arg).encode())
+ return m.hexdigest()
+
+
class CalendarExportAPI(http.HomeAssistantView):
"""View to export calendar in ICS format."""
@@ -38,6 +46,7 @@ class CalendarExportAPI(http.HomeAssistantView):
# Generate ICS data
cal = Calendar()
+ cal["VERSION"] = "2.0" # RFC5545 3.7.4
cal["X-WR-CALNAME"] = entity.name
cal["PRODID"] = "-//Home Assistant//Calendar Export//EN"
@@ -51,8 +60,9 @@ class CalendarExportAPI(http.HomeAssistantView):
for event in events:
e = Event()
- e.add("uid", event.uid)
+ e.add("uid", uid(event.uid, event.start))
e.add("summary", event.summary)
+ e.add("dtstamp", datetime(1970, 1, 1))
e.add("dtstart", event.start)
e.add("dtend", event.end)
if event.description:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment