feat: implement probe renaming and settings management via API

This commit is contained in:
Keith Solomon
2026-07-21 16:37:37 -05:00
parent 1bd1ddc20e
commit 2a72972b4f
4 changed files with 298 additions and 19 deletions
+45
View File
@@ -84,6 +84,51 @@ def api_cyd_latest():
return jsonify(payload)
def _fetch_cyd_settings():
try:
resp = requests.get(f"{config.CYD_BASE_URL}/api/settings", timeout=10)
resp.raise_for_status()
return resp.json()
except Exception as e:
app.logger.warning(f"CYD settings fetch failed: {e}")
return None
@app.route("/api/probes", methods=["GET", "PUT"])
def probes():
if request.method == "GET":
settings = _fetch_cyd_settings()
if settings is None:
# Fall back to the latest reading so the UI still has something to show.
latest = fetch_cyd()
names = []
if latest:
names = [p.get("name", f"Probe {i + 1}") for i, p in enumerate(latest.get("probes", []))]
if not names:
names = [f"Probe {i + 1}" for i in range(4)]
return jsonify({"ok": True, "names": names, "source": "fallback"}), 200
names = settings.get("probeNames", [f"Probe {i + 1}" for i in range(4)])
return jsonify({"ok": True, "names": names, "source": "cyd"})
# PUT — forward to CYD's /api/settings with just the probeNames field.
data = request.get_json() or {}
names = data.get("names", [])
if not isinstance(names, list) or len(names) != 4 or not all(isinstance(n, str) for n in names):
return jsonify({"ok": False, "error": "names must be an array of 4 strings"}), 422
try:
resp = requests.post(
f"{config.CYD_BASE_URL}/api/settings",
json={"probeNames": names},
timeout=10,
)
resp.raise_for_status()
except Exception as e:
app.logger.warning(f"CYD settings update failed: {e}")
return jsonify({"ok": False, "error": f"Unable to update CYD: {e}"}), 502
return jsonify({"ok": True, "names": names})
@app.route("/api/sessions", methods=["GET", "POST"])
def sessions():
if request.method == "POST":