Skip to content

Commit b67ba2b

Browse files
author
=
committed
fix: don't send target temp range form old state if heat cool mode is off
Fixes #299
1 parent 9e1f9bc commit b67ba2b

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

custom_components/dual_smart_thermostat/managers/environment_manager.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
CONF_DRY_TOLERANCE,
2525
CONF_FAN_HOT_TOLERANCE,
2626
CONF_FLOOR_SENSOR,
27+
CONF_HEAT_COOL_MODE,
2728
CONF_HOT_TOLERANCE,
2829
CONF_MAX_FLOOR_TEMP,
2930
CONF_MAX_HUMIDITY,
@@ -110,6 +111,7 @@ def __init__(self, hass: HomeAssistant, config: ConfigType):
110111
self._cur_outside_temp = None
111112
self._cur_humidity = None
112113
self._saved_target_humidity = None
114+
self._config_heat_cool_mode = config.get(CONF_HEAT_COOL_MODE) or False
113115

114116
@property
115117
def cur_temp(self) -> float:
@@ -789,14 +791,16 @@ def apply_old_state(self, old_state: State) -> None:
789791
if old_state is None:
790792
return
791793

794+
_LOGGER.debug("Old state attributes: %s", old_state.attributes)
795+
792796
# If we have no initial temperature, restore
793-
if self._target_temp_low is None:
797+
if self._target_temp_low is None and self._config_heat_cool_mode:
794798
old_target_min = old_state.attributes.get(
795799
ATTR_PREV_TARGET_LOW
796800
) or old_state.attributes.get(ATTR_TARGET_TEMP_LOW)
797801
if old_target_min is not None:
798802
self._target_temp_low = float(old_target_min)
799-
if self._target_temp_high is None:
803+
if self._target_temp_high is None and self._config_heat_cool_mode:
800804
old_target_max = old_state.attributes.get(
801805
ATTR_PREV_TARGET_HIGH
802806
) or old_state.attributes.get(ATTR_TARGET_TEMP_HIGH)

tests/__init__.py

+28
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,34 @@ async def setup_comp_heat_cool_2(hass: HomeAssistant) -> None:
748748
await hass.async_block_till_done()
749749

750750

751+
@pytest.fixture
752+
async def setup_comp_heat_cool_3(hass: HomeAssistant) -> None:
753+
"""Initialize components."""
754+
hass.config.units = METRIC_SYSTEM
755+
assert await async_setup_component(
756+
hass,
757+
CLIMATE,
758+
{
759+
"climate": {
760+
"platform": DOMAIN,
761+
"name": "test",
762+
"cold_tolerance": 2,
763+
"hot_tolerance": 4,
764+
"heater": common.ENT_HEATER,
765+
"cooler": common.ENT_COOLER,
766+
"target_sensor": common.ENT_SENSOR,
767+
"initial_hvac_mode": HVACMode.HEAT_COOL,
768+
"target_temp": 21,
769+
"heat_cool_mode": False,
770+
PRESET_AWAY: {
771+
"temperature": 16,
772+
},
773+
}
774+
},
775+
)
776+
await hass.async_block_till_done()
777+
778+
751779
@pytest.fixture
752780
async def setup_comp_dual_fan_config(hass: HomeAssistant) -> None:
753781
"""Initialize components."""

tests/test_dual_mode.py

+49
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,55 @@ async def test_get_hvac_modes_heat_cool_2(
392392
)
393393

394394

395+
# async def test_get_hvac_modes_heat_cool_if_heat_cool_mode_off(
396+
# hass: HomeAssistant, setup_comp_heat_cool_3 # noqa: F811
397+
# ) -> None:
398+
# """Test that the operation list returns the correct modes."""
399+
# await async_setup_component(
400+
# hass,
401+
# CLIMATE,
402+
# {
403+
# "climate": {
404+
# "platform": DOMAIN,
405+
# "name": "test",
406+
# "cold_tolerance": 2,
407+
# "hot_tolerance": 4,
408+
# "heater": common.ENT_HEATER,
409+
# "cooler": common.ENT_COOLER,
410+
# "target_sensor": common.ENT_SENSOR,
411+
# "initial_hvac_mode": HVACMode.OFF,
412+
# "target_temp": 21,
413+
# "heat_cool_mode": False,
414+
# PRESET_AWAY: {
415+
# "temperature": 16,
416+
# },
417+
# }
418+
# },
419+
# )
420+
# await hass.async_block_till_done()
421+
422+
# common.mock_restore_cache(
423+
# hass,
424+
# (
425+
# State(
426+
# common.ENTITY,
427+
# {
428+
# ATTR_PREV_TARGET_HIGH: "21",
429+
# ATTR_PREV_TARGET_LOW: "19",
430+
# },
431+
# ),
432+
# ),
433+
# )
434+
435+
# hass.set_state(CoreState.starting)
436+
# await hass.async_block_till_done()
437+
438+
# state = hass.states.get(common.ENTITY)
439+
# assert state.attributes.get("supported_features") == 401
440+
# modes = state.attributes.get("hvac_modes")
441+
# assert set(modes) == set([HVACMode.OFF, HVACMode.HEAT, HVACMode.COOL])
442+
443+
395444
async def test_dual_get_hvac_modes_fan_configured(
396445
hass: HomeAssistant, setup_comp_dual_fan_config # noqa: F811
397446
) -> None:

0 commit comments

Comments
 (0)