Skip to content

Commit bf668fd

Browse files
Simplify find_component
Co-authored-by: Peter Holloway <peter.holloway@diamond.ac.uk>
1 parent b79fd69 commit bf668fd

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

‎src/blueapi/core/bluesky_types.py‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,11 @@ class BlueapiDevice:
142142
device: Device
143143

144144
def find_component(self, addr: list[str]) -> Device | None:
145-
if not addr: # for the case when its just the device name with no child device
146-
return self.device
147-
head, *tail = addr
148-
component = getattr(self.device, head, None)
149-
if component is None:
150-
return None
151-
if not is_bluesky_compatible_device(component):
152-
raise ValueError(f"Found {component} but it is not a device")
153-
return BlueapiDevice(component).find_component(tail)
145+
dev = self.device
146+
for name in addr:
147+
dev = getattr(dev, name, None)
148+
if dev is None:
149+
return None
150+
elif not is_bluesky_compatible_device(dev):
151+
raise ValueError(f"Found {dev} but it is not a device")
152+
return dev

0 commit comments

Comments
 (0)