From 4d616e96e8f6c59a8a208e07641261dbac736fdb Mon Sep 17 00:00:00 2001 From: RogerSelwyn Date: Wed, 30 Mar 2022 08:08:14 +0100 Subject: [PATCH] Fix for breaking change in HA --- custom_components/o365/calendar.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/custom_components/o365/calendar.py b/custom_components/o365/calendar.py index 6e7efbb..9912fb9 100644 --- a/custom_components/o365/calendar.py +++ b/custom_components/o365/calendar.py @@ -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 @@ -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,