Skip to content

Commit

Permalink
Merge pull request #11 from Jurkash/develop
Browse files Browse the repository at this point in the history
Api sync improvements
  • Loading branch information
Jurkash authored Jul 15, 2024
2 parents 6d5ae91 + d0ec2ab commit 6704af9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
14 changes: 10 additions & 4 deletions custom_components/loe_outages/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ async def async_fetch_schedule(self) -> None:
schedule_data = await self.async_fetch_latest_json()
schedule = OutageSchedule.from_dict(schedule_data)

if self.schedule[-1].id != schedule.id:
if self.schedule[-1].dateString == schedule.dateString:
self.schedule.remove(self.schedule[-1])
self.schedule.append(schedule)
new_schedule = OutageSchedule.from_dict(schedule_data)
self.schedule = [
item
for item in self.schedule
if item.dateString != new_schedule.dateString
]
self.schedule.append(new_schedule)
self.schedule.sort(key=lambda item: item.dateString)

self.schedule = sorted(self.schedule, key=lambda s: s.date)

def get_current_event(self, at: datetime) -> dict:
"""Get the current event."""
Expand Down
9 changes: 4 additions & 5 deletions custom_components/loe_outages/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ async def async_get_events(
"""Return calendar events within a datetime range."""
LOGGER.debug('Getting all events between "%s" -> "%s"', start_date, end_date)
intervals = self.coordinator.get_events_between(start_date, end_date)
events = []

for interval in intervals:
event = CalendarEvent(
return [
CalendarEvent(
summary=interval.state,
start=interval.startTime,
end=interval.endTime,
description=interval.state,
)
events.append(event)
return events
for interval in intervals
]

0 comments on commit 6704af9

Please sign in to comment.