Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions homeassistant/components/climate/generic_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ async def async_set_operation_mode(self, operation_mode):
# Ensure we update the current operation after changing the mode
self.schedule_update_ha_state()

async def async_turn_on(self):
"""Turn thermostat on."""
await self.async_set_operation_mode(self.operation_list[0])

async def async_turn_off(self):
"""Turn thermostat off."""
await self.async_set_operation_mode(STATE_OFF)

async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
Expand Down
85 changes: 85 additions & 0 deletions tests/components/climate/test_generic_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from homeassistant.util.unit_system import METRIC_SYSTEM
from homeassistant.util.async_ import run_coroutine_threadsafe
from homeassistant.components import climate, input_boolean, switch
from homeassistant.components.climate import STATE_HEAT, STATE_COOL
import homeassistant.components as comps
from tests.common import (assert_setup_component, get_test_home_assistant,
mock_restore_cache)
Expand Down Expand Up @@ -924,6 +925,90 @@ def log_call(call):
self.hass.services.register(ha.DOMAIN, SERVICE_TURN_OFF, log_call)


class TestClimateGenericThermostatTurnOnOff(unittest.TestCase):
"""Test the Generic Thermostat."""

HEAT_ENTITY = 'climate.test_heat'
COOL_ENTITY = 'climate.test_cool'

def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
assert setup_component(self.hass, climate.DOMAIN, {'climate': [
{
'platform': 'generic_thermostat',
'name': 'test_heat',
'heater': ENT_SWITCH,
'target_sensor': ENT_SENSOR
},
{
'platform': 'generic_thermostat',
'name': 'test_cool',
'heater': ENT_SWITCH,
'ac_mode': True,
'target_sensor': ENT_SENSOR
}
]})

def tearDown(self): # pylint: disable=invalid-name
"""Stop down everything that was started."""
self.hass.stop()

def test_turn_on_when_off(self):
"""Test if climate.turn_on turns on a turned off device."""
climate.set_operation_mode(self.hass, STATE_OFF)
self.hass.block_till_done()
self.hass.services.call('climate', SERVICE_TURN_ON)
self.hass.block_till_done()
state_heat = self.hass.states.get(self.HEAT_ENTITY)
state_cool = self.hass.states.get(self.COOL_ENTITY)
self.assertEqual(STATE_HEAT,
state_heat.attributes.get('operation_mode'))
self.assertEqual(STATE_COOL,
state_cool.attributes.get('operation_mode'))

def test_turn_on_when_on(self):
"""Test if climate.turn_on does nothing to a turned on device."""
climate.set_operation_mode(self.hass, STATE_HEAT, self.HEAT_ENTITY)
climate.set_operation_mode(self.hass, STATE_COOL, self.COOL_ENTITY)
self.hass.block_till_done()
self.hass.services.call('climate', SERVICE_TURN_ON)
self.hass.block_till_done()
state_heat = self.hass.states.get(self.HEAT_ENTITY)
state_cool = self.hass.states.get(self.COOL_ENTITY)
self.assertEqual(STATE_HEAT,
state_heat.attributes.get('operation_mode'))
self.assertEqual(STATE_COOL,
state_cool.attributes.get('operation_mode'))

def test_turn_off_when_on(self):
"""Test if climate.turn_off turns off a turned on device."""
climate.set_operation_mode(self.hass, STATE_HEAT, self.HEAT_ENTITY)
climate.set_operation_mode(self.hass, STATE_COOL, self.COOL_ENTITY)
self.hass.block_till_done()
self.hass.services.call('climate', SERVICE_TURN_OFF)
self.hass.block_till_done()
state_heat = self.hass.states.get(self.HEAT_ENTITY)
state_cool = self.hass.states.get(self.COOL_ENTITY)
self.assertEqual(STATE_OFF,
state_heat.attributes.get('operation_mode'))
self.assertEqual(STATE_OFF,
state_cool.attributes.get('operation_mode'))

def test_turn_off_when_off(self):
"""Test if climate.turn_off does nothing to a turned off device."""
climate.set_operation_mode(self.hass, STATE_OFF)
self.hass.block_till_done()
self.hass.services.call('climate', SERVICE_TURN_OFF)
self.hass.block_till_done()
state_heat = self.hass.states.get(self.HEAT_ENTITY)
state_cool = self.hass.states.get(self.COOL_ENTITY)
self.assertEqual(STATE_OFF,
state_heat.attributes.get('operation_mode'))
self.assertEqual(STATE_OFF,
state_cool.attributes.get('operation_mode'))


@asyncio.coroutine
def test_custom_setup_params(hass):
"""Test the setup with custom parameters."""
Expand Down