From fdbff767336b7ae17a5322c8fb8facd911df8f69 Mon Sep 17 00:00:00 2001 From: Manu <4445816+tr4nt0r@users.noreply.github.com> Date: Mon, 22 Sep 2025 16:16:47 +0200 Subject: [PATCH] Add collapse checklist field to Habitica create/update task actions (#150988) --- homeassistant/components/habitica/const.py | 1 + homeassistant/components/habitica/services.py | 11 ++++++++ .../components/habitica/services.yaml | 11 ++++++++ .../components/habitica/strings.json | 26 +++++++++++++++++- tests/components/habitica/test_services.py | 27 +++++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/habitica/const.py b/homeassistant/components/habitica/const.py index d7cede1db030..a32179889cfc 100644 --- a/homeassistant/components/habitica/const.py +++ b/homeassistant/components/habitica/const.py @@ -39,6 +39,7 @@ ATTR_ADD_CHECKLIST_ITEM = "add_checklist_item" ATTR_REMOVE_CHECKLIST_ITEM = "remove_checklist_item" ATTR_SCORE_CHECKLIST_ITEM = "score_checklist_item" ATTR_UNSCORE_CHECKLIST_ITEM = "unscore_checklist_item" +ATTR_COLLAPSE_CHECKLIST = "collapse_checklist" ATTR_REMINDER = "reminder" ATTR_REMOVE_REMINDER = "remove_reminder" ATTR_CLEAR_REMINDER = "clear_reminder" diff --git a/homeassistant/components/habitica/services.py b/homeassistant/components/habitica/services.py index 38833f269322..1c677f18a588 100644 --- a/homeassistant/components/habitica/services.py +++ b/homeassistant/components/habitica/services.py @@ -47,6 +47,7 @@ from .const import ( ATTR_ALIAS, ATTR_CLEAR_DATE, ATTR_CLEAR_REMINDER, + ATTR_COLLAPSE_CHECKLIST, ATTR_CONFIG_ENTRY, ATTR_COST, ATTR_COUNTER_DOWN, @@ -130,6 +131,11 @@ SERVICE_TRANSFORMATION_SCHEMA = vol.Schema( } ) +COLLAPSE_CHECKLIST_MAP = { + "collapsed": True, + "expanded": False, +} + BASE_TASK_SCHEMA = vol.Schema( { vol.Required(ATTR_CONFIG_ENTRY): ConfigEntrySelector(), @@ -160,6 +166,7 @@ BASE_TASK_SCHEMA = vol.Schema( vol.Optional(ATTR_REMOVE_CHECKLIST_ITEM): vol.All(cv.ensure_list, [str]), vol.Optional(ATTR_SCORE_CHECKLIST_ITEM): vol.All(cv.ensure_list, [str]), vol.Optional(ATTR_UNSCORE_CHECKLIST_ITEM): vol.All(cv.ensure_list, [str]), + vol.Optional(ATTR_COLLAPSE_CHECKLIST): vol.In(COLLAPSE_CHECKLIST_MAP), vol.Optional(ATTR_START_DATE): cv.date, vol.Optional(ATTR_INTERVAL): vol.All(int, vol.Range(0)), vol.Optional(ATTR_REPEAT): vol.All(cv.ensure_list, [vol.In(WEEK_DAYS)]), @@ -223,6 +230,7 @@ ITEMID_MAP = { "shiny_seed": Skill.SHINY_SEED, } + SERVICE_TASK_TYPE_MAP = { SERVICE_UPDATE_REWARD: TaskType.REWARD, SERVICE_CREATE_REWARD: TaskType.REWARD, @@ -714,6 +722,9 @@ async def _create_or_update_task(call: ServiceCall) -> ServiceResponse: # noqa: ): data["checklist"] = checklist + if collapse_checklist := call.data.get(ATTR_COLLAPSE_CHECKLIST): + data["collapseChecklist"] = COLLAPSE_CHECKLIST_MAP[collapse_checklist] + reminders = current_task.reminders if current_task else [] if add_reminders := call.data.get(ATTR_REMINDER): diff --git a/homeassistant/components/habitica/services.yaml b/homeassistant/components/habitica/services.yaml index e7f4b4207b04..2752927ac0da 100644 --- a/homeassistant/components/habitica/services.yaml +++ b/homeassistant/components/habitica/services.yaml @@ -275,6 +275,15 @@ update_todo: selector: text: multiple: true + collapse_checklist: &collapse_checklist + required: false + selector: + select: + options: + - collapsed + - expanded + mode: list + translation_key: collapse_checklist priority: *priority duedate_options: collapsed: true @@ -318,6 +327,7 @@ create_todo: name: *name notes: *notes add_checklist_item: *add_checklist_item + collapse_checklist: *collapse_checklist priority: *priority date: *due_date reminder: *reminder @@ -419,6 +429,7 @@ create_daily: name: *name notes: *notes add_checklist_item: *add_checklist_item + collapse_checklist: *collapse_checklist priority: *priority start_date: *start_date frequency: *frequency_daily diff --git a/homeassistant/components/habitica/strings.json b/homeassistant/components/habitica/strings.json index 3ea0a29ec5a6..335eacc05e9b 100644 --- a/homeassistant/components/habitica/strings.json +++ b/homeassistant/components/habitica/strings.json @@ -66,7 +66,9 @@ "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.", - "quest_name": "Quest" + "quest_name": "Quest", + "collapse_checklist_name": "Collapse/expand checklist", + "collapse_checklist_description": "Whether the checklist of a task is displayed as collapsed or expanded in Habitica." }, "config": { "abort": { @@ -1006,6 +1008,10 @@ "unscore_checklist_item": { "name": "[%key:component::habitica::common::unscore_checklist_item_name%]", "description": "[%key:component::habitica::common::unscore_checklist_item_description%]" + }, + "collapse_checklist": { + "name": "[%key:component::habitica::common::collapse_checklist_name%]", + "description": "[%key:component::habitica::common::collapse_checklist_description%]" } }, "sections": { @@ -1070,6 +1076,10 @@ "add_checklist_item": { "name": "[%key:component::habitica::common::checklist_options_name%]", "description": "[%key:component::habitica::common::add_checklist_item_description%]" + }, + "collapse_checklist": { + "name": "[%key:component::habitica::common::collapse_checklist_name%]", + "description": "[%key:component::habitica::common::collapse_checklist_description%]" } }, "sections": { @@ -1151,6 +1161,10 @@ "name": "[%key:component::habitica::common::unscore_checklist_item_name%]", "description": "[%key:component::habitica::common::unscore_checklist_item_description%]" }, + "collapse_checklist": { + "name": "[%key:component::habitica::common::collapse_checklist_name%]", + "description": "[%key:component::habitica::common::collapse_checklist_description%]" + }, "streak": { "name": "Adjust streak", "description": "Adjust or reset the streak counter of the daily." @@ -1247,6 +1261,10 @@ "name": "[%key:component::habitica::common::checklist_options_name%]", "description": "[%key:component::habitica::common::add_checklist_item_description%]" }, + "collapse_checklist": { + "name": "[%key:component::habitica::common::collapse_checklist_name%]", + "description": "[%key:component::habitica::common::collapse_checklist_description%]" + }, "reminder": { "name": "[%key:component::habitica::common::reminder_options_name%]", "description": "[%key:component::habitica::common::reminder_description%]" @@ -1325,6 +1343,12 @@ "day_of_month": "Day of the month", "day_of_week": "Day of the week" } + }, + "collapse_checklist": { + "options": { + "collapsed": "Collapsed", + "expanded": "Expanded" + } } } } diff --git a/tests/components/habitica/test_services.py b/tests/components/habitica/test_services.py index 0e2a99ce215c..3692361942a6 100644 --- a/tests/components/habitica/test_services.py +++ b/tests/components/habitica/test_services.py @@ -28,6 +28,7 @@ from homeassistant.components.habitica.const import ( ATTR_ALIAS, ATTR_CLEAR_DATE, ATTR_CLEAR_REMINDER, + ATTR_COLLAPSE_CHECKLIST, ATTR_CONFIG_ENTRY, ATTR_COST, ATTR_COUNTER_DOWN, @@ -1498,6 +1499,18 @@ async def test_create_habit( }, Task(alias="ALIAS"), ), + ( + { + ATTR_COLLAPSE_CHECKLIST: "collapsed", + }, + Task(collapseChecklist=True), + ), + ( + { + ATTR_COLLAPSE_CHECKLIST: "expanded", + }, + Task(collapseChecklist=False), + ), ], ) @pytest.mark.usefixtures("mock_uuid4") @@ -1596,6 +1609,20 @@ async def test_update_todo( }, Task(type=TaskType.TODO, text="TITLE", alias="ALIAS"), ), + ( + { + ATTR_NAME: "TITLE", + ATTR_COLLAPSE_CHECKLIST: "collapsed", + }, + Task(type=TaskType.TODO, text="TITLE", collapseChecklist=True), + ), + ( + { + ATTR_NAME: "TITLE", + ATTR_COLLAPSE_CHECKLIST: "expanded", + }, + Task(type=TaskType.TODO, text="TITLE", collapseChecklist=False), + ), ], ) @pytest.mark.usefixtures("mock_uuid4")