From f6c576f57ea224402714de9e97190abfe419e264 Mon Sep 17 00:00:00 2001 From: vegano1 Date: Wed, 18 Sep 2024 13:41:55 -0400 Subject: [PATCH] feat(api): Update namespace for byonoy_devices library version 2024.09.0. --- .../drivers/absorbance_reader/async_byonoy.py | 58 ++++++------- .../drivers/absorbance_reader/hid_protocol.py | 86 +++++++++---------- .../drivers/absorbance_reader/test_driver.py | 60 +++++++------ 3 files changed, 92 insertions(+), 112 deletions(-) diff --git a/api/src/opentrons/drivers/absorbance_reader/async_byonoy.py b/api/src/opentrons/drivers/absorbance_reader/async_byonoy.py index 50f688206d0..f2c32e21748 100644 --- a/api/src/opentrons/drivers/absorbance_reader/async_byonoy.py +++ b/api/src/opentrons/drivers/absorbance_reader/async_byonoy.py @@ -74,13 +74,13 @@ async def create( loop = loop or asyncio.get_running_loop() executor = ThreadPoolExecutor(max_workers=1) - import pybyonoy_device_library as byonoy # type: ignore[import-not-found] + import byonoy_devices as byonoy # type: ignore[import-not-found] interface: AbsProtocol = byonoy device_sn = cls.serial_number_from_port(usb_port.name) found: List[AbsProtocol.Device] = await loop.run_in_executor( - executor=executor, func=byonoy.byonoy_available_devices + executor=executor, func=byonoy.available_devices ) device = cls.match_device_with_sn(device_sn, found) @@ -123,7 +123,7 @@ async def open(self) -> bool: err, device_handle = await self._loop.run_in_executor( executor=self._executor, - func=partial(self._interface.byonoy_open_device, self._device), + func=partial(self._interface.open_device, self._device), ) self._raise_if_error(err.name, f"Error opening device: {err}") self._device_handle = device_handle @@ -134,7 +134,7 @@ async def close(self) -> None: handle = self._verify_device_handle() await self._loop.run_in_executor( executor=self._executor, - func=partial(self._interface.byonoy_free_device, handle), + func=partial(self._interface.free_device, handle), ) self._device_handle = None @@ -145,7 +145,7 @@ async def is_open(self) -> bool: handle = self._verify_device_handle() return await self._loop.run_in_executor( executor=self._executor, - func=partial(self._interface.byonoy_device_open, handle), + func=partial(self._interface.device_open, handle), ) async def get_device_information(self) -> Dict[str, str]: @@ -153,7 +153,7 @@ async def get_device_information(self) -> Dict[str, str]: handle = self._verify_device_handle() err, device_info = await self._loop.run_in_executor( executor=self._executor, - func=partial(self._interface.byonoy_get_device_information, handle), + func=partial(self._interface.get_device_information, handle), ) self._raise_if_error(err.name, f"Error getting device information: {err}") serial_match = SERIAL_PARSER.match(device_info.sn) @@ -172,7 +172,7 @@ async def get_device_status(self) -> AbsorbanceReaderDeviceState: handle = self._verify_device_handle() err, status = await self._loop.run_in_executor( executor=self._executor, - func=partial(self._interface.byonoy_get_device_status, handle), + func=partial(self._interface.get_device_status, handle), ) self._raise_if_error(err.name, f"Error getting device status: {err}") return self.convert_device_state(status.name) @@ -184,11 +184,9 @@ async def update_firmware(self, firmware_file_path: str) -> Tuple[bool, str]: return False, f"Firmware file not found: {firmware_file_path}" err = await self._loop.run_in_executor( executor=self._executor, - func=partial( - self._interface.byonoy_update_device, handle, firmware_file_path - ), + func=partial(self._interface.update_device, handle, firmware_file_path), ) - if err.name != "BYONOY_ERROR_NO_ERROR": + if err.name != "NO_ERROR": return False, f"Byonoy update failed with error: {err}" return True, "" @@ -197,7 +195,7 @@ async def get_device_uptime(self) -> int: handle = self._verify_device_handle() err, uptime = await self._loop.run_in_executor( executor=self._executor, - func=partial(self._interface.byonoy_get_device_uptime, handle), + func=partial(self._interface.get_device_uptime, handle), ) self._raise_if_error(err.name, "Error getting device uptime: ") return uptime @@ -207,7 +205,7 @@ async def get_lid_status(self) -> AbsorbanceReaderLidStatus: handle = self._verify_device_handle() err, lid_info = await self._loop.run_in_executor( executor=self._executor, - func=partial(self._interface.byonoy_get_device_parts_aligned, handle), + func=partial(self._interface.get_device_parts_aligned, handle), ) self._raise_if_error(err.name, f"Error getting lid status: {err}") return ( @@ -219,9 +217,7 @@ async def get_supported_wavelengths(self) -> list[int]: handle = self._verify_device_handle() err, wavelengths = await self._loop.run_in_executor( executor=self._executor, - func=partial( - self._interface.byonoy_abs96_get_available_wavelengths, handle - ), + func=partial(self._interface.abs96_get_available_wavelengths, handle), ) self._raise_if_error(err.name, "Error getting available wavelengths: ") self._supported_wavelengths = wavelengths @@ -233,9 +229,9 @@ async def get_measurement(self) -> List[List[float]]: assert ( self._current_config is not None ), "Cannot get measurement without initializing." - measure_func: Any = self._interface.byonoy_abs96_single_measure + measure_func: Any = self._interface.abs96_single_measure if isinstance(self._current_config, AbsProtocol.MultiMeasurementConfig): - measure_func = self._interface.byonoy_abs96_multiple_measure + measure_func = self._interface.abs96_multiple_measure err, measurements = await self._loop.run_in_executor( executor=self._executor, func=partial( @@ -252,7 +248,7 @@ async def get_plate_presence(self) -> AbsorbanceReaderPlatePresence: handle = self._verify_device_handle() err, presence = await self._loop.run_in_executor( executor=self._executor, - func=partial(self._interface.byonoy_get_device_slot_status, handle), + func=partial(self._interface.get_device_slot_status, handle), ) self._raise_if_error(err.name, f"Error getting slot status: {err}") return self.convert_plate_presence(presence.name) @@ -260,9 +256,7 @@ async def get_plate_presence(self) -> AbsorbanceReaderPlatePresence: def _get_supported_wavelengths(self) -> List[int]: handle = self._verify_device_handle() wavelengths: List[int] - err, wavelengths = self._interface.byonoy_abs96_get_available_wavelengths( - handle - ) + err, wavelengths = self._interface.abs96_get_available_wavelengths(handle) self._raise_if_error(err.name, f"Error getting available wavelengths: {err}") self._supported_wavelengths = wavelengths return wavelengths @@ -270,13 +264,9 @@ def _get_supported_wavelengths(self) -> List[int]: def _initialize_measurement(self, conf: MeasurementConfig) -> None: handle = self._verify_device_handle() if isinstance(conf, AbsProtocol.SingleMeasurementConfig): - err = self._interface.byonoy_abs96_initialize_single_measurement( - handle, conf - ) + err = self._interface.abs96_initialize_single_measurement(handle, conf) else: - err = self._interface.byonoy_abs96_initialize_multiple_measurement( - handle, conf - ) + err = self._interface.abs96_initialize_multiple_measurement(handle, conf) self._raise_if_error(err.name, f"Error initializing measurement: {err}") self._current_config = conf @@ -292,11 +282,11 @@ def _initialize( conf: MeasurementConfig if set(wavelengths).issubset(self._supported_wavelengths): if mode == ABSMeasurementMode.SINGLE: - conf = self._interface.ByonoyAbs96SingleMeasurementConfig() + conf = self._interface.Abs96SingleMeasurementConfig() conf.sample_wavelength = wavelengths[0] or 0 conf.reference_wavelength = reference_wavelength or 0 else: - conf = self._interface.ByonoyAbs96MultipleMeasurementConfig() + conf = self._interface.Abs96MultipleMeasurementConfig() conf.sample_wavelengths = wavelengths else: raise ValueError( @@ -328,12 +318,12 @@ def _raise_if_error( msg: str = "Error occurred: ", ) -> None: if err_name in [ - "BYONOY_ERROR_DEVICE_CLOSED", - "BYONOY_ERROR_DEVICE_COMMUNICATION_FAILURE", - "BYONOY_ERROR_UNSUPPORTED_OPERATION", + "DEVICE_CLOSED", + "DEVICE_COMMUNICATION_FAILURE", + "UNSUPPORTED_OPERATION", ]: raise AbsorbanceReaderDisconnectedError(self._device.sn) - if err_name != "BYONOY_ERROR_NO_ERROR": + if err_name != "NO_ERROR": raise RuntimeError(msg, err_name) @staticmethod diff --git a/api/src/opentrons/drivers/absorbance_reader/hid_protocol.py b/api/src/opentrons/drivers/absorbance_reader/hid_protocol.py index d05059889ae..c418a652130 100644 --- a/api/src/opentrons/drivers/absorbance_reader/hid_protocol.py +++ b/api/src/opentrons/drivers/absorbance_reader/hid_protocol.py @@ -13,28 +13,28 @@ Response = TypeVar("Response") ErrorCodeNames = Literal[ - "BYONOY_ERROR_NO_ERROR", - "BYONOY_ERROR_UNKNOWN_ERROR", - "BYONOY_ERROR_DEVICE_CLOSED", - "BYONOY_ERROR_INVALID_ARGUMENT", - "BYONOY_ERROR_NO_MEMORY", - "BYONOY_ERROR_UNSUPPORTED_OPERATION", - "BYONOY_ERROR_DEVICE_COMMUNICATION_FAILURE", - "BYONOY_ERROR_DEVICE_OPERATION_FAILED", - "BYONOY_ERROR_DEVICE_OPEN_PREFIX", - "BYONOY_ERROR_DEVICE_NOT_FOUND", - "BYONOY_ERROR_DEVICE_TOO_NEW", - "BYONOY_ERROR_DEVICE_ALREADY_OPEN", - "BYONOY_ERROR_FIRMWARE_UPDATE_ERROR_PREFIX", - "BYONOY_ERROR_FIRMWARE_UPDATE_FILE_NOT_FOUND", - "BYONOY_ERROR_FIRMWARE_UPDATE_FILE_NOT_VALID", - "BYONOY_ERROR_FIRMWARE_UPDATE_FAILED", - "BYONOY_ERROR_FILE_ERROR_PREFIX", - "BYONOY_ERROR_FILE_WRITE_ERROR", - "BYONOY_ERROR_MEASUTEMNT_ERROR_PREFIX", - "BYONOY_ERROR_MEASUTEMNT_SLOT_NOT_EMPTY", - "BYONOY_ERROR_NOT_INITIALIZED", - "BYONOY_ERROR_INTERNAL", + "NO_ERROR", + "UNKNOWN_ERROR", + "DEVICE_CLOSED", + "INVALID_ARGUMENT", + "NO_MEMORY", + "UNSUPPORTED_OPERATION", + "DEVICE_COMMUNICATION_FAILURE", + "DEVICE_OPERATION_FAILED", + "DEVICE_OPEN_PREFIX", + "DEVICE_NOT_FOUND", + "DEVICE_TOO_NEW", + "DEVICE_ALREADY_OPEN", + "FIRMWARE_UPDATE_ERROR_PREFIX", + "FIRMWARE_UPDATE_FILE_NOT_FOUND", + "FIRMWARE_UPDATE_FILE_NOT_VALID", + "FIRMWARE_UPDATE_FAILED", + "FILE_ERROR_PREFIX", + "FILE_WRITE_ERROR", + "MEASUTEMNT_ERROR_PREFIX", + "MEASUTEMNT_SLOT_NOT_EMPTY", + "NOT_INITIALIZED", + "INTERNAL", ] SlotStateNames = Literal[ @@ -91,75 +91,67 @@ class DeviceState(Protocol): name: DeviceStateNames value: int - def ByonoyAbs96SingleMeasurementConfig(self) -> SingleMeasurementConfig: + def Abs96SingleMeasurementConfig(self) -> SingleMeasurementConfig: ... - def ByonoyAbs96MultipleMeasurementConfig(self) -> MultiMeasurementConfig: + def Abs96MultipleMeasurementConfig(self) -> MultiMeasurementConfig: ... - def byonoy_open_device(self, device: Device) -> Tuple[ErrorCode, int]: + def open_device(self, device: Device) -> Tuple[ErrorCode, int]: ... - def byonoy_free_device(self, device_handle: int) -> Tuple[ErrorCode, bool]: + def free_device(self, device_handle: int) -> Tuple[ErrorCode, bool]: ... - def byonoy_device_open(self, device_handle: int) -> bool: + def device_open(self, device_handle: int) -> bool: ... - def byonoy_get_device_information( + def get_device_information( self, device_handle: int ) -> Tuple[ErrorCode, DeviceInfo]: ... - def byonoy_update_device( - self, device_handle: int, firmware_file_path: str - ) -> ErrorCode: + def update_device(self, device_handle: int, firmware_file_path: str) -> ErrorCode: ... - def byonoy_get_device_status( - self, device_handle: int - ) -> Tuple[ErrorCode, DeviceState]: + def get_device_status(self, device_handle: int) -> Tuple[ErrorCode, DeviceState]: ... - def byonoy_get_device_uptime(self, device_handle: int) -> Tuple[ErrorCode, int]: + def get_device_uptime(self, device_handle: int) -> Tuple[ErrorCode, int]: ... - def byonoy_get_device_slot_status( - self, device_handle: int - ) -> Tuple[ErrorCode, SlotState]: + def get_device_slot_status(self, device_handle: int) -> Tuple[ErrorCode, SlotState]: ... - def byonoy_get_device_parts_aligned( - self, device_handle: int - ) -> Tuple[ErrorCode, bool]: + def get_device_parts_aligned(self, device_handle: int) -> Tuple[ErrorCode, bool]: ... - def byonoy_abs96_get_available_wavelengths( + def abs96_get_available_wavelengths( self, device_handle: int ) -> Tuple[ErrorCode, List[int]]: ... - def byonoy_abs96_initialize_single_measurement( + def abs96_initialize_single_measurement( self, device_handle: int, conf: SingleMeasurementConfig ) -> ErrorCode: ... - def byonoy_abs96_initialize_multiple_measurement( + def abs96_initialize_multiple_measurement( self, device_handle: int, conf: MultiMeasurementConfig ) -> ErrorCode: ... - def byonoy_abs96_single_measure( + def abs96_single_measure( self, device_handle: int, conf: SingleMeasurementConfig ) -> Tuple[ErrorCode, List[float]]: ... - def byonoy_abs96_multiple_measure( + def abs96_multiple_measure( self, device_handle: int, conf: MultiMeasurementConfig ) -> Tuple[ErrorCode, List[List[float]]]: ... - def byonoy_available_devices(self) -> List[Device]: + def available_devices(self) -> List[Device]: ... diff --git a/api/tests/opentrons/drivers/absorbance_reader/test_driver.py b/api/tests/opentrons/drivers/absorbance_reader/test_driver.py index 5fe71d2763c..685dcbd2150 100644 --- a/api/tests/opentrons/drivers/absorbance_reader/test_driver.py +++ b/api/tests/opentrons/drivers/absorbance_reader/test_driver.py @@ -24,8 +24,8 @@ def mock_device() -> MagicMock: class MockErrorCode(Enum): - BYONOY_ERROR_NO_ERROR = "no_error" - BYONOY_ERROR = "error" + NO_ERROR = "no_error" + ERROR = "error" @pytest.fixture @@ -53,20 +53,20 @@ async def test_driver_connect_disconnect( mock_interface: MagicMock, driver: AbsorbanceReaderDriver, ) -> None: - mock_interface.byonoy_open_device.return_value = ( - MockErrorCode.BYONOY_ERROR_NO_ERROR, + mock_interface.open_device.return_value = ( + MockErrorCode.NO_ERROR, 1, ) assert not await driver.is_connected() await driver.connect() - mock_interface.byonoy_open_device.assert_called_once() + mock_interface.open_device.assert_called_once() assert await driver.is_connected() assert driver._connection._verify_device_handle() assert driver._connection._device_handle == 1 - mock_interface.byonoy_free_device.return_value = MockErrorCode.BYONOY_ERROR_NO_ERROR + mock_interface.free_device.return_value = MockErrorCode.NO_ERROR await driver.disconnect() assert not await driver.is_connected() @@ -83,14 +83,14 @@ async def test_driver_get_device_info( DEVICE_INFO.sn = "SN: BYOMAA00013 REF: DE MAA 001" DEVICE_INFO.version = "Absorbance V1.0.2 2024-04-18" - mock_interface.byonoy_get_device_information.return_value = ( - MockErrorCode.BYONOY_ERROR_NO_ERROR, + mock_interface.get_device_information.return_value = ( + MockErrorCode.NO_ERROR, DEVICE_INFO, ) info = await connected_driver.get_device_info() - mock_interface.byonoy_get_device_information.assert_called_once() + mock_interface.get_device_information.assert_called_once() assert info == {"serial": "BYOMAA00013", "model": "ABS96", "version": "v1.0.2"} @@ -105,14 +105,14 @@ async def test_driver_get_lid_status( module_status: AbsorbanceReaderLidStatus, ) -> None: - mock_interface.byonoy_get_device_parts_aligned.return_value = ( - MockErrorCode.BYONOY_ERROR_NO_ERROR, + mock_interface.get_device_parts_aligned.return_value = ( + MockErrorCode.NO_ERROR, parts_aligned, ) status = await connected_driver.get_lid_status() - mock_interface.byonoy_get_device_parts_aligned.assert_called_once() + mock_interface.get_device_parts_aligned.assert_called_once() assert status == module_status @@ -121,8 +121,8 @@ async def test_driver_get_supported_wavelengths( connected_driver: AbsorbanceReaderDriver, ) -> None: SUPPORTED_WAVELENGTHS = [450, 500] - mock_interface.byonoy_abs96_get_available_wavelengths.return_value = ( - MockErrorCode.BYONOY_ERROR_NO_ERROR, + mock_interface.abs96_get_available_wavelengths.return_value = ( + MockErrorCode.NO_ERROR, SUPPORTED_WAVELENGTHS, ) @@ -130,7 +130,7 @@ async def test_driver_get_supported_wavelengths( wavelengths = await connected_driver.get_available_wavelengths() - mock_interface.byonoy_abs96_get_available_wavelengths.assert_called_once() + mock_interface.abs96_get_available_wavelengths.assert_called_once() assert connected_driver._connection._supported_wavelengths == SUPPORTED_WAVELENGTHS assert wavelengths == SUPPORTED_WAVELENGTHS @@ -141,8 +141,8 @@ async def test_driver_initialize_and_read_single( ) -> None: # set up mock interface connected_driver._connection._supported_wavelengths = [450, 500] - mock_interface.byonoy_abs96_initialize_single_measurement.return_value = ( - MockErrorCode.BYONOY_ERROR_NO_ERROR + mock_interface.abs96_initialize_single_measurement.return_value = ( + MockErrorCode.NO_ERROR ) class MeasurementConfig(AbsorbanceHidInterface.SingleMeasurementConfig): @@ -150,7 +150,7 @@ def __init__(self) -> None: self.sample_wavelength = 0 self.reference_wavelength = 0 - mock_interface.ByonoyAbs96SingleMeasurementConfig = MeasurementConfig + mock_interface.Abs96SingleMeasurementConfig = MeasurementConfig # current config should not have been setup yet assert not connected_driver._connection._current_config @@ -161,19 +161,17 @@ def __init__(self) -> None: connected_driver._connection._current_config, ) assert conf and conf.sample_wavelength == 450 - mock_interface.byonoy_abs96_initialize_single_measurement.assert_called_once_with( - 1, conf - ) + mock_interface.abs96_initialize_single_measurement.assert_called_once_with(1, conf) # setup up mock interface with a single reading MEASURE_RESULT = [[0.1] * 96] - mock_interface.byonoy_abs96_single_measure.return_value = ( - MockErrorCode.BYONOY_ERROR_NO_ERROR, + mock_interface.abs96_single_measure.return_value = ( + MockErrorCode.NO_ERROR, MEASURE_RESULT, ) result = await connected_driver.get_measurement() - mock_interface.byonoy_abs96_single_measure.assert_called_once_with(1, conf) + mock_interface.abs96_single_measure.assert_called_once_with(1, conf) assert result == MEASURE_RESULT @@ -184,15 +182,15 @@ async def test_driver_initialize_and_read_multi( ) -> None: # set up mock interface connected_driver._connection._supported_wavelengths = [450, 500, 600] - mock_interface.byonoy_abs96_initialize_multiple_measurement.return_value = ( - MockErrorCode.BYONOY_ERROR_NO_ERROR + mock_interface.abs96_initialize_multiple_measurement.return_value = ( + MockErrorCode.NO_ERROR ) class MeasurementConfig(AbsorbanceHidInterface.MultiMeasurementConfig): def __init__(self) -> None: self.sample_wavelengths = [0] - mock_interface.ByonoyAbs96MultipleMeasurementConfig = MeasurementConfig + mock_interface.Abs96MultipleMeasurementConfig = MeasurementConfig # current config should not have been setup yet assert not connected_driver._connection._current_config @@ -205,18 +203,18 @@ def __init__(self) -> None: connected_driver._connection._current_config, ) assert conf and conf.sample_wavelengths == [450, 500, 600] - mock_interface.byonoy_abs96_initialize_multiple_measurement.assert_called_once_with( + mock_interface.abs96_initialize_multiple_measurement.assert_called_once_with( 1, conf ) # setup up mock interface with multiple readings MEASURE_RESULT = [[0.1] * 96, [0.2] * 96, [0.3] * 96] - mock_interface.byonoy_abs96_multiple_measure.return_value = ( - MockErrorCode.BYONOY_ERROR_NO_ERROR, + mock_interface.abs96_multiple_measure.return_value = ( + MockErrorCode.NO_ERROR, MEASURE_RESULT, ) result = await connected_driver.get_measurement() - mock_interface.byonoy_abs96_multiple_measure.assert_called_once_with(1, conf) + mock_interface.abs96_multiple_measure.assert_called_once_with(1, conf) assert result == MEASURE_RESULT