Repository: craigjmidwinter/total-connect-client

Issue:
Handle ResponseCode is None
From https://github.com/home-assistant/core/issues/132236

Need to handle ResponseCode is None.  It happened during a system outage.

My _guess_ is that the database server went down, and already authenticated users started receiving empty responses because of it.  

If seen throw ServiceUnavailable exception and give users the Resideo status URL in the log.

Hints from issue comments:

Solution patch:
diff --git a/total_connect_client/const.py b/total_connect_client/const.py
index 5d0a666..ef7f8fe 100644
--- a/total_connect_client/const.py
+++ b/total_connect_client/const.py
@@ -2,7 +2,7 @@
 
 from enum import Enum
 
-from .exceptions import BadResultCodeError
+from .exceptions import BadResultCodeError, ServiceUnavailable
 
 
 class ArmType(Enum):
@@ -149,6 +149,9 @@ class _ResultCode(Enum):
     def from_response(response_dict):
         try:
             return _ResultCode(response_dict["ResultCode"])
+        except TypeError:
+            # sometimes when there are server issues, it returns empty responses - see issue #228
+            raise ServiceUnavailable(f"Server returned empty response, check server status at {STATUS_URL}") from None
         except ValueError:
             raise BadResultCodeError(
                 f"unknown result code {response_dict['ResultCode']}", response_dict
@@ -178,3 +181,5 @@ def from_response(response_dict):
 
 
 PROJECT_URL = "https://github.com/craigjmidwinter/total-connect-client"
+
+STATUS_URL = "https://status.resideo.com/"
\ No newline at end of file


Test patch:
diff --git a/tests/test_client_request.py b/tests/test_client_request.py
index 54c6cc7..e82e254 100644
--- a/tests/test_client_request.py
+++ b/tests/test_client_request.py
@@ -164,3 +164,10 @@ def tests_request_unknown_result_code(self):
             with pytest.raises(BadResultCodeError):
                 TotalConnectClient("username", "password", usercodes=None)
             assert mock_request.call_count == 1
+
+    def tests_empty_response_code(self):
+        """Test an empty response code."""
+        # see issue #228
+        from total_connect_client.const import _ResultCode
+        with pytest.raises(ServiceUnavailable):
+            _ResultCode.from_response(None)
\ No newline at end of file