Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle ResponseCode is None #229

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/test_client_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 6 additions & 1 deletion total_connect_client/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from enum import Enum

from .exceptions import BadResultCodeError
from .exceptions import BadResultCodeError, ServiceUnavailable


class ArmType(Enum):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -178,3 +181,5 @@ def from_response(response_dict):


PROJECT_URL = "https://github.com/craigjmidwinter/total-connect-client"

STATUS_URL = "https://status.resideo.com/"
Loading