diff --git a/garage/garage.py b/garage/garage.py index 1675e79..dd3280d 100644 --- a/garage/garage.py +++ b/garage/garage.py @@ -85,28 +85,39 @@ class GarageService(object): return "trigger gate" @cherrypy.expose - def garage(self): - Thread(target=garage_button,args=[0]).start() - return "trigger garage door" + def garage(self, action=None): + if action == "open": + Thread(target=garage_button,args=[0]).start() + return "{ action: open }" + elif action == "close": + Thread(target=garage_button,args=[0]).start() + return "{ action: close }" + if (GPIO.input(PIN_DOOR_OPEN) and not GPIO.input(PIN_DOOR_CLOSED)): + status = "true" + else: + status = "false" + return "{ status: " + status + " }" @cherrypy.expose - def gate(self): - Thread(target=gate_button,args=[0]).start() - return "trigger gate" + def gate(self, action=None): + if action == "open": + Thread(target=gate_button,args=[0]).start() + return "{ action: open }" + elif action == "close": + Thread(target=gate_button,args=[0]).start() + return "{ action: close }" + + if GPIO.input(PIN_SENSOR_GATE) == 0: + status = "false" + else: + status = "true" + return "{ status: " + status + " }" @cherrypy.expose def all(self): Thread(target=garage_button,args=[0]).start() Thread(target=gate_button,args=[0]).start() return "trigger all" - - @cherrypy.expose - def garage_status(self): - if (GPIO.input(PIN_DOOR_OPEN) and GPIO.input(PIN_DOOR_CLOSED)): - return "moving" - elif (GPIO.input(PIN_DOOR_OPEN) and not GPIO.input(PIN_DOOR_CLOSED)): - return "closed" - return "open"