Clarify e-paper dashboard and calendar pipeline by adding inline
comments.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
# Display contract shared with the ESPHome calendar page: compact German labels,
|
||||
# a bounded number of events, and strings sized for the e-paper layout.
|
||||
CALENDAR_NAMES = {
|
||||
"calendar.tkrz_kalender": "Arbeit",
|
||||
"calendar.privat": "Privat",
|
||||
@@ -9,6 +11,7 @@ MAX_TITLE_LENGTH = 22
|
||||
MAX_META_LENGTH = 35
|
||||
|
||||
|
||||
# Keep variable event text within the fixed-width e-paper agenda columns.
|
||||
def shorten(value, maximum):
|
||||
value = (value or "").strip()
|
||||
if len(value) <= maximum:
|
||||
@@ -16,6 +19,8 @@ def shorten(value, maximum):
|
||||
return value[: maximum - 3].rstrip() + "..."
|
||||
|
||||
|
||||
# Convert one Home Assistant calendar event into the small JSON shape consumed
|
||||
# by ESPHome, separating all-day, start-time, end-time, and metadata display data.
|
||||
def compact_event(event, calendar_name):
|
||||
start = event.get("start", "")
|
||||
all_day = "T" not in start
|
||||
@@ -37,6 +42,8 @@ def compact_event(event, calendar_name):
|
||||
}
|
||||
|
||||
|
||||
# Read the calendar.get_events response supplied by the calling template sensor
|
||||
# and collect events under the date on which they should appear in the agenda.
|
||||
calendar_data = data.get("calendar", {})
|
||||
today = str(data.get("now", ""))[:10]
|
||||
events_by_date = {}
|
||||
@@ -62,6 +69,8 @@ for calendar_id, calendar in calendar_data.items():
|
||||
compact_event(event, calendar_name)
|
||||
)
|
||||
|
||||
# Sort day groups and events, put all-day entries first, and cap the payload so
|
||||
# deserializing it stays safe on the ESP32 without PSRAM.
|
||||
entries = []
|
||||
entry_count = 0
|
||||
for date in sorted(events_by_date):
|
||||
@@ -84,4 +93,5 @@ for date in sorted(events_by_date):
|
||||
}
|
||||
)
|
||||
|
||||
# Return only the normalized agenda payload to the Home Assistant template sensor.
|
||||
output["entries"] = entries
|
||||
|
||||
Reference in New Issue
Block a user