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