mirror of
https://github.com/home-assistant/core.git
synced 2026-07-09 15:55:29 +01:00
Add support for options to todo triggers (#169947)
This commit is contained in:
committed by
Franck Nijhof
parent
4e61581cd8
commit
f644448d0f
@@ -10,7 +10,7 @@ from typing import TYPE_CHECKING, cast, override
|
||||
|
||||
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
|
||||
@@ -25,6 +25,7 @@ from .const import DATA_COMPONENT, DOMAIN, TodoItemStatus
|
||||
ITEM_TRIGGER_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_TARGET): cv.TARGET_FIELDS,
|
||||
vol.Required(CONF_OPTIONS, default={}): {},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -36,6 +36,10 @@ from homeassistant.setup import async_setup_component
|
||||
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"
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user