Skip to content

Commit

Permalink
detector demo device is now a standard readable. Tango devices can au…
Browse files Browse the repository at this point in the history
…tomatically 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.
  • Loading branch information
burkeds committed Oct 7, 2024
1 parent 632eccc commit b05024e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/ophyd_async/tango/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
AttributeProxy,
CommandProxy,
TangoSignalBackend,
__tango_signal_auto,
ensure_proper_executor,
get_dtype_extended,
get_python_type,
Expand All @@ -15,7 +16,6 @@
infer_python_type,
infer_signal_character,
make_backend,
tango_signal_auto,
tango_signal_r,
tango_signal_rw,
tango_signal_w,
Expand All @@ -37,7 +37,7 @@
"AttributeProxy",
"CommandProxy",
"ensure_proper_executor",
"tango_signal_auto",
"__tango_signal_auto",
"tango_signal_r",
"tango_signal_rw",
"tango_signal_w",
Expand Down
8 changes: 6 additions & 2 deletions src/ophyd_async/tango/base_devices/_base_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
24 changes: 10 additions & 14 deletions src/ophyd_async/tango/demo/_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/ophyd_async/tango/signal/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -35,5 +35,5 @@
"tango_signal_rw",
"tango_signal_w",
"tango_signal_x",
"tango_signal_auto",
"__tango_signal_auto",
)
2 changes: 1 addition & 1 deletion src/ophyd_async/tango/signal/_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion tests/tango/test_base_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
10 changes: 5 additions & 5 deletions tests/tango/test_tango_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit b05024e

Please sign in to comment.