mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Fix the todoist integration (#27273)
* Fixed the todoist integration. * Removing unused import * Flake8 fixes. * Added username to codeowners. * Updated global codeowners
This commit is contained in:
parent
eb10f8dcd3
commit
feb1986459
@ -291,6 +291,7 @@ homeassistant/components/threshold/* @fabaff
|
|||||||
homeassistant/components/tibber/* @danielhiversen
|
homeassistant/components/tibber/* @danielhiversen
|
||||||
homeassistant/components/tile/* @bachya
|
homeassistant/components/tile/* @bachya
|
||||||
homeassistant/components/time_date/* @fabaff
|
homeassistant/components/time_date/* @fabaff
|
||||||
|
homeassistant/components/todoist/* @boralyl
|
||||||
homeassistant/components/toon/* @frenck
|
homeassistant/components/toon/* @frenck
|
||||||
homeassistant/components/tplink/* @rytilahti
|
homeassistant/components/tplink/* @rytilahti
|
||||||
homeassistant/components/traccar/* @ludeeus
|
homeassistant/components/traccar/* @ludeeus
|
||||||
|
@ -36,6 +36,7 @@ CONTENT = "content"
|
|||||||
DESCRIPTION = "description"
|
DESCRIPTION = "description"
|
||||||
# Calendar Platform: Used in the '_get_date()' method
|
# Calendar Platform: Used in the '_get_date()' method
|
||||||
DATETIME = "dateTime"
|
DATETIME = "dateTime"
|
||||||
|
DUE = "due"
|
||||||
# Service Call: When is this task due (in natural language)?
|
# Service Call: When is this task due (in natural language)?
|
||||||
DUE_DATE_STRING = "due_date_string"
|
DUE_DATE_STRING = "due_date_string"
|
||||||
# Service Call: The language of DUE_DATE_STRING
|
# Service Call: The language of DUE_DATE_STRING
|
||||||
@ -206,7 +207,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
project_id = project_id_lookup[project_name]
|
project_id = project_id_lookup[project_name]
|
||||||
|
|
||||||
# Create the task
|
# 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:
|
if LABELS in call.data:
|
||||||
task_labels = call.data[LABELS]
|
task_labels = call.data[LABELS]
|
||||||
@ -216,11 +217,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
if PRIORITY in call.data:
|
if PRIORITY in call.data:
|
||||||
item.update(priority=call.data[PRIORITY])
|
item.update(priority=call.data[PRIORITY])
|
||||||
|
|
||||||
|
_due: dict = {}
|
||||||
if DUE_DATE_STRING in call.data:
|
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:
|
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:
|
if DUE_DATE in call.data:
|
||||||
due_date = dt.parse_datetime(call.data[DUE_DATE])
|
due_date = dt.parse_datetime(call.data[DUE_DATE])
|
||||||
@ -231,7 +233,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
due_date = dt.as_utc(due_date)
|
due_date = dt.as_utc(due_date)
|
||||||
date_format = "%Y-%m-%dT%H:%M"
|
date_format = "%Y-%m-%dT%H:%M"
|
||||||
due_date = datetime.strftime(due_date, date_format)
|
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
|
# Commit changes
|
||||||
api.commit()
|
api.commit()
|
||||||
_LOGGER.debug("Created Todoist task: %s", call.data[CONTENT])
|
_LOGGER.debug("Created Todoist task: %s", call.data[CONTENT])
|
||||||
@ -241,6 +247,17 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
class TodoistProjectDevice(CalendarEventDevice):
|
||||||
"""A device for getting the next Task from a Todoist Project."""
|
"""A device for getting the next Task from a Todoist Project."""
|
||||||
|
|
||||||
@ -412,16 +429,8 @@ class TodoistProjectData:
|
|||||||
# complete the task.
|
# complete the task.
|
||||||
# Generally speaking, that means right now.
|
# Generally speaking, that means right now.
|
||||||
task[START] = dt.utcnow()
|
task[START] = dt.utcnow()
|
||||||
if data[DUE_DATE_UTC] is not None:
|
if data[DUE] is not None:
|
||||||
due_date = data[DUE_DATE_UTC]
|
task[END] = _parse_due_date(data[DUE])
|
||||||
|
|
||||||
# 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 self._latest_due_date is not None and (
|
if self._latest_due_date is not None and (
|
||||||
task[END] > self._latest_due_date
|
task[END] > self._latest_due_date
|
||||||
@ -540,9 +549,8 @@ class TodoistProjectData:
|
|||||||
project_task_data = project_data[TASKS]
|
project_task_data = project_data[TASKS]
|
||||||
|
|
||||||
events = []
|
events = []
|
||||||
time_format = "%a %d %b %Y %H:%M:%S %z"
|
|
||||||
for task in project_task_data:
|
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:
|
if start_date < due_date < end_date:
|
||||||
event = {
|
event = {
|
||||||
"uid": task["id"],
|
"uid": task["id"],
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
"name": "Todoist",
|
"name": "Todoist",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/todoist",
|
"documentation": "https://www.home-assistant.io/integrations/todoist",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"todoist-python==7.0.17"
|
"todoist-python==8.0.0"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": []
|
"codeowners": ["@boralyl"]
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
|
@ -1891,7 +1891,7 @@ thingspeak==0.4.1
|
|||||||
tikteck==0.4
|
tikteck==0.4
|
||||||
|
|
||||||
# homeassistant.components.todoist
|
# homeassistant.components.todoist
|
||||||
todoist-python==7.0.17
|
todoist-python==8.0.0
|
||||||
|
|
||||||
# homeassistant.components.toon
|
# homeassistant.components.toon
|
||||||
toonapilib==3.2.4
|
toonapilib==3.2.4
|
||||||
|
Loading…
x
Reference in New Issue
Block a user