Skip to content

Commit

Permalink
fix: thermostat no longer turns on to heat/cool mode
Browse files Browse the repository at this point in the history
Fixes #167
  • Loading branch information
= authored and swingerman committed May 9, 2024
1 parent f614a6b commit 2ffed06
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
13 changes: 13 additions & 0 deletions config/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,19 @@ climate:
target_temp_step: 0.5
initial_hvac_mode: heat

- platform: dual_smart_thermostat
name: Edge Case 167
unique_id: edge_case_167
heater: switch.heater
cooler: switch.cooler
target_sensor: sensor.room_temp
min_temp: 55
max_temp: 110
heat_cool_mode: true
cold_tolerance: 0.3
hot_tolerance: 0.3
precision: 1.0

- platform: dual_smart_thermostat
name: Edge Case 175
unique_id: edge_case_175
Expand Down
22 changes: 16 additions & 6 deletions custom_components/dual_smart_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,10 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
_LOGGER.debug("Unrecognized hvac mode: %s", hvac_mode)
return

if hvac_mode == HVACMode.OFF:
self._last_hvac_mode = self.hvac_device.hvac_mode
_LOGGER.debug("Turning off with hvac mode: %s", self._last_hvac_mode)

self._hvac_mode = hvac_mode
self._set_support_flags()

Expand Down Expand Up @@ -870,21 +874,27 @@ def _set_hvac_action_reason(self, *args) -> None:

async def async_turn_on(self) -> None:
"""Turn on the device."""

if self._last_hvac_mode is not None:
_LOGGER.debug("Turning on with last hvac mode: %s", self._last_hvac_mode)
if self._last_hvac_mode is not None and self._last_hvac_mode != HVACMode.OFF:
on_hvac_mode = self._last_hvac_mode
else:
device_hvac_modes_not_off = [
mode for mode in self.hvac_device.hvac_modes if mode != HVACMode.OFF
]
device_hvac_modes_not_off.sort() # for sake of predictavility and consistency
on_hvac_mode = device_hvac_modes_not_off[0]
device_hvac_modes_not_off.sort() # for sake of predictability and consistency

# prioritize heat_cool mode if available
if (
HVACMode.HEAT_COOL in device_hvac_modes_not_off
and device_hvac_modes_not_off.index(HVACMode.HEAT_COOL) != -1
):
on_hvac_mode = HVACMode.HEAT_COOL
else:
on_hvac_mode = device_hvac_modes_not_off[0]

_LOGGER.debug("Turning on with hvac mode: %s", on_hvac_mode)
await self.async_set_hvac_mode(on_hvac_mode)

async def async_turn_off(self) -> None:
"""Turn off the device."""
self._last_hvac_mode = self.hvac_device.hvac_mode
_LOGGER.debug("Turning off with hvac mode: %s", self._last_hvac_mode)
await self.async_set_hvac_mode(HVACMode.OFF)
6 changes: 3 additions & 3 deletions tests/test_dual_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ async def test_heat_cool_fan_set_preset_mode_change_hvac_mode(
@pytest.mark.parametrize(
["from_hvac_mode", "to_hvac_mode"],
[
[HVACMode.OFF, HVACMode.COOL],
[HVACMode.OFF, HVACMode.HEAT],
[HVACMode.COOL, HVACMode.OFF],
[HVACMode.HEAT, HVACMode.OFF],
],
Expand Down Expand Up @@ -1046,7 +1046,7 @@ async def test_dual_toggle(
@pytest.mark.parametrize(
["from_hvac_mode", "to_hvac_mode"],
[
[HVACMode.OFF, HVACMode.COOL],
[HVACMode.OFF, HVACMode.HEAT_COOL],
[HVACMode.COOL, HVACMode.OFF],
[HVACMode.HEAT, HVACMode.OFF],
],
Expand Down Expand Up @@ -1111,7 +1111,7 @@ async def test_dual_toggle_with_fan(
@pytest.mark.parametrize(
["from_hvac_mode", "to_hvac_mode"],
[
[HVACMode.OFF, HVACMode.COOL],
[HVACMode.OFF, HVACMode.HEAT_COOL],
[HVACMode.HEAT_COOL, HVACMode.OFF],
[HVACMode.COOL, HVACMode.OFF],
[HVACMode.FAN_ONLY, HVACMode.OFF],
Expand Down

0 comments on commit 2ffed06

Please sign in to comment.