diff --git a/api/src/opentrons/hardware_control/simulator_setup.py b/api/src/opentrons/hardware_control/simulator_setup.py index 9cea61839d8..f9cedf928f3 100644 --- a/api/src/opentrons/hardware_control/simulator_setup.py +++ b/api/src/opentrons/hardware_control/simulator_setup.py @@ -17,6 +17,7 @@ @dataclass(frozen=True) class ModuleCall: function_name: str + serial_number: str args: List[Any] = field(default_factory=list) kwargs: Dict[str, Any] = field(default_factory=dict) @@ -24,7 +25,6 @@ class ModuleCall: # Name and kwargs for a module function @dataclass(frozen=True) class ModuleItem: - serial_number: str items: List[ModuleCall] = field(default_factory=list) @@ -205,14 +205,18 @@ def _prepare_for_ot3_simulator_setup(key: str, value: Dict[str, Any]) -> Any: if key == "config" and value: return robot_configs.build_config_ot3(value) if key == "attached_modules" and value: + attached_modules: Dict[str, ModuleItem] = {} # list of items with id, item - loop and set to ModuleCall for key, item in value.items(): - # print(list(item['items'])) for obj in item: for data in obj["items"]: - print(ModuleCall(**data)) + attached_modules.setdefault(key, ModuleItem().items).append( + ModuleCall(**data) + ) + + print(attached_modules) + print("----") # items = {k: [ModuleCall(**data) for data in v] for (k, v) in value.items()} - # print(items) - return {k: [ModuleCall(**data) for data in v] for (k, v) in value.items()} + return attached_modules return value diff --git a/api/tests/opentrons/hardware_control/test_simulator_setup.py b/api/tests/opentrons/hardware_control/test_simulator_setup.py index 44bda189d81..34903f0201d 100644 --- a/api/tests/opentrons/hardware_control/test_simulator_setup.py +++ b/api/tests/opentrons/hardware_control/test_simulator_setup.py @@ -164,30 +164,27 @@ def test_persistence_ot3(tmpdir: str) -> None: attached_modules={ "magdeck": [ simulator_setup.ModuleItem( - id="mag-123", - items=[simulator_setup.ModuleCall("engage", kwargs={"height": 3})], - ) - ], - "tempdeck": [ - simulator_setup.ModuleItem( - id="temp-123", items=[ simulator_setup.ModuleCall( - "set_temperature", kwargs={"celsius": 23} - ), - simulator_setup.ModuleCall( - "set_temperature", kwargs={"celsius": 24} - ), + function_name="engage", + serial_number="mag-1", + kwargs={"height": 3}, + ) ], - ), + ) + ], + "tempdeck": [ simulator_setup.ModuleItem( - id="temp-1234", items=[ simulator_setup.ModuleCall( - "set_temperature", kwargs={"celsius": 23} + function_name="set_temperature", + serial_number="temp-1", + kwargs={"celsius": 23}, ), simulator_setup.ModuleCall( - "set_temperature", kwargs={"celsius": 24} + function_name="set_temperature", + serial_number="temp-2", + kwargs={"celsius": 24}, ), ], ), @@ -199,4 +196,7 @@ def test_persistence_ot3(tmpdir: str) -> None: simulator_setup.save_simulator_setup(sim, file) test_sim = simulator_setup.load_simulator_setup(file) + print(sim.attached_modules) + print("====") + print(test_sim.attached_modules) assert test_sim == sim