Nicer format for -o
This commit is contained in:
parent
1ca22a14c3
commit
a1edf556d0
1 changed files with 24 additions and 10 deletions
34
c4ctrl.py
34
c4ctrl.py
|
@ -243,7 +243,7 @@ class C4Room:
|
||||||
for light in self.lights:
|
for light in self.lights:
|
||||||
if colorscheme.color_for(light.topic):
|
if colorscheme.color_for(light.topic):
|
||||||
if magic != "none" and magic != '0': # Send color to ghost, but skip masters
|
if magic != "none" and magic != '0': # Send color to ghost, but skip masters
|
||||||
if light.is_master: continue
|
#if light.is_master: continue
|
||||||
|
|
||||||
mode_id, error = Fluffy().mode_id(magic)
|
mode_id, error = Fluffy().mode_id(magic)
|
||||||
if error:
|
if error:
|
||||||
|
@ -658,14 +658,17 @@ class ColorScheme:
|
||||||
|
|
||||||
def color_for(self, topic):
|
def color_for(self, topic):
|
||||||
"""Returns the color (hex) this ColorScheme provides for the given topic."""
|
"""Returns the color (hex) this ColorScheme provides for the given topic."""
|
||||||
|
# We need to take care not to return colors for both "normal" topics
|
||||||
|
# and masters, as setting masters would override other settings
|
||||||
if self.mapping:
|
if self.mapping:
|
||||||
if topic in self.mapping.keys():
|
if topic in self.mapping.keys():
|
||||||
return self.mapping[topic]
|
return self.mapping[topic]
|
||||||
elif self.single_color:
|
elif self.single_color:
|
||||||
#return self.single_color
|
if self._topic_is_master(topic):
|
||||||
return self._single_color()
|
return None
|
||||||
|
else:
|
||||||
|
return self._single_color()
|
||||||
elif self.return_random_color:
|
elif self.return_random_color:
|
||||||
# Returning a value for master would override all other settings
|
|
||||||
if self._topic_is_master(topic):
|
if self._topic_is_master(topic):
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
|
@ -712,7 +715,7 @@ class ColorScheme:
|
||||||
# Validate hex code
|
# Validate hex code
|
||||||
for c in v.lower():
|
for c in v.lower():
|
||||||
if c not in "0123456789abcdef":
|
if c not in "0123456789abcdef":
|
||||||
print("Error: invalid color code \"{}\" in preset \"{}\"!".format(v, preset))
|
print("Error: invalid color code \"{}\" in preset \"{}\"!".format(v, preset), file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
self.mapping[k] = v
|
self.mapping[k] = v
|
||||||
|
|
||||||
|
@ -770,14 +773,20 @@ class ColorScheme:
|
||||||
c4 = C4Interface()
|
c4 = C4Interface()
|
||||||
|
|
||||||
if name == '-':
|
if name == '-':
|
||||||
fd.write("# Preset (auto generated)\n".format(name))
|
fd.write("# c4ctrl preset (auto generated)\n".format(name))
|
||||||
else:
|
else:
|
||||||
fd.write("# Preset \"{}\" (auto generated)\n".format(name))
|
fd.write("# c4ctrl preset \"{}\" (auto generated)\n".format(name))
|
||||||
fd.write("# Note: \"/master\" topics override every other topic in the room.\n")
|
fd.write("#\n")
|
||||||
|
fd.write("# Note: Topics ending with \"/master\" override all other topics in a room.\n")
|
||||||
|
fd.write("# All spaces will be stripped and lines beginning with \'#\' ignored.\n")
|
||||||
for room in Wohnzimmer, Plenarsaal, Fnordcenter:
|
for room in Wohnzimmer, Plenarsaal, Fnordcenter:
|
||||||
topics = []
|
topics = []
|
||||||
|
max_topic_len = 0
|
||||||
|
|
||||||
for light in room.lights:
|
for light in room.lights:
|
||||||
topics.append(light.topic)
|
topics.append(light.topic)
|
||||||
|
if len(light.topic) > max_topic_len:
|
||||||
|
max_topic_len = len(light.topic)
|
||||||
|
|
||||||
responce = c4.pull(topics)
|
responce = c4.pull(topics)
|
||||||
fd.write("\n# {}\n".format(room.name))
|
fd.write("\n# {}\n".format(room.name))
|
||||||
|
@ -785,11 +794,16 @@ class ColorScheme:
|
||||||
for r in responce:
|
for r in responce:
|
||||||
if r.topic == light.topic:
|
if r.topic == light.topic:
|
||||||
light.set_color(r.payload.hex())
|
light.set_color(r.payload.hex())
|
||||||
|
# Format payload more nicely
|
||||||
|
color = light.color
|
||||||
|
if len(color) > 6:
|
||||||
|
color = color[:6] + ' ' + color[6:]
|
||||||
|
topic = light.topic.ljust(max_topic_len)
|
||||||
# Out comment master, as it would override everything else
|
# Out comment master, as it would override 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(topic, color))
|
||||||
else:
|
else:
|
||||||
fd.write("{} = {}\n".format(light.topic, light.color))
|
fd.write("{} = {}\n".format(topic, color))
|
||||||
|
|
||||||
if name != '-':
|
if name != '-':
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
Loading…
Reference in a new issue