-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpylight.py
More file actions
127 lines (102 loc) · 3.05 KB
/
Copy pathpylight.py
File metadata and controls
127 lines (102 loc) · 3.05 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from yeelight import Bulb
import argparse
# from os import system
# system('cls||clear')
# not the master file!
# ini copotan, gue copas dari main repo di laptop
parser = argparse.ArgumentParser(description="Configure your Yeelight lamp.")
parser.add_argument("-m", "--manual", action='store_true', help="Enables manual configuration.")
args = parser.parse_args()
lamp = Bulb("")
effect_choice = "smooth"
options = {
1: "Turn on",
2: "Turn off",
3: "Toggle power",
4: "Set brightness",
5: "Set RGB value",
6: "Set HSV value",
7: "Set color temperature",
8: "Select preset",
9: "Change lamp",
10: "Get lamp properties",
0: "Exit",
}
presets = {
1: "Sleepy yellow",
2: "Fresh bright"
}
def preset_execute(preset_choice):
global lamp
if (preset_choice == 1):
lamp.turn_on
lamp.set_rgb(245, 145, 0)
elif (preset_choice == 2):
lamp.turn_on
lamp.set_color_temp(6417)
else:
return "There is no preset like that."
return("Preset selected!")
def launch(lamp_ip):
# init
changeLamp(lamp_ip)
manualMode = args.manual
# yet another menu loop
try:
while(manualMode == True):
print(options)
selection(int(input("Choice: ")))
print("")
else:
print("NOTICE: The default action is power toggle.")
print("Use '-m' parameter to enter manual customization mode")
selection(3)
except KeyboardInterrupt:
print("WARNING: Force closing the program.")
def selection(choice):
global effect_choice
if (choice == 1):
print("Turning on...")
lamp.turn_on(effect = effect_choice)
elif (choice == 2):
print("Turning off...")
lamp.turn_off(effect = effect_choice)
elif(choice == 3):
print("Toggling...")
lamp.toggle()
elif(choice == 4):
lamp.set_brightness(int(input("New brightness (in percent): ")))
elif(choice == 5):
r = int(input("Red value: "))
g = int(input("Green value: "))
b = int(input("Blue value: "))
lamp.set_rgb(r, g, b)
elif(choice == 6):
h = int(input("Hue value: "))
s = int(input("Saturation value: "))
lamp.set_hsv(h, s)
elif(choice == 7):
lamp.set_color_temp(int(input("New color temp: ")))
elif(choice == 8):
print("Available presets:")
print(presets)
print(
preset_execute(int(input("Preset choice: ")))
)
elif(choice == 9):
new_ip = input("New yeelight IP: ")
changeLamp(new_ip)
elif(choice == 10):
print(lamp.get_properties())
elif(choice == 0):
# exit here
# raise Exception("some exception happened")
print("Exiting...")
exit()
else:
print("There is no command with that number.")
def changeLamp(lamp_ip):
global lamp
lamp = Bulb(lamp_ip)
if __name__ == "__main__":
launch("192.168.177.11")