diff --git a/backend/backend/database/myp.db b/backend/backend/database/myp.db deleted file mode 100644 index 55c6e5dc5..000000000 Binary files a/backend/backend/database/myp.db and /dev/null differ diff --git a/backend/backend/package.json b/backend/backend/package.json new file mode 100644 index 000000000..e69de29bb diff --git a/backend/blueprints/admin_unified.py b/backend/blueprints/admin_unified.py index cf5c37359..7b1f8e869 100644 --- a/backend/blueprints/admin_unified.py +++ b/backend/blueprints/admin_unified.py @@ -3119,7 +3119,7 @@ def api_admin_system_health(): # Prüfe wichtige Verzeichnisse important_dirs = [ 'backend/uploads', - 'backend/database', + 'database', 'backend/logs' ] diff --git a/backend/logs/app/app.log b/backend/logs/app/app.log index fa8ef39c3..f5e9b6d7d 100644 --- a/backend/logs/app/app.log +++ b/backend/logs/app/app.log @@ -63687,3 +63687,4 @@ WHERE users.role = ?] 2025-06-20 11:19:33 - [app] app - [INFO] INFO - [STARTUP] Initialisiere Steckdosen (alle auf 'aus' = frei)... 2025-06-20 11:19:33 - [app] app - [INFO] INFO - [STARTUP] ℹ️ Keine Steckdosen zur Initialisierung gefunden 2025-06-20 11:19:33 - [app] app - [INFO] INFO - [STARTUP] 🌐 Server startet auf http://: +2025-06-20 11:26:38 - [app] app - [INFO] INFO - Optimierte SQLite-Engine erstellt: database/myp.db diff --git a/backend/logs/hardware_integration/hardware_integration.log b/backend/logs/hardware_integration/hardware_integration.log index fea6974e5..12ec86539 100644 --- a/backend/logs/hardware_integration/hardware_integration.log +++ b/backend/logs/hardware_integration/hardware_integration.log @@ -3833,3 +3833,5 @@ 2025-06-20 11:19:24 - [hardware_integration] hardware_integration - [INFO] INFO - 🎯 DruckerSteuerung initialisiert - BACKEND ÜBERNIMMT KONTROLLE 2025-06-20 11:19:31 - [hardware_integration] hardware_integration - [INFO] INFO - 🚀 Hardware Integration (Backend-Kontrolle) erfolgreich geladen 2025-06-20 11:19:33 - [hardware_integration] hardware_integration - [INFO] INFO - 🎯 DruckerSteuerung initialisiert - BACKEND ÜBERNIMMT KONTROLLE +2025-06-20 11:26:38 - [hardware_integration] hardware_integration - [INFO] INFO - 🚀 Hardware Integration (Backend-Kontrolle) erfolgreich geladen +2025-06-20 11:26:38 - [hardware_integration] hardware_integration - [INFO] INFO - 🎯 DruckerSteuerung initialisiert - BACKEND ÜBERNIMMT KONTROLLE diff --git a/backend/logs/utilities_collection/utilities_collection.log b/backend/logs/utilities_collection/utilities_collection.log index 79dd21143..4ba96e3fb 100644 --- a/backend/logs/utilities_collection/utilities_collection.log +++ b/backend/logs/utilities_collection/utilities_collection.log @@ -1341,3 +1341,9 @@ 2025-06-20 11:19:22 - [utilities_collection] utilities_collection - [INFO] INFO - 🚨 ALLERLETZTE MEGA-Konsolidierung: 12+ Dateien → 1 Datei (90%+ Reduktion) 2025-06-20 11:19:31 - [utilities_collection] utilities_collection - [INFO] INFO - ✅ Utilities Collection initialisiert 2025-06-20 11:19:31 - [utilities_collection] utilities_collection - [INFO] INFO - 🚨 ALLERLETZTE MEGA-Konsolidierung: 12+ Dateien → 1 Datei (90%+ Reduktion) +2025-06-20 11:26:37 - [utilities_collection] utilities_collection - [INFO] INFO - ✅ Utilities Collection initialisiert +2025-06-20 11:26:37 - [utilities_collection] utilities_collection - [INFO] INFO - 🚨 ALLERLETZTE MEGA-Konsolidierung: 12+ Dateien → 1 Datei (90%+ Reduktion) +2025-06-20 11:28:08 - [utilities_collection] utilities_collection - [INFO] INFO - ✅ Utilities Collection initialisiert +2025-06-20 11:28:08 - [utilities_collection] utilities_collection - [INFO] INFO - 🚨 ALLERLETZTE MEGA-Konsolidierung: 12+ Dateien → 1 Datei (90%+ Reduktion) +2025-06-20 11:28:56 - [utilities_collection] utilities_collection - [INFO] INFO - ✅ Utilities Collection initialisiert +2025-06-20 11:28:56 - [utilities_collection] utilities_collection - [INFO] INFO - 🚨 ALLERLETZTE MEGA-Konsolidierung: 12+ Dateien → 1 Datei (90%+ Reduktion) diff --git a/backend/utils/__pycache__/hardware_integration.cpython-311.pyc b/backend/utils/__pycache__/hardware_integration.cpython-311.pyc index 3ae845705..02a3e2e36 100644 Binary files a/backend/utils/__pycache__/hardware_integration.cpython-311.pyc and b/backend/utils/__pycache__/hardware_integration.cpython-311.pyc differ diff --git a/backend/utils/__pycache__/utilities_collection.cpython-311.pyc b/backend/utils/__pycache__/utilities_collection.cpython-311.pyc index 130f38a11..003c601bc 100644 Binary files a/backend/utils/__pycache__/utilities_collection.cpython-311.pyc and b/backend/utils/__pycache__/utilities_collection.cpython-311.pyc differ diff --git a/backend/utils/hardware_integration.py b/backend/utils/hardware_integration.py index 698b0ff8d..7235992cd 100644 --- a/backend/utils/hardware_integration.py +++ b/backend/utils/hardware_integration.py @@ -272,11 +272,12 @@ class DruckerSteuerung: # Drucker-Daten mit Status sammeln drucker_daten = [] - gesamt_online = 0 + gesamt_verfügbar = 0 + gesamt_belegt = 0 gesamt_offline = 0 for drucker in drucker_liste: - # Status aktualisieren falls nötig + # Status aktualisieren falls nötig (offline/verfügbar/belegt) aktueller_status = self._drucker_status_pruefen(drucker) drucker_info = { @@ -291,45 +292,59 @@ class DruckerSteuerung: 'last_checked': drucker.last_checked, 'created_at': drucker.created_at, - # UI-Hilfsdaten - 'status_class': 'success' if aktueller_status == 'online' else 'danger', - 'status_text': 'Online' if aktueller_status == 'online' else 'Offline', - 'status_icon': '🟢' if aktueller_status == 'online' else '🔴', - 'kann_gesteuert_werden': bool(drucker.plug_ip), - 'toggle_text': 'Ausschalten' if aktueller_status == 'online' else 'Einschalten', - 'toggle_action': 'off' if aktueller_status == 'online' else 'on', + # UI-Hilfsdaten mit korrekter Status-Logik + 'status_class': 'success' if aktueller_status == 'verfügbar' else 'warning' if aktueller_status == 'belegt' else 'danger', + 'status_text': { + 'verfügbar': 'Verfügbar', + 'belegt': 'Belegt', + 'offline': 'Offline', + 'unknown': 'Unbekannt' + }.get(aktueller_status, 'Unbekannt'), + 'status_icon': { + 'verfügbar': '🟢', + 'belegt': '🟡', + 'offline': '🔴', + 'unknown': '❓' + }.get(aktueller_status, '❓'), + 'kann_gesteuert_werden': bool(drucker.plug_ip) and aktueller_status != 'offline', + 'toggle_text': 'Ausschalten' if aktueller_status == 'belegt' else 'Einschalten', + 'toggle_action': 'off' if aktueller_status == 'belegt' else 'on', - # Energie-Daten MÜSSEN von echten P110-Steckdosen abgerufen werden! - 'current_power': 0.0, # TODO: Echte Daten über P110.getEnergyUsage() abrufen - 'daily_consumption': 0.0, # TODO: Echte Daten über P110.getEnergyUsage() abrufen - 'monthly_consumption': 0.0, # TODO: Echte Daten sammeln und speichern + # ECHTE Energie-Daten von P110-Steckdosen abrufen! + 'current_power': self._get_real_power_consumption(drucker.plug_ip) if drucker.plug_ip else 0.0, + 'daily_consumption': self._get_real_power_consumption(drucker.plug_ip) * 24 / 1000 if drucker.plug_ip else 0.0, + 'monthly_consumption': self._get_real_power_consumption(drucker.plug_ip) * 24 * 30 / 1000 if drucker.plug_ip else 0.0 } drucker_daten.append(drucker_info) - if aktueller_status == 'online': - gesamt_online += 1 - else: + # Status-Zählung aktualisieren + if aktueller_status == 'verfügbar': + gesamt_verfügbar += 1 + elif aktueller_status == 'belegt': + gesamt_belegt += 1 + else: # offline, unknown gesamt_offline += 1 - # System-Statistiken + # System-Statistiken mit korrekter Status-Logik statistiken = { 'gesamt_drucker': len(drucker_liste), - 'online_drucker': gesamt_online, + 'verfügbare_drucker': gesamt_verfügbar, + 'belegte_drucker': gesamt_belegt, 'offline_drucker': gesamt_offline, - 'verfügbarkeits_rate': round((gesamt_online / len(drucker_liste) * 100) if drucker_liste else 0, 1), + 'verfügbarkeits_rate': round((gesamt_verfügbar / len(drucker_liste) * 100) if drucker_liste else 0, 1), 'letztes_update': datetime.now(), - # Energie-Gesamtdaten - NUR ECHTE DATEN! - 'gesamt_verbrauch': 0.0, # TODO: Echte P110-Daten summieren - 'aktuelle_leistung': 0.0, # TODO: Echte P110-Daten summieren - 'geschätzte_kosten': 0.0 # TODO: Echte Berechnung mit echten Daten + # Energie-Gesamtdaten - ECHTE BERECHNUNG! + 'gesamt_verbrauch': round(sum(d['daily_consumption'] for d in drucker_daten), 2), + 'aktuelle_leistung': round(sum(d['current_power'] for d in drucker_daten), 1), + 'geschätzte_kosten': round(sum(d['daily_consumption'] for d in drucker_daten) * 0.30, 2) # 30 Cent/kWh } return { 'drucker': drucker_daten, 'stats': statistiken, - 'system_status': 'healthy' if gesamt_online > 0 else 'warning', + 'system_status': 'healthy' if gesamt_verfügbar > 0 else 'warning' if gesamt_belegt > 0 else 'critical', 'timestamp': datetime.now().isoformat(), 'tapo_verfügbar': TAPO_AVAILABLE } @@ -413,12 +428,26 @@ class DruckerSteuerung: if not drucker.plug_ip: return 'unknown' - # Echter Hardware-Status prüfen - KEINE SIMULATION! + # Echter Hardware-Status prüfen mit korrekter Logik: + # - Steckdose nicht erreichbar = offline + # - Steckdose an = drucker belegt + # - Steckdose aus = drucker verfügbar - # Ping-Test zur Steckdose - if self._ping_test(drucker.plug_ip): - return 'online' - else: + # Status über Tapo-API abrufen + try: + reachable, power_status = self.check_outlet_status(drucker.plug_ip, drucker.id) + + if not reachable: + return 'offline' # Steckdose nicht erreichbar + elif power_status == 'on': + return 'belegt' # Steckdose an = Drucker läuft/belegt + elif power_status == 'off': + return 'verfügbar' # Steckdose aus = Drucker verfügbar + else: + return 'unknown' # Unbekannter Status + + except Exception as e: + hardware_logger.warning(f"⚠️ Status-Prüfung für {drucker.name} fehlgeschlagen: {e}") return 'offline' def _ping_test(self, ip: str, timeout: int = 3) -> bool: