Add set_operation_mode support to generic_thermostat (#8392)

This commit adds support for the set_operation_mode system call to the
generic thermostat component. This enables users to set whether the
thermostat is enabled or not by either setting it to auto or off.
This commit is contained in:
Matthew Treinish authored and Paulus Schoutsen committed 2017-07-08 09:21:10 -07:00
1 parent c5bf4fe339
commit cb298123d4
2 files changed
+81 -1

No files matched your search

@@ -108,6 +108,12 @@ class TestClimateGenericThermostat(unittest.TestCase):
self.assertEqual(35, state.attributes.get('max_temp'))
self.assertEqual(None, state.attributes.get('temperature'))
def test_get_operation_modes(self):
"""Test that the operation list returns the correct modes."""
state = self.hass.states.get(ENTITY)
modes = state.attributes.get('operation_list')
self.assertEqual([climate.STATE_AUTO, STATE_OFF], modes)
def test_set_target_temp(self):
"""Test the setting of the target temperature."""
climate.set_temperature(self.hass, 30)
@@ -211,6 +217,30 @@ class TestClimateGenericThermostat(unittest.TestCase):
self.assertEqual(SERVICE_TURN_OFF, call.service)
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
def test_running_when_operating_mode_is_off(self):
"""Test that the switch turns off when enabled is set False."""
self._setup_switch(True)
climate.set_temperature(self.hass, 30)
self.hass.block_till_done()
climate.set_operation_mode(self.hass, STATE_OFF)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)
self.assertEqual(SERVICE_TURN_OFF, call.service)
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
def test_no_state_change_when_operation_mode_off(self):
"""Test that the switch doesn't turn on when enabled is False."""
self._setup_switch(False)
climate.set_temperature(self.hass, 30)
self.hass.block_till_done()
climate.set_operation_mode(self.hass, STATE_OFF)
self.hass.block_till_done()
self._setup_sensor(25)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
def _setup_sensor(self, temp, unit=TEMP_CELSIUS):
"""Setup the test sensor."""
self.hass.states.set(ENT_SENSOR, temp, {
@@ -321,6 +351,30 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
self.assertEqual(SERVICE_TURN_ON, call.service)
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
def test_running_when_operating_mode_is_off(self):
"""Test that the switch turns off when enabled is set False."""
self._setup_switch(True)
climate.set_temperature(self.hass, 30)
self.hass.block_till_done()
climate.set_operation_mode(self.hass, STATE_OFF)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)
self.assertEqual(SERVICE_TURN_OFF, call.service)
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
def test_no_state_change_when_operation_mode_off(self):
"""Test that the switch doesn't turn on when enabled is False."""
self._setup_switch(False)
climate.set_temperature(self.hass, 30)
self.hass.block_till_done()
climate.set_operation_mode(self.hass, STATE_OFF)
self.hass.block_till_done()
self._setup_sensor(35)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
def _setup_sensor(self, temp, unit=TEMP_CELSIUS):
"""Setup the test sensor."""
self.hass.states.set(ENT_SENSOR, temp, {