-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cb9596
commit b6c942b
Showing
4 changed files
with
53 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
from .coordination import group_uuid, inject | ||
from .coordination import group_uuid | ||
from .maths import in_micros, step_to_num | ||
from .types import MsgGenerator, PlanGenerator | ||
from .types import PlanGenerator | ||
|
||
__all__ = [ | ||
"group_uuid", | ||
"inject", | ||
"in_micros", | ||
"MsgGenerator", | ||
"PlanGenerator", | ||
"step_to_num", | ||
] | ||
|
||
|
||
def __getattr__(name): | ||
if name == "MsgGenerator": | ||
raise DeprecationWarning("import from bluesky.utils instead") | ||
if name == "inject": | ||
raise DeprecationWarning("Use result of dodal device call instead") | ||
|
||
return globals()[name] |
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,41 @@ | ||
from collections.abc import Callable, Collection, Mapping, Sequence | ||
from typing import ParamSpec | ||
|
||
from bluesky.utils import MsgGenerator, make_decorator | ||
from ophyd_async.core import DEFAULT_TIMEOUT, Device | ||
from ophyd_async.plan_stubs import ensure_connected | ||
|
||
P = ParamSpec("P") | ||
|
||
|
||
def _recursively_find_devices(obj) -> set[Device]: | ||
if isinstance(obj, Device): | ||
return {obj} | ||
if isinstance(obj, Sequence | Collection): | ||
return {dev for arg in obj for dev in _recursively_find_devices(arg)} | ||
if isinstance(obj, Mapping): | ||
return { | ||
dev | ||
for key, value in obj.items() | ||
for dev in _recursively_find_devices(key) | _recursively_find_devices(value) | ||
} | ||
return set() | ||
|
||
|
||
def ensure_devices_connected( | ||
plan: Callable[P, MsgGenerator], | ||
mock: bool = False, | ||
timeout: float = DEFAULT_TIMEOUT, | ||
force_reconnect: bool = False, | ||
) -> Callable[P, MsgGenerator]: | ||
def plan_with_connected_devices(*args: P.args, **kwargs: P.kwargs): | ||
devices = _recursively_find_devices(args) | _recursively_find_devices(kwargs) | ||
yield from ensure_connected( | ||
*devices, mock=mock, timeout=timeout, force_reconnect=force_reconnect | ||
) | ||
yield from plan(*args, **kwargs) | ||
|
||
return plan_with_connected_devices | ||
|
||
|
||
ensure_devices_connected_decorator = make_decorator(ensure_devices_connected) |
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