Skip to content

Commit

Permalink
Change shedding calculation delay to 20 sec (vs 60 sec)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Marc Collin committed Jan 4, 2025
1 parent 33c7c71 commit c01f96c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# circular dependency
# from .base_thermostat import BaseThermostat

MIN_DTEMP_SECS = 60
MIN_DTEMP_SECS = 20

_LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_binary_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_bugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions tests/test_central_power_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,11 @@ async def mock_set_overpowering(
"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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
8 changes: 4 additions & 4 deletions tests/test_multiple_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/test_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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())

Expand All @@ -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())
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit c01f96c

Please sign in to comment.