diff --git a/profiles/ring.json b/profiles/ring.json index a5dbfb1..4d8f86e 100644 --- a/profiles/ring.json +++ b/profiles/ring.json @@ -1,55 +1,9 @@ { "tab_password": "", - "patterns": { - "on": { - "min_delay": 10, - "max_delay": 10000 - }, - "off": { - "min_delay": 10, - "max_delay": 10000 - }, - "rainbow": { - "Step Rate": "n1", - "min_delay": 10, - "max_delay": 10000 - }, - "transition": { - "min_delay": 10, - "max_delay": 10000 - }, - "chase": { - "Colour 1 Length": "n1", - "Colour 2 Length": "n2", - "Step 1": "n3", - "Step 2": "n4", - "min_delay": 10, - "max_delay": 10000 - }, - "pulse": { - "Attack": "n1", - "Hold": "n2", - "Decay": "n3", - "min_delay": 10, - "max_delay": 10000 - }, - "circle": { - "Head Rate": "n1", - "Max Length": "n2", - "Tail Rate": "n3", - "Min Length": "n4", - "min_delay": 10, - "max_delay": 10000 - }, - "blink": { - "min_delay": 10, - "max_delay": 10000 - } - }, "lights": { - "ring1": { + "test": { "names": [ - "dj" + "1" ], "settings": { "pattern": "on", @@ -62,52 +16,11 @@ "n2": 10, "n3": 10, "n4": 10, - "patterns": { - "on": { - "colors": [ - "#000000" - ], - "delay": 99, - "n1": 10, - "n2": 10, - "n3": 10, - "n4": 10 - } - } - } - }, - "ring2": { - "names": [ - "ring2" - ], - "settings": { - "pattern": "on", - "brightness": 127, - "colors": [ - "#000000" - ], - "delay": 100, - "n1": 10, - "n2": 10, - "n3": 10, - "n4": 10, - "patterns": { - "on": { - "colors": [ - "#000000" - ], - "delay": 99, - "n1": 10, - "n2": 10, - "n3": 10, - "n4": 10 - } - } + "patterns": {} } } }, "tab_order": [ - "ring1", - "ring2" + "test" ] } \ No newline at end of file diff --git a/src/flask_app.py b/src/flask_app.py index c71345a..d48ddd3 100644 --- a/src/flask_app.py +++ b/src/flask_app.py @@ -83,6 +83,40 @@ def save_pattern_settings(tab_name, pattern_name, colors=None, delay=None, n_par pattern_settings[f"n{i}"] = n_params[f"n{i}"] +def save_current_profile(): + """Save current settings to the active profile file.""" + current_profile = settings.get("current_profile") + if not current_profile: + return + + try: + profiles_dir = "profiles" + os.makedirs(profiles_dir, exist_ok=True) + profile_path = os.path.join(profiles_dir, f"{current_profile}.json") + + # Get current tab order + tab_order = settings.get("tab_order", []) + if "lights" in settings: + # Ensure all current tabs are in the order + current_tabs = set(settings["lights"].keys()) + order_tabs = set(tab_order) + for tab in current_tabs: + if tab not in order_tabs: + tab_order.append(tab) + settings["tab_order"] = tab_order + + # Save to profile file (exclude current_profile from profile) + profile_data = dict(settings) + profile_data.pop("current_profile", None) + profile_data.pop("patterns", None) # Patterns stay in settings.json + + with open(profile_path, 'w') as file: + json.dump(profile_data, file, indent=4) + print(f"Profile '{current_profile}' saved successfully.") + except Exception as e: + print(f"Error saving profile: {e}") + + async def send_to_lighting_controller(payload): """Send data to the lighting controller via WebSocket.""" global websocket_client @@ -257,7 +291,9 @@ def set_parameters(): } run_async(send_to_lighting_controller(payload)) + # Save to settings.json (for patterns) and to profile file (for lights data) settings.save() + save_current_profile() return jsonify({"success": True}) @@ -303,6 +339,7 @@ def create_tab(): settings["tab_order"] = [] settings["tab_order"].append(tab_name) settings.save() + save_current_profile() return jsonify({"success": True, "tab_name": tab_name}) @@ -336,6 +373,7 @@ def update_tab(tab_name): settings["lights"][tab_name]["names"] = ids if isinstance(ids, list) else [ids] settings.save() + save_current_profile() return jsonify({"success": True, "tab_name": tab_name}) @@ -352,6 +390,7 @@ def delete_tab(tab_name): settings["tab_order"].remove(tab_name) settings.save() + save_current_profile() return jsonify({"success": True})