Skip to content

Commit

Permalink
fix: the heat/cool fuction is not working with the fan-mode
Browse files Browse the repository at this point in the history
Fixes #175
  • Loading branch information
= authored and swingerman committed May 1, 2024
1 parent dd67d9f commit ce8b169
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 31 deletions.
16 changes: 16 additions & 0 deletions config/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ climate:
target_temp_step: 0.5
initial_hvac_mode: heat

- platform: dual_smart_thermostat
name: Edge Case 175
unique_id: edge_case_175
heater: switch.heater
cooler: switch.cooler
target_sensor: sensor.room_temp
heat_cool_mode: true
fan: switch.fan
fan_hot_tolerance: 1
target_temp_step: 0.5
min_temp: 9
max_temp: 32
target_temp: 19.5
target_temp_high: 20.5
target_temp_low: 19.5

- platform: dual_smart_thermostat
name: AUX Heat Room
unique_id: aux_heat_room
Expand Down
3 changes: 2 additions & 1 deletion custom_components/dual_smart_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,11 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
_LOGGER.debug("Unrecognized hvac mode: %s", hvac_mode)
return

await self.hvac_device.async_set_hvac_mode(hvac_mode)
self._hvac_mode = hvac_mode
self._set_support_flags()

await self.hvac_device.async_set_hvac_mode(hvac_mode)

self._hvac_action_reason = self.hvac_device.HVACActionReason

# Ensure we update the current operation after changing the mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from custom_components.dual_smart_thermostat.hvac_device.specific_hvac_device import (
SpecificHVACDevice,
)
from custom_components.dual_smart_thermostat.managers.feature_manager import (
FeatureManager,
)
from custom_components.dual_smart_thermostat.managers.opening_manager import (
OpeningManager,
)
Expand All @@ -29,7 +32,7 @@ def __init__(
initial_hvac_mode: HVACMode,
temperatures: TemperatureManager,
openings: OpeningManager,
range_mode: bool = False,
features: FeatureManager,
) -> None:
super().__init__(
hass,
Expand All @@ -38,10 +41,16 @@ def __init__(
initial_hvac_mode,
temperatures,
openings,
features,
)

if range_mode:
self._target_temp_attr = "_target_temp_high"
@property
def target_temp_attr(self) -> str:
return (
"_target_temp_high"
if self.features.is_range_mode
else self._target_temp_attr
)

@property
def hvac_action(self) -> HVACAction:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
HVACDevice,
merge_hvac_modes,
)
from custom_components.dual_smart_thermostat.managers.feature_manager import (
FeatureManager,
)
from custom_components.dual_smart_thermostat.managers.opening_manager import (
OpeningManager,
)
Expand All @@ -38,19 +41,17 @@ def __init__(
initial_hvac_mode: HVACMode,
temperatures: TemperatureManager,
openings: OpeningManager,
fan_on_with_cooler: bool = False,
range_mode: bool = False,
features: FeatureManager,
) -> None:
super().__init__(hass, temperatures, openings)

self._features = features

self._device_type = self.__class__.__name__
self._fan_on_with_cooler = fan_on_with_cooler
self._fan_on_with_cooler = features.is_configured_for_fan_on_with_cooler
self.cooler_device = cooler_device
self.fan_device = fan_device

if range_mode:
self._target_temp_attr = "_target_temp_high"

# _hvac_modes are the combined values of the cooler_device.hvac_modes and fan_device.hvac_modes without duplicates
self.hvac_modes = merge_hvac_modes(
cooler_device.hvac_modes, fan_device.hvac_modes
Expand Down Expand Up @@ -135,7 +136,9 @@ async def async_control_hvac(self, time=None, force=False):
self.HVACActionReason = self.cooler_device.HVACActionReason
else:

if self.temperatures.is_within_fan_tolerance:
if self.temperatures.is_within_fan_tolerance(
self.fan_device.target_temp_attr
):
_LOGGER.info("within fan tolerance")
await self.fan_device.async_control_hvac(time, force)
await self.cooler_device.async_turn_off()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
HVACDevice,
merge_hvac_modes,
)
from custom_components.dual_smart_thermostat.managers.feature_manager import (
FeatureManager,
)
from custom_components.dual_smart_thermostat.managers.opening_manager import (
OpeningManager,
)
Expand All @@ -46,7 +49,7 @@ def __init__(
initial_hvac_mode: HVACMode,
temperatures: TemperatureManager,
openings: OpeningManager,
range_mode: bool = False,
features: FeatureManager,
) -> None:
super().__init__(hass, temperatures, openings)

Expand All @@ -56,7 +59,7 @@ def __init__(
self._aux_heater_timeout = aux_heater_timeout
self._aux_heater_dual_mode = aux_heater_dual_mode

if range_mode:
if features.is_range_mode:
self._target_temp_attr = "_target_temp_low"

self._aux_heater_last_run: datetime = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from custom_components.dual_smart_thermostat.hvac_device.specific_hvac_device import (
SpecificHVACDevice,
)
from custom_components.dual_smart_thermostat.managers.feature_manager import (
FeatureManager,
)
from custom_components.dual_smart_thermostat.managers.opening_manager import (
OpeningManager,
)
Expand All @@ -32,7 +35,7 @@ def __init__(
initial_hvac_mode: HVACMode,
temperatures: TemperatureManager,
openings: OpeningManager,
range_mode: bool = False,
features: FeatureManager,
) -> None:
super().__init__(
hass,
Expand All @@ -41,10 +44,16 @@ def __init__(
initial_hvac_mode,
temperatures,
openings,
features,
)

if range_mode:
self._target_temp_attr = "_target_temp_low"
@property
def target_temp_attr(self) -> str:
return (
"_target_temp_low"
if self.features.is_range_mode
else self._target_temp_attr
)

@property
def hvac_action(self) -> HVACAction:
Expand Down Expand Up @@ -72,7 +81,7 @@ async def async_control_hvac(self, time=None, force=False):

async def _async_control_device_when_on(self, time=None) -> None:
"""Check if we need to turn heating on or off when theheater is on."""
too_hot = self.temperatures.is_too_hot(self._target_temp_attr)
too_hot = self.temperatures.is_too_hot(self.target_temp_attr)
is_floor_hot = self.temperatures.is_floor_hot
is_floor_cold = self.temperatures.is_floor_cold
any_opening_open = self.openings.any_opening_open(self.hvac_mode)
Expand Down Expand Up @@ -104,7 +113,7 @@ async def _async_control_device_when_off(self, time=None) -> None:
"""Check if we need to turn heating on or off when the heater is off."""
_LOGGER.debug("%s _async_control_device_when_off", self.__class__.__name__)

too_cold = self.temperatures.is_too_cold(self._target_temp_attr)
too_cold = self.temperatures.is_too_cold(self.target_temp_attr)
is_floor_hot = self.temperatures.is_floor_hot
is_floor_cold = self.temperatures.is_floor_cold
any_opening_open = self.openings.any_opening_open(self.hvac_mode)
Expand Down
10 changes: 10 additions & 0 deletions custom_components/dual_smart_thermostat/hvac_device/hvac_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ async def async_turn_off(self):
pass


class CanTargetTemperature(ABC):

_target_temp_attr: str = "_target_temp"

@property
@abstractmethod
def target_temp_attr(self) -> str:
pass


class HVACDevice:

_active: bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def create_device(
self._initial_hvac_mode,
temperatures,
openings,
self._features,
)

if (
Expand All @@ -114,6 +115,7 @@ def create_device(
self._initial_hvac_mode,
temperatures,
openings,
self._features,
)

elif (
Expand All @@ -127,6 +129,7 @@ def create_device(
None,
temperatures,
openings,
self._features,
)
fan_device = FanDevice(
self.hass,
Expand All @@ -135,6 +138,7 @@ def create_device(
None,
temperatures,
openings,
self._features,
)

_LOGGER.info(
Expand All @@ -150,7 +154,7 @@ def create_device(
self._initial_hvac_mode,
temperatures,
openings,
fan_on_with_cooler=self._fan_on_with_cooler,
self._features,
)

elif self._features.is_configured_for_dual_mode:
Expand All @@ -168,6 +172,7 @@ def _create_heater_device(
self._initial_hvac_mode,
temperatures,
openings,
self._features,
)
if self._features.is_configured_for_aux_heating_mode:
aux_heater_device = HeaterDevice(
Expand All @@ -177,6 +182,7 @@ def _create_heater_device(
self._initial_hvac_mode,
temperatures,
openings,
self._features,
)
return HeaterAUXHeaterDevice(
self.hass,
Expand All @@ -187,6 +193,7 @@ def _create_heater_device(
self._initial_hvac_mode,
temperatures,
openings,
self._features,
)
_LOGGER.info(
"Creating HeaterDevice device, _is_configured_for_aux_heating_mode: %s",
Expand All @@ -204,7 +211,7 @@ def _create_heat_cool_device(
self._initial_hvac_mode,
temperatures,
openings,
range_mode=self._features.is_configured_for_heat_cool_mode,
self._features,
)

if self._features.is_configured_for_aux_heating_mode:
Expand All @@ -215,7 +222,7 @@ def _create_heat_cool_device(
self._initial_hvac_mode,
temperatures,
openings,
range_mode=self._features.is_configured_for_heat_cool_mode,
self._features,
)
return HeaterAUXHeaterDevice(
self.hass,
Expand All @@ -226,6 +233,7 @@ def _create_heat_cool_device(
self._initial_hvac_mode,
temperatures,
openings,
self._features,
)

cooler_device = CoolerDevice(
Expand All @@ -235,7 +243,7 @@ def _create_heat_cool_device(
self._initial_hvac_mode,
temperatures,
openings,
range_mode=self._features.is_configured_for_heat_cool_mode,
self._features,
)

cooler_fan_device = None
Expand All @@ -248,7 +256,7 @@ def _create_heat_cool_device(
self._initial_hvac_mode,
temperatures,
openings,
range_mode=self._features.is_configured_for_heat_cool_mode,
self._features,
)
cooler_fan_device = CoolerFanDevice(
self.hass,
Expand All @@ -257,7 +265,7 @@ def _create_heat_cool_device(
self._initial_hvac_mode,
temperatures,
openings,
fan_on_with_cooler=self._fan_on_with_cooler,
self._features,
)

_LOGGER.info(
Expand Down
Loading

0 comments on commit ce8b169

Please sign in to comment.