Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignores min_cycle_duration to avoid gaps in cooling when using fan_hot_tolerance #233

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: ignores min_cycle_duration to avoid gaps in cooling when using f…
…an_hot_tolerance

Fixes #218
  • Loading branch information
= committed Jul 8, 2024
commit 3282a8bb75f40e8d6da44846c7236c9f0a16ad83
2 changes: 1 addition & 1 deletion custom_components/dual_smart_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ async def async_added_to_hass(self) -> None:
)
)

# registre device's on-remove
# register device's on-remove
self.async_on_remove(self.hvac_device.call_on_remove_callbacks)

if self.sensor_floor_entity_id is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,30 @@ async def async_control_hvac(self, time=None, force=False):
is_warmer_outside = self.environment.is_warmer_outside
is_fan_air_outside = self.fan_device.fan_air_surce_outside

# If the fan_hot_tolerance is set, enforce the action for the fan or cooler device
# to ignore cycles as we switch between the fan and cooler device
# and we want to avoid idle time gaps between the devices
force_override = (
True
if self.environment.fan_hot_tolerance is not None
else force
)

if is_within_fan_tolerance and not (
is_fan_air_outside and is_warmer_outside
):
_LOGGER.debug("within fan tolerance")
self.fan_device.hvac_mode = HVACMode.FAN_ONLY
await self.fan_device.async_control_hvac(time, force)
await self.fan_device.async_control_hvac(time, force_override)
await self.cooler_device.async_turn_off()
self.HVACActionReason = (
HVACActionReason.TARGET_TEMP_NOT_REACHED_WITH_FAN
)
else:
_LOGGER.debug("outside fan tolerance")
await self.cooler_device.async_control_hvac(time, force)
await self.cooler_device.async_control_hvac(
time, force_override
)
await self.fan_device.async_turn_off()
self.HVACActionReason = self.cooler_device.HVACActionReason

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def saved_target_humidity(self, humidity: float) -> None:
self._saved_target_humidity = humidity

@property
def fan_cold_tolerance(self) -> float:
def fan_hot_tolerance(self) -> float:
return self._fan_hot_tolerance

@property
Expand Down Expand Up @@ -510,7 +510,7 @@ def _set_default_temps_range_mode(self) -> None:
self._target_temp_low = self.min_temp
self._target_temp_high = self.max_temp
_LOGGER.warning(
"Undefined target temperature range, falled back to %s-%s-%s",
"Undefined target temperature range, fell back to %s-%s-%s",
self._target_temp,
self._target_temp_low,
self._target_temp_high,
Expand Down
29 changes: 29 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,35 @@ async def setup_comp_heat_ac_cool_fan_config_tolerance(hass: HomeAssistant) -> N
await hass.async_block_till_done()


@pytest.fixture
async def setup_comp_heat_ac_cool_fan_config_tolerance_min_cycle(
hass: HomeAssistant,
) -> None:
"""Initialize components."""
hass.config.units = METRIC_SYSTEM
assert await async_setup_component(
hass,
CLIMATE,
{
"climate": {
"platform": DOMAIN,
"name": "test",
"cold_tolerance": 2,
"hot_tolerance": 4,
"ac_mode": True,
"heater": common.ENT_SWITCH,
"target_sensor": common.ENT_SENSOR,
"fan": common.ENT_FAN,
"fan_hot_tolerance": 1,
"min_cycle_duration": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVACMode.OFF,
PRESET_AWAY: {"temperature": 30},
}
},
)
await hass.async_block_till_done()


@pytest.fixture
async def setup_comp_heat_ac_cool_fan_config_cycle(hass: HomeAssistant) -> None:
"""Initialize components."""
Expand Down
87 changes: 85 additions & 2 deletions tests/test_fan_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2353,6 +2353,89 @@ async def test_set_target_temp_ac_fan_on(
assert call.data["entity_id"] == common.ENT_FAN


async def test_set_target_temp_ac_on_tolerance_and_cycle(
hass: HomeAssistant, setup_comp_1 # noqa: F811
) -> None:
"""Test if target temperature turn ac or fan on without cycle gap."""
cooler_switch = "input_boolean.test"
fan_switch = "input_boolean.fan"

assert await async_setup_component(
hass,
input_boolean.DOMAIN,
{"input_boolean": {"test": None, "fan": None}},
)

assert await async_setup_component(
hass,
input_number.DOMAIN,
{
"input_number": {
"temp": {"name": "test", "initial": 10, "min": 0, "max": 40, "step": 1}
}
},
)

assert await async_setup_component(
hass,
CLIMATE,
{
"climate": {
"platform": DOMAIN,
"name": "test",
"cold_tolerance": 0.2,
"hot_tolerance": 0.2,
"ac_mode": True,
"heater": cooler_switch,
"target_sensor": common.ENT_SENSOR,
"fan": fan_switch,
"fan_hot_tolerance": 0.5,
"min_cycle_duration": timedelta(minutes=10),
"initial_hvac_mode": HVACMode.OFF,
}
},
)
await hass.async_block_till_done()

await common.async_set_hvac_mode(hass, HVACMode.COOL)
await common.async_set_temperature(hass, 20)

# below hot_tolerance
setup_sensor(hass, 20)
await hass.async_block_till_done()

assert hass.states.get(cooler_switch).state == STATE_OFF
assert hass.states.get(fan_switch).state == STATE_OFF

# within hot_tolerance and fan_hot_tolerance
setup_sensor(hass, 20.2)
await hass.async_block_till_done()

assert hass.states.get(cooler_switch).state == STATE_OFF
assert hass.states.get(fan_switch).state == STATE_ON

# within hot_tolerance and fan_hot_tolerance
setup_sensor(hass, 20.5)
await hass.async_block_till_done()

assert hass.states.get(cooler_switch).state == STATE_OFF
assert hass.states.get(fan_switch).state == STATE_ON

# within hot_tolerance and fan_hot_tolerance
setup_sensor(hass, 20.7)
await hass.async_block_till_done()

assert hass.states.get(cooler_switch).state == STATE_OFF
assert hass.states.get(fan_switch).state == STATE_ON

# outside fan_hot_tolerance, within hot_tolerance
setup_sensor(hass, 20.8)
await hass.async_block_till_done()

assert hass.states.get(cooler_switch).state == STATE_ON
assert hass.states.get(fan_switch).state == STATE_OFF


async def test_set_target_temp_ac_on_after_fan_tolerance(
hass: HomeAssistant, setup_comp_heat_ac_cool_fan_config_tolerance # noqa: F811
) -> None:
Expand Down Expand Up @@ -2558,8 +2641,8 @@ async def test_set_target_temp_ac_on_dont_ignore_fan_tolerance(
hass: HomeAssistant, setup_comp_1 # noqa: F811
) -> None:
"""Test if target temperature turn ac on.
ignoring fan tolerance if fan blows outside air
that is warmer than the inside air"""
not ignoring fan tolerance if outside temp
is colder than target temp"""

cooler_switch = "input_boolean.test"
fan_switch = "input_boolean.fan"
Expand Down