Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiuchingau committed Dec 18, 2024
1 parent 21248c0 commit 132ab0d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api/src/opentrons/drivers/flex_stacker/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ async def get_device_info(self) -> StackerInfo:
response = await self._connection.send_command(
GCODE.DEVICE_INFO.build_command()
)
await self._connection.send_command(GCODE.GET_RESET_REASON.build_command())
return self.parse_device_info(response)

async def set_serial_number(self, sn: str) -> None:
Expand Down Expand Up @@ -161,7 +162,12 @@ async def get_limit_switches_status(self) -> LimitSwitchStatus:
)
return self.parse_limit_switch_status(response)

async def get_platform_sensor_status(self) -> PlatformStatus:
async def get_platform_sensor(self, direction: Direction) -> bool:
"""Get platform sensor at one direction."""
response = await self.get_platform_status()
return response.get(direction)

async def get_platform_status(self) -> PlatformStatus:
"""Get platform sensor status.
:return: True if platform is detected, False otherwise
Expand Down Expand Up @@ -226,3 +232,8 @@ async def set_led(
if external is not None:
command.add_int("E", external)
await self._connection.send_command(command)

async def update_firmware(self, firmware_file_path: str) -> None:
"""Updates the firmware on the device."""
# TODO: Implement firmware update
pass
5 changes: 5 additions & 0 deletions api/src/opentrons/drivers/flex_stacker/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class GCODE(str, Enum):
MOVE_TO_SWITCH = "G5"
HOME_AXIS = "G28"
STOP_MOTOR = "M0"
GET_RESET_REASON = "M114"
DEVICE_INFO = "M115"
GET_LIMIT_SWITCH = "M119"
SET_LED = "M200"
Expand Down Expand Up @@ -123,6 +124,10 @@ def get_fields(cls) -> List[str]:
"""Get fields."""
return [f.name for f in fields(cls)]

def get(self, direction: Direction) -> bool:
"""Get platform status."""
return self.E if direction == Direction.EXTENT else self.R


@dataclass
class MoveParams:
Expand Down
Empty file.
41 changes: 41 additions & 0 deletions api/tests/opentrons/drivers/flex_stacker/test_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest
from mock import AsyncMock
from opentrons.drivers.asyncio.communication.serial_connection import (
AsyncResponseSerialConnection,
)
from opentrons.drivers.flex_stacker.driver import FlexStackerDriver
from opentrons.drivers.flex_stacker import types
from opentrons.drivers.command_builder import CommandBuilder


@pytest.fixture
def connection() -> AsyncMock:
return AsyncMock(spec=AsyncResponseSerialConnection)


@pytest.fixture
def subject(connection: AsyncMock) -> FlexStackerDriver:
connection.send_command.return_value = ""
return FlexStackerDriver(connection)


async def test_get_device_info(
subject: FlexStackerDriver, connection: AsyncMock
) -> None:
"""It should send a get device info command"""
connection.send_command.return_value = (
"M115 FW:dummy-fw-version HW:Opentrons-flex-stacker-a1 SerialNo:dummy-serial ok\n"
)
response = await subject.get_device_info()
assert response == types.StackerInfo(
fw="dummy-fw-version",
hw=types.HardwareRevision.EVT,
sn="dummy-serial",
)

device_info = types.GCODE.DEVICE_INFO.build_command()
reset_reason = types.GCODE.GET_RESET_REASON.build_command()
connection.send_command.assert_any_call(command=device_info)
connection.send_command.assert_called_with(command=reset_reason)


0 comments on commit 132ab0d

Please sign in to comment.