File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff 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" ])
578617def get_all_calibrations () -> ResponseReturnValue :
579618 calibration_dir = Path (env ["DOT_PIOREACTOR" ]) / "storage" / "calibrations"
You can’t perform that action at this time.
0 commit comments