-
Notifications
You must be signed in to change notification settings - Fork 0
/
wled_fake.py
49 lines (41 loc) · 1.15 KB
/
wled_fake.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
class WLED():
def __init__(self, host):
self._host = host
self._on = True
self._preset = 'Foo'
self._presets = ['Foo', 'Bar', 'Baz']
def connect(self):
if self._host != 'error':
print(f'Connected to {self._host}')
else:
raise Exception('Could not connect to WLED.')
@property
def on(self):
return self._on
@on.setter
def on(self, value):
if type(value) == bool:
self._on = value
else:
self._on = not self._on
@property
def preset(self):
return self._preset
@preset.setter
def preset(self, value):
if value in self._presets:
self._preset = value
@property
def presets(self):
return list(self._presets)
def cycle_preset(self, offset):
"""Activate a next/previous preset."""
presets = self.presets
if not presets:
return
try:
index = presets.index(self.preset)
preset = presets[(index + offset) % len(presets)]
except ValueError:
preset = presets[0]
self.preset = preset