From cbb390a918f62f2bdef6a8cceda327f0024bb45e Mon Sep 17 00:00:00 2001 From: Daniel Hoyer Iversen Date: Thu, 23 Jul 2015 18:13:46 +0200 Subject: [PATCH 1/2] Custom min/max temperature for thermostat --- .../components/thermostat/__init__.py | 20 ++++++++++++++++++- .../components/thermostat/heat_control.py | 20 ++++++++++--------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/thermostat/__init__.py b/homeassistant/components/thermostat/__init__.py index 08940b977c9..dffa7dfcc26 100644 --- a/homeassistant/components/thermostat/__init__.py +++ b/homeassistant/components/thermostat/__init__.py @@ -11,7 +11,7 @@ from homeassistant.helpers.entity_component import EntityComponent import homeassistant.util as util from homeassistant.helpers.entity import Entity from homeassistant.const import ( - ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_ON, STATE_OFF) + ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_ON, STATE_OFF, TEMP_CELCIUS) DOMAIN = "thermostat" DEPENDENCIES = [] @@ -24,6 +24,8 @@ SERVICE_SET_TEMPERATURE = "set_temperature" ATTR_CURRENT_TEMPERATURE = "current_temperature" ATTR_AWAY_MODE = "away_mode" +ATTR_MAX_TEMP = "max_temp" +ATTR_MIN_TEMP = "min_temp" _LOGGER = logging.getLogger(__name__) @@ -131,6 +133,22 @@ class ThermostatDevice(Entity): if device_attr is not None: data.update(device_attr) + if hasattr(self, ATTR_MIN_TEMP): + min_temp = self.hass.config.temperature( + getattr(self, ATTR_MIN_TEMP), self.unit_of_measurement)[0] + else: + min_temp = self.hass.config.temperature( + 7, TEMP_CELCIUS)[0] + data[ATTR_MIN_TEMP] = min_temp + + if hasattr(self, ATTR_MAX_TEMP): + max_temp = self.hass.config.temperature( + getattr(self, ATTR_MAX_TEMP), self.unit_of_measurement)[0] + else: + max_temp = self.hass.config.temperature( + 35, TEMP_CELCIUS)[0] + data[ATTR_MAX_TEMP] = max_temp + return data @property diff --git a/homeassistant/components/thermostat/heat_control.py b/homeassistant/components/thermostat/heat_control.py index d21245dae3a..273f1173da8 100644 --- a/homeassistant/components/thermostat/heat_control.py +++ b/homeassistant/components/thermostat/heat_control.py @@ -90,16 +90,18 @@ class HeatControl(ThermostatDevice): self.target_sensor_entity_id = config.get("target_sensor") self.time_temp = [] - for time_temp in list(config.get("time_temp").split(",")): - time, temp = time_temp.split(':') - time_start, time_end = time.split('-') - start_time = datetime.datetime.time(datetime.datetime. - strptime(time_start, '%H%M')) - end_time = datetime.datetime.time(datetime.datetime. - strptime(time_end, '%H%M')) - self.time_temp.append((start_time, end_time, float(temp))) + if config.get("time_temp"): + for time_temp in list(config.get("time_temp").split(",")): + time, temp = time_temp.split(':') + time_start, time_end = time.split('-') + start_time = datetime.datetime.time( + datetime.datetime.strptime(time_start, '%H%M')) + end_time = datetime.datetime.time( + datetime.datetime.strptime(time_end, '%H%M')) + self.time_temp.append((start_time, end_time, float(temp))) self.min_temp = float(config.get("min_temp")) + self.max_temp = float(config.get("max_temp")) self._manual_sat_temp = None self._away = False @@ -178,7 +180,7 @@ class HeatControl(ThermostatDevice): if not self._heater_manual_changed: pass else: - self.set_temperature(100) + self.set_temperature(self.max_temp) self._heater_manual_changed = True From be937a795aaf2ea144c4cf8d8fb7004834f31333 Mon Sep 17 00:00:00 2001 From: Daniel Hoyer Iversen Date: Thu, 23 Jul 2015 22:15:17 +0200 Subject: [PATCH 2/2] Min max temp for thermostat --- .../components/thermostat/__init__.py | 27 +++++++++---------- .../components/thermostat/heat_control.py | 15 +++++++++-- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/thermostat/__init__.py b/homeassistant/components/thermostat/__init__.py index dffa7dfcc26..40e392709f2 100644 --- a/homeassistant/components/thermostat/__init__.py +++ b/homeassistant/components/thermostat/__init__.py @@ -133,21 +133,8 @@ class ThermostatDevice(Entity): if device_attr is not None: data.update(device_attr) - if hasattr(self, ATTR_MIN_TEMP): - min_temp = self.hass.config.temperature( - getattr(self, ATTR_MIN_TEMP), self.unit_of_measurement)[0] - else: - min_temp = self.hass.config.temperature( - 7, TEMP_CELCIUS)[0] - data[ATTR_MIN_TEMP] = min_temp - - if hasattr(self, ATTR_MAX_TEMP): - max_temp = self.hass.config.temperature( - getattr(self, ATTR_MAX_TEMP), self.unit_of_measurement)[0] - else: - max_temp = self.hass.config.temperature( - 35, TEMP_CELCIUS)[0] - data[ATTR_MAX_TEMP] = max_temp + data[ATTR_MIN_TEMP] = self.min_temp + data[ATTR_MAX_TEMP] = self.max_temp return data @@ -180,3 +167,13 @@ class ThermostatDevice(Entity): def turn_away_mode_off(self): """ Turns away mode off. """ pass + + @property + def min_temp(self): + """ Return minimum temperature. """ + return self.hass.config.temperature(7, TEMP_CELCIUS)[0] + + @property + def max_temp(self): + """ Return maxmum temperature. """ + return self.hass.config.temperature(35, TEMP_CELCIUS)[0] diff --git a/homeassistant/components/thermostat/heat_control.py b/homeassistant/components/thermostat/heat_control.py index 273f1173da8..54e7cc3e3a5 100644 --- a/homeassistant/components/thermostat/heat_control.py +++ b/homeassistant/components/thermostat/heat_control.py @@ -62,6 +62,7 @@ import logging import datetime import homeassistant.components as core +import homeassistant.util as util from homeassistant.components.thermostat import ThermostatDevice from homeassistant.const import TEMP_CELCIUS, STATE_ON, STATE_OFF @@ -100,8 +101,8 @@ class HeatControl(ThermostatDevice): datetime.datetime.strptime(time_end, '%H%M')) self.time_temp.append((start_time, end_time, float(temp))) - self.min_temp = float(config.get("min_temp")) - self.max_temp = float(config.get("max_temp")) + self._min_temp = util.convert(config.get("min_temp"), float, 0) + self._max_temp = util.convert(config.get("max_temp"), float, 100) self._manual_sat_temp = None self._away = False @@ -196,3 +197,13 @@ class HeatControl(ThermostatDevice): def turn_away_mode_off(self): """ Turns away mode off. """ self._away = False + + @property + def min_temp(self): + """ Return minimum temperature. """ + return self._min_temp + + @property + def max_temp(self): + """ Return maxmum temperature. """ + return self._max_temp