Skip to content

Commit

Permalink
Restore state does not function with presets
Browse files Browse the repository at this point in the history
Fixes #241
  • Loading branch information
= authored and swingerman committed Jul 22, 2024
1 parent 808e2c2 commit bf9c99b
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 18 deletions.
60 changes: 42 additions & 18 deletions config/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -390,30 +390,54 @@ climate:
# target_temp_low: 26.5
# target_temp_high: 28.0

# - platform: dual_smart_thermostat
# name: Edge Case 210
# unique_id: edge_case_210
# heater: switch.heater
# cooler: switch.cooler
# fan: switch.fan
# target_sensor: sensor.room_temp
# heat_cool_mode: true
# min_temp: 60
# max_temp: 85
# fan_hot_tolerance: 0.5
# heat_cool_mode: true
# min_cycle_duration:
# seconds: 60
# keep_alive:
# minutes: 3
# away:
# target_temp_low: 68
# target_temp_high: 77
# home:
# target_temp_low: 71
# target_temp_high: 74
# precision: 0.1
# target_temp_step: 0.5

- platform: dual_smart_thermostat
name: Edge Case 210
unique_id: edge_case_210
name: Edge Case 241
unique_id: edge_case_241
heater: switch.heater
cooler: switch.cooler
fan: switch.fan
target_sensor: sensor.room_temp
heat_cool_mode: true
min_temp: 60
max_temp: 85
fan_hot_tolerance: 0.5
heat_cool_mode: true
min_cycle_duration:
seconds: 60
keep_alive:
minutes: 3
away:
target_temp_low: 68
target_temp_high: 77
home:
target_temp_low: 71
target_temp_high: 74
precision: 0.1
heat_cool_mode: true # <-required
cold_tolerance: 0.3
hot_tolerance: 0.2
fan_hot_tolerance: 1
target_temp_step: 0.5
min_temp: 14
max_temp: 28
comfort:
temperature: 21
target_temp_low: 21
target_temp_high: 21.5
away:
temperature: 21
target_temp_low: 15
target_temp_high: 28


- platform: dual_smart_thermostat
name: Dual Humidity
Expand Down
56 changes: 56 additions & 0 deletions tests/test_dual_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,62 @@ async def test_set_heat_cool_preset_mode_twice_and_restore_prev_temp(
assert state.attributes.get("target_temp_high") == 22


@pytest.mark.parametrize(
("preset", "temp_low", "temp_high"),
[
# (PRESET_NONE, 18, 22),
(PRESET_AWAY, 16, 30),
# (PRESET_COMFORT, 20, 27),
# (PRESET_ECO, 18, 29),
# (PRESET_HOME, 19, 23),
# (PRESET_SLEEP, 17, 24),
# (PRESET_ACTIVITY, 21, 28),
# (PRESET_ANTI_FREEZE, 5, 32),
],
)
async def test_set_heat_cool_preset_mode_and_restore_prev_temp_apply_preset_again(
hass: HomeAssistant,
setup_comp_heat_cool_presets, # noqa: F811
preset,
temp_low,
temp_high,
) -> None:
"""Test the setting preset mode twice in a row.
Verify original temperature is restored.
"""
await common.async_set_temperature(hass, 23, common.ENTITY, 22, 18)
await common.async_set_preset_mode(hass, preset)

# targets match preset
state = hass.states.get(common.ENTITY)
assert state.attributes.get("target_temp_low") == temp_low
assert state.attributes.get("target_temp_high") == temp_high
await common.async_set_preset_mode(hass, PRESET_NONE)

# targets match presvios settings
state = hass.states.get(common.ENTITY)
assert state.attributes.get("target_temp_low") == 18
assert state.attributes.get("target_temp_high") == 22

common.mock_restore_cache(
hass,
(
State(
"climate.test_thermostat",
{ATTR_PRESET_MODE: {preset}},
),
),
)

hass.set_state(CoreState.starting)

# targets match preset again after restart
await common.async_set_preset_mode(hass, preset)
assert state.attributes.get("target_temp_low") == temp_low
assert state.attributes.get("target_temp_high") == temp_high


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

0 comments on commit bf9c99b

Please sign in to comment.