mirror of
https://github.com/home-assistant/core.git
synced 2025-06-19 12:37:06 +00:00
[climate.generic_thermostat] Make tolerance work both ways (#4830)
This commit is contained in:
parent
64de1c9777
commit
167260bcc6
@ -198,24 +198,30 @@ class GenericThermostat(ClimateDevice):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.ac_mode:
|
if self.ac_mode:
|
||||||
too_hot = self._cur_temp - self._target_temp > self._tolerance
|
|
||||||
is_cooling = self._is_device_active
|
is_cooling = self._is_device_active
|
||||||
if too_hot and not is_cooling:
|
if is_cooling:
|
||||||
_LOGGER.info('Turning on AC %s', self.heater_entity_id)
|
too_cold = self._target_temp - self._cur_temp > self._tolerance
|
||||||
switch.turn_on(self.hass, self.heater_entity_id)
|
if too_cold:
|
||||||
elif not too_hot and is_cooling:
|
_LOGGER.info('Turning off AC %s', self.heater_entity_id)
|
||||||
_LOGGER.info('Turning off AC %s', self.heater_entity_id)
|
switch.turn_off(self.hass, self.heater_entity_id)
|
||||||
switch.turn_off(self.hass, self.heater_entity_id)
|
else:
|
||||||
|
too_hot = self._cur_temp - self._target_temp > self._tolerance
|
||||||
|
if too_hot:
|
||||||
|
_LOGGER.info('Turning on AC %s', self.heater_entity_id)
|
||||||
|
switch.turn_on(self.hass, self.heater_entity_id)
|
||||||
else:
|
else:
|
||||||
too_cold = self._target_temp - self._cur_temp > self._tolerance
|
|
||||||
is_heating = self._is_device_active
|
is_heating = self._is_device_active
|
||||||
|
if is_heating:
|
||||||
if too_cold and not is_heating:
|
too_hot = self._cur_temp - self._target_temp > self._tolerance
|
||||||
_LOGGER.info('Turning on heater %s', self.heater_entity_id)
|
if too_hot:
|
||||||
switch.turn_on(self.hass, self.heater_entity_id)
|
_LOGGER.info('Turning off heater %s',
|
||||||
elif not too_cold and is_heating:
|
self.heater_entity_id)
|
||||||
_LOGGER.info('Turning off heater %s', self.heater_entity_id)
|
switch.turn_off(self.hass, self.heater_entity_id)
|
||||||
switch.turn_off(self.hass, self.heater_entity_id)
|
else:
|
||||||
|
too_cold = self._target_temp - self._cur_temp > self._tolerance
|
||||||
|
if too_cold:
|
||||||
|
_LOGGER.info('Turning on heater %s', self.heater_entity_id)
|
||||||
|
switch.turn_on(self.hass, self.heater_entity_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _is_device_active(self):
|
def _is_device_active(self):
|
||||||
|
@ -181,34 +181,10 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
|||||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||||
|
|
||||||
def test_set_temp_change_heater_on(self):
|
|
||||||
"""Test if temperature change turn heater on."""
|
|
||||||
self._setup_switch(False)
|
|
||||||
climate.set_temperature(self.hass, 30)
|
|
||||||
self.hass.block_till_done()
|
|
||||||
self._setup_sensor(25)
|
|
||||||
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 test_temp_change_heater_off(self):
|
|
||||||
"""Test if temperature change turn heater off."""
|
|
||||||
self._setup_switch(True)
|
|
||||||
climate.set_temperature(self.hass, 25)
|
|
||||||
self.hass.block_till_done()
|
|
||||||
self._setup_sensor(30)
|
|
||||||
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_temp_change_heater_on_within_tolerance(self):
|
def test_temp_change_heater_on_within_tolerance(self):
|
||||||
"""Test if temperature change turn heater on within tolerance."""
|
"""Test if temperature change doesn't turn heater on within
|
||||||
|
tolerance.
|
||||||
|
"""
|
||||||
self._setup_switch(False)
|
self._setup_switch(False)
|
||||||
climate.set_temperature(self.hass, 30)
|
climate.set_temperature(self.hass, 30)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
@ -217,9 +193,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
|||||||
self.assertEqual(0, len(self.calls))
|
self.assertEqual(0, len(self.calls))
|
||||||
|
|
||||||
def test_temp_change_heater_on_outside_tolerance(self):
|
def test_temp_change_heater_on_outside_tolerance(self):
|
||||||
"""Test if temperature change doesn't turn heater on outside
|
"""Test if temperature change turn heater on outside tolerance."""
|
||||||
tolerance.
|
|
||||||
"""
|
|
||||||
self._setup_switch(False)
|
self._setup_switch(False)
|
||||||
climate.set_temperature(self.hass, 30)
|
climate.set_temperature(self.hass, 30)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
@ -231,6 +205,30 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
|||||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
self.assertEqual(SERVICE_TURN_ON, call.service)
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||||
|
|
||||||
|
def test_temp_change_heater_off_within_tolerance(self):
|
||||||
|
"""Test if temperature change doesn't turn heater off within
|
||||||
|
tolerance.
|
||||||
|
"""
|
||||||
|
self._setup_switch(True)
|
||||||
|
climate.set_temperature(self.hass, 30)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
self._setup_sensor(31)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
self.assertEqual(0, len(self.calls))
|
||||||
|
|
||||||
|
def test_temp_change_heater_off_outside_tolerance(self):
|
||||||
|
"""Test if temperature change turn heater off outside tolerance."""
|
||||||
|
self._setup_switch(True)
|
||||||
|
climate.set_temperature(self.hass, 30)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
self._setup_sensor(35)
|
||||||
|
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 _setup_sensor(self, temp, unit=TEMP_CELSIUS):
|
def _setup_sensor(self, temp, unit=TEMP_CELSIUS):
|
||||||
"""Setup the test sensor."""
|
"""Setup the test sensor."""
|
||||||
self.hass.states.set(ENT_SENSOR, temp, {
|
self.hass.states.set(ENT_SENSOR, temp, {
|
||||||
@ -297,7 +295,18 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
|
|||||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
self.assertEqual(SERVICE_TURN_ON, call.service)
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||||
|
|
||||||
def test_set_temp_change_ac_off(self):
|
def test_temp_change_ac_off_within_tolerance(self):
|
||||||
|
"""Test if temperature change doesn't turn ac off within
|
||||||
|
tolerance.
|
||||||
|
"""
|
||||||
|
self._setup_switch(True)
|
||||||
|
climate.set_temperature(self.hass, 30)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
self._setup_sensor(29.8)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
self.assertEqual(0, len(self.calls))
|
||||||
|
|
||||||
|
def test_set_temp_change_ac_off_outside_tolerance(self):
|
||||||
"""Test if temperature change turn ac off."""
|
"""Test if temperature change turn ac off."""
|
||||||
self._setup_switch(True)
|
self._setup_switch(True)
|
||||||
climate.set_temperature(self.hass, 30)
|
climate.set_temperature(self.hass, 30)
|
||||||
@ -310,7 +319,18 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
|
|||||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
||||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||||
|
|
||||||
def test_temp_change_ac_on(self):
|
def test_temp_change_ac_on_within_tolerance(self):
|
||||||
|
"""Test if temperature change doesn't turn ac on within
|
||||||
|
tolerance.
|
||||||
|
"""
|
||||||
|
self._setup_switch(False)
|
||||||
|
climate.set_temperature(self.hass, 25)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
self._setup_sensor(25.2)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
self.assertEqual(0, len(self.calls))
|
||||||
|
|
||||||
|
def test_temp_change_ac_on_outside_tolerance(self):
|
||||||
"""Test if temperature change turn ac on."""
|
"""Test if temperature change turn ac on."""
|
||||||
self._setup_switch(False)
|
self._setup_switch(False)
|
||||||
climate.set_temperature(self.hass, 25)
|
climate.set_temperature(self.hass, 25)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user