From c703c89dbd0fea0b10dbddcf5f02d587c467f1a3 Mon Sep 17 00:00:00 2001 From: sander Date: Fri, 1 Jan 2016 15:29:58 +0100 Subject: [PATCH 1/6] implement away mode --- .../components/thermostat/honeywell.py | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/thermostat/honeywell.py b/homeassistant/components/thermostat/honeywell.py index 4139c5d8aa7..15162a4d279 100644 --- a/homeassistant/components/thermostat/honeywell.py +++ b/homeassistant/components/thermostat/honeywell.py @@ -6,8 +6,9 @@ Adds support for Honeywell Round Connected and Honeywell Evohome thermostats. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/thermostat.honeywell/ """ -import socket import logging +import socket + from homeassistant.components.thermostat import ThermostatDevice from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, TEMP_CELCIUS) @@ -15,6 +16,7 @@ REQUIREMENTS = ['evohomeclient==0.2.4'] _LOGGER = logging.getLogger(__name__) +CONF_AWAY_TEMP = "away_temperature" # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): @@ -23,20 +25,25 @@ def setup_platform(hass, config, add_devices, discovery_info=None): username = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) - + try: + away_temp = float(config.get(CONF_AWAY_TEMP,16)) + except ValueError: + _LOGGER.error("value entered for item {} should convert to a number" + .format(CONF_AWAY_TEMP)) if username is None or password is None: _LOGGER.error("Missing required configuration items %s or %s", CONF_USERNAME, CONF_PASSWORD) return False evo_api = EvohomeClient(username, password) + try: zones = evo_api.temperatures(force_refresh=True) for i, zone in enumerate(zones): - add_devices([RoundThermostat(evo_api, zone['id'], i == 0)]) + add_devices([RoundThermostat(evo_api, zone['id'], i == 0,away_temp)]) except socket.error: _LOGGER.error( - "Connection error logging into the honeywell evohome web service" + "Connection error logging into the honeywell evohome web service" ) return False @@ -44,7 +51,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class RoundThermostat(ThermostatDevice): """ Represents a Honeywell Round Connected thermostat. """ - def __init__(self, device, zone_id, master): + def __init__(self, device, zone_id, master, away_temp): self.device = device self._current_temperature = None self._target_temperature = None @@ -52,6 +59,8 @@ class RoundThermostat(ThermostatDevice): self._id = zone_id self._master = master self._is_dhw = False + self._away_temp = away_temp + self._away = False self.update() @property @@ -80,6 +89,25 @@ class RoundThermostat(ThermostatDevice): """ Set new target temperature """ self.device.set_temperature(self._name, temperature) + @property + def is_away_mode_on(self): + """ Returns if away mode is on. """ + return self._away + + def turn_away_mode_on(self): + """ Turns away on. + Evohome does have a proprietary away mode, but it doesn't really work + the way it should. For example: If you set a temperature manually + it doesn't get overwritten when away mode is switched on. + """ + self._away = True + self.device.set_temperature(self._name, self._away_temp) + + def turn_away_mode_off(self): + """ Turns away off. """ + self._away = False + self.device.cancel_temp_override(self._name) + def update(self): try: # Only refresh if this is the "master" device, From 8f2ca856c7bec90b55f788dc97ea09bd1c621259 Mon Sep 17 00:00:00 2001 From: sander Date: Sat, 2 Jan 2016 11:56:07 +0100 Subject: [PATCH 2/6] added return False --- homeassistant/components/thermostat/honeywell.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/thermostat/honeywell.py b/homeassistant/components/thermostat/honeywell.py index 15162a4d279..de6d5ff6a56 100644 --- a/homeassistant/components/thermostat/honeywell.py +++ b/homeassistant/components/thermostat/honeywell.py @@ -18,6 +18,7 @@ _LOGGER = logging.getLogger(__name__) CONF_AWAY_TEMP = "away_temperature" + # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): """ Sets up the honeywel thermostat. """ @@ -26,10 +27,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None): username = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) try: - away_temp = float(config.get(CONF_AWAY_TEMP,16)) + away_temp = float(config.get(CONF_AWAY_TEMP, 16)) except ValueError: _LOGGER.error("value entered for item {} should convert to a number" .format(CONF_AWAY_TEMP)) + return False if username is None or password is None: _LOGGER.error("Missing required configuration items %s or %s", CONF_USERNAME, CONF_PASSWORD) @@ -40,7 +42,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): try: zones = evo_api.temperatures(force_refresh=True) for i, zone in enumerate(zones): - add_devices([RoundThermostat(evo_api, zone['id'], i == 0,away_temp)]) + add_devices([RoundThermostat(evo_api, zone['id'], i == 0, away_temp)]) except socket.error: _LOGGER.error( "Connection error logging into the honeywell evohome web service" From 39de92960d040da71ccfe3b716be54f2ef8ad39f Mon Sep 17 00:00:00 2001 From: sander Date: Sat, 2 Jan 2016 20:27:40 +0100 Subject: [PATCH 3/6] line too long change --- homeassistant/components/thermostat/honeywell.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/thermostat/honeywell.py b/homeassistant/components/thermostat/honeywell.py index de6d5ff6a56..4d1a7fe708d 100644 --- a/homeassistant/components/thermostat/honeywell.py +++ b/homeassistant/components/thermostat/honeywell.py @@ -42,7 +42,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None): try: zones = evo_api.temperatures(force_refresh=True) for i, zone in enumerate(zones): - add_devices([RoundThermostat(evo_api, zone['id'], i == 0, away_temp)]) + add_devices([RoundThermostat(evo_api, + zone['id'], + i == 0, + away_temp)]) except socket.error: _LOGGER.error( "Connection error logging into the honeywell evohome web service" From 8c7898ed054fc10c07f2c02bd093f54768be615b Mon Sep 17 00:00:00 2001 From: sander Date: Sat, 2 Jan 2016 20:53:25 +0100 Subject: [PATCH 4/6] pylinting.. --- homeassistant/components/thermostat/honeywell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/thermostat/honeywell.py b/homeassistant/components/thermostat/honeywell.py index 4d1a7fe708d..491fe57900e 100644 --- a/homeassistant/components/thermostat/honeywell.py +++ b/homeassistant/components/thermostat/honeywell.py @@ -48,7 +48,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): away_temp)]) except socket.error: _LOGGER.error( - "Connection error logging into the honeywell evohome web service" + "Connection error logging into the honeywell evohome web service" ) return False From 36f5caa214215a51b29870a60aa1fda4d7e333ba Mon Sep 17 00:00:00 2001 From: sander Date: Sat, 2 Jan 2016 20:59:45 +0100 Subject: [PATCH 5/6] more pylinting.. --- homeassistant/components/thermostat/honeywell.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/thermostat/honeywell.py b/homeassistant/components/thermostat/honeywell.py index 491fe57900e..0b7479bd202 100644 --- a/homeassistant/components/thermostat/honeywell.py +++ b/homeassistant/components/thermostat/honeywell.py @@ -29,8 +29,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): try: away_temp = float(config.get(CONF_AWAY_TEMP, 16)) except ValueError: - _LOGGER.error("value entered for item {} should convert to a number" - .format(CONF_AWAY_TEMP)) + _LOGGER.error("value entered for item %s should convert to a number", + CONF_AWAY_TEMP) return False if username is None or password is None: _LOGGER.error("Missing required configuration items %s or %s", From 55c5d254d58e6902667ea712dc9eb0d820b258db Mon Sep 17 00:00:00 2001 From: sander Date: Sat, 2 Jan 2016 21:09:03 +0100 Subject: [PATCH 6/6] some more pylinting.. --- homeassistant/components/thermostat/honeywell.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/thermostat/honeywell.py b/homeassistant/components/thermostat/honeywell.py index 0b7479bd202..5475e1ce306 100644 --- a/homeassistant/components/thermostat/honeywell.py +++ b/homeassistant/components/thermostat/honeywell.py @@ -56,6 +56,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class RoundThermostat(ThermostatDevice): """ Represents a Honeywell Round Connected thermostat. """ + # pylint: disable=too-many-instance-attributes def __init__(self, device, zone_id, master, away_temp): self.device = device self._current_temperature = None