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
This commit is contained in:
Yegor Vialov 2018-10-23 10:04:47 +03:00 committed by Daniel Høyer Iversen
parent ad3d0c4e99
commit 324587b2db
2 changed files with 22 additions and 0 deletions

View File

@ -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()

View File

@ -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)