core/homeassistant/components/thermostat/honeywell.py

104 lines
3.3 KiB
Python
Raw Normal View History

2015-10-21 17:00:15 +00:00
"""
2015-11-09 12:12:18 +00:00
homeassistant.components.thermostat.honeywell
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2015-12-01 21:23:28 +00:00
Adds 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 socket
import logging
2015-10-31 19:35:23 +00:00
from homeassistant.components.thermostat import ThermostatDevice
2015-10-21 17:00:15 +00:00
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, TEMP_CELCIUS)
2015-12-01 21:23:28 +00:00
REQUIREMENTS = ['evohomeclient==0.2.4']
2015-10-21 17:00:15 +00:00
2015-11-09 04:56:11 +00:00
_LOGGER = logging.getLogger(__name__)
2015-10-21 17:00:15 +00:00
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
2015-11-05 08:58:35 +00:00
""" Sets up the honeywel thermostat. """
2015-11-09 04:56:11 +00:00
from evohomeclient import EvohomeClient
2015-10-21 17:00:15 +00:00
username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
if username is None or password is None:
2015-11-09 04:56:11 +00:00
_LOGGER.error("Missing required configuration items %s or %s",
CONF_USERNAME, CONF_PASSWORD)
return False
2015-10-21 17:00:15 +00:00
evo_api = EvohomeClient(username, password)
try:
2015-12-01 21:23:28 +00:00
zones = evo_api.temperatures(force_refresh=True)
for i, zone in enumerate(zones):
add_devices([RoundThermostat(evo_api, zone['id'], i == 0)])
2015-10-21 17:00:15 +00:00
except socket.error:
2015-11-09 04:56:11 +00:00
_LOGGER.error(
"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
2015-10-21 17:00:15 +00:00
class RoundThermostat(ThermostatDevice):
""" Represents a Honeywell Round Connected thermostat. """
2015-10-21 17:00:15 +00:00
2015-12-01 21:23:28 +00:00
def __init__(self, device, zone_id, master):
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
2015-10-21 19:48:21 +00:00
self.update()
2015-10-21 17:00:15 +00:00
@property
def name(self):
2015-11-05 08:58:35 +00:00
""" Returns the name of the honeywell, if any. """
return self._name
2015-10-21 17:00:15 +00:00
@property
def unit_of_measurement(self):
""" Unit of measurement this thermostat expresses itself in. """
return TEMP_CELCIUS
2015-10-21 19:48:21 +00:00
@property
def current_temperature(self):
""" Returns the current temperature. """
return self._current_temperature
@property
def target_temperature(self):
""" Returns 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):
""" 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
def update(self):
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