From 7b33cb7bb4f88a9f944db189b9b5a720d02c6355 Mon Sep 17 00:00:00 2001 From: adlee-was-taken Date: Sun, 5 Apr 2026 12:03:05 -0400 Subject: [PATCH] fix(web): align arm/disarm 202 response shape with {"ok": true} convention MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to efd5c4a. The plan invented {"accepted": True, ...} for the new 202 responses, but every other 2xx endpoint in the Flask app returns {"ok": True, ...} — including cameras.py:108 which is direct prior art for a 202 with the same convention. The shared JS helper at static/js/settings.js:54 does 'if (resp.ok && result.ok)' and was falling into the error branch on our success responses, showing a bogus "Save failed" toast after every arm/disarm click. Keep the 202 status. Swap the body key from 'accepted' to 'ok'. No JS change needed. --- tests/unit/test_system_pin.py | 2 +- vigilar/web/blueprints/system.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_system_pin.py b/tests/unit/test_system_pin.py index fb52be8..87475fd 100644 --- a/tests/unit/test_system_pin.py +++ b/tests/unit/test_system_pin.py @@ -110,7 +110,7 @@ def test_arm_publishes_arm_request_on_mqtt(app_with_pin): json={"mode": "ARMED_AWAY", "pin": "1234"}, ) assert rv.status_code == 202 - assert rv.get_json()["accepted"] is True + assert rv.get_json()["ok"] is True pub.assert_called_once() call_args = pub.call_args diff --git a/vigilar/web/blueprints/system.py b/vigilar/web/blueprints/system.py index 884c0c0..771c350 100644 --- a/vigilar/web/blueprints/system.py +++ b/vigilar/web/blueprints/system.py @@ -78,7 +78,7 @@ def arm_system(): except Exception: current_app.logger.exception("Failed to publish arm request") return jsonify({"error": "bus unavailable"}), 503 - return jsonify({"accepted": True, "mode": mode}), 202 + return jsonify({"ok": True, "mode": mode}), 202 @system_bp.route("/api/disarm", methods=["POST"]) @@ -91,7 +91,7 @@ def disarm_system(): except Exception: current_app.logger.exception("Failed to publish arm request") return jsonify({"error": "bus unavailable"}), 503 - return jsonify({"accepted": True, "mode": "DISARMED"}), 202 + return jsonify({"ok": True, "mode": "DISARMED"}), 202 @system_bp.route("/api/reset-pin", methods=["POST"])