diff --git a/pioreactor/background_jobs/stirring.py b/pioreactor/background_jobs/stirring.py index 114f6bdd..0a0d6ac8 100644 --- a/pioreactor/background_jobs/stirring.py +++ b/pioreactor/background_jobs/stirring.py @@ -282,7 +282,7 @@ def __init__( ) def action_to_do_before_od_reading(self): - self.set_duty_cycle(0) + self.stop_stirring() def action_to_do_after_od_reading(self): self.start_stirring() @@ -359,6 +359,12 @@ def start_stirring(self) -> None: if self.rpm_calculator is not None: self.rpm_check_repeated_thread.start() # .start is idempotent + def stop_stirring(self) -> None: + self.set_duty_cycle(0) # get momentum to start + if self.rpm_calculator is not None: + self.measured_rpm = structs.MeasuredRPM(timestamp=current_utc_datetime(), measured_rpm=0) + self.rpm_check_repeated_thread.pause() # .start is idempotent + def kick_stirring(self) -> None: self.logger.debug("Kicking stirring") self.set_duty_cycle(0) @@ -433,8 +439,7 @@ def poll_and_update_dc(self, poll_for_seconds: Optional[float] = None) -> None: self.set_duty_cycle(self._estimate_duty_cycle) def on_ready_to_sleeping(self) -> None: - self.rpm_check_repeated_thread.pause() - self.set_duty_cycle(0.0) + self.stop_stirring() def on_sleeping_to_ready(self) -> None: super().on_sleeping_to_ready() diff --git a/pioreactor/tests/test_stirring.py b/pioreactor/tests/test_stirring.py index 5d7d8ea4..46aff6b0 100644 --- a/pioreactor/tests/test_stirring.py +++ b/pioreactor/tests/test_stirring.py @@ -113,6 +113,17 @@ def test_publish_measured_rpm() -> None: assert message is not None assert json.loads(message.payload)["measured_rpm"] == 0 + publish(f"pioreactor/{unit}/{exp}/stirring/$state/set", "sleeping") + pause() + pause() + pause() + assert st.state == st.SLEEPING + assert st.duty_cycle == 0 + assert st.measured_rpm.measured_rpm == 0 + message = subscribe(f"pioreactor/{unit}/{exp}/stirring/measured_rpm", timeout=3) + assert message is not None + assert json.loads(message.payload)["measured_rpm"] == 0 + def test_rpm_isnt_updated_if_there_is_no_rpm_measurement() -> None: exp = "test_publish_measured_rpm"