Added support for fluffyd

This commit is contained in:
Shy 2017-03-17 23:27:54 +01:00
parent 4482c3d35c
commit fd051d4664

View file

@ -113,6 +113,7 @@ class Dmx:
def __init__(self, topic, color=None): def __init__(self, topic, color=None):
self.topic = topic self.topic = topic
self.set_color(color or self.template) self.set_color(color or self.template)
self.is_master = topic.rfind("/master") == len(topic)-7 # 7 = len("/master")
def __repr__(self): def __repr__(self):
return "<Dmx '{}: {}'>".format(self.topic, self.color) return "<Dmx '{}: {}'>".format(self.topic, self.color)
@ -225,18 +226,28 @@ class C4Room:
return self.c4.push(cmd) return self.c4.push(cmd)
def set_colorscheme(self, colorscheme): def set_colorscheme(self, colorscheme, magic=False):
"""Apply colorscheme to the LED Cans in this room.""" """Apply colorscheme to the LED Cans in this room."""
cmd = [] cmd = []
for light in self.lights: for light in self.lights:
if colorscheme.color_for(light.topic): if colorscheme.color_for(light.topic):
light.set_color(colorscheme.color_for(light.topic)) if magic: # Send color to ghost, but skip masters
cmd.append({ if light.is_master: continue
"topic" : light.topic,
"payload" : light.payload
})
return self.c4.push(cmd) light.set_color(colorscheme.color_for(light.topic))
cmd.append({
"topic" : "ghost" + light.topic[light.topic.find('/'):],
"payload" : light.payload
})
else:
light.set_color(colorscheme.color_for(light.topic))
cmd.append({
"topic" : light.topic,
"payload" : light.payload
})
# Do not retain "magic" messages
return self.c4.push(cmd, retain=(not magic))
class Wohnzimmer(C4Room): class Wohnzimmer(C4Room):
@ -610,7 +621,7 @@ class ColorScheme:
return self.single_color return self.single_color
elif self.return_random_color: elif self.return_random_color:
# Returning a value for master would override all other settings # Returning a value for master would override all other settings
if self._topic_is_master(topic): # 7 = len("/master") if self._topic_is_master(topic):
return None return None
else: else:
return self._random_color() return self._random_color()
@ -720,7 +731,7 @@ 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())
# Out comment master, as it would overre 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(light.topic, light.color))
else: else:
@ -936,6 +947,9 @@ if __name__ == "__main__":
group_cl.add_argument( group_cl.add_argument(
"-f", "--fnordcenter", type=str, dest="f_color", metavar="PRESET", "-f", "--fnordcenter", type=str, dest="f_color", metavar="PRESET",
help="apply local colorscheme PRESET to Fnordcenter") help="apply local colorscheme PRESET to Fnordcenter")
group_cl.add_argument(
"-m", "--magic", action="store_true", default=False,
help="EXPERIMENTAL: blend into preset (needs a running instance of fluffyd)")
group_cl.add_argument( group_cl.add_argument(
"-l", "--list-presets", action="store_true", "-l", "--list-presets", action="store_true",
help="list locally available presets") help="list locally available presets")
@ -998,13 +1012,13 @@ if __name__ == "__main__":
ColorScheme().store(args.store_as) ColorScheme().store(args.store_as)
if args.w_color: if args.w_color:
preset = ColorScheme(autoinit=args.w_color) preset = ColorScheme(autoinit=args.w_color)
if preset: Wohnzimmer().set_colorscheme(preset) if preset: Wohnzimmer().set_colorscheme(preset, args.magic)
if args.p_color: if args.p_color:
preset = ColorScheme(autoinit=args.p_color) preset = ColorScheme(autoinit=args.p_color)
if preset: Plenarsaal().set_colorscheme(preset) if preset: Plenarsaal().set_colorscheme(preset, args.magic)
if args.f_color: if args.f_color:
preset = ColorScheme(autoinit=args.f_color) preset = ColorScheme(autoinit=args.f_color)
if preset: Fnordcenter().set_colorscheme(preset) if preset: Fnordcenter().set_colorscheme(preset, args.magic)
if args.list_presets: if args.list_presets:
ColorScheme().list_available() ColorScheme().list_available()