Skip to content

Refactor: Combine functionality of Device and Device model #1725

Closed as not planned

Description

@abbiemery

Linked to the same issue for plans #

The distinction between actual ophyd-async devices stored in the context
and the model used to represent them is useful as the worker shouldn't
need to have any understanding of the user side of the interface that
calls it. However with the desire to have better modelling of devices
and their children for use in the client, having these separate will
cause more duplicated code and generation of objects on the fly will
have a performance overhead.

Falling in line with the plan model refactoring we can instead keep a
dictionary of BlueapiDevices which have a to_model function in them.

This will be a more involved change than the plans to ensure the
reference cache still behaves.


class BlueapiDevice(BlueapiBaseModel):

    name: str = Field(description="Name of the device")
    device: Device

    def to_model(self) -> dict[str, Any]:
        return {
            "name": self.name,
            "protocols": ist(_protocol_info(self)),
        }

The name checking would have to happen on the device registration if it
still needs to be done

name = device.name if isinstance(device, HasName) else _UNKNOWN_NAME

Acceptance Criteria

  • The dictionary of name to device in the context now stores name to
    BlueapiDevice
  • The blueapi device has a method on it that created the model for
    the rest interface
  • All behaviour should remain unchanged.

Activity

  1. self-assigned this
    on Oct 29, 2026
  2. shree-iyengar-dls commented on Nov 10, 2026

    @shree-iyengar-dls
    Contributor

    Similar to how #1728 was closed in order to keep both Plan and PlanModel separate, I think this issue can also be closed as not planned because we want to keep Device and DeviceModel separate.

    Just to check @tpoliaw am I fine to close this issue?

  3. tpoliaw commented on Nov 10, 2026

    @tpoliaw
    Contributor

    Makes sense to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions