From 19a1d84186f21d4f2eeae0a7afed5d07d542e4af Mon Sep 17 00:00:00 2001 From: appel_c Date: Wed, 14 May 2025 13:12:43 +0200 Subject: [PATCH] refactor(dxp): remove _default_read_attrs from base integration --- ophyd_devices/devices/dxp.py | 72 ++++++------------------------------ tests/test_dxp/test_dxp.py | 9 ----- 2 files changed, 12 insertions(+), 69 deletions(-) diff --git a/ophyd_devices/devices/dxp.py b/ophyd_devices/devices/dxp.py index 894ab4d..44c56d4 100644 --- a/ophyd_devices/devices/dxp.py +++ b/ophyd_devices/devices/dxp.py @@ -10,6 +10,16 @@ An example usage for a 4-element FalconX system. :: from ophyd_devices.devices.areadetector.plugins import HDF5Plugin_V35 as HDF5Plugin class FalconX4(Falcon): + + # Attributes needed to be set for the ADBase class + # Otherwise, ADBase will overwrite read_attrs and configuration_attrs + # and as a result a .read() will return an empty dictionary + # This is a shortcoming of the ADBase class and has to be fixed + # on the highest level of the class hierarchy, one may also include specific signals of the Falcon + # in the read_attrs and configuration_attrs, i.e. elapsed_real_time, elapsed_live_time, etc. + _default_read_attrs = ("dxp1", "dxp2", "dxp3", "dxp4", "mca1", "mca2", "mca3", "mca4", "hdf") + _default_configuration_attrs = ("dxp1", "dxp2", "dxp3", "dxp4", "mca1", "mca2", "mca3", "mca4", "hdf") + # DXP parameters dxp1 = Cpt(EpicsDXPFalcon, "dxp1:") dxp2 = Cpt(EpicsDXPFalcon, "dxp2:") @@ -52,7 +62,7 @@ __all__ = ("EpicsMCARecord", "EpicsDXP", "EpicsDXPFalcon", "Falcon", "Mercury", # pylint: disable=protected-access -class ROIFalcon(ROI): +class PSIROI(ROI): """ROI for FalconX DXP system with proper Kind settings.""" # normal Components @@ -77,7 +87,7 @@ def add_rois(range_, **kwargs): raise ValueError("roi must be in the set [0,31]") attr = f"roi{roi}" - defn[attr] = (ROIFalcon, f".R{roi}", kwargs) + defn[attr] = (PSIROI, f".R{roi}", kwargs) return defn @@ -210,34 +220,6 @@ class EpicsDxpFalconMapping(EpicsDXPMapping): class Falcon(EpicsDXPFalconMultiElementSystem, EpicsDxpFalconMapping, ADBase): """Falcon base device""" - _default_read_attrs = ( - ADBase._default_read_attrs - + ( - EpicsDXPFalconMultiElementSystem._default_read_attrs - if EpicsDXPFalconMultiElementSystem._default_read_attrs - else () - ) - + ( - EpicsDxpFalconMapping._default_read_attrs - if EpicsDxpFalconMapping._default_read_attrs - else () - ) - + ("port_name",) - ) - _default_configuration_attrs = ( - ADBase._default_configuration_attrs - + ( - EpicsDXPFalconMultiElementSystem._default_configuration_attrs - if EpicsDXPFalconMultiElementSystem._default_configuration_attrs - else () - ) - + ( - EpicsDxpFalconMapping._default_configuration_attrs - if EpicsDxpFalconMapping._default_configuration_attrs - else () - ) - ) - # attribute required by ADBase port_name = ADCpt(EpicsSignalRO, "Asyn.PORT", string=True) @@ -260,17 +242,6 @@ class EpicsDXPMultiElementSystem(_EpicsDXPMultiElementSystem): class Mercury(EpicsDXPMultiElementSystem, ADBase): """Mercury base device""" - _default_read_attrs = ADBase._default_read_attrs + ( - EpicsDXPMultiElementSystem._default_read_attrs - if EpicsDXPMultiElementSystem._default_read_attrs - else () + ("port_name",) - ) - _default_configuration_attrs = ADBase._default_configuration_attrs + ( - EpicsDXPMultiElementSystem._default_configuration_attrs - if EpicsDXPMultiElementSystem._default_configuration_attrs - else () - ) - # attribute required by ADBase port_name = ADCpt(EpicsSignalRO, "Asyn.PORT", string=True) @@ -278,24 +249,5 @@ class Mercury(EpicsDXPMultiElementSystem, ADBase): class xMAP(EpicsDXPMultiElementSystem, EpicsDXPMapping, ADBase): """xMAP base device""" - _default_read_attrs = ADBase._default_read_attrs + ( - EpicsDXPMultiElementSystem._default_read_attrs - if EpicsDXPMultiElementSystem._default_read_attrs - else ( - () + EpicsDXPMapping._default_read_attrs - if EpicsDXPMapping._default_read_attrs - else () + ("port_name",) - ) - ) - _default_configuration_attrs = ADBase._default_configuration_attrs + ( - EpicsDXPMultiElementSystem._default_configuration_attrs - if EpicsDXPMultiElementSystem._default_configuration_attrs - else ( - () + EpicsDXPMapping._default_configuration_attrs - if EpicsDXPMapping._default_configuration_attrs - else () - ) - ) - # attribute required by ADBase port_name = ADCpt(EpicsSignalRO, "Asyn.PORT", string=True) diff --git a/tests/test_dxp/test_dxp.py b/tests/test_dxp/test_dxp.py index 52f0cd5..a90d752 100644 --- a/tests/test_dxp/test_dxp.py +++ b/tests/test_dxp/test_dxp.py @@ -86,9 +86,6 @@ def test_falcon(mock_falcon): assert isinstance(mock_falcon, EpicsDxpFalconMapping) assert isinstance(mock_falcon, ADBase) - assert mock_falcon.read_attrs == ["port_name"] - assert mock_falcon.configuration_attrs == [] - assert mock_falcon.hints == {"fields": []} assert mock_falcon.mca1.rois.roi0.read_attrs == ["count", "net_count"] @@ -111,9 +108,6 @@ def test_xmap(mock_xmap): assert isinstance(mock_xmap, EpicsDXPMultiElementSystem) assert isinstance(mock_xmap, ADBase) - assert mock_xmap.read_attrs == ["port_name"] - assert mock_xmap.configuration_attrs == [] - def test_mercury(mock_mercury): """Test the Mercury device.""" @@ -124,6 +118,3 @@ def test_mercury(mock_mercury): assert isinstance(mock_mercury, EpicsDXPMultiElementSystem) # assert isinstance(mock_mercury, EpicsDXPMapping) # Not sure why this fails assert isinstance(mock_mercury, ADBase) - - assert mock_mercury.read_attrs == ["port_name"] - assert mock_mercury.configuration_attrs == []