Skip to content

Commit

Permalink
Fix incorrect handling of all daya events
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Sep 26, 2021
1 parent d56fcf6 commit a8d02bf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion custom_components/o365/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def async_setup(hass, config):
except NameError:
callback_url = f"{hass.config.api.base_url}{AUTH_CALLBACK_PATH}"

account = Account(credentials, token_backend=TOKEN_BACKEND)
account = Account(credentials, token_backend=TOKEN_BACKEND, timezone="UTC")
is_authenticated = account.is_authenticated
permissions = validate_permissions()
if is_authenticated and permissions:
Expand Down
17 changes: 9 additions & 8 deletions custom_components/o365/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(self, hass, account, calendar_id, entity, entity_id):
def device_state_attributes(self):
"""Device state property."""
return {
"all_day": self._event.get("is_all_day", False) if self.data.event is not None else False,
"all_day": self._event.get("all_day", False) if self.data.event is not None else False,
"offset_reached": self._offset_reached,
"data": self._data_attribute,
}
Expand Down Expand Up @@ -175,8 +175,8 @@ async def async_get_events(self, hass, start_date, end_date):
event_list = []
for event in vevent_list:
data = format_event_data(event, self.calendar.calendar_id)
data["start"] = self.get_hass_date(data["start"])
data["end"] = self.get_hass_date(data["end"])
data["start"] = self.get_hass_date(data["start"], event.is_all_day)
data["end"] = self.get_hass_date(data["end"], event.is_all_day)
event_list.append(data)

return event_list
Expand Down Expand Up @@ -208,10 +208,11 @@ async def async_update(self, hass):

self.event = {
"summary": vevent.subject,
"start": self.get_hass_date(vevent.start),
"end": self.get_hass_date(self.get_end_date(vevent)),
"start": self.get_hass_date(vevent.start, vevent.is_all_day),
"end": self.get_hass_date(self.get_end_date(vevent), vevent.is_all_day),
"location": vevent.location,
"description": clean_html(vevent.body),
"all_day": vevent.is_all_day,
}

@staticmethod
Expand All @@ -225,12 +226,12 @@ def is_over(vevent):
return dt.now() >= O365CalendarData.to_datetime(O365CalendarData.get_end_date(vevent))

@staticmethod
def get_hass_date(obj):
def get_hass_date(obj, is_all_day):
"""Get the date."""
if isinstance(obj, datetime):
if isinstance(obj, datetime) and not is_all_day:
return {"dateTime": obj.isoformat()}

return {"date": obj.isoformat()}
return {"date": obj.date().isoformat()}

@staticmethod
def to_datetime(obj):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/o365/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def format_event_data(event, calendar_id):
"categories": event.categories,
"sensitivity": event.sensitivity.name,
"show_as": event.show_as.name,
"is_all_day": event.is_all_day,
"all_day": event.is_all_day,
"attendees": [
{"email": x.address, "type": x.attendee_type.value} for x in event.attendees._Attendees__attendees
],
Expand Down

0 comments on commit a8d02bf

Please sign in to comment.