-
-
Notifications
You must be signed in to change notification settings - Fork 37.6k
Fix the todoist integration #27273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix the todoist integration #27273
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ | |
| DESCRIPTION = "description" | ||
| # Calendar Platform: Used in the '_get_date()' method | ||
| DATETIME = "dateTime" | ||
| DUE = "due" | ||
| # Service Call: When is this task due (in natural language)? | ||
| DUE_DATE_STRING = "due_date_string" | ||
| # Service Call: The language of DUE_DATE_STRING | ||
|
|
@@ -206,7 +207,7 @@ def handle_new_task(call): | |
| project_id = project_id_lookup[project_name] | ||
|
|
||
| # Create the task | ||
| item = api.items.add(call.data[CONTENT], project_id) | ||
| item = api.items.add(call.data[CONTENT], project_id=project_id) | ||
|
|
||
| if LABELS in call.data: | ||
| task_labels = call.data[LABELS] | ||
|
|
@@ -216,11 +217,12 @@ def handle_new_task(call): | |
| if PRIORITY in call.data: | ||
| item.update(priority=call.data[PRIORITY]) | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the primary change to get things working with the latest version. The |
||
| _due: dict = {} | ||
| if DUE_DATE_STRING in call.data: | ||
| item.update(date_string=call.data[DUE_DATE_STRING]) | ||
| _due["string"] = call.data[DUE_DATE_STRING] | ||
|
|
||
| if DUE_DATE_LANG in call.data: | ||
| item.update(date_lang=call.data[DUE_DATE_LANG]) | ||
| _due["lang"] = call.data[DUE_DATE_LANG] | ||
|
|
||
| if DUE_DATE in call.data: | ||
| due_date = dt.parse_datetime(call.data[DUE_DATE]) | ||
|
|
@@ -231,7 +233,11 @@ def handle_new_task(call): | |
| due_date = dt.as_utc(due_date) | ||
| date_format = "%Y-%m-%dT%H:%M" | ||
| due_date = datetime.strftime(due_date, date_format) | ||
| item.update(due_date_utc=due_date) | ||
| _due["date"] = due_date | ||
|
|
||
| if _due: | ||
| item.update(due=_due) | ||
|
|
||
| # Commit changes | ||
| api.commit() | ||
| _LOGGER.debug("Created Todoist task: %s", call.data[CONTENT]) | ||
|
|
@@ -241,6 +247,17 @@ def handle_new_task(call): | |
| ) | ||
|
|
||
|
|
||
| def _parse_due_date(data: dict) -> datetime: | ||
| """Parse the due date dict into a datetime object.""" | ||
| # Add time information to date only strings. | ||
| if len(data["date"]) == 10: | ||
| data["date"] += "T00:00:00" | ||
| # If there is no timezone provided, use UTC. | ||
| if data["timezone"] is None: | ||
| data["date"] += "Z" | ||
| return dt.parse_datetime(data["date"]) | ||
|
|
||
|
|
||
| class TodoistProjectDevice(CalendarEventDevice): | ||
| """A device for getting the next Task from a Todoist Project.""" | ||
|
|
||
|
|
@@ -412,16 +429,8 @@ def create_todoist_task(self, data): | |
| # complete the task. | ||
| # Generally speaking, that means right now. | ||
| task[START] = dt.utcnow() | ||
| if data[DUE_DATE_UTC] is not None: | ||
| due_date = data[DUE_DATE_UTC] | ||
|
|
||
| # Due dates are represented in RFC3339 format, in UTC. | ||
| # Home Assistant exclusively uses UTC, so it'll | ||
| # handle the conversion. | ||
| time_format = "%a %d %b %Y %H:%M:%S %z" | ||
| # HASS' built-in parse time function doesn't like | ||
| # Todoist's time format; strptime has to be used. | ||
| task[END] = datetime.strptime(due_date, time_format) | ||
| if data[DUE] is not None: | ||
| task[END] = _parse_due_date(data[DUE]) | ||
|
|
||
| if self._latest_due_date is not None and ( | ||
| task[END] > self._latest_due_date | ||
|
|
@@ -540,9 +549,8 @@ async def async_get_events(self, hass, start_date, end_date): | |
| project_task_data = project_data[TASKS] | ||
|
|
||
| events = [] | ||
| time_format = "%a %d %b %Y %H:%M:%S %z" | ||
| for task in project_task_data: | ||
| due_date = datetime.strptime(task["due_date_utc"], time_format) | ||
| due_date = _parse_due_date(task["due"]) | ||
| if start_date < due_date < end_date: | ||
| event = { | ||
| "uid": task["id"], | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| new_task: | ||
| description: Create a new task and add it to a project. | ||
| fields: | ||
| content: | ||
| description: The name of the task. | ||
| example: Pick up the mail. | ||
| project: | ||
| description: The name of the project this task should belong to. Defaults to Inbox. | ||
| example: Errands | ||
| labels: | ||
| description: Any labels that you want to apply to this task, separated by a comma. | ||
| example: Chores,Delivieries | ||
| priority: | ||
| description: The priority of this task, from 1 (normal) to 4 (urgent). | ||
| example: 2 | ||
| due_date_string: | ||
| description: The day this task is due, in natural language. | ||
| example: Tomorrow | ||
| due_date_lang: | ||
| description: The language of due_date_string. | ||
| example: en | ||
| due_date: | ||
| description: The day this task is due, in format YYYY-MM-DD. | ||
| example: 2019-10-22 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call now requires a kwarg.