Skip to content

Commit 9575a29

Browse files
delete cal api
1 parent 7d154e3 commit 9575a29

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

pioreactorui/unit_api.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,45 @@ def create_calibration(device) -> ResponseReturnValue:
574574
abort(500, description="Failed to create calibration.")
575575

576576

577+
@unit_api.route("/calibrations/<device>/<calibration_name>", methods=["DELETE"])
578+
def delete_calibration(device: str, calibration_name: str) -> ResponseReturnValue:
579+
"""
580+
Delete a specific calibration for a given device.
581+
"""
582+
calibration_path = (
583+
Path(env["DOT_PIOREACTOR"])
584+
/ "storage"
585+
/ "calibrations"
586+
/ device
587+
/ f"{calibration_name}.yaml"
588+
)
589+
590+
if not calibration_path.exists():
591+
abort(404, description=f"Calibration '{calibration_name}' not found for device '{device}'.")
592+
593+
try:
594+
# Remove the calibration file
595+
calibration_path.unlink()
596+
597+
# If the deleted calibration was active, remove its active status
598+
with local_persistent_storage("active_calibrations") as cache:
599+
if cache.get(device) == calibration_name:
600+
cache.pop(device)
601+
602+
return (
603+
jsonify(
604+
{
605+
"msg": f"Calibration '{calibration_name}' for device '{device}' deleted successfully."
606+
}
607+
),
608+
200,
609+
)
610+
611+
except Exception as e:
612+
publish_to_error_log(f"Error deleting calibration: {e}", "delete_calibration")
613+
abort(500, description="Failed to delete calibration.")
614+
615+
577616
@unit_api.route("/calibrations", methods=["GET"])
578617
def get_all_calibrations() -> ResponseReturnValue:
579618
calibration_dir = Path(env["DOT_PIOREACTOR"]) / "storage" / "calibrations"

0 commit comments

Comments
 (0)