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
22 changes: 11 additions & 11 deletions tests/components/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,18 +1255,18 @@ async def assert_condition_behavior_any(
for excluded_entity_id in excluded_entity_ids:
set_or_remove_state(hass, excluded_entity_id, excluded_state)
await hass.async_block_till_done()
assert cond(hass) is False
assert cond.async_check() is False

set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()
assert cond(hass) == state["condition_true"]
assert cond.async_check() == state["condition_true"]

# Set other included entities to the included state to verify that
# they don't change the condition evaluation
for other_entity_id in other_entity_ids:
set_or_remove_state(hass, other_entity_id, included_state)
await hass.async_block_till_done()
assert cond(hass) == state["condition_true"]
assert cond.async_check() == state["condition_true"]


async def assert_condition_behavior_all(
Expand Down Expand Up @@ -1305,7 +1305,7 @@ async def assert_condition_behavior_all(

set_or_remove_state(hass, entity_id, included_state)
await hass.async_block_till_done()
assert cond(hass) == state["condition_true_first_entity"]
assert cond.async_check() == state["condition_true_first_entity"]

for other_entity_id in other_entity_ids:
set_or_remove_state(hass, other_entity_id, included_state)
Expand All @@ -1314,7 +1314,7 @@ async def assert_condition_behavior_all(
set_or_remove_state(hass, excluded_entity_id, excluded_state)
await hass.async_block_till_done()

assert cond(hass) == state["condition_true"]
assert cond.async_check() == state["condition_true"]


async def assert_trigger_behavior_any(
Expand Down Expand Up @@ -1947,10 +1947,10 @@ async def assert_numerical_condition_unit_conversion(
)
for state in pass_states:
set_or_remove_state(hass, entity_id, state)
assert cond(hass) is True
assert cond.async_check() is True
for state in fail_states:
set_or_remove_state(hass, entity_id, state)
assert cond(hass) is False
assert cond.async_check() is False

# Test limits set by entity
cond = await create_target_condition(
Expand All @@ -1965,18 +1965,18 @@ async def assert_numerical_condition_unit_conversion(
set_or_remove_state(hass, limit_entities[1], limit_states[1])
for state in pass_states:
set_or_remove_state(hass, entity_id, state)
assert cond(hass) is True
assert cond.async_check() is True
for state in fail_states:
set_or_remove_state(hass, entity_id, state)
assert cond(hass) is False
assert cond.async_check() is False

# Test invalid unit
for limit_states in invalid_limit_entity_states:
set_or_remove_state(hass, limit_entities[0], limit_states[0])
set_or_remove_state(hass, limit_entities[1], limit_states[1])
for state in pass_states:
set_or_remove_state(hass, entity_id, state)
assert cond(hass) is False
assert cond.async_check() is False
for state in fail_states:
set_or_remove_state(hass, entity_id, state)
assert cond(hass) is False
assert cond.async_check() is False
4 changes: 2 additions & 2 deletions tests/components/cover/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ async def test_cover_condition_excludes_non_matching_device_class(
)

# Matching entity in matching state - condition should be True
assert condition_any(hass) is True
assert condition_any.async_check() is True

# Set matching entity to non-matching state
hass.states.async_set(
Expand All @@ -296,4 +296,4 @@ async def test_cover_condition_excludes_non_matching_device_class(
await hass.async_block_till_done()

# Wrong device class entity still in matching state, but should be excluded
assert condition_any(hass) is False
assert condition_any.async_check() is False
4 changes: 2 additions & 2 deletions tests/components/door/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ async def test_door_condition_excludes_non_door_device_class(
)

# Matching entities in matching state - condition should be True
assert condition_any(hass) is True
assert condition_any.async_check() is True

# Set matching entities to non-matching state
hass.states.async_set(
Expand All @@ -386,4 +386,4 @@ async def test_door_condition_excludes_non_door_device_class(
await hass.async_block_till_done()

# Wrong device class entities still in matching state, but should be excluded
assert condition_any(hass) is False
assert condition_any.async_check() is False
4 changes: 2 additions & 2 deletions tests/components/garage_door/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ async def test_garage_door_condition_excludes_non_garage_door_device_class(
)

# Matching entities in matching state - condition should be True
assert condition_any(hass) is True
assert condition_any.async_check() is True

# Set matching entities to non-matching state
hass.states.async_set(
Expand All @@ -390,4 +390,4 @@ async def test_garage_door_condition_excludes_non_garage_door_device_class(
await hass.async_block_till_done()

# Wrong device class entities still in matching state, but should be excluded
assert condition_any(hass) is False
assert condition_any.async_check() is False
4 changes: 2 additions & 2 deletions tests/components/gate/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async def test_gate_condition_excludes_non_gate_device_class(
)

# Matching entity in matching state - condition should be True
assert condition_any(hass) is True
assert condition_any.async_check() is True

# Set matching entity to non-matching state
hass.states.async_set(
Expand All @@ -258,4 +258,4 @@ async def test_gate_condition_excludes_non_gate_device_class(
await hass.async_block_till_done()

# Wrong device class entity still in matching state, but should be excluded
assert condition_any(hass) is False
assert condition_any.async_check() is False
4 changes: 2 additions & 2 deletions tests/components/motion/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ async def test_motion_condition_excludes_non_motion_device_class(
)

# Matching entity in matching state - condition should be True
assert condition_any(hass) is True
assert condition_any.async_check() is True

# Set matching entity to non-matching state
hass.states.async_set(
Expand All @@ -219,4 +219,4 @@ async def test_motion_condition_excludes_non_motion_device_class(
await hass.async_block_till_done()

# Wrong device class entity still in matching state, but should be excluded
assert condition_any(hass) is False
assert condition_any.async_check() is False
4 changes: 2 additions & 2 deletions tests/components/occupancy/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ async def test_occupancy_condition_excludes_non_occupancy_device_class(
)

# Matching entity in matching state - condition should be True
assert condition_any(hass) is True
assert condition_any.async_check() is True

# Set matching entity to non-matching state
hass.states.async_set(
Expand All @@ -219,4 +219,4 @@ async def test_occupancy_condition_excludes_non_occupancy_device_class(
await hass.async_block_till_done()

# Wrong device class entity still in matching state, but should be excluded
assert condition_any(hass) is False
assert condition_any.async_check() is False
6 changes: 3 additions & 3 deletions tests/components/select/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,19 @@ async def test_select_condition_evaluates_both_domains(
condition_options={CONF_OPTION: ["option_a", "option_b"]},
)

assert cond(hass) is True
assert cond.async_check() is True

# Set one to a non-matching option - "any" behavior should still pass
hass.states.async_set(entity_id_select, "option_c")
await hass.async_block_till_done()

assert cond(hass) is True
assert cond.async_check() is True

# Set both to non-matching options
hass.states.async_set(entity_id_input_select, "option_c")
await hass.async_block_till_done()

assert cond(hass) is False
assert cond.async_check() is False


# --- Schema validation tests ---
Expand Down
6 changes: 3 additions & 3 deletions tests/components/switch/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ async def test_switch_condition_evaluates_both_domains(
)

# Both off - condition should be false
assert condition(hass) is False
assert condition.async_check() is False

# switch entity turns on - condition should be true
hass.states.async_set(entity_id_switch, STATE_ON)
await hass.async_block_till_done()
assert condition(hass) is True
assert condition.async_check() is True

# Reset switch, turn on input_boolean - condition should still be true
hass.states.async_set(entity_id_switch, STATE_OFF)
hass.states.async_set(entity_id_input_boolean, STATE_ON)
await hass.async_block_till_done()
assert condition(hass) is True
assert condition.async_check() is True
4 changes: 2 additions & 2 deletions tests/components/text/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ async def test_text_condition_fires_for_both_domains(
},
)

assert checker(hass) is True
assert checker.async_check() is True

# Change input_text to non-matching - all behavior should fail
hass.states.async_set(entity_id_input_text, "world")
await hass.async_block_till_done()
assert checker(hass) is False
assert checker.async_check() is False
4 changes: 2 additions & 2 deletions tests/components/window/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ async def test_window_condition_excludes_non_window_device_class(
)

# Matching entities in matching state - condition should be True
assert condition_any(hass) is True
assert condition_any.async_check() is True

# Set matching entities to non-matching state
hass.states.async_set(
Expand All @@ -386,4 +386,4 @@ async def test_window_condition_excludes_non_window_device_class(
await hass.async_block_till_done()

# Wrong device class entities still in matching state, but should be excluded
assert condition_any(hass) is False
assert condition_any.async_check() is False
28 changes: 14 additions & 14 deletions tests/components/zone/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def test_zone_raises(hass: HomeAssistant) -> None:
zone_condition.zone(hass, zone_ent=None, entity="sensor.any")

with pytest.raises(ConditionError, match="unknown zone"):
test(hass)
test.async_check()

hass.states.async_set(
"zone.home",
Expand All @@ -34,7 +34,7 @@ async def test_zone_raises(hass: HomeAssistant) -> None:
zone_condition.zone(hass, zone_ent="zone.home", entity=None)

with pytest.raises(ConditionError, match="unknown entity"):
test(hass)
test.async_check()

hass.states.async_set(
"device_tracker.cat",
Expand All @@ -43,7 +43,7 @@ async def test_zone_raises(hass: HomeAssistant) -> None:
)

with pytest.raises(ConditionError, match="latitude"):
test(hass)
test.async_check()

hass.states.async_set(
"device_tracker.cat",
Expand All @@ -52,7 +52,7 @@ async def test_zone_raises(hass: HomeAssistant) -> None:
)

with pytest.raises(ConditionError, match="longitude"):
test(hass)
test.async_check()

hass.states.async_set(
"device_tracker.cat",
Expand All @@ -61,7 +61,7 @@ async def test_zone_raises(hass: HomeAssistant) -> None:
)

# All okay, now test multiple failed conditions
assert test(hass)
assert test.async_check()

config = {
"condition": "zone",
Expand All @@ -75,10 +75,10 @@ async def test_zone_raises(hass: HomeAssistant) -> None:
test = await condition.async_from_config(hass, config)

with pytest.raises(ConditionError, match="dog"):
test(hass)
test.async_check()

with pytest.raises(ConditionError, match="work"):
test(hass)
test.async_check()

hass.states.async_set(
"zone.work",
Expand All @@ -92,7 +92,7 @@ async def test_zone_raises(hass: HomeAssistant) -> None:
{"friendly_name": "dog", "latitude": 20.1, "longitude": 10.1},
)

assert test(hass)
assert test.async_check()


async def test_zone_multiple_entities(hass: HomeAssistant) -> None:
Expand Down Expand Up @@ -130,7 +130,7 @@ async def test_zone_multiple_entities(hass: HomeAssistant) -> None:
"home",
{"friendly_name": "person_2", "latitude": 2.1, "longitude": 1.1},
)
assert test(hass)
assert test.async_check()

hass.states.async_set(
"device_tracker.person_1",
Expand All @@ -142,7 +142,7 @@ async def test_zone_multiple_entities(hass: HomeAssistant) -> None:
"home",
{"friendly_name": "person_2", "latitude": 2.1, "longitude": 1.1},
)
assert not test(hass)
assert not test.async_check()

hass.states.async_set(
"device_tracker.person_1",
Expand All @@ -154,7 +154,7 @@ async def test_zone_multiple_entities(hass: HomeAssistant) -> None:
"home",
{"friendly_name": "person_2", "latitude": 20.1, "longitude": 10.1},
)
assert not test(hass)
assert not test.async_check()


async def test_multiple_zones(hass: HomeAssistant) -> None:
Expand Down Expand Up @@ -191,18 +191,18 @@ async def test_multiple_zones(hass: HomeAssistant) -> None:
"home",
{"friendly_name": "person", "latitude": 2.1, "longitude": 1.1},
)
assert test(hass)
assert test.async_check()

hass.states.async_set(
"device_tracker.person",
"home",
{"friendly_name": "person", "latitude": 20.1, "longitude": 10.1},
)
assert test(hass)
assert test.async_check()

hass.states.async_set(
"device_tracker.person",
"home",
{"friendly_name": "person", "latitude": 50.1, "longitude": 20.1},
)
assert not test(hass)
assert not test.async_check()
Loading