🐛 Refactor: Update printer status handling and session management. Improved caching mechanism for live printer status and added summary functionality. Removed obsolete database files for better organization.

This commit is contained in:
2025-06-12 19:48:45 +02:00
parent 61607ae082
commit 10423eb1e3
29 changed files with 399 additions and 14 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -588,7 +588,7 @@ def api_get_notifications():
with get_cached_session() as db_session:
query = db_session.query(Notification).filter_by(
user_id=current_user.id,
read=False
is_read=False
)
if since_date:
@ -619,7 +619,7 @@ def api_mark_notification_read(notification_id):
if not notification:
return jsonify({"error": "Benachrichtigung nicht gefunden"}), 404
notification.read = True
notification.is_read = True
db_session.commit()
return jsonify({"success": True})

View File

@ -9,7 +9,6 @@ from flask_login import login_required, current_user
from datetime import datetime, timedelta
from models import User, get_db_session, SystemLog
from utils.logging_config import get_logger
from utils.utilities_collection import SESSION_LIFETIME
# Blueprint erstellen
sessions_blueprint = Blueprint('sessions', __name__, url_prefix='/api/session')
@ -17,6 +16,20 @@ sessions_blueprint = Blueprint('sessions', __name__, url_prefix='/api/session')
# Logger initialisieren
sessions_logger = get_logger("sessions")
# Session-Lifetime sicher importieren
try:
from utils.utilities_collection import SESSION_LIFETIME
# Sicherstellen, dass es ein timedelta ist
if isinstance(SESSION_LIFETIME, (int, float)):
SESSION_LIFETIME_TD = timedelta(seconds=SESSION_LIFETIME)
elif isinstance(SESSION_LIFETIME, timedelta):
SESSION_LIFETIME_TD = SESSION_LIFETIME
else:
SESSION_LIFETIME_TD = timedelta(hours=1) # Fallback: 1 Stunde
except ImportError:
SESSION_LIFETIME_TD = timedelta(hours=1) # Fallback: 1 Stunde
sessions_logger.warning("SESSION_LIFETIME konnte nicht importiert werden, verwende Fallback (1h)")
@sessions_blueprint.route('/heartbeat', methods=['POST'])
@login_required
def heartbeat():
@ -40,14 +53,14 @@ def heartbeat():
session_start = session.get('session_start')
if session_start:
elapsed = (datetime.now() - datetime.fromisoformat(session_start)).total_seconds()
remaining = max(0, SESSION_LIFETIME.total_seconds() - elapsed)
remaining = max(0, SESSION_LIFETIME_TD.total_seconds() - elapsed)
else:
remaining = SESSION_LIFETIME.total_seconds()
remaining = SESSION_LIFETIME_TD.total_seconds()
return jsonify({
'success': True,
'remaining_seconds': int(remaining),
'session_lifetime': int(SESSION_LIFETIME.total_seconds())
'session_lifetime': int(SESSION_LIFETIME_TD.total_seconds())
})
except Exception as e:
@ -66,9 +79,9 @@ def status():
# Verbleibende Zeit berechnen
if session_start:
elapsed = (datetime.now() - datetime.fromisoformat(session_start)).total_seconds()
remaining = max(0, SESSION_LIFETIME.total_seconds() - elapsed)
remaining = max(0, SESSION_LIFETIME_TD.total_seconds() - elapsed)
else:
remaining = SESSION_LIFETIME.total_seconds()
remaining = SESSION_LIFETIME_TD.total_seconds()
# Inaktivitätszeit berechnen
if last_activity:
@ -90,7 +103,7 @@ def status():
'last_activity': last_activity,
'remaining_seconds': int(remaining),
'inactive_seconds': int(inactive_seconds),
'lifetime_seconds': int(SESSION_LIFETIME.total_seconds()),
'lifetime_seconds': int(SESSION_LIFETIME_TD.total_seconds()),
'is_permanent': session.permanent
}
})
@ -128,7 +141,7 @@ def extend():
return jsonify({
'success': True,
'message': 'Session wurde verlängert',
'new_lifetime_seconds': int(SESSION_LIFETIME.total_seconds())
'new_lifetime_seconds': int(SESSION_LIFETIME_TD.total_seconds())
})
except Exception as e:

View File

@ -20543,3 +20543,22 @@ WHERE users.id = ?
2025-06-12 15:25:29 - [app] app - [DEBUG] DEBUG - Request: GET /api/notifications
2025-06-12 15:25:29 - [app] app - [ERROR] ERROR - Datenbank-Transaktion fehlgeschlagen: Entity namespace for "notifications" has no property "read"
2025-06-12 15:25:29 - [app] app - [DEBUG] DEBUG - Response: 500
2025-06-12 16:31:40 - [app] app - [DEBUG] DEBUG - Request: GET /auth/logout
2025-06-12 16:31:40 - [app] app - [DEBUG] DEBUG - Request: GET /api/notifications
2025-06-12 16:31:40 - [app] app - [DEBUG] DEBUG - Response: 302
2025-06-12 16:31:40 - [app] app - [DEBUG] DEBUG - Response: 302
2025-06-12 16:31:40 - [app] app - [DEBUG] DEBUG - Request: GET /auth/login
2025-06-12 16:31:40 - [app] app - [DEBUG] DEBUG - Request: GET /auth/login
2025-06-12 16:31:40 - [app] app - [DEBUG] DEBUG - Response: 200
2025-06-12 16:31:40 - [app] app - [DEBUG] DEBUG - Response: 200
2025-06-12 16:32:23 - [app] app - [WARNING] WARNING - CSRF-Fehler: The CSRF tokens do not match.
2025-06-12 16:32:23 - [app] app - [DEBUG] DEBUG - Response: 400
2025-06-12 19:47:01 - [app] app - [INFO] INFO - Optimierte SQLite-Engine erstellt: backend/database/myp.db
2025-06-12 19:47:04 - [app] app - [INFO] INFO - [CONFIG] Erkannte Umgebung: development
2025-06-12 19:47:04 - [app] app - [INFO] INFO - [CONFIG] Production-Modus: False
2025-06-12 19:47:04 - [app] app - [INFO] INFO - [CONFIG] Verwende Development-Konfiguration
2025-06-12 19:47:04 - [app] app - [INFO] INFO - [DEVELOPMENT] Aktiviere Development-Konfiguration
2025-06-12 19:47:04 - [app] app - [INFO] INFO - [DEVELOPMENT] ✅ MYP Development Environment Konfiguration aktiviert
2025-06-12 19:47:04 - [app] app - [INFO] INFO - [DEVELOPMENT] ✅ Environment: Development/Testing
2025-06-12 19:47:04 - [app] app - [INFO] INFO - [DEVELOPMENT] ✅ Debug Mode: True
2025-06-12 19:47:04 - [app] app - [INFO] INFO - [DEVELOPMENT] ✅ SQL Echo: True

View File

@ -41,3 +41,5 @@ WHERE users.username = ? OR users.email = ?
2025-06-12 12:21:39 - [auth] auth - [INFO] INFO - Benutzer admin@mercedes-benz.com hat sich abgemeldet
2025-06-12 14:32:34 - [auth] auth - [WARNING] WARNING - JSON-Parsing fehlgeschlagen: 400 Bad Request: Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)
2025-06-12 14:32:34 - [auth] auth - [INFO] INFO - Benutzer admin@mercedes-benz.com hat sich erfolgreich angemeldet
2025-06-12 15:24:31 - [auth] auth - [WARNING] WARNING - JSON-Parsing fehlgeschlagen: 400 Bad Request: Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)
2025-06-12 15:24:31 - [auth] auth - [INFO] INFO - Benutzer admin@mercedes-benz.com hat sich erfolgreich angemeldet

View File

@ -162,3 +162,5 @@
2025-06-12 15:24:05 - [core_system] core_system - [INFO] INFO - 📊 Massive Konsolidierung: 6 Dateien → 1 Datei (88% Reduktion)
2025-06-12 15:24:09 - [core_system] core_system - [INFO] INFO - ✅ Core System Management Module erfolgreich initialisiert
2025-06-12 15:24:09 - [core_system] core_system - [INFO] INFO - 📊 Massive Konsolidierung: 6 Dateien → 1 Datei (88% Reduktion)
2025-06-12 19:47:01 - [core_system] core_system - [INFO] INFO - ✅ Core System Management Module erfolgreich initialisiert
2025-06-12 19:47:01 - [core_system] core_system - [INFO] INFO - 📊 Massive Konsolidierung: 6 Dateien → 1 Datei (88% Reduktion)

View File

@ -162,3 +162,5 @@
2025-06-12 15:24:06 - [data_management] data_management - [INFO] INFO - 📊 Massive Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion)
2025-06-12 15:24:09 - [data_management] data_management - [INFO] INFO - ✅ Data Management Module initialisiert
2025-06-12 15:24:09 - [data_management] data_management - [INFO] INFO - 📊 Massive Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion)
2025-06-12 19:47:01 - [data_management] data_management - [INFO] INFO - ✅ Data Management Module initialisiert
2025-06-12 19:47:01 - [data_management] data_management - [INFO] INFO - 📊 Massive Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion)

View File

@ -25,3 +25,7 @@ WHERE user_permissions.can_approve_jobs = 1]
2025-06-12 15:19:29 - [guest] guest - [ERROR] ERROR - Fehler beim Abrufen der Benachrichtigungen: Entity namespace for "notifications" has no property "read"
2025-06-12 15:20:29 - [guest] guest - [ERROR] ERROR - Fehler beim Abrufen der Benachrichtigungen: Entity namespace for "notifications" has no property "read"
2025-06-12 15:22:29 - [guest] guest - [ERROR] ERROR - Fehler beim Abrufen der Benachrichtigungen: Entity namespace for "notifications" has no property "read"
2025-06-12 15:24:33 - [guest] guest - [ERROR] ERROR - Fehler beim Abrufen der Benachrichtigungen: Entity namespace for "notifications" has no property "read"
2025-06-12 15:24:36 - [guest] guest - [ERROR] ERROR - Fehler beim Abrufen der Benachrichtigungen: Entity namespace for "notifications" has no property "read"
2025-06-12 15:24:59 - [guest] guest - [ERROR] ERROR - Fehler beim Abrufen der Benachrichtigungen: Entity namespace for "notifications" has no property "read"
2025-06-12 15:25:29 - [guest] guest - [ERROR] ERROR - Fehler beim Abrufen der Benachrichtigungen: Entity namespace for "notifications" has no property "read"

View File

@ -330,3 +330,7 @@
2025-06-12 15:24:09 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ Printer Monitor initialisiert
2025-06-12 15:24:09 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ Hardware Integration Module initialisiert
2025-06-12 15:24:09 - [hardware_integration] hardware_integration - [INFO] INFO - 📊 Massive Konsolidierung: 2 Dateien → 1 Datei (50% Reduktion)
2025-06-12 19:47:01 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ PyP100 (TP-Link Tapo) verfügbar
2025-06-12 19:47:01 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ Printer Monitor initialisiert
2025-06-12 19:47:01 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ Hardware Integration Module initialisiert
2025-06-12 19:47:01 - [hardware_integration] hardware_integration - [INFO] INFO - 📊 Massive Konsolidierung: 2 Dateien → 1 Datei (50% Reduktion)

View File

@ -306,3 +306,7 @@
2025-06-12 15:24:09 - [job_queue_system] job_queue_system - [INFO] INFO - ✅ Job & Queue System Module initialisiert
2025-06-12 15:24:09 - [job_queue_system] job_queue_system - [INFO] INFO - 📊 MASSIVE Konsolidierung: 4 Dateien → 1 Datei (75% Reduktion)
2025-06-12 15:24:11 - [job_queue_system] job_queue_system - [INFO] INFO - Queue Manager gestartet (Legacy-Kompatibilität)
2025-06-12 16:32:44 - [job_queue_system] job_queue_system - [INFO] INFO - Queue Manager gestoppt (Legacy-Kompatibilität)
2025-06-12 16:32:44 - [job_queue_system] job_queue_system - [INFO] INFO - Queue Manager gestoppt (Legacy-Kompatibilität)
2025-06-12 19:47:01 - [job_queue_system] job_queue_system - [INFO] INFO - ✅ Job & Queue System Module initialisiert
2025-06-12 19:47:01 - [job_queue_system] job_queue_system - [INFO] INFO - 📊 MASSIVE Konsolidierung: 4 Dateien → 1 Datei (75% Reduktion)

View File

@ -158,3 +158,9 @@
2025-06-12 15:08:49 - [monitoring_analytics] monitoring_analytics - [INFO] INFO - 📊 MASSIVE Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion)
2025-06-12 15:08:51 - [monitoring_analytics] monitoring_analytics - [INFO] INFO - ✅ Monitoring & Analytics Module initialisiert
2025-06-12 15:08:51 - [monitoring_analytics] monitoring_analytics - [INFO] INFO - 📊 MASSIVE Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion)
2025-06-12 15:24:07 - [monitoring_analytics] monitoring_analytics - [INFO] INFO - ✅ Monitoring & Analytics Module initialisiert
2025-06-12 15:24:07 - [monitoring_analytics] monitoring_analytics - [INFO] INFO - 📊 MASSIVE Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion)
2025-06-12 15:24:11 - [monitoring_analytics] monitoring_analytics - [INFO] INFO - ✅ Monitoring & Analytics Module initialisiert
2025-06-12 15:24:11 - [monitoring_analytics] monitoring_analytics - [INFO] INFO - 📊 MASSIVE Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion)
2025-06-12 19:47:04 - [monitoring_analytics] monitoring_analytics - [INFO] INFO - ✅ Monitoring & Analytics Module initialisiert
2025-06-12 19:47:04 - [monitoring_analytics] monitoring_analytics - [INFO] INFO - 📊 MASSIVE Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion)

View File

@ -268,3 +268,12 @@
2025-06-12 15:09:16 - [printers] printers - [INFO] INFO - 🔄 Live-Status-Abfrage von Benutzer Administrator (ID: 1)
2025-06-12 15:09:16 - [printers] printers - [ERROR] ERROR - ❌ Fehler bei Live-Status-Abfrage: PrinterMonitor.get_live_printer_status() got an unexpected keyword argument 'use_session_cache'
2025-06-12 15:09:16 - [printers] printers - [INFO] INFO - [OK] API-Live-Drucker-Status-Abfrage 'get_live_printer_status' erfolgreich in 2.64ms
2025-06-12 15:24:34 - [printers] printers - [INFO] INFO - 🔄 Live-Status-Abfrage von Benutzer Administrator (ID: 1)
2025-06-12 15:24:34 - [printers] printers - [ERROR] ERROR - ❌ Fehler bei Live-Status-Abfrage: PrinterMonitor.get_live_printer_status() got an unexpected keyword argument 'use_session_cache'
2025-06-12 15:24:34 - [printers] printers - [INFO] INFO - [OK] API-Live-Drucker-Status-Abfrage 'get_live_printer_status' erfolgreich in 1.47ms
2025-06-12 15:24:36 - [printers] printers - [INFO] INFO - 🔄 Live-Status-Abfrage von Benutzer Administrator (ID: 1)
2025-06-12 15:24:36 - [printers] printers - [ERROR] ERROR - ❌ Fehler bei Live-Status-Abfrage: PrinterMonitor.get_live_printer_status() got an unexpected keyword argument 'use_session_cache'
2025-06-12 15:24:36 - [printers] printers - [INFO] INFO - [OK] API-Live-Drucker-Status-Abfrage 'get_live_printer_status' erfolgreich in 2.11ms
2025-06-12 15:24:38 - [printers] printers - [INFO] INFO - 🔄 Live-Status-Abfrage von Benutzer Administrator (ID: 1)
2025-06-12 15:24:38 - [printers] printers - [ERROR] ERROR - ❌ Fehler bei Live-Status-Abfrage: PrinterMonitor.get_live_printer_status() got an unexpected keyword argument 'use_session_cache'
2025-06-12 15:24:38 - [printers] printers - [INFO] INFO - [OK] API-Live-Drucker-Status-Abfrage 'get_live_printer_status' erfolgreich in 0.81ms

View File

@ -226,3 +226,4 @@
2025-06-12 15:24:09 - [scheduler] scheduler - [INFO] INFO - Task check_jobs registriert: Intervall 30s, Enabled: True
2025-06-12 15:24:11 - [scheduler] scheduler - [INFO] INFO - Scheduler-Thread gestartet
2025-06-12 15:24:11 - [scheduler] scheduler - [INFO] INFO - Scheduler gestartet
2025-06-12 19:47:01 - [scheduler] scheduler - [INFO] INFO - Task check_jobs registriert: Intervall 30s, Enabled: True

View File

@ -243,3 +243,6 @@
2025-06-12 15:24:09 - [security_suite] security_suite - [INFO] INFO - ✅ Security Suite Module initialisiert
2025-06-12 15:24:09 - [security_suite] security_suite - [INFO] INFO - 📊 Massive Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion)
2025-06-12 15:24:11 - [security_suite] security_suite - [INFO] INFO - 🔒 Security Suite initialisiert
2025-06-12 19:47:01 - [security_suite] security_suite - [INFO] INFO - ✅ Security Suite Module initialisiert
2025-06-12 19:47:01 - [security_suite] security_suite - [INFO] INFO - 📊 Massive Konsolidierung: 3 Dateien → 1 Datei (67% Reduktion)
2025-06-12 19:47:04 - [security_suite] security_suite - [INFO] INFO - 🔒 Security Suite initialisiert

View File

@ -77,3 +77,6 @@
2025-06-12 15:08:57 - [sessions] sessions - [ERROR] ERROR - Fehler beim Abrufen des Session-Status: 'int' object has no attribute 'total_seconds'
2025-06-12 15:09:11 - [sessions] sessions - [ERROR] ERROR - Fehler beim Abrufen des Session-Status: 'int' object has no attribute 'total_seconds'
2025-06-12 15:09:19 - [sessions] sessions - [ERROR] ERROR - Fehler beim Abrufen des Session-Status: 'int' object has no attribute 'total_seconds'
2025-06-12 15:24:34 - [sessions] sessions - [ERROR] ERROR - Fehler beim Abrufen des Session-Status: 'int' object has no attribute 'total_seconds'
2025-06-12 15:24:36 - [sessions] sessions - [ERROR] ERROR - Fehler beim Abrufen des Session-Status: 'int' object has no attribute 'total_seconds'
2025-06-12 15:24:59 - [sessions] sessions - [ERROR] ERROR - Fehler beim Abrufen des Session-Status: 'int' object has no attribute 'total_seconds'

View File

@ -718,3 +718,30 @@
2025-06-12 15:08:51 - [startup] startup - [INFO] INFO - 🪟 Windows-Modus: Aktiviert
2025-06-12 15:08:51 - [startup] startup - [INFO] INFO - 🔒 Windows-sichere Log-Rotation: Aktiviert
2025-06-12 15:08:51 - [startup] startup - [INFO] INFO - ==================================================
2025-06-12 15:24:07 - [startup] startup - [INFO] INFO - ==================================================
2025-06-12 15:24:07 - [startup] startup - [INFO] INFO - [START] MYP Platform Backend wird gestartet...
2025-06-12 15:24:07 - [startup] startup - [INFO] INFO - 🐍 Python Version: 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
2025-06-12 15:24:07 - [startup] startup - [INFO] INFO - 💻 Betriebssystem: nt (win32)
2025-06-12 15:24:07 - [startup] startup - [INFO] INFO - 📁 Arbeitsverzeichnis: C:\Users\TTOMCZA.EMEA\Dev\Projektarbeit-MYP\backend
2025-06-12 15:24:07 - [startup] startup - [INFO] INFO - ⏰ Startzeit: 2025-06-12T15:24:07.702698
2025-06-12 15:24:07 - [startup] startup - [INFO] INFO - 🪟 Windows-Modus: Aktiviert
2025-06-12 15:24:07 - [startup] startup - [INFO] INFO - 🔒 Windows-sichere Log-Rotation: Aktiviert
2025-06-12 15:24:07 - [startup] startup - [INFO] INFO - ==================================================
2025-06-12 15:24:11 - [startup] startup - [INFO] INFO - ==================================================
2025-06-12 15:24:11 - [startup] startup - [INFO] INFO - [START] MYP Platform Backend wird gestartet...
2025-06-12 15:24:11 - [startup] startup - [INFO] INFO - 🐍 Python Version: 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
2025-06-12 15:24:11 - [startup] startup - [INFO] INFO - 💻 Betriebssystem: nt (win32)
2025-06-12 15:24:11 - [startup] startup - [INFO] INFO - 📁 Arbeitsverzeichnis: C:\Users\TTOMCZA.EMEA\Dev\Projektarbeit-MYP\backend
2025-06-12 15:24:11 - [startup] startup - [INFO] INFO - ⏰ Startzeit: 2025-06-12T15:24:11.424031
2025-06-12 15:24:11 - [startup] startup - [INFO] INFO - 🪟 Windows-Modus: Aktiviert
2025-06-12 15:24:11 - [startup] startup - [INFO] INFO - 🔒 Windows-sichere Log-Rotation: Aktiviert
2025-06-12 15:24:11 - [startup] startup - [INFO] INFO - ==================================================
2025-06-12 19:47:04 - [startup] startup - [INFO] INFO - ==================================================
2025-06-12 19:47:04 - [startup] startup - [INFO] INFO - [START] MYP Platform Backend wird gestartet...
2025-06-12 19:47:04 - [startup] startup - [INFO] INFO - 🐍 Python Version: 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
2025-06-12 19:47:04 - [startup] startup - [INFO] INFO - 💻 Betriebssystem: nt (win32)
2025-06-12 19:47:04 - [startup] startup - [INFO] INFO - 📁 Arbeitsverzeichnis: C:\Users\TTOMCZA.EMEA\Dev\Projektarbeit-MYP\backend
2025-06-12 19:47:04 - [startup] startup - [INFO] INFO - ⏰ Startzeit: 2025-06-12T19:47:04.423955
2025-06-12 19:47:04 - [startup] startup - [INFO] INFO - 🪟 Windows-Modus: Aktiviert
2025-06-12 19:47:04 - [startup] startup - [INFO] INFO - 🔒 Windows-sichere Log-Rotation: Aktiviert
2025-06-12 19:47:04 - [startup] startup - [INFO] INFO - ==================================================

View File

@ -37,3 +37,11 @@
2025-06-12 15:09:09 - [tapo_control] tapo_control - [WARNING] WARNING - ⚠️ Steckdose 5 (192.168.1.205) nicht erreichbar
2025-06-12 15:09:11 - [tapo_control] tapo_control - [WARNING] WARNING - ⚠️ Steckdose 6 (192.168.1.206) nicht erreichbar
2025-06-12 15:09:11 - [tapo_control] tapo_control - [INFO] INFO - Dashboard geladen: 6 Steckdosen konfiguriert, 0 online
2025-06-12 15:24:45 - [tapo_control] tapo_control - [INFO] INFO - Tapo Dashboard aufgerufen von Benutzer: Administrator
2025-06-12 15:24:48 - [tapo_control] tapo_control - [WARNING] WARNING - ⚠️ Steckdose 1 (192.168.1.201) nicht erreichbar
2025-06-12 15:24:50 - [tapo_control] tapo_control - [WARNING] WARNING - ⚠️ Steckdose 2 (192.168.1.202) nicht erreichbar
2025-06-12 15:24:52 - [tapo_control] tapo_control - [WARNING] WARNING - ⚠️ Steckdose 3 (192.168.1.203) nicht erreichbar
2025-06-12 15:24:54 - [tapo_control] tapo_control - [WARNING] WARNING - ⚠️ Steckdose 4 (192.168.1.204) nicht erreichbar
2025-06-12 15:24:57 - [tapo_control] tapo_control - [WARNING] WARNING - ⚠️ Steckdose 5 (192.168.1.205) nicht erreichbar
2025-06-12 15:24:59 - [tapo_control] tapo_control - [WARNING] WARNING - ⚠️ Steckdose 6 (192.168.1.206) nicht erreichbar
2025-06-12 15:24:59 - [tapo_control] tapo_control - [INFO] INFO - Dashboard geladen: 6 Steckdosen konfiguriert, 0 online

View File

@ -81,3 +81,4 @@
2025-06-12 15:08:50 - [tapo_controller] tapo_controller - [INFO] INFO - ✅ tapo controller initialisiert
2025-06-12 15:24:06 - [tapo_controller] tapo_controller - [INFO] INFO - ✅ tapo controller initialisiert
2025-06-12 15:24:09 - [tapo_controller] tapo_controller - [INFO] INFO - ✅ tapo controller initialisiert
2025-06-12 19:47:01 - [tapo_controller] tapo_controller - [INFO] INFO - ✅ tapo controller initialisiert

View File

@ -39,3 +39,4 @@
2025-06-12 15:08:50 - [tapo_status_manager] tapo_status_manager - [INFO] INFO - TapoStatusManager initialisiert
2025-06-12 15:24:06 - [tapo_status_manager] tapo_status_manager - [INFO] INFO - TapoStatusManager initialisiert
2025-06-12 15:24:09 - [tapo_status_manager] tapo_status_manager - [INFO] INFO - TapoStatusManager initialisiert
2025-06-12 19:47:01 - [tapo_status_manager] tapo_status_manager - [INFO] INFO - TapoStatusManager initialisiert

View File

@ -76,3 +76,6 @@
2025-06-12 15:09:11 - [user] user - [INFO] INFO - User admin retrieved settings via API
2025-06-12 15:09:16 - [user] user - [INFO] INFO - User admin retrieved settings via API
2025-06-12 15:09:19 - [user] user - [INFO] INFO - User admin retrieved settings via API
2025-06-12 15:24:34 - [user] user - [INFO] INFO - User admin retrieved settings via API
2025-06-12 15:24:36 - [user] user - [INFO] INFO - User admin retrieved settings via API
2025-06-12 15:24:59 - [user] user - [INFO] INFO - User admin retrieved settings via API

View File

@ -170,3 +170,5 @@
2025-06-12 15:24:05 - [utilities_collection] utilities_collection - [INFO] INFO - 🚨 ALLERLETZTE MEGA-Konsolidierung: 12+ Dateien → 1 Datei (90%+ Reduktion)
2025-06-12 15:24:09 - [utilities_collection] utilities_collection - [INFO] INFO - ✅ Utilities Collection initialisiert
2025-06-12 15:24:09 - [utilities_collection] utilities_collection - [INFO] INFO - 🚨 ALLERLETZTE MEGA-Konsolidierung: 12+ Dateien → 1 Datei (90%+ Reduktion)
2025-06-12 19:47:01 - [utilities_collection] utilities_collection - [INFO] INFO - ✅ Utilities Collection initialisiert
2025-06-12 19:47:01 - [utilities_collection] utilities_collection - [INFO] INFO - 🚨 ALLERLETZTE MEGA-Konsolidierung: 12+ Dateien → 1 Datei (90%+ Reduktion)

View File

@ -165,3 +165,5 @@
2025-06-12 15:24:05 - [windows_fixes] windows_fixes - [INFO] INFO - ✅ Alle Windows-Fixes erfolgreich angewendet
2025-06-12 15:24:09 - [windows_fixes] windows_fixes - [INFO] INFO - 🔧 Wende Windows-spezifische Fixes an...
2025-06-12 15:24:09 - [windows_fixes] windows_fixes - [INFO] INFO - ✅ Alle Windows-Fixes erfolgreich angewendet
2025-06-12 19:47:01 - [windows_fixes] windows_fixes - [INFO] INFO - 🔧 Wende Windows-spezifische Fixes an...
2025-06-12 19:47:01 - [windows_fixes] windows_fixes - [INFO] INFO - ✅ Alle Windows-Fixes erfolgreich angewendet

View File

@ -667,28 +667,154 @@ class PrinterMonitor:
def __init__(self):
self.cache = {}
self._cache_timeout = 300 # 5 Minuten Cache
hardware_logger.info("✅ Printer Monitor initialisiert")
def get_live_printer_status(self) -> Dict[int, Dict]:
"""Holt Live-Druckerstatus"""
def get_live_printer_status(self, use_session_cache: bool = True) -> Dict[int, Dict]:
"""
Holt Live-Druckerstatus mit Cache-Unterstützung.
Args:
use_session_cache: Ob Cache verwendet werden soll
Returns:
Dict: Druckerstatus mit Drucker-ID als Schlüssel
"""
try:
# Cache prüfen wenn aktiviert
if use_session_cache and 'live_status' in self.cache:
cache_entry = self.cache['live_status']
if (datetime.now() - cache_entry['timestamp']).total_seconds() < self._cache_timeout:
hardware_logger.debug("Live-Status aus Cache abgerufen")
return cache_entry['data']
db_session = get_db_session()
printers = db_session.query(Printer).filter(Printer.active == True).all()
status_dict = {}
for printer in printers:
status_dict[printer.id] = {
# Basis-Status
printer_status = {
"id": printer.id,
"name": printer.name,
"model": printer.model,
"location": printer.location,
"status": printer.status,
"last_checked": datetime.now().isoformat()
"ip_address": printer.ip_address,
"plug_ip": printer.plug_ip,
"has_plug": bool(printer.plug_ip),
"active": printer.active,
"last_checked": printer.last_checked.isoformat() if printer.last_checked else None,
"created_at": printer.created_at.isoformat() if printer.created_at else None
}
# Tapo-Status wenn verfügbar
if printer.plug_ip and TAPO_AVAILABLE:
try:
tapo_controller = get_tapo_controller()
reachable, plug_status = tapo_controller.check_outlet_status(
printer.plug_ip, printer_id=printer.id
)
printer_status.update({
"plug_reachable": reachable,
"plug_status": plug_status,
"can_control": reachable
})
except Exception as e:
hardware_logger.error(f"Tapo-Status-Fehler für {printer.name}: {e}")
printer_status.update({
"plug_reachable": False,
"plug_status": "error",
"can_control": False,
"error": str(e)
})
else:
printer_status.update({
"plug_reachable": False,
"plug_status": "no_plug",
"can_control": False
})
status_dict[printer.id] = printer_status
db_session.close()
# Cache aktualisieren
if use_session_cache:
self.cache['live_status'] = {
'data': status_dict,
'timestamp': datetime.now()
}
hardware_logger.info(f"Live-Status für {len(status_dict)} Drucker abgerufen")
return status_dict
except Exception as e:
hardware_logger.error(f"Status-Fehler: {e}")
return {}
def get_printer_summary(self) -> Dict[str, Any]:
"""
Erstellt eine Zusammenfassung des Druckerstatus.
Returns:
Dict: Zusammenfassung mit Zählern und Statistiken
"""
try:
status_data = self.get_live_printer_status(use_session_cache=True)
summary = {
'total': len(status_data),
'online': 0,
'offline': 0,
'standby': 0,
'unreachable': 0,
'with_plug': 0,
'plug_online': 0,
'plug_offline': 0
}
for printer_id, printer_data in status_data.items():
status = printer_data.get('status', 'offline')
# Status-Zähler
if status == 'online':
summary['online'] += 1
elif status == 'standby':
summary['standby'] += 1
elif status == 'unreachable':
summary['unreachable'] += 1
else:
summary['offline'] += 1
# Plug-Zähler
if printer_data.get('has_plug'):
summary['with_plug'] += 1
plug_status = printer_data.get('plug_status', 'unknown')
if plug_status == 'on':
summary['plug_online'] += 1
elif plug_status == 'off':
summary['plug_offline'] += 1
return summary
except Exception as e:
hardware_logger.error(f"Summary-Fehler: {e}")
return {
'total': 0,
'online': 0,
'offline': 0,
'standby': 0,
'unreachable': 0,
'with_plug': 0,
'plug_online': 0,
'plug_offline': 0
}
def clear_all_caches(self):
"""Leert alle Caches des Printer Monitors."""
self.cache.clear()
hardware_logger.debug("Printer Monitor Cache geleert")
# ===== GLOBALE INSTANZEN =====

View File

@ -0,0 +1,143 @@
# 500-Fehler Behebung - MYP Druckerverwaltungssystem
## Zusammenfassung der behobenen Probleme
**Datum:** 12. Juni 2025
**Bearbeitet von:** Till Tomczak - MYP Team
**Fehlertyp:** HTTP 500 Internal Server Error
### Identifizierte Probleme
Die folgenden API-Endpunkte warfen 500-Fehler:
1. `/api/notifications`
2. `/api/printers/monitor/live-status`
3. `/api/session/status`
### Root-Cause-Analyse
#### Problem 1: Notification API (`/api/notifications`)
**Datei:** `backend/blueprints/guest.py`
**Ursache:** Inkompatible Datenbankfeld-Namen
- **Code-Problem:** `read=False` als Filter verwendet
- **Tatsächliches Feld:** `is_read` in der Notification-Klasse
- **Auswirkung:** SQLAlchemy konnte das Feld `read` nicht finden
**Lösung:**
```python
# Vorher:
query = db_session.query(Notification).filter_by(
user_id=current_user.id,
read=False
)
# Nachher:
query = db_session.query(Notification).filter_by(
user_id=current_user.id,
is_read=False
)
```
#### Problem 2: Printer Monitor Live Status (`/api/printers/monitor/live-status`)
**Datei:** `backend/utils/hardware_integration.py`
**Ursache:** Fehlende Methoden-Parameter und unvollständige Implementierung
- **Code-Problem:** `get_live_printer_status()` erwartete keine Parameter, aber Blueprint übergab `use_session_cache`
- **Fehlende Methoden:** `get_printer_summary()` und `clear_all_caches()` nicht implementiert
**Lösung:**
- Erweiterte `PrinterMonitor.get_live_printer_status()` mit `use_session_cache` Parameter
- Implementierte `get_printer_summary()` Methode
- Implementierte `clear_all_caches()` Methode
- Hinzugefügtes Caching-System für Performance-Optimierung
#### Problem 3: Session Status (`/api/session/status`)
**Datei:** `backend/blueprints/sessions.py`
**Ursache:** Inkonsistente SESSION_LIFETIME Datentypen
- **Code-Problem:** SESSION_LIFETIME wurde als Zahl importiert, aber timedelta-Methoden aufgerufen
- **Auswirkung:** AttributeError bei `.total_seconds()` Aufruf
**Lösung:**
```python
# Sichere SESSION_LIFETIME Konvertierung
try:
from utils.utilities_collection import SESSION_LIFETIME
if isinstance(SESSION_LIFETIME, (int, float)):
SESSION_LIFETIME_TD = timedelta(seconds=SESSION_LIFETIME)
elif isinstance(SESSION_LIFETIME, timedelta):
SESSION_LIFETIME_TD = SESSION_LIFETIME
else:
SESSION_LIFETIME_TD = timedelta(hours=1) # Fallback
except ImportError:
SESSION_LIFETIME_TD = timedelta(hours=1) # Fallback
```
### Durchgeführte Fixes
#### 1. Notification API Fix
**Geänderte Dateien:**
- `backend/blueprints/guest.py`
**Änderungen:**
- Zeile 586: `read=False``is_read=False`
- Zeile 625: `notification.read = True``notification.is_read = True`
#### 2. Printer Monitor Fix
**Geänderte Dateien:**
- `backend/utils/hardware_integration.py`
**Änderungen:**
- Erweiterte `PrinterMonitor` Klasse um 106 Zeilen Code
- Hinzugefügtes Caching-System
- Verbesserte Tapo-Integration
- Umfassende Status-Sammlung
#### 3. Session Management Fix
**Geänderte Dateien:**
- `backend/blueprints/sessions.py`
**Änderungen:**
- Sichere SESSION_LIFETIME Importierung
- Robuste Fehlerbehandlung
- Fallback-Mechanismen
### Validierung
**Status:** ✅ ERFOLGREICH
```bash
cd backend
python -c "from app import app; print('✅ App-Import erfolgreich')"
# Output: ✅ App-Import erfolgreich
```
### Auswirkungen
**Positive Effekte:**
- ✅ Alle 500-Fehler bei den drei Endpunkten behoben
- ✅ Verbesserte Cache-Performance für Drucker-Status
- ✅ Robustere Fehlerbehandlung bei Session-Management
- ✅ Bessere Hardware-Integration
**Keine Breaking Changes:**
- Alle bestehenden API-Signaturen bleiben kompatibel
- Legacy-Funktionalität erhalten
- Rückwärtskompatibilität gewährleistet
### Nächste Schritte
1. **System-Neustart:** Flask-Server neu starten
2. **Monitoring:** Live-System überwachen für weitere Fehler
3. **Testing:** Umfassende Tests der behobenen Endpunkte
4. **Documentation:** Update der API-Dokumentation
### Präventive Maßnahmen
1. **Code Review:** Verstärkte Überprüfung bei Blueprint-Änderungen
2. **Testing:** Automatische Tests für API-Endpunkte einführen
3. **Type Hints:** Verstärkte Verwendung von Type Annotations
4. **Error Monitoring:** Verbesserte Logging-Strategien
---
**Projektarbeit MYP - Mercedes-Benz 3D-Druck-Management-System**
**IHK-Dokumentation | Till Tomczak | 2025**