Skip to content

Commit fa3acde

Browse files
committed
Adjustments to highcontrol and multicontrol
1 parent e61c1ae commit fa3acde

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '0.1.32'
1+
__version__ = '0.1.33'
22

33
_classifiers = [
44
'Development Status :: 4 - Beta',

xled_plus/highcontrol.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# -*- coding: utf-8 -*-
22

33
"""
4-
xled++.highcontrol
5-
~~~~~~~~~~~~~
4+
xled_plus.highcontrol
5+
~~~~~~~~~~~~~~~~~~~~~
66
7-
This module contains interface to control specific device
7+
High level control interface to the Twinkly led lights.
88
99
"""
1010

@@ -194,17 +194,20 @@ def turn_on(self):
194194
Turns on the device.
195195
196196
Sets the mode to the last used mode before turn_off().
197-
If the last mode is not known, sets 'movie' mode if there is an
198-
uploaded movie, else 'effect' mode.
197+
If the last mode is not known, sets 'playlist' mode if there is a
198+
playlist, otherwise 'movie' mode if there is any uploaded movie,
199+
else 'effect' mode.
199200
"""
200201
if self.last_mode:
201202
return self.set_mode(self.last_mode)
202203
else:
203204
if self.family == "D" or self.version < (2, 5, 6):
204-
response = self.get_led_movie_config()["frames_number"]
205+
mlst = self.get_led_movie_config()["frames_number"]
206+
return self.set_mode("effect" if not mlst else "movie")
205207
else:
206-
response = self.get_movies()["movies"]
207-
return self.set_mode("effect" if not response else "movie")
208+
mlst = self.get_movies()["movies"]
209+
plst = self.get_playlist()["entries"]
210+
return self.set_mode("effect" if not mlst else "playlist" if plst else "movie")
208211

209212
def turn_off(self):
210213
"""
@@ -605,7 +608,7 @@ def make_func_pattern(self, func, circular=False):
605608
return pat
606609

607610
def fetch_layout(self, aspect=False):
608-
if self.version > (2, 2, 1):
611+
if self.family != 'D' and self.version > (2, 2, 1):
609612
res = self.get_led_layout()
610613
if res["source"] == "3d":
611614
if aspect:

xled_plus/multicontrol.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,33 @@
2626
from xled_plus.highcontrol import HighControlInterface
2727

2828

29+
def pick_master_and_slaves(hostlst):
30+
ctrlst = [ControlInterface(ip) for ip in hostlst]
31+
master = False
32+
slaves = []
33+
for ctr in ctrlst:
34+
sync = ctr.get_led_movie_config()['sync']
35+
if sync['mode'] == 'master':
36+
assert not master, "Only one master device allowed in the group"
37+
master = ctr
38+
elif sync['mode'] == 'slave':
39+
slaves.append(ctr)
40+
else:
41+
assert len(hostlst) == 1, "One device does not belong to the group"
42+
master = ctr
43+
assert master, "No master device in the group"
44+
return master, slaves
45+
46+
2947
class MultiHighControlInterface(HighControlInterface):
3048
"""
31-
High level interface to control specific device
49+
High level interface to control a group of joined devices in sync
3250
"""
3351

3452
def __init__(self, hostlst):
35-
super(MultiHighControlInterface, self).__init__(hostlst[0])
36-
self.ctrlst = [self] + [ControlInterface(ip) for ip in hostlst[1:]]
53+
master, slaves = pick_master_and_slaves(hostlst)
54+
super(MultiHighControlInterface, self).__init__(master.host)
55+
self.ctrlst = slaves
3756
info = self.get_device_info()
3857
self.family = info["fw_family"] if "fw_family" in info else "D"
3958
self.led_bytes = info["bytes_per_led"] if "bytes_per_led" in info else 3

0 commit comments

Comments
 (0)