from opentrons.protocol_api import Labware
from opentrons.protocol_api._types import OffDeckType


def get_location(labware: Labware):
    parent = labware.parent
    while not isinstance(parent, str):
        if not isinstance(parent, OffDeckType):
            parent = parent.parent
        else:
            return None

    if not isinstance(parent, str):
        return None

    return parent