Automation2040W Mini: Fixed example.

pull/533/head
Gee Bartlett 2022-10-07 09:31:07 +01:00 zatwierdzone przez Phil Howard
rodzic 9dbd25bd51
commit 0616a0694e
1 zmienionych plików z 46 dodań i 16 usunięć

Wyświetl plik

@ -8,13 +8,21 @@ import time
board = Automation2040W()
isMini = False
# Uncomment for Automation2040WMini
'''
from automation import Automation2040WMini
board = Automation2040WMini()
isMini = True
'''
def status_handler(mode, status, ip):
print("Network: {}".format(WIFI_CONFIG.SSID))
status_text = "Connecting..."
board.conn_led(20.0)
board.conn_led(20)
if status is not None:
if status:
status_text = "Connection successful!"
@ -72,7 +80,9 @@ class LEDs:
if 'two' in data.keys():
board.output(1, int(data['two']))
if 'three' in data.keys():
board.output(2, int(data['three']))
if (not isMini):
board.output(2, int(data['three']))
return {'message': 'outputs updated'}, 201
@ -82,7 +92,10 @@ class inputs:
return {'message': 'no data provided'}, 404
def get(self, data):
return {"one": board.read_input(0), "two": board.read_input(1), "three": board.read_input(2), "four": board.read_input(3)}, 201
if (not isMini):
return {"one": board.read_input(0), "two": board.read_input(1), "three": board.read_input(2), "four": board.read_input(3)}, 201
else:
return {"one": board.read_input(0), "two": board.read_input(1), "three": "N/A", "four": "N/A"}, 201
def post(self, data):
return {'message': 'outputs updated'}, 201
@ -118,21 +131,28 @@ class outputs:
return {'message': 'no data provided'}, 404
def get(self, data):
if 'one' in data.keys():
board.output(0, bool(data['one']))
print(int(data['one']))
board.output(0, bool(int(data['one'])))
if 'two' in data.keys():
board.output(1, bool(data['two']))
board.output(1, bool(int(data['two'])))
if 'three' in data.keys():
board.output(2, bool(data['three']))
return {"one": bool(board.output(0)), "two": bool(board.output(1)), "three": bool(board.output(2))}, 201
if (not isMini):
board.output(2, bool(int(data['three'])))
if (not isMini):
return {"one": bool(board.output(0)), "two": bool(board.output(1)), "three": bool(board.output(2))}, 201
else:
return {"one": bool(board.output(0)), "two": bool(board.output(1)), "three": "N/A"}, 201
def post(self, data):
if 'one' in data.keys():
board.output(0, int(data['one']))
board.output(0, bool(int(data['one'])))
if 'two' in data.keys():
board.output(1, int(data['two']))
board.output(1, bool(int(data['two'])))
if 'three' in data.keys():
board.output(2, int(data['three']))
if (not isMini):
board.output(2, int(data['three']))
return {'message': 'outputs updated'}, 201
@ -143,20 +163,30 @@ class relays:
def get(self, data):
if 'one' in data.keys():
board.relay(0, int(data['one']))
if (not isMini):
board.relay(0, int(data['one']))
else:
board.relay(int(data['one']))
if 'two' in data.keys():
board.relay(1, int(data['two']))
if (not isMini):
board.relay(1, int(data['two']))
if 'three' in data.keys():
board.relay(2, int(data['three']))
return {"one": board.relay(0), "two": board.relay(1), "three": board.relay(2)}, 201
if (not isMini):
board.relay(2, int(data['three']))
if (not isMini):
return {"one": bool(board.relay(0)), "two": bool(board.relay(1)), "three": bool(board.relay(2))}, 201
else:
return {"one": bool(board.relay()), "two": "N/A", "three": "N/A"}, 201
def post(self, data):
if 'one' in data.keys():
board.relay(0, int(data['one']))
if 'two' in data.keys():
board.relay(1, int(data['two']))
if (not isMini):
board.relay(1, int(data['two']))
if 'three' in data.keys():
board.relay(2, int(data['three']))
if (not isMini):
board.relay(2, int(data['three']))
return {'message': 'outputs updated'}, 201