DiamondLightSource / blueapi

Apache License 2.0
6 stars 6 forks source link

Support plan parameters of TypedDict, Dataclass, BaseModel that include devices, collections of devices #523

Open DiamondJoseph opened 3 months ago

DiamondJoseph commented 3 months ago

Extends #506

Plans that have parameters of e.g.

def foo_plan(thing: TypedThing):
  ...

where

class TypedThing(TypedDict):
  x: Readable

or

@dataclass
class TypedThing:
  x: Readable

or

class TypedThing(BaseModel):
  x: Readable

Should be able to have their schemas generated and presented from /plans, and these plans should be runnable with x being passed as a reference to a device (i.e. parameters = {"thing": {"x": "stage_x"}})

DiamondJoseph commented 3 months ago

Note that the "idiomatic way" does not work


class MyComposite(BlueapiBaseModel):
    x: Motor = inject("x")
    y: Motor = inject("y")
    det: Eiger = inject("det1")```