Guest User

Untitled

a guest
Feb 28th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.88 KB | None | 0 0
  1. """
  2. Support for Honeywell Evohome thermostats.
  3. """
  4. import logging
  5. import socket
  6. import datetime
  7.  
  8. import requests
  9. import voluptuous as vol
  10.  
  11. import homeassistant.helpers.config_validation as cv
  12. from homeassistant.components.climate import (
  13. ClimateDevice, PLATFORM_SCHEMA, ATTR_FAN_MODE, ATTR_FAN_LIST,
  14. ATTR_OPERATION_MODE, ATTR_OPERATION_LIST, SUPPORT_TARGET_TEMPERATURE,
  15. SUPPORT_OPERATION_MODE)
  16. from homeassistant.const import (
  17. CONF_PASSWORD, CONF_USERNAME, TEMP_CELSIUS, TEMP_FAHRENHEIT,
  18. ATTR_TEMPERATURE)
  19.  
  20.  
  21. REQUIREMENTS = ['evohomeclient==0.2.5']
  22.  
  23. _LOGGER = logging.getLogger(__name__)
  24.  
  25. ATTR_FAN = 'fan'
  26. ATTR_SYSTEM_MODE = 'system_mode'
  27. ATTR_CURRENT_OPERATION = 'equipment_output_status'
  28.  
  29. CONF_AWAY_TEMPERATURE = 'away_temperature'
  30. CONF_COOL_AWAY_TEMPERATURE = 'away_cool_temperature'
  31. CONF_HEAT_AWAY_TEMPERATURE = 'away_heat_temperature'
  32.  
  33. DEFAULT_AWAY_TEMPERATURE = 16
  34. DEFAULT_COOL_AWAY_TEMPERATURE = 30
  35. DEFAULT_HEAT_AWAY_TEMPERATURE = 16
  36.  
  37.  
  38. PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
  39. vol.Required(CONF_USERNAME): cv.string,
  40. vol.Required(CONF_PASSWORD): cv.string,
  41. vol.Optional(CONF_AWAY_TEMPERATURE,
  42. default=DEFAULT_AWAY_TEMPERATURE): vol.Coerce(float),
  43. vol.Optional(CONF_COOL_AWAY_TEMPERATURE,
  44. default=DEFAULT_COOL_AWAY_TEMPERATURE): vol.Coerce(float),
  45. vol.Optional(CONF_HEAT_AWAY_TEMPERATURE,
  46. default=DEFAULT_HEAT_AWAY_TEMPERATURE): vol.Coerce(float),
  47. })
  48.  
  49. STATE_AUTO = 'Auto'
  50. STATE_ECO = 'AutoWithEco'
  51. STATE_AWAY = 'Away'
  52. STATE_DAYOFF = 'DayOff'
  53. STATE_CUSTOM = 'Custom'
  54. STATE_OFF = 'HeatingOff'
  55.  
  56. EVOHOME_STATE_MAP = {
  57. 'AUTO_MODE': STATE_AUTO,
  58. 'ECO_MODE': STATE_ECO,
  59. 'AWAY_MODE': STATE_AWAY,
  60. 'DAYOFF_MODE': STATE_DAYOFF,
  61. 'CUSTOM_MODE': STATE_CUSTOM,
  62. 'OFF_MODE' : STATE_OFF
  63. }
  64.  
  65.  
  66. def setup_platform(hass, config, add_devices, discovery_info=None):
  67. """Set up the Honeywell thermostat."""
  68. username = config.get(CONF_USERNAME)
  69. password = config.get(CONF_PASSWORD)
  70.  
  71. return _setup_round(username, password, config, add_devices)
  72.  
  73.  
  74. def _setup_round(username, password, config, add_devices):
  75. """Set up the rounding function."""
  76. from evohomeclient2 import EvohomeClient
  77.  
  78. away_temp = config.get(CONF_AWAY_TEMPERATURE)
  79. client = EvohomeClient(username, password)
  80.  
  81. try:
  82. for device in client.temperatures():
  83. add_devices([RoundThermostat(client, device['id'], True, 10)], True)
  84. except socket.error:
  85. _LOGGER.error(
  86. "Connection error logging into the honeywell evohome web service")
  87. return False
  88. return True
  89.  
  90.  
  91. class RoundThermostat(ClimateDevice):
  92. """Representation of a Honeywell Round Connected thermostat."""
  93.  
  94. def __init__(self, client, zone_id, master, away_temp):
  95. """Initialize the thermostat."""
  96. self.client = client
  97. self._current_temperature = None
  98. self._target_temperature = None
  99. self._name = 'round connected'
  100. self._id = zone_id
  101. self._master = master
  102. self._is_dhw = False
  103. self._away_temp = away_temp
  104. self._away = False
  105.  
  106.  
  107. @property
  108. def supported_features(self):
  109. """Return the list of supported features."""
  110. supported = (SUPPORT_TARGET_TEMPERATURE)
  111. if hasattr(self.client, ATTR_SYSTEM_MODE):
  112. supported |= SUPPORT_OPERATION_MODE
  113. return supported
  114.  
  115. @property
  116. def name(self):
  117. """Return the name of the honeywell, if any."""
  118. return self._name
  119.  
  120. @property
  121. def temperature_unit(self):
  122. """Return the unit of measurement."""
  123. return TEMP_CELSIUS
  124.  
  125. @property
  126. def current_temperature(self):
  127. """Return the current temperature."""
  128. return self._current_temperature
  129.  
  130. @property
  131. def target_temperature(self):
  132. """Return the temperature we try to reach."""
  133. if self._is_dhw:
  134. return None
  135. return self._target_temperature
  136.  
  137. @property
  138. def operation_list(self):
  139. """Return the list of available operation modes."""
  140. op_list = []
  141.  
  142. for mode in EVOHOME_STATE_MAP:
  143. op_list.append(EVOHOME_STATE_MAP.get(mode))
  144.  
  145. return op_list
  146.  
  147.  
  148. def set_temperature(self, **kwargs):
  149. """Set new target temperature."""
  150. temperature = kwargs.get(ATTR_TEMPERATURE)
  151. if temperature is None:
  152. return
  153. zone = self.client.locations[0]._gateways[0]._control_systems[0].zones[self._name]
  154. zone.set_temperature(temperature)
  155.  
  156. @property
  157. def current_operation(self: ClimateDevice) -> str:
  158. """Get the current operation of the system."""
  159. return getattr(self.client, ATTR_SYSTEM_MODE, None)
  160.  
  161. @property
  162. def is_away_mode_on(self):
  163. """Return true if away mode is on."""
  164. return self._away
  165.  
  166. def set_operation_mode(self: ClimateDevice, operation_mode: str) -> None:
  167. """Set the HVAC mode for the thermostat."""
  168.  
  169. functions = {
  170. 'Auto': self.client.set_status_normal,
  171. 'AutoWithEco': self.client.set_status_eco,
  172. 'Away': self.client.set_status_away,
  173. 'DayOff': self.client.set_status_dayoff,
  174. 'Custom': self.client.set_status_custom,
  175. 'HeatingOff': self.client.set_status_heatingoff
  176. }
  177.  
  178. func = functions[operation_mode]
  179. func()
  180.  
  181. def turn_away_mode_on(self):
  182. """Turn away on.
  183. Honeywell does have a proprietary away mode, but it doesn't really work
  184. the way it should. For example: If you set a temperature manually
  185. it doesn't get overwritten when away mode is switched on.
  186. """
  187. self._away = True
  188. self.client.set_status_away() # Heating and hot water off
  189.  
  190. def turn_away_mode_off(self):
  191. """Turn away off."""
  192. self._away = False
  193. self.client.set_status_normal()
  194.  
  195. def update(self):
  196. """Get the latest date."""
  197. try:
  198. # Only refresh if this is the "master" device,
  199. # others will pick up the cache
  200. for val in self.client.temperatures():
  201. if val['id'] == self._id:
  202. data = val
  203.  
  204. except KeyError:
  205. _LOGGER.error("Update failed from Honeywell server")
  206. self.client.user_data = None
  207. return
  208.  
  209. except StopIteration:
  210. _LOGGER.error("Did not receive any temperature data from the evohomeclient API")
  211. return
  212.  
  213. self._current_temperature = data['temp']
  214. self._target_temperature = data['setpoint']
  215. if data['thermostat'] == 'DOMESTIC_HOT_WATER':
  216. self._name = 'Hot Water'
  217. self._is_dhw = True
  218. else:
  219. self._name = data['name']
  220. self._is_dhw = False
  221.  
  222. status=self.client.locations[0].status()
  223. tcs=status['gateways'][0]['temperatureControlSystems'][0]
  224. currentmode=tcs['systemModeStatus']['mode']
  225. self.client.system_mode = currentmode
  226. #_LOGGER.error(status)
Add Comment
Please, Sign In to add comment