Skip to content

Commit

Permalink
Merge pull request #12 from Glennmen/convert-script-v2
Browse files Browse the repository at this point in the history
Parse presets.json
  • Loading branch information
nilsreiter authored Oct 27, 2024
2 parents 64a79d2 + a83d472 commit 756684d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/presets.json
49 changes: 37 additions & 12 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=(',', ':')))
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}\"")
print(f"- \"{s}\"")

0 comments on commit 756684d

Please sign in to comment.