From b05024e1fcee03317afb3957e2eb0c2e62858a74 Mon Sep 17 00:00:00 2001 From: Devin Burke Date: Mon, 7 Oct 2024 11:19:53 +0200 Subject: [PATCH] detector demo device is now a standard readable. Tango devices can automatically infer their signals but the tango device server does not necessarily carry information about subdevices. Individual device servers should not have sub-devices but tango device databases can. This may be the subject of a future pr. Made tango_signal_auto private to discourage use. --- src/ophyd_async/tango/__init__.py | 4 ++-- .../tango/base_devices/_base_device.py | 8 +++++-- src/ophyd_async/tango/demo/_detector.py | 24 ++++++++----------- src/ophyd_async/tango/signal/__init__.py | 4 ++-- src/ophyd_async/tango/signal/_signal.py | 2 +- tests/tango/test_base_device.py | 1 - tests/tango/test_tango_signals.py | 10 ++++---- 7 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/ophyd_async/tango/__init__.py b/src/ophyd_async/tango/__init__.py index e81278fd91..5b45a067c4 100644 --- a/src/ophyd_async/tango/__init__.py +++ b/src/ophyd_async/tango/__init__.py @@ -7,6 +7,7 @@ AttributeProxy, CommandProxy, TangoSignalBackend, + __tango_signal_auto, ensure_proper_executor, get_dtype_extended, get_python_type, @@ -15,7 +16,6 @@ infer_python_type, infer_signal_character, make_backend, - tango_signal_auto, tango_signal_r, tango_signal_rw, tango_signal_w, @@ -37,7 +37,7 @@ "AttributeProxy", "CommandProxy", "ensure_proper_executor", - "tango_signal_auto", + "__tango_signal_auto", "tango_signal_r", "tango_signal_rw", "tango_signal_w", diff --git a/src/ophyd_async/tango/base_devices/_base_device.py b/src/ophyd_async/tango/base_devices/_base_device.py index 5e531709e5..4db9d27991 100644 --- a/src/ophyd_async/tango/base_devices/_base_device.py +++ b/src/ophyd_async/tango/base_devices/_base_device.py @@ -14,7 +14,11 @@ DeviceVector, Signal, ) -from ophyd_async.tango.signal import TangoSignalBackend, make_backend, tango_signal_auto +from ophyd_async.tango.signal import ( + TangoSignalBackend, + __tango_signal_auto, + make_backend, +) from tango import DeviceProxy as DeviceProxy from tango.asyncio import DeviceProxy as AsyncDeviceProxy @@ -193,7 +197,7 @@ async def _fill_proxy_entries(device: TangoDevice): if name not in children: full_trl = f"{proxy_trl}/{name}" try: - auto_signal = await tango_signal_auto( + auto_signal = await __tango_signal_auto( trl=full_trl, device_proxy=device.proxy ) setattr(device, name, auto_signal) diff --git a/src/ophyd_async/tango/demo/_detector.py b/src/ophyd_async/tango/demo/_detector.py index fc53e48dcf..61025c18c7 100644 --- a/src/ophyd_async/tango/demo/_detector.py +++ b/src/ophyd_async/tango/demo/_detector.py @@ -3,31 +3,27 @@ from ophyd_async.core import ( AsyncStatus, DeviceVector, + StandardReadable, ) -from ophyd_async.tango import TangoReadable from ._counter import TangoCounter from ._mover import TangoMover -class TangoDetector(TangoReadable): - counters: DeviceVector[TangoCounter] - mover: TangoMover - - def __init__(self, trl: str, mover_trl: str, counter_trls: list[str], name=""): - super().__init__(trl, name=name) - - # If devices are inferred from type hints, they will be created automatically - # during init. If they are created automatically, their trl must be set before - # they are connected. - self.mover.set_trl(mover_trl) - for i, c_trl in enumerate(counter_trls): - self.counters[i + 1] = TangoCounter(c_trl) +class TangoDetector(StandardReadable): + def __init__(self, mover_trl: str, counter_trls: list[str], name=""): + # A detector device may be composed of tango sub-devices + self.mover = TangoMover(mover_trl) + self.counters = DeviceVector( + {i + 1: TangoCounter(c_trl) for i, c_trl in enumerate(counter_trls)} + ) # Define the readables for TangoDetector # DeviceVectors are incompatible with AsyncReadable. Ignore until fixed. self.add_readables([self.counters, self.mover]) # type: ignore + super().__init__(name=name) + def set(self, value): return self.mover.set(value) diff --git a/src/ophyd_async/tango/signal/__init__.py b/src/ophyd_async/tango/signal/__init__.py index a285e34c03..8923718b6a 100644 --- a/src/ophyd_async/tango/signal/__init__.py +++ b/src/ophyd_async/tango/signal/__init__.py @@ -1,8 +1,8 @@ from ._signal import ( + __tango_signal_auto, infer_python_type, infer_signal_character, make_backend, - tango_signal_auto, tango_signal_r, tango_signal_rw, tango_signal_w, @@ -35,5 +35,5 @@ "tango_signal_rw", "tango_signal_w", "tango_signal_x", - "tango_signal_auto", + "__tango_signal_auto", ) diff --git a/src/ophyd_async/tango/signal/_signal.py b/src/ophyd_async/tango/signal/_signal.py index b4d9f92bca..f9274842d5 100644 --- a/src/ophyd_async/tango/signal/_signal.py +++ b/src/ophyd_async/tango/signal/_signal.py @@ -128,7 +128,7 @@ def tango_signal_x( return SignalX(backend, timeout=timeout, name=name) -async def tango_signal_auto( +async def __tango_signal_auto( datatype: type[T] | None = None, *, trl: str, diff --git a/tests/tango/test_base_device.py b/tests/tango/test_base_device.py index c0b79d425e..3c23461f99 100644 --- a/tests/tango/test_base_device.py +++ b/tests/tango/test_base_device.py @@ -377,7 +377,6 @@ async def test_with_bluesky(tango_test_device): async def test_tango_demo(demo_test_context): with demo_test_context: detector = TangoDetector( - trl="", name="detector", mover_trl="demo/motor/1", counter_trls=["demo/counter/1", "demo/counter/2"], diff --git a/tests/tango/test_tango_signals.py b/tests/tango/test_tango_signals.py index 330e680a09..40a5b591aa 100644 --- a/tests/tango/test_tango_signals.py +++ b/tests/tango/test_tango_signals.py @@ -14,7 +14,7 @@ from ophyd_async.core import SignalBackend, SignalR, SignalRW, SignalW, SignalX, T from ophyd_async.tango import ( TangoSignalBackend, - tango_signal_auto, + __tango_signal_auto, tango_signal_r, tango_signal_rw, tango_signal_w, @@ -646,7 +646,7 @@ async def test_tango_signal_auto_attrs( timeout = 0.2 async def _test_signal(dtype, proxy): - signal = await tango_signal_auto( + signal = await __tango_signal_auto( datatype=dtype, trl=source, device_proxy=proxy, @@ -720,7 +720,7 @@ async def test_tango_signal_auto_cmds( timeout = 0.2 async def _test_signal(dtype, proxy): - signal = await tango_signal_auto( + signal = await __tango_signal_auto( datatype=dtype, trl=source, device_proxy=proxy, @@ -751,7 +751,7 @@ async def _test_signal(dtype, proxy): @pytest.mark.parametrize("use_proxy", [True, False]) async def test_tango_signal_auto_cmds_void(tango_test_device: str, use_proxy: bool): proxy = await DeviceProxy(tango_test_device) if use_proxy else None - signal = await tango_signal_auto( + signal = await __tango_signal_auto( datatype=None, trl=tango_test_device + "/" + "clear", device_proxy=proxy, @@ -767,7 +767,7 @@ async def test_tango_signal_auto_cmds_void(tango_test_device: str, use_proxy: bo async def test_tango_signal_auto_badtrl(tango_test_device: str): proxy = await DeviceProxy(tango_test_device) with pytest.raises(RuntimeError) as exc_info: - await tango_signal_auto( + await __tango_signal_auto( datatype=None, trl=tango_test_device + "/" + "badtrl", device_proxy=proxy,