From 8f2d88db293bdb7dc5c14f527d10815af9953266 Mon Sep 17 00:00:00 2001 From: Scott Martin Date: Sat, 10 Sep 2022 09:11:42 -0400 Subject: [PATCH] Fix print successes treated as failures, bump version to 2.1.2 --- continuousprint/driver.py | 18 ++++++++---------- continuousprint/driver_test.py | 4 ++-- setup.py | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/continuousprint/driver.py b/continuousprint/driver.py index bfc4ab0..9bec01b 100644 --- a/continuousprint/driver.py +++ b/continuousprint/driver.py @@ -37,7 +37,7 @@ def timeAgo(elapsed): class Driver: # If the printer is idle for this long while printing, break out of the printing state (consider it a failure) - PRINTING_IDLE_BREAKOUT_SEC = 10.0 + PRINTING_IDLE_BREAKOUT_SEC = 15.0 def __init__( self, @@ -200,7 +200,13 @@ def _state_printing(self, a: Action, p: Printer, elapsed=None): StatusType.NEEDS_ACTION, ) return self._state_paused - elif a == Action.SUCCESS: + elif a == Action.SUCCESS or ( + p == Printer.IDLE + and time.time() - self.idle_start_ts > self.PRINTING_IDLE_BREAKOUT_SEC + ): + # If idle state without event, assume we somehow missed the SUCCESS action. + # We wait for a period of idleness to prevent idle-before-success events + # from double-completing prints. item = self.q.get_set() # A limitation of `octoprint.printer`, the "current file" path passed to the driver is only @@ -222,14 +228,6 @@ def _state_printing(self, a: Action, p: Printer, elapsed=None): self._set_status("Waiting for printer to be ready") elif p == Printer.PAUSED: return self._state_paused - elif ( - p == Printer.IDLE - and time.time() - self.idle_start_ts > self.PRINTING_IDLE_BREAKOUT_SEC - ): - # Idle state without event; assume we somehow missed the SUCCESS action - # We wait for a period of idleness to prevent idle-before-success events - # from double-completing prints. - return self._state_failure def _state_paused(self, a: Action, p: Printer): self._set_status("Paused", StatusType.NEEDS_ACTION) diff --git a/continuousprint/driver_test.py b/continuousprint/driver_test.py index e53f41b..4385b50 100644 --- a/continuousprint/driver_test.py +++ b/continuousprint/driver_test.py @@ -77,10 +77,10 @@ def test_idle_while_printing(self): self.d.action(DA.TICK, DP.IDLE) self.assertEqual(self.d.state.__name__, self.d._state_printing.__name__) - # Continued idleness triggers failure (retry behavior validated in test_retry_after_failure) + # Continued idleness triggers bed clearing and such self.d.idle_start_ts = time.time() - (Driver.PRINTING_IDLE_BREAKOUT_SEC + 1) self.d.action(DA.TICK, DP.IDLE) - self.assertEqual(self.d.state.__name__, self.d._state_failure.__name__) + self.assertEqual(self.d.state.__name__, self.d._state_start_clearing.__name__) def test_retry_after_failure(self): self.d.state = self.d._state_failure diff --git a/setup.py b/setup.py index 7051924..ab4dc1f 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "continuousprint" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "2.1.1" +plugin_version = "2.1.2" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module