Skip to content

Commit 7680d92

Browse files
sanni-tb-coopermcous
authored
fix(api, app): display labware label (#9587)
Closes #9105, closes #9088 Co-authored-by: Brian Cooper <[email protected]> Co-authored-by: Mike Cousins <[email protected]>
1 parent 983306c commit 7680d92

File tree

27 files changed

+207
-28
lines changed

27 files changed

+207
-28
lines changed

api/src/opentrons/protocol_api/load_info.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class LabwareLoadInfo:
4040
# if there was one.
4141
offset_id: Optional[str]
4242

43+
# user-specified label if present
44+
labware_display_name: Optional[str]
45+
4346

4447
@dataclass(frozen=True)
4548
class InstrumentLoadInfo:

api/src/opentrons/protocol_api/module_contexts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def load_labware_object(self, labware: Labware) -> Labware:
105105
deck_slot=deck_slot,
106106
on_module=True,
107107
offset_id=provided_offset.offset_id,
108+
labware_display_name=labware._implementation.get_label(),
108109
)
109110
)
110111
return mod_labware

api/src/opentrons/protocol_api/protocol_context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ def load_labware_from_definition(
416416
deck_slot=types.DeckSlotName.from_primitive(location),
417417
on_module=False,
418418
offset_id=provided_labware_offset.offset_id,
419+
labware_display_name=implementation.get_label(),
419420
)
420421
)
421422

@@ -483,6 +484,7 @@ def load_labware(
483484
deck_slot=types.DeckSlotName.from_primitive(location),
484485
on_module=False,
485486
offset_id=provided_labware_offset.offset_id,
487+
labware_display_name=implementation.get_label(),
486488
)
487489
)
488490

api/src/opentrons/protocol_engine/commands/load_labware.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ class LoadLabwareParams(BaseModel):
3636
description="An optional ID to assign to this labware. If None, an ID "
3737
"will be generated.",
3838
)
39+
displayName: Optional[str] = Field(
40+
None,
41+
description="An optional user-specified display name "
42+
"or label for this labware.",
43+
# NOTE: v4/5 JSON protocols will always have a displayName which will be the
44+
# user-specified label OR the displayName property of the labware's definition.
45+
# TODO: Make sure v6 JSON protocols don't do that.
46+
)
3947

4048

4149
class LoadLabwareResult(BaseModel):

api/src/opentrons/protocol_runner/legacy_command_mapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def map_labware_load(
201201
loadName=labware_load_info.labware_load_name,
202202
namespace=labware_load_info.labware_namespace,
203203
version=labware_load_info.labware_version,
204+
displayName=labware_load_info.labware_display_name,
204205
),
205206
result=pe_commands.LoadLabwareResult.construct(
206207
labwareId=labware_id,

api/src/opentrons/protocols/context/labware.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""The interface that implements InstrumentContext."""
22

33
from abc import abstractmethod
4-
from typing import List, Dict
4+
from typing import List, Dict, Optional
55

66
from opentrons.protocols.geometry.deck_item import DeckItem
77
from opentrons.protocols.geometry.labware_geometry import AbstractLabwareGeometry
@@ -23,6 +23,10 @@ def get_uri(self) -> str:
2323
def get_display_name(self) -> str:
2424
...
2525

26+
@abstractmethod
27+
def get_label(self) -> Optional[str]:
28+
...
29+
2630
@abstractmethod
2731
def get_name(self) -> str:
2832
...

api/src/opentrons/protocols/context/protocol_api/labware.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ def __init__(
3535
:param label: An optional label to use instead of the displayName
3636
from the definition's metadata element
3737
"""
38+
self._label: Optional[str] = None
3839
if label:
39-
dn = label
40+
dn = self._label = label
4041
self._name = dn
4142
else:
4243
dn = definition["metadata"]["displayName"]
@@ -65,6 +66,9 @@ def get_uri(self) -> str:
6566
def get_display_name(self) -> str:
6667
return self._display_name
6768

69+
def get_label(self) -> Optional[str]:
70+
return self._label
71+
6872
def get_name(self) -> str:
6973
return self._name
7074

api/tests/opentrons/protocol_api/test_labware_load.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def test_get_mixed_case_labware_def():
3030
def test_load_label(ctx):
3131
labware = ctx.load_labware(labware_name, "1", "my cool labware")
3232
assert "my cool labware" in str(labware)
33+
assert labware._implementation.get_label() == "my cool labware"
3334

3435

3536
def test_deprecated_load(ctx):

api/tests/opentrons/protocol_engine/commands/test_load_labware.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ async def test_load_labware_implementation(
3939
loadName="some-load-name",
4040
namespace="opentrons-test",
4141
version=1,
42+
displayName="My custom display name",
4243
)
4344

4445
decoy.when(

api/tests/opentrons/protocol_runner/test_legacy_command_mapper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def test_map_labware_load(minimal_labware_def: LabwareDefinition) -> None:
241241
deck_slot=DeckSlotName.SLOT_1,
242242
on_module=False,
243243
offset_id="labware-offset-id-123",
244+
labware_display_name="My special labware",
244245
)
245246
expected_output = pe_commands.LoadLabware.construct(
246247
id=matchers.IsA(str),
@@ -254,6 +255,7 @@ def test_map_labware_load(minimal_labware_def: LabwareDefinition) -> None:
254255
namespace="some_namespace",
255256
loadName="some_load_name",
256257
version=123,
258+
displayName="My special labware",
257259
labwareId=None,
258260
),
259261
result=pe_commands.LoadLabwareResult.construct(
@@ -340,6 +342,7 @@ def test_map_module_labware_load(minimal_labware_def: LabwareDefinition) -> None
340342
labware_definition=minimal_labware_def,
341343
labware_namespace="some_namespace",
342344
labware_load_name="some_load_name",
345+
labware_display_name="My very special module labware",
343346
labware_version=123,
344347
deck_slot=DeckSlotName.SLOT_1,
345348
on_module=True,
@@ -358,6 +361,7 @@ def test_map_module_labware_load(minimal_labware_def: LabwareDefinition) -> None
358361
namespace="some_namespace",
359362
loadName="some_load_name",
360363
version=123,
364+
displayName="My very special module labware",
361365
labwareId=None,
362366
),
363367
result=pe_commands.LoadLabwareResult.construct(

0 commit comments

Comments
 (0)