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:
|
||||
if request.method == "POST":
|
||||
response = interface_handler.write(device_name,request.data.get("output"))
|
||||
return {'output': str(response)}
|
||||
return {'state': interface_handler.read(device_name)}
|
||||
except Exception as e:
|
||||
return {'error': str(e)}
|
||||
|
@ -104,7 +104,7 @@ class Interface_handler:
|
||||
return returnValues
|
||||
|
||||
|
||||
def write(self, device_name:str, value):
|
||||
def write(self, device_name:str, output):
|
||||
"""writes an output to a given device
|
||||
|
||||
Args:
|
||||
@ -128,16 +128,20 @@ class Interface_handler:
|
||||
protocol = port_info["protocol"]
|
||||
pins = port_info["pins"]
|
||||
|
||||
for pin in self.xml_reader.get_port(device_name)["pins"]:
|
||||
if protocol == "DO":
|
||||
#type check input value
|
||||
if not value in ['0','1']:
|
||||
raise TypeError("value must be '0' or '1'")
|
||||
value = GPIO.HIGH if value == '1' else GPIO.LOW
|
||||
if protocol == "DO":
|
||||
#type check input value
|
||||
if not isinstance(output,dict):
|
||||
raise TypeError("value must be a dictionary of GPIOs and values")
|
||||
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)
|
||||
return GPIO.input(self.Pin[pin].value)
|
||||
else: #throw error for protocols without write functionality
|
||||
raise ValueError("you cannot write to device %s" % device_name)
|
||||
return output
|
||||
else: #throw error for protocols without write functionality
|
||||
raise ValueError("you cannot write to device %s" % device_name)
|
||||
|
||||
|
||||
# ##test
|
||||
|
Loading…
x
Reference in New Issue
Block a user