Remote progress, it works :D

fetchIP
E. Almqvist 4 years ago
parent c9880f792c
commit 4dcf07a15b
  1. 11
      hue_controller.py
  2. 35
      hue_remote.py

@ -126,13 +126,12 @@ class controller:
else: else:
print("Error: Light index '" + str(index) + "' out of range") print("Error: Light index '" + str(index) + "' out of range")
def setPreset( presetDict ): def setPreset( presetID:str, index:int=-1 ):
if( type(presetDict) is dict ): if( index == -1 ):
for index, preset in presetDict.items():
controller.setLightPreset( index, preset )
elif( type(presetDict) is str ):
for key in LIGHTS: for key in LIGHTS:
controller.setLightPreset( key, presetDict ) controller.setLightPreset( key, presetID )
else:
controller.setLightPreset( index, presetID )
# Controller "system" functions # Controller "system" functions

@ -29,12 +29,13 @@ boolConvert = {
"off": False "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( cmd[pos] == "on" or cmd[pos] == "off" ):
if( index == -1 ): if( index == -1 ):
hue.controller.Power( boolConvert[cmd[pos]] ) hue.controller.Power( boolConvert[cmd[pos]] )
else: else:
hue.controller.Power() hue.controller.powerLight( index, boolConvert[cmd[pos]] )
elif( cmd[pos] == "switch" ): elif( cmd[pos] == "switch" ):
if(index == -1): if(index == -1):
@ -42,7 +43,33 @@ def parseCommand( cmd:list, pos:int, index:int=-1 ):
else: else:
hue.controller.switchLight(index) 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 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 cmd = sys.argv
if( cmd[1] == "light" ): print(cmd)
index = cmd[2] 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()

Loading…
Cancel
Save