Skip to content

Commit

Permalink
Merge pull request #47 from vinnyfuria/master
Browse files Browse the repository at this point in the history
Add optional timeout parameter
  • Loading branch information
mhrivnak authored Jan 18, 2021
2 parents f6e7b22 + e38b41e commit b2230c7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions radiotherm/thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class Thermostat(object):
# and it's the right thing to do.
JSON_HEADER = {'Content-Type' : 'application/json'}

def __init__(self, host):
def __init__(self, host, timeout=4):
self.host = host
self.timeout = timeout

def get(self, relative_url):
"""
Expand All @@ -32,7 +33,7 @@ def get(self, relative_url):
:returns: file-like object as returned by urllib[2,.request].urlopen
"""
url = self._construct_url(relative_url)
return request.urlopen(url)
return request.urlopen(url, timeout=self.timeout)

def post(self, relative_url, value):
"""
Expand All @@ -43,7 +44,7 @@ def post(self, relative_url, value):
"""
url = self._construct_url(relative_url)
request_instance = request.Request(url, value, self.JSON_HEADER)
return request.urlopen(request_instance)
return request.urlopen(request_instance, timeout=self.timeout)

def _construct_url(self, relative_url):
"""
Expand Down

0 comments on commit b2230c7

Please sign in to comment.