forked from davidkrantz/Colorfy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wled_controller.py
39 lines (29 loc) · 1001 Bytes
/
wled_controller.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
import requests
class WLEDController():
"""Controller for WLED devices.
Attributes:
ip (string): The IP address of the WLED device.
"""
def __init__(self, ip):
self.ip = ip
self.wledControlURL = ip + "/win"
self.wledStateURL = ip + "/json/state"
def set_color(self, r, g, b):
"""Sets a new color. WLED already smoothly transitions between colors.
Args:
r (int): The new red value.
g (int): The new green value.
b (int): The new blue value.
"""
requests.get(url = self.wledControlURL + "&R=%d&G=%d&B=%d" % (r, g, b))
def get_color(self):
"""Returns the current color.
Returns:
tuple: (R, G, B). The current color.
"""
r = requests.get(url = self.wledStateURL)
data = r.json()
r = data['seg'][0]['col'][0][0]
g = data['seg'][0]['col'][0][1]
b = data['seg'][0]['col'][0][2]
return r,g,b