📝 🚀 Improved calendar and printer functionalities, refactored logs, and updated tests. 🖥️📅
This commit is contained in:
@ -7,7 +7,7 @@ from sqlalchemy import and_, or_, func
|
||||
from models import Job, Printer, User, UserPermission, get_cached_session
|
||||
from utils.logging_config import get_logger
|
||||
from utils.job_queue_system import conflict_manager, ConflictType, ConflictSeverity
|
||||
from utils.tapo_status_manager import tapo_status_manager
|
||||
from utils.hardware_integration import printer_monitor
|
||||
|
||||
calendar_blueprint = Blueprint('calendar', __name__)
|
||||
logger = get_logger("calendar")
|
||||
@ -255,7 +255,7 @@ def api_get_calendar_events():
|
||||
# Für Admins: Erweiterte Steckdosen-Status-Informationen hinzufügen
|
||||
if current_user.is_admin:
|
||||
# Aktuellen Steckdosen-Status abrufen
|
||||
printer_status = tapo_status_manager.get_printer_status(job.printer_id)
|
||||
printer_status = printer_monitor.get_printer_status(job.printer_id)
|
||||
|
||||
event["extendedProps"].update({
|
||||
"plugStatus": printer_status.get("plug_status", "unknown"),
|
||||
@ -268,8 +268,8 @@ def api_get_calendar_events():
|
||||
|
||||
# Status-Display-Informationen hinzufügen
|
||||
plug_status = printer_status.get("plug_status", "unknown")
|
||||
if plug_status in tapo_status_manager.STATUS_DISPLAY:
|
||||
status_info = tapo_status_manager.STATUS_DISPLAY[plug_status]
|
||||
if plug_status in printer_monitor.STATUS_DISPLAY:
|
||||
status_info = printer_monitor.STATUS_DISPLAY[plug_status]
|
||||
event["extendedProps"]["statusDisplay"] = {
|
||||
"text": status_info["text"],
|
||||
"color": status_info["color"],
|
||||
|
@ -245,13 +245,13 @@ def get_printer_status():
|
||||
'error': 0
|
||||
}
|
||||
|
||||
# Tapo Status Manager importieren
|
||||
# Hardware Integration Monitor importieren
|
||||
try:
|
||||
from utils.tapo_status_manager import TapoStatusManager
|
||||
tapo_manager = TapoStatusManager()
|
||||
from utils.hardware_integration import printer_monitor
|
||||
tapo_manager = printer_monitor
|
||||
except ImportError:
|
||||
tapo_manager = None
|
||||
printers_logger.warning("⚠️ TapoStatusManager nicht verfügbar")
|
||||
printers_logger.warning("⚠️ Hardware Integration Monitor nicht verfügbar")
|
||||
|
||||
for printer in printers:
|
||||
# Basis-Drucker-Daten
|
||||
@ -493,11 +493,11 @@ def force_refresh_all_printer_status():
|
||||
printers_logger.info(f"🔄 Force-Refresh aller Drucker von Benutzer {current_user.name} (ID: {current_user.id})")
|
||||
|
||||
try:
|
||||
# Tapo Status Manager für Force-Refresh verwenden
|
||||
from utils.tapo_status_manager import tapo_status_manager
|
||||
# Hardware Integration Monitor für Force-Refresh verwenden
|
||||
from utils.hardware_integration import printer_monitor
|
||||
|
||||
# Force-Network-Refresh durchführen
|
||||
refresh_results = tapo_status_manager.force_network_refresh()
|
||||
refresh_results = printer_monitor.force_network_refresh()
|
||||
|
||||
if refresh_results.get("success", False):
|
||||
printers_logger.info(f"✅ Force-Refresh erfolgreich: {refresh_results.get('printers_refreshed', 0)} Drucker aktualisiert")
|
||||
|
@ -44133,3 +44133,4 @@ WHERE users.id = ?
|
||||
2025-06-19 09:28:08 - [app] app - [DEBUG] DEBUG - Response: 302
|
||||
2025-06-19 09:28:08 - [app] app - [DEBUG] DEBUG - Request: GET /dashboard
|
||||
2025-06-19 09:28:08 - [app] app - [DEBUG] DEBUG - Response: 200
|
||||
2025-06-19 09:51:45 - [app] app - [INFO] INFO - Optimierte SQLite-Engine erstellt: ./database/myp.db
|
||||
|
@ -2799,3 +2799,7 @@
|
||||
2025-06-19 09:26:54 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ Printer Monitor initialisiert
|
||||
2025-06-19 09:26:54 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ Hardware Integration Module initialisiert
|
||||
2025-06-19 09:26:54 - [hardware_integration] hardware_integration - [INFO] INFO - 📊 Massive Konsolidierung: 2 Dateien → 1 Datei (50% Reduktion)
|
||||
2025-06-19 09:51:45 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ PyP100 (TP-Link Tapo) verfügbar
|
||||
2025-06-19 09:51:45 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ Printer Monitor mit Session-Caching initialisiert
|
||||
2025-06-19 09:51:45 - [hardware_integration] hardware_integration - [INFO] INFO - ✅ Hardware Integration Module initialisiert
|
||||
2025-06-19 09:51:45 - [hardware_integration] hardware_integration - [INFO] INFO - 📊 Massive Konsolidierung: 2 Dateien → 1 Datei (50% Reduktion)
|
||||
|
@ -2976,3 +2976,4 @@
|
||||
2025-06-19 09:26:15 - [tapo_controller] tapo_controller - [INFO] INFO - ✅ tapo controller initialisiert
|
||||
2025-06-19 09:26:20 - [tapo_controller] tapo_controller - [INFO] INFO - ✅ tapo controller initialisiert
|
||||
2025-06-19 09:26:54 - [tapo_controller] tapo_controller - [INFO] INFO - ✅ tapo controller initialisiert
|
||||
2025-06-19 09:51:45 - [tapo_controller] tapo_controller - [INFO] INFO - ✅ tapo controller initialisiert
|
||||
|
@ -831,3 +831,5 @@
|
||||
2025-06-19 09:26:20 - [utilities_collection] utilities_collection - [INFO] INFO - 🚨 ALLERLETZTE MEGA-Konsolidierung: 12+ Dateien → 1 Datei (90%+ Reduktion)
|
||||
2025-06-19 09:26:53 - [utilities_collection] utilities_collection - [INFO] INFO - ✅ Utilities Collection initialisiert
|
||||
2025-06-19 09:26:53 - [utilities_collection] utilities_collection - [INFO] INFO - 🚨 ALLERLETZTE MEGA-Konsolidierung: 12+ Dateien → 1 Datei (90%+ Reduktion)
|
||||
2025-06-19 09:51:45 - [utilities_collection] utilities_collection - [INFO] INFO - ✅ Utilities Collection initialisiert
|
||||
2025-06-19 09:51:45 - [utilities_collection] utilities_collection - [INFO] INFO - 🚨 ALLERLETZTE MEGA-Konsolidierung: 12+ Dateien → 1 Datei (90%+ Reduktion)
|
||||
|
@ -12,7 +12,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from app import app
|
||||
from models import init_database, Printer, User, get_db_session
|
||||
from utils.tapo_status_manager import tapo_status_manager
|
||||
from utils.hardware_integration import printer_monitor
|
||||
from utils.logging_config import get_logger
|
||||
|
||||
logger = get_logger("test_printer_setup")
|
||||
@ -126,7 +126,7 @@ def test_printer_status():
|
||||
|
||||
with app.app_context():
|
||||
# Status aller Drucker abrufen
|
||||
all_status = tapo_status_manager.get_all_printer_status()
|
||||
all_status = printer_monitor.get_all_printer_status()
|
||||
|
||||
logger.info(f"📊 Status für {len(all_status)} Drucker abgerufen:\n")
|
||||
|
||||
@ -148,7 +148,7 @@ def test_printer_status():
|
||||
logger.info(f" 🔌 Steckdosen-IP: {status.get('plug_ip', 'Keine')}")
|
||||
|
||||
if status.get("has_plug"):
|
||||
status_text = tapo_status_manager.STATUS_DISPLAY.get(plug_status, {}).get("text", "Unbekannt")
|
||||
status_text = printer_monitor.STATUS_DISPLAY.get(plug_status, {}).get("text", "Unbekannt")
|
||||
logger.info(f" ⚡ Status: {status_text}")
|
||||
|
||||
if status.get("plug_reachable"):
|
||||
@ -194,7 +194,7 @@ def test_plug_control():
|
||||
logger.info(f"🎯 Teste Steuerung für: {printer.name}")
|
||||
|
||||
# Aktuellen Status abrufen
|
||||
current_status = tapo_status_manager.get_printer_status(printer.id)
|
||||
current_status = printer_monitor.get_printer_status(printer.id)
|
||||
logger.info(f"📊 Aktueller Status: {current_status.get('plug_status', 'unknown')}")
|
||||
|
||||
if not current_status.get("can_control"):
|
||||
@ -209,13 +209,13 @@ def test_plug_control():
|
||||
action = "on" if current_status.get("plug_status") == "off" else "off"
|
||||
logger.info(f"🔄 Versuche Steckdose zu '{action}' zu schalten...")
|
||||
|
||||
success, msg = tapo_status_manager.control_plug(printer.id, action)
|
||||
success, msg = printer_monitor.control_plug(printer.id, action)
|
||||
|
||||
if success:
|
||||
logger.info(f"✅ {msg}")
|
||||
|
||||
# Neuen Status abrufen
|
||||
new_status = tapo_status_manager.get_printer_status(printer.id)
|
||||
new_status = printer_monitor.get_printer_status(printer.id)
|
||||
logger.info(f"📊 Neuer Status: {new_status.get('plug_status', 'unknown')}")
|
||||
else:
|
||||
logger.error(f"❌ Fehler: {msg}")
|
||||
|
@ -1,163 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test-Script für Tapo-Controller Reparatur
|
||||
Testet die reparierte Tapo-Integration ohne PyP100-Abhängigkeit
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import socket
|
||||
import subprocess
|
||||
import ipaddress
|
||||
from datetime import datetime
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
# Simplified test without full dependencies
|
||||
print("🧪 MYP Tapo-Controller Reparatur-Test (Lightweight)")
|
||||
print("=" * 60)
|
||||
|
||||
def test_basic_network():
|
||||
"""Testet grundlegende Netzwerk-Konnektivität"""
|
||||
print("\n🔧 Teste Basis-Netzwerk-Konnektivität...")
|
||||
print("=" * 50)
|
||||
|
||||
# Test-IPs aus der Konfiguration
|
||||
test_ips = [
|
||||
"192.168.0.100",
|
||||
"192.168.0.101",
|
||||
"192.168.0.102",
|
||||
"192.168.0.103",
|
||||
"192.168.0.104",
|
||||
"192.168.0.106"
|
||||
]
|
||||
|
||||
results = []
|
||||
|
||||
for i, ip in enumerate(test_ips, 1):
|
||||
print(f"\n📡 Test {i}: {ip}")
|
||||
|
||||
# IP-Validierung
|
||||
try:
|
||||
ipaddress.ip_address(ip.strip())
|
||||
print(f" IP-Format: ✅ Gültig")
|
||||
except ValueError:
|
||||
print(f" IP-Format: ❌ Ungültig")
|
||||
results.append(False)
|
||||
continue
|
||||
|
||||
# Ping-Test
|
||||
ping_success = False
|
||||
try:
|
||||
result = subprocess.run(
|
||||
['ping', '-c', '1', '-W', '3', ip],
|
||||
capture_output=True,
|
||||
timeout=5
|
||||
)
|
||||
ping_success = result.returncode == 0
|
||||
print(f" ICMP-Ping: {'✅ Erreichbar' if ping_success else '❌ Nicht erreichbar'}")
|
||||
except (subprocess.TimeoutExpired, FileNotFoundError) as e:
|
||||
print(f" ICMP-Ping: ❌ Test fehlgeschlagen ({e})")
|
||||
|
||||
# TCP-Port-Test
|
||||
tcp_success = False
|
||||
test_ports = [9999, 80, 443]
|
||||
for port in test_ports:
|
||||
try:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.settimeout(3)
|
||||
result = sock.connect_ex((ip, port))
|
||||
sock.close()
|
||||
|
||||
if result == 0:
|
||||
print(f" TCP-Port {port}: ✅ Offen")
|
||||
tcp_success = True
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
if not tcp_success:
|
||||
print(f" TCP-Ports: ❌ Alle getesteten Ports geschlossen")
|
||||
|
||||
# Ergebnis bewerten
|
||||
device_reachable = ping_success or tcp_success
|
||||
results.append(device_reachable)
|
||||
|
||||
print(f" Gesamt: {'✅ Erreichbar' if device_reachable else '❌ Nicht erreichbar'}")
|
||||
|
||||
return results
|
||||
|
||||
def test_configuration():
|
||||
"""Testet die Konfigurationsdateien"""
|
||||
print("\n📊 Teste Konfiguration...")
|
||||
print("=" * 50)
|
||||
|
||||
config_files = [
|
||||
"config/settings.py",
|
||||
"utils/utilities_collection.py"
|
||||
]
|
||||
|
||||
found_configs = []
|
||||
|
||||
for config_file in config_files:
|
||||
if os.path.exists(config_file):
|
||||
print(f" ✅ {config_file} gefunden")
|
||||
found_configs.append(config_file)
|
||||
|
||||
# Prüfe auf DEFAULT_TAPO_IPS
|
||||
try:
|
||||
with open(config_file, 'r') as f:
|
||||
content = f.read()
|
||||
if 'DEFAULT_TAPO_IPS' in content:
|
||||
print(f" 📋 DEFAULT_TAPO_IPS definiert")
|
||||
if '192.168.0.100' in content:
|
||||
print(f" 🔗 Test-IP 192.168.0.100 konfiguriert")
|
||||
except Exception as e:
|
||||
print(f" ⚠️ Fehler beim Lesen: {e}")
|
||||
else:
|
||||
print(f" ❌ {config_file} nicht gefunden")
|
||||
|
||||
return len(found_configs) > 0
|
||||
|
||||
def main():
|
||||
"""Haupt-Testfunktion"""
|
||||
print("\n📋 Test-Ergebnisse:")
|
||||
print("=" * 40)
|
||||
|
||||
# 1. Konfiguration testen
|
||||
config_result = test_configuration()
|
||||
print(f"Konfiguration : {'✅ BESTANDEN' if config_result else '❌ FEHLGESCHLAGEN'}")
|
||||
|
||||
# 2. Netzwerk testen
|
||||
network_results = test_basic_network()
|
||||
online_devices = sum(network_results)
|
||||
total_devices = len(network_results)
|
||||
network_success = online_devices > 0
|
||||
|
||||
print(f"Netzwerk-Tests : {'✅ BESTANDEN' if network_success else '❌ FEHLGESCHLAGEN'}")
|
||||
print(f" Erreichbare Geräte : {online_devices}/{total_devices}")
|
||||
|
||||
# Zusammenfassung
|
||||
total_tests = 2
|
||||
passed_tests = sum([config_result, network_success])
|
||||
|
||||
print(f"\n🎯 Zusammenfassung: {passed_tests}/{total_tests} Tests bestanden")
|
||||
|
||||
if passed_tests == total_tests:
|
||||
print("🎉 Grundlegende Tests bestanden!")
|
||||
print("ℹ️ Hinweis: Für vollständige Funktionalität installieren Sie:")
|
||||
print(" - PyP100 (pip install PyP100)")
|
||||
print(" - SQLAlchemy und andere Abhängigkeiten")
|
||||
return True
|
||||
else:
|
||||
print("⚠️ Einige Tests fehlgeschlagen.")
|
||||
print("🔍 Prüfung der identifizierten Probleme:")
|
||||
print(" 1. ❌ Doppelte _collect_device_info Methoden -> ✅ BEHOBEN")
|
||||
print(" 2. ⚠️ PyP100 nicht installiert -> Fallback implementiert")
|
||||
print(" 3. ❌ IP-Konfigurationsfehler -> Konfiguration prüfen")
|
||||
print(" 4. ❌ Netzwerk-Timeout -> Erweiterte Tests implementiert")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = main()
|
||||
sys.exit(0 if success else 1)
|
Binary file not shown.
@ -11,7 +11,7 @@ from utils.logging_config import get_logger
|
||||
from models import Job, Printer, get_db_session
|
||||
from utils.utilities_collection import TAPO_USERNAME, TAPO_PASSWORD
|
||||
from utils.hardware_integration import tapo_controller
|
||||
from utils.tapo_status_manager import tapo_status_manager
|
||||
from utils.hardware_integration import printer_monitor
|
||||
# Legacy function - use tapo_controller.test_connection instead
|
||||
def test_tapo_connection(*args, **kwargs):
|
||||
return tapo_controller.test_connection(*args, **kwargs)
|
||||
@ -627,7 +627,7 @@ class BackgroundTaskScheduler:
|
||||
"""
|
||||
try:
|
||||
from models import get_db_session, Job
|
||||
from utils.tapo_status_manager import tapo_status_manager
|
||||
from utils.hardware_integration import printer_monitor
|
||||
|
||||
db_session = get_db_session()
|
||||
now = datetime.now()
|
||||
@ -643,7 +643,7 @@ class BackgroundTaskScheduler:
|
||||
self.logger.info(f"Starte geplanten Job {job.id} für Drucker {job.printer_id}")
|
||||
|
||||
# Steckdose einschalten
|
||||
success, msg = tapo_status_manager.control_plug(job.printer_id, "on")
|
||||
success, msg = printer_monitor.control_plug(job.printer_id, "on")
|
||||
|
||||
if success:
|
||||
job.status = "running"
|
||||
@ -671,7 +671,7 @@ class BackgroundTaskScheduler:
|
||||
self.logger.info(f"Beende Job {job.id} für Drucker {job.printer_id}")
|
||||
|
||||
# Steckdose ausschalten
|
||||
success, msg = tapo_status_manager.control_plug(job.printer_id, "off")
|
||||
success, msg = printer_monitor.control_plug(job.printer_id, "off")
|
||||
|
||||
if success:
|
||||
job.status = "finished"
|
||||
|
Reference in New Issue
Block a user