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
46
home/app.py
46
home/app.py
@ -69,13 +69,19 @@ class Control(threading.Thread):
|
|||||||
|
|
||||||
url = "http://" + config["host"] + ":" + str(config["port"])
|
url = "http://" + config["host"] + ":" + str(config["port"])
|
||||||
if now > on_time and now <= off_time and not self.water_state[water_index]:
|
if now > on_time and now <= off_time and not self.water_state[water_index]:
|
||||||
client = xmlrpc.client.ServerProxy(url)
|
try:
|
||||||
client.switch_relay(water["relay"], True)
|
client = xmlrpc.client.ServerProxy(url)
|
||||||
self.water_state[water_index] = client.get_relay_state(water["relay"])
|
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]:
|
elif now > off_time and self.water_state[water_index]:
|
||||||
client = xmlrpc.client.ServerProxy(url)
|
try:
|
||||||
client.switch_relay(water["relay"], False)
|
client = xmlrpc.client.ServerProxy(url)
|
||||||
self.water_state[water_index] = client.get_relay_state(water["relay"])
|
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
|
water_index += 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
@ -114,13 +120,16 @@ def get_sample(idx='0'):
|
|||||||
relay = int(water["relay"])
|
relay = int(water["relay"])
|
||||||
res = {}
|
res = {}
|
||||||
url = "http://" + cfg["host"] + ":" + str(cfg["port"])
|
url = "http://" + cfg["host"] + ":" + str(cfg["port"])
|
||||||
client = xmlrpc.client.ServerProxy(url)
|
try:
|
||||||
water = {}
|
client = xmlrpc.client.ServerProxy(url)
|
||||||
water['id'] = str(idx)
|
water = {}
|
||||||
water['state'] = client.get_relay_state(relay)
|
water['id'] = str(idx)
|
||||||
res['water'] = water
|
water['state'] = client.get_relay_state(relay)
|
||||||
response = make_response(jsonify(res), 200)
|
res['water'] = water
|
||||||
break
|
response = make_response(jsonify(res), 200)
|
||||||
|
break
|
||||||
|
except OSError as error:
|
||||||
|
print(error)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@ -138,10 +147,13 @@ def patch_sample(idx='0'):
|
|||||||
water = cfg["water"]
|
water = cfg["water"]
|
||||||
relay = int(water["relay"])
|
relay = int(water["relay"])
|
||||||
url = "http://" + cfg["host"] + ":" + str(cfg["port"])
|
url = "http://" + cfg["host"] + ":" + str(cfg["port"])
|
||||||
client = xmlrpc.client.ServerProxy(url)
|
try:
|
||||||
client.switch_relay(relay, record["waterstate"])
|
client = xmlrpc.client.ServerProxy(url)
|
||||||
response = make_response("", 204)
|
client.switch_relay(relay, record["waterstate"])
|
||||||
break
|
response = make_response("", 204)
|
||||||
|
break
|
||||||
|
except OSError as error:
|
||||||
|
print(error)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
2
setup.py
2
setup.py
@ -6,7 +6,7 @@ from setuptools import setup
|
|||||||
from setuptools.command.install import install
|
from setuptools.command.install import install
|
||||||
|
|
||||||
NAME = 'home'
|
NAME = 'home'
|
||||||
VERSION = '1'
|
VERSION = '2'
|
||||||
AUTHOR = 'Thomas Klaehn'
|
AUTHOR = 'Thomas Klaehn'
|
||||||
EMAIL = 'tkl@blackfinn.de'
|
EMAIL = 'tkl@blackfinn.de'
|
||||||
PACKAGES = ['home']
|
PACKAGES = ['home']
|
||||||
|
Loading…
Reference in New Issue
Block a user