From 523d4aa5ac65cfac058ee237d5046555b5b29ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 23 Oct 2023 18:22:11 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20progress=20to=20Print(Failed|?= =?UTF-8?q?Cancelled|Paused)=20events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/events/index.rst | 2 ++ src/octoprint/printer/standard.py | 9 +++++++++ 2 files changed, 11 insertions(+) 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