diff --git a/homeassistant/components/todoist/calendar.py b/homeassistant/components/todoist/calendar.py index 4caef136f3f..386e80bd061 100644 --- a/homeassistant/components/todoist/calendar.py +++ b/homeassistant/components/todoist/calendar.py @@ -9,6 +9,7 @@ import voluptuous as vol from homeassistant.components.calendar import PLATFORM_SCHEMA, CalendarEventDevice from homeassistant.const import CONF_ID, CONF_NAME, CONF_TOKEN +from homeassistant.core import ServiceCall import homeassistant.helpers.config_validation as cv from homeassistant.helpers.template import DATE_STR_FORMAT from homeassistant.util import dt @@ -161,7 +162,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(project_devices) - def handle_new_task(call): + def handle_new_task(call: ServiceCall) -> None: """Call when a user creates a new Todoist Task from Home Assistant.""" project_name = call.data[PROJECT_NAME] project_id = project_id_lookup[project_name] @@ -188,12 +189,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None): due_date = dt.parse_datetime(call.data[DUE_DATE]) if due_date is None: due = dt.parse_date(call.data[DUE_DATE]) + if due is None: + raise ValueError(f"Invalid due_date: {call.data[DUE_DATE]}") due_date = datetime(due.year, due.month, due.day) # Format it in the manner Todoist expects due_date = dt.as_utc(due_date) date_format = "%Y-%m-%dT%H:%M%S" - due_date = datetime.strftime(due_date, date_format) - _due["date"] = due_date + _due["date"] = datetime.strftime(due_date, date_format) if _due: item.update(due=_due) @@ -209,12 +211,15 @@ def setup_platform(hass, config, add_entities, discovery_info=None): due_date = dt.parse_datetime(call.data[REMINDER_DATE]) if due_date is None: due = dt.parse_date(call.data[REMINDER_DATE]) + if due is None: + raise ValueError( + f"Invalid reminder_date: {call.data[REMINDER_DATE]}" + ) due_date = datetime(due.year, due.month, due.day) # Format it in the manner Todoist expects due_date = dt.as_utc(due_date) date_format = "%Y-%m-%dT%H:%M:%S" - due_date = datetime.strftime(due_date, date_format) - _reminder_due["date"] = due_date + _reminder_due["date"] = datetime.strftime(due_date, date_format) if _reminder_due: api.reminders.add(item["id"], due=_reminder_due)