From cbe868b5882d42325c1fadbe82391966aa038174 Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Wed, 6 Sep 2023 10:15:21 -0400 Subject: [PATCH] some more cleanup --- pioreactor/automations/__init__.py | 15 ++++++++++++++- pioreactor/automations/dosing/base.py | 15 --------------- pioreactor/automations/led/base.py | 6 ------ pioreactor/automations/temperature/base.py | 17 ----------------- 4 files changed, 14 insertions(+), 39 deletions(-) diff --git a/pioreactor/automations/__init__.py b/pioreactor/automations/__init__.py index 251167b3..cf58a94c 100644 --- a/pioreactor/automations/__init__.py +++ b/pioreactor/automations/__init__.py @@ -1,8 +1,12 @@ # -*- coding: utf-8 -*- from __future__ import annotations +from typing import Optional + +from pioreactor.automations import events from pioreactor.background_jobs.subjobs import BackgroundSubJob + DISALLOWED_AUTOMATION_NAMES = { "config", } @@ -11,7 +15,7 @@ class BaseAutomationJob(BackgroundSubJob): automation_name = "base_automation_job" - def __init__(self, unit: str, experiment: str): + def __init__(self, unit: str, experiment: str) -> None: super(BaseAutomationJob, self).__init__(unit, experiment) if self.automation_name in DISALLOWED_AUTOMATION_NAMES: @@ -24,3 +28,12 @@ def __init__(self, unit: str, experiment: str): "settable": False, }, ) + + def on_init_to_ready(self) -> None: + self.start_passive_listeners() + + def execute(self) -> Optional[events.AutomationEvent]: + """ + Overwrite in subclass + """ + raise NotImplementedError("Overwrite in base class") diff --git a/pioreactor/automations/dosing/base.py b/pioreactor/automations/dosing/base.py index 36780b9c..c196d255 100644 --- a/pioreactor/automations/dosing/base.py +++ b/pioreactor/automations/dosing/base.py @@ -250,19 +250,8 @@ def __init__( self._init_volume_throughput() self._init_vial_volume(float(initial_vial_volume)) - self.add_to_published_settings( - "latest_event", - { - "datatype": "AutomationEvent", - "settable": False, - }, - ) - self.set_duration(duration) - def on_init_to_ready(self): - self.start_passive_listeners() - def set_duration(self, duration: Optional[float]) -> None: if duration: self.duration = float(duration) @@ -340,10 +329,6 @@ def run(self, timeout: float = 60.0) -> Optional[events.AutomationEvent]: self._latest_run_at = current_utc_datetime() return event - def execute(self) -> Optional[events.AutomationEvent]: - # should be defined in subclass - return events.NoEvent() - def block_until_not_sleeping(self) -> bool: while self.state == self.SLEEPING: brief_pause() diff --git a/pioreactor/automations/led/base.py b/pioreactor/automations/led/base.py index 7a483c41..76472948 100644 --- a/pioreactor/automations/led/base.py +++ b/pioreactor/automations/led/base.py @@ -89,9 +89,6 @@ def __init__( self.set_duration(duration) - def on_init_to_ready(self): - self.start_passive_listeners() - def set_duration(self, duration: float) -> None: self.duration = float(duration) if self._latest_run_at is not None: @@ -159,9 +156,6 @@ def run(self, timeout: float = 60.0) -> Optional[events.AutomationEvent]: self._latest_run_at = current_utc_datetime() return event - def execute(self) -> Optional[events.AutomationEvent]: - pass - @property def most_stale_time(self) -> datetime: return min(self.latest_normalized_od_at, self.latest_growth_rate_at) diff --git a/pioreactor/automations/temperature/base.py b/pioreactor/automations/temperature/base.py index b792e28d..58a19a95 100644 --- a/pioreactor/automations/temperature/base.py +++ b/pioreactor/automations/temperature/base.py @@ -68,19 +68,8 @@ def __init__( self.latest_temperture_at: datetime = current_utc_datetime() self._latest_settings_started_at = current_utc_datetime() - self.add_to_published_settings( - "latest_event", - { - "datatype": "AutomationEvent", - "settable": False, - }, - ) - self.temperature_control_parent = temperature_control_parent - def on_init_to_ready(self): - self.start_passive_listeners() - def update_heater(self, new_duty_cycle: float) -> bool: """ Update heater's duty cycle. This function checks for a lock on the PWM, and will not @@ -116,12 +105,6 @@ def update_heater_with_delta(self, delta_duty_cycle: float) -> bool: """ return self.temperature_control_parent.update_heater_with_delta(delta_duty_cycle) - def execute(self): - """ - Overwrite in base class - """ - raise NotImplementedError - @property def most_stale_time(self) -> datetime: return min(self.latest_normalized_od_at, self.latest_growth_rate_at)