All windows tests ok

This commit is contained in:
Jean-Marc Collin
2024-12-27 12:47:19 +00:00
parent c83c772901
commit 329598b95a
9 changed files with 135 additions and 82 deletions

View File

@@ -68,7 +68,7 @@ async def test_window_management_time_not_enough(
assert entity.power_manager.overpowering_state is STATE_UNAVAILABLE
assert entity.target_temperature == 19
assert entity.window_state is STATE_OFF
assert entity.window_state is STATE_UNKNOWN
# Open the window, but condition of time is not satisfied and check the thermostat don't turns off
with patch(
@@ -157,7 +157,7 @@ async def test_window_management_time_enough(
assert entity.power_manager.overpowering_state is STATE_UNAVAILABLE
assert entity.target_temperature == 19
assert entity.window_state is STATE_OFF
assert entity.window_state is STATE_UNKNOWN
# change temperature to force turning on the heater
with patch(
@@ -307,8 +307,8 @@ async def test_window_auto_fast(hass: HomeAssistant, skip_hass_states_is_state):
assert entity.power_manager.overpowering_state is STATE_UNAVAILABLE
assert entity.target_temperature == 21
assert entity.window_state is STATE_OFF
assert entity.is_window_auto_configured is True
assert entity.window_state is STATE_UNKNOWN
assert entity.window_manager.is_window_auto_configured is True
# Initialize the slope algo with 2 measurements
event_timestamp = now + timedelta(minutes=1)
@@ -337,8 +337,12 @@ async def test_window_auto_fast(hass: HomeAssistant, skip_hass_states_is_state):
assert mock_send_event.call_count == 0
assert entity.is_device_active is True
assert entity.last_temperature_slope == 0.0
assert entity._window_auto_algo.is_window_open_detected() is False
assert entity._window_auto_algo.is_window_close_detected() is False
assert (
entity.window_manager._window_auto_algo.is_window_open_detected() is False
)
assert (
entity.window_manager._window_auto_algo.is_window_close_detected() is False
)
assert entity.hvac_mode is HVACMode.HEAT
# send one degre down in one minute
@@ -361,8 +365,10 @@ async def test_window_auto_fast(hass: HomeAssistant, skip_hass_states_is_state):
assert mock_heater_on.call_count == 0
assert mock_heater_off.call_count >= 1
assert entity.last_temperature_slope == -6.24
assert entity._window_auto_algo.is_window_open_detected() is True
assert entity._window_auto_algo.is_window_close_detected() is False
assert entity.window_manager._window_auto_algo.is_window_open_detected() is True
assert (
entity.window_manager._window_auto_algo.is_window_close_detected() is False
)
assert entity.window_auto_state == STATE_ON
assert entity.hvac_mode is HVACMode.OFF
@@ -397,8 +403,10 @@ async def test_window_auto_fast(hass: HomeAssistant, skip_hass_states_is_state):
assert mock_heater_on.call_count == 0
assert mock_heater_off.call_count == 0
assert round(entity.last_temperature_slope, 3) == -7.49
assert entity._window_auto_algo.is_window_open_detected() is True
assert entity._window_auto_algo.is_window_close_detected() is False
assert entity.window_manager._window_auto_algo.is_window_open_detected() is True
assert (
entity.window_manager._window_auto_algo.is_window_close_detected() is False
)
assert entity.window_auto_state == STATE_ON
assert entity.hvac_mode is HVACMode.OFF
@@ -438,8 +446,12 @@ async def test_window_auto_fast(hass: HomeAssistant, skip_hass_states_is_state):
assert mock_heater_on.call_count == 1
assert mock_heater_off.call_count == 0
assert entity.last_temperature_slope == 0.42
assert entity._window_auto_algo.is_window_open_detected() is False
assert entity._window_auto_algo.is_window_close_detected() is True
assert (
entity.window_manager._window_auto_algo.is_window_open_detected() is False
)
assert (
entity.window_manager._window_auto_algo.is_window_close_detected() is True
)
assert entity.window_auto_state == STATE_OFF
assert entity.hvac_mode is HVACMode.HEAT
@@ -481,6 +493,7 @@ async def test_window_auto_fast_and_sensor(
CONF_SECURITY_DELAY_MIN: 5,
CONF_SECURITY_MIN_ON_PERCENT: 0.3,
CONF_WINDOW_SENSOR: "binary_sensor.fake_window_sensor",
CONF_WINDOW_DELAY: 10,
CONF_WINDOW_AUTO_OPEN_THRESHOLD: 0.1,
CONF_WINDOW_AUTO_CLOSE_THRESHOLD: 0.1,
CONF_WINDOW_AUTO_MAX_DURATION: 10, # Should be 0 for test
@@ -504,8 +517,10 @@ async def test_window_auto_fast_and_sensor(
assert entity.preset_mode is PRESET_BOOST
assert entity.target_temperature == 21
assert entity.window_state is STATE_OFF
assert entity.is_window_auto_configured is False
assert entity.window_state is STATE_UNKNOWN
assert entity.window_auto_state is STATE_UNAVAILABLE
assert entity.window_manager.is_window_auto_configured is False
assert entity.window_manager.is_configured is True
# Initialize the slope algo with 2 measurements
event_timestamp = now + timedelta(minutes=1)
@@ -534,8 +549,12 @@ async def test_window_auto_fast_and_sensor(
assert mock_send_event.call_count == 0
assert entity.is_device_active is True
assert entity.last_temperature_slope == 0.0
assert entity._window_auto_algo.is_window_open_detected() is False
assert entity._window_auto_algo.is_window_close_detected() is False
assert (
entity.window_manager._window_auto_algo.is_window_open_detected() is False
)
assert (
entity.window_manager._window_auto_algo.is_window_close_detected() is False
)
assert entity.hvac_mode is HVACMode.HEAT
# send one degre down in one minute
@@ -559,9 +578,11 @@ async def test_window_auto_fast_and_sensor(
assert entity.last_temperature_slope == -6.24
# The window open should be detected (but not used)
# because we need to calculate the slope anyway, we have the algorithm running
assert entity._window_auto_algo.is_window_open_detected() is True
assert entity._window_auto_algo.is_window_close_detected() is False
assert entity.window_auto_state == STATE_OFF
assert entity.window_manager._window_auto_algo.is_window_open_detected() is True
assert (
entity.window_manager._window_auto_algo.is_window_close_detected() is False
)
assert entity.window_auto_state == STATE_UNAVAILABLE
assert entity.hvac_mode is HVACMode.HEAT
# Clean the entity
@@ -620,8 +641,8 @@ async def test_window_auto_auto_stop(hass: HomeAssistant, skip_hass_states_is_st
assert entity.power_manager.overpowering_state is STATE_UNAVAILABLE
assert entity.target_temperature == 21
assert entity.window_state is STATE_OFF
assert entity.is_window_auto_configured is True
assert entity.window_state is STATE_UNKNOWN
assert entity.window_manager.is_window_auto_configured is True
# 1. Initialize the slope algo with 2 measurements
event_timestamp = now + timedelta(minutes=1)
@@ -647,8 +668,12 @@ async def test_window_auto_auto_stop(hass: HomeAssistant, skip_hass_states_is_st
# The climate turns on but was alredy on
assert mock_set_hvac_mode.call_count == 0
assert entity.last_temperature_slope == 0.0
assert entity._window_auto_algo.is_window_open_detected() is False
assert entity._window_auto_algo.is_window_close_detected() is False
assert (
entity.window_manager._window_auto_algo.is_window_open_detected() is False
)
assert (
entity.window_manager._window_auto_algo.is_window_close_detected() is False
)
assert entity.hvac_mode is HVACMode.HEAT
# 3. send one degre down in one minute
@@ -665,8 +690,10 @@ async def test_window_auto_auto_stop(hass: HomeAssistant, skip_hass_states_is_st
await send_temperature_change_event(entity, 18, event_timestamp, sleep=False)
assert entity.last_temperature_slope == -6.24
assert entity._window_auto_algo.is_window_open_detected() is True
assert entity._window_auto_algo.is_window_close_detected() is False
assert entity.window_manager._window_auto_algo.is_window_open_detected() is True
assert (
entity.window_manager._window_auto_algo.is_window_close_detected() is False
)
assert mock_send_event.call_count == 2
# The heater turns off
@@ -714,8 +741,12 @@ async def test_window_auto_auto_stop(hass: HomeAssistant, skip_hass_states_is_st
assert mock_set_hvac_mode.call_count == 1
assert round(entity.last_temperature_slope, 3) == -0.29
assert entity._window_auto_algo.is_window_open_detected() is False
assert entity._window_auto_algo.is_window_close_detected() is False
assert (
entity.window_manager._window_auto_algo.is_window_open_detected() is False
)
assert (
entity.window_manager._window_auto_algo.is_window_close_detected() is False
)
# Clean the entity
entity.remove_thermostat()
@@ -756,7 +787,7 @@ async def test_window_auto_no_on_percent(
CONF_SECURITY_MIN_ON_PERCENT: 0.3,
CONF_WINDOW_AUTO_OPEN_THRESHOLD: 6,
CONF_WINDOW_AUTO_CLOSE_THRESHOLD: 6,
CONF_WINDOW_AUTO_MAX_DURATION: 0, # Should be 0 for test
CONF_WINDOW_AUTO_MAX_DURATION: 1, # Should be 0 for test but 0 is not possible
},
)
@@ -778,7 +809,8 @@ async def test_window_auto_no_on_percent(
assert entity.power_manager.overpowering_state is STATE_UNAVAILABLE
assert entity.target_temperature == 20
assert entity.window_state is STATE_OFF
assert entity.window_state is STATE_UNKNOWN
assert entity.window_auto_state is STATE_UNKNOWN
# Initialize the slope algo with 2 measurements
event_timestamp = now + timedelta(minutes=1)
@@ -806,8 +838,12 @@ async def test_window_auto_no_on_percent(
# The heater don't turns on
assert mock_heater_on.call_count == 0
assert entity.last_temperature_slope == 0.0
assert entity._window_auto_algo.is_window_open_detected() is False
assert entity._window_auto_algo.is_window_close_detected() is False
assert (
entity.window_manager._window_auto_algo.is_window_open_detected() is False
)
assert (
entity.window_manager._window_auto_algo.is_window_close_detected() is False
)
assert entity.hvac_mode is HVACMode.HEAT
assert entity.proportional_algorithm.on_percent == 0.0
@@ -833,10 +869,12 @@ async def test_window_auto_no_on_percent(
assert mock_heater_off.call_count == 1
assert entity.last_temperature_slope == -6.24
# The algo calculate open ...
assert entity._window_auto_algo.is_window_open_detected() is True
assert entity._window_auto_algo.is_window_close_detected() is False
# But the entity is still on
assert entity.window_auto_state == STATE_OFF
assert entity.window_manager._window_auto_algo.is_window_open_detected() is True
assert (
entity.window_manager._window_auto_algo.is_window_close_detected() is False
)
# But the entity is still on and window_auto is not detected
assert entity.window_auto_state == STATE_UNKNOWN
assert entity.hvac_mode is HVACMode.HEAT
# Clean the entity
@@ -894,8 +932,8 @@ async def test_window_bypass(hass: HomeAssistant, skip_hass_states_is_state):
assert entity.power_manager.overpowering_state is STATE_UNAVAILABLE
assert entity.target_temperature == 19
assert entity.window_state is STATE_OFF
assert entity.is_window_auto_configured is False
assert entity.window_state is STATE_UNKNOWN
assert entity.window_manager.is_window_auto_configured is False
# change temperature to force turning on the heater
with patch(
@@ -920,8 +958,6 @@ async def test_window_bypass(hass: HomeAssistant, skip_hass_states_is_state):
await entity.service_set_window_bypass_state(True)
assert entity.is_window_bypass is True
# entity._is_window_bypass = True
# Open the window, condition of time is satisfied, check the thermostat and heater turns off
with patch(
"custom_components.versatile_thermostat.base_thermostat.BaseThermostat.send_event"
@@ -936,7 +972,10 @@ async def test_window_bypass(hass: HomeAssistant, skip_hass_states_is_state):
new_callable=PropertyMock,
return_value=True,
):
await send_window_change_event(entity, True, False, datetime.now())
try_function = await send_window_change_event(
entity, True, False, datetime.now()
)
await try_function(None)
assert mock_send_event.call_count == 0
@@ -944,7 +983,7 @@ async def test_window_bypass(hass: HomeAssistant, skip_hass_states_is_state):
assert mock_heater_on.call_count == 0
# One call in set_hvac_mode turn_off and one call in the control_heating for security
assert mock_heater_off.call_count == 0
assert mock_condition.call_count == 1
assert mock_condition.call_count > 0
assert entity.hvac_mode is HVACMode.HEAT
assert entity.window_state == STATE_ON
@@ -1037,8 +1076,8 @@ async def test_window_auto_bypass(hass: HomeAssistant, skip_hass_states_is_state
assert entity.power_manager.overpowering_state is STATE_UNAVAILABLE
assert entity.target_temperature == 21
assert entity.window_state is STATE_OFF
assert entity.is_window_auto_configured
assert entity.window_state is STATE_UNKNOWN
assert entity.window_manager.is_window_auto_configured
# Initialize the slope algo with 2 measurements
event_timestamp = now + timedelta(minutes=1)
@@ -1066,8 +1105,12 @@ async def test_window_auto_bypass(hass: HomeAssistant, skip_hass_states_is_state
# The heater turns on
assert entity.is_device_active is True
assert entity.last_temperature_slope == 0.0
assert entity._window_auto_algo.is_window_open_detected() is False
assert entity._window_auto_algo.is_window_close_detected() is False
assert (
entity.window_manager._window_auto_algo.is_window_open_detected() is False
)
assert (
entity.window_manager._window_auto_algo.is_window_close_detected() is False
)
assert entity.hvac_mode is HVACMode.HEAT
# send one degre down in one minute with window bypass on
@@ -1094,9 +1137,11 @@ async def test_window_auto_bypass(hass: HomeAssistant, skip_hass_states_is_state
assert mock_heater_on.call_count == 0
assert mock_heater_off.call_count == 0
assert entity.last_temperature_slope == -6.24
assert entity._window_auto_algo.is_window_open_detected() is True
assert entity._window_auto_algo.is_window_close_detected() is False
assert entity.window_auto_state == STATE_OFF
assert entity.window_manager._window_auto_algo.is_window_open_detected() is True
assert (
entity.window_manager._window_auto_algo.is_window_close_detected() is False
)
assert entity.window_auto_state == STATE_UNKNOWN
assert entity.hvac_mode is HVACMode.HEAT
# Clean the entity
@@ -1155,7 +1200,7 @@ async def test_window_bypass_reactivate(hass: HomeAssistant, skip_hass_states_is
assert entity.power_manager.overpowering_state is STATE_UNAVAILABLE
assert entity.target_temperature == 19
assert entity.window_state is STATE_OFF
assert entity.window_state is STATE_UNKNOWN
# change temperature to force turning on the heater
with patch(
@@ -1299,7 +1344,7 @@ async def test_window_action_fan_only(hass: HomeAssistant, skip_hass_states_is_s
assert entity
assert entity.is_over_climate is True
assert entity.window_action == CONF_WINDOW_FAN_ONLY
assert entity.window_manager.window_action == CONF_WINDOW_FAN_ONLY
await entity.async_set_hvac_mode(HVACMode.HEAT)
assert entity.hvac_mode == HVACMode.HEAT
@@ -1307,7 +1352,7 @@ async def test_window_action_fan_only(hass: HomeAssistant, skip_hass_states_is_s
assert entity.preset_mode == PRESET_COMFORT
assert entity.target_temperature == 18
assert entity.window_state is STATE_OFF
assert entity.window_state is STATE_UNKNOWN
# 2. Open the window, condition of time is satisfied, check the thermostat and heater turns off
with patch(
@@ -1456,7 +1501,7 @@ async def test_window_action_fan_only_ko(
assert entity
assert entity.is_over_climate is True
assert entity.window_action == CONF_WINDOW_FAN_ONLY
assert entity.window_manager.window_action == CONF_WINDOW_FAN_ONLY
await entity.async_set_hvac_mode(HVACMode.HEAT)
assert entity.hvac_mode == HVACMode.HEAT
@@ -1464,7 +1509,7 @@ async def test_window_action_fan_only_ko(
assert entity.preset_mode == PRESET_COMFORT
assert entity.target_temperature == 18
assert entity.window_state is STATE_OFF
assert entity.window_state is STATE_UNKNOWN
# 2. Open the window, condition of time is satisfied, check the thermostat and heater turns off
with patch(
@@ -1594,8 +1639,8 @@ async def test_window_action_eco_temp(hass: HomeAssistant, skip_hass_states_is_s
assert entity.power_manager.overpowering_state is STATE_UNAVAILABLE
assert entity.target_temperature == 21
assert entity.window_state is STATE_OFF
assert entity.is_window_auto_configured is True
assert entity.window_state is STATE_UNKNOWN
assert entity.window_manager.is_window_auto_configured is True
# 1. Initialize the slope algo with 2 measurements
event_timestamp = now + timedelta(minutes=1)
@@ -1624,8 +1669,8 @@ async def test_window_action_eco_temp(hass: HomeAssistant, skip_hass_states_is_s
assert mock_send_event.call_count == 0
assert entity.is_device_active is True
assert entity.hvac_mode is HVACMode.HEAT
assert entity.window_state is STATE_OFF
assert entity.window_auto_state is STATE_OFF
assert entity.window_state is STATE_UNKNOWN
assert entity.window_auto_state is STATE_UNKNOWN
# 3. send one degre down in one minute
with patch(
@@ -1648,7 +1693,7 @@ async def test_window_action_eco_temp(hass: HomeAssistant, skip_hass_states_is_s
assert mock_heater_off.call_count == 0
assert entity.last_temperature_slope == -6.24
assert entity.window_auto_state == STATE_ON
assert entity.window_state == STATE_OFF
assert entity.window_state == STATE_ON
# No change on HVACMode
assert entity.hvac_mode is HVACMode.HEAT
# No change on preset
@@ -1791,8 +1836,8 @@ async def test_window_action_frost_temp(hass: HomeAssistant, skip_hass_states_is
assert entity.power_manager.overpowering_state is STATE_UNAVAILABLE
assert entity.target_temperature == 21
assert entity.window_state is STATE_OFF
assert entity.is_window_auto_configured is True
assert entity.window_state is STATE_UNKNOWN
assert entity.window_manager.is_window_auto_configured is True
# 1. Initialize the slope algo with 2 measurements
event_timestamp = now + timedelta(minutes=1)
@@ -1821,8 +1866,8 @@ async def test_window_action_frost_temp(hass: HomeAssistant, skip_hass_states_is
assert mock_send_event.call_count == 0
assert entity.is_device_active is True
assert entity.hvac_mode is HVACMode.HEAT
assert entity.window_state is STATE_OFF
assert entity.window_auto_state is STATE_OFF
assert entity.window_state is STATE_UNKNOWN
assert entity.window_auto_state is STATE_UNKNOWN
# 3. send one degre down in one minute
with patch(
@@ -1845,7 +1890,7 @@ async def test_window_action_frost_temp(hass: HomeAssistant, skip_hass_states_is
assert mock_heater_off.call_count == 0
assert entity.last_temperature_slope == -6.24
assert entity.window_auto_state == STATE_ON
assert entity.window_state == STATE_OFF
assert entity.window_state == STATE_ON
# No change on HVACMode
assert entity.hvac_mode is HVACMode.HEAT
# No change on preset
@@ -1991,7 +2036,7 @@ async def test_bug_66(
assert entity.hvac_mode is HVACMode.HEAT
assert entity.preset_mode is PRESET_BOOST
assert entity.target_temperature == 19
assert entity.window_state is STATE_OFF
assert entity.window_state is STATE_UNKNOWN
# Open the window and let the thermostat shut down
with patch(
@@ -2150,8 +2195,8 @@ async def test_window_action_frost_temp_preset_change(
assert vtherm.preset_mode is PRESET_BOOST
assert vtherm.target_temperature == 21
assert vtherm.window_state is STATE_OFF
assert vtherm.is_window_auto_configured is False
assert vtherm.window_state is STATE_UNKNOWN
assert vtherm.window_manager.is_window_auto_configured is False
# 1. Turn on the window sensor
now = now + timedelta(minutes=1)
@@ -2260,8 +2305,8 @@ async def test_window_action_frost_temp_temp_change(
assert vtherm.preset_mode is PRESET_BOOST
assert vtherm.target_temperature == 21
assert vtherm.window_state is STATE_OFF
assert vtherm.is_window_auto_configured is False
assert vtherm.window_state is STATE_UNKNOWN
assert vtherm.window_manager.is_window_auto_configured is False
# 1. Turn on the window sensor
now = now + timedelta(minutes=1)