Skip to content

Commit

Permalink
move to async device
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-dot committed Jul 2, 2024
1 parent 956b1ec commit 8ed8301
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/blueapi/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from bluesky.run_engine import RunEngine
from dodal.utils import make_all_devices
from ophyd_async.core import Device as AsyncDevice
from ophyd_async.core import NotConnected
from pydantic import create_model
from pydantic.fields import FieldInfo, ModelField
Expand All @@ -28,7 +29,7 @@

LOGGER = logging.getLogger(__name__)

DevicesDict = dict[str, Device]
DevicesDict = dict[str, AsyncDevice]


@dataclass
Expand All @@ -43,7 +44,7 @@ class BlueskyContext:
default_factory=lambda: RunEngine(context_managers=[])
)
plans: dict[str, Plan] = field(default_factory=dict)
devices: dict[str, Device] = field(default_factory=dict)
devices: DevicesDict = field(default_factory=dict)

plan_functions: dict[str, PlanGenerator] = field(default_factory=dict)

Expand Down Expand Up @@ -113,7 +114,10 @@ def with_dodal_module(self, module: ModuleType, **kwargs) -> None:

# for non-lazy devices, we instantiate them
# eager_devices = devices.items().filter(lambda x: not x.lazy)
eager_devices = {k: v for k, v in devices.items() if not v.lazy}
eager_devices = {
k: v for k, v in devices.items()
if not v.lazy
}

for device in eager_devices.values():
self.register_device(device)
Expand Down Expand Up @@ -154,7 +158,7 @@ def my_plan(a: int, b: str):
self.plan_functions[plan.__name__] = plan
return plan

def register_device(self, device: Device, name: str | None = None) -> None:
def register_device(self, device: AsyncDevice, name: str | None = None) -> None:
"""
Register an device in the context. The device needs to be registered with a
name. If the device is Readable, Movable or Flyable it has a `name`
Expand Down

0 comments on commit 8ed8301

Please sign in to comment.