Skip to content

Commit

Permalink
fix(api): update the plate reader parsing of the serial + version to …
Browse files Browse the repository at this point in the history
…account for the new format. (#16824)
  • Loading branch information
vegano1 authored Nov 15, 2024
1 parent df80263 commit d49f990
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
9 changes: 5 additions & 4 deletions api/src/opentrons/drivers/absorbance_reader/async_byonoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@


SN_PARSER = re.compile(r'ATTRS{serial}=="(?P<serial>.+?)"')
VERSION_PARSER = re.compile(r"Absorbance (?P<version>V\d+\.\d+\.\d+)")
# match semver V0.0.0 (old format) or one integer (latest format)
VERSION_PARSER = re.compile(r"(?P<version>(V\d+\.\d+\.\d+|^\d+$))")
SERIAL_PARSER = re.compile(r"(?P<serial>(OPT|BYO)[A-Z]{3}[0-9]+)")


Expand Down Expand Up @@ -156,10 +157,10 @@ async def get_device_information(self) -> Dict[str, str]:
func=partial(self._interface.get_device_information, handle),
)
self._raise_if_error(err.name, f"Error getting device information: {err}")
serial_match = SERIAL_PARSER.fullmatch(device_info.sn)
version_match = VERSION_PARSER.match(device_info.version)
serial_match = SERIAL_PARSER.match(device_info.sn)
version_match = VERSION_PARSER.search(device_info.version)
serial = serial_match["serial"].strip() if serial_match else "OPTMAA00000"
version = version_match["version"].lower() if version_match else "v0.0.0"
version = version_match["version"].lower() if version_match else "v0"
info = {
"serial": serial,
"version": version,
Expand Down
30 changes: 30 additions & 0 deletions api/tests/opentrons/drivers/absorbance_reader/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,36 @@ async def test_driver_get_device_info(
mock_interface.get_device_information.assert_called_once()
mock_interface.reset_mock()

# Test Device info with updated version format
DEVICE_INFO.sn = "OPTMAA00034"
DEVICE_INFO.version = "8"

mock_interface.get_device_information.return_value = (
MockErrorCode.NO_ERROR,
DEVICE_INFO,
)

info = await connected_driver.get_device_info()

assert info == {"serial": "OPTMAA00034", "model": "ABS96", "version": "8"}
mock_interface.get_device_information.assert_called_once()
mock_interface.reset_mock()

# Test Device info with invalid version format
DEVICE_INFO.sn = "OPTMAA00034"
DEVICE_INFO.version = "asd"

mock_interface.get_device_information.return_value = (
MockErrorCode.NO_ERROR,
DEVICE_INFO,
)

info = await connected_driver.get_device_info()

assert info == {"serial": "OPTMAA00034", "model": "ABS96", "version": "v0"}
mock_interface.get_device_information.assert_called_once()
mock_interface.reset_mock()


@pytest.mark.parametrize(
"parts_aligned, module_status",
Expand Down

0 comments on commit d49f990

Please sign in to comment.