-
Notifications
You must be signed in to change notification settings - Fork 0
/
miactions.py
73 lines (59 loc) · 1.63 KB
/
miactions.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
A set of example actions for the homebrain-milight python library
"""
import milight
from time import sleep
def on(zone):
msg = milight.on(zone)
milight.send_cmd(msg)
def off(zone):
msg = milight.off(zone)
milight.send_cmd(msg)
def whitemode(zone):
# Select zone
msg = milight.on(zone)
milight.send_cmd(msg)
# Send brightness message
msg = milight.whitemode()
milight.send_cmd(msg)
def brightness(zone, brightness):
# Select zone
msg = milight.on(zone)
milight.send_cmd(msg)
# Send brightness message
msg = milight.brightness(brightness)
milight.send_cmd(msg)
def hue(zone, hue):
# Select zone
msg = milight.on(zone)
milight.send_cmd(msg)
# Send brightness message
msg = milight.hue(hue)
milight.send_cmd(msg)
def blink(zone=0, loop=False, sleeptime=1):
while True:
ZONE = 0
on(zone)
sleep(sleeptime)
off(zone)
if not loop:
break
sleep(sleeptime)
def strobe(zone, time):
blink(zone, True, time)
def fade_brightness(zone, time, fadein=True):
"""
Fades in from lowest to highest during a total of the passed argument time.
If argument fadein is set to False it will instead fade out from the highest to lowest.
"""
# Loop brightness levels
step = time/milight.BRIGHTNESS_LEVELS
for i in range(milight.BRIGHTNESS_LEVELS):
if not fadein:
i = (milight.BRIGHTNESS_LEVELS-1) - i
brightness(zone, i)
sleep(step)
def fadein(zone, time):
fade_brightness(zone, time, True)
def fadeout(zone, time):
fade_brightness(zone, time, False)