Skip to content

Commit

Permalink
FIX anto_fan rule for Cooling mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Marc Collin committed Dec 10, 2023
1 parent 76416d2 commit a7480e1
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
16 changes: 15 additions & 1 deletion custom_components/versatile_thermostat/thermostat_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
async_track_time_interval,
)

from homeassistant.components.climate import HVACAction, HVACMode, ClimateEntityFeature
from homeassistant.components.climate import (
HVACAction,
HVACMode,
ClimateEntityFeature,
)

from .commons import NowClass, round_to_nearest
from .base_thermostat import BaseThermostat
Expand Down Expand Up @@ -194,6 +198,16 @@ async def _send_auto_fan_mode(self):
should_activate_auto_fan = (
dtemp >= AUTO_FAN_DTEMP_THRESHOLD or dtemp <= -AUTO_FAN_DTEMP_THRESHOLD
)

# deal with ac / non ac mode
hvac_mode = self.hvac_mode
if (
(hvac_mode == HVACMode.COOL and dtemp > 0)
or (hvac_mode == HVACMode.HEAT and dtemp < 0)
or (hvac_mode == HVACMode.OFF)
):
should_activate_auto_fan = False

if should_activate_auto_fan and self.fan_mode != self._auto_activated_fan_mode:
_LOGGER.info(
"%s - Activate the auto fan mode with %s because delta temp is %.2f",
Expand Down
61 changes: 61 additions & 0 deletions tests/test_auto_fan_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ async def test_over_climate_auto_fan_mode_turbo_activation(
"eco_temp": 17,
"comfort_temp": 18,
"boost_temp": 19,
"eco_ac_temp": 25,
"comfort_ac_temp": 23,
"boost_ac_temp": 21,
CONF_USE_WINDOW_FEATURE: False,
CONF_USE_MOTION_FEATURE: False,
CONF_USE_POWER_FEATURE: False,
Expand All @@ -189,6 +192,7 @@ async def test_over_climate_auto_fan_mode_turbo_activation(
CONF_SECURITY_DELAY_MIN: 5,
CONF_SECURITY_MIN_ON_PERCENT: 0.3,
CONF_AUTO_FAN_MODE: CONF_AUTO_FAN_TURBO,
CONF_AC_MODE: True,
},
)

Expand Down Expand Up @@ -235,6 +239,7 @@ async def test_over_climate_auto_fan_mode_turbo_activation(
assert entity.hvac_mode == HVACMode.HEAT
await entity.async_set_preset_mode(PRESET_COMFORT)
assert entity.preset_mode == PRESET_COMFORT
assert entity.target_temperature == 18

# Change the current temperature to 16 which is 2° under
await send_temperature_change_event(entity, 16, now, True)
Expand Down Expand Up @@ -283,3 +288,59 @@ async def test_over_climate_auto_fan_mode_turbo_activation(

assert mock_send_fan_mode.call_count == 0
assert entity.fan_mode == "mute"

# 6. Set temperature very high above the target
with patch(
"custom_components.versatile_thermostat.underlyings.UnderlyingClimate.set_fan_mode"
) as mock_send_fan_mode:
fake_underlying_climate.set_fan_mode("mute")

# Change the current temperature to 17 which is 1° under
await send_temperature_change_event(entity, 21, now, True)

assert mock_send_fan_mode.call_count == 0
assert entity.fan_mode == "mute"

# 7. In AC mode, set temperature very high under the target
with patch(
"custom_components.versatile_thermostat.underlyings.UnderlyingClimate.set_fan_mode"
) as mock_send_fan_mode:
await entity.async_set_hvac_mode(HVACMode.COOL)
assert entity.hvac_mode == HVACMode.COOL
assert entity.preset_mode == PRESET_COMFORT
assert entity.target_temperature == 23

assert entity.current_temperature == 21

fake_underlying_climate.set_fan_mode("mute")

# Change the current temperature to 17 which is 1° under
await send_temperature_change_event(entity, 20, now, True)

assert mock_send_fan_mode.call_count == 0
assert entity.fan_mode == "mute"

# 8. In AC mode, set temperature not so high above the target
with patch(
"custom_components.versatile_thermostat.underlyings.UnderlyingClimate.set_fan_mode"
) as mock_send_fan_mode:
assert entity.target_temperature == 23
await send_temperature_change_event(entity, 24, now, True)
assert entity.current_temperature == 24
fake_underlying_climate.set_fan_mode("mute")

assert mock_send_fan_mode.call_count == 0
assert entity.fan_mode == "mute"

# 8. In AC mode, set temperature high above the target
with patch(
"custom_components.versatile_thermostat.underlyings.UnderlyingClimate.set_fan_mode"
) as mock_send_fan_mode:
assert entity.target_temperature == 23
await send_temperature_change_event(entity, 25.1, now, True)
assert entity.current_temperature == 25.1
fake_underlying_climate.set_fan_mode("turbo")

assert mock_send_fan_mode.call_count == 1
mock_send_fan_mode.assert_has_calls([call.set_fan_mode("turbo")])
assert entity.fan_mode == "turbo"

0 comments on commit a7480e1

Please sign in to comment.