Skip to content
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

Ophyd-async support now also register child devices. #9

Merged
merged 4 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "ophyd-registry"
version = "1.3.2"
version = "1.3.3"
authors = [
{ name="Mark Wolfman", email="[email protected]" },
]
Expand All @@ -19,7 +19,7 @@ dependencies = ["ophyd"]

[project.optional-dependencies]

dev = ["black", "isort", "pytest", "build", "twine", "flake8", "ruff", "pytest-mock", "caproto"]
dev = ["ophyd_async", "black", "isort", "pytest", "build", "twine", "flake8", "ruff", "pytest-mock", "caproto"]

[project.urls]
"Homepage" = "https://github.com/spc-group/ophyd-registry"
Expand Down
23 changes: 18 additions & 5 deletions src/ophydregistry/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import warnings
from collections import OrderedDict
from itertools import chain
from typing import Hashable, List, Mapping, Optional, Tuple, Sequence
from typing import Hashable, List, Mapping, Optional, Sequence, Tuple
from weakref import WeakSet, WeakValueDictionary

from ophyd import ophydobj
Expand Down Expand Up @@ -126,7 +126,11 @@ class Registry:
use_typhos: bool
keep_references: bool
_auto_register: bool
_valid_classes: Tuple[type] = (ophydobj.OphydObject, _AggregateSignalState, AsyncDevice)
_valid_classes: Tuple[type] = (
ophydobj.OphydObject,
_AggregateSignalState,
AsyncDevice,
)

# components: Sequence
_objects_by_name: Mapping
Expand Down Expand Up @@ -255,7 +259,9 @@ def pop_disconnected(self, timeout: float = 0.0) -> List:
timeout_reached = False
while not timeout_reached:
# Remove any connected devices for the running list
remaining = [dev for dev in remaining if not getattr(dev, "connected", True)]
remaining = [
dev for dev in remaining if not getattr(dev, "connected", True)
]
if len(remaining) == 0:
# All devices are connected, so just end early.
break
Expand Down Expand Up @@ -584,7 +590,14 @@ def register(

typhos.plugins.register_signal(component)
# Recusively register sub-components
sub_signals = getattr(component, "_signals", {})
for cpt_name, cpt in sub_signals.items():
if hasattr(component, "_signals"):
# Vanilla ophyd device
sub_signals = component._signals.items()
elif hasattr(component, "children"):
# Ophyd-async device
sub_signals = component.children()
else:
sub_signals = []
for cpt_name, cpt in sub_signals:
self.register(cpt)
return component
13 changes: 13 additions & 0 deletions src/ophydregistry/tests/test_instrument_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pytest
from ophyd import Device, EpicsMotor, sim
from ophyd_async.core import Device as AsyncDevice, soft_signal_rw

from ophydregistry import ComponentNotFound, MultipleComponentsFound, Registry

Expand Down Expand Up @@ -143,6 +144,18 @@ def test_find_component(registry):
result = registry.find(label="ion_chamber")


def test_find_async_children(registry):
"""Check that the child components of an async device get registered."""
class MyDevice(AsyncDevice):
def __init__(self, name):
self.signal = soft_signal_rw()
super().__init__(name=name)

device = MyDevice(name="m1")
registry.register(device)
assert registry.find(device.signal.name) is device.signal


def test_find_name_by_dot_notation(registry):
# Create a simulated component
cptA = sim.SynGauss(
Expand Down
Loading