From 324587b2dbd388536c987ce5b6372cc706fc94e9 Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Tue, 23 Oct 2018 10:04:47 +0300 Subject: [PATCH] Away mode temperature fix for generic thermostat (#17641) * Resolves /home-assistant/home-assistant#17433 Away mode temperature issue fix for generic_thermostat * Debug messages removed from generic_thermostat.py * Test for repeat away_mode set Test for fix of generic thermostat issue when away_mode was set several times in a row. * Code style fix in generic_thermostat * Remove blank line in the end of generic_thermostat * Fix style --- .../components/climate/generic_thermostat.py | 4 ++++ .../climate/test_generic_thermostat.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/homeassistant/components/climate/generic_thermostat.py b/homeassistant/components/climate/generic_thermostat.py index 258699ff90a..ad8875462fd 100644 --- a/homeassistant/components/climate/generic_thermostat.py +++ b/homeassistant/components/climate/generic_thermostat.py @@ -380,6 +380,8 @@ class GenericThermostat(ClimateDevice): async def async_turn_away_mode_on(self): """Turn away mode on by setting it on away hold indefinitely.""" + if self._is_away: + return self._is_away = True self._saved_target_temp = self._target_temp self._target_temp = self._away_temp @@ -388,6 +390,8 @@ class GenericThermostat(ClimateDevice): async def async_turn_away_mode_off(self): """Turn away off.""" + if not self._is_away: + return self._is_away = False self._target_temp = self._saved_target_temp await self._async_control_heating() diff --git a/tests/components/climate/test_generic_thermostat.py b/tests/components/climate/test_generic_thermostat.py index 47ec621aeb5..8bbcbc8f840 100644 --- a/tests/components/climate/test_generic_thermostat.py +++ b/tests/components/climate/test_generic_thermostat.py @@ -221,6 +221,24 @@ class TestClimateGenericThermostat(unittest.TestCase): state = self.hass.states.get(ENTITY) self.assertEqual(23, state.attributes.get('temperature')) + def test_set_away_mode_twice_and_restore_prev_temp(self): + """Test the setting away mode twice in a row. + + Verify original temperature is restored. + """ + common.set_temperature(self.hass, 23) + self.hass.block_till_done() + common.set_away_mode(self.hass, True) + self.hass.block_till_done() + common.set_away_mode(self.hass, True) + self.hass.block_till_done() + state = self.hass.states.get(ENTITY) + self.assertEqual(16, state.attributes.get('temperature')) + common.set_away_mode(self.hass, False) + self.hass.block_till_done() + state = self.hass.states.get(ENTITY) + self.assertEqual(23, state.attributes.get('temperature')) + def test_sensor_bad_value(self): """Test sensor that have None as state.""" state = self.hass.states.get(ENTITY)