next fix for check status
This commit is contained in:
parent
da40eb5599
commit
444e1394fb
39
app.py
39
app.py
@ -254,35 +254,30 @@ def api_connect():
|
||||
|
||||
@app.route('/api/status', methods=['GET'])
|
||||
def api_status():
|
||||
"""
|
||||
Einfacher Status-Check: Ist ein Hub verbunden?
|
||||
Wird von Frontend periodisch aufgerufen, um Verbindungsverlust zu erkennen.
|
||||
"""
|
||||
global current_device
|
||||
|
||||
if current_device is None:
|
||||
logger.debug("Status-Check: Kein Device aktiv")
|
||||
return jsonify({
|
||||
"connected": False,
|
||||
"message": "Keine aktive Verbindung"
|
||||
}), 200 # 200 OK, damit der Check nicht als Fehler gilt
|
||||
return jsonify({"connected": False, "message": "Keine aktive Verbindung"})
|
||||
|
||||
try:
|
||||
# Optional: Hier könnte man später einen echten Test-Befehl machen
|
||||
# z. B. current_device.CreateTelegram() oder nur prüfen, ob Instanz lebt
|
||||
logger.debug("Status-Check: Device vorhanden → verbunden")
|
||||
return jsonify({
|
||||
"connected": True,
|
||||
"message": "Verbunden",
|
||||
"hub_id": current_config.get('hub_id') if current_config else None
|
||||
})
|
||||
# Echter Mini-Test: Setze Kanal 0 (A) auf 0.0 – sollte immer gehen, wenn Hub da ist
|
||||
current_device.SetChannel(0, 0.0)
|
||||
logger.debug("Status-Check: SetChannel(0, 0.0) erfolgreich → Hub antwortet")
|
||||
return jsonify({"connected": True, "message": "Verbunden"})
|
||||
|
||||
except Exception as e:
|
||||
logger.exception("Status-Check-Fehler")
|
||||
return jsonify({
|
||||
"connected": False,
|
||||
"message": f"Verbindungsfehler: {str(e)}"
|
||||
}), 200 # immer 200, damit Frontend entscheidet
|
||||
logger.warning(f"Status-Check: SetChannel-Test fehlgeschlagen → Hub wahrscheinlich weg: {e}")
|
||||
# Optional: Verbindung sauber beenden
|
||||
try:
|
||||
current_device.Disconnect()
|
||||
except:
|
||||
pass
|
||||
global current_device, current_module, current_hub
|
||||
current_device = None
|
||||
current_module = None
|
||||
current_hub = None
|
||||
|
||||
return jsonify({"connected": False, "message": f"Hub reagiert nicht: {str(e)}"})
|
||||
|
||||
|
||||
@app.route('/api/control', methods=['POST'])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user