implement away mode

This commit is contained in:
sander 2016-01-01 15:29:58 +01:00
parent b3227e491b
commit c703c89dbd

View File

@ -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 For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/thermostat.honeywell/ https://home-assistant.io/components/thermostat.honeywell/
""" """
import socket
import logging import logging
import socket
from homeassistant.components.thermostat import ThermostatDevice from homeassistant.components.thermostat import ThermostatDevice
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, TEMP_CELCIUS) from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, TEMP_CELCIUS)
@ -15,6 +16,7 @@ REQUIREMENTS = ['evohomeclient==0.2.4']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONF_AWAY_TEMP = "away_temperature"
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
@ -23,17 +25,22 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
username = config.get(CONF_USERNAME) username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD) 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: if username is None or password is None:
_LOGGER.error("Missing required configuration items %s or %s", _LOGGER.error("Missing required configuration items %s or %s",
CONF_USERNAME, CONF_PASSWORD) CONF_USERNAME, CONF_PASSWORD)
return False return False
evo_api = EvohomeClient(username, password) evo_api = EvohomeClient(username, password)
try: try:
zones = evo_api.temperatures(force_refresh=True) zones = evo_api.temperatures(force_refresh=True)
for i, zone in enumerate(zones): 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: except socket.error:
_LOGGER.error( _LOGGER.error(
"Connection error logging into the honeywell evohome web service" "Connection error logging into the honeywell evohome web service"
@ -44,7 +51,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class RoundThermostat(ThermostatDevice): class RoundThermostat(ThermostatDevice):
""" Represents a Honeywell Round Connected thermostat. """ """ 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.device = device
self._current_temperature = None self._current_temperature = None
self._target_temperature = None self._target_temperature = None
@ -52,6 +59,8 @@ class RoundThermostat(ThermostatDevice):
self._id = zone_id self._id = zone_id
self._master = master self._master = master
self._is_dhw = False self._is_dhw = False
self._away_temp = away_temp
self._away = False
self.update() self.update()
@property @property
@ -80,6 +89,25 @@ class RoundThermostat(ThermostatDevice):
""" Set new target temperature """ """ Set new target temperature """
self.device.set_temperature(self._name, 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): def update(self):
try: try:
# Only refresh if this is the "master" device, # Only refresh if this is the "master" device,