From a83d47230f8362a1518d5af9ebe4ab4b30565ff5 Mon Sep 17 00:00:00 2001 From: Glenn Carremans Date: Sun, 27 Oct 2024 20:26:08 +0100 Subject: [PATCH] Update script to latest json format --- .gitignore | 1 - convert-v2.py | 39 --------------------------------------- convert.py | 47 ++++++++++++++++++++++++++++++++++++----------- 3 files changed, 36 insertions(+), 51 deletions(-) delete mode 100644 convert-v2.py diff --git a/.gitignore b/.gitignore index 260867b..0988cef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -/scenes.json /presets.json diff --git a/convert-v2.py b/convert-v2.py deleted file mode 100644 index 55d359a..0000000 --- a/convert-v2.py +++ /dev/null @@ -1,39 +0,0 @@ -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}\"") diff --git a/convert.py b/convert.py index f7367c5..f0e7f07 100644 --- a/convert.py +++ b/convert.py @@ -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}\"")