From b2e39884f90ccfbe965ddece44d04c4457916633 Mon Sep 17 00:00:00 2001 From: Todd Ingarfield Date: Wed, 14 Oct 2015 11:02:07 -0500 Subject: [PATCH] Removed name and netdisco functions, implemented update method to caches values, radiotherm lib to coveragerc and requirements_all.txt --- .coveragerc | 1 + .../components/thermostat/radiotherm.py | 69 ++++++++----------- requirements_all.txt | 3 + 3 files changed, 33 insertions(+), 40 deletions(-) diff --git a/.coveragerc b/.coveragerc index 1ff145e2de3..e44a905a0ab 100644 --- a/.coveragerc +++ b/.coveragerc @@ -88,6 +88,7 @@ omit = homeassistant/components/switch/transmission.py homeassistant/components/switch/wemo.py homeassistant/components/thermostat/nest.py + homeassistant/components/thermostat/radiotherm.py [report] diff --git a/homeassistant/components/thermostat/radiotherm.py b/homeassistant/components/thermostat/radiotherm.py index e11f845b0b4..3acd3ef8986 100644 --- a/homeassistant/components/thermostat/radiotherm.py +++ b/homeassistant/components/thermostat/radiotherm.py @@ -9,33 +9,23 @@ from urllib.error import URLError from homeassistant.components.thermostat import (ThermostatDevice, STATE_COOL, STATE_IDLE, STATE_HEAT) -from homeassistant.const import (CONF_HOST, CONF_NAME, TEMP_FAHRENHEIT) +from homeassistant.const import (CONF_HOST, TEMP_FAHRENHEIT) REQUIREMENTS = ['radiotherm==1.2'] def setup_platform(hass, config, add_devices, discovery_info=None): """ Sets up the Radio Thermostat. """ + import radiotherm + logger = logging.getLogger(__name__) - try: - import radiotherm - except ImportError: - logger.exception( - "Error while importing dependency radiotherm. " - "Did you maybe not install the radiotherm dependency?") - return - - # Detect hosts with hass discovery, config or radiotherm discovery hosts = [] - if discovery_info: - logger.info('hass radiotherm discovery', discovery_info) - elif CONF_HOST in config: + if CONF_HOST in config: hosts = [config[CONF_HOST]] else: hosts.append(radiotherm.discover.discover_address()) - name = config.get(CONF_NAME) if hosts is None: logger.error("no radiotherm thermostats detected") return @@ -48,7 +38,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): tstats.append(RadioThermostat(tstat)) except (URLError, OSError): logger.exception( - "Unable to connect to Radio Thermostat @{}".format(host)) + "Unable to connect to Radio Thermostat: %s", host) add_devices(tstats) @@ -56,16 +46,19 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class RadioThermostat(ThermostatDevice): """ Represent a Radio Thermostat. """ - def __init__(self, device, name=None): + def __init__(self, device): self.device = device - if name: - self.set_name(name) self.set_time() + self._target_temperature = None + self._current_temperature = None + self._operation = STATE_IDLE + self._name = None + self.update() @property def name(self): """ Returns the name of the Radio Thermostat. """ - return self.device.name['raw'] + return self._name @property def unit_of_measurement(self): @@ -75,10 +68,7 @@ class RadioThermostat(ThermostatDevice): @property def device_state_attributes(self): """ Returns device specific state attributes. """ - # Move these to Thermostat Device and make them global return { - "humidity": None, - "target_humidity": None, "fan": self.device.fmode['human'], "mode": self.device.tmode['human'] } @@ -86,39 +76,38 @@ class RadioThermostat(ThermostatDevice): @property def current_temperature(self): """ Returns the current temperature. """ - return self.device.temp['raw'] + return round(self._current_temperature, 1) @property def operation(self): """ Returns current operation. head, cool idle """ - if self.device.tmode['human'] == 'Cool': - return STATE_COOL - elif self.device.tmode['human'] == 'Heat': - return STATE_HEAT - else: - return STATE_IDLE + return self._operation @property def target_temperature(self): """ Returns the temperature we try to reach. """ - if self.operation == STATE_COOL: - temp = self.device.t_cool['raw'] - elif self.operation == STATE_HEAT: - temp = self.device.t_heat['raw'] + return round(self._target_temperature, 1) - return round(temp, 1) + def update(self): + self._current_temperature = self.device.temp['raw'] + self._name = self.device.name['raw'] + if self.device.tmode['human'] == 'Cool': + self._target_temperature = self.device.t_cool['raw'] + self._operation = STATE_COOL + elif self.device.tmode['human'] == 'Heat': + self._target_temperature = self.device.t_heat['raw'] + self._operation = STATE_HEAT + else: + self._operation = STATE_IDLE def set_temperature(self, temperature): """ Set new target temperature """ - if self.operation == STATE_COOL: + if self._operation == STATE_COOL: self.device.t_cool = temperature - elif self.operation == STATE_HEAT: + elif self._operation == STATE_HEAT: self.device.t_heat = temperature - - def set_name(self, name): - """ Set thermostat name """ - self.device.name = name + self.device.hold = 1 def set_time(self): """ Set device time """ diff --git a/requirements_all.txt b/requirements_all.txt index 2b7074d91cd..668cedf65b2 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -137,3 +137,6 @@ SoCo==0.11.1 # PlexAPI (media_player.plex) https://github.com/adrienbrault/python-plexapi/archive/df2d0847e801d6d5cda920326d693cf75f304f1a.zip#python-plexapi==1.0.2 + +# Radio Thermostat (thermostat.radiotherm) +radiotherm=1.2