Skip to content

Commit

Permalink
feat: ensures temperature is not null when changing hvac mode in dual…
Browse files Browse the repository at this point in the history
… mode

Fixes #289
  • Loading branch information
= authored and swingerman committed Sep 9, 2024
1 parent 5121759 commit 563837f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 30 deletions.
70 changes: 42 additions & 28 deletions config/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -369,39 +369,53 @@ climate:
# cold_tolerance: 0.3
# hot_tolerance: 0.3

# - platform: dual_smart_thermostat
# name: Edge Case 239
# unique_id: edge_case_239
# heater: switch.heater
# # cooler: switch.cooler
# target_sensor: sensor.room_temp
# 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
# 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: Edge Case 239
unique_id: edge_case_239
name: Edge Case 289
unique_id: edge_case_289
heater: switch.heater
# cooler: switch.cooler
cooler: switch.cooler
target_sensor: sensor.room_temp
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
ac_mode: false
min_temp: 16
max_temp: 32
cold_tolerance: 0.4
hot_tolerance: 0.1
max_temp: 30
cold_tolerance: 1
hot_tolerance: 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
precision: 0.1

# - platform: dual_smart_thermostat
# name: Edge Case 210
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,14 +765,17 @@ def _set_temps_when_target_mode(
self.target_temp = self.saved_target_temp
# switching from preset NONE to NONE
elif supports_temp_range:
if hvac_mode in [HVACMode.COOL, HVACMode.FAN_ONLY]:
if (
hvac_mode in [HVACMode.COOL, HVACMode.FAN_ONLY]
and self.target_temp_high is not None
):
_LOGGER.debug(
"Setting temperatures from no preset target mode. HVACMode.COOL, target temp: %s",
self.target_temp,
)
self.target_temp = self.target_temp_high

elif hvac_mode == HVACMode.HEAT:
elif hvac_mode == HVACMode.HEAT and self.target_temp_low is not None:
_LOGGER.debug(
"Setting temperatures from no preset target mode. HVACMode.HEAT, target temp: %s",
self.target_temp,
Expand Down
19 changes: 19 additions & 0 deletions tests/test_dual_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,25 @@ async def test_heat_cool_get_hvac_modes_fan_configured(
)


async def test_set_hvac_mode_chnage_trarget_temp(
hass: HomeAssistant, setup_comp_dual # noqa: F811
) -> None:
"""Test the changing of the hvac mode avoid invalid target temp."""
await common.async_set_temperature(hass, 30)
state = hass.states.get(common.ENTITY)
assert state.attributes.get("temperature") == 30

await common.async_set_hvac_mode(hass, HVACMode.COOL)
await hass.async_block_till_done()
state = hass.states.get(common.ENTITY)
assert state.attributes.get("temperature") == 30

await common.async_set_hvac_mode(hass, HVACMode.HEAT)
await hass.async_block_till_done()
state = hass.states.get(common.ENTITY)
assert state.attributes.get("temperature") == 30


async def test_set_target_temp_dual(
hass: HomeAssistant, setup_comp_dual # noqa: F811
) -> None:
Expand Down

0 comments on commit 563837f

Please sign in to comment.