Various bug fixes and optimizations
This commit is contained in:
parent
e17873c648
commit
9d7f23ef78
1 changed files with 15 additions and 25 deletions
40
c4ctrl.py
40
c4ctrl.py
|
@ -26,17 +26,19 @@ class C4Interface():
|
||||||
|
|
||||||
if type(cmd) == list:
|
if type(cmd) == list:
|
||||||
# Add <qos> and <retain> to every message
|
# Add <qos> and <retain> to every message
|
||||||
for item in cmd:
|
for item in cmd.copy():
|
||||||
if type(item) == dict:
|
if type(item) == dict:
|
||||||
item["qos"] = self.qos
|
item["qos"] = self.qos
|
||||||
item["retain"] = self.retain
|
item["retain"] = self.retain
|
||||||
elif type(item) == tuple:
|
elif type(item) == tuple:
|
||||||
item = (
|
new_item = (
|
||||||
item[0] or self.topic, # topic
|
item[0] or self.topic, # topic
|
||||||
item[1], # payload
|
item[1], # payload
|
||||||
self.qos, # qos
|
self.qos, # qos
|
||||||
self.retain # retain
|
self.retain # retain
|
||||||
)
|
)
|
||||||
|
cmd.remove(item)
|
||||||
|
cmd.append(new_item)
|
||||||
|
|
||||||
if self.debug: return print("[DEBUG] inhibited messages:", cmd)
|
if self.debug: return print("[DEBUG] inhibited messages:", cmd)
|
||||||
|
|
||||||
|
@ -139,6 +141,7 @@ class Dmx:
|
||||||
|
|
||||||
def set_color(self, color):
|
def set_color(self, color):
|
||||||
"""Set color (hex) for this instance.
|
"""Set color (hex) for this instance.
|
||||||
|
|
||||||
The color is then available via the color variable."""
|
The color is then available via the color variable."""
|
||||||
|
|
||||||
if not color:
|
if not color:
|
||||||
|
@ -148,12 +151,6 @@ class Dmx:
|
||||||
self.color = color
|
self.color = color
|
||||||
self.payload = bytearray.fromhex(color)
|
self.payload = bytearray.fromhex(color)
|
||||||
|
|
||||||
def color_from_array(self, ba):
|
|
||||||
"""Set color (bytearray) for thes instance.
|
|
||||||
|
|
||||||
The color is then available via the color variable."""
|
|
||||||
self.set_color(ba.hex())
|
|
||||||
|
|
||||||
|
|
||||||
class Dmx5(Dmx):
|
class Dmx5(Dmx):
|
||||||
"""Abstraction of the 5 Channel LED Cans in the Club."""
|
"""Abstraction of the 5 Channel LED Cans in the Club."""
|
||||||
|
@ -225,7 +222,7 @@ class C4Room:
|
||||||
def set_colorscheme(self, colorscheme):
|
def set_colorscheme(self, colorscheme):
|
||||||
"""Apply colorscheme to the LED Cans in this room."""
|
"""Apply colorscheme to the LED Cans in this room."""
|
||||||
cmd = []
|
cmd = []
|
||||||
# Todo: this stuff would make sense when the Sink Light would be slave
|
# Todo: this stuff would make sense if the Sink Light would be slave
|
||||||
# to a master
|
# to a master
|
||||||
#if colorscheme.single_color:
|
#if colorscheme.single_color:
|
||||||
# # Setting only master is more efficient here
|
# # Setting only master is more efficient here
|
||||||
|
@ -718,7 +715,6 @@ class ColorScheme:
|
||||||
|
|
||||||
fd.write("# Preset \"{}\" (auto generated)\n".format(name))
|
fd.write("# Preset \"{}\" (auto generated)\n".format(name))
|
||||||
fd.write("# Note: \"/master\" topics override every other topic in the room.\n")
|
fd.write("# Note: \"/master\" topics override every other topic in the room.\n")
|
||||||
fd.write("# Thus, they have been commented out.\n")
|
|
||||||
for room in Wohnzimmer, Plenarsaal, Fnordcenter:
|
for room in Wohnzimmer, Plenarsaal, Fnordcenter:
|
||||||
topics = []
|
topics = []
|
||||||
for light in room.lights:
|
for light in room.lights:
|
||||||
|
@ -729,7 +725,7 @@ class ColorScheme:
|
||||||
for light in room.lights:
|
for light in room.lights:
|
||||||
for r in responce:
|
for r in responce:
|
||||||
if r.topic == light.topic:
|
if r.topic == light.topic:
|
||||||
light.color_from_array(r.payload)
|
light.set_color(r.payload.hex())
|
||||||
# Out comment master, as it would overre everything else
|
# Out comment master, as it would overre everything else
|
||||||
if self._topic_is_master(r.topic):
|
if self._topic_is_master(r.topic):
|
||||||
fd.write("#{} = {}\n".format(light.topic, light.color))
|
fd.write("#{} = {}\n".format(light.topic, light.color))
|
||||||
|
@ -780,7 +776,7 @@ class RemotePresets:
|
||||||
def _expand_room_name(self, name):
|
def _expand_room_name(self, name):
|
||||||
"""Try to expand partial names."""
|
"""Try to expand partial names."""
|
||||||
if name in self.map.keys():
|
if name in self.map.keys():
|
||||||
# Return exact match
|
# Return on exact match
|
||||||
return name
|
return name
|
||||||
|
|
||||||
for room in self.map.keys():
|
for room in self.map.keys():
|
||||||
|
@ -808,8 +804,7 @@ class RemotePresets:
|
||||||
|
|
||||||
# First check if there is an exact match
|
# First check if there is an exact match
|
||||||
if name in matchtable.keys() and matchtable[name] == len(rooms):
|
if name in matchtable.keys() and matchtable[name] == len(rooms):
|
||||||
return name # Exact match
|
return name
|
||||||
|
|
||||||
# Return first preset available in all rooms
|
# Return first preset available in all rooms
|
||||||
for match in matchtable.keys():
|
for match in matchtable.keys():
|
||||||
if matchtable[match] == len(rooms):
|
if matchtable[match] == len(rooms):
|
||||||
|
@ -821,7 +816,7 @@ class RemotePresets:
|
||||||
"""Returns a dict of remotely available presets for [rooms]."""
|
"""Returns a dict of remotely available presets for [rooms]."""
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# "global" is available everywhere and should always be included
|
# Presets in "global" are available everywhere and should always be included
|
||||||
if "global" not in rooms:
|
if "global" not in rooms:
|
||||||
rooms.append("global")
|
rooms.append("global")
|
||||||
|
|
||||||
|
@ -849,11 +844,7 @@ class RemotePresets:
|
||||||
def list_available(self, room="global"):
|
def list_available(self, room="global"):
|
||||||
"""Print a list of available Presets."""
|
"""Print a list of available Presets."""
|
||||||
room = self._expand_room_name(room)
|
room = self._expand_room_name(room)
|
||||||
if room == "global":
|
available = self.query_available([room])
|
||||||
rooms = [room]
|
|
||||||
else: # "global" is available in every room, thus append
|
|
||||||
rooms = ["global", room]
|
|
||||||
available = self.query_available(rooms.copy())
|
|
||||||
|
|
||||||
if not available:
|
if not available:
|
||||||
print("No presets available for {}".format(self.map[room]["name"]))
|
print("No presets available for {}".format(self.map[room]["name"]))
|
||||||
|
@ -891,8 +882,7 @@ class RemotePresets:
|
||||||
|
|
||||||
cmd = []
|
cmd = []
|
||||||
for room in rooms:
|
for room in rooms:
|
||||||
cmd.append({"topic" : self.map[room]["set_topic"],
|
cmd.append((self.map[room]["set_topic"], preset))
|
||||||
"payload" : preset})
|
|
||||||
|
|
||||||
c4 = C4Interface()
|
c4 = C4Interface()
|
||||||
return c4.update(cmd)
|
return c4.update(cmd)
|
||||||
|
@ -1017,10 +1007,10 @@ if __name__ == "__main__":
|
||||||
#remote_opts = ' '.join(args.remote_preset).split(':')
|
#remote_opts = ' '.join(args.remote_preset).split(':')
|
||||||
remote_opts = args.remote_preset.split(':')
|
remote_opts = args.remote_preset.split(':')
|
||||||
if len(remote_opts) == 1:
|
if len(remote_opts) == 1:
|
||||||
RemotePresets().apply_preset(remote_opts[0].lower().strip())
|
RemotePresets().apply_preset(remote_opts[0].strip())
|
||||||
else:
|
else:
|
||||||
RemotePresets().apply_preset(remote_opts[0].lower().strip(),
|
RemotePresets().apply_preset(remote_opts[0].strip(),
|
||||||
remote_opts[1].split(','))
|
remote_opts[1].lower().split(','))
|
||||||
|
|
||||||
# Light switches
|
# Light switches
|
||||||
if args.w_switch:
|
if args.w_switch:
|
||||||
|
|
Loading…
Reference in a new issue