enabled single edit of output
This commit is contained in:
parent
ee28832caa
commit
0733a13104
1
app.py
1
app.py
@ -56,7 +56,6 @@ def api_devices(device_name):
|
|||||||
try:
|
try:
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
response = interface_handler.write(device_name,request.data.get("output"))
|
response = interface_handler.write(device_name,request.data.get("output"))
|
||||||
return {'output': str(response)}
|
|
||||||
return {'state': interface_handler.read(device_name)}
|
return {'state': interface_handler.read(device_name)}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {'error': str(e)}
|
return {'error': str(e)}
|
||||||
|
@ -104,7 +104,7 @@ class Interface_handler:
|
|||||||
return returnValues
|
return returnValues
|
||||||
|
|
||||||
|
|
||||||
def write(self, device_name:str, value):
|
def write(self, device_name:str, output):
|
||||||
"""writes an output to a given device
|
"""writes an output to a given device
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -128,14 +128,18 @@ class Interface_handler:
|
|||||||
protocol = port_info["protocol"]
|
protocol = port_info["protocol"]
|
||||||
pins = port_info["pins"]
|
pins = port_info["pins"]
|
||||||
|
|
||||||
for pin in self.xml_reader.get_port(device_name)["pins"]:
|
|
||||||
if protocol == "DO":
|
if protocol == "DO":
|
||||||
#type check input value
|
#type check input value
|
||||||
if not value in ['0','1']:
|
if not isinstance(output,dict):
|
||||||
raise TypeError("value must be '0' or '1'")
|
raise TypeError("value must be a dictionary of GPIOs and values")
|
||||||
value = GPIO.HIGH if value == '1' else GPIO.LOW
|
for pin in output:
|
||||||
|
if not pin in self.xml_reader.get_port(device_name)["pins"]:
|
||||||
|
raise ValueError(str("pin %s is not a part of device %s",pin,device_name))
|
||||||
|
if not output[pin] in ['0','1']:
|
||||||
|
raise TypeError("value must be 1 or 0")
|
||||||
|
value = GPIO.HIGH if output[pin] == '1' else GPIO.LOW
|
||||||
GPIO.output(self.Pin[pin].value,value)
|
GPIO.output(self.Pin[pin].value,value)
|
||||||
return GPIO.input(self.Pin[pin].value)
|
return output
|
||||||
else: #throw error for protocols without write functionality
|
else: #throw error for protocols without write functionality
|
||||||
raise ValueError("you cannot write to device %s" % device_name)
|
raise ValueError("you cannot write to device %s" % device_name)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user