diff --git a/homeassistant/components/todoist/calendar.py b/homeassistant/components/todoist/calendar.py index f81a4a7249a..978e58c2500 100644 --- a/homeassistant/components/todoist/calendar.py +++ b/homeassistant/components/todoist/calendar.py @@ -39,6 +39,9 @@ from .const import ( PROJECT_ID, PROJECT_NAME, PROJECTS, + REMINDER_DATE, + REMINDER_DATE_LANG, + REMINDER_DATE_STRING, SERVICE_NEW_TASK, START, SUMMARY, @@ -56,6 +59,11 @@ NEW_TASK_SERVICE_SCHEMA = vol.Schema( vol.Exclusive(DUE_DATE_STRING, "due_date"): cv.string, vol.Optional(DUE_DATE_LANG): vol.All(cv.string, vol.In(DUE_DATE_VALID_LANGS)), vol.Exclusive(DUE_DATE, "due_date"): cv.string, + vol.Exclusive(REMINDER_DATE_STRING, "reminder_date"): cv.string, + vol.Optional(REMINDER_DATE_LANG): vol.All( + cv.string, vol.In(DUE_DATE_VALID_LANGS) + ), + vol.Exclusive(REMINDER_DATE, "reminder_date"): cv.string, } ) @@ -181,13 +189,34 @@ def setup_platform(hass, config, add_entities, discovery_info=None): 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" + date_format = "%Y-%m-%dT%H:%M%S" due_date = datetime.strftime(due_date, date_format) _due["date"] = due_date if _due: item.update(due=_due) + _reminder_due: dict = {} + if REMINDER_DATE_STRING in call.data: + _reminder_due["string"] = call.data[REMINDER_DATE_STRING] + + if REMINDER_DATE_LANG in call.data: + _reminder_due["lang"] = call.data[REMINDER_DATE_LANG] + + if REMINDER_DATE in call.data: + due_date = dt.parse_datetime(call.data[REMINDER_DATE]) + if due_date is None: + due = dt.parse_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 + + if _reminder_due: + api.reminders.add(item["id"], due=_reminder_due) + # Commit changes api.commit() _LOGGER.debug("Created Todoist task: %s", call.data[CONTENT]) diff --git a/homeassistant/components/todoist/const.py b/homeassistant/components/todoist/const.py index a1e37bf0292..c83567981af 100644 --- a/homeassistant/components/todoist/const.py +++ b/homeassistant/components/todoist/const.py @@ -24,6 +24,10 @@ DUE = "due" DUE_DATE_STRING = "due_date_string" # Service Call: The language of DUE_DATE_STRING DUE_DATE_LANG = "due_date_lang" +# Service Call: When should user be reminded of this task (in natural language)? +REMINDER_DATE_STRING = "reminder_date_string" +# Service Call: The language of REMINDER_DATE_STRING +REMINDER_DATE_LANG = "reminder_date_lang" # Service Call: The available options of DUE_DATE_LANG DUE_DATE_VALID_LANGS = [ "en", @@ -44,6 +48,8 @@ DUE_DATE_VALID_LANGS = [ # Attribute: When is this task due? # Service Call: When is this task due? DUE_DATE = "due_date" +# Service Call: When should user be reminded of this task? +REMINDER_DATE = "reminder_date" # Attribute: Is this task due today? DUE_TODAY = "due_today" # Calendar Platform: When a calendar event ends diff --git a/homeassistant/components/todoist/services.yaml b/homeassistant/components/todoist/services.yaml index 186b15a18a9..88c057c1ef8 100644 --- a/homeassistant/components/todoist/services.yaml +++ b/homeassistant/components/todoist/services.yaml @@ -20,5 +20,14 @@ new_task: description: The language of due_date_string. example: en due_date: - description: The day this task is due, in format YYYY-MM-DD. + description: The time this task is due, in format YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS, in UTC timezone. example: "2019-10-22" + reminder_date_string: + description: When should user be reminded of this task, in natural language. + example: Tomorrow + reminder_date_lang: + description: The language of reminder_date_string. + example: en + reminder_date: + description: When should user be reminded of this task, in format YYYY-MM-DDTHH:MM:SS, in UTC timezone. + example: "2019-10-22T10:30:00"