Skip to content

Allow HasName to be used with DeviceManager #1997

@oliwenmandiamond

Description

@oliwenmandiamond

In #1798 and through out other beamlines, we have a mix of global state and dependency injection being used for the daq config server config client. The global state is used because in MX, they need access to the config server inside plans independent of devices. DeviceManager and BlueAPI currently only supports the concept of a Device from ophyd-async.

Instead, I'm proposing broadening this restriction to include the Bluesky protocol HasName inside DeviceManager (V2 = TypeVar("V2", bound=OphydV2Device | HasName)) (will also need BlueAPI to support DiamondLightSource/blueapi#1462) so we can make still make a clear distinction between what is a Device and what isn't while also making other objects findable and therefore injectable inside plans and can remove the use of troublesome global states.

For example:

class InjectableConfigClient(HasName):
    def __init__(self, url: str, name):
        self.client = ConfigClient(url)
        self._name = name

    @property
    def name(self) -> str:
        return self._name
...

devices = DeviceManager()

@devices.factory()
def config_client() -> InjectableConfigClient:
    return InjectableConfigClient("https://daq-config.diamond.ac.uk", "config_client")

Then in a plan repository, we can then do this for example

@plan
def my_plan(config_client: InjectableConfigClient = inject("config_client")) -> MsgGenerator:
     config_client.client.reset_cache()

This will make plans working with BlueAPI much more flexible.

One thing is that isn't really as much of DeviceManager with this change and I would argue more of BeamlineManager (maybe rename...?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions