Fix: Handle OSError: [Errno 113] Host is unreachable
Signed-off-by: Thomas Klaehn <thomas.klaehn@perinet.io>
This commit is contained in:
parent
bc04332c92
commit
64157b00e0
12
home/app.py
12
home/app.py
@ -69,13 +69,19 @@ class Control(threading.Thread):
|
||||
|
||||
url = "http://" + config["host"] + ":" + str(config["port"])
|
||||
if now > on_time and now <= off_time and not self.water_state[water_index]:
|
||||
try:
|
||||
client = xmlrpc.client.ServerProxy(url)
|
||||
client.switch_relay(water["relay"], True)
|
||||
self.water_state[water_index] = client.get_relay_state(water["relay"])
|
||||
except OSError as error:
|
||||
print(error)
|
||||
elif now > off_time and self.water_state[water_index]:
|
||||
try:
|
||||
client = xmlrpc.client.ServerProxy(url)
|
||||
client.switch_relay(water["relay"], False)
|
||||
self.water_state[water_index] = client.get_relay_state(water["relay"])
|
||||
except OSError as error:
|
||||
print(error)
|
||||
water_index += 1
|
||||
time.sleep(1)
|
||||
|
||||
@ -114,6 +120,7 @@ def get_sample(idx='0'):
|
||||
relay = int(water["relay"])
|
||||
res = {}
|
||||
url = "http://" + cfg["host"] + ":" + str(cfg["port"])
|
||||
try:
|
||||
client = xmlrpc.client.ServerProxy(url)
|
||||
water = {}
|
||||
water['id'] = str(idx)
|
||||
@ -121,6 +128,8 @@ def get_sample(idx='0'):
|
||||
res['water'] = water
|
||||
response = make_response(jsonify(res), 200)
|
||||
break
|
||||
except OSError as error:
|
||||
print(error)
|
||||
return response
|
||||
|
||||
|
||||
@ -138,10 +147,13 @@ def patch_sample(idx='0'):
|
||||
water = cfg["water"]
|
||||
relay = int(water["relay"])
|
||||
url = "http://" + cfg["host"] + ":" + str(cfg["port"])
|
||||
try:
|
||||
client = xmlrpc.client.ServerProxy(url)
|
||||
client.switch_relay(relay, record["waterstate"])
|
||||
response = make_response("", 204)
|
||||
break
|
||||
except OSError as error:
|
||||
print(error)
|
||||
return response
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user