bluesky / ophyd

hardware abstraction in Python with an emphasis on EPICS
https://blueskyproject.io/ophyd
BSD 3-Clause "New" or "Revised" License
51 stars 79 forks source link

Add children property to a device #1138

Open rosesyrett opened 1 year ago

rosesyrett commented 1 year ago

It was recently discovered that get_device_children() doesn't work for devices that are device_vectors.

To fix this issue, this PR removes get_device_children, connect_children and name_children and instead defines a children property on a device which effectively does what get_device_children did.

This simplifies the code for DeviceVector somewhat, which only needs to define a children property and no longer needs to redefine connect and name class methods that it inherits from Device.

rosesyrett commented 1 year ago

@olliesilvester could you mention your use case for this here?

olliesilvester commented 1 year ago

For adding a load/save to devices (https://github.com/bluesky/ophyd-epics-devices/issues/28#event-9812353107), we need to walk through the device and find all of its SignalRW's, including those within sub-devices. It makes sense to use get_device_children() for this, however the Panda device has its SignalRW's within device_vectors so this currently doesn't work

rosesyrett commented 1 year ago

Ok, sure. This change will mean that instead of using get_device_children, each Device has a children property that you can iterate through instead. DeviceVector now has this property also.

Have a look at the changes in this PR and the tests. Please let me know if this will fix your problem or if you think there's anything missing. Thanks!

olliesilvester commented 1 year ago

Ok, sure. This change will mean that instead of using get_device_children, each Device has a children property that you can iterate through instead. DeviceVector now has this property also.

Have a look at the changes in this PR and the tests. Please let me know if this will fix your problem or if you think there's anything missing. Thanks!

Fixes my problem very well, thanks!

untzag commented 1 year ago

consider adding a HasChildren property to bluesky protocols, analogy to existing HasParent