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: picks temp if set n presets #273

Merged
merged 1 commit into from
Aug 26, 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
98 changes: 67 additions & 31 deletions custom_components/dual_smart_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,7 @@ async def _async_startup(*_) -> None:
if hvac_mode not in self.hvac_modes:
hvac_mode = HVACMode.OFF

self.features.apply_old_state(
old_state, hvac_mode, self.presets.presets_range
)
self.features.apply_old_state(old_state, hvac_mode, self.presets.presets)
self._attr_supported_features = self.features.supported_features

self.environment.set_default_target_temps(
Expand Down Expand Up @@ -761,30 +759,39 @@ def extra_state_attributes(self) -> dict:
"""Return entity specific state attributes to be saved."""

attributes = {}
if self._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._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._target_temp is not None:
_LOGGER.debug(
"Setting previous target temp: %s, %s",
self.environment.target_temp,
self.environment.saved_target_temp,
)
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.environment.saved_target_temp_low is not None:
attributes[ATTR_PREV_TARGET_LOW] = self.environment.saved_target_temp_low

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 All @@ -808,7 +815,6 @@ def extra_state_attributes(self) -> dict:
def _set_support_flags(self) -> None:
self.features.set_support_flags(
self.presets.presets,
self.presets.presets_range,
self.presets.preset_mode,
self._hvac_mode,
)
Expand Down Expand Up @@ -877,7 +883,11 @@ async def async_set_hvac_mode(

if not is_restore:
self.environment.set_temepratures_from_hvac_mode_and_presets(
self._hvac_mode, self.presets.preset_mode, self.presets.presets_range
self._hvac_mode,
self.features.hvac_modes_support_range_temp(self._attr_hvac_modes),
self.presets.preset_mode,
self.presets.preset_env,
self.features.is_range_mode,
)

self._target_humidity = self.environment.target_humidity
Expand Down Expand Up @@ -1209,14 +1219,40 @@ def _is_device_active(self) -> bool:
return self.hvac_device.is_active

async def async_set_preset_mode(self, preset_mode: str) -> None:
self.presets.set_preset_mode(preset_mode, self.hvac_device.hvac_mode)
"""Set new preset mode."""
_LOGGER.debug(
"Climate Setting preset mode: %s, is_range_mode: %s",
preset_mode,
self.features.is_range_mode,
)

old_preset_mode = self.presets.preset_mode

if old_preset_mode == preset_mode:
_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._attr_preset_mode = self.presets.preset_mode

self.environment.set_temepratures_from_hvac_mode_and_presets(
self._hvac_mode, preset_mode, self.presets.presets_range
self._hvac_mode,
self.features.hvac_modes_support_range_temp(self._attr_hvac_modes),
preset_mode,
self.presets.preset_env,
is_range_mode=self.features.is_range_mode,
old_preset_mode=old_preset_mode,
)

if self.features.is_configured_for_dryer_mode:

self.environment.set_humidity_from_preset(
self.presets.preset_mode, self.presets.preset_env
)

await self._async_control_climate(force=True)
self.async_write_ha_state()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,4 @@ async def async_control_device_when_off(
if any_opening_open:
self._hvac_action_reason = HVACActionReason.OPENING
else:
_LOGGER.warning("No case matched when off")
_LOGGER.debug("No case matched when - keeping device off")
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def async_control_device_when_off(

else:
_LOGGER.debug(
"No case matched when off - too_cold: %s, any_opening_open: %s, is_floor_hot: %s, is_floor_cold: %s, time: %s. Taking default action to turn off heater.",
"No case matched - keeping device off - too_cold: %s, any_opening_open: %s, is_floor_hot: %s, is_floor_cold: %s, time: %s. Taking default action to turn off heater.",
too_cold,
any_opening_open,
is_floor_hot,
Expand Down
Loading