diff --git a/docs/events/index.rst b/docs/events/index.rst index 111983006..2ef7d2d70 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -525,6 +525,7 @@ PrintCancelled feedrate outside of OctoPrint, e.g. through the printer controller, or if you are printing from SD, this will NOT be accurate) * ``fileposition``: position in the file in bytes at the time of cancellation + * ``progress``: print progress as a percentage at the time of cancellation .. deprecated:: 1.3.0 @@ -557,6 +558,7 @@ PrintPaused feedrate outside of OctoPrint, e.g. through the printer controller, or if you are printing from SD, this will NOT be accurate) * ``fileposition``: position in the file in bytes at the time of pausing + * ``progress``: print progress as a percentage at the time of pausing .. deprecated:: 1.3.0 diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 28fe87813..c1739357d 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -1453,6 +1453,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): payload["time"] = self._comm.getPrintTime() payload["reason"] = "error" payload["error"] = self._comm.getErrorString() + payload["progress"] = self._comm.getPrintProgress() def finalize(): self._fileManager.log_print( @@ -1688,11 +1689,13 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self._updateProgressData() fileposition = self._comm.getFilePosition() if self._comm else None + progress = self._comm.getPrintProgress() if self._comm else None payload = self._payload_for_print_job_event( position=self._comm.cancel_position.as_dict() if self._comm and self._comm.cancel_position else None, fileposition=fileposition["pos"] if fileposition else None, + progress=progress, action_user=user, ) if payload: @@ -1741,11 +1744,13 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): def on_comm_print_job_paused(self, suppress_script=False, user=None): fileposition = self._comm.getFilePosition() if self._comm else None + progress = self._comm.getPrintProgress() if self._comm else None payload = self._payload_for_print_job_event( position=self._comm.pause_position.as_dict() if self._comm and self._comm.pause_position and not suppress_script else None, fileposition=fileposition["pos"] if fileposition else None, + progress=progress, action_user=user, ) if payload: @@ -1874,6 +1879,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): print_job_user=None, position=None, fileposition=None, + progress=None, action_user=None, ): if print_job_file is None: @@ -1919,6 +1925,9 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): if fileposition is not None: result["fileposition"] = fileposition + if progress is not None: + result["progress"] = int(progress * 100) + if print_job_user is not None: result["owner"] = print_job_user