Skip to content

Commit

Permalink
cleaned up after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Apr 17, 2024
1 parent c4d8e04 commit 496d857
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
21 changes: 9 additions & 12 deletions src/ophyd_async/epics/pvi/pvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ def _split_subscript(tp: T) -> Union[Tuple[Any, Tuple[Any]], Tuple[T, None]]:
return tp, None


def _strip_union(field: Union[Union[T], T]) -> T:
def _strip_union(field: Union[Union[T], T]) -> Tuple[T, bool]:
is_optional = False
if get_origin(field) is Union:
args = get_args(field)
is_optional = type(None) in args
for field in args:
if field is not type(None):
break
for arg in args:
if arg is not type(None):
return arg, is_optional
return field, is_optional


Expand Down Expand Up @@ -130,7 +131,7 @@ def _parse_type(
):
if common_device_type:
# pre-defined type
device_cls = _strip_union(common_device_type)
device_cls, _ = _strip_union(common_device_type)
is_device_vector, device_cls = _strip_device_vector(device_cls)
device_cls, device_args = _split_subscript(device_cls)
assert issubclass(device_cls, Device)
Expand Down Expand Up @@ -164,7 +165,7 @@ def _sim_common_blocks(device: Device, stripped_type: Optional[Type] = None):
)

for device_name, device_cls in sub_devices:
device_cls = _strip_union(device_cls)
device_cls, _ = _strip_union(device_cls)
is_device_vector, device_cls = _strip_device_vector(device_cls)
device_cls, device_args = _split_subscript(device_cls)
assert issubclass(device_cls, Device)
Expand All @@ -189,8 +190,7 @@ def _sim_common_blocks(device: Device, stripped_type: Optional[Type] = None):
if is_signal:
sub_device = device_cls(SimSignalBackend(signal_dtype, device_name))
else:
sub_device = device_cls()

sub_device = getattr(device, device_name, device_cls())
_sim_common_blocks(sub_device, stripped_type=device_cls)

setattr(device, device_name, sub_device)
Expand Down Expand Up @@ -225,10 +225,7 @@ async def _get_pvi_entries(entry: PVIEntry, timeout=DEFAULT_TIMEOUT):
if is_signal:
device = _pvi_mapping[frozenset(pva_entries.keys())](signal_dtype, *pvs)
else:
if hasattr(entry.device, sub_name):
device = getattr(entry.device, sub_name)
else:
device = device_type()
device = getattr(entry.device, sub_name, device_type())

sub_entry = PVIEntry(
device=device, common_device_type=device_type, sub_entries={}
Expand Down
2 changes: 1 addition & 1 deletion src/ophyd_async/panda/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._common_panda import (
from ._common_blocks import (
CommonPandaBlocks,
DataBlock,
PcapBlock,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ophyd_async/panda/_hdf_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from ophyd_async.epics.pvi import create_children_from_annotations, fill_pvi_entries

from ._common_panda import CommonPandaBlocks
from ._common_blocks import CommonPandaBlocks
from ._panda_controller import PandaPcapController
from .writers._hdf_writer import PandaHDFWriter

Expand Down
2 changes: 1 addition & 1 deletion tests/panda/test_panda_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ophyd_async.epics.pvi import fill_pvi_entries
from ophyd_async.epics.signal import epics_signal_rw
from ophyd_async.panda import CommonPandaBlocks, TimeUnits
from ophyd_async.panda._common_panda import DataBlock
from ophyd_async.panda._common_blocks import DataBlock
from ophyd_async.panda._utils import phase_sorter


Expand Down

0 comments on commit 496d857

Please sign in to comment.