From c01f96c955d5950aa05417e7aab325a4b11fd909 Mon Sep 17 00:00:00 2001 From: Jean-Marc Collin Date: Sat, 4 Jan 2025 15:50:30 +0000 Subject: [PATCH] Change shedding calculation delay to 20 sec (vs 60 sec) --- .../central_feature_power_manager.py | 2 +- tests/test_binary_sensors.py | 2 +- tests/test_bugs.py | 4 ++-- tests/test_central_power_manager.py | 12 ++++++------ tests/test_multiple_switch.py | 8 ++++---- tests/test_power.py | 10 +++++----- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/custom_components/versatile_thermostat/central_feature_power_manager.py b/custom_components/versatile_thermostat/central_feature_power_manager.py index 5614faf..9275ee3 100644 --- a/custom_components/versatile_thermostat/central_feature_power_manager.py +++ b/custom_components/versatile_thermostat/central_feature_power_manager.py @@ -23,7 +23,7 @@ from .base_manager import BaseFeatureManager # circular dependency # from .base_thermostat import BaseThermostat -MIN_DTEMP_SECS = 60 +MIN_DTEMP_SECS = 20 _LOGGER = logging.getLogger(__name__) diff --git a/tests/test_binary_sensors.py b/tests/test_binary_sensors.py index c39e3ed..7ef51ee 100644 --- a/tests/test_binary_sensors.py +++ b/tests/test_binary_sensors.py @@ -195,7 +195,7 @@ async def test_overpowering_binary_sensors( # fmt:off with patch("homeassistant.core.StateMachine.get", side_effect=side_effects.get_side_effects()): # fmt: on - now = now + timedelta(seconds=61) + now = now + timedelta(seconds=30) VersatileThermostatAPI.get_vtherm_api()._set_now(now) await send_max_power_change_event(entity, 201, now) assert entity.power_manager.is_overpowering_detected is False diff --git a/tests/test_bugs.py b/tests/test_bugs.py index a1cf4df..3c049aa 100644 --- a/tests/test_bugs.py +++ b/tests/test_bugs.py @@ -378,7 +378,7 @@ async def test_bug_407( "homeassistant.core.StateMachine.get", side_effect=side_effects.get_side_effects(), ): - now = now + timedelta(seconds=61) + now = now + timedelta(seconds=30) VersatileThermostatAPI.get_vtherm_api()._set_now(now) # change preset to Boost @@ -409,7 +409,7 @@ async def test_bug_407( "homeassistant.core.StateMachine.get", side_effect=side_effects.get_side_effects(), ): - now = now + timedelta(seconds=61) + now = now + timedelta(seconds=30) VersatileThermostatAPI.get_vtherm_api()._set_now(now) # change preset to Boost diff --git a/tests/test_central_power_manager.py b/tests/test_central_power_manager.py index 0d30745..6932c77 100644 --- a/tests/test_central_power_manager.py +++ b/tests/test_central_power_manager.py @@ -537,11 +537,11 @@ async def test_central_power_manageer_calculate_shedding( "dsecs, power, nb_call", [ (0, 1000, 1), - (61, 1000, 1), - (59, 1000, 1), (0, None, 0), (0, STATE_UNAVAILABLE, 0), (0, STATE_UNKNOWN, 0), + (21, 1000, 1), + (19, 1000, 1), ], ) async def test_central_power_manager_power_event( @@ -622,18 +622,18 @@ async def test_central_power_manager_power_event( })) assert central_power_manager.current_power == expected_power - assert mock_calculate_shedding.call_count == (nb_call if dsecs >= 60 else 0) + assert mock_calculate_shedding.call_count == (nb_call if dsecs >= 20 else 0) @pytest.mark.parametrize( "dsecs, max_power, nb_call", [ (0, 1000, 1), - (61, 1000, 1), - (59, 1000, 1), (0, None, 0), (0, STATE_UNAVAILABLE, 0), (0, STATE_UNKNOWN, 0), + (21, 1000, 1), + (19, 1000, 1), ], ) async def test_central_power_manager_max_power_event( @@ -716,4 +716,4 @@ async def test_central_power_manager_max_power_event( })) assert central_power_manager.current_max_power == expected_power - assert mock_calculate_shedding.call_count == (nb_call if dsecs >= 60 else 0) + assert mock_calculate_shedding.call_count == (nb_call if dsecs >= 20 else 0) diff --git a/tests/test_multiple_switch.py b/tests/test_multiple_switch.py index 75c23a3..648afbd 100644 --- a/tests/test_multiple_switch.py +++ b/tests/test_multiple_switch.py @@ -796,7 +796,7 @@ async def test_multiple_switch_power_management( # fmt:off with patch("homeassistant.core.StateMachine.get", side_effect=side_effects.get_side_effects()): # fmt: on - now = now + timedelta(seconds=61) + now = now + timedelta(seconds=30) VersatileThermostatAPI.get_vtherm_api()._set_now(now) await send_power_change_event(entity, 50, datetime.now()) @@ -817,7 +817,7 @@ async def test_multiple_switch_power_management( "custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.turn_off" ) as mock_heater_off: - now = now + timedelta(seconds=61) + now = now + timedelta(seconds=30) VersatileThermostatAPI.get_vtherm_api()._set_now(now) # 100 of the device / 4 -> 25, current power 50 so max is 75 await send_max_power_change_event(entity, 74, datetime.now()) @@ -851,7 +851,7 @@ async def test_multiple_switch_power_management( with patch( "custom_components.versatile_thermostat.base_thermostat.BaseThermostat.send_event" ) as mock_send_event: - now = now + timedelta(seconds=61) + now = now + timedelta(seconds=30) VersatileThermostatAPI.get_vtherm_api()._set_now(now) await entity.async_set_preset_mode(PRESET_ECO) @@ -869,7 +869,7 @@ async def test_multiple_switch_power_management( ) as mock_heater_on, patch( "custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.turn_off" ) as mock_heater_off: - now = now + timedelta(seconds=61) + now = now + timedelta(seconds=30) VersatileThermostatAPI.get_vtherm_api()._set_now(now) # 100 of the device / 4 -> 25, current power 50 so max is 75. With 150 no overheating diff --git a/tests/test_power.py b/tests/test_power.py index 8d68579..74dce38 100644 --- a/tests/test_power.py +++ b/tests/test_power.py @@ -398,7 +398,7 @@ async def test_power_management_hvac_off( assert entity.power_manager.overpowering_state is STATE_UNKNOWN # due to hvac_off # Send power max mesurement - now = now + timedelta(seconds=61) + now = now + timedelta(seconds=30) VersatileThermostatAPI.get_vtherm_api()._set_now(now) await send_max_power_change_event(entity, 300, now) assert entity.power_manager.is_overpowering_detected is False @@ -414,7 +414,7 @@ async def test_power_management_hvac_off( patch("custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.turn_on") as mock_heater_on, \ patch("custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.turn_off") as mock_heater_off: # fmt: on - now = now + timedelta(seconds=61) + now = now + timedelta(seconds=30) VersatileThermostatAPI.get_vtherm_api()._set_now(now) await send_max_power_change_event(entity, 149, datetime.now()) @@ -500,7 +500,7 @@ async def test_power_management_hvac_on( # fmt: on await send_power_change_event(entity, 50, datetime.now()) # Send power max mesurement - now = now + timedelta(seconds=61) + now = now + timedelta(seconds=30) VersatileThermostatAPI.get_vtherm_api()._set_now(now) await send_max_power_change_event(entity, 300, datetime.now()) @@ -517,7 +517,7 @@ async def test_power_management_hvac_on( patch("custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.turn_on") as mock_heater_on, \ patch("custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.turn_off") as mock_heater_off: # fmt: on - now = now + timedelta(seconds=61) + now = now + timedelta(seconds=30) VersatileThermostatAPI.get_vtherm_api()._set_now(now) await send_max_power_change_event(entity, 149, datetime.now()) @@ -555,7 +555,7 @@ async def test_power_management_hvac_on( patch("custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.turn_on") as mock_heater_on, \ patch("custom_components.versatile_thermostat.underlyings.UnderlyingSwitch.turn_off") as mock_heater_off: # fmt: on - now = now + timedelta(seconds=61) + now = now + timedelta(seconds=30) VersatileThermostatAPI.get_vtherm_api()._set_now(now) await send_power_change_event(entity, 48, datetime.now())