|
|
@ -16,7 +16,7 @@ def boolToString(v: bool): # To fix the dumb python syntax |
|
|
|
|
|
|
|
|
|
|
|
class APIrequest: |
|
|
|
class APIrequest: |
|
|
|
# Get Req |
|
|
|
# Get Req |
|
|
|
async def get( dest: str="", payload: str="{}" ): |
|
|
|
async def get( dest: str="", payload: str="" ): |
|
|
|
try: |
|
|
|
try: |
|
|
|
apiReq = req.get( genUrl(dest), data = payload ) |
|
|
|
apiReq = req.get( genUrl(dest), data = payload ) |
|
|
|
return apiReq |
|
|
|
return apiReq |
|
|
@ -25,7 +25,7 @@ class APIrequest: |
|
|
|
print(err) |
|
|
|
print(err) |
|
|
|
|
|
|
|
|
|
|
|
# POST Req |
|
|
|
# POST Req |
|
|
|
async def post( dest: str="", payload: str="{}" ): |
|
|
|
async def post( dest: str="", payload: str="" ): |
|
|
|
try: |
|
|
|
try: |
|
|
|
apiReq = req.post( genUrl(params), data = payload ) |
|
|
|
apiReq = req.post( genUrl(params), data = payload ) |
|
|
|
return apiReq |
|
|
|
return apiReq |
|
|
@ -34,7 +34,7 @@ class APIrequest: |
|
|
|
print(err) |
|
|
|
print(err) |
|
|
|
|
|
|
|
|
|
|
|
# PUT Req |
|
|
|
# PUT Req |
|
|
|
async def put( dest: str="", payload: str="{}" ): |
|
|
|
async def put( dest: str="", payload: str="" ): |
|
|
|
try: |
|
|
|
try: |
|
|
|
apiReq = req.put( genUrl(dest), data = payload ) # send the payload |
|
|
|
apiReq = req.put( genUrl(dest), data = payload ) # send the payload |
|
|
|
print(apiReq) |
|
|
|
print(apiReq) |
|
|
@ -46,6 +46,12 @@ class APIrequest: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class controller: |
|
|
|
class controller: |
|
|
|
|
|
|
|
async def getLights(): |
|
|
|
|
|
|
|
return await APIrequest.get("/lights") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def getLight(index: int=1): |
|
|
|
|
|
|
|
return await APIrequest.get( "/lights/" + str(index) ) |
|
|
|
|
|
|
|
|
|
|
|
async def toggleLight(index: int=1, isOn: bool=True): |
|
|
|
async def toggleLight(index: int=1, isOn: bool=True): |
|
|
|
await APIrequest.put( "/lights/1/state", '{"on":' + boolToString(isOn) + '}' ) |
|
|
|
await APIrequest.put( "/lights/1/state", '{"on":' + boolToString(isOn) + '}' ) |
|
|
|
|
|
|
|
|
|
|
|