Skip to content

Commit

Permalink
Update script to latest json format
Browse files Browse the repository at this point in the history
  • Loading branch information
Glennmen committed Oct 27, 2024
1 parent 2f472ab commit a83d472
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 51 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/scenes.json
/presets.json
39 changes: 0 additions & 39 deletions convert-v2.py

This file was deleted.

47 changes: 36 additions & 11 deletions convert.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
import json

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

d = {}
l = []

for scene_set in obj["sets"]:
set_name = scene_set["name"]
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}
d[scene_name] = s
l.append(set_name + ": " + scene_name)
categories = obj["categories"]

print(json.dumps(d, separators=(',', ':'), sort_keys=True))
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"]
preset_id = preset["id"]
bri = preset["bri"]
lights = [[l["x"], l["y"]] for l in preset["lights"]]
s = {"c": lights, "b": round(bri / 255, 3), "s": set_name, "n": scene_name}
d[preset_id] = s
l.append(set_name + ": " + scene_name)

sorted_json = {k: d[k] for k in sorted(d)}
with open('output.json', 'w') as f:
for key, value in sorted_json.items():
f.write(f'{json.dumps(value, separators=(',', ':'), ensure_ascii=False)},\n')
f.write("""{"colors":[
[ range(hue_min|default(0),hue_max|default(360))|random,range(sat_min|default(99),sat_max|default(101))|random ],
[ range(hue_min|default(0),hue_max|default(360))|random,range(sat_min|default(99),sat_max|default(101))|random ],
[ range(hue_min|default(0),hue_max|default(360))|random,range(sat_min|default(99),sat_max|default(101))|random ],
[ range(hue_min|default(0),hue_max|default(360))|random,range(sat_min|default(99),sat_max|default(101))|random ],
[ range(hue_min|default(0),hue_max|default(360))|random,range(sat_min|default(99),sat_max|default(101))|random ],
],"s":"Special","n":"Random"},
""")
f.write('{"colors":[],"s":"Special","n":"Colorloop"}')

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

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

0 comments on commit a83d472

Please sign in to comment.