mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Add create_todo action to Habitica integration (#140090)
This commit is contained in:
parent
f1a6e949c0
commit
e2d4e8b65d
@ -72,6 +72,7 @@ SERVICE_CREATE_REWARD = "create_reward"
|
||||
SERVICE_UPDATE_HABIT = "update_habit"
|
||||
SERVICE_CREATE_HABIT = "create_habit"
|
||||
SERVICE_UPDATE_TODO = "update_todo"
|
||||
SERVICE_CREATE_TODO = "create_todo"
|
||||
|
||||
DEVELOPER_ID = "4c4ca53f-c059-4ffa-966e-9d29dd405daf"
|
||||
X_CLIENT = f"{DEVELOPER_ID} - {APPLICATION_NAME} {__version__}"
|
||||
|
@ -253,6 +253,12 @@
|
||||
"duedate_options": "mdi:calendar-blank",
|
||||
"reminder_options": "mdi:reminder"
|
||||
}
|
||||
},
|
||||
"create_todo": {
|
||||
"service": "mdi:pencil-box-outline",
|
||||
"sections": {
|
||||
"developer_options": "mdi:test-tube"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ from .const import (
|
||||
SERVICE_CAST_SKILL,
|
||||
SERVICE_CREATE_HABIT,
|
||||
SERVICE_CREATE_REWARD,
|
||||
SERVICE_CREATE_TODO,
|
||||
SERVICE_GET_TASKS,
|
||||
SERVICE_LEAVE_QUEST,
|
||||
SERVICE_REJECT_QUEST,
|
||||
@ -214,6 +215,7 @@ SERVICE_TASK_TYPE_MAP = {
|
||||
SERVICE_UPDATE_HABIT: TaskType.HABIT,
|
||||
SERVICE_CREATE_HABIT: TaskType.HABIT,
|
||||
SERVICE_UPDATE_TODO: TaskType.TODO,
|
||||
SERVICE_CREATE_TODO: TaskType.TODO,
|
||||
}
|
||||
|
||||
|
||||
@ -811,20 +813,14 @@ def async_setup_services(hass: HomeAssistant) -> None: # noqa: C901
|
||||
schema=SERVICE_UPDATE_TASK_SCHEMA,
|
||||
supports_response=SupportsResponse.ONLY,
|
||||
)
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
SERVICE_CREATE_REWARD,
|
||||
create_or_update_task,
|
||||
schema=SERVICE_CREATE_TASK_SCHEMA,
|
||||
supports_response=SupportsResponse.ONLY,
|
||||
)
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
SERVICE_CREATE_HABIT,
|
||||
create_or_update_task,
|
||||
schema=SERVICE_CREATE_TASK_SCHEMA,
|
||||
supports_response=SupportsResponse.ONLY,
|
||||
)
|
||||
for service in (SERVICE_CREATE_HABIT, SERVICE_CREATE_REWARD, SERVICE_CREATE_TODO):
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
service,
|
||||
create_or_update_task,
|
||||
schema=SERVICE_CREATE_TASK_SCHEMA,
|
||||
supports_response=SupportsResponse.ONLY,
|
||||
)
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
SERVICE_API_CALL,
|
||||
|
@ -271,7 +271,7 @@ update_todo:
|
||||
checklist_options:
|
||||
collapsed: true
|
||||
fields:
|
||||
add_checklist_item:
|
||||
add_checklist_item: &add_checklist_item
|
||||
required: false
|
||||
selector:
|
||||
text:
|
||||
@ -295,7 +295,7 @@ update_todo:
|
||||
duedate_options:
|
||||
collapsed: true
|
||||
fields:
|
||||
date:
|
||||
date: &due_date
|
||||
required: false
|
||||
selector:
|
||||
date:
|
||||
@ -308,7 +308,7 @@ update_todo:
|
||||
reminder_options:
|
||||
collapsed: true
|
||||
fields:
|
||||
reminder:
|
||||
reminder: &reminder
|
||||
required: false
|
||||
selector:
|
||||
text:
|
||||
@ -328,3 +328,14 @@ update_todo:
|
||||
label: "🗑️"
|
||||
tag_options: *tag_options
|
||||
developer_options: *developer_options
|
||||
create_todo:
|
||||
fields:
|
||||
config_entry: *config_entry
|
||||
name: *name
|
||||
notes: *notes
|
||||
add_checklist_item: *add_checklist_item
|
||||
priority: *priority
|
||||
date: *due_date
|
||||
reminder: *reminder
|
||||
tag: *tag
|
||||
developer_options: *developer_options
|
||||
|
@ -49,7 +49,9 @@
|
||||
"clear_reminder_name": "Clear all reminders",
|
||||
"clear_reminder_description": "Remove all reminders from a Habitica task.",
|
||||
"reminder_options_name": "Reminders",
|
||||
"reminder_options_description": "Add, remove or clear reminders of a Habitica task."
|
||||
"reminder_options_description": "Add, remove or clear reminders of a Habitica task.",
|
||||
"date_name": "Due date",
|
||||
"date_description": "The to-do's due date."
|
||||
},
|
||||
"config": {
|
||||
"abort": {
|
||||
@ -929,8 +931,8 @@
|
||||
"description": "[%key:component::habitica::common::priority_description%]"
|
||||
},
|
||||
"date": {
|
||||
"name": "Due date",
|
||||
"description": "The to-do's due date."
|
||||
"name": "[%key:component::habitica::common::date_name%]",
|
||||
"description": "[%key:component::habitica::common::date_description%]"
|
||||
},
|
||||
"clear_date": {
|
||||
"name": "Clear due date",
|
||||
@ -971,7 +973,7 @@
|
||||
"description": "[%key:component::habitica::common::checklist_options_description%]"
|
||||
},
|
||||
"duedate_options": {
|
||||
"name": "Due date",
|
||||
"name": "[%key:component::habitica::common::date_name%]",
|
||||
"description": "Set, update or remove due dates of a to-do."
|
||||
},
|
||||
"reminder_options": {
|
||||
@ -987,6 +989,54 @@
|
||||
"description": "[%key:component::habitica::common::developer_options_description%]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"create_todo": {
|
||||
"name": "Create to-do",
|
||||
"description": "Adds a new to-do.",
|
||||
"fields": {
|
||||
"config_entry": {
|
||||
"name": "[%key:component::habitica::common::config_entry_name%]",
|
||||
"description": "Select the Habitica account to create a to-do."
|
||||
},
|
||||
"name": {
|
||||
"name": "[%key:component::habitica::common::task_name%]",
|
||||
"description": "[%key:component::habitica::common::name_description%]"
|
||||
},
|
||||
"notes": {
|
||||
"name": "[%key:component::habitica::common::notes_name%]",
|
||||
"description": "[%key:component::habitica::common::notes_description%]"
|
||||
},
|
||||
"tag": {
|
||||
"name": "[%key:component::habitica::common::tag_name%]",
|
||||
"description": "[%key:component::habitica::common::tag_description%]"
|
||||
},
|
||||
"alias": {
|
||||
"name": "[%key:component::habitica::common::alias_name%]",
|
||||
"description": "[%key:component::habitica::common::alias_description%]"
|
||||
},
|
||||
"priority": {
|
||||
"name": "[%key:component::habitica::common::priority_name%]",
|
||||
"description": "[%key:component::habitica::common::priority_description%]"
|
||||
},
|
||||
"date": {
|
||||
"name": "[%key:component::habitica::common::date_name%]",
|
||||
"description": "[%key:component::habitica::common::date_description%]"
|
||||
},
|
||||
"reminder": {
|
||||
"name": "[%key:component::habitica::common::reminder_name%]",
|
||||
"description": "[%key:component::habitica::common::reminder_description%]"
|
||||
},
|
||||
"add_checklist_item": {
|
||||
"name": "[%key:component::habitica::common::add_checklist_item_name%]",
|
||||
"description": "[%key:component::habitica::common::add_checklist_item_description%]"
|
||||
}
|
||||
},
|
||||
"sections": {
|
||||
"developer_options": {
|
||||
"name": "[%key:component::habitica::common::developer_options_name%]",
|
||||
"description": "[%key:component::habitica::common::developer_options_description%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"selector": {
|
||||
|
@ -55,6 +55,7 @@ from homeassistant.components.habitica.const import (
|
||||
SERVICE_CAST_SKILL,
|
||||
SERVICE_CREATE_HABIT,
|
||||
SERVICE_CREATE_REWARD,
|
||||
SERVICE_CREATE_TODO,
|
||||
SERVICE_GET_TASKS,
|
||||
SERVICE_LEAVE_QUEST,
|
||||
SERVICE_REJECT_QUEST,
|
||||
@ -1002,7 +1003,7 @@ async def test_update_task_exceptions(
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"service",
|
||||
[SERVICE_CREATE_REWARD, SERVICE_CREATE_HABIT],
|
||||
[SERVICE_CREATE_REWARD, SERVICE_CREATE_HABIT, SERVICE_CREATE_TODO],
|
||||
)
|
||||
@pytest.mark.usefixtures("habitica")
|
||||
async def test_create_task_exceptions(
|
||||
@ -1509,6 +1510,102 @@ async def test_update_todo(
|
||||
habitica.update_task.assert_awaited_with(UUID(task_id), call_args)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("service_data", "call_args"),
|
||||
[
|
||||
(
|
||||
{
|
||||
ATTR_NAME: "TITLE",
|
||||
},
|
||||
Task(type=TaskType.TODO, text="TITLE"),
|
||||
),
|
||||
(
|
||||
{
|
||||
ATTR_NAME: "TITLE",
|
||||
ATTR_NOTES: "NOTES",
|
||||
},
|
||||
Task(type=TaskType.TODO, text="TITLE", notes="NOTES"),
|
||||
),
|
||||
(
|
||||
{
|
||||
ATTR_NAME: "TITLE",
|
||||
ATTR_ADD_CHECKLIST_ITEM: "Checklist-item",
|
||||
},
|
||||
Task(
|
||||
type=TaskType.TODO,
|
||||
text="TITLE",
|
||||
checklist=[
|
||||
Checklist(
|
||||
id=UUID("12345678-1234-5678-1234-567812345678"),
|
||||
text="Checklist-item",
|
||||
completed=False,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
(
|
||||
{
|
||||
ATTR_NAME: "TITLE",
|
||||
ATTR_PRIORITY: "trivial",
|
||||
},
|
||||
Task(type=TaskType.TODO, text="TITLE", priority=TaskPriority.TRIVIAL),
|
||||
),
|
||||
(
|
||||
{
|
||||
ATTR_NAME: "TITLE",
|
||||
ATTR_DATE: "2025-03-05",
|
||||
},
|
||||
Task(type=TaskType.TODO, text="TITLE", date=datetime(2025, 3, 5)),
|
||||
),
|
||||
(
|
||||
{
|
||||
ATTR_NAME: "TITLE",
|
||||
ATTR_REMINDER: ["2025-02-25T00:00"],
|
||||
},
|
||||
Task(
|
||||
type=TaskType.TODO,
|
||||
text="TITLE",
|
||||
reminders=[
|
||||
Reminders(
|
||||
id=UUID("12345678-1234-5678-1234-567812345678"),
|
||||
time=datetime(2025, 2, 25, 0, 0),
|
||||
startDate=None,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
(
|
||||
{
|
||||
ATTR_NAME: "TITLE",
|
||||
ATTR_ALIAS: "ALIAS",
|
||||
},
|
||||
Task(type=TaskType.TODO, text="TITLE", alias="ALIAS"),
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_uuid4")
|
||||
async def test_create_todo(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
habitica: AsyncMock,
|
||||
service_data: dict[str, Any],
|
||||
call_args: Task,
|
||||
) -> None:
|
||||
"""Test Habitica create todo action."""
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_CREATE_TODO,
|
||||
service_data={
|
||||
ATTR_CONFIG_ENTRY: config_entry.entry_id,
|
||||
**service_data,
|
||||
},
|
||||
return_response=True,
|
||||
blocking=True,
|
||||
)
|
||||
habitica.create_task.assert_awaited_with(call_args)
|
||||
|
||||
|
||||
async def test_tags(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
|
Loading…
x
Reference in New Issue
Block a user