From 7f0d4779856b402ea1387574c6a49cbc60e09d0a Mon Sep 17 00:00:00 2001 From: Till Tomczak Date: Thu, 19 Jun 2025 22:40:51 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Fix:=20DruckerSteuerung.check=5F?= =?UTF-8?q?outlet=5Fstatus=20Methode=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fehlende check_outlet_status Methode zur DruckerSteuerung Klasse hinzugefügt - Vollständige Tapo-Steckdosen Status-Prüfung implementiert - Error-Handling für Verbindungsfehler und Device-Errors - Simulation-Mode Support für Entwicklung ohne Hardware - Debug-Logging für bessere Fehlerdiagnose Fixes AttributeError: 'DruckerSteuerung' object has no attribute 'check_outlet_status' 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- backend/utils/hardware_integration.py | 62 +++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/backend/utils/hardware_integration.py b/backend/utils/hardware_integration.py index 1158ecd68..8856f41dd 100644 --- a/backend/utils/hardware_integration.py +++ b/backend/utils/hardware_integration.py @@ -425,6 +425,68 @@ class DruckerSteuerung: def _template_daten_sammeln(self) -> Dict[str, Any]: """Wrapper für template_daten_sammeln (Backward-Compatibility)""" return self.template_daten_sammeln() + + def check_outlet_status(self, ip: str) -> Dict[str, Any]: + """ + Prüft den Status einer Tapo-Steckdose. + + Args: + ip: IP-Adresse der Steckdose + + Returns: + Dict mit Status-Informationen + """ + hardware_logger.debug(f"🔍 Prüfe Steckdosen-Status: {ip}") + + if not TAPO_AVAILABLE: + return { + 'success': True, + 'outlet_on': True, + 'message': 'Simulation: Steckdose online' + } + + try: + # Tapo P100/P110 Verbindung + p100 = PyP100(ip, self.tapo_username, self.tapo_password) + p100.handshake() + p100.login() + + # Device Info abrufen + device_info = p100.getDeviceInfo() + + if device_info and 'error_code' in device_info: + if device_info['error_code'] == 0: + device_on = device_info.get('result', {}).get('device_on', False) + + hardware_logger.debug(f"✅ Steckdose {ip}: {'EIN' if device_on else 'AUS'}") + + return { + 'success': True, + 'outlet_on': device_on, + 'message': f"Steckdose ist {'eingeschaltet' if device_on else 'ausgeschaltet'}" + } + else: + hardware_logger.warning(f"⚠️ Steckdose {ip} Error Code: {device_info['error_code']}") + return { + 'success': False, + 'outlet_on': False, + 'message': f"Steckdose Fehler: {device_info['error_code']}" + } + else: + hardware_logger.error(f"❌ Steckdose {ip}: Keine gültige Antwort") + return { + 'success': False, + 'outlet_on': False, + 'message': 'Keine gültige Antwort von Steckdose' + } + + except Exception as e: + hardware_logger.error(f"❌ Fehler beim Prüfen von Steckdose {ip}: {e}") + return { + 'success': False, + 'outlet_on': False, + 'message': f'Verbindungsfehler: {str(e)}' + } # ===== GLOBALE INSTANZ =====