Skip to content

Device

Base classes

Bases: PDevice, ABC

Base class for devices.

Users may subclass from this device and implement their own configuration properties and methods.

Parameters:

Name Type Description Default
name str

Name of the device. Serves as a unique identifier for the object created from it.

required
kwargs Any

Additional keyword arguments for device subclasses.

{}
Source code in src/redsun/device/_base.py
class Device(PDevice, abc.ABC):
    """Base class for devices.

    Users may subclass from this device and implement their own
    configuration properties and methods.

    Parameters
    ----------
    name : str
        Name of the device. Serves as a unique identifier for the object created from it.
    kwargs : Any, optional
        Additional keyword arguments for device subclasses.
    """

    @abc.abstractmethod
    def __init__(self, name: str, /, **kwargs: Any) -> None:
        self._name = name
        super().__init__(**kwargs)

    @abc.abstractmethod
    def describe_configuration(self) -> dict[str, Descriptor]:
        """Provide a description of the device configuration.

        Subclasses should override this method to provide their own
        configuration description compatible with the Bluesky event model.

        Returns
        -------
        dict[str, Descriptor]
            A dictionary with the description of each field of the device configuration.
        """
        raise NotImplementedError

    @abc.abstractmethod
    def read_configuration(self) -> dict[str, Reading[Any]]:
        """Provide a description of the device configuration.

        Subclasses should override this method to provide their own
        configuration reading compatible with the Bluesky event model.

        Returns
        -------
        dict[str, Reading[Any]]
            A dictionary with the reading of each field of the device configuration.
        """
        raise NotImplementedError

    @property
    def name(self) -> str:
        """The name of the device, serving as a unique identifier."""
        return self._name

    @property
    def parent(self) -> None:
        """Parent of the device. Always returns None for compliance with [`HasParent`]() protocol."""
        return None

name property

name: str

The name of the device, serving as a unique identifier.

parent property

parent: None

Parent of the device. Always returns None for compliance with HasParent protocol.

describe_configuration abstractmethod

describe_configuration() -> dict[str, Descriptor]

Provide a description of the device configuration.

Subclasses should override this method to provide their own configuration description compatible with the Bluesky event model.

Returns:

Type Description
dict[str, Descriptor]

A dictionary with the description of each field of the device configuration.

Source code in src/redsun/device/_base.py
@abc.abstractmethod
def describe_configuration(self) -> dict[str, Descriptor]:
    """Provide a description of the device configuration.

    Subclasses should override this method to provide their own
    configuration description compatible with the Bluesky event model.

    Returns
    -------
    dict[str, Descriptor]
        A dictionary with the description of each field of the device configuration.
    """
    raise NotImplementedError

read_configuration abstractmethod

read_configuration() -> dict[str, Reading[Any]]

Provide a description of the device configuration.

Subclasses should override this method to provide their own configuration reading compatible with the Bluesky event model.

Returns:

Type Description
dict[str, Reading[Any]]

A dictionary with the reading of each field of the device configuration.

Source code in src/redsun/device/_base.py
@abc.abstractmethod
def read_configuration(self) -> dict[str, Reading[Any]]:
    """Provide a description of the device configuration.

    Subclasses should override this method to provide their own
    configuration reading compatible with the Bluesky event model.

    Returns
    -------
    dict[str, Reading[Any]]
        A dictionary with the reading of each field of the device configuration.
    """
    raise NotImplementedError

Bases: HasName, HasParent, Configurable[Any], Protocol

Minimal required protocol for a recognizable device in Redsun.

Source code in src/redsun/device/_base.py
@runtime_checkable
class PDevice(HasName, HasParent, Configurable[Any], Protocol):  # pragma: no cover
    """Minimal required protocol for a recognizable device in Redsun."""

Protocols

Device-level protocols for redsun.

This module defines structural protocols that devices can implement to participate in specific redsun behaviours, beyond the standard Bluesky device protocols.

HasCache

Bases: Protocol

Protocol for devices that can cache readings during a plan.

Devices implementing this protocol can accumulate readings in an internal cache (e.g. for metadata collection or deferred writing) and have that cache cleared between acquisitions.

Source code in src/redsun/device/protocols.py
@runtime_checkable
class HasCache(Protocol):
    """Protocol for devices that can cache readings during a plan.

    Devices implementing this protocol can accumulate readings in an
    internal cache (e.g. for metadata collection or deferred writing)
    and have that cache cleared between acquisitions.
    """

    @abstractmethod
    def stash(self, values: dict[str, Reading[Any]]) -> Status:
        """Stash *values* into the device cache.

        Parameters
        ----------
        values : dict[str, Reading[Any]]
            Readings to cache, keyed by the canonical ``name-property``
            key returned by ``describe()``.

        Returns
        -------
        Status
            A status object that completes when the cache operation finishes.
        """
        ...

    @abstractmethod
    def clear(self) -> Status:
        """Clear all cached readings.

        Returns
        -------
        Status
            A status object that completes when the cache is empty.
        """
        ...

stash abstractmethod

stash(values: dict[str, Reading[Any]]) -> Status

Stash values into the device cache.

Parameters:

Name Type Description Default
values dict[str, Reading[Any]]

Readings to cache, keyed by the canonical name-property key returned by describe().

required

Returns:

Type Description
Status

A status object that completes when the cache operation finishes.

Source code in src/redsun/device/protocols.py
@abstractmethod
def stash(self, values: dict[str, Reading[Any]]) -> Status:
    """Stash *values* into the device cache.

    Parameters
    ----------
    values : dict[str, Reading[Any]]
        Readings to cache, keyed by the canonical ``name-property``
        key returned by ``describe()``.

    Returns
    -------
    Status
        A status object that completes when the cache operation finishes.
    """
    ...

clear abstractmethod

clear() -> Status

Clear all cached readings.

Returns:

Type Description
Status

A status object that completes when the cache is empty.

Source code in src/redsun/device/protocols.py
@abstractmethod
def clear(self) -> Status:
    """Clear all cached readings.

    Returns
    -------
    Status
        A status object that completes when the cache is empty.
    """
    ...