Skip to content

Commit

Permalink
make OneOfEverythingDevice inherit StandardReadable not StandardDetector
Browse files Browse the repository at this point in the history
Remove explicit signal names in OneOfEverythingDevice
  • Loading branch information
jsouter committed Jan 7, 2025
1 parent c7159aa commit 42d1170
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 99 deletions.
88 changes: 28 additions & 60 deletions src/ophyd_async/testing/_one_of_everything.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@

from ophyd_async.core import (
Array1D,
DetectorController,
DetectorWriter,
Device,
DTypeScalar_co,
SignalR,
SignalRW,
StandardDetector,
StandardReadable,
StrictEnum,
Table,
soft_signal_r_and_setter,
Expand Down Expand Up @@ -62,55 +60,31 @@ def float_array_signal(
return soft_signal_rw(Array1D[dtype], value, name)


class DummyController(DetectorController):
def get_deadtime(self, exposure: float | None) -> float: ...

async def prepare(self, trigger_info): ...

async def arm(self) -> None: ...

async def wait_for_idle(self): ...

async def disarm(self): ...


class DummyWriter(DetectorWriter):
async def open(self, multiplier: int = 1):
return {}

def observe_indices_written(self, timeout: float = 10.0):
raise NotImplementedError()

async def get_indices_written(self) -> int:
return 0

def collect_stream_docs(self, indices_written: int):
raise NotImplementedError()

async def close(self) -> None: ...


class OneOfEverythingDevice(StandardDetector):
class OneOfEverythingDevice(StandardReadable):
# make a detector to test assert_configuration
def __init__(self, name=""):
self.int = soft_signal_rw(int, 1, name="int")
self.float = soft_signal_rw(float, 1.234, name="float")
self.str = soft_signal_rw(str, "test_string", name="str")
self.bool = soft_signal_rw(bool, True, name="bool")
self.enum = soft_signal_rw(ExampleEnum, ExampleEnum.B, name="enum")
self.int8a = int_array_signal(np.int8, name="int8a")
self.uint8a = int_array_signal(np.uint8, name="uint8a")
self.int16a = int_array_signal(np.int16, name="int16a")
self.uint16a = int_array_signal(np.uint16, name="uint16a")
self.int32a = int_array_signal(np.int32, name="int32a")
self.uint32a = int_array_signal(np.uint32, name="uint32a")
self.int64a = int_array_signal(np.int64, name="int64a")
self.uint64a = int_array_signal(np.uint64, name="uint64a")
self.float32a = float_array_signal(np.float32, name="float32a")
self.float64a = float_array_signal(np.float64, name="float64a")
self.stra = soft_signal_rw(Sequence[str], ["one", "two", "three"], name="stra")
self.int = soft_signal_rw(int, 1)
self.float = soft_signal_rw(float, 1.234)
self.str = soft_signal_rw(str, "test_string")
self.bool = soft_signal_rw(bool, True)
self.enum = soft_signal_rw(ExampleEnum, ExampleEnum.B)
self.int8a = int_array_signal(np.int8)
self.uint8a = int_array_signal(np.uint8)
self.int16a = int_array_signal(np.int16)
self.uint16a = int_array_signal(np.uint16)
self.int32a = int_array_signal(np.int32)
self.uint32a = int_array_signal(np.uint32)
self.int64a = int_array_signal(np.int64)
self.uint64a = int_array_signal(np.uint64)
self.float32a = float_array_signal(np.float32)
self.float64a = float_array_signal(np.float64)
self.stra = soft_signal_rw(
Sequence[str],
["one", "two", "three"],
)
self.enuma = soft_signal_rw(
Sequence[ExampleEnum], [ExampleEnum.A, ExampleEnum.C], name="enuma"
Sequence[ExampleEnum],
[ExampleEnum.A, ExampleEnum.C],
)
self.table = soft_signal_rw(
ExampleTable,
Expand All @@ -121,19 +95,13 @@ def __init__(self, name=""):
str=["Hello", "World", "Foo", "Bar"],
enum=[ExampleEnum.A, ExampleEnum.B, ExampleEnum.A, ExampleEnum.C],
),
name="table",
)
self.ndarray = soft_signal_rw(
np.ndarray, np.array(([1, 2, 3], [4, 5, 6])), name="ndarray"
)
signals = [sig for sig in self.__dict__.values() if isinstance(sig, SignalR)]
# add all signals to config
super().__init__(
controller=DummyController(),
writer=DummyWriter(),
config_sigs=signals,
name=name,
self.ndarray = soft_signal_rw(np.ndarray, np.array(([1, 2, 3], [4, 5, 6])))
# add all signals to configuration
self._read_config_funcs = tuple( # type: ignore
sig.read for sig in self.__dict__.values() if isinstance(sig, SignalR)
)
super().__init__(name)


async def _get_signal_values(child: Device) -> dict[SignalRW, Any]:
Expand Down
Loading

0 comments on commit 42d1170

Please sign in to comment.