diff --git a/hue_controller.py b/hue_controller.py index 5b14b0e..f61f353 100644 --- a/hue_controller.py +++ b/hue_controller.py @@ -126,13 +126,12 @@ class controller: else: print("Error: Light index '" + str(index) + "' out of range") - def setPreset( presetDict ): - if( type(presetDict) is dict ): - for index, preset in presetDict.items(): - controller.setLightPreset( index, preset ) - elif( type(presetDict) is str ): + def setPreset( presetID:str, index:int=-1 ): + if( index == -1 ): for key in LIGHTS: - controller.setLightPreset( key, presetDict ) + controller.setLightPreset( key, presetID ) + else: + controller.setLightPreset( index, presetID ) # Controller "system" functions diff --git a/hue_remote.py b/hue_remote.py index c2cb4e1..150441a 100755 --- a/hue_remote.py +++ b/hue_remote.py @@ -29,12 +29,13 @@ boolConvert = { "off": False } -def parseCommand( cmd:list, pos:int, index:int=-1 ): +def parseCommand( cmd:list, pos:int, i=-1 ): + index = int(i) if( cmd[pos] == "on" or cmd[pos] == "off" ): if( index == -1 ): hue.controller.Power( boolConvert[cmd[pos]] ) else: - hue.controller.Power() + hue.controller.powerLight( index, boolConvert[cmd[pos]] ) elif( cmd[pos] == "switch" ): if(index == -1): @@ -42,7 +43,33 @@ def parseCommand( cmd:list, pos:int, index:int=-1 ): else: hue.controller.switchLight(index) + elif( cmd[pos] == "set" ): + if( cmd[pos+1] == "preset" ): + hue.controller.setPreset( cmd[pos+2], index ) + + #elif( cmd[pos+1] == "color" ): + + + #elif( cmd[pos+1] == "preset" ): + + def parseCommandline(): # this is the most spaghetti code I have ever written but it works and I do not intend to fix cmd = sys.argv - if( cmd[1] == "light" ): - index = cmd[2] + print(cmd) + if( len(cmd) > 1 ): + if( cmd[1] == "light" ): + index = cmd[2] + parseCommand( cmd, 3, index ) + + elif( cmd[1] == "lights" ): + parseCommand( cmd, 2 ) + else: + help() + + +def init(): + hue.controller.init() + parseCommandline() + hue.controller.end() + +init()