From fb90dab471d5078936693030888a64ebc53ec2f3 Mon Sep 17 00:00:00 2001 From: Derek Brooks Date: Sun, 24 Dec 2017 10:09:27 -0700 Subject: [PATCH] add ability to change the Nuheat thermostat hold mode --- homeassistant/components/climate/nuheat.py | 18 ++++++++++++++++-- tests/components/climate/test_nuheat.py | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/climate/nuheat.py b/homeassistant/components/climate/nuheat.py index f08c2d7b7d5..c1cb4651c6c 100644 --- a/homeassistant/components/climate/nuheat.py +++ b/homeassistant/components/climate/nuheat.py @@ -12,12 +12,12 @@ from homeassistant.components.climate import ( SUPPORT_HOLD_MODE, SUPPORT_OPERATION_MODE, SUPPORT_TARGET_TEMPERATURE, + STATE_AUTO, STATE_HEAT, STATE_IDLE) from homeassistant.components.nuheat import DATA_NUHEAT from homeassistant.const import ( ATTR_TEMPERATURE, - STATE_HOME, TEMP_CELSIUS, TEMP_FAHRENHEIT) from homeassistant.util import Throttle @@ -31,7 +31,7 @@ ICON = "mdi:thermometer" MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=5) # Hold modes -MODE_AUTO = STATE_HOME # Run device schedule +MODE_AUTO = STATE_AUTO # Run device schedule MODE_HOLD_TEMPERATURE = "temperature" MODE_TEMPORARY_HOLD = "temporary_temperature" @@ -156,6 +156,20 @@ class NuHeatThermostat(ClimateDevice): self._thermostat.resume_schedule() self._force_update = True + def set_hold_mode(self, hold_mode, **kwargs): + """Update the hold mode of the thermostat.""" + if hold_mode == MODE_AUTO: + schedule_mode = SCHEDULE_RUN + + if hold_mode == MODE_HOLD_TEMPERATURE: + schedule_mode = SCHEDULE_HOLD + + if hold_mode == MODE_TEMPORARY_HOLD: + schedule_mode = SCHEDULE_TEMPORARY_HOLD + + self._thermostat.schedule_mode = schedule_mode + self._force_update = True + def set_temperature(self, **kwargs): """Set a new target temperature.""" temperature = kwargs.get(ATTR_TEMPERATURE) diff --git a/tests/components/climate/test_nuheat.py b/tests/components/climate/test_nuheat.py index b2b3e6cddff..3e30e7caaf7 100644 --- a/tests/components/climate/test_nuheat.py +++ b/tests/components/climate/test_nuheat.py @@ -138,6 +138,20 @@ class TestNuHeat(unittest.TestCase): self.thermostat._thermostat.resume_schedule.assert_called_once_with() self.assertTrue(self.thermostat._force_update) + def test_set_hold_mode(self): + """Test set hold mode.""" + self.thermostat.set_hold_mode("temperature") + self.assertEqual(self.thermostat._thermostat.schedule_mode, SCHEDULE_HOLD) + self.assertTrue(self.thermostat._force_update) + + self.thermostat.set_hold_mode("temporary_temperature") + self.assertEqual(self.thermostat._thermostat.schedule_mode, SCHEDULE_TEMPORARY_HOLD) + self.assertTrue(self.thermostat._force_update) + + self.thermostat.set_hold_mode("auto") + self.assertEqual(self.thermostat._thermostat.schedule_mode, SCHEDULE_RUN) + self.assertTrue(self.thermostat._force_update) + def test_set_temperature(self): """Test set temperature.""" self.thermostat.set_temperature(temperature=85)