From e38b41e679a187b3026a7e2f94dc94fd05711a57 Mon Sep 17 00:00:00 2001 From: Vinny Furia Date: Sat, 22 Aug 2020 20:43:54 +0000 Subject: [PATCH] Add optional timeout parameter --- radiotherm/thermostat.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/radiotherm/thermostat.py b/radiotherm/thermostat.py index e8c0081..0b4e1a7 100644 --- a/radiotherm/thermostat.py +++ b/radiotherm/thermostat.py @@ -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): """ @@ -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): """ @@ -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): """