From 31553db02e53bcc126a707541d3f69e60ee9fbe5 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 4 Aug 2020 22:10:51 +0200 Subject: [PATCH] Updated lib to not display debug when there is no error --- hue_controller.py | 17 ++++++++--------- hue_remote.py | 8 +++++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/hue_controller.py b/hue_controller.py index 915cb2d..7f9dbfc 100644 --- a/hue_controller.py +++ b/hue_controller.py @@ -20,15 +20,11 @@ class APIrequest: async def get( dest: str="", payload: str="" ): try: apiReq = req.get( genUrl(dest), data = payload ) - return apiReq - except req.exceptions.RequestException as err: - print(err) + if( apiReq.status_code != 200 ): # print out the error if the status code is not 200 + print(apiReq) + print(apiReq.text) - # POST Req - async def post( dest: str="", payload: str="" ): - try: - apiReq = req.post( genUrl(params), data = payload ) return apiReq except req.exceptions.RequestException as err: @@ -38,8 +34,11 @@ class APIrequest: async def put( dest: str="", payload: str="" ): try: apiReq = req.put( genUrl(dest), data = payload ) # send the payload - print(apiReq) - print(apiReq.text) + + if( apiReq.status_code != 200 ): + print(apiReq) + print(apiReq.text) + return apiReq except req.exceptions.RequestException as err: diff --git a/hue_remote.py b/hue_remote.py index f16528c..231bb76 100755 --- a/hue_remote.py +++ b/hue_remote.py @@ -29,6 +29,8 @@ boolConvert = { "off": False } +# this is the most spaghetti-ish code I have ever written but it works + def parseCommand( cmd:list, pos:int, i=-1 ): index = int(i) try: @@ -83,9 +85,9 @@ def parseCommand( cmd:list, pos:int, i=-1 ): help() # display the help page if parameters are missing (it will give out an IndexError) -def parseCommandline(): # this is the most spaghetti code I have ever written but it works and I do not intend to fix +def parseCommandline(): cmd = sys.argv - print(cmd) + if( len(cmd) > 1 ): if( cmd[1] == "light" ): parseCommand( cmd, 3, cmd[2] ) @@ -101,4 +103,4 @@ def init(): parseCommandline() hue.controller.end() # also to end it -init() +init() # actually call the init function