mirror of
https://github.com/home-assistant/core.git
synced 2025-11-12 20:40:18 +00:00
Add type hints to integration tests (part 2) (#88493)
This commit is contained in:
@@ -33,7 +33,7 @@ def setup_comp(hass):
|
||||
hass.states.async_set("test.entity", "hello")
|
||||
|
||||
|
||||
async def test_if_fires_on_entity_change(hass, calls):
|
||||
async def test_if_fires_on_entity_change(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for firing on entity change."""
|
||||
context = Context()
|
||||
hass.states.async_set("test.entity", "hello")
|
||||
@@ -83,7 +83,7 @@ async def test_if_fires_on_entity_change(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_entity_change_uuid(hass, calls):
|
||||
async def test_if_fires_on_entity_change_uuid(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for firing on entity change."""
|
||||
context = Context()
|
||||
|
||||
@@ -141,7 +141,9 @@ async def test_if_fires_on_entity_change_uuid(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_entity_change_with_from_filter(hass, calls):
|
||||
async def test_if_fires_on_entity_change_with_from_filter(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on entity change with filter."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -194,7 +196,9 @@ async def test_if_fires_on_entity_change_with_not_from_filter(
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_entity_change_with_to_filter(hass, calls):
|
||||
async def test_if_fires_on_entity_change_with_to_filter(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on entity change with to filter."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -247,7 +251,9 @@ async def test_if_fires_on_entity_change_with_not_to_filter(
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_entity_change_with_from_filter_all(hass, calls):
|
||||
async def test_if_fires_on_entity_change_with_from_filter_all(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on entity change with filter."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -271,7 +277,9 @@ async def test_if_fires_on_entity_change_with_from_filter_all(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_entity_change_with_to_filter_all(hass, calls):
|
||||
async def test_if_fires_on_entity_change_with_to_filter_all(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on entity change with to filter."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -295,7 +303,9 @@ async def test_if_fires_on_entity_change_with_to_filter_all(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_attribute_change_with_to_filter(hass, calls):
|
||||
async def test_if_fires_on_attribute_change_with_to_filter(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for not firing on attribute change."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -319,7 +329,9 @@ async def test_if_fires_on_attribute_change_with_to_filter(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_entity_change_with_both_filters(hass, calls):
|
||||
async def test_if_fires_on_entity_change_with_both_filters(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing if both filters are a non match."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -437,7 +449,7 @@ async def test_if_fires_on_entity_change_with_from_not_to(
|
||||
assert len(calls) == 2
|
||||
|
||||
|
||||
async def test_if_not_fires_if_to_filter_not_match(hass, calls):
|
||||
async def test_if_not_fires_if_to_filter_not_match(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for not firing if to filter is not a match."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -461,7 +473,9 @@ async def test_if_not_fires_if_to_filter_not_match(hass, calls):
|
||||
assert len(calls) == 0
|
||||
|
||||
|
||||
async def test_if_not_fires_if_from_filter_not_match(hass, calls):
|
||||
async def test_if_not_fires_if_from_filter_not_match(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for not firing if from filter is not a match."""
|
||||
hass.states.async_set("test.entity", "bye")
|
||||
|
||||
@@ -487,7 +501,7 @@ async def test_if_not_fires_if_from_filter_not_match(hass, calls):
|
||||
assert len(calls) == 0
|
||||
|
||||
|
||||
async def test_if_not_fires_if_entity_not_match(hass, calls):
|
||||
async def test_if_not_fires_if_entity_not_match(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for not firing if entity is not matching."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -506,7 +520,7 @@ async def test_if_not_fires_if_entity_not_match(hass, calls):
|
||||
assert len(calls) == 0
|
||||
|
||||
|
||||
async def test_if_action(hass, calls):
|
||||
async def test_if_action(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for to action."""
|
||||
entity_id = "domain.test_entity"
|
||||
test_state = "new_state"
|
||||
@@ -538,7 +552,7 @@ async def test_if_action(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fails_setup_if_to_boolean_value(hass, calls):
|
||||
async def test_if_fails_setup_if_to_boolean_value(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for setup failure for boolean to."""
|
||||
with assert_setup_component(0, automation.DOMAIN):
|
||||
assert await async_setup_component(
|
||||
@@ -557,7 +571,7 @@ async def test_if_fails_setup_if_to_boolean_value(hass, calls):
|
||||
)
|
||||
|
||||
|
||||
async def test_if_fails_setup_if_from_boolean_value(hass, calls):
|
||||
async def test_if_fails_setup_if_from_boolean_value(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for setup failure for boolean from."""
|
||||
with assert_setup_component(0, automation.DOMAIN):
|
||||
assert await async_setup_component(
|
||||
@@ -576,7 +590,7 @@ async def test_if_fails_setup_if_from_boolean_value(hass, calls):
|
||||
)
|
||||
|
||||
|
||||
async def test_if_fails_setup_bad_for(hass, calls):
|
||||
async def test_if_fails_setup_bad_for(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for setup failure for bad for."""
|
||||
with assert_setup_component(0, automation.DOMAIN):
|
||||
assert await async_setup_component(
|
||||
@@ -596,7 +610,9 @@ async def test_if_fails_setup_bad_for(hass, calls):
|
||||
)
|
||||
|
||||
|
||||
async def test_if_not_fires_on_entity_change_with_for(hass, calls):
|
||||
async def test_if_not_fires_on_entity_change_with_for(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for not firing on entity change with for."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -624,7 +640,9 @@ async def test_if_not_fires_on_entity_change_with_for(hass, calls):
|
||||
assert len(calls) == 0
|
||||
|
||||
|
||||
async def test_if_not_fires_on_entities_change_with_for_after_stop(hass, calls):
|
||||
async def test_if_not_fires_on_entities_change_with_for_after_stop(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for not firing on entity change with for after stop trigger."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -668,7 +686,9 @@ async def test_if_not_fires_on_entities_change_with_for_after_stop(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_entity_change_with_for_attribute_change(hass, calls):
|
||||
async def test_if_fires_on_entity_change_with_for_attribute_change(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on entity change with for and attribute change."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -705,7 +725,9 @@ async def test_if_fires_on_entity_change_with_for_attribute_change(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_entity_change_with_for_multiple_force_update(hass, calls):
|
||||
async def test_if_fires_on_entity_change_with_for_multiple_force_update(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on entity change with for and force update."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -741,7 +763,7 @@ async def test_if_fires_on_entity_change_with_for_multiple_force_update(hass, ca
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_entity_change_with_for(hass, calls):
|
||||
async def test_if_fires_on_entity_change_with_for(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for firing on entity change with for."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -767,7 +789,9 @@ async def test_if_fires_on_entity_change_with_for(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_entity_change_with_for_without_to(hass, calls):
|
||||
async def test_if_fires_on_entity_change_with_for_without_to(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on entity change with for."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -804,7 +828,9 @@ async def test_if_fires_on_entity_change_with_for_without_to(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_does_not_fires_on_entity_change_with_for_without_to_2(hass, calls):
|
||||
async def test_if_does_not_fires_on_entity_change_with_for_without_to_2(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on entity change with for."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -837,7 +863,9 @@ async def test_if_does_not_fires_on_entity_change_with_for_without_to_2(hass, ca
|
||||
assert len(calls) == 0
|
||||
|
||||
|
||||
async def test_if_fires_on_entity_creation_and_removal(hass, calls):
|
||||
async def test_if_fires_on_entity_creation_and_removal(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on entity creation and removal, with to/from constraints."""
|
||||
# set automations for multiple combinations to/from
|
||||
assert await async_setup_component(
|
||||
@@ -902,7 +930,7 @@ async def test_if_fires_on_entity_creation_and_removal(hass, calls):
|
||||
assert calls[3].context.parent_id == context_0.id
|
||||
|
||||
|
||||
async def test_if_fires_on_for_condition(hass, calls):
|
||||
async def test_if_fires_on_for_condition(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for firing if condition is on."""
|
||||
point1 = dt_util.utcnow()
|
||||
point2 = point1 + timedelta(seconds=10)
|
||||
@@ -939,7 +967,9 @@ async def test_if_fires_on_for_condition(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_for_condition_attribute_change(hass, calls):
|
||||
async def test_if_fires_on_for_condition_attribute_change(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing if condition is on with attribute change."""
|
||||
point1 = dt_util.utcnow()
|
||||
point2 = point1 + timedelta(seconds=4)
|
||||
@@ -986,7 +1016,7 @@ async def test_if_fires_on_for_condition_attribute_change(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fails_setup_for_without_time(hass, calls):
|
||||
async def test_if_fails_setup_for_without_time(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for setup failure if no time is provided."""
|
||||
with assert_setup_component(0, automation.DOMAIN):
|
||||
assert await async_setup_component(
|
||||
@@ -1007,7 +1037,7 @@ async def test_if_fails_setup_for_without_time(hass, calls):
|
||||
)
|
||||
|
||||
|
||||
async def test_if_fails_setup_for_without_entity(hass, calls):
|
||||
async def test_if_fails_setup_for_without_entity(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for setup failure if no entity is provided."""
|
||||
with assert_setup_component(0, automation.DOMAIN):
|
||||
assert await async_setup_component(
|
||||
@@ -1027,7 +1057,7 @@ async def test_if_fails_setup_for_without_entity(hass, calls):
|
||||
)
|
||||
|
||||
|
||||
async def test_wait_template_with_trigger(hass, calls):
|
||||
async def test_wait_template_with_trigger(hass: HomeAssistant, calls) -> None:
|
||||
"""Test using wait template with 'trigger.entity_id'."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -1069,7 +1099,9 @@ async def test_wait_template_with_trigger(hass, calls):
|
||||
assert calls[0].data["some"] == "state - test.entity - hello - world"
|
||||
|
||||
|
||||
async def test_if_fires_on_entities_change_no_overlap(hass, calls):
|
||||
async def test_if_fires_on_entities_change_no_overlap(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on entities change with no overlap."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -1111,7 +1143,7 @@ async def test_if_fires_on_entities_change_no_overlap(hass, calls):
|
||||
assert calls[1].data["some"] == "test.entity_2"
|
||||
|
||||
|
||||
async def test_if_fires_on_entities_change_overlap(hass, calls):
|
||||
async def test_if_fires_on_entities_change_overlap(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for firing on entities change with overlap."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -1164,7 +1196,9 @@ async def test_if_fires_on_entities_change_overlap(hass, calls):
|
||||
assert calls[1].data["some"] == "test.entity_2"
|
||||
|
||||
|
||||
async def test_if_fires_on_change_with_for_template_1(hass, calls):
|
||||
async def test_if_fires_on_change_with_for_template_1(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on change with for template."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -1190,7 +1224,9 @@ async def test_if_fires_on_change_with_for_template_1(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_change_with_for_template_2(hass, calls):
|
||||
async def test_if_fires_on_change_with_for_template_2(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on change with for template."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -1216,7 +1252,9 @@ async def test_if_fires_on_change_with_for_template_2(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_change_with_for_template_3(hass, calls):
|
||||
async def test_if_fires_on_change_with_for_template_3(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on change with for template."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -1242,7 +1280,9 @@ async def test_if_fires_on_change_with_for_template_3(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_change_with_for_template_4(hass, calls):
|
||||
async def test_if_fires_on_change_with_for_template_4(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on change with for template."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -1269,7 +1309,7 @@ async def test_if_fires_on_change_with_for_template_4(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_change_from_with_for(hass, calls):
|
||||
async def test_if_fires_on_change_from_with_for(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for firing on change with from/for."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -1298,7 +1338,7 @@ async def test_if_fires_on_change_from_with_for(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_not_fires_on_change_from_with_for(hass, calls):
|
||||
async def test_if_not_fires_on_change_from_with_for(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for firing on change with from/for."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -1327,7 +1367,7 @@ async def test_if_not_fires_on_change_from_with_for(hass, calls):
|
||||
assert len(calls) == 0
|
||||
|
||||
|
||||
async def test_invalid_for_template_1(hass, calls):
|
||||
async def test_invalid_for_template_1(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for invalid for template."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -1351,7 +1391,9 @@ async def test_invalid_for_template_1(hass, calls):
|
||||
assert mock_logger.error.called
|
||||
|
||||
|
||||
async def test_if_fires_on_entities_change_overlap_for_template(hass, calls):
|
||||
async def test_if_fires_on_entities_change_overlap_for_template(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing on entities change with overlap and for template."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -1411,7 +1453,9 @@ async def test_if_fires_on_entities_change_overlap_for_template(hass, calls):
|
||||
assert calls[1].data["some"] == "test.entity_2 - 0:00:10"
|
||||
|
||||
|
||||
async def test_attribute_if_fires_on_entity_change_with_both_filters(hass, calls):
|
||||
async def test_attribute_if_fires_on_entity_change_with_both_filters(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing if both filters are match attribute."""
|
||||
hass.states.async_set("test.entity", "bla", {"name": "hello"})
|
||||
|
||||
@@ -1438,7 +1482,9 @@ async def test_attribute_if_fires_on_entity_change_with_both_filters(hass, calls
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_attribute_if_fires_on_entity_where_attr_stays_constant(hass, calls):
|
||||
async def test_attribute_if_fires_on_entity_where_attr_stays_constant(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing if attribute stays the same."""
|
||||
hass.states.async_set("test.entity", "bla", {"name": "hello", "other": "old_value"})
|
||||
|
||||
@@ -1475,8 +1521,8 @@ async def test_attribute_if_fires_on_entity_where_attr_stays_constant(hass, call
|
||||
|
||||
|
||||
async def test_attribute_if_fires_on_entity_where_attr_stays_constant_filter(
|
||||
hass, calls
|
||||
):
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing if attribute stays the same."""
|
||||
hass.states.async_set("test.entity", "bla", {"name": "other_name"})
|
||||
|
||||
@@ -1519,7 +1565,9 @@ async def test_attribute_if_fires_on_entity_where_attr_stays_constant_filter(
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_attribute_if_fires_on_entity_where_attr_stays_constant_all(hass, calls):
|
||||
async def test_attribute_if_fires_on_entity_where_attr_stays_constant_all(
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing if attribute stays the same."""
|
||||
hass.states.async_set("test.entity", "bla", {"name": "hello", "other": "old_value"})
|
||||
|
||||
@@ -1563,8 +1611,8 @@ async def test_attribute_if_fires_on_entity_where_attr_stays_constant_all(hass,
|
||||
|
||||
|
||||
async def test_attribute_if_not_fires_on_entities_change_with_for_after_stop(
|
||||
hass, calls
|
||||
):
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for not firing on entity change with for after stop trigger."""
|
||||
hass.states.async_set("test.entity", "bla", {"name": "hello"})
|
||||
|
||||
@@ -1616,8 +1664,8 @@ async def test_attribute_if_not_fires_on_entities_change_with_for_after_stop(
|
||||
|
||||
|
||||
async def test_attribute_if_fires_on_entity_change_with_both_filters_boolean(
|
||||
hass, calls
|
||||
):
|
||||
hass: HomeAssistant, calls
|
||||
) -> None:
|
||||
"""Test for firing if both filters are match attribute."""
|
||||
hass.states.async_set("test.entity", "bla", {"happening": False})
|
||||
|
||||
@@ -1644,7 +1692,7 @@ async def test_attribute_if_fires_on_entity_change_with_both_filters_boolean(
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_variables_priority(hass, calls):
|
||||
async def test_variables_priority(hass: HomeAssistant, calls) -> None:
|
||||
"""Test an externally defined trigger variable is overridden."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
|
||||
Reference in New Issue
Block a user