From 84c72ebf634e0f89c381b46b44e9d050a053b9d0 Mon Sep 17 00:00:00 2001 From: Todd Ingarfield Date: Sun, 11 Oct 2015 09:28:25 -0500 Subject: [PATCH] Add support for multiple thermostats (via hass-config) and auto-discovery via ratiotherm module --- .../components/thermostat/radiotherm.py | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/thermostat/radiotherm.py b/homeassistant/components/thermostat/radiotherm.py index b0ae38461b3..e11f845b0b4 100644 --- a/homeassistant/components/thermostat/radiotherm.py +++ b/homeassistant/components/thermostat/radiotherm.py @@ -26,24 +26,31 @@ def setup_platform(hass, config, add_devices, discovery_info=None): "Did you maybe not install the radiotherm dependency?") return + # Detect hosts with hass discovery, config or radiotherm discovery hosts = [] - logger.info(discovery_info) + if discovery_info: + logger.info('hass radiotherm discovery', discovery_info) + elif CONF_HOST in config: + hosts = [config[CONF_HOST]] + else: + hosts.append(radiotherm.discover.discover_address()) - - host = config.get(CONF_HOST) name = config.get(CONF_NAME) - if host is None: - logger.error("host not defined in config.") + if hosts is None: + logger.error("no radiotherm thermostats detected") return - try: - tstat = radiotherm.get_thermostat(host) - except URLError: - logger.exception( - "Unable to connect to Radio Thermostat") - return + tstats = [] - add_devices([RadioThermostat(tstat, name)]) + for host in hosts: + try: + tstat = radiotherm.get_thermostat(host) + tstats.append(RadioThermostat(tstat)) + except (URLError, OSError): + logger.exception( + "Unable to connect to Radio Thermostat @{}".format(host)) + + add_devices(tstats) class RadioThermostat(ThermostatDevice):