mirror of
https://github.com/home-assistant/core.git
synced 2026-04-02 16:36:08 +01:00
154 lines
4.6 KiB
Python
154 lines
4.6 KiB
Python
"""Test update triggers."""
|
|
|
|
from typing import Any
|
|
|
|
import pytest
|
|
|
|
from homeassistant.components.update import DOMAIN
|
|
from homeassistant.const import STATE_OFF, STATE_ON
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from tests.components.common import (
|
|
TriggerStateDescription,
|
|
assert_trigger_behavior_any,
|
|
assert_trigger_behavior_first,
|
|
assert_trigger_behavior_last,
|
|
assert_trigger_gated_by_labs_flag,
|
|
parametrize_target_entities,
|
|
parametrize_trigger_states,
|
|
target_entities,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
async def target_updates(hass: HomeAssistant) -> dict[str, list[str]]:
|
|
"""Create multiple update entities associated with different targets."""
|
|
return await target_entities(hass, DOMAIN)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"trigger_key",
|
|
[
|
|
"update.update_became_available",
|
|
],
|
|
)
|
|
async def test_update_triggers_gated_by_labs_flag(
|
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, trigger_key: str
|
|
) -> None:
|
|
"""Test the update 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_target_config", "entity_id", "entities_in_target"),
|
|
parametrize_target_entities(DOMAIN),
|
|
)
|
|
@pytest.mark.parametrize(
|
|
("trigger", "trigger_options", "states"),
|
|
[
|
|
*parametrize_trigger_states(
|
|
trigger="update.update_became_available",
|
|
target_states=[STATE_ON],
|
|
other_states=[STATE_OFF],
|
|
),
|
|
],
|
|
)
|
|
async def test_update_state_trigger_behavior_any(
|
|
hass: HomeAssistant,
|
|
target_updates: dict[str, list[str]],
|
|
trigger_target_config: dict,
|
|
entity_id: str,
|
|
entities_in_target: int,
|
|
trigger: str,
|
|
trigger_options: dict[str, Any],
|
|
states: list[TriggerStateDescription],
|
|
) -> None:
|
|
"""Test that the update state trigger fires when any update state changes to a specific state."""
|
|
await assert_trigger_behavior_any(
|
|
hass,
|
|
target_entities=target_updates,
|
|
trigger_target_config=trigger_target_config,
|
|
entity_id=entity_id,
|
|
entities_in_target=entities_in_target,
|
|
trigger=trigger,
|
|
trigger_options=trigger_options,
|
|
states=states,
|
|
)
|
|
|
|
|
|
@pytest.mark.usefixtures("enable_labs_preview_features")
|
|
@pytest.mark.parametrize(
|
|
("trigger_target_config", "entity_id", "entities_in_target"),
|
|
parametrize_target_entities(DOMAIN),
|
|
)
|
|
@pytest.mark.parametrize(
|
|
("trigger", "trigger_options", "states"),
|
|
[
|
|
*parametrize_trigger_states(
|
|
trigger="update.update_became_available",
|
|
target_states=[STATE_ON],
|
|
other_states=[STATE_OFF],
|
|
),
|
|
],
|
|
)
|
|
async def test_update_state_trigger_behavior_first(
|
|
hass: HomeAssistant,
|
|
target_updates: dict[str, list[str]],
|
|
trigger_target_config: dict,
|
|
entity_id: str,
|
|
entities_in_target: int,
|
|
trigger: str,
|
|
trigger_options: dict[str, Any],
|
|
states: list[TriggerStateDescription],
|
|
) -> None:
|
|
"""Test that the update state trigger fires when the first update changes to a specific state."""
|
|
await assert_trigger_behavior_first(
|
|
hass,
|
|
target_entities=target_updates,
|
|
trigger_target_config=trigger_target_config,
|
|
entity_id=entity_id,
|
|
entities_in_target=entities_in_target,
|
|
trigger=trigger,
|
|
trigger_options=trigger_options,
|
|
states=states,
|
|
)
|
|
|
|
|
|
@pytest.mark.usefixtures("enable_labs_preview_features")
|
|
@pytest.mark.parametrize(
|
|
("trigger_target_config", "entity_id", "entities_in_target"),
|
|
parametrize_target_entities(DOMAIN),
|
|
)
|
|
@pytest.mark.parametrize(
|
|
("trigger", "trigger_options", "states"),
|
|
[
|
|
*parametrize_trigger_states(
|
|
trigger="update.update_became_available",
|
|
target_states=[STATE_ON],
|
|
other_states=[STATE_OFF],
|
|
),
|
|
],
|
|
)
|
|
async def test_update_state_trigger_behavior_last(
|
|
hass: HomeAssistant,
|
|
target_updates: dict[str, list[str]],
|
|
trigger_target_config: dict,
|
|
entity_id: str,
|
|
entities_in_target: int,
|
|
trigger: str,
|
|
trigger_options: dict[str, Any],
|
|
states: list[TriggerStateDescription],
|
|
) -> None:
|
|
"""Test that the update state trigger fires when the last update changes to a specific state."""
|
|
await assert_trigger_behavior_last(
|
|
hass,
|
|
target_entities=target_updates,
|
|
trigger_target_config=trigger_target_config,
|
|
entity_id=entity_id,
|
|
entities_in_target=entities_in_target,
|
|
trigger=trigger,
|
|
trigger_options=trigger_options,
|
|
states=states,
|
|
)
|