Skip to content

Commit

Permalink
Parse presets.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Glennmen committed Oct 24, 2024
1 parent cb3005b commit 2f472ab
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 4

[*.py]
indent_size = 2

[{*.yaml,*.yml}]
indent_size = 2
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/scenes.json
/presets.json
39 changes: 39 additions & 0 deletions convert-v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json

f = open("presets.json")
obj = json.load(f)

d = {}
l = []

categories = obj["categories"]

for preset in obj["presets"]:
set_name = None
for category in categories:
if preset["categoryId"] == category["id"] and category["id"] != "6e102277-814f-47c7-a054-f4a31cae30bf":
set_name = category["name"]
break

if set_name is None:
print(f"Warning: No category found for preset {preset['name']}")
continue

scene_name = preset["name"]
bri = preset["bri"]
lights = [[l["x"], l["y"]] for l in preset["lights"]]
s = {"c": lights, "b": round(bri / 255, 3), "s": set_name}
d[scene_name] = s
l.append(set_name + ": " + scene_name)

sorted_json = {k: d[k] for k in sorted(d)}
with open('output.json', 'w') as f:
# Need to add Colorloop and Random manually
json.dump(sorted_json, f, separators=(',', ':'), ensure_ascii=False)

l.sort()
l.append("Special: Colorloop")
l.append("Special: Random")

for s in l:
print(f"- \"{s}\"")
8 changes: 4 additions & 4 deletions convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
for scene in scene_set["scenes"]:
scene_name = scene["name"]
bri = scene["bri"]
lights = [ [l["x"],l["y"]] for l in scene["lights"]]
s = { "c": lights, "b": round(bri/255, 3), "s": set_name }
lights = [[l["x"], l["y"]] for l in scene["lights"]]
s = {"c": lights, "b": round(bri / 255, 3), "s": set_name}
d[scene_name] = s
l.append(set_name + ": " + scene_name)

print(json.dumps(d, separators=(',', ':')))
print(json.dumps(d, separators=(',', ':'), sort_keys=True))

l.sort()

for s in l:
print(f"- \"{s}\"")
print(f"- \"{s}\"")

0 comments on commit 2f472ab

Please sign in to comment.