From 34f701a69b5e16e73ecb4f4f4b1a4aef95d2ee2c Mon Sep 17 00:00:00 2001
From: Vinny Furia <vinnyfuria@users.noreply.github.com>
Date: Sun, 24 Jan 2021 16:01:41 -0700
Subject: [PATCH] Fix for radiotherm component stall (#45482)

---
 CODEOWNERS                                    |  1 +
 .../components/radiotherm/climate.py          | 85 ++++++++++---------
 .../components/radiotherm/manifest.json       |  4 +-
 requirements_all.txt                          |  2 +-
 4 files changed, 47 insertions(+), 45 deletions(-)

diff --git a/CODEOWNERS b/CODEOWNERS
index f6eeac33d89..8ade4488540 100644
--- a/CODEOWNERS
+++ b/CODEOWNERS
@@ -363,6 +363,7 @@ homeassistant/components/quantum_gateway/* @cisasteelersfan
 homeassistant/components/qvr_pro/* @oblogic7
 homeassistant/components/qwikswitch/* @kellerza
 homeassistant/components/rachio/* @bdraco
+homeassistant/components/radiotherm/* @vinnyfuria
 homeassistant/components/rainbird/* @konikvranik
 homeassistant/components/raincloud/* @vanstinator
 homeassistant/components/rainforest_eagle/* @gtdiehl @jcalbert
diff --git a/homeassistant/components/radiotherm/climate.py b/homeassistant/components/radiotherm/climate.py
index 4383cf97a2d..f09ef95170f 100644
--- a/homeassistant/components/radiotherm/climate.py
+++ b/homeassistant/components/radiotherm/climate.py
@@ -1,5 +1,6 @@
 """Support for Radio Thermostat wifi-enabled home thermostats."""
 import logging
+from socket import timeout
 
 import radiotherm
 import voluptuous as vol
@@ -261,60 +262,60 @@ class RadioThermostat(ClimateEntity):
         # thermostats tend to time out sometimes when they're actively
         # heating or cooling.
 
-        # First time - get the name from the thermostat.  This is
-        # normally set in the radio thermostat web app.
-        if self._name is None:
-            self._name = self.device.name["raw"]
-
-        # Request the current state from the thermostat.
         try:
+            # First time - get the name from the thermostat.  This is
+            # normally set in the radio thermostat web app.
+            if self._name is None:
+                self._name = self.device.name["raw"]
+
+            # Request the current state from the thermostat.
             data = self.device.tstat["raw"]
+
+            if self._is_model_ct80:
+                humiditydata = self.device.humidity["raw"]
+
         except radiotherm.validate.RadiothermTstatError:
             _LOGGER.warning(
                 "%s (%s) was busy (invalid value returned)",
                 self._name,
                 self.device.host,
             )
-            return
 
-        current_temp = data["temp"]
+        except timeout:
+            _LOGGER.warning(
+                "Timeout waiting for response from %s (%s)",
+                self._name,
+                self.device.host,
+            )
 
-        if self._is_model_ct80:
-            try:
-                humiditydata = self.device.humidity["raw"]
-            except radiotherm.validate.RadiothermTstatError:
-                _LOGGER.warning(
-                    "%s (%s) was busy (invalid value returned)",
-                    self._name,
-                    self.device.host,
-                )
-                return
-            self._current_humidity = humiditydata
-            self._program_mode = data["program_mode"]
-            self._preset_mode = CODE_TO_PRESET_MODE[data["program_mode"]]
-
-        # Map thermostat values into various STATE_ flags.
-        self._current_temperature = current_temp
-        self._fmode = CODE_TO_FAN_MODE[data["fmode"]]
-        self._fstate = CODE_TO_FAN_STATE[data["fstate"]]
-        self._tmode = CODE_TO_TEMP_MODE[data["tmode"]]
-        self._tstate = CODE_TO_TEMP_STATE[data["tstate"]]
-
-        self._current_operation = self._tmode
-        if self._tmode == HVAC_MODE_COOL:
-            self._target_temperature = data["t_cool"]
-        elif self._tmode == HVAC_MODE_HEAT:
-            self._target_temperature = data["t_heat"]
-        elif self._tmode == HVAC_MODE_AUTO:
-            # This doesn't really work - tstate is only set if the HVAC is
-            # active. If it's idle, we don't know what to do with the target
-            # temperature.
-            if self._tstate == CURRENT_HVAC_COOL:
+        else:
+            if self._is_model_ct80:
+                self._current_humidity = humiditydata
+                self._program_mode = data["program_mode"]
+                self._preset_mode = CODE_TO_PRESET_MODE[data["program_mode"]]
+
+            # Map thermostat values into various STATE_ flags.
+            self._current_temperature = data["temp"]
+            self._fmode = CODE_TO_FAN_MODE[data["fmode"]]
+            self._fstate = CODE_TO_FAN_STATE[data["fstate"]]
+            self._tmode = CODE_TO_TEMP_MODE[data["tmode"]]
+            self._tstate = CODE_TO_TEMP_STATE[data["tstate"]]
+
+            self._current_operation = self._tmode
+            if self._tmode == HVAC_MODE_COOL:
                 self._target_temperature = data["t_cool"]
-            elif self._tstate == CURRENT_HVAC_HEAT:
+            elif self._tmode == HVAC_MODE_HEAT:
                 self._target_temperature = data["t_heat"]
-        else:
-            self._current_operation = HVAC_MODE_OFF
+            elif self._tmode == HVAC_MODE_AUTO:
+                # This doesn't really work - tstate is only set if the HVAC is
+                # active. If it's idle, we don't know what to do with the target
+                # temperature.
+                if self._tstate == CURRENT_HVAC_COOL:
+                    self._target_temperature = data["t_cool"]
+                elif self._tstate == CURRENT_HVAC_HEAT:
+                    self._target_temperature = data["t_heat"]
+            else:
+                self._current_operation = HVAC_MODE_OFF
 
     def set_temperature(self, **kwargs):
         """Set new target temperature."""
diff --git a/homeassistant/components/radiotherm/manifest.json b/homeassistant/components/radiotherm/manifest.json
index 6d4567c59d6..0220c233841 100644
--- a/homeassistant/components/radiotherm/manifest.json
+++ b/homeassistant/components/radiotherm/manifest.json
@@ -2,6 +2,6 @@
   "domain": "radiotherm",
   "name": "Radio Thermostat",
   "documentation": "https://www.home-assistant.io/integrations/radiotherm",
-  "requirements": ["radiotherm==2.0.0"],
-  "codeowners": []
+  "requirements": ["radiotherm==2.1.0"],
+  "codeowners": ["@vinnyfuria"]
 }
diff --git a/requirements_all.txt b/requirements_all.txt
index d0fdc3f8a30..c55f9adedb9 100644
--- a/requirements_all.txt
+++ b/requirements_all.txt
@@ -1913,7 +1913,7 @@ quantum-gateway==0.0.5
 rachiopy==1.0.3
 
 # homeassistant.components.radiotherm
-radiotherm==2.0.0
+radiotherm==2.1.0
 
 # homeassistant.components.raincloud
 raincloudy==0.0.7
-- 
GitLab