-
Notifications
You must be signed in to change notification settings - Fork 0
/
LightController.py
26 lines (23 loc) · 1 KB
/
LightController.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from lifxlan import LifxLAN, Light, BLUE, CYAN, GREEN, ORANGE, PINK, PURPLE, RED, YELLOW, WHITE
class LightController:
def __init__(self, mac = None, ip = None):
self.bulb = None
if mac != None and ip != None:
self.bulb = Light(mac, ip) # put a try block in here later
elif self.bulb == None: #put this in the catch block later
lights = LifxLAN(1)
self.bulb = lights.get_lights()[0] # just get whatever light you find
else:
lights = LifxLAN(1)
self.bulb = lights.get_lights()[0]
self.color = 0
#self.colors = [BLUE, CYAN, GREEN, ORANGE, PINK, PURPLE, RED, YELLOW, WHITE]
self.colors = [BLUE, GREEN, RED, WHITE]
def shiftColor(self):
self.color = (1 + self.color) % len(self.colors)
self.bulb.set_color(self.colors[self.color])
def togglePower(self):
if self.bulb.get_power() == 65535:
self.bulb.set_power(0)
else:
self.bulb.set_power(65535)