Skip to content
This repository has been archived by the owner on Feb 14, 2021. It is now read-only.

Commit

Permalink
Add default timeout to all requests
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericvl committed Apr 28, 2020
1 parent 599daf8 commit 7ea8938
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
36 changes: 26 additions & 10 deletions pyevacalor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
API_PATH_DEVICE_BUFFER_READING = "/deviceGetBufferReading"
API_PATH_DEVICE_JOB_STATUS = "/deviceJobStatus/"
API_PATH_DEVICE_WRITING = "/deviceRequestWriting"
DEFAULT_TIMEOUT_VALUE = 5
EVA_CALOR_CUSTOMER_CODE = "635987"
EVA_COLOR_BRAND_ID = "1"

Expand Down Expand Up @@ -116,8 +117,11 @@ def register_app_id(self):
payload = json.dumps(payload)

try:
response = requests.post(url, data=payload, headers=self._headers(),
allow_redirects=False)
response = requests.post(url,
data=payload,
headers=self._headers(),
allow_redirects=False,
timeout=DEFAULT_TIMEOUT_VALUE)
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
raise ConnectionError(str.format("Connection to {0} not possible", url))

Expand Down Expand Up @@ -146,8 +150,11 @@ def login(self):
headers.update(extra_headers)

try:
response = requests.post(url, data=payload, headers=headers,
allow_redirects=False)
response = requests.post(url,
data=payload,
headers=headers,
allow_redirects=False,
timeout=DEFAULT_TIMEOUT_VALUE)
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
raise ConnectionError(str.format("Connection to {0} not possible", url))

Expand All @@ -174,8 +181,11 @@ def do_refresh_token(self):
payload = json.dumps(payload)

try:
response = requests.post(url, data=payload, headers=self._headers(),
allow_redirects=False)
response = requests.post(url,
data=payload,
headers=self._headers(),
allow_redirects=False,
timeout=DEFAULT_TIMEOUT_VALUE)
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
raise ConnectionError(str.format("Connection to {0} not possible", url))

Expand Down Expand Up @@ -249,11 +259,17 @@ def handle_webcall(self, method, url, payload):

try:
if method == "POST":
response = requests.post(url, data=payload, headers=headers,
allow_redirects=False)
response = requests.post(url,
data=payload,
headers=headers,
allow_redirects=False,
timeout=DEFAULT_TIMEOUT_VALUE)
else:
response = requests.get(url, data=payload, headers=headers,
allow_redirects=False)
response = requests.get(url,
data=payload,
headers=headers,
allow_redirects=False,
timeout=DEFAULT_TIMEOUT_VALUE)
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
raise ConnectionError(str.format("Connection to {0} not possible", url))

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pyevacalor",
version="0.0.6",
version="0.0.7",
author="Frederic Van Linthoudt",
author_email="[email protected]",
description="pyevacalor provides controlling Eva Calor heating devices connected via the IOT Agua platform of Micronova",
Expand Down

0 comments on commit 7ea8938

Please sign in to comment.