Migration to 2023.4 and fix lingering tasks and timers tests errors

This commit is contained in:
Jean-Marc Collin
2023-04-22 09:24:57 +02:00
parent 429ff47269
commit 4dd7c62a42
13 changed files with 99 additions and 4 deletions

View File

@@ -601,7 +601,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
) )
) )
self.async_on_remove(self.async_remove_thermostat) self.async_on_remove(self.remove_thermostat)
try: try:
await self.async_startup() await self.async_startup()
@@ -609,11 +609,11 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
# Ingore this error which is possible if underlying climate is not found temporary # Ingore this error which is possible if underlying climate is not found temporary
pass pass
def async_remove_thermostat(self): async def remove_thermostat(self):
"""Called when the thermostat will be removed""" """Called when the thermostat will be removed"""
_LOGGER.info("%s - Removing thermostat", self) _LOGGER.info("%s - Removing thermostat", self)
for under in self._underlyings: for under in self._underlyings:
under.remove_entity() await under.remove_entity()
async def async_startup(self): async def async_startup(self):
"""Triggered on startup, used to get old state and set internal states accordingly""" """Triggered on startup, used to get old state and set internal states accordingly"""
@@ -1521,7 +1521,9 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
) )
# We do not change the preset which is kept to ACTIVITY but only the target_temperature # We do not change the preset which is kept to ACTIVITY but only the target_temperature
# We take the presence into account # We take the presence into account
await self._async_internal_set_temperature(self.find_preset_temp(new_preset)) await self._async_internal_set_temperature(
self.find_preset_temp(new_preset)
)
self.recalculate() self.recalculate()
await self._async_control_heating(force=True) await self._async_control_heating(force=True)

View File

@@ -2,6 +2,7 @@
import asyncio import asyncio
import logging import logging
from unittest.mock import patch, MagicMock from unittest.mock import patch, MagicMock
import pytest
from homeassistant.core import HomeAssistant, Event, EVENT_STATE_CHANGED, State from homeassistant.core import HomeAssistant, Event, EVENT_STATE_CHANGED, State
from homeassistant.const import UnitOfTemperature, STATE_ON, STATE_OFF from homeassistant.const import UnitOfTemperature, STATE_ON, STATE_OFF

View File

@@ -9,6 +9,7 @@ from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from pytest_homeassistant_custom_component.common import MockConfigEntry from pytest_homeassistant_custom_component.common import MockConfigEntry
from .commons import *
from ..climate import VersatileThermostat from ..climate import VersatileThermostat
from ..binary_sensor import ( from ..binary_sensor import (
SecurityBinarySensor, SecurityBinarySensor,
@@ -21,6 +22,8 @@ from ..binary_sensor import (
from .commons import * # pylint: disable=wildcard-import, unused-wildcard-import from .commons import * # pylint: disable=wildcard-import, unused-wildcard-import
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_security_binary_sensors( async def test_security_binary_sensors(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,
@@ -96,6 +99,8 @@ async def test_security_binary_sensors(
assert security_binary_sensor.state == STATE_OFF assert security_binary_sensor.state == STATE_OFF
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_overpowering_binary_sensors( async def test_overpowering_binary_sensors(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,
@@ -178,6 +183,8 @@ async def test_overpowering_binary_sensors(
assert overpowering_binary_sensor.state == STATE_OFF assert overpowering_binary_sensor.state == STATE_OFF
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_window_binary_sensors( async def test_window_binary_sensors(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,
@@ -264,6 +271,8 @@ async def test_window_binary_sensors(
assert window_binary_sensor.state == STATE_OFF assert window_binary_sensor.state == STATE_OFF
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_motion_binary_sensors( async def test_motion_binary_sensors(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,
@@ -350,6 +359,8 @@ async def test_motion_binary_sensors(
assert motion_binary_sensor.state == STATE_OFF assert motion_binary_sensor.state == STATE_OFF
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_presence_binary_sensors( async def test_presence_binary_sensors(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,
@@ -432,6 +443,8 @@ async def test_presence_binary_sensors(
assert presence_binary_sensor.state == STATE_OFF assert presence_binary_sensor.state == STATE_OFF
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_binary_sensors_over_climate_minimal( async def test_binary_sensors_over_climate_minimal(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,

View File

@@ -8,6 +8,8 @@ import logging
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_bug_56( async def test_bug_56(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,
@@ -85,6 +87,8 @@ async def test_bug_56(
entity.update_custom_attributes() entity.update_custom_attributes()
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_bug_63( async def test_bug_63(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,
@@ -135,6 +139,8 @@ async def test_bug_63(
# Waiting for answer in https://github.com/jmcollin78/versatile_thermostat/issues/64 # Waiting for answer in https://github.com/jmcollin78/versatile_thermostat/issues/64
# Repro case not evident # Repro case not evident
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_bug_64( async def test_bug_64(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,
@@ -180,6 +186,8 @@ async def test_bug_64(
assert entity assert entity
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_bug_66( async def test_bug_66(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,

View File

@@ -6,9 +6,12 @@ from homeassistant.config_entries import SOURCE_USER, ConfigEntry
from custom_components.versatile_thermostat.const import DOMAIN from custom_components.versatile_thermostat.const import DOMAIN
from .commons import * # pylint: disable=wildcard-import, unused-wildcard-import
from .const import * # pylint: disable=wildcard-import, unused-wildcard-import from .const import * # pylint: disable=wildcard-import, unused-wildcard-import
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_show_form(hass: HomeAssistant) -> None: async def test_show_form(hass: HomeAssistant) -> None:
"""Test that the form is served with no input""" """Test that the form is served with no input"""
# Init the API # Init the API
@@ -24,6 +27,8 @@ async def test_show_form(hass: HomeAssistant) -> None:
assert result["step_id"] == SOURCE_USER assert result["step_id"] == SOURCE_USER
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_user_config_flow_over_switch(hass: HomeAssistant, skip_hass_states_get): async def test_user_config_flow_over_switch(hass: HomeAssistant, skip_hass_states_get):
"""Test the config flow with all thermostat_over_switch features""" """Test the config flow with all thermostat_over_switch features"""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@@ -121,6 +126,8 @@ async def test_user_config_flow_over_switch(hass: HomeAssistant, skip_hass_state
assert isinstance(result["result"], ConfigEntry) assert isinstance(result["result"], ConfigEntry)
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_user_config_flow_over_climate(hass: HomeAssistant, skip_hass_states_get): async def test_user_config_flow_over_climate(hass: HomeAssistant, skip_hass_states_get):
"""Test the config flow with all thermostat_over_climate features and no additional features""" """Test the config flow with all thermostat_over_climate features and no additional features"""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@@ -206,6 +213,8 @@ async def test_user_config_flow_over_climate(hass: HomeAssistant, skip_hass_stat
assert isinstance(result["result"], ConfigEntry) assert isinstance(result["result"], ConfigEntry)
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_user_config_flow_window_auto_ok( async def test_user_config_flow_window_auto_ok(
hass: HomeAssistant, skip_hass_states_get, skip_control_heating hass: HomeAssistant, skip_hass_states_get, skip_control_heating
): ):
@@ -301,6 +310,8 @@ async def test_user_config_flow_window_auto_ok(
assert isinstance(result["result"], ConfigEntry) assert isinstance(result["result"], ConfigEntry)
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_user_config_flow_window_auto_ko( async def test_user_config_flow_window_auto_ko(
hass: HomeAssistant, skip_hass_states_get hass: HomeAssistant, skip_hass_states_get
): ):
@@ -371,6 +382,8 @@ async def test_user_config_flow_window_auto_ko(
} }
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_user_config_flow_over_4_switches( async def test_user_config_flow_over_4_switches(
hass: HomeAssistant, skip_hass_states_get, skip_control_heating hass: HomeAssistant, skip_hass_states_get, skip_control_heating
): ):

View File

@@ -9,6 +9,8 @@ import logging
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_movement_management_time_not_enough( async def test_movement_management_time_not_enough(
hass: HomeAssistant, skip_hass_states_is_state hass: HomeAssistant, skip_hass_states_is_state
): ):
@@ -140,6 +142,8 @@ async def test_movement_management_time_not_enough(
assert mock_send_event.call_count == 0 assert mock_send_event.call_count == 0
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_movement_management_time_enough_and_presence( async def test_movement_management_time_enough_and_presence(
hass: HomeAssistant, skip_hass_states_is_state hass: HomeAssistant, skip_hass_states_is_state
): ):
@@ -270,6 +274,8 @@ async def test_movement_management_time_enough_and_presence(
assert mock_send_event.call_count == 0 assert mock_send_event.call_count == 0
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_movement_management_time_enoughand_not_presence( async def test_movement_management_time_enoughand_not_presence(
hass: HomeAssistant, skip_hass_states_is_state hass: HomeAssistant, skip_hass_states_is_state
): ):

View File

@@ -9,6 +9,8 @@ import logging
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_one_switch_cycle( async def test_one_switch_cycle(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,
@@ -206,6 +208,8 @@ async def test_one_switch_cycle(
# assert entity.underlying_entity(0)._should_relaunch_control_heating is False # assert entity.underlying_entity(0)._should_relaunch_control_heating is False
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_multiple_switchs( async def test_multiple_switchs(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,

View File

@@ -10,6 +10,8 @@ import logging
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_power_management_hvac_off( async def test_power_management_hvac_off(
hass: HomeAssistant, skip_hass_states_is_state hass: HomeAssistant, skip_hass_states_is_state
): ):
@@ -96,6 +98,8 @@ async def test_power_management_hvac_off(
assert mock_heater_off.call_count == 0 assert mock_heater_off.call_count == 0
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_power_management_hvac_on(hass: HomeAssistant, skip_hass_states_is_state): async def test_power_management_hvac_on(hass: HomeAssistant, skip_hass_states_is_state):
"""Test the Power management""" """Test the Power management"""
@@ -226,6 +230,8 @@ async def test_power_management_hvac_on(hass: HomeAssistant, skip_hass_states_is
assert mock_heater_off.call_count == 0 assert mock_heater_off.call_count == 0
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_power_management_energy_over_switch( async def test_power_management_energy_over_switch(
hass: HomeAssistant, skip_hass_states_is_state hass: HomeAssistant, skip_hass_states_is_state
): ):
@@ -350,6 +356,8 @@ async def test_power_management_energy_over_switch(
assert round(entity.total_energy, 2) == round((2.0 + 0.6) * 100 * 5 / 60.0, 2) assert round(entity.total_energy, 2) == round((2.0 + 0.6) * 100 * 5 / 60.0, 2)
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_power_management_energy_over_climate( async def test_power_management_energy_over_climate(
hass: HomeAssistant, skip_hass_states_is_state hass: HomeAssistant, skip_hass_states_is_state
): ):

View File

@@ -9,6 +9,8 @@ import logging
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_security_feature(hass: HomeAssistant, skip_hass_states_is_state): async def test_security_feature(hass: HomeAssistant, skip_hass_states_is_state):
"""Test the security feature and https://github.com/jmcollin78/versatile_thermostat/issues/49: """Test the security feature and https://github.com/jmcollin78/versatile_thermostat/issues/49:
1. creates a thermostat and check that security is off 1. creates a thermostat and check that security is off

View File

@@ -26,6 +26,8 @@ from ..sensor import (
from .commons import * # pylint: disable=wildcard-import, unused-wildcard-import from .commons import * # pylint: disable=wildcard-import, unused-wildcard-import
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_sensors_over_switch( async def test_sensors_over_switch(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,
@@ -182,6 +184,8 @@ async def test_sensors_over_switch(
cancel_switchs_cycles(entity) cancel_switchs_cycles(entity)
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_sensors_over_climate( async def test_sensors_over_climate(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,
@@ -316,6 +320,8 @@ async def test_sensors_over_climate(
assert last_ext_temperature_sensor.device_class == SensorDeviceClass.TIMESTAMP assert last_ext_temperature_sensor.device_class == SensorDeviceClass.TIMESTAMP
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_sensors_over_climate_minimal( async def test_sensors_over_climate_minimal(
hass: HomeAssistant, hass: HomeAssistant,
skip_hass_states_is_state, skip_hass_states_is_state,

View File

@@ -15,6 +15,8 @@ from ..climate import VersatileThermostat
from .commons import * # pylint: disable=wildcard-import, unused-wildcard-import from .commons import * # pylint: disable=wildcard-import, unused-wildcard-import
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_over_switch_full_start(hass: HomeAssistant, skip_hass_states_is_state): async def test_over_switch_full_start(hass: HomeAssistant, skip_hass_states_is_state):
"""Test the normal full start of a thermostat in thermostat_over_switch type""" """Test the normal full start of a thermostat in thermostat_over_switch type"""
@@ -76,6 +78,8 @@ async def test_over_switch_full_start(hass: HomeAssistant, skip_hass_states_is_s
) )
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_over_climate_full_start(hass: HomeAssistant, skip_hass_states_is_state): async def test_over_climate_full_start(hass: HomeAssistant, skip_hass_states_is_state):
"""Test the normal full start of a thermostat in thermostat_over_climate type""" """Test the normal full start of a thermostat in thermostat_over_climate type"""
@@ -143,6 +147,8 @@ async def test_over_climate_full_start(hass: HomeAssistant, skip_hass_states_is_
mock_find_climate.assert_has_calls([call.find_underlying_entity()]) mock_find_climate.assert_has_calls([call.find_underlying_entity()])
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_over_4switch_full_start(hass: HomeAssistant, skip_hass_states_is_state): async def test_over_4switch_full_start(hass: HomeAssistant, skip_hass_states_is_state):
"""Test the normal full start of a thermostat in thermostat_over_switch with 4 switches type""" """Test the normal full start of a thermostat in thermostat_over_switch with 4 switches type"""

View File

@@ -3,6 +3,8 @@
from .commons import * # pylint: disable=wildcard-import, unused-wildcard-import from .commons import * # pylint: disable=wildcard-import, unused-wildcard-import
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_tpi_calculation(hass: HomeAssistant, skip_hass_states_is_state): async def test_tpi_calculation(hass: HomeAssistant, skip_hass_states_is_state):
"""Test the TPI calculation""" """Test the TPI calculation"""

View File

@@ -9,6 +9,8 @@ import logging
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_window_management_time_not_enough( async def test_window_management_time_not_enough(
hass: HomeAssistant, skip_hass_states_is_state hass: HomeAssistant, skip_hass_states_is_state
): ):
@@ -92,7 +94,11 @@ async def test_window_management_time_not_enough(
await try_window_condition(None) await try_window_condition(None)
assert entity.window_state == STATE_OFF assert entity.window_state == STATE_OFF
await entity.remove_thermostat()
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_window_management_time_enough( async def test_window_management_time_enough(
hass: HomeAssistant, skip_hass_states_is_state hass: HomeAssistant, skip_hass_states_is_state
): ):
@@ -227,7 +233,12 @@ async def test_window_management_time_enough(
) )
assert entity.preset_mode is PRESET_BOOST assert entity.preset_mode is PRESET_BOOST
# Clean the entity
await entity.remove_thermostat()
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_window_auto_fast(hass: HomeAssistant, skip_hass_states_is_state): async def test_window_auto_fast(hass: HomeAssistant, skip_hass_states_is_state):
"""Test the Power management""" """Test the Power management"""
@@ -406,7 +417,12 @@ async def test_window_auto_fast(hass: HomeAssistant, skip_hass_states_is_state):
assert entity.window_auto_state == STATE_OFF assert entity.window_auto_state == STATE_OFF
assert entity.hvac_mode is HVACMode.HEAT assert entity.hvac_mode is HVACMode.HEAT
# Clean the entity
await entity.remove_thermostat()
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_window_auto_auto_stop(hass: HomeAssistant, skip_hass_states_is_state): async def test_window_auto_auto_stop(hass: HomeAssistant, skip_hass_states_is_state):
"""Test the Power management""" """Test the Power management"""
@@ -544,7 +560,12 @@ async def test_window_auto_auto_stop(hass: HomeAssistant, skip_hass_states_is_st
assert entity.hvac_mode is HVACMode.HEAT assert entity.hvac_mode is HVACMode.HEAT
assert entity.preset_mode is PRESET_BOOST assert entity.preset_mode is PRESET_BOOST
# Clean the entity
await entity.remove_thermostat()
@pytest.mark.parametrize("expected_lingering_tasks", [True])
@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_window_auto_no_on_percent( async def test_window_auto_no_on_percent(
hass: HomeAssistant, skip_hass_states_is_state hass: HomeAssistant, skip_hass_states_is_state
): ):
@@ -647,3 +668,6 @@ async def test_window_auto_no_on_percent(
assert entity._window_auto_algo.is_window_close_detected() is False assert entity._window_auto_algo.is_window_close_detected() is False
assert entity.window_auto_state == STATE_OFF assert entity.window_auto_state == STATE_OFF
assert entity.hvac_mode is HVACMode.HEAT assert entity.hvac_mode is HVACMode.HEAT
# Clean the entity
await entity.remove_thermostat()