-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
601 convert smargon to ophyd async #656
Changes from all commits
5687e13
0f5f40c
f748a05
fcf5c4b
07ea06c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
from functools import partial | ||
from typing import Callable | ||
|
||
from ophyd import Component, Device, EpicsSignal | ||
from bluesky.protocols import Movable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I would like it better if we did something like from ophyd_async.core import device as OphydAsyncDevice
from ophyd import device as OphydDevice or alternatively to use |
||
from ophyd import Component, EpicsSignal | ||
from ophyd import Device as OphydDevice | ||
from ophyd.status import Status, StatusBase | ||
from ophyd_async.core import AsyncStatus, wait_for_value | ||
from ophyd_async.core import Device as OphydAsyncDevice | ||
from ophyd_async.epics.signal import epics_signal_r, epics_signal_rw | ||
|
||
from dodal.devices.status import await_value | ||
from dodal.log import LOGGER | ||
|
||
|
||
|
@@ -24,7 +28,7 @@ def epics_signal_put_wait(pv_name: str, wait: float = 3.0) -> Component[EpicsSig | |
def run_functions_without_blocking( | ||
functions_to_chain: list[Callable[[], StatusBase]], | ||
timeout: float = 60.0, | ||
associated_obj: Device | None = None, | ||
associated_obj: OphydDevice | None = None, | ||
) -> Status: | ||
"""Creates and initiates an asynchronous chaining of functions which return a status | ||
|
||
|
@@ -112,16 +116,15 @@ def call_func(func: Callable[[], StatusBase]) -> StatusBase: | |
return func() | ||
|
||
|
||
class SetWhenEnabled(Device): | ||
class SetWhenEnabled(OphydAsyncDevice, Movable): | ||
"""A device that sets the proc field of a PV when it becomes enabled.""" | ||
|
||
proc = Component(EpicsSignal, ".PROC") | ||
disp = Component(EpicsSignal, ".DISP") | ||
def __init__(self, name: str = "", prefix: str = ""): | ||
self.proc = epics_signal_rw(int, prefix + ".PROC") | ||
self.disp = epics_signal_r(int, prefix + ".DISP") | ||
super().__init__(name) | ||
|
||
def set(self, proc: int) -> Status: | ||
return run_functions_without_blocking( | ||
[ | ||
lambda: await_value(self.disp, 0), | ||
lambda: self.proc.set(proc), | ||
] | ||
) | ||
@AsyncStatus.wrap | ||
async def set(self, value: int): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 |
||
await wait_for_value(self.disp, 0, None) | ||
await self.proc.set(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it a deliberate choice not to use
__contains__
here?