Adds create_daily action to Habitica integration (#140684)

Add create_daily action
This commit is contained in:
Manu 2025-03-25 10:27:21 +01:00 committed by GitHub
parent d20fc30409
commit 348ebe1402
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 319 additions and 22 deletions

View File

@ -79,6 +79,7 @@ SERVICE_CREATE_HABIT = "create_habit"
SERVICE_UPDATE_TODO = "update_todo"
SERVICE_CREATE_TODO = "create_todo"
SERVICE_UPDATE_DAILY = "update_daily"
SERVICE_CREATE_DAILY = "create_daily"
DEVELOPER_ID = "4c4ca53f-c059-4ffa-966e-9d29dd405daf"
X_CLIENT = f"{DEVELOPER_ID} - {APPLICATION_NAME} {__version__}"

View File

@ -270,6 +270,14 @@
"repeat_weekly_options": "mdi:calendar-refresh",
"repeat_monthly_options": "mdi:calendar-refresh"
}
},
"create_daily": {
"service": "mdi:calendar-month",
"sections": {
"developer_options": "mdi:test-tube",
"repeat_weekly_options": "mdi:calendar-refresh",
"repeat_monthly_options": "mdi:calendar-refresh"
}
}
}
}

View File

@ -84,6 +84,7 @@ from .const import (
SERVICE_API_CALL,
SERVICE_CANCEL_QUEST,
SERVICE_CAST_SKILL,
SERVICE_CREATE_DAILY,
SERVICE_CREATE_HABIT,
SERVICE_CREATE_REWARD,
SERVICE_CREATE_TODO,
@ -243,6 +244,7 @@ SERVICE_TASK_TYPE_MAP = {
SERVICE_UPDATE_TODO: TaskType.TODO,
SERVICE_CREATE_TODO: TaskType.TODO,
SERVICE_UPDATE_DAILY: TaskType.DAILY,
SERVICE_CREATE_DAILY: TaskType.DAILY,
}
@ -913,7 +915,12 @@ def async_setup_services(hass: HomeAssistant) -> None: # noqa: C901
schema=SERVICE_UPDATE_TASK_SCHEMA,
supports_response=SupportsResponse.ONLY,
)
for service in (SERVICE_CREATE_HABIT, SERVICE_CREATE_REWARD, SERVICE_CREATE_TODO):
for service in (
SERVICE_CREATE_DAILY,
SERVICE_CREATE_HABIT,
SERVICE_CREATE_REWARD,
SERVICE_CREATE_TODO,
):
hass.services.async_register(
DOMAIN,
service,

View File

@ -347,11 +347,11 @@ update_daily:
notes: *notes
checklist_options: *checklist_options
priority: *priority
start_date:
start_date: &start_date
required: false
selector:
date:
frequency:
frequency: &frequency_daily
required: false
selector:
select:
@ -362,7 +362,7 @@ update_daily:
- "yearly"
translation_key: "frequency"
mode: dropdown
every_x:
every_x: &every_x
required: false
selector:
number:
@ -370,7 +370,7 @@ update_daily:
step: 1
unit_of_measurement: "🔃"
mode: box
repeat_weekly_options:
repeat_weekly_options: &repeat_weekly_options
collapsed: true
fields:
repeat:
@ -388,7 +388,7 @@ update_daily:
mode: list
translation_key: repeat
multiple: true
repeat_monthly_options:
repeat_monthly_options: &repeat_monthly_options
collapsed: true
fields:
repeat_monthly:
@ -403,7 +403,7 @@ update_daily:
reminder_options:
collapsed: true
fields:
reminder:
reminder: &reminder_daily
required: false
selector:
text:
@ -420,7 +420,7 @@ update_daily:
developer_options:
collapsed: true
fields:
streak:
streak: &streak
required: false
selector:
number:
@ -429,3 +429,18 @@ update_daily:
unit_of_measurement: "▶▶"
mode: box
alias: *alias
create_daily:
fields:
config_entry: *config_entry
name: *name
notes: *notes
add_checklist_item: *add_checklist_item
priority: *priority
start_date: *start_date
frequency: *frequency_daily
every_x: *every_x
repeat_weekly_options: *repeat_weekly_options
repeat_monthly_options: *repeat_monthly_options
reminder: *reminder_daily
tag: *tag
developer_options: *developer_options

View File

@ -52,7 +52,19 @@
"reminder_options_description": "Add, remove or clear reminders of a Habitica task.",
"date_name": "Due date",
"date_description": "The to-do's due date.",
"repeat_name": "Repeat on"
"repeat_name": "Repeat on",
"start_date_name": "Start date",
"start_date_description": "Defines when the daily task becomes active and specifies the exact weekday or day of the month it repeats on.",
"frequency_daily_name": "Repeat interval",
"frequency_daily_description": "The repetition interval of a daily.",
"every_x_name": "Repeat every X",
"every_x_description": "The number of intervals (days, weeks, months, or years) after which the daily repeats, based on the chosen repetition interval. A value of 0 makes the daily inactive ('Grey Daily').",
"repeat_weekly_description": "The days of the week the daily repeats.",
"repeat_monthly_description": "Whether a monthly recurring task repeats on the same calendar day each month or on the same weekday and week of the month, based on the start date.",
"repeat_weekly_options_name": "Weekly repeat days",
"repeat_weekly_options_description": "Options related to weekly repetition, applicable when the repetition interval is set to weekly.",
"repeat_monthly_options_name": "Monthly repeat day",
"repeat_monthly_options_description": "Options related to monthly repetition, applicable when the repetition interval is set to monthly."
},
"config": {
"abort": {
@ -1076,24 +1088,24 @@
"description": "[%key:component::habitica::common::priority_description%]"
},
"start_date": {
"name": "Start date",
"description": "Defines when the daily task becomes active and specifies the exact weekday or day of the month it repeats on."
"name": "[%key:component::habitica::common::start_date_name%]",
"description": "[%key:component::habitica::common::start_date_description%]"
},
"frequency": {
"name": "Repeat interval",
"description": "The repetition interval of a daily."
"name": "[%key:component::habitica::common::frequency_daily_name%]",
"description": "[%key:component::habitica::common::frequency_daily_description%]"
},
"every_x": {
"name": "Repeat every X",
"description": "The number of intervals (days, weeks, months, or years) after which the daily repeats, based on the chosen repetition interval. A value of 0 makes the daily inactive ('Grey Daily')."
"name": "[%key:component::habitica::common::every_x_name%]",
"description": "[%key:component::habitica::common::every_x_description%]"
},
"repeat": {
"name": "[%key:component::habitica::common::repeat_name%]",
"description": "The days of the week the daily repeats."
"description": "[%key:component::habitica::common::repeat_weekly_description%]"
},
"repeat_monthly": {
"name": "[%key:component::habitica::common::repeat_name%]",
"description": "Whether a monthly recurring task repeats on the same calendar day each month or on the same weekday and week of the month, based on the start date."
"description": "[%key:component::habitica::common::repeat_monthly_description%]"
},
"add_checklist_item": {
"name": "[%key:component::habitica::common::add_checklist_item_name%]",
@ -1134,12 +1146,12 @@
"description": "[%key:component::habitica::common::checklist_options_description%]"
},
"repeat_weekly_options": {
"name": "Weekly repeat days",
"description": "Options related to weekly repetition, applicable when the repetition interval is set to weekly."
"name": "[%key:component::habitica::common::repeat_weekly_options_name%]",
"description": "[%key:component::habitica::common::repeat_weekly_options_description%]"
},
"repeat_monthly_options": {
"name": "Monthly repeat day",
"description": "Options related to monthly repetition, applicable when the repetition interval is set to monthly."
"name": "[%key:component::habitica::common::repeat_monthly_options_name%]",
"description": "[%key:component::habitica::common::repeat_monthly_options_description%]"
},
"tag_options": {
"name": "[%key:component::habitica::common::tag_options_name%]",
@ -1154,6 +1166,78 @@
"description": "[%key:component::habitica::common::reminder_options_description%]"
}
}
},
"create_daily": {
"name": "Create a daily",
"description": "Adds a new daily.",
"fields": {
"config_entry": {
"name": "[%key:component::habitica::common::config_entry_name%]",
"description": "[%key:component::habitica::common::config_entry_description%]"
},
"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_options_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%]"
},
"start_date": {
"name": "[%key:component::habitica::common::start_date_name%]",
"description": "[%key:component::habitica::common::start_date_description%]"
},
"frequency": {
"name": "[%key:component::habitica::common::frequency_daily_name%]",
"description": "[%key:component::habitica::common::frequency_daily_description%]"
},
"every_x": {
"name": "[%key:component::habitica::common::every_x_name%]",
"description": "[%key:component::habitica::common::every_x_description%]"
},
"repeat": {
"name": "[%key:component::habitica::common::repeat_name%]",
"description": "[%key:component::habitica::common::repeat_weekly_description%]"
},
"repeat_monthly": {
"name": "[%key:component::habitica::common::repeat_name%]",
"description": "[%key:component::habitica::common::repeat_monthly_description%]"
},
"add_checklist_item": {
"name": "[%key:component::habitica::common::checklist_options_name%]",
"description": "[%key:component::habitica::common::add_checklist_item_description%]"
},
"reminder": {
"name": "[%key:component::habitica::common::reminder_options_name%]",
"description": "[%key:component::habitica::common::reminder_description%]"
}
},
"sections": {
"repeat_weekly_options": {
"name": "[%key:component::habitica::common::repeat_weekly_options_name%]",
"description": "[%key:component::habitica::common::repeat_weekly_options_description%]"
},
"repeat_monthly_options": {
"name": "[%key:component::habitica::common::repeat_monthly_options_name%]",
"description": "[%key:component::habitica::common::repeat_monthly_options_description%]"
},
"developer_options": {
"name": "[%key:component::habitica::common::developer_options_name%]",
"description": "[%key:component::habitica::common::developer_options_description%]"
}
}
}
},
"selector": {

View File

@ -60,6 +60,7 @@ from homeassistant.components.habitica.const import (
SERVICE_ACCEPT_QUEST,
SERVICE_CANCEL_QUEST,
SERVICE_CAST_SKILL,
SERVICE_CREATE_DAILY,
SERVICE_CREATE_HABIT,
SERVICE_CREATE_REWARD,
SERVICE_CREATE_TODO,
@ -1012,7 +1013,12 @@ async def test_update_task_exceptions(
)
@pytest.mark.parametrize(
"service",
[SERVICE_CREATE_REWARD, SERVICE_CREATE_HABIT, SERVICE_CREATE_TODO],
[
SERVICE_CREATE_DAILY,
SERVICE_CREATE_HABIT,
SERVICE_CREATE_REWARD,
SERVICE_CREATE_TODO,
],
)
@pytest.mark.usefixtures("habitica")
async def test_create_task_exceptions(
@ -1837,6 +1843,182 @@ async def test_update_daily(
habitica.update_task.assert_awaited_with(UUID(task_id), call_args)
@pytest.mark.parametrize(
("service_data", "call_args"),
[
(
{
ATTR_NAME: "TITLE",
},
Task(type=TaskType.DAILY, text="TITLE"),
),
(
{
ATTR_NAME: "TITLE",
ATTR_NOTES: "NOTES",
},
Task(type=TaskType.DAILY, text="TITLE", notes="NOTES"),
),
(
{
ATTR_NAME: "TITLE",
ATTR_ADD_CHECKLIST_ITEM: "Checklist-item",
},
Task(
type=TaskType.DAILY,
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.DAILY, text="TITLE", priority=TaskPriority.TRIVIAL),
),
(
{
ATTR_NAME: "TITLE",
ATTR_START_DATE: "2025-03-05",
},
Task(type=TaskType.DAILY, text="TITLE", startDate=datetime(2025, 3, 5)),
),
(
{
ATTR_NAME: "TITLE",
ATTR_FREQUENCY: "weekly",
},
Task(type=TaskType.DAILY, text="TITLE", frequency=Frequency.WEEKLY),
),
(
{
ATTR_NAME: "TITLE",
ATTR_INTERVAL: 5,
},
Task(type=TaskType.DAILY, text="TITLE", everyX=5),
),
(
{
ATTR_NAME: "TITLE",
ATTR_FREQUENCY: "weekly",
ATTR_REPEAT: ["m", "t", "w", "th"],
},
Task(
type=TaskType.DAILY,
text="TITLE",
frequency=Frequency.WEEKLY,
repeat=Repeat(m=True, t=True, w=True, th=True),
),
),
(
{
ATTR_NAME: "TITLE",
ATTR_FREQUENCY: "monthly",
ATTR_REPEAT_MONTHLY: "day_of_month",
},
Task(
type=TaskType.DAILY,
text="TITLE",
frequency=Frequency.MONTHLY,
daysOfMonth=[25],
weeksOfMonth=[],
),
),
(
{
ATTR_NAME: "TITLE",
ATTR_FREQUENCY: "monthly",
ATTR_REPEAT_MONTHLY: "day_of_week",
},
Task(
type=TaskType.DAILY,
text="TITLE",
frequency=Frequency.MONTHLY,
daysOfMonth=[],
weeksOfMonth=[3],
repeat=Repeat(
m=False, t=True, w=False, th=False, f=False, s=False, su=False
),
),
),
(
{
ATTR_NAME: "TITLE",
ATTR_REMINDER: ["10:00"],
},
Task(
type=TaskType.DAILY,
text="TITLE",
reminders=[
Reminders(
id=UUID("12345678-1234-5678-1234-567812345678"),
time=datetime(2025, 2, 25, 10, 0, tzinfo=UTC),
startDate=None,
)
],
),
),
(
{
ATTR_NAME: "TITLE",
ATTR_REMOVE_REMINDER: ["10:00"],
},
Task(type=TaskType.DAILY, text="TITLE", reminders=[]),
),
(
{
ATTR_NAME: "TITLE",
ATTR_CLEAR_REMINDER: True,
},
Task(type=TaskType.DAILY, text="TITLE", reminders=[]),
),
(
{
ATTR_NAME: "TITLE",
ATTR_STREAK: 10,
},
Task(type=TaskType.DAILY, text="TITLE", streak=10),
),
(
{
ATTR_NAME: "TITLE",
ATTR_ALIAS: "ALIAS",
},
Task(type=TaskType.DAILY, text="TITLE", alias="ALIAS"),
),
],
)
@pytest.mark.usefixtures("mock_uuid4")
@freeze_time("2025-02-25T22:00:00.000Z")
async def test_create_daily(
hass: HomeAssistant,
config_entry: MockConfigEntry,
habitica: AsyncMock,
service_data: dict[str, Any],
call_args: Task,
) -> None:
"""Test Habitica create daily action."""
await hass.services.async_call(
DOMAIN,
SERVICE_CREATE_DAILY,
service_data={
ATTR_CONFIG_ENTRY: config_entry.entry_id,
**service_data,
},
return_response=True,
blocking=True,
)
habitica.create_task.assert_awaited_with(call_args)
@pytest.mark.parametrize(
"service_data",
[