Compare commits

...

1 Commits

Author SHA1 Message Date
Erik
a9649486c5 Improve naming in condition and trigger test helpers 2026-03-17 21:29:25 +01:00
18 changed files with 367 additions and 283 deletions

View File

@@ -78,7 +78,7 @@ async def test_alarm_control_panel_conditions_gated_by_labs_flag(
condition="alarm_control_panel.is_armed_away",
target_states=[AlarmControlPanelState.ARMED_AWAY],
other_states=other_states(AlarmControlPanelState.ARMED_AWAY),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_AWAY
},
),
@@ -86,7 +86,7 @@ async def test_alarm_control_panel_conditions_gated_by_labs_flag(
condition="alarm_control_panel.is_armed_home",
target_states=[AlarmControlPanelState.ARMED_HOME],
other_states=other_states(AlarmControlPanelState.ARMED_HOME),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_HOME
},
),
@@ -94,7 +94,7 @@ async def test_alarm_control_panel_conditions_gated_by_labs_flag(
condition="alarm_control_panel.is_armed_night",
target_states=[AlarmControlPanelState.ARMED_NIGHT],
other_states=other_states(AlarmControlPanelState.ARMED_NIGHT),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_NIGHT
},
),
@@ -102,7 +102,7 @@ async def test_alarm_control_panel_conditions_gated_by_labs_flag(
condition="alarm_control_panel.is_armed_vacation",
target_states=[AlarmControlPanelState.ARMED_VACATION],
other_states=other_states(AlarmControlPanelState.ARMED_VACATION),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_VACATION
},
),
@@ -170,7 +170,7 @@ async def test_alarm_control_panel_state_condition_behavior_any(
condition="alarm_control_panel.is_armed_away",
target_states=[AlarmControlPanelState.ARMED_AWAY],
other_states=other_states(AlarmControlPanelState.ARMED_AWAY),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_AWAY
},
),
@@ -178,7 +178,7 @@ async def test_alarm_control_panel_state_condition_behavior_any(
condition="alarm_control_panel.is_armed_home",
target_states=[AlarmControlPanelState.ARMED_HOME],
other_states=other_states(AlarmControlPanelState.ARMED_HOME),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_HOME
},
),
@@ -186,7 +186,7 @@ async def test_alarm_control_panel_state_condition_behavior_any(
condition="alarm_control_panel.is_armed_night",
target_states=[AlarmControlPanelState.ARMED_NIGHT],
other_states=other_states(AlarmControlPanelState.ARMED_NIGHT),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_NIGHT
},
),
@@ -194,7 +194,7 @@ async def test_alarm_control_panel_state_condition_behavior_any(
condition="alarm_control_panel.is_armed_vacation",
target_states=[AlarmControlPanelState.ARMED_VACATION],
other_states=other_states(AlarmControlPanelState.ARMED_VACATION),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_VACATION
},
),

View File

@@ -78,7 +78,7 @@ async def test_alarm_control_panel_triggers_gated_by_labs_flag(
trigger="alarm_control_panel.armed_away",
target_states=[AlarmControlPanelState.ARMED_AWAY],
other_states=other_states(AlarmControlPanelState.ARMED_AWAY),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_AWAY
},
trigger_from_none=False,
@@ -87,7 +87,7 @@ async def test_alarm_control_panel_triggers_gated_by_labs_flag(
trigger="alarm_control_panel.armed_home",
target_states=[AlarmControlPanelState.ARMED_HOME],
other_states=other_states(AlarmControlPanelState.ARMED_HOME),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_HOME
},
trigger_from_none=False,
@@ -96,7 +96,7 @@ async def test_alarm_control_panel_triggers_gated_by_labs_flag(
trigger="alarm_control_panel.armed_night",
target_states=[AlarmControlPanelState.ARMED_NIGHT],
other_states=other_states(AlarmControlPanelState.ARMED_NIGHT),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_NIGHT
},
trigger_from_none=False,
@@ -105,7 +105,7 @@ async def test_alarm_control_panel_triggers_gated_by_labs_flag(
trigger="alarm_control_panel.armed_vacation",
target_states=[AlarmControlPanelState.ARMED_VACATION],
other_states=other_states(AlarmControlPanelState.ARMED_VACATION),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_VACATION
},
trigger_from_none=False,
@@ -176,7 +176,7 @@ async def test_alarm_control_panel_state_trigger_behavior_any(
trigger="alarm_control_panel.armed_away",
target_states=[AlarmControlPanelState.ARMED_AWAY],
other_states=other_states(AlarmControlPanelState.ARMED_AWAY),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_AWAY
},
trigger_from_none=False,
@@ -185,7 +185,7 @@ async def test_alarm_control_panel_state_trigger_behavior_any(
trigger="alarm_control_panel.armed_home",
target_states=[AlarmControlPanelState.ARMED_HOME],
other_states=other_states(AlarmControlPanelState.ARMED_HOME),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_HOME
},
trigger_from_none=False,
@@ -194,7 +194,7 @@ async def test_alarm_control_panel_state_trigger_behavior_any(
trigger="alarm_control_panel.armed_night",
target_states=[AlarmControlPanelState.ARMED_NIGHT],
other_states=other_states(AlarmControlPanelState.ARMED_NIGHT),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_NIGHT
},
trigger_from_none=False,
@@ -203,7 +203,7 @@ async def test_alarm_control_panel_state_trigger_behavior_any(
trigger="alarm_control_panel.armed_vacation",
target_states=[AlarmControlPanelState.ARMED_VACATION],
other_states=other_states(AlarmControlPanelState.ARMED_VACATION),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_VACATION
},
trigger_from_none=False,
@@ -274,7 +274,7 @@ async def test_alarm_control_panel_state_trigger_behavior_first(
trigger="alarm_control_panel.armed_away",
target_states=[AlarmControlPanelState.ARMED_AWAY],
other_states=other_states(AlarmControlPanelState.ARMED_AWAY),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_AWAY
},
trigger_from_none=False,
@@ -283,7 +283,7 @@ async def test_alarm_control_panel_state_trigger_behavior_first(
trigger="alarm_control_panel.armed_home",
target_states=[AlarmControlPanelState.ARMED_HOME],
other_states=other_states(AlarmControlPanelState.ARMED_HOME),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_HOME
},
trigger_from_none=False,
@@ -292,7 +292,7 @@ async def test_alarm_control_panel_state_trigger_behavior_first(
trigger="alarm_control_panel.armed_night",
target_states=[AlarmControlPanelState.ARMED_NIGHT],
other_states=other_states(AlarmControlPanelState.ARMED_NIGHT),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_NIGHT
},
trigger_from_none=False,
@@ -301,7 +301,7 @@ async def test_alarm_control_panel_state_trigger_behavior_first(
trigger="alarm_control_panel.armed_vacation",
target_states=[AlarmControlPanelState.ARMED_VACATION],
other_states=other_states(AlarmControlPanelState.ARMED_VACATION),
additional_attributes={
required_filter_attributes={
ATTR_SUPPORTED_FEATURES: AlarmControlPanelEntityFeature.ARM_VACATION
},
trigger_from_none=False,

View File

@@ -40,36 +40,19 @@ async def test_button_triggers_gated_by_labs_flag(
(
"button.pressed",
[
{"included": {"state": None, "attributes": {}}, "count": 0},
{
"included": {
"included_target_state": {"state": None, "attributes": {}},
"count": 0,
},
{
"included_target_state": {
"state": "2021-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 0,
},
{
"included": {
"state": "2022-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 1,
},
],
),
(
"button.pressed",
[
{"included": {"state": "foo", "attributes": {}}, "count": 0},
{
"included": {
"state": "2021-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 1,
},
{
"included": {
"included_target_state": {
"state": "2022-01-01T23:59:59+00:00",
"attributes": {},
},
@@ -81,25 +64,54 @@ async def test_button_triggers_gated_by_labs_flag(
"button.pressed",
[
{
"included": {"state": STATE_UNAVAILABLE, "attributes": {}},
"included_target_state": {"state": "foo", "attributes": {}},
"count": 0,
},
{
"included": {
"included_target_state": {
"state": "2021-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 1,
},
{
"included_target_state": {
"state": "2022-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 1,
},
],
),
(
"button.pressed",
[
{
"included_target_state": {
"state": STATE_UNAVAILABLE,
"attributes": {},
},
"count": 0,
},
{
"included_target_state": {
"state": "2021-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 0,
},
{
"included": {
"included_target_state": {
"state": "2022-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 1,
},
{
"included": {"state": STATE_UNAVAILABLE, "attributes": {}},
"included_target_state": {
"state": STATE_UNAVAILABLE,
"attributes": {},
},
"count": 0,
},
],
@@ -107,22 +119,28 @@ async def test_button_triggers_gated_by_labs_flag(
(
"button.pressed",
[
{"included": {"state": STATE_UNKNOWN, "attributes": {}}, "count": 0},
{
"included": {
"included_target_state": {"state": STATE_UNKNOWN, "attributes": {}},
"count": 0,
},
{
"included_target_state": {
"state": "2021-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 1,
},
{
"included": {
"included_target_state": {
"state": "2022-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 1,
},
{"included": {"state": STATE_UNKNOWN, "attributes": {}}, "count": 0},
{
"included_target_state": {"state": STATE_UNKNOWN, "attributes": {}},
"count": 0,
},
],
),
],
@@ -138,17 +156,17 @@ async def test_button_state_trigger_behavior_any(
states: list[TriggerStateDescription],
) -> None:
"""Test that the button state trigger fires when any button state changes to a specific state."""
other_entity_ids = set(target_buttons["included"]) - {entity_id}
other_entity_ids = set(target_buttons["included_entities"]) - {entity_id}
# Set all buttons, including the tested button, to the initial state
for eid in target_buttons["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_buttons["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
await arm_trigger(hass, trigger, None, trigger_target_config)
for state in states[1:]:
included_state = state["included"]
included_state = state["included_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()
assert len(service_calls) == state["count"]

View File

@@ -133,7 +133,7 @@ async def target_entities(hass: HomeAssistant, domain: str) -> dict[str, list[st
# Return all available entities
return {
"included": [
"included_entities": [
f"{domain}.standalone_{domain}",
f"{domain}.standalone2_{domain}",
f"{domain}.label_{domain}",
@@ -141,7 +141,7 @@ async def target_entities(hass: HomeAssistant, domain: str) -> dict[str, list[st
f"{domain}.device_{domain}",
f"{domain}.device2_{domain}",
],
"excluded": [
"excluded_entities": [
f"{domain}.standalone_{domain}_excluded",
f"{domain}.label_{domain}_excluded",
f"{domain}.area_{domain}_excluded",
@@ -207,7 +207,7 @@ def _parametrize_condition_states(
condition_options: dict[str, Any] | None = None,
target_states: list[str | None | tuple[str | None, dict]],
other_states: list[str | None | tuple[str | None, dict]],
additional_attributes: dict | None,
required_filter_attributes: dict | None,
condition_true_if_invalid: bool,
) -> list[tuple[str, dict[str, Any], list[ConditionStateDescription]]]:
"""Parametrize states and expected condition evaluations.
@@ -219,7 +219,7 @@ def _parametrize_condition_states(
where states is a list of ConditionStateDescription dicts.
"""
additional_attributes = additional_attributes or {}
required_filter_attributes = required_filter_attributes or {}
condition_options = condition_options or {}
def state_with_attributes(
@@ -230,11 +230,11 @@ def _parametrize_condition_states(
"""Return ConditionStateDescription dict."""
if isinstance(state, str) or state is None:
return {
"included": {
"included_target_state": {
"state": state,
"attributes": additional_attributes,
"attributes": required_filter_attributes,
},
"excluded": {
"excluded_target_state": {
"state": state,
"attributes": {},
},
@@ -242,11 +242,11 @@ def _parametrize_condition_states(
"condition_true_first_entity": condition_true_first_entity,
}
return {
"included": {
"included_target_state": {
"state": state[0],
"attributes": state[1] | additional_attributes,
"attributes": state[1] | required_filter_attributes,
},
"excluded": {
"excluded_target_state": {
"state": state[0],
"attributes": state[1],
},
@@ -299,7 +299,7 @@ def parametrize_condition_states_any(
condition_options: dict[str, Any] | None = None,
target_states: list[str | None | tuple[str | None, dict]],
other_states: list[str | None | tuple[str | None, dict]],
additional_attributes: dict | None = None,
required_filter_attributes: dict | None = None,
) -> list[tuple[str, dict[str, Any], list[ConditionStateDescription]]]:
"""Parametrize states and expected condition evaluations.
@@ -315,7 +315,7 @@ def parametrize_condition_states_any(
condition_options=condition_options,
target_states=target_states,
other_states=other_states,
additional_attributes=additional_attributes,
required_filter_attributes=required_filter_attributes,
condition_true_if_invalid=False,
)
@@ -326,7 +326,7 @@ def parametrize_condition_states_all(
condition_options: dict[str, Any] | None = None,
target_states: list[str | None | tuple[str | None, dict]],
other_states: list[str | None | tuple[str | None, dict]],
additional_attributes: dict | None = None,
required_filter_attributes: dict | None = None,
) -> list[tuple[str, dict[str, Any], list[ConditionStateDescription]]]:
"""Parametrize states and expected condition evaluations.
@@ -342,7 +342,7 @@ def parametrize_condition_states_all(
condition_options=condition_options,
target_states=target_states,
other_states=other_states,
additional_attributes=additional_attributes,
required_filter_attributes=required_filter_attributes,
condition_true_if_invalid=True,
)
@@ -354,7 +354,7 @@ def parametrize_trigger_states(
target_states: list[str | None | tuple[str | None, dict]],
other_states: list[str | None | tuple[str | None, dict]],
extra_invalid_states: list[str | None | tuple[str | None, dict]] | None = None,
additional_attributes: dict | None = None,
required_filter_attributes: dict | None = None,
trigger_from_none: bool = True,
retrigger_on_target_state: bool = False,
) -> list[tuple[str, dict[str, Any], list[TriggerStateDescription]]]:
@@ -377,7 +377,7 @@ def parametrize_trigger_states(
extra_invalid_states = extra_invalid_states or []
invalid_states = [STATE_UNAVAILABLE, STATE_UNKNOWN, *extra_invalid_states]
additional_attributes = additional_attributes or {}
required_filter_attributes = required_filter_attributes or {}
trigger_options = trigger_options or {}
def state_with_attributes(
@@ -386,23 +386,23 @@ def parametrize_trigger_states(
"""Return TriggerStateDescription dict."""
if isinstance(state, str) or state is None:
return {
"included": {
"included_target_state": {
"state": state,
"attributes": additional_attributes,
"attributes": required_filter_attributes,
},
"excluded": {
"state": state if additional_attributes else None,
"excluded_target_state": {
"state": state if required_filter_attributes else None,
"attributes": {},
},
"count": count,
}
return {
"included": {
"included_target_state": {
"state": state[0],
"attributes": state[1] | additional_attributes,
"attributes": state[1] | required_filter_attributes,
},
"excluded": {
"state": state[0] if additional_attributes else None,
"excluded_target_state": {
"state": state[0] if required_filter_attributes else None,
"attributes": state[1],
},
"count": count,
@@ -644,14 +644,14 @@ def parametrize_numerical_state_value_changed_trigger_states(
"""
from homeassistant.const import ATTR_DEVICE_CLASS # noqa: PLC0415
additional_attributes = {ATTR_DEVICE_CLASS: device_class}
required_filter_attributes = {ATTR_DEVICE_CLASS: device_class}
return [
*parametrize_trigger_states(
trigger=trigger,
trigger_options={},
target_states=["0", "50", "100"],
other_states=["none"],
additional_attributes=additional_attributes,
required_filter_attributes=required_filter_attributes,
retrigger_on_target_state=True,
trigger_from_none=False,
),
@@ -660,7 +660,7 @@ def parametrize_numerical_state_value_changed_trigger_states(
trigger_options={CONF_ABOVE: 10},
target_states=["50", "100"],
other_states=["none", "0"],
additional_attributes=additional_attributes,
required_filter_attributes=required_filter_attributes,
retrigger_on_target_state=True,
trigger_from_none=False,
),
@@ -669,7 +669,7 @@ def parametrize_numerical_state_value_changed_trigger_states(
trigger_options={CONF_BELOW: 90},
target_states=["0", "50"],
other_states=["none", "100"],
additional_attributes=additional_attributes,
required_filter_attributes=required_filter_attributes,
retrigger_on_target_state=True,
trigger_from_none=False,
),
@@ -687,7 +687,7 @@ def parametrize_numerical_state_value_crossed_threshold_trigger_states(
"""
from homeassistant.const import ATTR_DEVICE_CLASS # noqa: PLC0415
additional_attributes = {ATTR_DEVICE_CLASS: device_class}
required_filter_attributes = {ATTR_DEVICE_CLASS: device_class}
return [
*parametrize_trigger_states(
trigger=trigger,
@@ -698,7 +698,7 @@ def parametrize_numerical_state_value_crossed_threshold_trigger_states(
},
target_states=["50", "60"],
other_states=["none", "0", "100"],
additional_attributes=additional_attributes,
required_filter_attributes=required_filter_attributes,
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -710,7 +710,7 @@ def parametrize_numerical_state_value_crossed_threshold_trigger_states(
},
target_states=["0", "100"],
other_states=["none", "50", "60"],
additional_attributes=additional_attributes,
required_filter_attributes=required_filter_attributes,
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -721,7 +721,7 @@ def parametrize_numerical_state_value_crossed_threshold_trigger_states(
},
target_states=["50", "100"],
other_states=["none", "0"],
additional_attributes=additional_attributes,
required_filter_attributes=required_filter_attributes,
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -732,7 +732,7 @@ def parametrize_numerical_state_value_crossed_threshold_trigger_states(
},
target_states=["0", "50"],
other_states=["none", "100"],
additional_attributes=additional_attributes,
required_filter_attributes=required_filter_attributes,
trigger_from_none=False,
),
]
@@ -876,14 +876,14 @@ async def assert_condition_behavior_any(
states: list[ConditionStateDescription],
) -> None:
"""Test condition with the 'any' behavior."""
other_entity_ids = set(target_entities["included"]) - {entity_id}
excluded_entity_ids = set(target_entities["excluded"]) - {entity_id}
other_entity_ids = set(target_entities["included_entities"]) - {entity_id}
excluded_entity_ids = set(target_entities["excluded_entities"]) - {entity_id}
for eid in target_entities["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_entities["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
for eid in excluded_entity_ids:
set_or_remove_state(hass, eid, states[0]["excluded"])
set_or_remove_state(hass, eid, states[0]["excluded_target_state"])
await hass.async_block_till_done()
condition = await create_target_condition(
@@ -894,8 +894,8 @@ async def assert_condition_behavior_any(
)
for state in states:
included_state = state["included"]
excluded_state = state["excluded"]
included_state = state["included_target_state"]
excluded_state = state["excluded_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()
assert condition(hass) == state["condition_true"]
@@ -921,14 +921,14 @@ async def assert_condition_behavior_all(
states: list[ConditionStateDescription],
) -> None:
"""Test condition with the 'all' behavior."""
other_entity_ids = set(target_entities["included"]) - {entity_id}
excluded_entity_ids = set(target_entities["excluded"]) - {entity_id}
other_entity_ids = set(target_entities["included_entities"]) - {entity_id}
excluded_entity_ids = set(target_entities["excluded_entities"]) - {entity_id}
for eid in target_entities["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_entities["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
for eid in excluded_entity_ids:
set_or_remove_state(hass, eid, states[0]["excluded"])
set_or_remove_state(hass, eid, states[0]["excluded_target_state"])
await hass.async_block_till_done()
condition = await create_target_condition(
@@ -939,8 +939,8 @@ async def assert_condition_behavior_all(
)
for state in states:
included_state = state["included"]
excluded_state = state["excluded"]
included_state = state["included_target_state"]
excluded_state = state["excluded_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()
@@ -969,21 +969,21 @@ async def assert_trigger_behavior_any(
states: list[TriggerStateDescription],
) -> None:
"""Test trigger fires in mode any."""
other_entity_ids = set(target_entities["included"]) - {entity_id}
excluded_entity_ids = set(target_entities["excluded"]) - {entity_id}
other_entity_ids = set(target_entities["included_entities"]) - {entity_id}
excluded_entity_ids = set(target_entities["excluded_entities"]) - {entity_id}
for eid in target_entities["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_entities["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
for eid in excluded_entity_ids:
set_or_remove_state(hass, eid, states[0]["excluded"])
set_or_remove_state(hass, eid, states[0]["excluded_target_state"])
await hass.async_block_till_done()
await arm_trigger(hass, trigger, trigger_options, trigger_target_config)
for state in states[1:]:
excluded_state = state["excluded"]
included_state = state["included"]
excluded_state = state["excluded_target_state"]
included_state = state["included_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()
assert len(service_calls) == state["count"]
@@ -1014,14 +1014,14 @@ async def assert_trigger_behavior_first(
states: list[TriggerStateDescription],
) -> None:
"""Test trigger fires in mode first."""
other_entity_ids = set(target_entities["included"]) - {entity_id}
excluded_entity_ids = set(target_entities["excluded"]) - {entity_id}
other_entity_ids = set(target_entities["included_entities"]) - {entity_id}
excluded_entity_ids = set(target_entities["excluded_entities"]) - {entity_id}
for eid in target_entities["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_entities["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
for eid in excluded_entity_ids:
set_or_remove_state(hass, eid, states[0]["excluded"])
set_or_remove_state(hass, eid, states[0]["excluded_target_state"])
await hass.async_block_till_done()
await arm_trigger(
@@ -1029,8 +1029,8 @@ async def assert_trigger_behavior_first(
)
for state in states[1:]:
excluded_state = state["excluded"]
included_state = state["included"]
excluded_state = state["excluded_target_state"]
included_state = state["included_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()
assert len(service_calls) == state["count"]
@@ -1060,14 +1060,14 @@ async def assert_trigger_behavior_last(
states: list[TriggerStateDescription],
) -> None:
"""Test trigger fires in mode last."""
other_entity_ids = set(target_entities["included"]) - {entity_id}
excluded_entity_ids = set(target_entities["excluded"]) - {entity_id}
other_entity_ids = set(target_entities["included_entities"]) - {entity_id}
excluded_entity_ids = set(target_entities["excluded_entities"]) - {entity_id}
for eid in target_entities["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_entities["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
for eid in excluded_entity_ids:
set_or_remove_state(hass, eid, states[0]["excluded"])
set_or_remove_state(hass, eid, states[0]["excluded_target_state"])
await hass.async_block_till_done()
await arm_trigger(
@@ -1075,8 +1075,8 @@ async def assert_trigger_behavior_last(
)
for state in states[1:]:
excluded_state = state["excluded"]
included_state = state["included"]
excluded_state = state["excluded_target_state"]
included_state = state["included_target_state"]
for other_entity_id in other_entity_ids:
set_or_remove_state(hass, other_entity_id, included_state)
await hass.async_block_till_done()

View File

@@ -72,7 +72,7 @@ async def test_cover_conditions_gated_by_labs_flag(
(CoverState.CLOSED, {ATTR_IS_CLOSED: True}),
(CoverState.CLOSING, {ATTR_IS_CLOSED: True}),
],
additional_attributes={ATTR_DEVICE_CLASS: device_class},
required_filter_attributes={ATTR_DEVICE_CLASS: device_class},
),
*parametrize_condition_states_any(
condition=is_closed_key,
@@ -85,7 +85,7 @@ async def test_cover_conditions_gated_by_labs_flag(
(CoverState.OPENING, {ATTR_IS_CLOSED: False}),
(CoverState.CLOSING, {ATTR_IS_CLOSED: False}),
],
additional_attributes={ATTR_DEVICE_CLASS: device_class},
required_filter_attributes={ATTR_DEVICE_CLASS: device_class},
),
)
],
@@ -135,7 +135,7 @@ async def test_cover_condition_behavior_any(
(CoverState.CLOSED, {ATTR_IS_CLOSED: True}),
(CoverState.CLOSING, {ATTR_IS_CLOSED: True}),
],
additional_attributes={ATTR_DEVICE_CLASS: device_class},
required_filter_attributes={ATTR_DEVICE_CLASS: device_class},
),
*parametrize_condition_states_all(
condition=is_closed_key,
@@ -148,7 +148,7 @@ async def test_cover_condition_behavior_any(
(CoverState.OPENING, {ATTR_IS_CLOSED: False}),
(CoverState.CLOSING, {ATTR_IS_CLOSED: False}),
],
additional_attributes={ATTR_DEVICE_CLASS: device_class},
required_filter_attributes={ATTR_DEVICE_CLASS: device_class},
),
)
],

View File

@@ -75,7 +75,7 @@ async def test_cover_triggers_gated_by_labs_flag(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: device_class},
required_filter_attributes={ATTR_DEVICE_CLASS: device_class},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -93,7 +93,7 @@ async def test_cover_triggers_gated_by_labs_flag(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: device_class},
required_filter_attributes={ATTR_DEVICE_CLASS: device_class},
trigger_from_none=False,
),
)
@@ -149,7 +149,7 @@ async def test_cover_trigger_behavior_any(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: device_class},
required_filter_attributes={ATTR_DEVICE_CLASS: device_class},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -167,7 +167,7 @@ async def test_cover_trigger_behavior_any(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: device_class},
required_filter_attributes={ATTR_DEVICE_CLASS: device_class},
trigger_from_none=False,
),
)
@@ -223,7 +223,7 @@ async def test_cover_trigger_behavior_first(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: device_class},
required_filter_attributes={ATTR_DEVICE_CLASS: device_class},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -241,7 +241,7 @@ async def test_cover_trigger_behavior_first(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: device_class},
required_filter_attributes={ATTR_DEVICE_CLASS: device_class},
trigger_from_none=False,
),
)

View File

@@ -59,14 +59,14 @@ async def test_door_triggers_gated_by_labs_flag(
trigger="door.opened",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="door.closed",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
],
@@ -118,7 +118,7 @@ async def test_door_trigger_binary_sensor_behavior_any(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -136,7 +136,7 @@ async def test_door_trigger_binary_sensor_behavior_any(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
],
@@ -178,14 +178,14 @@ async def test_door_trigger_cover_behavior_any(
trigger="door.opened",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="door.closed",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
],
@@ -227,14 +227,14 @@ async def test_door_trigger_binary_sensor_behavior_first(
trigger="door.opened",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="door.closed",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
],
@@ -286,7 +286,7 @@ async def test_door_trigger_binary_sensor_behavior_last(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -304,7 +304,7 @@ async def test_door_trigger_binary_sensor_behavior_last(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
],
@@ -356,7 +356,7 @@ async def test_door_trigger_cover_behavior_first(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -374,7 +374,7 @@ async def test_door_trigger_cover_behavior_first(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
],

View File

@@ -81,11 +81,11 @@ async def test_fan_state_condition_behavior_any(
states: list[ConditionStateDescription],
) -> None:
"""Test the fan state condition with the 'any' behavior."""
other_entity_ids = set(target_fans["included"]) - {entity_id}
other_entity_ids = set(target_fans["included_entities"]) - {entity_id}
# Set all fans, including the tested fan, to the initial state
for eid in target_fans["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_fans["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
condition = await create_target_condition(
@@ -97,13 +97,13 @@ async def test_fan_state_condition_behavior_any(
# Set state for switches to ensure that they don't impact the condition
for state in states:
for eid in target_switches["included"]:
set_or_remove_state(hass, eid, state["included"])
for eid in target_switches["included_entities"]:
set_or_remove_state(hass, eid, state["included_target_state"])
await hass.async_block_till_done()
assert condition(hass) is False
for state in states:
included_state = state["included"]
included_state = state["included_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()
assert condition(hass) == state["condition_true"]
@@ -150,11 +150,11 @@ async def test_fan_state_condition_behavior_all(
hass.states.async_set("switch.label_switch_1", STATE_OFF)
hass.states.async_set("switch.label_switch_2", STATE_ON)
other_entity_ids = set(target_fans["included"]) - {entity_id}
other_entity_ids = set(target_fans["included_entities"]) - {entity_id}
# Set all fans, including the tested fan, to the initial state
for eid in target_fans["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_fans["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
condition = await create_target_condition(
@@ -165,7 +165,7 @@ async def test_fan_state_condition_behavior_all(
)
for state in states:
included_state = state["included"]
included_state = state["included_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()

View File

@@ -59,14 +59,14 @@ async def test_garage_door_triggers_gated_by_labs_flag(
trigger="garage_door.opened",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "garage_door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "garage_door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="garage_door.closed",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "garage_door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "garage_door"},
trigger_from_none=False,
),
],
@@ -118,7 +118,7 @@ async def test_garage_door_trigger_binary_sensor_behavior_any(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "garage"},
required_filter_attributes={ATTR_DEVICE_CLASS: "garage"},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -136,7 +136,7 @@ async def test_garage_door_trigger_binary_sensor_behavior_any(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "garage"},
required_filter_attributes={ATTR_DEVICE_CLASS: "garage"},
trigger_from_none=False,
),
],
@@ -178,14 +178,14 @@ async def test_garage_door_trigger_cover_behavior_any(
trigger="garage_door.opened",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "garage_door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "garage_door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="garage_door.closed",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "garage_door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "garage_door"},
trigger_from_none=False,
),
],
@@ -227,14 +227,14 @@ async def test_garage_door_trigger_binary_sensor_behavior_first(
trigger="garage_door.opened",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "garage_door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "garage_door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="garage_door.closed",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "garage_door"},
required_filter_attributes={ATTR_DEVICE_CLASS: "garage_door"},
trigger_from_none=False,
),
],
@@ -286,7 +286,7 @@ async def test_garage_door_trigger_binary_sensor_behavior_last(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "garage"},
required_filter_attributes={ATTR_DEVICE_CLASS: "garage"},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -304,7 +304,7 @@ async def test_garage_door_trigger_binary_sensor_behavior_last(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "garage"},
required_filter_attributes={ATTR_DEVICE_CLASS: "garage"},
trigger_from_none=False,
),
],
@@ -356,7 +356,7 @@ async def test_garage_door_trigger_cover_behavior_first(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "garage"},
required_filter_attributes={ATTR_DEVICE_CLASS: "garage"},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -374,7 +374,7 @@ async def test_garage_door_trigger_cover_behavior_first(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "garage"},
required_filter_attributes={ATTR_DEVICE_CLASS: "garage"},
trigger_from_none=False,
),
],

View File

@@ -63,7 +63,7 @@ async def test_gate_triggers_gated_by_labs_flag(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "gate"},
required_filter_attributes={ATTR_DEVICE_CLASS: "gate"},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -81,7 +81,7 @@ async def test_gate_triggers_gated_by_labs_flag(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "gate"},
required_filter_attributes={ATTR_DEVICE_CLASS: "gate"},
trigger_from_none=False,
),
],
@@ -133,7 +133,7 @@ async def test_gate_trigger_cover_behavior_any(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "gate"},
required_filter_attributes={ATTR_DEVICE_CLASS: "gate"},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -151,7 +151,7 @@ async def test_gate_trigger_cover_behavior_any(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "gate"},
required_filter_attributes={ATTR_DEVICE_CLASS: "gate"},
trigger_from_none=False,
),
],
@@ -203,7 +203,7 @@ async def test_gate_trigger_cover_behavior_first(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "gate"},
required_filter_attributes={ATTR_DEVICE_CLASS: "gate"},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -221,7 +221,7 @@ async def test_gate_trigger_cover_behavior_first(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "gate"},
required_filter_attributes={ATTR_DEVICE_CLASS: "gate"},
trigger_from_none=False,
),
],

View File

@@ -81,11 +81,11 @@ async def test_light_state_condition_behavior_any(
states: list[ConditionStateDescription],
) -> None:
"""Test the light state condition with the 'any' behavior."""
other_entity_ids = set(target_lights["included"]) - {entity_id}
other_entity_ids = set(target_lights["included_entities"]) - {entity_id}
# Set all lights, including the tested light, to the initial state
for eid in target_lights["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_lights["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
condition = await create_target_condition(
@@ -97,13 +97,13 @@ async def test_light_state_condition_behavior_any(
# Set state for switches to ensure that they don't impact the condition
for state in states:
for eid in target_switches["included"]:
set_or_remove_state(hass, eid, state["included"])
for eid in target_switches["included_entities"]:
set_or_remove_state(hass, eid, state["included_target_state"])
await hass.async_block_till_done()
assert condition(hass) is False
for state in states:
included_state = state["included"]
included_state = state["included_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()
assert condition(hass) == state["condition_true"]
@@ -150,11 +150,11 @@ async def test_light_state_condition_behavior_all(
hass.states.async_set("switch.label_switch_1", STATE_OFF)
hass.states.async_set("switch.label_switch_2", STATE_ON)
other_entity_ids = set(target_lights["included"]) - {entity_id}
other_entity_ids = set(target_lights["included_entities"]) - {entity_id}
# Set all lights, including the tested light, to the initial state
for eid in target_lights["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_lights["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
condition = await create_target_condition(
@@ -165,7 +165,7 @@ async def test_light_state_condition_behavior_all(
)
for state in states:
included_state = state["included"]
included_state = state["included_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()

View File

@@ -52,14 +52,14 @@ async def test_motion_triggers_gated_by_labs_flag(
trigger="motion.detected",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "motion"},
required_filter_attributes={ATTR_DEVICE_CLASS: "motion"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="motion.cleared",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "motion"},
required_filter_attributes={ATTR_DEVICE_CLASS: "motion"},
trigger_from_none=False,
),
],
@@ -101,14 +101,14 @@ async def test_motion_trigger_binary_sensor_behavior_any(
trigger="motion.detected",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "motion"},
required_filter_attributes={ATTR_DEVICE_CLASS: "motion"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="motion.cleared",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "motion"},
required_filter_attributes={ATTR_DEVICE_CLASS: "motion"},
trigger_from_none=False,
),
],
@@ -150,14 +150,14 @@ async def test_motion_trigger_binary_sensor_behavior_first(
trigger="motion.detected",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "motion"},
required_filter_attributes={ATTR_DEVICE_CLASS: "motion"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="motion.cleared",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "motion"},
required_filter_attributes={ATTR_DEVICE_CLASS: "motion"},
trigger_from_none=False,
),
],

View File

@@ -52,14 +52,14 @@ async def test_occupancy_triggers_gated_by_labs_flag(
trigger="occupancy.detected",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "occupancy"},
required_filter_attributes={ATTR_DEVICE_CLASS: "occupancy"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="occupancy.cleared",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "occupancy"},
required_filter_attributes={ATTR_DEVICE_CLASS: "occupancy"},
trigger_from_none=False,
),
],
@@ -101,14 +101,14 @@ async def test_occupancy_trigger_binary_sensor_behavior_any(
trigger="occupancy.detected",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "occupancy"},
required_filter_attributes={ATTR_DEVICE_CLASS: "occupancy"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="occupancy.cleared",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "occupancy"},
required_filter_attributes={ATTR_DEVICE_CLASS: "occupancy"},
trigger_from_none=False,
),
],
@@ -150,14 +150,14 @@ async def test_occupancy_trigger_binary_sensor_behavior_first(
trigger="occupancy.detected",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "occupancy"},
required_filter_attributes={ATTR_DEVICE_CLASS: "occupancy"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="occupancy.cleared",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "occupancy"},
required_filter_attributes={ATTR_DEVICE_CLASS: "occupancy"},
trigger_from_none=False,
),
],

View File

@@ -40,36 +40,19 @@ async def test_scene_triggers_gated_by_labs_flag(
(
"scene.activated",
[
{"included": {"state": None, "attributes": {}}, "count": 0},
{
"included": {
"included_target_state": {"state": None, "attributes": {}},
"count": 0,
},
{
"included_target_state": {
"state": "2021-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 0,
},
{
"included": {
"state": "2022-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 1,
},
],
),
(
"scene.activated",
[
{"included": {"state": "foo", "attributes": {}}, "count": 0},
{
"included": {
"state": "2021-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 1,
},
{
"included": {
"included_target_state": {
"state": "2022-01-01T23:59:59+00:00",
"attributes": {},
},
@@ -81,25 +64,54 @@ async def test_scene_triggers_gated_by_labs_flag(
"scene.activated",
[
{
"included": {"state": STATE_UNAVAILABLE, "attributes": {}},
"included_target_state": {"state": "foo", "attributes": {}},
"count": 0,
},
{
"included": {
"included_target_state": {
"state": "2021-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 1,
},
{
"included_target_state": {
"state": "2022-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 1,
},
],
),
(
"scene.activated",
[
{
"included_target_state": {
"state": STATE_UNAVAILABLE,
"attributes": {},
},
"count": 0,
},
{
"included_target_state": {
"state": "2021-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 0,
},
{
"included": {
"included_target_state": {
"state": "2022-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 1,
},
{
"included": {"state": STATE_UNAVAILABLE, "attributes": {}},
"included_target_state": {
"state": STATE_UNAVAILABLE,
"attributes": {},
},
"count": 0,
},
],
@@ -107,22 +119,28 @@ async def test_scene_triggers_gated_by_labs_flag(
(
"scene.activated",
[
{"included": {"state": STATE_UNKNOWN, "attributes": {}}, "count": 0},
{
"included": {
"included_target_state": {"state": STATE_UNKNOWN, "attributes": {}},
"count": 0,
},
{
"included_target_state": {
"state": "2021-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 1,
},
{
"included": {
"included_target_state": {
"state": "2022-01-01T23:59:59+00:00",
"attributes": {},
},
"count": 1,
},
{"included": {"state": STATE_UNKNOWN, "attributes": {}}, "count": 0},
{
"included_target_state": {"state": STATE_UNKNOWN, "attributes": {}},
"count": 0,
},
],
),
],
@@ -138,17 +156,17 @@ async def test_scene_state_trigger_behavior_any(
states: list[TriggerStateDescription],
) -> None:
"""Test that the scene state trigger fires when any scene state changes to a specific state."""
other_entity_ids = set(target_scenes["included"]) - {entity_id}
other_entity_ids = set(target_scenes["included_entities"]) - {entity_id}
# Set all scenes, including the tested scene, to the initial state
for eid in target_scenes["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_scenes["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
await arm_trigger(hass, trigger, None, trigger_target_config)
for state in states[1:]:
included_state = state["included"]
included_state = state["included_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()
assert len(service_calls) == state["count"]

View File

@@ -81,11 +81,11 @@ async def test_siren_state_condition_behavior_any(
states: list[ConditionStateDescription],
) -> None:
"""Test the siren state condition with the 'any' behavior."""
other_entity_ids = set(target_sirens["included"]) - {entity_id}
other_entity_ids = set(target_sirens["included_entities"]) - {entity_id}
# Set all sirens, including the tested siren, to the initial state
for eid in target_sirens["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_sirens["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
condition = await create_target_condition(
@@ -97,13 +97,13 @@ async def test_siren_state_condition_behavior_any(
# Set state for switches to ensure that they don't impact the condition
for state in states:
for eid in target_switches["included"]:
set_or_remove_state(hass, eid, state["included"])
for eid in target_switches["included_entities"]:
set_or_remove_state(hass, eid, state["included_target_state"])
await hass.async_block_till_done()
assert condition(hass) is False
for state in states:
included_state = state["included"]
included_state = state["included_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()
assert condition(hass) == state["condition_true"]
@@ -149,11 +149,11 @@ async def test_siren_state_condition_behavior_all(
# Set state for two switches to ensure that they don't impact the condition
hass.states.async_set("switch.label_switch_1", STATE_OFF)
hass.states.async_set("switch.label_switch_2", STATE_ON)
other_entity_ids = set(target_sirens["included"]) - {entity_id}
other_entity_ids = set(target_sirens["included_entities"]) - {entity_id}
# Set all sirens, including the tested siren, to the initial state
for eid in target_sirens["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_sirens["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
condition = await create_target_condition(
@@ -164,7 +164,7 @@ async def test_siren_state_condition_behavior_all(
)
for state in states:
included_state = state["included"]
included_state = state["included_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()

View File

@@ -81,11 +81,11 @@ async def test_switch_state_condition_behavior_any(
states: list[ConditionStateDescription],
) -> None:
"""Test the switch state condition with the 'any' behavior."""
other_entity_ids = set(target_switches["included"]) - {entity_id}
other_entity_ids = set(target_switches["included_entities"]) - {entity_id}
# Set all switches, including the tested switch, to the initial state
for eid in target_switches["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_switches["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
condition = await create_target_condition(
@@ -97,13 +97,13 @@ async def test_switch_state_condition_behavior_any(
# Set state for lights to ensure that they don't impact the condition
for state in states:
for eid in target_lights["included"]:
set_or_remove_state(hass, eid, state["included"])
for eid in target_lights["included_entities"]:
set_or_remove_state(hass, eid, state["included_target_state"])
await hass.async_block_till_done()
assert condition(hass) is False
for state in states:
included_state = state["included"]
included_state = state["included_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()
assert condition(hass) == state["condition_true"]
@@ -150,11 +150,11 @@ async def test_switch_state_condition_behavior_all(
hass.states.async_set("switch.label_switch_1", STATE_OFF)
hass.states.async_set("switch.label_switch_2", STATE_ON)
other_entity_ids = set(target_switches["included"]) - {entity_id}
other_entity_ids = set(target_switches["included_entities"]) - {entity_id}
# Set all switches, including the tested switch, to the initial state
for eid in target_switches["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_switches["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
condition = await create_target_condition(
@@ -165,7 +165,7 @@ async def test_switch_state_condition_behavior_all(
)
for state in states:
included_state = state["included"]
included_state = state["included_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()

View File

@@ -40,39 +40,75 @@ async def test_text_triggers_gated_by_labs_flag(
(
"text.changed",
[
{"included": {"state": None, "attributes": {}}, "count": 0},
{"included": {"state": "bar", "attributes": {}}, "count": 0},
{"included": {"state": "baz", "attributes": {}}, "count": 1},
{
"included_target_state": {"state": None, "attributes": {}},
"count": 0,
},
{
"included_target_state": {"state": "bar", "attributes": {}},
"count": 0,
},
{
"included_target_state": {"state": "baz", "attributes": {}},
"count": 1,
},
],
),
(
"text.changed",
[
{"included": {"state": "foo", "attributes": {}}, "count": 0},
{"included": {"state": "bar", "attributes": {}}, "count": 1},
{"included": {"state": "baz", "attributes": {}}, "count": 1},
{
"included_target_state": {"state": "foo", "attributes": {}},
"count": 0,
},
{
"included_target_state": {"state": "bar", "attributes": {}},
"count": 1,
},
{
"included_target_state": {"state": "baz", "attributes": {}},
"count": 1,
},
],
),
(
"text.changed",
[
{"included": {"state": "foo", "attributes": {}}, "count": 0},
{
"included_target_state": {"state": "foo", "attributes": {}},
"count": 0,
},
# empty string
{"included": {"state": "", "attributes": {}}, "count": 1},
{"included": {"state": "baz", "attributes": {}}, "count": 1},
{"included_target_state": {"state": "", "attributes": {}}, "count": 1},
{
"included_target_state": {"state": "baz", "attributes": {}},
"count": 1,
},
],
),
(
"text.changed",
[
{
"included": {"state": STATE_UNAVAILABLE, "attributes": {}},
"included_target_state": {
"state": STATE_UNAVAILABLE,
"attributes": {},
},
"count": 0,
},
{"included": {"state": "bar", "attributes": {}}, "count": 0},
{"included": {"state": "baz", "attributes": {}}, "count": 1},
{
"included": {"state": STATE_UNAVAILABLE, "attributes": {}},
"included_target_state": {"state": "bar", "attributes": {}},
"count": 0,
},
{
"included_target_state": {"state": "baz", "attributes": {}},
"count": 1,
},
{
"included_target_state": {
"state": STATE_UNAVAILABLE,
"attributes": {},
},
"count": 0,
},
],
@@ -80,10 +116,22 @@ async def test_text_triggers_gated_by_labs_flag(
(
"text.changed",
[
{"included": {"state": STATE_UNKNOWN, "attributes": {}}, "count": 0},
{"included": {"state": "bar", "attributes": {}}, "count": 0},
{"included": {"state": "baz", "attributes": {}}, "count": 1},
{"included": {"state": STATE_UNKNOWN, "attributes": {}}, "count": 0},
{
"included_target_state": {"state": STATE_UNKNOWN, "attributes": {}},
"count": 0,
},
{
"included_target_state": {"state": "bar", "attributes": {}},
"count": 0,
},
{
"included_target_state": {"state": "baz", "attributes": {}},
"count": 1,
},
{
"included_target_state": {"state": STATE_UNKNOWN, "attributes": {}},
"count": 0,
},
],
),
],
@@ -99,17 +147,17 @@ async def test_text_state_trigger_behavior_any(
states: list[TriggerStateDescription],
) -> None:
"""Test that the text state trigger fires when any text state changes to a specific state."""
other_entity_ids = set(target_texts["included"]) - {entity_id}
other_entity_ids = set(target_texts["included_entities"]) - {entity_id}
# Set all texts, including the tested text, to the initial state
for eid in target_texts["included"]:
set_or_remove_state(hass, eid, states[0]["included"])
for eid in target_texts["included_entities"]:
set_or_remove_state(hass, eid, states[0]["included_target_state"])
await hass.async_block_till_done()
await arm_trigger(hass, trigger, None, trigger_target_config)
for state in states[1:]:
included_state = state["included"]
included_state = state["included_target_state"]
set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()
assert len(service_calls) == state["count"]

View File

@@ -59,14 +59,14 @@ async def test_window_triggers_gated_by_labs_flag(
trigger="window.opened",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "window"},
required_filter_attributes={ATTR_DEVICE_CLASS: "window"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="window.closed",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "window"},
required_filter_attributes={ATTR_DEVICE_CLASS: "window"},
trigger_from_none=False,
),
],
@@ -118,7 +118,7 @@ async def test_window_trigger_binary_sensor_behavior_any(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "window"},
required_filter_attributes={ATTR_DEVICE_CLASS: "window"},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -136,7 +136,7 @@ async def test_window_trigger_binary_sensor_behavior_any(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "window"},
required_filter_attributes={ATTR_DEVICE_CLASS: "window"},
trigger_from_none=False,
),
],
@@ -178,14 +178,14 @@ async def test_window_trigger_cover_behavior_any(
trigger="window.opened",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "window"},
required_filter_attributes={ATTR_DEVICE_CLASS: "window"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="window.closed",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "window"},
required_filter_attributes={ATTR_DEVICE_CLASS: "window"},
trigger_from_none=False,
),
],
@@ -227,14 +227,14 @@ async def test_window_trigger_binary_sensor_behavior_first(
trigger="window.opened",
target_states=[STATE_ON],
other_states=[STATE_OFF],
additional_attributes={ATTR_DEVICE_CLASS: "window"},
required_filter_attributes={ATTR_DEVICE_CLASS: "window"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="window.closed",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "window"},
required_filter_attributes={ATTR_DEVICE_CLASS: "window"},
trigger_from_none=False,
),
],
@@ -286,7 +286,7 @@ async def test_window_trigger_binary_sensor_behavior_last(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "window"},
required_filter_attributes={ATTR_DEVICE_CLASS: "window"},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -304,7 +304,7 @@ async def test_window_trigger_binary_sensor_behavior_last(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "window"},
required_filter_attributes={ATTR_DEVICE_CLASS: "window"},
trigger_from_none=False,
),
],
@@ -356,7 +356,7 @@ async def test_window_trigger_cover_behavior_first(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "window"},
required_filter_attributes={ATTR_DEVICE_CLASS: "window"},
trigger_from_none=False,
),
*parametrize_trigger_states(
@@ -374,7 +374,7 @@ async def test_window_trigger_cover_behavior_first(
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "window"},
required_filter_attributes={ATTR_DEVICE_CLASS: "window"},
trigger_from_none=False,
),
],