From a876d666253d24d307172b441280a3ff2fac9604 Mon Sep 17 00:00:00 2001 From: Nick Pesce Date: Sun, 6 Dec 2020 15:37:20 -0500 Subject: [PATCH] Fix color state --- lit/color.py | 7 +++++-- lit/commands.py | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lit/color.py b/lit/color.py index 7a8d6bb..a3a27cf 100644 --- a/lit/color.py +++ b/lit/color.py @@ -8,7 +8,7 @@ def new_generator(self, args, lights): return ColorGenerator(self, args, lights) def __str__(self): - return str({"name": self.name, "schema": self.schema}) + return str({"type": self.name, "schema": self.schema}) class ColorGenerator: @@ -26,5 +26,8 @@ def get_palette(self, size): return self.color_type.module.get_palette(size) return [self.get_color(i) for i in range(size)] + def as_dict(self): + return {"type": self.color_type.name, "args": self.args} + def __str__(self): - return str({"name": self.color_type.name, "args": self.args}) + return str(self.as_dict) diff --git a/lit/commands.py b/lit/commands.py index f09e915..54535bd 100644 --- a/lit/commands.py +++ b/lit/commands.py @@ -334,7 +334,9 @@ def get_colors(self): return self.named_rgb_colors def get_color_types(self): - return [{"name": ct.name, "schema": ct.schema} for ct in self.color_types.values()] + return [ + {"name": ct.name, "schema": ct.schema} for ct in self.color_types.values() + ] def get_sections(self): return self.sections @@ -349,7 +351,19 @@ def get_state(self): state = [] def state_schema(state, schema): - return {k: v for k, v in state.items() if k in schema} + processed = {} + for k, v in state.items(): + if k in schema: + if ( + not isinstance(v, (dict, str, int, float, bool)) + and v is not None + ): + try: + v = v.as_dict() + except AttributeError: + v = str(v) + processed[k] = v + return processed with self.show_lock: for effect in self.effects_by_id.values():