Skip to content

Commit

Permalink
Added watsonmarlow323 device for i22 ppump. (#575)
Browse files Browse the repository at this point in the history
* Added watsonmarlow323 device for i22 ppump.

* Changes from code review: improved naming, made enabled read/write, and used ophyd-async assert_reading utility function for tests.

* Fixed linting errors.

* Changes from code review: added device details to docstring, removed skip device, enabled fake_with_ophyd_sim, and don't specify read write pv if they are the same.

* Change from code review: added simulated pump to p38.

* Change from code review: Removed limits that are now propagted by their corresponding signal.

* Rebased, updated to use add_children_as_readables to fix deprecated errors, and updated enum baseclass to use ophyd_async's.

---------

Co-authored-by: William Barnett <[email protected]>
Co-authored-by: Will Barnett <[email protected]>
  • Loading branch information
3 people authored Nov 10, 2024
1 parent 8ab51b1 commit fc296b5
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/dodal/beamlines/i22.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from dodal.devices.synchrotron import Synchrotron
from dodal.devices.tetramm import TetrammDetector
from dodal.devices.undulator import Undulator
from dodal.devices.watsonmarlow323_pump import WatsonMarlow323Pump
from dodal.log import set_beamline as set_log_beamline
from dodal.utils import BeamlinePrefix, get_beamline_name, skip_device

Expand Down Expand Up @@ -376,3 +377,16 @@ def linkam(
wait_for_connection,
fake_with_ophyd_sim,
)


def ppump(
wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False
) -> WatsonMarlow323Pump:
"""Sample Environment Peristaltic Pump"""
return device_instantiation(
WatsonMarlow323Pump,
"ppump",
"-EA-PUMP-01:",
wait_for_connection,
fake_with_ophyd_sim,
)
14 changes: 14 additions & 0 deletions src/dodal/beamlines/p38.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from dodal.devices.slits import Slits
from dodal.devices.tetramm import TetrammDetector
from dodal.devices.undulator import Undulator
from dodal.devices.watsonmarlow323_pump import WatsonMarlow323Pump
from dodal.log import set_beamline as set_log_beamline
from dodal.utils import BeamlinePrefix, get_beamline_name, skip_device

Expand Down Expand Up @@ -315,3 +316,16 @@ def linkam(
wait_for_connection,
fake_with_ophyd_sim,
)


def ppump(
wait_for_connection: bool = True, fake_with_ophyd_sim: bool = True
) -> WatsonMarlow323Pump:
"""Peristaltic Pump"""
return device_instantiation(
WatsonMarlow323Pump,
"ppump",
"-EA-PUMP-01:",
wait_for_connection,
fake_with_ophyd_sim,
)
45 changes: 45 additions & 0 deletions src/dodal/devices/watsonmarlow323_pump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from ophyd_async.core import ConfigSignal, StandardReadable, StrictEnum
from ophyd_async.epics.signal import epics_signal_rw


class WatsonMarlow323PumpEnable(StrictEnum):
DISABLED = "Disabled"
ENABLED = "Enabled"


class WatsonMarlow323PumpDirection(StrictEnum):
CLOCKWISE = "CW"
COUNTER_CLOCKWISE = "CCW"


class WatsonMarlow323PumpState(StrictEnum):
STOPPED = "STOP"
STARTED = "START"


class WatsonMarlow323Pump(StandardReadable):
"""Watson Marlow 323 Peristaltic Pump device"""

def __init__(self, prefix: str, name: str = "") -> None:
with self.add_children_as_readables():
self.direction = epics_signal_rw(
WatsonMarlow323PumpDirection,
read_pv=prefix + "INFO:DIR",
write_pv=prefix + "SET:DIR",
)
self.state = epics_signal_rw(
WatsonMarlow323PumpState,
read_pv=prefix + "INFO:RUN",
write_pv=prefix + "SET:RUN",
)
self.speed = epics_signal_rw(
float, read_pv=prefix + "INFO:SPD", write_pv=prefix + "SET:SPD"
)

with self.add_children_as_readables(ConfigSignal):
self.enabled = epics_signal_rw(
WatsonMarlow323PumpEnable,
prefix + "DISABLE",
)

super().__init__(name=name)
47 changes: 47 additions & 0 deletions tests/devices/unit_tests/test_watsonmarlow323_pump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from unittest.mock import ANY

import pytest
from ophyd_async.core import DeviceCollector, assert_reading, set_mock_value

from dodal.devices.watsonmarlow323_pump import (
WatsonMarlow323Pump,
WatsonMarlow323PumpDirection,
WatsonMarlow323PumpState,
)


@pytest.fixture
async def watsonmarlow323() -> WatsonMarlow323Pump:
async with DeviceCollector(mock=True):
wm_pump = WatsonMarlow323Pump("DEMO-WMPUMP-01:")

return wm_pump


async def test_reading_pump_reads_state_speed_and_direction(
watsonmarlow323: WatsonMarlow323Pump,
):
set_mock_value(watsonmarlow323.state, WatsonMarlow323PumpState.STOPPED)
set_mock_value(watsonmarlow323.speed, 25)
set_mock_value(watsonmarlow323.direction, WatsonMarlow323PumpDirection.CLOCKWISE)

await assert_reading(
watsonmarlow323,
{
"wm_pump-state": {
"value": WatsonMarlow323PumpState.STOPPED,
"timestamp": ANY,
"alarm_severity": 0,
},
"wm_pump-speed": {
"value": 25,
"timestamp": ANY,
"alarm_severity": 0,
},
"wm_pump-direction": {
"value": WatsonMarlow323PumpDirection.CLOCKWISE,
"timestamp": ANY,
"alarm_severity": 0,
},
},
)

0 comments on commit fc296b5

Please sign in to comment.