-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added AsyncReadable, AsyncConfigurable and AsyncPausable
Also replaced imports of bluesky.protocols for each with their new async counterparts.
- Loading branch information
Oliver Copping
committed
Apr 16, 2024
1 parent
e54c91c
commit d519495
Showing
5 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .protocols import AsyncReadable, AsyncConfigurable, AsyncPausable | ||
|
||
__all__ = ["AsyncReadable", "AsyncConfigurable", "AsyncPausable"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from abc import abstractmethod | ||
from typing import Any, Coroutine, Dict, Protocol, runtime_checkable | ||
from bluesky.protocols import HasName, Reading, Descriptor | ||
|
||
|
||
@runtime_checkable | ||
class AsyncReadable(HasName, Protocol): | ||
@abstractmethod | ||
async def read(self) -> Coroutine[Any, Any, Dict[str, Reading]]: | ||
"""Return an OrderedDict mapping string field name(s) to dictionaries | ||
of values and timestamps and optional per-point metadata. | ||
Example return value: | ||
.. code-block:: python | ||
OrderedDict(('channel1', | ||
{'value': 5, 'timestamp': 1472493713.271991}), | ||
('channel2', | ||
{'value': 16, 'timestamp': 1472493713.539238})) | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
async def describe(self) -> Coroutine[Any, Any, Dict[str, Descriptor]]: | ||
"""Return an OrderedDict with exactly the same keys as the ``read`` | ||
method, here mapped to per-scan metadata about each field. | ||
Example return value: | ||
.. code-block:: python | ||
OrderedDict(('channel1', | ||
{'source': 'XF23-ID:SOME_PV_NAME', | ||
'dtype': 'number', | ||
'shape': []}), | ||
('channel2', | ||
{'source': 'XF23-ID:SOME_PV_NAME', | ||
'dtype': 'number', | ||
'shape': []})) | ||
""" | ||
... | ||
|
||
|
||
@runtime_checkable | ||
class AsyncConfigurable(Protocol): | ||
@abstractmethod | ||
async def read_configuration(self) -> Coroutine[Any, Any, Dict[str, Reading]]: | ||
"""Same API as ``read`` but for slow-changing fields related to configuration. | ||
e.g., exposure time. These will typically be read only once per run. | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
async def describe_configuration(self) -> Coroutine[Any, Any, Dict[str, Descriptor]]: | ||
"""Same API as ``describe``, but corresponding to the keys in | ||
``read_configuration``. | ||
""" | ||
... | ||
|
||
|
||
@runtime_checkable | ||
class AsyncPausable(Protocol): | ||
@abstractmethod | ||
async def pause(self) -> None: | ||
"""Perform device-specific work when the RunEngine pauses.""" | ||
... | ||
|
||
@abstractmethod | ||
async def resume(self) -> None: | ||
"""Perform device-specific work when the RunEngine resumes after a pause.""" | ||
... |