Skip to content

Commit

Permalink
Now actually implements the offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
PTST committed Sep 1, 2020
1 parent debf019 commit 3fc4c9a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions custom_components/o365/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(self, hass, account, calendar_id, entity, entity_id):
self.end_offset = entity.get(CONF_HOURS_FORWARD_TO_GET)
self.search = entity.get(CONF_SEARCH)
self.data = O365CalendarData(
account, calendar_id, self.search, self.max_results
account, calendar_id, self.search, self.max_results, self.start_offset, self.end_offset
)
self._event = {}
self._name = entity.get(CONF_NAME)
Expand Down Expand Up @@ -140,10 +140,12 @@ async def async_update(self):


class O365CalendarData:
def __init__(self, account, calendar_id, search=None, limit=999):
def __init__(self, account, calendar_id, search=None, limit=999, start_offset=None, end_offset=None):
self.account = account
self.calendar_id = calendar_id
self.limit = limit
self.start_offset = start_offset
self.end_offset = end_offset
self.schedule = self.account.schedule()
self.calendar = self.schedule.get_calendar(calendar_id=self.calendar_id)
self.search = search
Expand Down Expand Up @@ -174,6 +176,17 @@ async def async_get_events(self, hass, start_date, end_date):

@Throttle(MIN_TIME_BETWEEN_UPDATES)
async def async_update(self, hass):
if self.start_offset is None:
start = dt.start_of_local_day()
else:
start = dt.now() + timedelta(hours=self.start_offset)
if self.end_offset is None:
end = start + timedelta(days=1)
else:
end = dt.now() + timedelta(hours=self.end_offset)



results = await hass.async_add_executor_job(self.o365_get_events,
dt.start_of_local_day(), dt.start_of_local_day() + timedelta(days=1)
)
Expand Down

0 comments on commit 3fc4c9a

Please sign in to comment.