mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-12 13:42:59 +00:00
Refactor CalendarManager: Separate event fetching (update) and display logic
This commit is contained in:
@@ -177,26 +177,21 @@ class CalendarManager:
|
|||||||
return lines
|
return lines
|
||||||
|
|
||||||
def update(self, current_time):
|
def update(self, current_time):
|
||||||
"""Update calendar display if needed."""
|
"""Update calendar events if needed."""
|
||||||
if not self.enabled:
|
if not self.enabled:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Only fetch new events if the update interval has passed
|
||||||
if current_time - self.last_update >= self.update_interval:
|
if current_time - self.last_update >= self.update_interval:
|
||||||
|
logging.info("Fetching new calendar events...")
|
||||||
self.events = self.get_events()
|
self.events = self.get_events()
|
||||||
self.last_update = current_time
|
self.last_update = current_time
|
||||||
|
if not self.events:
|
||||||
# Clear the display
|
logging.info("No upcoming calendar events found.")
|
||||||
self.display_manager.clear()
|
else:
|
||||||
|
logging.info(f"Fetched {len(self.events)} calendar events.")
|
||||||
# Draw each event
|
# Reset index if events change
|
||||||
y_pos = 1
|
self.current_event_index = 0
|
||||||
for event in self.events:
|
|
||||||
y_pos = self.draw_event(event, y_pos)
|
|
||||||
if y_pos >= self.matrix.height - 8: # Leave some space at the bottom
|
|
||||||
break
|
|
||||||
|
|
||||||
# Update the display
|
|
||||||
self.display_manager.update_display()
|
|
||||||
|
|
||||||
def _format_event_date(self, event):
|
def _format_event_date(self, event):
|
||||||
"""Format event date for display"""
|
"""Format event date for display"""
|
||||||
@@ -234,15 +229,18 @@ class CalendarManager:
|
|||||||
return "Invalid Time"
|
return "Invalid Time"
|
||||||
|
|
||||||
def display(self):
|
def display(self):
|
||||||
"""Display calendar events on the matrix"""
|
"""Display the current calendar event on the matrix"""
|
||||||
if not self.enabled or not self.events:
|
if not self.enabled:
|
||||||
# Optionally display a 'No events' message here
|
|
||||||
# self.display_manager.clear()
|
|
||||||
# self.display_manager.draw_text("No Events", small_font=True)
|
|
||||||
# self.display_manager.update_display()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Clear the display
|
if not self.events:
|
||||||
|
# Display "No Events" message if the list is empty
|
||||||
|
self.display_manager.clear()
|
||||||
|
self.display_manager.draw_text("No Events", small_font=True, color=self.text_color)
|
||||||
|
self.display_manager.update_display()
|
||||||
|
return
|
||||||
|
|
||||||
|
# Clear the display before drawing the current event
|
||||||
self.display_manager.clear()
|
self.display_manager.clear()
|
||||||
|
|
||||||
# Get current event to display
|
# Get current event to display
|
||||||
@@ -250,11 +248,15 @@ class CalendarManager:
|
|||||||
self.current_event_index = 0
|
self.current_event_index = 0
|
||||||
event = self.events[self.current_event_index]
|
event = self.events[self.current_event_index]
|
||||||
|
|
||||||
# Draw the event centered vertically
|
# Draw the current event centered vertically
|
||||||
|
logging.debug(f"Displaying calendar event {self.current_event_index + 1}/{len(self.events)}: {event.get('summary')}")
|
||||||
self.draw_event(event)
|
self.draw_event(event)
|
||||||
|
|
||||||
# Update the display
|
# Update the display
|
||||||
self.display_manager.update_display()
|
self.display_manager.update_display()
|
||||||
|
|
||||||
# Increment event index for next display
|
# Increment event index for the *next* time display is called within its duration
|
||||||
|
# This logic might need adjustment depending on how often display() is called vs the mode duration
|
||||||
|
# For now, let's assume it cycles once per display call. If it needs to stay on one event
|
||||||
|
# for the full duration, this increment needs to move to the controller's mode switch logic.
|
||||||
self.current_event_index += 1
|
self.current_event_index += 1
|
||||||
Reference in New Issue
Block a user