From 3ec8d2db14ee552197c01b4129bbab70d19bedc2 Mon Sep 17 00:00:00 2001 From: Tyler Britten <1933680+tybritten@users.noreply.github.com> Date: Wed, 30 Aug 2023 14:15:52 -0400 Subject: [PATCH] Update for all day events (#127) * update for all day events * add fix for RRULE too --- custom_components/ical/__init__.py | 23 +++++++++++++++++++---- custom_components/ical/manifest.json | 4 ++-- ical_updater.json | 4 ++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/custom_components/ical/__init__.py b/custom_components/ical/__init__.py index 2ddf722..f6f2e08 100644 --- a/custom_components/ical/__init__.py +++ b/custom_components/ical/__init__.py @@ -191,11 +191,18 @@ def _ical_parser(self, calendar, from_date, to_date): event["DTSTART"].dt, dt.DEFAULT_TIME_ZONE ) - # If we don't have a DTEND, just use DTSTART if "DTEND" not in event: - dtend = dtstart + _LOGGER.debug("Event found without end datetime") + if self.all_day: + # if it's an all day event with no endtime listed, we'll assume it ends at 23:59:59 + _LOGGER.debug(f"Event {event['SUMMARY']} is flagged as all day, with a start time of {start}.") + dtend = dtstart + timedelta(days=1, seconds=-1) + _LOGGER.debug(f"Setting the end time to {dtend}") + else: + _LOGGER.debug(f"Event {event['SUMMARY']} doesn't have an end but isn't flagged as all day.") + dtend = dtstart else: - _LOGGER.debug("DTEND in rrule: %s", str(event["DTEND"].dt)) + _LOGGER.debug("DTEND in event") dtend = self._ical_date_fixer( event["DTEND"].dt, dt.DEFAULT_TIME_ZONE ) @@ -329,7 +336,15 @@ def _ical_parser(self, calendar, from_date, to_date): start = dtstart if "DTEND" not in event: - dtend = dtstart + _LOGGER.debug("Event found without end datetime") + if self.all_day: + # if it's an all day event with no endtime listed, we'll assume it ends at 23:59:59 + _LOGGER.debug(f"Event {event['SUMMARY']} is flagged as all day, with a start time of {start}.") + dtend = dtstart + timedelta(days=1, seconds=-1) + _LOGGER.debug(f"Setting the end time to {dtend}") + else: + _LOGGER.debug(f"Event {event['SUMMARY']} doesn't have an end but isn't flagged as all day.") + dtend = dtstart else: _LOGGER.debug("DTEND in event") dtend = self._ical_date_fixer( diff --git a/custom_components/ical/manifest.json b/custom_components/ical/manifest.json index de17706..9b6a324 100644 --- a/custom_components/ical/manifest.json +++ b/custom_components/ical/manifest.json @@ -12,9 +12,9 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/tybritten/ical-sensor-homeassistant/issues", "requirements": [ - "icalendar==5.0.4" + "icalendar==5.0.7" ], "ssdp": [], - "version": "1.6.6", + "version": "1.6.7", "zeroconf": [] } diff --git a/ical_updater.json b/ical_updater.json index 420e6f6..49cf636 100644 --- a/ical_updater.json +++ b/ical_updater.json @@ -1,7 +1,7 @@ { "sensor.ical": { - "updated_at": "2023-03-38", - "version": "1.6.6", + "updated_at": "2023-08-28", + "version": "1.6.7", "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/",