Skip to content

Instantly share code, notes, and snippets.

@terabyte128
Created July 16, 2018 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terabyte128/db1860270a37033bd3d2d382759f1453 to your computer and use it in GitHub Desktop.
Save terabyte128/db1860270a37033bd3d2d382759f1453 to your computer and use it in GitHub Desktop.
quick n dirty way to play with lifx light colors
import tkinter
import lifxlan
class Application(tkinter.Frame):
def sendCommand(self, type, val):
try:
light = self.lights[int(self.selectedLight.get())]
except ValueError:
return
if light is None:
return
if type not in ['hue', 'brightness', 'saturation', 'colortemp']:
print("invalid type: %s" % type)
func = getattr(light, 'set_' + type)
func(val)
def sendWithType(self, type):
def f(val):
return self.sendCommand(type, val)
return f
def createWidgets(self):
self.lan = lifxlan.LifxLAN()
self.lights = self.lan.get_color_lights()
labelText = "\n".join([ "%d: %s" % (i, self.lights[i].get_label()) for i in range(len(self.lights)) ])
label = tkinter.Label(self, text=labelText)
label.pack()
self.selectedLight = tkinter.StringVar(self)
self.selectedLight.set("Select an option")
self.lightSelector = apply(tkinter.OptionMenu, (self, self.selectedLight) + tuple(range(len(self.lights))))
self.lightSelector.pack()
for type in ['hue', 'saturation', 'brightness', 'colortemp']:
min = 2500 if type == 'colortemp' else 0
max = 9000 if type == 'colortemp' else 2**16 - 1
scale = tkinter.Scale(self, from_=min, to=max,
orient=tkinter.HORIZONTAL,
label=type,
command=self.sendWithType(type),
length=200)
scale.pack()
def __init__(self, master=None):
tkinter.Frame.__init__(self, master)
self.pack()
self.createWidgets()
root = tkinter.Tk()
app = Application(master=root)
app.mainloop()
root.destroy()
@terabyte128
Copy link
Author

before using:

pip install tkinter
pip install lifxlan

requires python3, probably

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment