mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Add ToDoist Assignee option for new task service (#63918)
Co-authored-by: Aaron Godfrey <me@aarongodfrey.dev>
This commit is contained in:
parent
53e9a2451e
commit
5954ca2b1f
@ -19,7 +19,9 @@ from homeassistant.util import dt
|
|||||||
from .const import (
|
from .const import (
|
||||||
ALL_DAY,
|
ALL_DAY,
|
||||||
ALL_TASKS,
|
ALL_TASKS,
|
||||||
|
ASSIGNEE,
|
||||||
CHECKED,
|
CHECKED,
|
||||||
|
COLLABORATORS,
|
||||||
COMPLETED,
|
COMPLETED,
|
||||||
CONF_EXTRA_PROJECTS,
|
CONF_EXTRA_PROJECTS,
|
||||||
CONF_PROJECT_DUE_DATE,
|
CONF_PROJECT_DUE_DATE,
|
||||||
@ -36,6 +38,7 @@ from .const import (
|
|||||||
DUE_DATE_VALID_LANGS,
|
DUE_DATE_VALID_LANGS,
|
||||||
DUE_TODAY,
|
DUE_TODAY,
|
||||||
END,
|
END,
|
||||||
|
FULL_NAME,
|
||||||
ID,
|
ID,
|
||||||
LABELS,
|
LABELS,
|
||||||
NAME,
|
NAME,
|
||||||
@ -60,6 +63,7 @@ NEW_TASK_SERVICE_SCHEMA = vol.Schema(
|
|||||||
vol.Required(CONTENT): cv.string,
|
vol.Required(CONTENT): cv.string,
|
||||||
vol.Optional(PROJECT_NAME, default="inbox"): vol.All(cv.string, vol.Lower),
|
vol.Optional(PROJECT_NAME, default="inbox"): vol.All(cv.string, vol.Lower),
|
||||||
vol.Optional(LABELS): cv.ensure_list_csv,
|
vol.Optional(LABELS): cv.ensure_list_csv,
|
||||||
|
vol.Optional(ASSIGNEE): cv.string,
|
||||||
vol.Optional(PRIORITY): vol.All(vol.Coerce(int), vol.Range(min=1, max=4)),
|
vol.Optional(PRIORITY): vol.All(vol.Coerce(int), vol.Range(min=1, max=4)),
|
||||||
vol.Exclusive(DUE_DATE_STRING, "due_date"): cv.string,
|
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.Optional(DUE_DATE_LANG): vol.All(cv.string, vol.In(DUE_DATE_VALID_LANGS)),
|
||||||
@ -112,6 +116,7 @@ def setup_platform(
|
|||||||
# Look up IDs based on (lowercase) names.
|
# Look up IDs based on (lowercase) names.
|
||||||
project_id_lookup = {}
|
project_id_lookup = {}
|
||||||
label_id_lookup = {}
|
label_id_lookup = {}
|
||||||
|
collaborator_id_lookup = {}
|
||||||
|
|
||||||
api = TodoistAPI(token)
|
api = TodoistAPI(token)
|
||||||
api.sync()
|
api.sync()
|
||||||
@ -120,6 +125,7 @@ def setup_platform(
|
|||||||
# Grab all projects.
|
# Grab all projects.
|
||||||
projects = api.state[PROJECTS]
|
projects = api.state[PROJECTS]
|
||||||
|
|
||||||
|
collaborators = api.state[COLLABORATORS]
|
||||||
# Grab all labels
|
# Grab all labels
|
||||||
labels = api.state[LABELS]
|
labels = api.state[LABELS]
|
||||||
|
|
||||||
@ -137,6 +143,9 @@ def setup_platform(
|
|||||||
for label in labels:
|
for label in labels:
|
||||||
label_id_lookup[label[NAME].lower()] = label[ID]
|
label_id_lookup[label[NAME].lower()] = label[ID]
|
||||||
|
|
||||||
|
for collaborator in collaborators:
|
||||||
|
collaborator_id_lookup[collaborator[FULL_NAME].lower()] = collaborator[ID]
|
||||||
|
|
||||||
# Check config for more projects.
|
# Check config for more projects.
|
||||||
extra_projects = config[CONF_EXTRA_PROJECTS]
|
extra_projects = config[CONF_EXTRA_PROJECTS]
|
||||||
for project in extra_projects:
|
for project in extra_projects:
|
||||||
@ -182,6 +191,15 @@ def setup_platform(
|
|||||||
label_ids = [label_id_lookup[label.lower()] for label in task_labels]
|
label_ids = [label_id_lookup[label.lower()] for label in task_labels]
|
||||||
item.update(labels=label_ids)
|
item.update(labels=label_ids)
|
||||||
|
|
||||||
|
if ASSIGNEE in call.data:
|
||||||
|
task_assignee = call.data[ASSIGNEE].lower()
|
||||||
|
if task_assignee in collaborator_id_lookup:
|
||||||
|
item.update(responsible_uid=collaborator_id_lookup[task_assignee])
|
||||||
|
else:
|
||||||
|
raise ValueError(
|
||||||
|
f"User is not part of the shared project. user: {task_assignee}"
|
||||||
|
)
|
||||||
|
|
||||||
if PRIORITY in call.data:
|
if PRIORITY in call.data:
|
||||||
item.update(priority=call.data[PRIORITY])
|
item.update(priority=call.data[PRIORITY])
|
||||||
|
|
||||||
|
@ -61,6 +61,8 @@ ID = "id"
|
|||||||
LABELS = "labels"
|
LABELS = "labels"
|
||||||
# Todoist API: "Name" value
|
# Todoist API: "Name" value
|
||||||
NAME = "name"
|
NAME = "name"
|
||||||
|
# Todoist API: "Full Name" value
|
||||||
|
FULL_NAME = "full_name"
|
||||||
# Attribute: Is this task overdue?
|
# Attribute: Is this task overdue?
|
||||||
OVERDUE = "overdue"
|
OVERDUE = "overdue"
|
||||||
# Attribute: What is this task's priority?
|
# Attribute: What is this task's priority?
|
||||||
@ -79,6 +81,10 @@ START = "start"
|
|||||||
SUMMARY = "summary"
|
SUMMARY = "summary"
|
||||||
# Todoist API: Fetch all Tasks
|
# Todoist API: Fetch all Tasks
|
||||||
TASKS = "items"
|
TASKS = "items"
|
||||||
|
# Todoist API: "responsible" for a Task
|
||||||
|
ASSIGNEE = "assignee"
|
||||||
|
# Todoist API: Collaborators in shared projects
|
||||||
|
COLLABORATORS = "collaborators"
|
||||||
|
|
||||||
DOMAIN = "todoist"
|
DOMAIN = "todoist"
|
||||||
|
|
||||||
|
@ -22,6 +22,12 @@ new_task:
|
|||||||
example: Chores,Delivieries
|
example: Chores,Delivieries
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
|
assignee:
|
||||||
|
name: Assignee
|
||||||
|
description: A members username of a shared project to assign this task to.
|
||||||
|
example: username
|
||||||
|
selector:
|
||||||
|
text:
|
||||||
priority:
|
priority:
|
||||||
name: Priority
|
name: Priority
|
||||||
description: The priority of this task, from 1 (normal) to 4 (urgent).
|
description: The priority of this task, from 1 (normal) to 4 (urgent).
|
||||||
@ -41,20 +47,20 @@ new_task:
|
|||||||
selector:
|
selector:
|
||||||
select:
|
select:
|
||||||
options:
|
options:
|
||||||
- 'da'
|
- "da"
|
||||||
- 'de'
|
- "de"
|
||||||
- 'en'
|
- "en"
|
||||||
- 'es'
|
- "es"
|
||||||
- 'fr'
|
- "fr"
|
||||||
- 'it'
|
- "it"
|
||||||
- 'ja'
|
- "ja"
|
||||||
- 'ko'
|
- "ko"
|
||||||
- 'nl'
|
- "nl"
|
||||||
- 'pl'
|
- "pl"
|
||||||
- 'pt'
|
- "pt"
|
||||||
- 'ru'
|
- "ru"
|
||||||
- 'sv'
|
- "sv"
|
||||||
- 'zh'
|
- "zh"
|
||||||
due_date:
|
due_date:
|
||||||
name: Due date
|
name: Due date
|
||||||
description: The time this task is due, in format YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS, in UTC timezone.
|
description: The time this task is due, in format YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS, in UTC timezone.
|
||||||
@ -73,20 +79,20 @@ new_task:
|
|||||||
selector:
|
selector:
|
||||||
select:
|
select:
|
||||||
options:
|
options:
|
||||||
- 'da'
|
- "da"
|
||||||
- 'de'
|
- "de"
|
||||||
- 'en'
|
- "en"
|
||||||
- 'es'
|
- "es"
|
||||||
- 'fr'
|
- "fr"
|
||||||
- 'it'
|
- "it"
|
||||||
- 'ja'
|
- "ja"
|
||||||
- 'ko'
|
- "ko"
|
||||||
- 'nl'
|
- "nl"
|
||||||
- 'pl'
|
- "pl"
|
||||||
- 'pt'
|
- "pt"
|
||||||
- 'ru'
|
- "ru"
|
||||||
- 'sv'
|
- "sv"
|
||||||
- 'zh'
|
- "zh"
|
||||||
reminder_date:
|
reminder_date:
|
||||||
name: Reminder date
|
name: Reminder date
|
||||||
description: When should user be reminded of this task, in format YYYY-MM-DDTHH:MM:SS, in UTC timezone.
|
description: When should user be reminded of this task, in format YYYY-MM-DDTHH:MM:SS, in UTC timezone.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user