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
= committed May 9, 2024
1 parent f614a6b commit b937ec0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 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
16 changes: 12 additions & 4 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,25 @@ def _set_hvac_action_reason(self, *args) -> None:

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

_LOGGER.debug("Turning on with last hvac mode: %s", self._last_hvac_mode)
if self._last_hvac_mode is not None:
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
device_hvac_modes_not_off.sort() # for sake of predictability and consistency

# prioritize heat_cool mode if available
heat_cool_index = device_hvac_modes_not_off.index(HVACMode.HEAT_COOL)
if heat_cool_index != -1:
on_hvac_mode = HVACMode.HEAT_COOL

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)

0 comments on commit b937ec0

Please sign in to comment.