From c9880f792c1e71f044c898717164d60c1f024930 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 4 Aug 2020 20:55:14 +0200 Subject: [PATCH] Remote stuff and lib update --- hue_controller.py | 5 ++++- hue_remote.py | 30 +++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/hue_controller.py b/hue_controller.py index 999c309..5b14b0e 100644 --- a/hue_controller.py +++ b/hue_controller.py @@ -105,9 +105,12 @@ class controller: for key in LIGHTS: controller.setLightColor( key, r, g, b ) - def Power(isOn: bool=True): # Controlling the power of the lights + def Power(isOn:bool=True): # Controlling the power of the lights loop.run_until_complete( controller.toggleLights(isOn) ) + def powerLight( index:int, isOn:bool=True ): + loop.run_until_complete( controller.toggleLight( index, isOn ) ) + # Presets def setLightPreset( index:int, p:str ): if( LIGHTS.get(str(index)) ): diff --git a/hue_remote.py b/hue_remote.py index 79645e9..c2cb4e1 100755 --- a/hue_remote.py +++ b/hue_remote.py @@ -1,5 +1,7 @@ #!/usr/bin/env python -from lib.input import * # Commandline parser +# from lib.input import * # Commandline parser + +import sys import hue_controller as hue # Actual controller @@ -13,7 +15,8 @@ def help(): print( "'" + cmd + " lights' ... : Specify all lights\n" ) print("--Commands--") - print( "'on/off' : Turn light(s) on/off" ) + print( "'on'/'off' : Turn light(s) on/off" ) + print( "'switch' : Switch the light(s) power" ) print( "'set ...'" ) print( " 'preset (preset ID)' : Set the preset (from presets.py)" ) print( " 'color (red) (green) (blue)' : Set the color, from 0-255" ) @@ -21,4 +24,25 @@ def help(): print("\nExamples:\n'hue light 2 on' : Turn on light 2\n'hue lights set color 255 255 255' : Set all lights colors to white") -help() +boolConvert = { + "on": True, + "off": False +} + +def parseCommand( cmd:list, pos:int, index:int=-1 ): + if( cmd[pos] == "on" or cmd[pos] == "off" ): + if( index == -1 ): + hue.controller.Power( boolConvert[cmd[pos]] ) + else: + hue.controller.Power() + + elif( cmd[pos] == "switch" ): + if(index == -1): + hue.controller.switchLights() + else: + hue.controller.switchLight(index) + +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]