From f3679cbd29895d210d1c105a99cf387736146c24 Mon Sep 17 00:00:00 2001 From: oberon Date: Mon, 16 Feb 2026 14:49:18 +0100 Subject: [PATCH] fixxed imports, added state.py --- app/__init__.py | 6 ++++++ app/bluetooth/manager.py | 2 ++ app/routes/admin.py | 2 +- app/routes/api.py | 3 ++- app/routes/main.py | 2 +- app/state.py | 14 ++++++++++++++ 6 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 app/state.py diff --git a/app/__init__.py b/app/__init__.py index 4af1b1e..e64bfb4 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -6,6 +6,7 @@ from .routes.main import main_bp from .routes.admin import admin_bp from .routes.api import api_bp import threading +import pygame def create_app(): @@ -32,6 +33,11 @@ def create_app(): from .bluetooth.manager import init_bluetooth init_bluetooth() + # pygame initialisieren (einmalig) + pygame.mixer.init(frequency=44100, size=-16, channels=2, buffer=512) + pygame.mixer.music.set_volume(0.8) # Standard-Lautstärke + app.logger.info("pygame initialisiert") + # Blueprints registrieren from .routes.main import main_bp from .routes.admin import admin_bp diff --git a/app/bluetooth/manager.py b/app/bluetooth/manager.py index abb9611..998d2c4 100644 --- a/app/bluetooth/manager.py +++ b/app/bluetooth/manager.py @@ -30,6 +30,8 @@ def init_bluetooth(): logger.info("Bluetooth-Komponenten initialisiert (Advertiser + Tracer)") # Hier ggf. weitere Initialisierung (z. B. hci0 prüfen) +from app.state import current_device, current_module, current_hub + def connection_monitor(): """ Background-Thread: Prüft alle 5 Sekunden, ob der Hub noch antwortet. diff --git a/app/routes/admin.py b/app/routes/admin.py index f49b392..290ed67 100644 --- a/app/routes/admin.py +++ b/app/routes/admin.py @@ -1,6 +1,6 @@ # app/routes/admin.py from flask import Blueprint, render_template, request, jsonify, redirect, url_for -from .. import current_config +from app.state import current_config from app.utils.helpers import load_configs, load_default_sounds admin_bp = Blueprint('admin', __name__) diff --git a/app/routes/api.py b/app/routes/api.py index cb3f8ef..529e738 100644 --- a/app/routes/api.py +++ b/app/routes/api.py @@ -1,6 +1,7 @@ # app/routes/api.py +import pygame from flask import Blueprint, jsonify, request -from .. import current_device, current_config, pygame +from app.state import current_device, current_config api_bp = Blueprint('api', __name__) diff --git a/app/routes/main.py b/app/routes/main.py index 9e0df94..079345f 100644 --- a/app/routes/main.py +++ b/app/routes/main.py @@ -1,7 +1,7 @@ # app/routes/main.py from flask import Blueprint, render_template, redirect, url_for, request, jsonify -from .. import current_config from app.utils.helpers import load_configs, load_default_sounds +from app.state import current_config, reset_state main_bp = Blueprint('main', __name__) diff --git a/app/state.py b/app/state.py new file mode 100644 index 0000000..11dc05d --- /dev/null +++ b/app/state.py @@ -0,0 +1,14 @@ +# app/state.py – Zentrale globale Zustände (wird von überall importiert) + +current_config = None +current_hub = None +current_module = None +current_device = None + +# Optional: Funktionen zum Setzen/Resetten (für Klarheit) +def reset_state(): + global current_config, current_hub, current_module, current_device + current_config = None + current_hub = None + current_module = None + current_device = None \ No newline at end of file