Add connection failure handling

This commit is contained in:
Evan Fiordeliso 2021-12-19 10:39:50 -05:00
parent 74c6ee0987
commit 7123783768
1 changed files with 12 additions and 3 deletions

View File

@ -57,7 +57,12 @@ class Flickerstrip:
Returns: Returns:
bool: If the request was successful bool: If the request was successful
""" """
resp = requests.get(f"http://{self.ip_address}/{path}", params=params) try:
resp = requests.get(f"http://{self.ip_address}/{path}",
params=params)
except requests.exceptions.ConnectionError:
print("Unable to connect to flickerstrip, is it online?")
return False
return self.__check_response(resp) return self.__check_response(resp)
def __post_request(self, path, json=None, params=None, data=None): def __post_request(self, path, json=None, params=None, data=None):
@ -74,8 +79,12 @@ class Flickerstrip:
Returns: Returns:
bool: If the request was successful bool: If the request was successful
""" """
resp = requests.post(f"http://{self.ip_address}/{path}", try:
params=params, json=json, data=data) resp = requests.post(f"http://{self.ip_address}/{path}",
params=params, json=json, data=data)
except requests.exceptions.ConnectionError:
print("Unable to connect to flickerstrip, is it online?")
return False
return self.__check_response(resp) return self.__check_response(resp)
def force_update(self): def force_update(self):