mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Update heat_control.py
This commit is contained in:
parent
90eab17ea6
commit
ac59847120
@ -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,32 @@ 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. """
|
||||||
|
|
||||||
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)
|
||||||
@ -97,6 +105,22 @@ 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. """
|
||||||
|
if self._min_temp:
|
||||||
|
return self._min_temp
|
||||||
|
else:
|
||||||
|
return ThermostatDevice.min_temp.fget(self)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_temp(self):
|
||||||
|
""" Return maximum temperature. """
|
||||||
|
if self._min_temp:
|
||||||
|
return self._max_temp
|
||||||
|
else:
|
||||||
|
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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user