Skip to content

Commit

Permalink
Fix for breaking change in HA
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Mar 30, 2022
1 parent d98a34d commit 4d616e9
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions custom_components/o365/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
from datetime import datetime, timedelta
from operator import attrgetter, itemgetter

from homeassistant.components.calendar import (
CalendarEventDevice,
calculate_offset,
is_offset_reached,
)
from homeassistant.components.calendar import CalendarEventDevice, is_offset_reached

try:
from homeassistant.components.calendar import calculate_offset
except ImportError:
from homeassistant.components.calendar import extract_offset

from homeassistant.helpers.entity import generate_entity_id
from homeassistant.util import Throttle, dt

Expand Down Expand Up @@ -166,8 +168,15 @@ async def async_update(self):
await self.data.async_update(self.hass)
event = copy.deepcopy(self.data.event)
if event:
event = calculate_offset(event, DEFAULT_OFFSET)
self._offset_reached = is_offset_reached(event)
try:
event = calculate_offset(event, DEFAULT_OFFSET)
self._offset_reached = is_offset_reached(event)
except NameError:
event["summary"], offset = extract_offset(
event.get("summary", ""), DEFAULT_OFFSET
)
start = dt.parse_datetime(event["start"])
self._offset_reached = is_offset_reached(start, offset)
events = list(
await self.data.async_o365_get_events(
self.hass,
Expand Down

0 comments on commit 4d616e9

Please sign in to comment.