Allow use of date_string in service call (#13256)

* Allow use of date_string in service call

* Add stricter validation, fix descriptions
This commit is contained in:
Juggels 2018-04-06 22:23:40 +02:00 committed by Fabian Affolter
parent 48fe2d18e8
commit c77d013f43
2 changed files with 43 additions and 20 deletions

View file

@ -1,21 +1,26 @@
# Describes the format for available calendar services # Describes the format for available calendar services
todoist: todoist_new_task:
new_task: description: Create a new task and add it to a project.
description: Create a new task and add it to a project. fields:
fields: content:
content: description: The name of the task.
description: The name of the task (Required). example: Pick up the mail
example: Pick up the mail project:
project: description: The name of the project this task should belong to. Defaults to Inbox.
description: The name of the project this task should belong to. Defaults to Inbox (Optional). example: Errands
example: Errands labels:
labels: description: Any labels that you want to apply to this task, separated by a comma.
description: Any labels that you want to apply to this task, separated by a comma (Optional). example: Chores,Deliveries
example: Chores,Deliveries priority:
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) (Optional). example: 2
example: 2 due_date_string:
due_date: description: The day this task is due, in natural language.
description: The day this task is due, in format YYYY-MM-DD (Optional). example: "tomorrow"
example: "2018-04-01" 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: "2018-04-01"

View file

@ -41,6 +41,14 @@ 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'
# Service Call: When is this task due (in natural language)?
DUE_DATE_STRING = 'due_date_string'
# Service Call: The language of DUE_DATE_STRING
DUE_DATE_LANG = 'due_date_lang'
# Service Call: The available options of DUE_DATE_LANG
DUE_DATE_VALID_LANGS = ['en', 'da', 'pl', 'zh', 'ko', 'de',
'pt', 'ja', 'it', 'fr', 'sv', 'ru',
'es', 'nl']
# Attribute: When is this task due? # Attribute: When is this task due?
# Service Call: When is this task due? # Service Call: When is this task due?
DUE_DATE = 'due_date' DUE_DATE = 'due_date'
@ -83,7 +91,11 @@ NEW_TASK_SERVICE_SCHEMA = vol.Schema({
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(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.Optional(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.Exclusive(DUE_DATE, 'due_date'): cv.string,
}) })
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
@ -186,6 +198,12 @@ def setup_platform(hass, config, add_devices, 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])
if DUE_DATE_STRING in call.data:
item.update(date_string=call.data[DUE_DATE_STRING])
if DUE_DATE_LANG in call.data:
item.update(date_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])
if due_date is None: if due_date is None: