diff --git a/custom_components/ical/__init__.py b/custom_components/ical/__init__.py index a22d781..5d33eae 100644 --- a/custom_components/ical/__init__.py +++ b/custom_components/ical/__init__.py @@ -9,6 +9,7 @@ from dateutil.tz import gettz, tzutc import icalendar import voluptuous as vol +from homeassistant.components.calendar import CalendarEvent from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_NAME, CONF_URL, CONF_VERIFY_SSL @@ -106,7 +107,11 @@ async def async_get_events(self, hass, start_date, end_date): if event["start"] < end_date and event["end"] > start_date: _LOGGER.debug("... and it has") - events.append(event) + # strongly type class fix + events.append( + CalendarEvent(event["start"], event["end"], event["summary"]) + ) + # events.append(event) return events @Throttle(MIN_TIME_BETWEEN_UPDATES) @@ -114,13 +119,13 @@ async def update(self): """Update list of upcoming events.""" _LOGGER.debug("Running ICalEvents update for calendar %s", self.name) parts = urlparse(self.url) - if parts.scheme == 'file': + if parts.scheme == "file": with open(parts.path) as f: text = f.read() else: - if parts.scheme == 'webcal': + if parts.scheme == "webcal": # There is a potential issue here if the real URL is http, not https - self.url = parts.geturl().replace('webcal', 'https', 1) + self.url = parts.geturl().replace("webcal", "https", 1) session = async_get_clientsession(self.hass, verify_ssl=self.verify_ssl) async with session.get(self.url) as response: text = await response.text() @@ -402,7 +407,7 @@ def _ical_date_fixer(self, indate, timezone="UTC"): if not str(indate.tzinfo).startswith("tzfile"): # _LOGGER.debug("Pytz indate: %s. replacing with tz %s", str(indate), str(gettz(str(indate.tzinfo)))) indate = indate.replace(tzinfo=gettz(str(indate.tzinfo))) - if str(indate.tzinfo).endswith('/UTC'): + if str(indate.tzinfo).endswith("/UTC"): indate = indate.replace(tzinfo=tzutc) # _LOGGER.debug("Tzinfo 2: %s", str(indate.tzinfo)) diff --git a/custom_components/ical/calendar.py b/custom_components/ical/calendar.py index b4a630d..ee6a67f 100644 --- a/custom_components/ical/calendar.py +++ b/custom_components/ical/calendar.py @@ -5,7 +5,8 @@ from homeassistant.components.calendar import ( ENTITY_ID_FORMAT, - CalendarEventDevice, + CalendarEntity, + CalendarEvent, extract_offset, get_date, is_offset_reached, @@ -36,7 +37,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities([calendar], True) -class ICalCalendarEventDevice(CalendarEventDevice): +class ICalCalendarEventDevice(CalendarEntity): """A device for getting the next Task from a WebDav Calendar.""" def __init__(self, hass, name, entity_id, ical_events): @@ -78,9 +79,11 @@ async def async_update(self): (summary, offset) = extract_offset(event["summary"], OFFSET) event["summary"] = summary self._offset_reached = is_offset_reached(event["start"], offset) - self._event = copy.deepcopy(event) - self._event["start"] = {} - self._event["end"] = {} - self._event["start"]["dateTime"] = event["start"].isoformat() - self._event["end"]["dateTime"] = event["end"].isoformat() - self._event["all_day"] = event["all_day"] + self._event = CalendarEvent(event["start"], event["end"], event["summary"]) + # strongly typed class required. + # self._event = copy.deepcopy(event) + # self._event["start"] = {} + # self._event["end"] = {} + # self._event["start"]["dateTime"] = event["start"].isoformat() + # self._event["end"]["dateTime"] = event["end"].isoformat() + # self._event["all_day"] = event["all_day"] diff --git a/hacs.json b/hacs.json index 9677119..2150249 100644 --- a/hacs.json +++ b/hacs.json @@ -1,4 +1,4 @@ { "name": "iCal Sensor", - "homeassistant":"2022.4.0" + "homeassistant":"2022.5.0" } diff --git a/ical_updater.json b/ical_updater.json index 2c37dae..69eaf9a 100644 --- a/ical_updater.json +++ b/ical_updater.json @@ -1,7 +1,7 @@ { "sensor.ical": { - "updated_at": "2022-04-07", - "version": "1.5.0", + "updated_at": "2022-07-18", + "version": "1.6.0", "local_location": "/custom_components/ics/__init__.py", "remote_location": "https://raw.githubusercontent.com/tybritten/ical-sensor-homeassistant/master/__init__.py", "visit_repo": "https://github.com/tybritten/ical-sensor-homeassistant/",