mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Merge branch 'heatcontroll_config' into dev
This commit is contained in:
commit
dd0424435a
@ -24,6 +24,9 @@ CONF_NAME = 'name'
|
|||||||
DEFAULT_NAME = 'Heat Control'
|
DEFAULT_NAME = 'Heat Control'
|
||||||
CONF_HEATER = 'heater'
|
CONF_HEATER = 'heater'
|
||||||
CONF_SENSOR = 'target_sensor'
|
CONF_SENSOR = 'target_sensor'
|
||||||
|
CONF_MIN_TEMP = 'min_temp'
|
||||||
|
CONF_MAX_TEMP = 'max_temp'
|
||||||
|
CONF_TARGET_TEMP = 'target_temp'
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -34,27 +37,34 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
name = config.get(CONF_NAME, DEFAULT_NAME)
|
name = config.get(CONF_NAME, DEFAULT_NAME)
|
||||||
heater_entity_id = config.get(CONF_HEATER)
|
heater_entity_id = config.get(CONF_HEATER)
|
||||||
sensor_entity_id = config.get(CONF_SENSOR)
|
sensor_entity_id = config.get(CONF_SENSOR)
|
||||||
|
min_temp = util.convert(config.get(CONF_MIN_TEMP), float, None)
|
||||||
|
max_temp = util.convert(config.get(CONF_MAX_TEMP), float, None)
|
||||||
|
target_temp = util.convert(config.get(CONF_TARGET_TEMP), float, None)
|
||||||
|
|
||||||
if None in (heater_entity_id, sensor_entity_id):
|
if None in (heater_entity_id, sensor_entity_id):
|
||||||
_LOGGER.error('Missing required key %s or %s', CONF_HEATER,
|
_LOGGER.error('Missing required key %s or %s', CONF_HEATER,
|
||||||
CONF_SENSOR)
|
CONF_SENSOR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
add_devices([HeatControl(hass, name, heater_entity_id, sensor_entity_id)])
|
add_devices([HeatControl(hass, name, heater_entity_id, sensor_entity_id,
|
||||||
|
min_temp, max_temp, target_temp)])
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-instance-attributes
|
# pylint: disable=too-many-instance-attributes
|
||||||
class HeatControl(ThermostatDevice):
|
class HeatControl(ThermostatDevice):
|
||||||
""" Represents a HeatControl device. """
|
""" Represents a HeatControl device. """
|
||||||
|
# pylint: disable=too-many-arguments
|
||||||
def __init__(self, hass, name, heater_entity_id, sensor_entity_id):
|
def __init__(self, hass, name, heater_entity_id, sensor_entity_id,
|
||||||
|
min_temp, max_temp, target_temp):
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self._name = name
|
self._name = name
|
||||||
self.heater_entity_id = heater_entity_id
|
self.heater_entity_id = heater_entity_id
|
||||||
|
|
||||||
self._active = False
|
self._active = False
|
||||||
self._cur_temp = None
|
self._cur_temp = None
|
||||||
self._target_temp = None
|
self._min_temp = min_temp
|
||||||
|
self._max_temp = max_temp
|
||||||
|
self._target_temp = target_temp
|
||||||
self._unit = None
|
self._unit = None
|
||||||
|
|
||||||
track_state_change(hass, sensor_entity_id, self._sensor_changed)
|
track_state_change(hass, sensor_entity_id, self._sensor_changed)
|
||||||
@ -79,6 +89,7 @@ class HeatControl(ThermostatDevice):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def current_temperature(self):
|
def current_temperature(self):
|
||||||
|
""" Returns the sensor temperature. """
|
||||||
return self._cur_temp
|
return self._cur_temp
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -97,6 +108,26 @@ class HeatControl(ThermostatDevice):
|
|||||||
self._control_heating()
|
self._control_heating()
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def min_temp(self):
|
||||||
|
""" Return minimum temperature. """
|
||||||
|
# pylint: disable=no-member
|
||||||
|
if self._min_temp:
|
||||||
|
return self._min_temp
|
||||||
|
else:
|
||||||
|
# get default temp from super class
|
||||||
|
return ThermostatDevice.min_temp.fget(self)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_temp(self):
|
||||||
|
""" Return maximum temperature. """
|
||||||
|
# pylint: disable=no-member
|
||||||
|
if self._min_temp:
|
||||||
|
return self._max_temp
|
||||||
|
else:
|
||||||
|
# get default temp from super class
|
||||||
|
return ThermostatDevice.max_temp.fget(self)
|
||||||
|
|
||||||
def _sensor_changed(self, entity_id, old_state, new_state):
|
def _sensor_changed(self, entity_id, old_state, new_state):
|
||||||
""" Called when temperature changes. """
|
""" Called when temperature changes. """
|
||||||
if new_state is None:
|
if new_state is None:
|
||||||
|
@ -21,6 +21,9 @@ from homeassistant.components import switch, thermostat
|
|||||||
entity = 'thermostat.test'
|
entity = 'thermostat.test'
|
||||||
ent_sensor = 'sensor.test'
|
ent_sensor = 'sensor.test'
|
||||||
ent_switch = 'switch.test'
|
ent_switch = 'switch.test'
|
||||||
|
min_temp = 3.0
|
||||||
|
max_temp = 65.0
|
||||||
|
target_temp = 42.0
|
||||||
|
|
||||||
|
|
||||||
class TestThermostatHeatControl(unittest.TestCase):
|
class TestThermostatHeatControl(unittest.TestCase):
|
||||||
@ -43,6 +46,28 @@ class TestThermostatHeatControl(unittest.TestCase):
|
|||||||
def test_setup_defaults_to_unknown(self):
|
def test_setup_defaults_to_unknown(self):
|
||||||
self.assertEqual('unknown', self.hass.states.get(entity).state)
|
self.assertEqual('unknown', self.hass.states.get(entity).state)
|
||||||
|
|
||||||
|
def test_default_setup_params(self):
|
||||||
|
state = self.hass.states.get(entity)
|
||||||
|
self.assertEqual(7, state.attributes.get('min_temp'))
|
||||||
|
self.assertEqual(35, state.attributes.get('max_temp'))
|
||||||
|
self.assertEqual(None, state.attributes.get('temperature'))
|
||||||
|
|
||||||
|
def test_custom_setup_params(self):
|
||||||
|
thermostat.setup(self.hass, {'thermostat': {
|
||||||
|
'platform': 'heat_control',
|
||||||
|
'name': 'test',
|
||||||
|
'heater': ent_switch,
|
||||||
|
'target_sensor': ent_sensor,
|
||||||
|
'min_temp': min_temp,
|
||||||
|
'max_temp': max_temp,
|
||||||
|
'target_temp': target_temp
|
||||||
|
}})
|
||||||
|
state = self.hass.states.get(entity)
|
||||||
|
self.assertEqual(min_temp, state.attributes.get('min_temp'))
|
||||||
|
self.assertEqual(max_temp, state.attributes.get('max_temp'))
|
||||||
|
self.assertEqual(target_temp, state.attributes.get('temperature'))
|
||||||
|
self.assertEqual(str(target_temp), self.hass.states.get(entity).state)
|
||||||
|
|
||||||
def test_set_target_temp(self):
|
def test_set_target_temp(self):
|
||||||
thermostat.set_temperature(self.hass, 30)
|
thermostat.set_temperature(self.hass, 30)
|
||||||
self.hass.pool.block_till_done()
|
self.hass.pool.block_till_done()
|
||||||
@ -113,3 +138,4 @@ class TestThermostatHeatControl(unittest.TestCase):
|
|||||||
|
|
||||||
self.hass.services.register('switch', SERVICE_TURN_ON, log_call)
|
self.hass.services.register('switch', SERVICE_TURN_ON, log_call)
|
||||||
self.hass.services.register('switch', SERVICE_TURN_OFF, log_call)
|
self.hass.services.register('switch', SERVICE_TURN_OFF, log_call)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user