Began work on remote

fetchIP
E. Almqvist 4 years ago
parent c30e465ff7
commit add4ea6539
  1. 26
      hue_controller.py
  2. 24
      hue_remote.py
  3. 17
      lib/vars.py
  4. 9
      main.py
  5. 22
      presets.py

@ -93,10 +93,13 @@ class controller:
def setLightBrightness( index:int, b:int ): def setLightBrightness( index:int, b:int ):
if( LIGHTS.get(str(index)) ): if( LIGHTS.get(str(index)) ):
payload = '{"bri":' + str(b) + '}' payload = '{"bri":' + str(b) + '}'
APIrequest.put( "/lights/" + str(index) + "/state", payload ) loop.run_until_complete( APIrequest.put( "/lights/" + str(index) + "/state", payload ) )
else: else:
print("Error: Light index '" + str(index) + "' out of range") print("Error: Light index '" + str(index) + "' out of range")
def setBrightness( b:int ):
for key in LIGHTS:
controller.setLightBrightness( key, b )
def setAllLightsColor( r:int, g:int, b:int ): def setAllLightsColor( r:int, g:int, b:int ):
for key in LIGHTS: for key in LIGHTS:
@ -106,17 +109,29 @@ class controller:
loop.run_until_complete( controller.toggleLights(isOn) ) loop.run_until_complete( controller.toggleLights(isOn) )
# Presets # Presets
def setPreset(index:int, p:str): def setLightPreset( index:int, p:str ):
if( LIGHTS.get(str(index)) ): if( LIGHTS.get(str(index)) ):
if( PRESETS.get(p) ): if( PRESETS.get(p) ):
preset = PRESETS[p] preset = PRESETS[p]
r, g, b = preset["color"] r, g, b = preset["color"]
brightness = preset["brightness"]
controller.setLightColor( index, r, g, b ) controller.setLightColor( index, r, g, b )
controller.setLightBrightness( index, brightness )
else: else:
print("Error: Unknown preset '" + p + "'") print("Error: Unknown preset '" + p + "'")
else: else:
print("Error: Light index '" + str(index) + "' out of range") 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 ):
for key in LIGHTS:
controller.setLightPreset( key, presetDict )
# Controller "system" functions # Controller "system" functions
def delay(n:int): def delay(n:int):
time.sleep(n) time.sleep(n)
@ -126,13 +141,6 @@ class controller:
global LIGHTS global LIGHTS
LIGHTS = json.loads(jsonLights.text) LIGHTS = json.loads(jsonLights.text)
print(LIGHTS)
def end(): def end():
loop.close() loop.close()
def testReq():
controller.init()
controller.Power(True)
controller.setAllLightsColor( 178, 199, 255 )
controller.end()

@ -0,0 +1,24 @@
#!/usr/bin/env python
from lib.input import * # Commandline parser
import hue_controller as hue # Actual controller
cmd = "hue"
def help():
print("--Help page--")
print( "'" + cmd + "' : Display this help page" )
print( "'" + cmd + " light (index)' ... : Specify light target" )
print( "'" + cmd + " lights' ... : Specify all lights\n" )
print("--Commands--")
print( "'on/off' : Turn light(s) on/off" )
print( "'set ...'" )
print( " 'preset (preset ID)' : Set the preset (from presets.py)" )
print( " 'color (red) (green) (blue)' : Set the color, from 0-255" )
print( " 'brightness (brightness)' : Set the brightness, from 0-255" )
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()

@ -1,17 +0,0 @@
eng_alphabet = *"abcdefghijklmnopqrstuvwxyz",
swe_alphabet = *"abcdefghijklmnopqrstuvwxyzåäö",
# Definitions
alphabet = dict()
alphabet["ENG"] = eng_alphabet
alphabet["SWE"] = swe_alphabet
# Functions
def listToString( l ):
returnStr = ""
for char in l:
returnStr += char
return returnStr

@ -1,9 +0,0 @@
#!/usr/bin/env python
from lib.input import * # Commandline parser
import hue_controller as hue # Actual controller
def init():
hue.testReq()
init()

@ -1,7 +1,29 @@
# Presets goes in here # Presets goes in here
PRESETS = { PRESETS = {
"default": { "default": {
"color": (178, 199, 255), "color": (178, 199, 255),
"brightness": 255 "brightness": 255
},
"red": {
"color": (255, 0, 0),
"brightness": 255
},
"green": {
"color": (0, 255, 0),
"brightness": 255
},
"blue": {
"color": (0, 0, 255),
"brightness": 255
},
"sleep": {
"color": (185, 155, 25),
"brightness": 80
} }
} }

Loading…
Cancel
Save