Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion homeassistant/components/todo/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import voluptuous as vol

from homeassistant.const import ATTR_ENTITY_ID, CONF_TARGET
from homeassistant.const import ATTR_ENTITY_ID, CONF_OPTIONS, CONF_TARGET
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback, split_entity_id
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv
Expand All @@ -25,6 +25,7 @@
ITEM_TRIGGER_SCHEMA = vol.Schema(
{
vol.Required(CONF_TARGET): cv.TARGET_FIELDS,
vol.Required(CONF_OPTIONS, default={}): {},
}
)

Expand Down
45 changes: 45 additions & 0 deletions tests/components/todo/test_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
from . import MockTodoListEntity, create_mock_platform

from tests.common import async_mock_service, mock_device_registry
from tests.components.common import (
assert_trigger_gated_by_labs_flag,
assert_trigger_options_supported,
)

TODO_ENTITY_ID1 = "todo.list_one"
TODO_ENTITY_ID2 = "todo.list_two"
Expand Down Expand Up @@ -122,6 +126,47 @@ def service_calls(hass: HomeAssistant) -> list[ServiceCall]:
return async_mock_service(hass, "test", "item_added")


@pytest.mark.parametrize(
"trigger_key",
[
"todo.item_added",
"todo.item_completed",
"todo.item_removed",
],
)
async def test_todo_triggers_gated_by_labs_flag(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, trigger_key: str
) -> None:
"""Test the todo triggers are gated by the labs flag."""
await assert_trigger_gated_by_labs_flag(hass, caplog, trigger_key)


@pytest.mark.usefixtures("enable_labs_preview_features")
@pytest.mark.parametrize(
("trigger_key", "base_options", "supports_behavior", "supports_duration"),
[
("todo.item_added", None, False, False),
("todo.item_completed", None, False, False),
("todo.item_removed", None, False, False),
],
)
async def test_todo_trigger_options_validation(
hass: HomeAssistant,
trigger_key: str,
base_options: dict[str, Any] | None,
supports_behavior: bool,
supports_duration: bool,
) -> None:
"""Test that todo triggers support the expected options."""
await assert_trigger_options_supported(
hass,
trigger_key,
base_options,
supports_behavior=supports_behavior,
supports_duration=supports_duration,
)


def _assert_service_calls(
service_calls: list[ServiceCall], expected_calls: list[dict[str, Any]]
) -> None:
Expand Down