Ignore min_cycle_duration when manually controlling the thermostat. (#16128)

* Ignore min_cycle_duration when manually controlling the thermostat.

* style

* Generic thermostat: add minimum cycle duration to keep-alive tests.

There was a bug in previous versions of the code, that would not execute
the keep-alive action if the minimum cycle duration hasn't passed.
This test verifies that the keep-alive action is executed correctly.

* Generic thermostat: added tests to verify that changing the
thermostat mode manually triggers the switch, regardless of
minimum cycle duration.

* Updated tests to use `common` module instead of the deprecated `climate`
This commit is contained in:
Lev Aronsky authored and Paulus Schoutsen committed 2018-11-01 21:25:50 +01:00
1 parent e9ae862fca
commit 02b46e2ba3
2 files changed
+87 -16

No files matched your search

@@ -623,6 +623,38 @@ class TestClimateGenericThermostatACModeMinCycle(unittest.TestCase):
assert SERVICE_TURN_OFF == call.service
assert ENT_SWITCH == call.data['entity_id']
def test_mode_change_ac_trigger_off_not_long_enough(self):
"""Test if mode change turns ac off despite minimum cycle."""
self._setup_switch(True)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
self._setup_sensor(25)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
common.set_operation_mode(self.hass, climate.STATE_OFF)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('homeassistant', call.domain)
self.assertEqual(SERVICE_TURN_OFF, call.service)
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
def test_mode_change_ac_trigger_on_not_long_enough(self):
"""Test if mode change turns ac on despite minimum cycle."""
self._setup_switch(False)
common.set_temperature(self.hass, 25)
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
common.set_operation_mode(self.hass, climate.STATE_HEAT)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('homeassistant', call.domain)
self.assertEqual(SERVICE_TURN_ON, call.service)
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
def _setup_sensor(self, temp):
"""Set up the test sensor."""
self.hass.states.set(ENT_SENSOR, temp)
@@ -714,6 +746,38 @@ class TestClimateGenericThermostatMinCycle(unittest.TestCase):
assert SERVICE_TURN_OFF == call.service
assert ENT_SWITCH == call.data['entity_id']
def test_mode_change_heater_trigger_off_not_long_enough(self):
"""Test if mode change turns heater off despite minimum cycle."""
self._setup_switch(True)
common.set_temperature(self.hass, 25)
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
common.set_operation_mode(self.hass, climate.STATE_OFF)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('homeassistant', call.domain)
self.assertEqual(SERVICE_TURN_OFF, call.service)
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
def test_mode_change_heater_trigger_on_not_long_enough(self):
"""Test if mode change turns heater on despite minimum cycle."""
self._setup_switch(False)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
self._setup_sensor(25)
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
common.set_operation_mode(self.hass, climate.STATE_HEAT)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('homeassistant', call.domain)
self.assertEqual(SERVICE_TURN_ON, call.service)
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
def _setup_sensor(self, temp):
"""Set up the test sensor."""
self.hass.states.set(ENT_SENSOR, temp)
@@ -748,6 +812,7 @@ class TestClimateGenericThermostatACKeepAlive(unittest.TestCase):
'target_temp': 25,
'target_sensor': ENT_SENSOR,
'ac_mode': True,
'min_cycle_duration': datetime.timedelta(minutes=15),
'keep_alive': datetime.timedelta(minutes=10)
}})
@@ -838,6 +903,7 @@ class TestClimateGenericThermostatKeepAlive(unittest.TestCase):
'target_temp': 25,
'heater': ENT_SWITCH,
'target_sensor': ENT_SENSOR,
'min_cycle_duration': datetime.timedelta(minutes=15),
'keep_alive': datetime.timedelta(minutes=10)
}})