Skip to content

Commit

Permalink
improvements to get_object_by_role() in BaseHartwareObjectNode
Browse files Browse the repository at this point in the history
  • Loading branch information
Costin committed Feb 23, 2024
1 parent eecd35e commit 4e31839
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions mxcubecore/BaseHardwareObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,18 +473,15 @@ def get_object_by_role(self, role: str) -> Union["HardwareObject", None]:
Union[HardwareObject, None]: Hardware object.
"""
role = str(role).lower()
objects = [o for o in self if o]
objects = [self]

while objects:
if role in self._objects_by_role:
return self._objects_by_role[role]
for curr in objects:
result = curr._objects_by_role.get(role)
if result is None:
objects.extend(obj for obj in curr if obj)

try :
self = objects.pop()

except :
if self.get_object_by_role(role):
return self.get_object_by_role(role)
else :
return result


def objects_names(self) -> List[Union[str, None]]:
Expand Down

0 comments on commit 4e31839

Please sign in to comment.