1
mirror of https://github.com/home-assistant/core synced 2024-07-12 07:21:24 +02:00

Add ToDoist Assignee option for new task service (#63918)

Co-authored-by: Aaron Godfrey <me@aarongodfrey.dev>
This commit is contained in:
Kai Bepperling 2022-01-21 11:13:16 +01:00 committed by GitHub
parent 53e9a2451e
commit 5954ca2b1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 28 deletions

View File

@ -19,7 +19,9 @@ from homeassistant.util import dt
from .const import (
ALL_DAY,
ALL_TASKS,
ASSIGNEE,
CHECKED,
COLLABORATORS,
COMPLETED,
CONF_EXTRA_PROJECTS,
CONF_PROJECT_DUE_DATE,
@ -36,6 +38,7 @@ from .const import (
DUE_DATE_VALID_LANGS,
DUE_TODAY,
END,
FULL_NAME,
ID,
LABELS,
NAME,
@ -60,6 +63,7 @@ NEW_TASK_SERVICE_SCHEMA = vol.Schema(
vol.Required(CONTENT): cv.string,
vol.Optional(PROJECT_NAME, default="inbox"): vol.All(cv.string, vol.Lower),
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.Exclusive(DUE_DATE_STRING, "due_date"): cv.string,
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.
project_id_lookup = {}
label_id_lookup = {}
collaborator_id_lookup = {}
api = TodoistAPI(token)
api.sync()
@ -120,6 +125,7 @@ def setup_platform(
# Grab all projects.
projects = api.state[PROJECTS]
collaborators = api.state[COLLABORATORS]
# Grab all labels
labels = api.state[LABELS]
@ -137,6 +143,9 @@ def setup_platform(
for label in labels:
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.
extra_projects = config[CONF_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]
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:
item.update(priority=call.data[PRIORITY])

View File

@ -61,6 +61,8 @@ ID = "id"
LABELS = "labels"
# Todoist API: "Name" value
NAME = "name"
# Todoist API: "Full Name" value
FULL_NAME = "full_name"
# Attribute: Is this task overdue?
OVERDUE = "overdue"
# Attribute: What is this task's priority?
@ -79,6 +81,10 @@ START = "start"
SUMMARY = "summary"
# Todoist API: Fetch all Tasks
TASKS = "items"
# Todoist API: "responsible" for a Task
ASSIGNEE = "assignee"
# Todoist API: Collaborators in shared projects
COLLABORATORS = "collaborators"
DOMAIN = "todoist"

View File

@ -22,6 +22,12 @@ new_task:
example: Chores,Delivieries
selector:
text:
assignee:
name: Assignee
description: A members username of a shared project to assign this task to.
example: username
selector:
text:
priority:
name: Priority
description: The priority of this task, from 1 (normal) to 4 (urgent).
@ -41,20 +47,20 @@ new_task:
selector:
select:
options:
- 'da'
- 'de'
- 'en'
- 'es'
- 'fr'
- 'it'
- 'ja'
- 'ko'
- 'nl'
- 'pl'
- 'pt'
- 'ru'
- 'sv'
- 'zh'
- "da"
- "de"
- "en"
- "es"
- "fr"
- "it"
- "ja"
- "ko"
- "nl"
- "pl"
- "pt"
- "ru"
- "sv"
- "zh"
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.
@ -73,20 +79,20 @@ new_task:
selector:
select:
options:
- 'da'
- 'de'
- 'en'
- 'es'
- 'fr'
- 'it'
- 'ja'
- 'ko'
- 'nl'
- 'pl'
- 'pt'
- 'ru'
- 'sv'
- 'zh'
- "da"
- "de"
- "en"
- "es"
- "fr"
- "it"
- "ja"
- "ko"
- "nl"
- "pl"
- "pt"
- "ru"
- "sv"
- "zh"
reminder_date:
name: Reminder date
description: When should user be reminded of this task, in format YYYY-MM-DDTHH:MM:SS, in UTC timezone.