fix error in app.py
This commit is contained in:
parent
444e1394fb
commit
7adda970fb
21
app.py
21
app.py
@ -254,30 +254,37 @@ def api_connect():
|
|||||||
|
|
||||||
@app.route('/api/status', methods=['GET'])
|
@app.route('/api/status', methods=['GET'])
|
||||||
def api_status():
|
def api_status():
|
||||||
global current_device
|
global current_device, current_module, current_hub # ← Global am Anfang!
|
||||||
|
|
||||||
if current_device is None:
|
if current_device is None:
|
||||||
return jsonify({"connected": False, "message": "Keine aktive Verbindung"})
|
logger.debug("Status-Check: Kein Device aktiv")
|
||||||
|
return jsonify({
|
||||||
|
"connected": False,
|
||||||
|
"message": "Keine aktive Verbindung"
|
||||||
|
}), 200
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Echter Mini-Test: Setze Kanal 0 (A) auf 0.0 – sollte immer gehen, wenn Hub da ist
|
# Echter Mini-Test: Setze Kanal 0 (A) auf 0.0
|
||||||
current_device.SetChannel(0, 0.0)
|
current_device.SetChannel(0, 0.0)
|
||||||
logger.debug("Status-Check: SetChannel(0, 0.0) erfolgreich → Hub antwortet")
|
logger.debug("Status-Check: SetChannel(0, 0.0) erfolgreich → Hub antwortet")
|
||||||
return jsonify({"connected": True, "message": "Verbunden"})
|
return jsonify({
|
||||||
|
"connected": True,
|
||||||
|
"message": "Verbunden"
|
||||||
|
})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Status-Check: SetChannel-Test fehlgeschlagen → Hub wahrscheinlich weg: {e}")
|
logger.warning(f"Status-Check: SetChannel-Test fehlgeschlagen → Hub wahrscheinlich weg: {e}")
|
||||||
# Optional: Verbindung sauber beenden
|
# Verbindung sauber beenden
|
||||||
try:
|
try:
|
||||||
current_device.Disconnect()
|
current_device.Disconnect()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
global current_device, current_module, current_hub
|
|
||||||
current_device = None
|
current_device = None
|
||||||
current_module = None
|
current_module = None
|
||||||
current_hub = None
|
current_hub = None
|
||||||
|
|
||||||
return jsonify({"connected": False, "message": f"Hub reagiert nicht: {str(e)}"})
|
return jsonify({"connected": False, "message": f"Hub reagiert nicht: {str(e)}"}), 200
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/control', methods=['POST'])
|
@app.route('/api/control', methods=['POST'])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user