From c211c617c2f4288aa4048ccd41c670b3ce7c2442 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 4 Aug 2020 01:47:54 +0200 Subject: [PATCH] Controller get functions --- hue_controller.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hue_controller.py b/hue_controller.py index 968a18e..fd61d6c 100644 --- a/hue_controller.py +++ b/hue_controller.py @@ -16,7 +16,7 @@ def boolToString(v: bool): # To fix the dumb python syntax class APIrequest: # Get Req - async def get( dest: str="", payload: str="{}" ): + async def get( dest: str="", payload: str="" ): try: apiReq = req.get( genUrl(dest), data = payload ) return apiReq @@ -25,7 +25,7 @@ class APIrequest: print(err) # POST Req - async def post( dest: str="", payload: str="{}" ): + async def post( dest: str="", payload: str="" ): try: apiReq = req.post( genUrl(params), data = payload ) return apiReq @@ -34,7 +34,7 @@ class APIrequest: print(err) # PUT Req - async def put( dest: str="", payload: str="{}" ): + async def put( dest: str="", payload: str="" ): try: apiReq = req.put( genUrl(dest), data = payload ) # send the payload print(apiReq) @@ -46,6 +46,12 @@ class APIrequest: 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): await APIrequest.put( "/lights/1/state", '{"on":' + boolToString(isOn) + '}' )