Skip to content

Commit

Permalink
fix up structure - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed Mar 11, 2024
1 parent 0c52312 commit 58e3b0b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
14 changes: 9 additions & 5 deletions api/src/opentrons/hardware_control/simulator_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
@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)


# Name and kwargs for a module function
@dataclass(frozen=True)
class ModuleItem:
serial_number: str
items: List[ModuleCall] = field(default_factory=list)


Expand Down Expand Up @@ -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
32 changes: 16 additions & 16 deletions api/tests/opentrons/hardware_control/test_simulator_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
),
],
),
Expand All @@ -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

0 comments on commit 58e3b0b

Please sign in to comment.