Skip to content

Commit

Permalink
fix: picks temp if set n presets
Browse files Browse the repository at this point in the history
Fixes #269
  • Loading branch information
= committed Aug 26, 2024
1 parent cc18514 commit 280fafb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 49 deletions.
29 changes: 1 addition & 28 deletions custom_components/dual_smart_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,33 +765,8 @@ def extra_state_attributes(self) -> dict:
if self.environment.saved_target_temp_high is not None:
attributes[ATTR_PREV_TARGET_HIGH] = self.environment.saved_target_temp_high

# if self.environment.target_temp_low is not None:
# if self._attr_preset_mode != PRESET_NONE and self.features.is_range_mode:
# attributes[ATTR_PREV_TARGET_LOW] = (
# self.environment.saved_target_temp_low
# )
# else:
# attributes[ATTR_PREV_TARGET_LOW] = self.environment.target_temp_low
# if self.environment.target_temp_high is not None:
# if self._attr_preset_mode != PRESET_NONE and self.features.is_range_mode:
# attributes[ATTR_PREV_TARGET_HIGH] = (
# self.environment.saved_target_temp_high
# )
# else:
# attributes[ATTR_PREV_TARGET_HIGH] = self.environment.target_temp_high
if self.environment.saved_target_temp is not None:
attributes[ATTR_PREV_TARGET] = self.environment.saved_target_temp
# if self.environment.target_temp is not None:
# _LOGGER.debug(
# "Setting previous target temp: %s, %s, %s",
# self.environment.target_temp,
# self.environment.saved_target_temp,
# self._attr_preset_mode,
# )
# if self._attr_preset_mode != PRESET_NONE and self.features.is_target_mode:
# attributes[ATTR_PREV_TARGET] = self.environment.saved_target_temp
# else:
# attributes[ATTR_PREV_TARGET] = self.environment.target_temp

if self._cur_humidity is not None:
attributes[ATTR_PREV_HUMIDITY] = self.environment.target_humidity
Expand Down Expand Up @@ -1232,9 +1207,7 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
_LOGGER.debug("Preset mode is the same, skipping")
return

self.presets.set_preset_mode(
preset_mode, self.hvac_device.hvac_mode, self.hvac_device.hvac_modes
)
self.presets.set_preset_mode(preset_mode)

self._attr_preset_mode = self.presets.preset_mode

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ def set_humidity_from_preset(self, preset_mode: str, preset_env: PresetEnv) -> N
if preset_mode == PRESET_NONE:
if self.saved_target_humidity:
self.target_humidity = self.saved_target_humidity
# self._environment.saved_target_humidity = self._environment.target_humidity

else:
if preset_env.to_dict[ATTR_HUMIDITY] is not None:
Expand Down Expand Up @@ -634,7 +633,6 @@ def _set_temps_when_have_preset_mode(
if preset_env.has_temp_range():
self.target_temp_low = preset_env.to_dict[ATTR_TARGET_TEMP_LOW]
self.target_temp_high = preset_env.to_dict[ATTR_TARGET_TEMP_HIGH]
return

else:
_LOGGER.debug(
Expand Down Expand Up @@ -673,7 +671,6 @@ def _set_temps_when_have_preset_mode(
self._saved_target_temp,
)
self.target_temp = self._saved_target_temp
return

# handles when temperature is not set in preset but temp range is set
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,6 @@ def set_support_flags(
self.environment.set_default_target_humidity()

else:
# TODO: Preset based ltemperature logic should move to environment manager
if self.is_target_mode and preset_mode != PRESET_NONE:
self.environment.target_temp = self.environment.saved_target_temp
self._supported_features = (
self._default_support_flags
| ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
Expand All @@ -252,7 +249,9 @@ def set_support_flags(
if self.is_configured_for_dryer_mode:
self._supported_features |= ClimateEntityFeature.TARGET_HUMIDITY

def apply_old_state(self, old_state: State, hvac_mode, presets) -> None:
def apply_old_state(
self, old_state: State | None, hvac_mode: HVACMode | None = None, presets=[]
) -> None:
if old_state is None:
return

Expand Down
19 changes: 5 additions & 14 deletions custom_components/dual_smart_thermostat/managers/preset_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW,
PRESET_NONE,
HVACMode,
)
from homeassistant.const import ATTR_TEMPERATURE
from homeassistant.core import State
Expand Down Expand Up @@ -115,9 +114,7 @@ def _get_preset_modes_from_config(
)
return presets

def set_preset_mode(
self, preset_mode: str, hvac_mode: HVACMode, hvac_modes: list[HVACMode]
) -> None:
def set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
_LOGGER.debug("Setting preset mode: %s", preset_mode)
if preset_mode not in (self.preset_modes or []):
Expand All @@ -131,20 +128,14 @@ def set_preset_mode(
# if preset_mode == self._preset_mode we still need to continue
# to set the target environment to the preset mode
if preset_mode == PRESET_NONE:
self._set_presets_when_no_preset_mode()
self._preset_mode = PRESET_NONE
self._preset_env = PresetEnv()
else:
self._set_presets_when_have_preset_mode(preset_mode, hvac_mode, hvac_modes)
self._set_presets_when_have_preset_mode(preset_mode)

_LOGGER.debug("Preset env set: %s", self._preset_env)

def _set_presets_when_no_preset_mode(self):
"""Sets target environment when preset is none."""
self._preset_mode = PRESET_NONE
self._preset_env = PresetEnv()

def _set_presets_when_have_preset_mode(
self, preset_mode: str, hvac_mode: HVACMode, hvac_modes: list[HVACMode]
):
def _set_presets_when_have_preset_mode(self, preset_mode: str):
"""Sets target temperatures when have preset is not none."""
_LOGGER.debug("Setting presets when have preset mode")
if self._features.is_range_mode:
Expand Down

0 comments on commit 280fafb

Please sign in to comment.