"Refactor job scheduling and printer monitoring"
This commit is contained in:
@@ -1297,45 +1297,61 @@ def check_printer_status(ip_address: str, timeout: int = 7) -> Tuple[str, bool]:
|
||||
return "offline", False
|
||||
|
||||
try:
|
||||
# IP-Adresse validieren
|
||||
import ipaddress
|
||||
# TCP-Verbindung zu Port 80 oder 443 testen (statt Ping)
|
||||
try:
|
||||
ipaddress.ip_address(ip_address.strip())
|
||||
except ValueError:
|
||||
printers_logger.debug(f"Ungültige IP-Adresse: {ip_address}")
|
||||
import socket
|
||||
# Zuerst Port 80 versuchen
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.settimeout(timeout)
|
||||
result = sock.connect_ex((ip_address.strip(), 80))
|
||||
sock.close()
|
||||
|
||||
connection_ok = result == 0
|
||||
|
||||
# Falls Port 80 nicht erfolgreich, Port 443 testen
|
||||
if not connection_ok:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.settimeout(timeout)
|
||||
result = sock.connect_ex((ip_address.strip(), 443))
|
||||
sock.close()
|
||||
connection_ok = result == 0
|
||||
except:
|
||||
connection_ok = False
|
||||
|
||||
if not connection_ok:
|
||||
printers_logger.debug(f"Keine Verbindung zu {ip_address} möglich")
|
||||
return "offline", False
|
||||
|
||||
# Importiere PyP100 für Tapo-Unterstützung
|
||||
# TP-Link Tapo P100-Verbindung aufbauen
|
||||
try:
|
||||
from PyP100 import PyP110
|
||||
except ImportError:
|
||||
printers_logger.error("⚠️ PyP100-Modul nicht verfügbar - kann Tapo-Steckdosen nicht abfragen")
|
||||
# Passwort aus config/settings.py (mit 'A' am Ende)
|
||||
from config.settings import TAPO_USERNAME, TAPO_PASSWORD
|
||||
|
||||
# Verbindung aufbauen
|
||||
from PyP100 import PyP100
|
||||
p100 = PyP100.P100(ip_address, TAPO_USERNAME, TAPO_PASSWORD)
|
||||
p100.handshake() # Authentifizierung
|
||||
p100.login() # Login
|
||||
|
||||
# Geräteinformationen abrufen
|
||||
device_info = p100.getDeviceInfo()
|
||||
|
||||
# Status auswerten
|
||||
device_on = device_info.get('device_on', False)
|
||||
|
||||
if device_on:
|
||||
printers_logger.debug(f"Steckdose {ip_address} ist eingeschaltet")
|
||||
return "online", True
|
||||
else:
|
||||
printers_logger.debug(f"Steckdose {ip_address} ist ausgeschaltet")
|
||||
return "offline", False
|
||||
|
||||
except Exception as e:
|
||||
printers_logger.debug(f"Fehler bei Tapo-Verbindung zu {ip_address}: {str(e)}")
|
||||
return "offline", False
|
||||
|
||||
# Verwende IMMER die globalen hardkodierten Tapo-Anmeldedaten
|
||||
username = TAPO_USERNAME
|
||||
password = TAPO_PASSWORD
|
||||
|
||||
printers_logger.debug(f"🔌 Teste Tapo-Steckdose {ip_address} mit hardkodierten Anmeldedaten")
|
||||
|
||||
# TP-Link Tapo P110 Verbindung herstellen
|
||||
p110 = PyP110.P110(ip_address.strip(), username, password)
|
||||
p110.handshake() # Authentifizierung
|
||||
p110.login() # Login
|
||||
|
||||
# Geräteinformationen abrufen
|
||||
device_info = p110.getDeviceInfo()
|
||||
device_on = device_info.get('device_on', False)
|
||||
|
||||
if device_on:
|
||||
printers_logger.debug(f"✅ Drucker {ip_address}: ONLINE (Steckdose eingeschaltet)")
|
||||
return "online", True
|
||||
else:
|
||||
printers_logger.debug(f"🔄 Drucker {ip_address}: STANDBY (Steckdose ausgeschaltet)")
|
||||
return "standby", False
|
||||
|
||||
except Exception as e:
|
||||
printers_logger.debug(f"❌ Fehler beim Tapo-Status-Check für {ip_address}: {str(e)}")
|
||||
printers_logger.error(f"Fehler bei Status-Check für {ip_address}: {str(e)}")
|
||||
return "offline", False
|
||||
|
||||
@measure_execution_time(logger=printers_logger, task_name="Mehrere-Drucker-Status-Prüfung")
|
||||
|
Reference in New Issue
Block a user