Skip to content

Commit

Permalink
Adjustments to highcontrol and multicontrol
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders-Holst committed Dec 31, 2021
1 parent e61c1ae commit fa3acde
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.1.32'
__version__ = '0.1.33'

_classifiers = [
'Development Status :: 4 - Beta',
Expand Down
21 changes: 12 additions & 9 deletions xled_plus/highcontrol.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-

"""
xled++.highcontrol
~~~~~~~~~~~~~
xled_plus.highcontrol
~~~~~~~~~~~~~~~~~~~~~
This module contains interface to control specific device
High level control interface to the Twinkly led lights.
"""

Expand Down Expand Up @@ -194,17 +194,20 @@ def turn_on(self):
Turns on the device.
Sets the mode to the last used mode before turn_off().
If the last mode is not known, sets 'movie' mode if there is an
uploaded movie, else 'effect' mode.
If the last mode is not known, sets 'playlist' mode if there is a
playlist, otherwise 'movie' mode if there is any uploaded movie,
else 'effect' mode.
"""
if self.last_mode:
return self.set_mode(self.last_mode)
else:
if self.family == "D" or self.version < (2, 5, 6):
response = self.get_led_movie_config()["frames_number"]
mlst = self.get_led_movie_config()["frames_number"]
return self.set_mode("effect" if not mlst else "movie")
else:
response = self.get_movies()["movies"]
return self.set_mode("effect" if not response else "movie")
mlst = self.get_movies()["movies"]
plst = self.get_playlist()["entries"]
return self.set_mode("effect" if not mlst else "playlist" if plst else "movie")

def turn_off(self):
"""
Expand Down Expand Up @@ -605,7 +608,7 @@ def make_func_pattern(self, func, circular=False):
return pat

def fetch_layout(self, aspect=False):
if self.version > (2, 2, 1):
if self.family != 'D' and self.version > (2, 2, 1):
res = self.get_led_layout()
if res["source"] == "3d":
if aspect:
Expand Down
25 changes: 22 additions & 3 deletions xled_plus/multicontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,33 @@
from xled_plus.highcontrol import HighControlInterface


def pick_master_and_slaves(hostlst):
ctrlst = [ControlInterface(ip) for ip in hostlst]
master = False
slaves = []
for ctr in ctrlst:
sync = ctr.get_led_movie_config()['sync']
if sync['mode'] == 'master':
assert not master, "Only one master device allowed in the group"
master = ctr
elif sync['mode'] == 'slave':
slaves.append(ctr)
else:
assert len(hostlst) == 1, "One device does not belong to the group"
master = ctr
assert master, "No master device in the group"
return master, slaves


class MultiHighControlInterface(HighControlInterface):
"""
High level interface to control specific device
High level interface to control a group of joined devices in sync
"""

def __init__(self, hostlst):
super(MultiHighControlInterface, self).__init__(hostlst[0])
self.ctrlst = [self] + [ControlInterface(ip) for ip in hostlst[1:]]
master, slaves = pick_master_and_slaves(hostlst)
super(MultiHighControlInterface, self).__init__(master.host)
self.ctrlst = slaves
info = self.get_device_info()
self.family = info["fw_family"] if "fw_family" in info else "D"
self.led_bytes = info["bytes_per_led"] if "bytes_per_led" in info else 3
Expand Down

0 comments on commit fa3acde

Please sign in to comment.