Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change generic thermostat to control heating on mode change Off -> Auto #10601

Merged
merged 2 commits into from
Nov 16, 2017
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
1 change: 1 addition & 0 deletions homeassistant/components/climate/generic_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def set_operation_mode(self, operation_mode):
"""Set operation mode."""
if operation_mode == STATE_AUTO:
self._enabled = True
self._async_control_heating()
elif operation_mode == STATE_OFF:
self._enabled = False
if self._is_device_active:
Expand Down
44 changes: 36 additions & 8 deletions tests/components/climate/test_generic_thermostat.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""The tests for the generic_thermostat."""
import asyncio
import datetime
import pytz
import unittest
from unittest import mock
import pytz

import homeassistant.core as ha
from homeassistant.core import callback
Expand Down Expand Up @@ -54,13 +54,16 @@ def test_setup_missing_conf(self):
'climate': config})

def test_valid_conf(self):
"""Test set up genreic_thermostat with valid config values."""
self.assertTrue(setup_component(self.hass, 'climate',
{'climate': {
'platform': 'generic_thermostat',
'name': 'test',
'heater': ENT_SWITCH,
'target_sensor': ENT_SENSOR}}))
"""Test set up generic_thermostat with valid config values."""
self.assertTrue(
setup_component(self.hass, 'climate',
{'climate': {
'platform': 'generic_thermostat',
'name': 'test',
'heater': ENT_SWITCH,
'target_sensor': ENT_SENSOR
}})
)

def test_setup_with_sensor(self):
"""Test set up heat_control with sensor to trigger update at init."""
Expand Down Expand Up @@ -243,6 +246,31 @@ def test_no_state_change_when_operation_mode_off(self):
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))

@mock.patch('logging.Logger.error')
def test_invalid_operating_mode(self, log_mock):
"""Test error handling for invalid operation mode."""
climate.set_operation_mode(self.hass, 'invalid mode')
self.hass.block_till_done()
self.assertEqual(log_mock.call_count, 1)

def test_operating_mode_auto(self):
"""Test change mode from OFF to AUTO.

Switch turns on when temp below setpoint and mode changes.
"""
climate.set_operation_mode(self.hass, STATE_OFF)
climate.set_temperature(self.hass, 30)
self._setup_sensor(25)
self.hass.block_till_done()
self._setup_switch(False)
climate.set_operation_mode(self.hass, climate.STATE_AUTO)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)
self.assertEqual(SERVICE_TURN_ON, call.service)
self.assertEqual(ENT_SWITCH, call.data['entity_id'])

def _setup_sensor(self, temp, unit=TEMP_CELSIUS):
"""Setup the test sensor."""
self.hass.states.set(ENT_SENSOR, temp, {
Expand Down