Improve type hints in generic_hygrostat/thermostat tests (#121167)

This commit is contained in:
epenet 2024-07-04 10:30:17 +02:00 committed by GitHub
parent 1f22f0d89b
commit 1eec49696a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 180 additions and 151 deletions

View File

@ -87,13 +87,14 @@ async def test_valid_conf(hass: HomeAssistant) -> None:
@pytest.fixture @pytest.fixture
async def setup_comp_1(hass): async def setup_comp_1(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
assert await async_setup_component(hass, "homeassistant", {}) assert await async_setup_component(hass, "homeassistant", {})
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_humidifier_input_boolean(hass: HomeAssistant, setup_comp_1) -> None: @pytest.mark.usefixtures("setup_comp_1")
async def test_humidifier_input_boolean(hass: HomeAssistant) -> None:
"""Test humidifier switching input_boolean.""" """Test humidifier switching input_boolean."""
humidifier_switch = "input_boolean.test" humidifier_switch = "input_boolean.test"
assert await async_setup_component( assert await async_setup_component(
@ -132,8 +133,9 @@ async def test_humidifier_input_boolean(hass: HomeAssistant, setup_comp_1) -> No
assert hass.states.get(ENTITY).attributes.get("action") == "humidifying" assert hass.states.get(ENTITY).attributes.get("action") == "humidifying"
@pytest.mark.usefixtures("setup_comp_1")
async def test_humidifier_switch( async def test_humidifier_switch(
hass: HomeAssistant, setup_comp_1, mock_switch_entities: list[MockSwitch] hass: HomeAssistant, mock_switch_entities: list[MockSwitch]
) -> None: ) -> None:
"""Test humidifier switching test switch.""" """Test humidifier switching test switch."""
setup_test_component_platform(hass, switch.DOMAIN, mock_switch_entities) setup_test_component_platform(hass, switch.DOMAIN, mock_switch_entities)
@ -176,8 +178,9 @@ async def test_humidifier_switch(
assert hass.states.get(ENTITY).attributes.get("action") == "humidifying" assert hass.states.get(ENTITY).attributes.get("action") == "humidifying"
@pytest.mark.usefixtures("setup_comp_1")
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, entity_registry: er.EntityRegistry, setup_comp_1 hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None: ) -> None:
"""Test setting a unique ID.""" """Test setting a unique ID."""
unique_id = "some_unique_id" unique_id = "some_unique_id"
@ -209,7 +212,7 @@ def _setup_sensor(hass, humidity):
@pytest.fixture @pytest.fixture
async def setup_comp_0(hass): async def setup_comp_0(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
_setup_sensor(hass, 45) _setup_sensor(hass, 45)
hass.states.async_set(ENT_SWITCH, STATE_OFF) hass.states.async_set(ENT_SWITCH, STATE_OFF)
@ -235,7 +238,7 @@ async def setup_comp_0(hass):
@pytest.fixture @pytest.fixture
async def setup_comp_2(hass): async def setup_comp_2(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
_setup_sensor(hass, 45) _setup_sensor(hass, 45)
hass.states.async_set(ENT_SWITCH, STATE_OFF) hass.states.async_set(ENT_SWITCH, STATE_OFF)
@ -307,7 +310,8 @@ async def test_setup_defaults_to_unknown(hass: HomeAssistant) -> None:
assert hass.states.get(ENTITY).state == STATE_UNAVAILABLE assert hass.states.get(ENTITY).state == STATE_UNAVAILABLE
async def test_default_setup_params(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_default_setup_params(hass: HomeAssistant) -> None:
"""Test the setup with default parameters.""" """Test the setup with default parameters."""
state = hass.states.get(ENTITY) state = hass.states.get(ENTITY)
assert state.attributes.get("min_humidity") == 0 assert state.attributes.get("min_humidity") == 0
@ -316,9 +320,8 @@ async def test_default_setup_params(hass: HomeAssistant, setup_comp_2) -> None:
assert state.attributes.get("action") == "idle" assert state.attributes.get("action") == "idle"
async def test_default_setup_params_dehumidifier( @pytest.mark.usefixtures("setup_comp_0")
hass: HomeAssistant, setup_comp_0 async def test_default_setup_params_dehumidifier(hass: HomeAssistant) -> None:
) -> None:
"""Test the setup with default parameters for dehumidifier.""" """Test the setup with default parameters for dehumidifier."""
state = hass.states.get(ENTITY) state = hass.states.get(ENTITY)
assert state.attributes.get("min_humidity") == 0 assert state.attributes.get("min_humidity") == 0
@ -327,14 +330,16 @@ async def test_default_setup_params_dehumidifier(
assert state.attributes.get("action") == "idle" assert state.attributes.get("action") == "idle"
async def test_get_modes(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_get_modes(hass: HomeAssistant) -> None:
"""Test that the attributes returns the correct modes.""" """Test that the attributes returns the correct modes."""
state = hass.states.get(ENTITY) state = hass.states.get(ENTITY)
modes = state.attributes.get("available_modes") modes = state.attributes.get("available_modes")
assert modes == [MODE_NORMAL, MODE_AWAY] assert modes == [MODE_NORMAL, MODE_AWAY]
async def test_set_target_humidity(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_set_target_humidity(hass: HomeAssistant) -> None:
"""Test the setting of the target humidity.""" """Test the setting of the target humidity."""
await hass.services.async_call( await hass.services.async_call(
DOMAIN, DOMAIN,
@ -357,7 +362,8 @@ async def test_set_target_humidity(hass: HomeAssistant, setup_comp_2) -> None:
assert state.attributes.get("humidity") == 40 assert state.attributes.get("humidity") == 40
async def test_set_away_mode(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_set_away_mode(hass: HomeAssistant) -> None:
"""Test the setting away mode.""" """Test the setting away mode."""
await hass.services.async_call( await hass.services.async_call(
DOMAIN, DOMAIN,
@ -377,9 +383,8 @@ async def test_set_away_mode(hass: HomeAssistant, setup_comp_2) -> None:
assert state.attributes.get("humidity") == 35 assert state.attributes.get("humidity") == 35
async def test_set_away_mode_and_restore_prev_humidity( @pytest.mark.usefixtures("setup_comp_2")
hass: HomeAssistant, setup_comp_2 async def test_set_away_mode_and_restore_prev_humidity(hass: HomeAssistant) -> None:
) -> None:
"""Test the setting and removing away mode. """Test the setting and removing away mode.
Verify original humidity is restored. Verify original humidity is restored.
@ -411,8 +416,9 @@ async def test_set_away_mode_and_restore_prev_humidity(
assert state.attributes.get("humidity") == 44 assert state.attributes.get("humidity") == 44
@pytest.mark.usefixtures("setup_comp_2")
async def test_set_away_mode_twice_and_restore_prev_humidity( async def test_set_away_mode_twice_and_restore_prev_humidity(
hass: HomeAssistant, setup_comp_2 hass: HomeAssistant,
) -> None: ) -> None:
"""Test the setting away mode twice in a row. """Test the setting away mode twice in a row.
@ -452,7 +458,8 @@ async def test_set_away_mode_twice_and_restore_prev_humidity(
assert state.attributes.get("humidity") == 44 assert state.attributes.get("humidity") == 44
async def test_sensor_affects_attribute(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_sensor_affects_attribute(hass: HomeAssistant) -> None:
"""Test that the sensor changes are reflected in the current_humidity attribute.""" """Test that the sensor changes are reflected in the current_humidity attribute."""
state = hass.states.get(ENTITY) state = hass.states.get(ENTITY)
assert state.attributes.get("current_humidity") == 45 assert state.attributes.get("current_humidity") == 45
@ -464,7 +471,8 @@ async def test_sensor_affects_attribute(hass: HomeAssistant, setup_comp_2) -> No
assert state.attributes.get("current_humidity") == 47 assert state.attributes.get("current_humidity") == 47
async def test_sensor_bad_value(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_sensor_bad_value(hass: HomeAssistant) -> None:
"""Test sensor that have None as state.""" """Test sensor that have None as state."""
assert hass.states.get(ENTITY).state == STATE_ON assert hass.states.get(ENTITY).state == STATE_ON
@ -474,8 +482,9 @@ async def test_sensor_bad_value(hass: HomeAssistant, setup_comp_2) -> None:
assert hass.states.get(ENTITY).state == STATE_UNAVAILABLE assert hass.states.get(ENTITY).state == STATE_UNAVAILABLE
@pytest.mark.usefixtures("setup_comp_2")
async def test_sensor_bad_value_twice( async def test_sensor_bad_value_twice(
hass: HomeAssistant, setup_comp_2, caplog: pytest.LogCaptureFixture hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None: ) -> None:
"""Test sensor that the second bad value is not logged as warning.""" """Test sensor that the second bad value is not logged as warning."""
assert hass.states.get(ENTITY).state == STATE_ON assert hass.states.get(ENTITY).state == STATE_ON
@ -503,9 +512,8 @@ async def test_sensor_bad_value_twice(
] == ["DEBUG"] ] == ["DEBUG"]
async def test_set_target_humidity_humidifier_on( @pytest.mark.usefixtures("setup_comp_2")
hass: HomeAssistant, setup_comp_2 async def test_set_target_humidity_humidifier_on(hass: HomeAssistant) -> None:
) -> None:
"""Test if target humidity turn humidifier on.""" """Test if target humidity turn humidifier on."""
calls = await _setup_switch(hass, False) calls = await _setup_switch(hass, False)
_setup_sensor(hass, 36) _setup_sensor(hass, 36)
@ -524,9 +532,8 @@ async def test_set_target_humidity_humidifier_on(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_set_target_humidity_humidifier_off( @pytest.mark.usefixtures("setup_comp_2")
hass: HomeAssistant, setup_comp_2 async def test_set_target_humidity_humidifier_off(hass: HomeAssistant) -> None:
) -> None:
"""Test if target humidity turn humidifier off.""" """Test if target humidity turn humidifier off."""
calls = await _setup_switch(hass, True) calls = await _setup_switch(hass, True)
_setup_sensor(hass, 45) _setup_sensor(hass, 45)
@ -545,8 +552,9 @@ async def test_set_target_humidity_humidifier_off(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
@pytest.mark.usefixtures("setup_comp_2")
async def test_humidity_change_humidifier_on_within_tolerance( async def test_humidity_change_humidifier_on_within_tolerance(
hass: HomeAssistant, setup_comp_2 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if humidity change doesn't turn on within tolerance.""" """Test if humidity change doesn't turn on within tolerance."""
calls = await _setup_switch(hass, False) calls = await _setup_switch(hass, False)
@ -562,8 +570,9 @@ async def test_humidity_change_humidifier_on_within_tolerance(
assert len(calls) == 0 assert len(calls) == 0
@pytest.mark.usefixtures("setup_comp_2")
async def test_humidity_change_humidifier_on_outside_tolerance( async def test_humidity_change_humidifier_on_outside_tolerance(
hass: HomeAssistant, setup_comp_2 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if humidity change turn humidifier on outside dry tolerance.""" """Test if humidity change turn humidifier on outside dry tolerance."""
calls = await _setup_switch(hass, False) calls = await _setup_switch(hass, False)
@ -583,8 +592,9 @@ async def test_humidity_change_humidifier_on_outside_tolerance(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
@pytest.mark.usefixtures("setup_comp_2")
async def test_humidity_change_humidifier_off_within_tolerance( async def test_humidity_change_humidifier_off_within_tolerance(
hass: HomeAssistant, setup_comp_2 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if humidity change doesn't turn off within tolerance.""" """Test if humidity change doesn't turn off within tolerance."""
calls = await _setup_switch(hass, True) calls = await _setup_switch(hass, True)
@ -600,8 +610,9 @@ async def test_humidity_change_humidifier_off_within_tolerance(
assert len(calls) == 0 assert len(calls) == 0
@pytest.mark.usefixtures("setup_comp_2")
async def test_humidity_change_humidifier_off_outside_tolerance( async def test_humidity_change_humidifier_off_outside_tolerance(
hass: HomeAssistant, setup_comp_2 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if humidity change turn humidifier off outside wet tolerance.""" """Test if humidity change turn humidifier off outside wet tolerance."""
calls = await _setup_switch(hass, True) calls = await _setup_switch(hass, True)
@ -621,7 +632,8 @@ async def test_humidity_change_humidifier_off_outside_tolerance(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_operation_mode_humidify(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_operation_mode_humidify(hass: HomeAssistant) -> None:
"""Test change mode from OFF to HUMIDIFY. """Test change mode from OFF to HUMIDIFY.
Switch turns on when humidity below setpoint and mode changes. Switch turns on when humidity below setpoint and mode changes.
@ -675,7 +687,7 @@ async def _setup_switch(hass, is_on):
@pytest.fixture @pytest.fixture
async def setup_comp_3(hass): async def setup_comp_3(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
assert await async_setup_component( assert await async_setup_component(
hass, hass,
@ -698,7 +710,8 @@ async def setup_comp_3(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_set_target_humidity_dry_off(hass: HomeAssistant, setup_comp_3) -> None: @pytest.mark.usefixtures("setup_comp_3")
async def test_set_target_humidity_dry_off(hass: HomeAssistant) -> None:
"""Test if target humidity turn dry off.""" """Test if target humidity turn dry off."""
calls = await _setup_switch(hass, True) calls = await _setup_switch(hass, True)
_setup_sensor(hass, 50) _setup_sensor(hass, 50)
@ -718,7 +731,8 @@ async def test_set_target_humidity_dry_off(hass: HomeAssistant, setup_comp_3) ->
assert hass.states.get(ENTITY).attributes.get("action") == "drying" assert hass.states.get(ENTITY).attributes.get("action") == "drying"
async def test_turn_away_mode_on_drying(hass: HomeAssistant, setup_comp_3) -> None: @pytest.mark.usefixtures("setup_comp_3")
async def test_turn_away_mode_on_drying(hass: HomeAssistant) -> None:
"""Test the setting away mode when drying.""" """Test the setting away mode when drying."""
await _setup_switch(hass, True) await _setup_switch(hass, True)
_setup_sensor(hass, 50) _setup_sensor(hass, 50)
@ -741,7 +755,8 @@ async def test_turn_away_mode_on_drying(hass: HomeAssistant, setup_comp_3) -> No
assert state.attributes.get("humidity") == 30 assert state.attributes.get("humidity") == 30
async def test_operation_mode_dry(hass: HomeAssistant, setup_comp_3) -> None: @pytest.mark.usefixtures("setup_comp_3")
async def test_operation_mode_dry(hass: HomeAssistant) -> None:
"""Test change mode from OFF to DRY. """Test change mode from OFF to DRY.
Switch turns on when humidity below setpoint and state changes. Switch turns on when humidity below setpoint and state changes.
@ -774,7 +789,8 @@ async def test_operation_mode_dry(hass: HomeAssistant, setup_comp_3) -> None:
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_set_target_humidity_dry_on(hass: HomeAssistant, setup_comp_3) -> None: @pytest.mark.usefixtures("setup_comp_3")
async def test_set_target_humidity_dry_on(hass: HomeAssistant) -> None:
"""Test if target humidity turn dry on.""" """Test if target humidity turn dry on."""
calls = await _setup_switch(hass, False) calls = await _setup_switch(hass, False)
_setup_sensor(hass, 45) _setup_sensor(hass, 45)
@ -786,7 +802,8 @@ async def test_set_target_humidity_dry_on(hass: HomeAssistant, setup_comp_3) ->
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_init_ignores_tolerance(hass: HomeAssistant, setup_comp_3) -> None: @pytest.mark.usefixtures("setup_comp_3")
async def test_init_ignores_tolerance(hass: HomeAssistant) -> None:
"""Test if tolerance is ignored on initialization.""" """Test if tolerance is ignored on initialization."""
calls = await _setup_switch(hass, True) calls = await _setup_switch(hass, True)
_setup_sensor(hass, 39) _setup_sensor(hass, 39)
@ -798,9 +815,8 @@ async def test_init_ignores_tolerance(hass: HomeAssistant, setup_comp_3) -> None
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_humidity_change_dry_off_within_tolerance( @pytest.mark.usefixtures("setup_comp_3")
hass: HomeAssistant, setup_comp_3 async def test_humidity_change_dry_off_within_tolerance(hass: HomeAssistant) -> None:
) -> None:
"""Test if humidity change doesn't turn dry off within tolerance.""" """Test if humidity change doesn't turn dry off within tolerance."""
calls = await _setup_switch(hass, True) calls = await _setup_switch(hass, True)
_setup_sensor(hass, 45) _setup_sensor(hass, 45)
@ -809,8 +825,9 @@ async def test_humidity_change_dry_off_within_tolerance(
assert len(calls) == 0 assert len(calls) == 0
@pytest.mark.usefixtures("setup_comp_3")
async def test_set_humidity_change_dry_off_outside_tolerance( async def test_set_humidity_change_dry_off_outside_tolerance(
hass: HomeAssistant, setup_comp_3 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if humidity change turn dry off.""" """Test if humidity change turn dry off."""
calls = await _setup_switch(hass, True) calls = await _setup_switch(hass, True)
@ -823,9 +840,8 @@ async def test_set_humidity_change_dry_off_outside_tolerance(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_humidity_change_dry_on_within_tolerance( @pytest.mark.usefixtures("setup_comp_3")
hass: HomeAssistant, setup_comp_3 async def test_humidity_change_dry_on_within_tolerance(hass: HomeAssistant) -> None:
) -> None:
"""Test if humidity change doesn't turn dry on within tolerance.""" """Test if humidity change doesn't turn dry on within tolerance."""
calls = await _setup_switch(hass, False) calls = await _setup_switch(hass, False)
_setup_sensor(hass, 37) _setup_sensor(hass, 37)
@ -834,9 +850,8 @@ async def test_humidity_change_dry_on_within_tolerance(
assert len(calls) == 0 assert len(calls) == 0
async def test_humidity_change_dry_on_outside_tolerance( @pytest.mark.usefixtures("setup_comp_3")
hass: HomeAssistant, setup_comp_3 async def test_humidity_change_dry_on_outside_tolerance(hass: HomeAssistant) -> None:
) -> None:
"""Test if humidity change turn dry on.""" """Test if humidity change turn dry on."""
calls = await _setup_switch(hass, False) calls = await _setup_switch(hass, False)
_setup_sensor(hass, 45) _setup_sensor(hass, 45)
@ -848,9 +863,8 @@ async def test_humidity_change_dry_on_outside_tolerance(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_running_when_operating_mode_is_off_2( @pytest.mark.usefixtures("setup_comp_3")
hass: HomeAssistant, setup_comp_3 async def test_running_when_operating_mode_is_off_2(hass: HomeAssistant) -> None:
) -> None:
"""Test that the switch turns off when enabled is set False.""" """Test that the switch turns off when enabled is set False."""
calls = await _setup_switch(hass, True) calls = await _setup_switch(hass, True)
_setup_sensor(hass, 45) _setup_sensor(hass, 45)
@ -870,9 +884,8 @@ async def test_running_when_operating_mode_is_off_2(
assert hass.states.get(ENTITY).attributes.get("action") == "off" assert hass.states.get(ENTITY).attributes.get("action") == "off"
async def test_no_state_change_when_operation_mode_off_2( @pytest.mark.usefixtures("setup_comp_3")
hass: HomeAssistant, setup_comp_3 async def test_no_state_change_when_operation_mode_off_2(hass: HomeAssistant) -> None:
) -> None:
"""Test that the switch doesn't turn on when enabled is False.""" """Test that the switch doesn't turn on when enabled is False."""
calls = await _setup_switch(hass, False) calls = await _setup_switch(hass, False)
_setup_sensor(hass, 30) _setup_sensor(hass, 30)
@ -891,7 +904,7 @@ async def test_no_state_change_when_operation_mode_off_2(
@pytest.fixture @pytest.fixture
async def setup_comp_4(hass): async def setup_comp_4(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
assert await async_setup_component( assert await async_setup_component(
hass, hass,
@ -914,8 +927,9 @@ async def setup_comp_4(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
@pytest.mark.usefixtures("setup_comp_4")
async def test_humidity_change_dry_trigger_on_not_long_enough( async def test_humidity_change_dry_trigger_on_not_long_enough(
hass: HomeAssistant, setup_comp_4 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if humidity change turn dry on.""" """Test if humidity change turn dry on."""
calls = await _setup_switch(hass, False) calls = await _setup_switch(hass, False)
@ -928,9 +942,8 @@ async def test_humidity_change_dry_trigger_on_not_long_enough(
assert len(calls) == 0 assert len(calls) == 0
async def test_humidity_change_dry_trigger_on_long_enough( @pytest.mark.usefixtures("setup_comp_4")
hass: HomeAssistant, setup_comp_4 async def test_humidity_change_dry_trigger_on_long_enough(hass: HomeAssistant) -> None:
) -> None:
"""Test if humidity change turn dry on.""" """Test if humidity change turn dry on."""
fake_changed = datetime.datetime(1970, 11, 11, 11, 11, 11, tzinfo=datetime.UTC) fake_changed = datetime.datetime(1970, 11, 11, 11, 11, 11, tzinfo=datetime.UTC)
with freeze_time(fake_changed): with freeze_time(fake_changed):
@ -948,8 +961,9 @@ async def test_humidity_change_dry_trigger_on_long_enough(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
@pytest.mark.usefixtures("setup_comp_4")
async def test_humidity_change_dry_trigger_off_not_long_enough( async def test_humidity_change_dry_trigger_off_not_long_enough(
hass: HomeAssistant, setup_comp_4 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if humidity change turn dry on.""" """Test if humidity change turn dry on."""
calls = await _setup_switch(hass, True) calls = await _setup_switch(hass, True)
@ -962,9 +976,8 @@ async def test_humidity_change_dry_trigger_off_not_long_enough(
assert len(calls) == 0 assert len(calls) == 0
async def test_humidity_change_dry_trigger_off_long_enough( @pytest.mark.usefixtures("setup_comp_4")
hass: HomeAssistant, setup_comp_4 async def test_humidity_change_dry_trigger_off_long_enough(hass: HomeAssistant) -> None:
) -> None:
"""Test if humidity change turn dry on.""" """Test if humidity change turn dry on."""
fake_changed = datetime.datetime(1970, 11, 11, 11, 11, 11, tzinfo=datetime.UTC) fake_changed = datetime.datetime(1970, 11, 11, 11, 11, 11, tzinfo=datetime.UTC)
with freeze_time(fake_changed): with freeze_time(fake_changed):
@ -982,9 +995,8 @@ async def test_humidity_change_dry_trigger_off_long_enough(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_mode_change_dry_trigger_off_not_long_enough( @pytest.mark.usefixtures("setup_comp_4")
hass: HomeAssistant, setup_comp_4 async def test_mode_change_dry_trigger_off_not_long_enough(hass: HomeAssistant) -> None:
) -> None:
"""Test if mode change turns dry off despite minimum cycle.""" """Test if mode change turns dry off despite minimum cycle."""
calls = await _setup_switch(hass, True) calls = await _setup_switch(hass, True)
_setup_sensor(hass, 45) _setup_sensor(hass, 45)
@ -1004,9 +1016,8 @@ async def test_mode_change_dry_trigger_off_not_long_enough(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_mode_change_dry_trigger_on_not_long_enough( @pytest.mark.usefixtures("setup_comp_4")
hass: HomeAssistant, setup_comp_4 async def test_mode_change_dry_trigger_on_not_long_enough(hass: HomeAssistant) -> None:
) -> None:
"""Test if mode change turns dry on despite minimum cycle.""" """Test if mode change turns dry on despite minimum cycle."""
calls = await _setup_switch(hass, False) calls = await _setup_switch(hass, False)
_setup_sensor(hass, 35) _setup_sensor(hass, 35)
@ -1036,7 +1047,7 @@ async def test_mode_change_dry_trigger_on_not_long_enough(
@pytest.fixture @pytest.fixture
async def setup_comp_6(hass): async def setup_comp_6(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
assert await async_setup_component( assert await async_setup_component(
hass, hass,
@ -1058,8 +1069,9 @@ async def setup_comp_6(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
@pytest.mark.usefixtures("setup_comp_6")
async def test_humidity_change_humidifier_trigger_off_not_long_enough( async def test_humidity_change_humidifier_trigger_off_not_long_enough(
hass: HomeAssistant, setup_comp_6 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if humidity change doesn't turn humidifier off because of time.""" """Test if humidity change doesn't turn humidifier off because of time."""
calls = await _setup_switch(hass, True) calls = await _setup_switch(hass, True)
@ -1072,8 +1084,9 @@ async def test_humidity_change_humidifier_trigger_off_not_long_enough(
assert len(calls) == 0 assert len(calls) == 0
@pytest.mark.usefixtures("setup_comp_6")
async def test_humidity_change_humidifier_trigger_on_not_long_enough( async def test_humidity_change_humidifier_trigger_on_not_long_enough(
hass: HomeAssistant, setup_comp_6 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if humidity change doesn't turn humidifier on because of time.""" """Test if humidity change doesn't turn humidifier on because of time."""
calls = await _setup_switch(hass, False) calls = await _setup_switch(hass, False)
@ -1086,8 +1099,9 @@ async def test_humidity_change_humidifier_trigger_on_not_long_enough(
assert len(calls) == 0 assert len(calls) == 0
@pytest.mark.usefixtures("setup_comp_6")
async def test_humidity_change_humidifier_trigger_on_long_enough( async def test_humidity_change_humidifier_trigger_on_long_enough(
hass: HomeAssistant, setup_comp_6 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if humidity change turn humidifier on after min cycle.""" """Test if humidity change turn humidifier on after min cycle."""
fake_changed = datetime.datetime(1970, 11, 11, 11, 11, 11, tzinfo=datetime.UTC) fake_changed = datetime.datetime(1970, 11, 11, 11, 11, 11, tzinfo=datetime.UTC)
@ -1106,8 +1120,9 @@ async def test_humidity_change_humidifier_trigger_on_long_enough(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
@pytest.mark.usefixtures("setup_comp_6")
async def test_humidity_change_humidifier_trigger_off_long_enough( async def test_humidity_change_humidifier_trigger_off_long_enough(
hass: HomeAssistant, setup_comp_6 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if humidity change turn humidifier off after min cycle.""" """Test if humidity change turn humidifier off after min cycle."""
fake_changed = datetime.datetime(1970, 11, 11, 11, 11, 11, tzinfo=datetime.UTC) fake_changed = datetime.datetime(1970, 11, 11, 11, 11, 11, tzinfo=datetime.UTC)
@ -1126,8 +1141,9 @@ async def test_humidity_change_humidifier_trigger_off_long_enough(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
@pytest.mark.usefixtures("setup_comp_6")
async def test_mode_change_humidifier_trigger_off_not_long_enough( async def test_mode_change_humidifier_trigger_off_not_long_enough(
hass: HomeAssistant, setup_comp_6 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if mode change turns humidifier off despite minimum cycle.""" """Test if mode change turns humidifier off despite minimum cycle."""
calls = await _setup_switch(hass, True) calls = await _setup_switch(hass, True)
@ -1149,8 +1165,9 @@ async def test_mode_change_humidifier_trigger_off_not_long_enough(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
@pytest.mark.usefixtures("setup_comp_6")
async def test_mode_change_humidifier_trigger_on_not_long_enough( async def test_mode_change_humidifier_trigger_on_not_long_enough(
hass: HomeAssistant, setup_comp_6 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if mode change turns humidifier on despite minimum cycle.""" """Test if mode change turns humidifier on despite minimum cycle."""
calls = await _setup_switch(hass, False) calls = await _setup_switch(hass, False)
@ -1186,7 +1203,7 @@ async def test_mode_change_humidifier_trigger_on_not_long_enough(
@pytest.fixture @pytest.fixture
async def setup_comp_7(hass): async def setup_comp_7(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
assert await async_setup_component( assert await async_setup_component(
hass, hass,
@ -1210,8 +1227,9 @@ async def setup_comp_7(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
@pytest.mark.usefixtures("setup_comp_7")
async def test_humidity_change_dry_trigger_on_long_enough_3( async def test_humidity_change_dry_trigger_on_long_enough_3(
hass: HomeAssistant, setup_comp_7 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if turn on signal is sent at keep-alive intervals.""" """Test if turn on signal is sent at keep-alive intervals."""
calls = await _setup_switch(hass, True) calls = await _setup_switch(hass, True)
@ -1230,8 +1248,9 @@ async def test_humidity_change_dry_trigger_on_long_enough_3(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
@pytest.mark.usefixtures("setup_comp_7")
async def test_humidity_change_dry_trigger_off_long_enough_3( async def test_humidity_change_dry_trigger_off_long_enough_3(
hass: HomeAssistant, setup_comp_7 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if turn on signal is sent at keep-alive intervals.""" """Test if turn on signal is sent at keep-alive intervals."""
calls = await _setup_switch(hass, False) calls = await _setup_switch(hass, False)
@ -1251,7 +1270,7 @@ async def test_humidity_change_dry_trigger_off_long_enough_3(
@pytest.fixture @pytest.fixture
async def setup_comp_8(hass): async def setup_comp_8(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
assert await async_setup_component( assert await async_setup_component(
hass, hass,
@ -1274,8 +1293,9 @@ async def setup_comp_8(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
@pytest.mark.usefixtures("setup_comp_8")
async def test_humidity_change_humidifier_trigger_on_long_enough_2( async def test_humidity_change_humidifier_trigger_on_long_enough_2(
hass: HomeAssistant, setup_comp_8 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if turn on signal is sent at keep-alive intervals.""" """Test if turn on signal is sent at keep-alive intervals."""
calls = await _setup_switch(hass, True) calls = await _setup_switch(hass, True)
@ -1294,8 +1314,9 @@ async def test_humidity_change_humidifier_trigger_on_long_enough_2(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
@pytest.mark.usefixtures("setup_comp_8")
async def test_humidity_change_humidifier_trigger_off_long_enough_2( async def test_humidity_change_humidifier_trigger_off_long_enough_2(
hass: HomeAssistant, setup_comp_8 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if turn on signal is sent at keep-alive intervals.""" """Test if turn on signal is sent at keep-alive intervals."""
calls = await _setup_switch(hass, False) calls = await _setup_switch(hass, False)
@ -1706,8 +1727,9 @@ async def test_away_fixed_humidity_mode(hass: HomeAssistant) -> None:
assert state.state == STATE_OFF assert state.state == STATE_OFF
@pytest.mark.usefixtures("setup_comp_1")
async def test_sensor_stale_duration( async def test_sensor_stale_duration(
hass: HomeAssistant, setup_comp_1, caplog: pytest.LogCaptureFixture hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None: ) -> None:
"""Test turn off on sensor stale.""" """Test turn off on sensor stale."""

View File

@ -103,14 +103,15 @@ async def test_valid_conf(hass: HomeAssistant) -> None:
@pytest.fixture @pytest.fixture
async def setup_comp_1(hass): async def setup_comp_1(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
hass.config.units = METRIC_SYSTEM hass.config.units = METRIC_SYSTEM
assert await async_setup_component(hass, "homeassistant", {}) assert await async_setup_component(hass, "homeassistant", {})
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_heater_input_boolean(hass: HomeAssistant, setup_comp_1) -> None: @pytest.mark.usefixtures("setup_comp_1")
async def test_heater_input_boolean(hass: HomeAssistant) -> None:
"""Test heater switching input_boolean.""" """Test heater switching input_boolean."""
heater_switch = "input_boolean.test" heater_switch = "input_boolean.test"
assert await async_setup_component( assert await async_setup_component(
@ -142,8 +143,9 @@ async def test_heater_input_boolean(hass: HomeAssistant, setup_comp_1) -> None:
assert hass.states.get(heater_switch).state == STATE_ON assert hass.states.get(heater_switch).state == STATE_ON
@pytest.mark.usefixtures("setup_comp_1")
async def test_heater_switch( async def test_heater_switch(
hass: HomeAssistant, setup_comp_1, mock_switch_entities: list[MockSwitch] hass: HomeAssistant, mock_switch_entities: list[MockSwitch]
) -> None: ) -> None:
"""Test heater switching test switch.""" """Test heater switching test switch."""
setup_test_component_platform(hass, switch.DOMAIN, mock_switch_entities) setup_test_component_platform(hass, switch.DOMAIN, mock_switch_entities)
@ -178,8 +180,9 @@ async def test_heater_switch(
assert hass.states.get(heater_switch).state == STATE_ON assert hass.states.get(heater_switch).state == STATE_ON
@pytest.mark.usefixtures("setup_comp_1")
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, entity_registry: er.EntityRegistry, setup_comp_1 hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None: ) -> None:
"""Test setting a unique ID.""" """Test setting a unique ID."""
unique_id = "some_unique_id" unique_id = "some_unique_id"
@ -211,7 +214,7 @@ def _setup_sensor(hass, temp):
@pytest.fixture @pytest.fixture
async def setup_comp_2(hass): async def setup_comp_2(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
hass.config.units = METRIC_SYSTEM hass.config.units = METRIC_SYSTEM
assert await async_setup_component( assert await async_setup_component(
@ -284,7 +287,8 @@ async def test_setup_gets_current_temp_from_sensor(hass: HomeAssistant) -> None:
assert hass.states.get(ENTITY).attributes["current_temperature"] == 18 assert hass.states.get(ENTITY).attributes["current_temperature"] == 18
async def test_default_setup_params(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_default_setup_params(hass: HomeAssistant) -> None:
"""Test the setup with default parameters.""" """Test the setup with default parameters."""
state = hass.states.get(ENTITY) state = hass.states.get(ENTITY)
assert state.attributes.get("min_temp") == 7 assert state.attributes.get("min_temp") == 7
@ -293,14 +297,16 @@ async def test_default_setup_params(hass: HomeAssistant, setup_comp_2) -> None:
assert state.attributes.get("target_temp_step") == 0.1 assert state.attributes.get("target_temp_step") == 0.1
async def test_get_hvac_modes(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_get_hvac_modes(hass: HomeAssistant) -> None:
"""Test that the operation list returns the correct modes.""" """Test that the operation list returns the correct modes."""
state = hass.states.get(ENTITY) state = hass.states.get(ENTITY)
modes = state.attributes.get("hvac_modes") modes = state.attributes.get("hvac_modes")
assert modes == [HVACMode.HEAT, HVACMode.OFF] assert modes == [HVACMode.HEAT, HVACMode.OFF]
async def test_set_target_temp(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_set_target_temp(hass: HomeAssistant) -> None:
"""Test the setting of the target temperature.""" """Test the setting of the target temperature."""
await common.async_set_temperature(hass, 30) await common.async_set_temperature(hass, 30)
state = hass.states.get(ENTITY) state = hass.states.get(ENTITY)
@ -323,7 +329,8 @@ async def test_set_target_temp(hass: HomeAssistant, setup_comp_2) -> None:
(PRESET_ACTIVITY, 21), (PRESET_ACTIVITY, 21),
], ],
) )
async def test_set_away_mode(hass: HomeAssistant, setup_comp_2, preset, temp) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_set_away_mode(hass: HomeAssistant, preset, temp) -> None:
"""Test the setting away mode.""" """Test the setting away mode."""
await common.async_set_temperature(hass, 23) await common.async_set_temperature(hass, 23)
await common.async_set_preset_mode(hass, preset) await common.async_set_preset_mode(hass, preset)
@ -343,8 +350,9 @@ async def test_set_away_mode(hass: HomeAssistant, setup_comp_2, preset, temp) ->
(PRESET_ACTIVITY, 21), (PRESET_ACTIVITY, 21),
], ],
) )
@pytest.mark.usefixtures("setup_comp_2")
async def test_set_away_mode_and_restore_prev_temp( async def test_set_away_mode_and_restore_prev_temp(
hass: HomeAssistant, setup_comp_2, preset, temp hass: HomeAssistant, preset, temp
) -> None: ) -> None:
"""Test the setting and removing away mode. """Test the setting and removing away mode.
@ -371,8 +379,9 @@ async def test_set_away_mode_and_restore_prev_temp(
(PRESET_ACTIVITY, 21), (PRESET_ACTIVITY, 21),
], ],
) )
@pytest.mark.usefixtures("setup_comp_2")
async def test_set_away_mode_twice_and_restore_prev_temp( async def test_set_away_mode_twice_and_restore_prev_temp(
hass: HomeAssistant, setup_comp_2, preset, temp hass: HomeAssistant, preset, temp
) -> None: ) -> None:
"""Test the setting away mode twice in a row. """Test the setting away mode twice in a row.
@ -388,7 +397,8 @@ async def test_set_away_mode_twice_and_restore_prev_temp(
assert state.attributes.get("temperature") == 23 assert state.attributes.get("temperature") == 23
async def test_set_preset_mode_invalid(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_set_preset_mode_invalid(hass: HomeAssistant) -> None:
"""Test an invalid mode raises an error and ignore case when checking modes.""" """Test an invalid mode raises an error and ignore case when checking modes."""
await common.async_set_temperature(hass, 23) await common.async_set_temperature(hass, 23)
await common.async_set_preset_mode(hass, "away") await common.async_set_preset_mode(hass, "away")
@ -403,7 +413,8 @@ async def test_set_preset_mode_invalid(hass: HomeAssistant, setup_comp_2) -> Non
assert state.attributes.get("preset_mode") == "none" assert state.attributes.get("preset_mode") == "none"
async def test_sensor_bad_value(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_sensor_bad_value(hass: HomeAssistant) -> None:
"""Test sensor that have None as state.""" """Test sensor that have None as state."""
state = hass.states.get(ENTITY) state = hass.states.get(ENTITY)
temp = state.attributes.get("current_temperature") temp = state.attributes.get("current_temperature")
@ -464,7 +475,8 @@ async def test_sensor_unavailable(hass: HomeAssistant) -> None:
assert state.attributes.get("current_temperature") is None assert state.attributes.get("current_temperature") is None
async def test_set_target_temp_heater_on(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_set_target_temp_heater_on(hass: HomeAssistant) -> None:
"""Test if target temperature turn heater on.""" """Test if target temperature turn heater on."""
calls = _setup_switch(hass, False) calls = _setup_switch(hass, False)
_setup_sensor(hass, 25) _setup_sensor(hass, 25)
@ -477,7 +489,8 @@ async def test_set_target_temp_heater_on(hass: HomeAssistant, setup_comp_2) -> N
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_set_target_temp_heater_off(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_set_target_temp_heater_off(hass: HomeAssistant) -> None:
"""Test if target temperature turn heater off.""" """Test if target temperature turn heater off."""
calls = _setup_switch(hass, True) calls = _setup_switch(hass, True)
_setup_sensor(hass, 30) _setup_sensor(hass, 30)
@ -490,9 +503,8 @@ async def test_set_target_temp_heater_off(hass: HomeAssistant, setup_comp_2) ->
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_temp_change_heater_on_within_tolerance( @pytest.mark.usefixtures("setup_comp_2")
hass: HomeAssistant, setup_comp_2 async def test_temp_change_heater_on_within_tolerance(hass: HomeAssistant) -> None:
) -> None:
"""Test if temperature change doesn't turn on within tolerance.""" """Test if temperature change doesn't turn on within tolerance."""
calls = _setup_switch(hass, False) calls = _setup_switch(hass, False)
await common.async_set_temperature(hass, 30) await common.async_set_temperature(hass, 30)
@ -501,9 +513,8 @@ async def test_temp_change_heater_on_within_tolerance(
assert len(calls) == 0 assert len(calls) == 0
async def test_temp_change_heater_on_outside_tolerance( @pytest.mark.usefixtures("setup_comp_2")
hass: HomeAssistant, setup_comp_2 async def test_temp_change_heater_on_outside_tolerance(hass: HomeAssistant) -> None:
) -> None:
"""Test if temperature change turn heater on outside cold tolerance.""" """Test if temperature change turn heater on outside cold tolerance."""
calls = _setup_switch(hass, False) calls = _setup_switch(hass, False)
await common.async_set_temperature(hass, 30) await common.async_set_temperature(hass, 30)
@ -516,9 +527,8 @@ async def test_temp_change_heater_on_outside_tolerance(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_temp_change_heater_off_within_tolerance( @pytest.mark.usefixtures("setup_comp_2")
hass: HomeAssistant, setup_comp_2 async def test_temp_change_heater_off_within_tolerance(hass: HomeAssistant) -> None:
) -> None:
"""Test if temperature change doesn't turn off within tolerance.""" """Test if temperature change doesn't turn off within tolerance."""
calls = _setup_switch(hass, True) calls = _setup_switch(hass, True)
await common.async_set_temperature(hass, 30) await common.async_set_temperature(hass, 30)
@ -527,9 +537,8 @@ async def test_temp_change_heater_off_within_tolerance(
assert len(calls) == 0 assert len(calls) == 0
async def test_temp_change_heater_off_outside_tolerance( @pytest.mark.usefixtures("setup_comp_2")
hass: HomeAssistant, setup_comp_2 async def test_temp_change_heater_off_outside_tolerance(hass: HomeAssistant) -> None:
) -> None:
"""Test if temperature change turn heater off outside hot tolerance.""" """Test if temperature change turn heater off outside hot tolerance."""
calls = _setup_switch(hass, True) calls = _setup_switch(hass, True)
await common.async_set_temperature(hass, 30) await common.async_set_temperature(hass, 30)
@ -542,7 +551,8 @@ async def test_temp_change_heater_off_outside_tolerance(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_running_when_hvac_mode_is_off(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_running_when_hvac_mode_is_off(hass: HomeAssistant) -> None:
"""Test that the switch turns off when enabled is set False.""" """Test that the switch turns off when enabled is set False."""
calls = _setup_switch(hass, True) calls = _setup_switch(hass, True)
await common.async_set_temperature(hass, 30) await common.async_set_temperature(hass, 30)
@ -554,9 +564,8 @@ async def test_running_when_hvac_mode_is_off(hass: HomeAssistant, setup_comp_2)
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_no_state_change_when_hvac_mode_off( @pytest.mark.usefixtures("setup_comp_2")
hass: HomeAssistant, setup_comp_2 async def test_no_state_change_when_hvac_mode_off(hass: HomeAssistant) -> None:
) -> None:
"""Test that the switch doesn't turn on when enabled is False.""" """Test that the switch doesn't turn on when enabled is False."""
calls = _setup_switch(hass, False) calls = _setup_switch(hass, False)
await common.async_set_temperature(hass, 30) await common.async_set_temperature(hass, 30)
@ -566,7 +575,8 @@ async def test_no_state_change_when_hvac_mode_off(
assert len(calls) == 0 assert len(calls) == 0
async def test_hvac_mode_heat(hass: HomeAssistant, setup_comp_2) -> None: @pytest.mark.usefixtures("setup_comp_2")
async def test_hvac_mode_heat(hass: HomeAssistant) -> None:
"""Test change mode from OFF to HEAT. """Test change mode from OFF to HEAT.
Switch turns on when temp below setpoint and mode changes. Switch turns on when temp below setpoint and mode changes.
@ -601,7 +611,7 @@ def _setup_switch(hass, is_on):
@pytest.fixture @pytest.fixture
async def setup_comp_3(hass): async def setup_comp_3(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
hass.config.temperature_unit = UnitOfTemperature.CELSIUS hass.config.temperature_unit = UnitOfTemperature.CELSIUS
assert await async_setup_component( assert await async_setup_component(
@ -624,7 +634,8 @@ async def setup_comp_3(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_set_target_temp_ac_off(hass: HomeAssistant, setup_comp_3) -> None: @pytest.mark.usefixtures("setup_comp_3")
async def test_set_target_temp_ac_off(hass: HomeAssistant) -> None:
"""Test if target temperature turn ac off.""" """Test if target temperature turn ac off."""
calls = _setup_switch(hass, True) calls = _setup_switch(hass, True)
_setup_sensor(hass, 25) _setup_sensor(hass, 25)
@ -637,7 +648,8 @@ async def test_set_target_temp_ac_off(hass: HomeAssistant, setup_comp_3) -> None
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_turn_away_mode_on_cooling(hass: HomeAssistant, setup_comp_3) -> None: @pytest.mark.usefixtures("setup_comp_3")
async def test_turn_away_mode_on_cooling(hass: HomeAssistant) -> None:
"""Test the setting away mode when cooling.""" """Test the setting away mode when cooling."""
_setup_switch(hass, True) _setup_switch(hass, True)
_setup_sensor(hass, 25) _setup_sensor(hass, 25)
@ -648,7 +660,8 @@ async def test_turn_away_mode_on_cooling(hass: HomeAssistant, setup_comp_3) -> N
assert state.attributes.get("temperature") == 30 assert state.attributes.get("temperature") == 30
async def test_hvac_mode_cool(hass: HomeAssistant, setup_comp_3) -> None: @pytest.mark.usefixtures("setup_comp_3")
async def test_hvac_mode_cool(hass: HomeAssistant) -> None:
"""Test change mode from OFF to COOL. """Test change mode from OFF to COOL.
Switch turns on when temp below setpoint and mode changes. Switch turns on when temp below setpoint and mode changes.
@ -666,7 +679,8 @@ async def test_hvac_mode_cool(hass: HomeAssistant, setup_comp_3) -> None:
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_set_target_temp_ac_on(hass: HomeAssistant, setup_comp_3) -> None: @pytest.mark.usefixtures("setup_comp_3")
async def test_set_target_temp_ac_on(hass: HomeAssistant) -> None:
"""Test if target temperature turn ac on.""" """Test if target temperature turn ac on."""
calls = _setup_switch(hass, False) calls = _setup_switch(hass, False)
_setup_sensor(hass, 30) _setup_sensor(hass, 30)
@ -679,9 +693,8 @@ async def test_set_target_temp_ac_on(hass: HomeAssistant, setup_comp_3) -> None:
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_temp_change_ac_off_within_tolerance( @pytest.mark.usefixtures("setup_comp_3")
hass: HomeAssistant, setup_comp_3 async def test_temp_change_ac_off_within_tolerance(hass: HomeAssistant) -> None:
) -> None:
"""Test if temperature change doesn't turn ac off within tolerance.""" """Test if temperature change doesn't turn ac off within tolerance."""
calls = _setup_switch(hass, True) calls = _setup_switch(hass, True)
await common.async_set_temperature(hass, 30) await common.async_set_temperature(hass, 30)
@ -690,9 +703,8 @@ async def test_temp_change_ac_off_within_tolerance(
assert len(calls) == 0 assert len(calls) == 0
async def test_set_temp_change_ac_off_outside_tolerance( @pytest.mark.usefixtures("setup_comp_3")
hass: HomeAssistant, setup_comp_3 async def test_set_temp_change_ac_off_outside_tolerance(hass: HomeAssistant) -> None:
) -> None:
"""Test if temperature change turn ac off.""" """Test if temperature change turn ac off."""
calls = _setup_switch(hass, True) calls = _setup_switch(hass, True)
await common.async_set_temperature(hass, 30) await common.async_set_temperature(hass, 30)
@ -705,9 +717,8 @@ async def test_set_temp_change_ac_off_outside_tolerance(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_temp_change_ac_on_within_tolerance( @pytest.mark.usefixtures("setup_comp_3")
hass: HomeAssistant, setup_comp_3 async def test_temp_change_ac_on_within_tolerance(hass: HomeAssistant) -> None:
) -> None:
"""Test if temperature change doesn't turn ac on within tolerance.""" """Test if temperature change doesn't turn ac on within tolerance."""
calls = _setup_switch(hass, False) calls = _setup_switch(hass, False)
await common.async_set_temperature(hass, 25) await common.async_set_temperature(hass, 25)
@ -716,9 +727,8 @@ async def test_temp_change_ac_on_within_tolerance(
assert len(calls) == 0 assert len(calls) == 0
async def test_temp_change_ac_on_outside_tolerance( @pytest.mark.usefixtures("setup_comp_3")
hass: HomeAssistant, setup_comp_3 async def test_temp_change_ac_on_outside_tolerance(hass: HomeAssistant) -> None:
) -> None:
"""Test if temperature change turn ac on.""" """Test if temperature change turn ac on."""
calls = _setup_switch(hass, False) calls = _setup_switch(hass, False)
await common.async_set_temperature(hass, 25) await common.async_set_temperature(hass, 25)
@ -731,9 +741,8 @@ async def test_temp_change_ac_on_outside_tolerance(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_running_when_operating_mode_is_off_2( @pytest.mark.usefixtures("setup_comp_3")
hass: HomeAssistant, setup_comp_3 async def test_running_when_operating_mode_is_off_2(hass: HomeAssistant) -> None:
) -> None:
"""Test that the switch turns off when enabled is set False.""" """Test that the switch turns off when enabled is set False."""
calls = _setup_switch(hass, True) calls = _setup_switch(hass, True)
await common.async_set_temperature(hass, 30) await common.async_set_temperature(hass, 30)
@ -745,9 +754,8 @@ async def test_running_when_operating_mode_is_off_2(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_no_state_change_when_operation_mode_off_2( @pytest.mark.usefixtures("setup_comp_3")
hass: HomeAssistant, setup_comp_3 async def test_no_state_change_when_operation_mode_off_2(hass: HomeAssistant) -> None:
) -> None:
"""Test that the switch doesn't turn on when enabled is False.""" """Test that the switch doesn't turn on when enabled is False."""
calls = _setup_switch(hass, False) calls = _setup_switch(hass, False)
await common.async_set_temperature(hass, 30) await common.async_set_temperature(hass, 30)
@ -912,7 +920,7 @@ async def test_hvac_mode_change_toggles_heating_cooling_switch_even_when_within_
@pytest.fixture @pytest.fixture
async def setup_comp_7(hass): async def setup_comp_7(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
hass.config.temperature_unit = UnitOfTemperature.CELSIUS hass.config.temperature_unit = UnitOfTemperature.CELSIUS
assert await async_setup_component( assert await async_setup_component(
@ -938,9 +946,8 @@ async def setup_comp_7(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_temp_change_ac_trigger_on_long_enough_3( @pytest.mark.usefixtures("setup_comp_7")
hass: HomeAssistant, setup_comp_7 async def test_temp_change_ac_trigger_on_long_enough_3(hass: HomeAssistant) -> None:
) -> None:
"""Test if turn on signal is sent at keep-alive intervals.""" """Test if turn on signal is sent at keep-alive intervals."""
calls = _setup_switch(hass, True) calls = _setup_switch(hass, True)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -963,9 +970,8 @@ async def test_temp_change_ac_trigger_on_long_enough_3(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
async def test_temp_change_ac_trigger_off_long_enough_3( @pytest.mark.usefixtures("setup_comp_7")
hass: HomeAssistant, setup_comp_7 async def test_temp_change_ac_trigger_off_long_enough_3(hass: HomeAssistant) -> None:
) -> None:
"""Test if turn on signal is sent at keep-alive intervals.""" """Test if turn on signal is sent at keep-alive intervals."""
calls = _setup_switch(hass, False) calls = _setup_switch(hass, False)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -989,7 +995,7 @@ async def test_temp_change_ac_trigger_off_long_enough_3(
@pytest.fixture @pytest.fixture
async def setup_comp_8(hass): async def setup_comp_8(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
hass.config.temperature_unit = UnitOfTemperature.CELSIUS hass.config.temperature_unit = UnitOfTemperature.CELSIUS
assert await async_setup_component( assert await async_setup_component(
@ -1013,9 +1019,8 @@ async def setup_comp_8(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_temp_change_heater_trigger_on_long_enough_2( @pytest.mark.usefixtures("setup_comp_8")
hass: HomeAssistant, setup_comp_8 async def test_temp_change_heater_trigger_on_long_enough_2(hass: HomeAssistant) -> None:
) -> None:
"""Test if turn on signal is sent at keep-alive intervals.""" """Test if turn on signal is sent at keep-alive intervals."""
calls = _setup_switch(hass, True) calls = _setup_switch(hass, True)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -1038,8 +1043,9 @@ async def test_temp_change_heater_trigger_on_long_enough_2(
assert call.data["entity_id"] == ENT_SWITCH assert call.data["entity_id"] == ENT_SWITCH
@pytest.mark.usefixtures("setup_comp_8")
async def test_temp_change_heater_trigger_off_long_enough_2( async def test_temp_change_heater_trigger_off_long_enough_2(
hass: HomeAssistant, setup_comp_8 hass: HomeAssistant,
) -> None: ) -> None:
"""Test if turn on signal is sent at keep-alive intervals.""" """Test if turn on signal is sent at keep-alive intervals."""
calls = _setup_switch(hass, False) calls = _setup_switch(hass, False)
@ -1064,7 +1070,7 @@ async def test_temp_change_heater_trigger_off_long_enough_2(
@pytest.fixture @pytest.fixture
async def setup_comp_9(hass): async def setup_comp_9(hass: HomeAssistant) -> None:
"""Initialize components.""" """Initialize components."""
assert await async_setup_component( assert await async_setup_component(
hass, hass,
@ -1087,7 +1093,8 @@ async def setup_comp_9(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_precision(hass: HomeAssistant, setup_comp_9) -> None: @pytest.mark.usefixtures("setup_comp_9")
async def test_precision(hass: HomeAssistant) -> None:
"""Test that setting precision to tenths works as intended.""" """Test that setting precision to tenths works as intended."""
hass.config.units = US_CUSTOMARY_SYSTEM hass.config.units = US_CUSTOMARY_SYSTEM
await common.async_set_temperature(hass, 23.27) await common.async_set_temperature(hass, 23.27)