From ae54c38a8528b1983569d1353fd4e05d46c1784f Mon Sep 17 00:00:00 2001 From: Steven Rollason <2099542+gadgetchnnel@users.noreply.github.com> Date: Mon, 25 May 2020 21:18:59 +0100 Subject: [PATCH 1/2] Check that due date is not None Check that due date is not None, prevents taks without due dates from breaking Calendar API --- homeassistant/components/todoist/calendar.py | 21 ++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/todoist/calendar.py b/homeassistant/components/todoist/calendar.py index fd24652069669..2fddc27826150 100644 --- a/homeassistant/components/todoist/calendar.py +++ b/homeassistant/components/todoist/calendar.py @@ -500,16 +500,17 @@ async def async_get_events(self, hass, start_date, end_date): events = [] for task in project_task_data: - due_date = _parse_due_date(task["due"]) - if start_date < due_date < end_date: - event = { - "uid": task["id"], - "title": task["content"], - "start": due_date.isoformat(), - "end": due_date.isoformat(), - "allDay": True, - } - events.append(event) + if task["due"] is not None: + due_date = _parse_due_date(task["due"]) + if start_date < due_date < end_date: + event = { + "uid": task["id"], + "title": task["content"], + "start": due_date.isoformat(), + "end": due_date.isoformat(), + "allDay": True, + } + events.append(event) return events @Throttle(MIN_TIME_BETWEEN_UPDATES) From d4af889239b6b13282bb46fd0fdd22f4c4cf1c3b Mon Sep 17 00:00:00 2001 From: Steven Rollason <2099542+gadgetchnnel@users.noreply.github.com> Date: Tue, 26 May 2020 13:47:58 +0100 Subject: [PATCH 2/2] Invert None check to reduce indentation --- homeassistant/components/todoist/calendar.py | 23 ++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/todoist/calendar.py b/homeassistant/components/todoist/calendar.py index 2fddc27826150..0ce8101f49c37 100644 --- a/homeassistant/components/todoist/calendar.py +++ b/homeassistant/components/todoist/calendar.py @@ -500,17 +500,18 @@ async def async_get_events(self, hass, start_date, end_date): events = [] for task in project_task_data: - if task["due"] is not None: - due_date = _parse_due_date(task["due"]) - if start_date < due_date < end_date: - event = { - "uid": task["id"], - "title": task["content"], - "start": due_date.isoformat(), - "end": due_date.isoformat(), - "allDay": True, - } - events.append(event) + if task["due"] is None: + continue + due_date = _parse_due_date(task["due"]) + if start_date < due_date < end_date: + event = { + "uid": task["id"], + "title": task["content"], + "start": due_date.isoformat(), + "end": due_date.isoformat(), + "allDay": True, + } + events.append(event) return events @Throttle(MIN_TIME_BETWEEN_UPDATES)