Skip to content

Commit

Permalink
fix: avoids setting target temperature as a dicttionary
Browse files Browse the repository at this point in the history
Fixes #239
  • Loading branch information
= committed Jul 22, 2024
1 parent 078daa9 commit 9ca6b30
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 17 deletions.
64 changes: 49 additions & 15 deletions config/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -336,25 +336,59 @@ climate:
# precision: 0.1
# target_temp_step: 0.5

# - platform: dual_smart_thermostat
# name: Edge Case 181
# unique_id: edge_case_181
# heater: switch.heater
# cooler: switch.cooler
# fan: switch.fan
# target_sensor: sensor.room_temp
# floor_sensor: sensor.floor_temp
# heat_cool_mode: true
# max_floor_temp: 26
# min_floor_temp: 10
# fan_hot_tolerance: 0.7
# target_temp_step: 0.1
# precision: 0.1
# min_temp: 9
# max_temp: 32
# target_temp: 20
# cold_tolerance: 0.3
# hot_tolerance: 0.3

- platform: dual_smart_thermostat
name: Edge Case 181
unique_id: edge_case_181
name: Edge Case 239
unique_id: edge_case_239
heater: switch.heater
cooler: switch.cooler
fan: switch.fan
# cooler: switch.cooler
target_sensor: sensor.room_temp
floor_sensor: sensor.floor_temp
heat_cool_mode: true
max_floor_temp: 26
min_floor_temp: 10
fan_hot_tolerance: 0.7
target_temp_step: 0.1
precision: 0.1
min_temp: 9
heat_cool_mode: false #true # <-important
keep_alive: #lo attivo e commento initial_hvac_mode per verificare se mantiene lo stato al riavvio
minutes: 2
ac_mode: true
min_temp: 16
max_temp: 32
target_temp: 20
cold_tolerance: 0.3
hot_tolerance: 0.3
cold_tolerance: 0.4
hot_tolerance: 0.1
target_temp_step: 0.1
min_cycle_duration:
minutes: 1
away:
temperature: 28.0
target_temp_low: 27
target_temp_high: 29.5
home:
temperature: 23.0
target_temp_low: 22.5
target_temp_high: 23.5
comfort:
temperature: 25.0
target_temp_low: 24
target_temp_high: 25.5
sleep:
temperature: 27.5
target_temp_low: 26.5
target_temp_high: 28.0

- platform: dual_smart_thermostat
name: Dual Humidity
Expand Down
5 changes: 5 additions & 0 deletions custom_components/dual_smart_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,11 @@ def extra_state_attributes(self) -> dict:
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def saved_target_temp(self) -> float:

@saved_target_temp.setter
def saved_target_temp(self, temp: float) -> None:
_LOGGER.debug("Setting saved target temp: %s", temp)
self._saved_target_temp = temp

@property
Expand Down Expand Up @@ -569,8 +570,12 @@ def apply_old_state(self, old_state: State) -> None:
if old_target is None:
_LOGGER.info("No previous target temperature")
old_target = old_state.attributes.get(ATTR_TEMPERATURE)
# fix issues caused by old version saving target as dict
if isinstance(old_target, dict):
old_target = old_target.get(ATTR_TEMPERATURE)
if old_target is not None:
_LOGGER.info("Restoring previous target temperature: %s", old_target)

self._target_temp = float(old_target)

self._max_floor_temp = (
Expand Down
17 changes: 15 additions & 2 deletions custom_components/dual_smart_thermostat/managers/preset_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,17 @@ def __init__(
)

# sets the target environment to the preset mode
self._environment.saved_target_temp = self._environment.target_temp or next(
iter(presets.values()), None
_LOGGER.debug(
"Setting target temp when no preset mode, %s, %s",
self._environment.target_temp,
next(iter(presets.values())),
)

first_preset = next(iter(presets.values()), None)
preset_temperature = first_preset.get(ATTR_TEMPERATURE)

self._environment.saved_target_temp = (
self._environment.target_temp or preset_temperature or None
)

@property
Expand Down Expand Up @@ -171,6 +180,10 @@ def _set_presets_when_have_preset_mode(self, preset_mode: str, hvac_mode: HVACMo
self._environment.target_temp_high = self._presets_range[preset_mode][1]
else:
if self._preset_mode == PRESET_NONE:
_LOGGER.debug(
"Saving target temp when target and no preset: %s",
self._environment.target_temp,
)
self._environment.saved_target_temp = self._environment.target_temp
# handles when temperature is set in preset
if self._presets[preset_mode].get(ATTR_TEMPERATURE) is not None:
Expand Down

0 comments on commit 9ca6b30

Please sign in to comment.