Skip to content

Commit

Permalink
Fix color state
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpesce committed Dec 6, 2020
1 parent 4cf53f1 commit a876d66
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lit/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
18 changes: 16 additions & 2 deletions lit/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down

0 comments on commit a876d66

Please sign in to comment.