make sure is_away_mode_on supports user-defined minimum away temps

This commit is contained in:
Derek Brooks 2017-11-13 12:28:09 -06:00
parent ef5edb95ba
commit 766893253a
2 changed files with 31 additions and 3 deletions

View File

@ -151,9 +151,21 @@ class NuHeatThermostat(ClimateDevice):
Return true if away mode is on. Return true if away mode is on.
Away mode is determined by setting and HOLDing the target temperature Away mode is determined by setting and HOLDing the target temperature
to the minimum temperature supported. to the user-defined minimum away temperature or the minimum
temperature supported by the thermostat.
""" """
if self._thermostat.target_celsius > self._thermostat.min_celsius: if self._min_away_temp:
if self._temperature_unit == "C":
min_target = self._min_away_temp
target = self._thermostat.target_celsius
else:
min_target = self._min_away_temp
target = self._thermostat.target_fahrenheit
if target > min_target:
return False
elif self._thermostat.target_celsius > self._thermostat.min_celsius:
return False return False
if self._thermostat.schedule_mode != SCHEDULE_HOLD: if self._thermostat.schedule_mode != SCHEDULE_HOLD:

View File

@ -137,13 +137,29 @@ class TestNuHeat(unittest.TestCase):
def test_is_away_mode_on(self): def test_is_away_mode_on(self):
"""Test is away mode on.""" """Test is away mode on."""
_thermostat = self.thermostat._thermostat _thermostat = self.thermostat._thermostat
_thermostat.target_celsius = _thermostat.min_celsius
_thermostat.schedule_mode = SCHEDULE_HOLD _thermostat.schedule_mode = SCHEDULE_HOLD
# user-defined minimum fahrenheit
self.thermostat._min_away_temp = 59
_thermostat.target_fahrenheit = 59
self.assertTrue(self.thermostat.is_away_mode_on) self.assertTrue(self.thermostat.is_away_mode_on)
# user-defined minimum celsius
self.thermostat._temperature_unit = "C"
self.thermostat._min_away_temp = 15
_thermostat.target_celsius = 15
self.assertTrue(self.thermostat.is_away_mode_on)
# thermostat's minimum supported temperature
self.thermostat._min_away_temp = None
_thermostat.target_celsius = _thermostat.min_celsius
self.assertTrue(self.thermostat.is_away_mode_on)
# thermostat held at a temperature above the minimum
_thermostat.target_celsius = _thermostat.min_celsius + 1 _thermostat.target_celsius = _thermostat.min_celsius + 1
self.assertFalse(self.thermostat.is_away_mode_on) self.assertFalse(self.thermostat.is_away_mode_on)
# thermostat not on HOLD
_thermostat.target_celsius = _thermostat.min_celsius _thermostat.target_celsius = _thermostat.min_celsius
_thermostat.schedule_mode = SCHEDULE_RUN _thermostat.schedule_mode = SCHEDULE_RUN
self.assertFalse(self.thermostat.is_away_mode_on) self.assertFalse(self.thermostat.is_away_mode_on)