core/homeassistant/components/thermostat/honeywell.py

265 lines
8.4 KiB
Python
Raw Normal View History

2015-10-21 17:00:15 +00:00
"""
2016-03-07 21:44:35 +00:00
Support for Honeywell Round Connected and Honeywell Evohome thermostats.
2015-11-09 12:12:18 +00:00
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/thermostat.honeywell/
2015-10-21 17:00:15 +00:00
"""
import logging
2016-01-01 14:29:58 +00:00
import socket
2015-10-31 19:35:23 +00:00
from homeassistant.components.thermostat import ThermostatDevice
2016-02-19 05:27:50 +00:00
from homeassistant.const import (
2016-04-20 03:30:44 +00:00
CONF_PASSWORD, CONF_USERNAME, TEMP_CELSIUS, TEMP_FAHRENHEIT)
2015-10-21 17:00:15 +00:00
REQUIREMENTS = ['evohomeclient==0.2.5',
'somecomfort==0.2.1']
2015-10-21 17:00:15 +00:00
2015-11-09 04:56:11 +00:00
_LOGGER = logging.getLogger(__name__)
2016-01-01 14:29:58 +00:00
CONF_AWAY_TEMP = "away_temperature"
DEFAULT_AWAY_TEMP = 16
2015-10-21 17:00:15 +00:00
2016-01-02 10:56:07 +00:00
def _setup_round(username, password, config, add_devices):
2016-03-07 21:44:35 +00:00
"""Setup rounding function."""
2015-11-09 04:56:11 +00:00
from evohomeclient import EvohomeClient
2015-10-21 17:00:15 +00:00
2016-01-01 14:29:58 +00:00
try:
away_temp = float(config.get(CONF_AWAY_TEMP, DEFAULT_AWAY_TEMP))
2016-01-01 14:29:58 +00:00
except ValueError:
2016-01-02 19:59:45 +00:00
_LOGGER.error("value entered for item %s should convert to a number",
CONF_AWAY_TEMP)
2016-01-02 10:56:07 +00:00
return False
2015-10-21 17:00:15 +00:00
evo_api = EvohomeClient(username, password)
2016-01-01 14:29:58 +00:00
2015-10-21 17:00:15 +00:00
try:
2015-12-01 21:23:28 +00:00
zones = evo_api.temperatures(force_refresh=True)
for i, zone in enumerate(zones):
2016-01-02 19:27:40 +00:00
add_devices([RoundThermostat(evo_api,
zone['id'],
i == 0,
away_temp)])
2015-10-21 17:00:15 +00:00
except socket.error:
2015-11-09 04:56:11 +00:00
_LOGGER.error(
2016-01-02 19:53:25 +00:00
"Connection error logging into the honeywell evohome web service"
2015-10-21 17:00:15 +00:00
)
2015-11-09 04:56:11 +00:00
return False
return True
2015-10-21 17:00:15 +00:00
# config will be used later
def _setup_us(username, password, config, add_devices):
2016-03-07 21:44:35 +00:00
"""Setup user."""
import somecomfort
try:
client = somecomfort.SomeComfort(username, password)
except somecomfort.AuthError:
_LOGGER.error('Failed to login to honeywell account %s', username)
return False
except somecomfort.SomeComfortError as ex:
_LOGGER.error('Failed to initialize honeywell client: %s', str(ex))
return False
dev_id = config.get('thermostat')
loc_id = config.get('location')
add_devices([HoneywellUSThermostat(client, device)
for location in client.locations_by_id.values()
for device in location.devices_by_id.values()
if ((not loc_id or location.locationid == loc_id) and
(not dev_id or device.deviceid == dev_id))])
return True
def setup_platform(hass, config, add_devices, discovery_info=None):
2016-03-07 21:44:35 +00:00
"""Setup the honeywel thermostat."""
username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
region = config.get('region', 'eu').lower()
if username is None or password is None:
_LOGGER.error("Missing required configuration items %s or %s",
CONF_USERNAME, CONF_PASSWORD)
return False
if region not in ('us', 'eu'):
_LOGGER.error('Region `%s` is invalid (use either us or eu)', region)
return False
if region == 'us':
return _setup_us(username, password, config, add_devices)
else:
return _setup_round(username, password, config, add_devices)
2015-10-21 17:00:15 +00:00
class RoundThermostat(ThermostatDevice):
2016-03-07 21:44:35 +00:00
"""Representation of a Honeywell Round Connected thermostat."""
2015-10-21 17:00:15 +00:00
# pylint: disable=too-many-instance-attributes, abstract-method
2016-01-01 14:29:58 +00:00
def __init__(self, device, zone_id, master, away_temp):
2016-03-07 21:44:35 +00:00
"""Initialize the thermostat."""
2015-10-21 17:00:15 +00:00
self.device = device
2015-10-31 19:35:23 +00:00
self._current_temperature = None
self._target_temperature = None
self._name = "round connected"
2015-12-01 21:23:28 +00:00
self._id = zone_id
self._master = master
self._is_dhw = False
2016-01-01 14:29:58 +00:00
self._away_temp = away_temp
self._away = False
2015-10-21 19:48:21 +00:00
self.update()
2015-10-21 17:00:15 +00:00
@property
def name(self):
2016-03-07 21:44:35 +00:00
"""Return the name of the honeywell, if any."""
return self._name
2015-10-21 17:00:15 +00:00
@property
def unit_of_measurement(self):
2016-03-07 21:44:35 +00:00
"""Return the unit of measurement."""
2016-04-20 03:30:44 +00:00
return TEMP_CELSIUS
2015-10-21 17:00:15 +00:00
2015-10-21 19:48:21 +00:00
@property
def current_temperature(self):
2016-03-07 21:44:35 +00:00
"""Return the current temperature."""
2015-10-21 19:48:21 +00:00
return self._current_temperature
@property
def target_temperature(self):
2016-03-07 21:44:35 +00:00
"""Return the temperature we try to reach."""
2015-12-01 21:23:28 +00:00
if self._is_dhw:
2015-12-01 21:30:44 +00:00
return None
2015-10-21 19:48:21 +00:00
return self._target_temperature
def set_temperature(self, temperature):
2016-03-07 21:44:35 +00:00
"""Set new target temperature."""
2015-10-31 19:35:23 +00:00
self.device.set_temperature(self._name, temperature)
2015-10-21 17:00:15 +00:00
@property
def operation(self: ThermostatDevice) -> str:
"""Get the current operation of the system."""
return self.device.system_mode
2016-01-01 14:29:58 +00:00
@property
def is_away_mode_on(self):
2016-03-07 21:44:35 +00:00
"""Return true if away mode is on."""
2016-01-01 14:29:58 +00:00
return self._away
def set_hvac_mode(self: ThermostatDevice, hvac_mode: str) -> None:
"""Set the HVAC mode for the thermostat."""
self.device.system_mode = hvac_mode
2016-01-01 14:29:58 +00:00
def turn_away_mode_on(self):
2016-03-07 21:44:35 +00:00
"""Turn 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.
"""
2016-01-01 14:29:58 +00:00
self._away = True
self.device.set_temperature(self._name, self._away_temp)
def turn_away_mode_off(self):
2016-03-07 21:44:35 +00:00
"""Turn away off."""
2016-01-01 14:29:58 +00:00
self._away = False
self.device.cancel_temp_override(self._name)
2015-10-21 17:00:15 +00:00
def update(self):
2016-03-07 21:44:35 +00:00
"""Get the latest date."""
2015-11-05 08:58:35 +00:00
try:
2015-12-01 21:23:28 +00:00
# Only refresh if this is the "master" device,
# others will pick up the cache
for val in self.device.temperatures(force_refresh=self._master):
if val['id'] == self._id:
data = val
2015-11-05 08:58:35 +00:00
except StopIteration:
2015-11-09 04:56:11 +00:00
_LOGGER.error("Did not receive any temperature data from the "
2015-11-09 12:12:18 +00:00
"evohomeclient API.")
2015-11-09 04:56:11 +00:00
return
self._current_temperature = data['temp']
self._target_temperature = data['setpoint']
2015-12-01 21:23:28 +00:00
if data['thermostat'] == "DOMESTIC_HOT_WATER":
self._name = "Hot Water"
self._is_dhw = True
else:
self._name = data['name']
self._is_dhw = False
# pylint: disable=abstract-method
class HoneywellUSThermostat(ThermostatDevice):
2016-03-07 21:44:35 +00:00
"""Representation of a Honeywell US Thermostat."""
def __init__(self, client, device):
2016-03-07 21:44:35 +00:00
"""Initialize the thermostat."""
self._client = client
self._device = device
@property
def is_fan_on(self):
2016-03-07 21:44:35 +00:00
"""Return true if fan is on."""
return self._device.fan_running
@property
def name(self):
2016-03-07 21:44:35 +00:00
"""Return the name of the honeywell, if any."""
return self._device.name
@property
def unit_of_measurement(self):
2016-03-07 21:44:35 +00:00
"""Return the unit of measurement."""
2016-04-20 03:30:44 +00:00
return (TEMP_CELSIUS if self._device.temperature_unit == 'C'
else TEMP_FAHRENHEIT)
@property
def current_temperature(self):
2016-03-07 21:44:35 +00:00
"""Return the current temperature."""
self._device.refresh()
return self._device.current_temperature
@property
def target_temperature(self):
2016-03-07 21:44:35 +00:00
"""Return the temperature we try to reach."""
if self._device.system_mode == 'cool':
return self._device.setpoint_cool
else:
return self._device.setpoint_heat
@property
def operation(self: ThermostatDevice) -> str:
"""Return current operation ie. heat, cool, idle."""
return self._device.system_mode
def set_temperature(self, temperature):
2016-03-07 21:44:35 +00:00
"""Set target temperature."""
import somecomfort
try:
if self._device.system_mode == 'cool':
self._device.setpoint_cool = temperature
else:
self._device.setpoint_heat = temperature
except somecomfort.SomeComfortError:
_LOGGER.error('Temperature %.1f out of range', temperature)
@property
def device_state_attributes(self):
2016-03-07 21:44:35 +00:00
"""Return the device specific state attributes."""
return {'fan': (self.is_fan_on and 'running' or 'idle'),
'fanmode': self._device.fan_mode,
'system_mode': self._device.system_mode}
def turn_away_mode_on(self):
2016-03-07 21:44:35 +00:00
"""Turn away on."""
pass
def turn_away_mode_off(self):
2016-03-07 21:44:35 +00:00
"""Turn away off."""
pass
def set_hvac_mode(self: ThermostatDevice, hvac_mode: str) -> None:
"""Set the system mode (Cool, Heat, etc)."""
self._device.system_mode = hvac_mode