From ac598471209a96f980460036df9ca625eee3feed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B8yer=20Iversen?= Date: Mon, 30 Nov 2015 09:14:32 +0100 Subject: [PATCH 1/7] Update heat_control.py --- .../components/thermostat/heat_control.py | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/thermostat/heat_control.py b/homeassistant/components/thermostat/heat_control.py index 7080528fd17..66992e223a0 100644 --- a/homeassistant/components/thermostat/heat_control.py +++ b/homeassistant/components/thermostat/heat_control.py @@ -24,6 +24,9 @@ CONF_NAME = 'name' DEFAULT_NAME = 'Heat Control' CONF_HEATER = 'heater' CONF_SENSOR = 'target_sensor' +CONF_MIN_TEMP = 'min_temp' +CONF_MAX_TEMP = 'max_temp' +CONF_TARGET_TEMP = 'target_temp' _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) heater_entity_id = config.get(CONF_HEATER) 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): _LOGGER.error('Missing required key %s or %s', CONF_HEATER, CONF_SENSOR) 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 class HeatControl(ThermostatDevice): """ 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._name = name self.heater_entity_id = heater_entity_id self._active = False 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 track_state_change(hass, sensor_entity_id, self._sensor_changed) @@ -97,6 +105,22 @@ class HeatControl(ThermostatDevice): self._control_heating() 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): """ Called when temperature changes. """ if new_state is None: From 2732b2030545a857e3e419051b8832c9c2b3e789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B8yer=20Iversen?= Date: Mon, 30 Nov 2015 09:22:04 +0100 Subject: [PATCH 2/7] style fix in heatcontrol --- homeassistant/components/thermostat/heat_control.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/thermostat/heat_control.py b/homeassistant/components/thermostat/heat_control.py index 66992e223a0..93326be384a 100644 --- a/homeassistant/components/thermostat/heat_control.py +++ b/homeassistant/components/thermostat/heat_control.py @@ -46,14 +46,16 @@ def setup_platform(hass, config, add_devices, discovery_info=None): CONF_SENSOR) return False - add_devices([HeatControl(hass, name, heater_entity_id, sensor_entity_id, min_temp, max_temp, target_temp)]) + add_devices([HeatControl(hass, name, heater_entity_id, sensor_entity_id, + min_temp, max_temp, target_temp)]) # pylint: disable=too-many-instance-attributes class HeatControl(ThermostatDevice): """ Represents a HeatControl device. """ - def __init__(self, hass, name, heater_entity_id, sensor_entity_id, min_temp, max_temp, target_temp): + def __init__(self, hass, name, heater_entity_id, sensor_entity_id, + min_temp, max_temp, target_temp): self.hass = hass self._name = name self.heater_entity_id = heater_entity_id @@ -111,6 +113,7 @@ class HeatControl(ThermostatDevice): if self._min_temp: return self._min_temp else: + # pylint: disable=no-member return ThermostatDevice.min_temp.fget(self) @property @@ -119,6 +122,7 @@ class HeatControl(ThermostatDevice): if self._min_temp: return self._max_temp else: + # pylint: disable=no-member return ThermostatDevice.max_temp.fget(self) def _sensor_changed(self, entity_id, old_state, new_state): From 8fee38f2cd22bc1719184ab9ac22a2381b54045b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B8yer=20Iversen?= Date: Mon, 30 Nov 2015 10:05:05 +0100 Subject: [PATCH 3/7] style fix in heat control --- homeassistant/components/thermostat/heat_control.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/thermostat/heat_control.py b/homeassistant/components/thermostat/heat_control.py index 93326be384a..7ee548be53c 100644 --- a/homeassistant/components/thermostat/heat_control.py +++ b/homeassistant/components/thermostat/heat_control.py @@ -46,8 +46,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): CONF_SENSOR) return False - add_devices([HeatControl(hass, name, heater_entity_id, sensor_entity_id, - min_temp, max_temp, target_temp)]) + add_devices([HeatControl(hass, name, heater_entity_id, sensor_entity_id, + min_temp, max_temp, target_temp)]) # pylint: disable=too-many-instance-attributes @@ -55,7 +55,7 @@ class HeatControl(ThermostatDevice): """ Represents a HeatControl device. """ def __init__(self, hass, name, heater_entity_id, sensor_entity_id, - min_temp, max_temp, target_temp): + min_temp, max_temp, target_temp): self.hass = hass self._name = name self.heater_entity_id = heater_entity_id @@ -89,6 +89,7 @@ class HeatControl(ThermostatDevice): @property def current_temperature(self): + """ Returns the sensor temperature. """ return self._cur_temp @property @@ -113,7 +114,7 @@ class HeatControl(ThermostatDevice): if self._min_temp: return self._min_temp else: - # pylint: disable=no-member + # pylint: disable=no-member return ThermostatDevice.min_temp.fget(self) @property @@ -122,7 +123,7 @@ class HeatControl(ThermostatDevice): if self._min_temp: return self._max_temp else: - # pylint: disable=no-member + # pylint: disable=no-member return ThermostatDevice.max_temp.fget(self) def _sensor_changed(self, entity_id, old_state, new_state): From 758c0aae24b08efb64f0729ccfb0196bab2e5cd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B8yer=20Iversen?= Date: Mon, 30 Nov 2015 10:32:32 +0100 Subject: [PATCH 4/7] Update heat_control.py --- homeassistant/components/thermostat/heat_control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/thermostat/heat_control.py b/homeassistant/components/thermostat/heat_control.py index 7ee548be53c..7c8db91265b 100644 --- a/homeassistant/components/thermostat/heat_control.py +++ b/homeassistant/components/thermostat/heat_control.py @@ -53,7 +53,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): # pylint: disable=too-many-instance-attributes class HeatControl(ThermostatDevice): """ Represents a HeatControl device. """ - + # pylint: disable=too-many-arguments def __init__(self, hass, name, heater_entity_id, sensor_entity_id, min_temp, max_temp, target_temp): self.hass = hass From 2e89f0a8c7bf80ca8d1d3b1ffcd5979586cb3b87 Mon Sep 17 00:00:00 2001 From: Daniel Hoyer Iversen Date: Mon, 30 Nov 2015 11:45:09 +0100 Subject: [PATCH 5/7] style fix in heat control --- .../components/frontend/www_static/home-assistant-polymer | 2 +- homeassistant/components/thermostat/heat_control.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/frontend/www_static/home-assistant-polymer b/homeassistant/components/frontend/www_static/home-assistant-polymer index 300f3582a61..c130933f452 160000 --- a/homeassistant/components/frontend/www_static/home-assistant-polymer +++ b/homeassistant/components/frontend/www_static/home-assistant-polymer @@ -1 +1 @@ -Subproject commit 300f3582a61b5781431778cd2f44bef05d49baf3 +Subproject commit c130933f45262dd1c7b4fd75d23a90c132fb271f diff --git a/homeassistant/components/thermostat/heat_control.py b/homeassistant/components/thermostat/heat_control.py index 7c8db91265b..7e560a2276f 100644 --- a/homeassistant/components/thermostat/heat_control.py +++ b/homeassistant/components/thermostat/heat_control.py @@ -111,19 +111,21 @@ class HeatControl(ThermostatDevice): @property def min_temp(self): """ Return minimum temperature. """ + # pylint: disable=no-member if self._min_temp: return self._min_temp else: - # pylint: disable=no-member + # 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: - # pylint: disable=no-member + # get default temp from super class return ThermostatDevice.max_temp.fget(self) def _sensor_changed(self, entity_id, old_state, new_state): From d6cac08be66b71912d0d475c6ed9a1e63a61691a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B8yer=20Iversen?= Date: Mon, 30 Nov 2015 11:46:14 +0100 Subject: [PATCH 6/7] Update heat_control.py --- homeassistant/components/thermostat/heat_control.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/thermostat/heat_control.py b/homeassistant/components/thermostat/heat_control.py index 7c8db91265b..7e560a2276f 100644 --- a/homeassistant/components/thermostat/heat_control.py +++ b/homeassistant/components/thermostat/heat_control.py @@ -111,19 +111,21 @@ class HeatControl(ThermostatDevice): @property def min_temp(self): """ Return minimum temperature. """ + # pylint: disable=no-member if self._min_temp: return self._min_temp else: - # pylint: disable=no-member + # 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: - # pylint: disable=no-member + # get default temp from super class return ThermostatDevice.max_temp.fget(self) def _sensor_changed(self, entity_id, old_state, new_state): From 0025e67b051047d1a6947c96cc7cf56c85aa54ca Mon Sep 17 00:00:00 2001 From: Daniel Hoyer Iversen Date: Tue, 1 Dec 2015 11:09:22 +0100 Subject: [PATCH 7/7] Added test to heat control --- .../thermostat/test_heat_control.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/components/thermostat/test_heat_control.py b/tests/components/thermostat/test_heat_control.py index f0b487ae86c..4ec305574e2 100644 --- a/tests/components/thermostat/test_heat_control.py +++ b/tests/components/thermostat/test_heat_control.py @@ -21,6 +21,9 @@ from homeassistant.components import switch, thermostat entity = 'thermostat.test' ent_sensor = 'sensor.test' ent_switch = 'switch.test' +min_temp = 3.0 +max_temp = 65.0 +target_temp = 42.0 class TestThermostatHeatControl(unittest.TestCase): @@ -43,6 +46,28 @@ class TestThermostatHeatControl(unittest.TestCase): def test_setup_defaults_to_unknown(self): 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): thermostat.set_temperature(self.hass, 30) 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_OFF, log_call) +