ophyd.device.FormattedComponent

class ophyd.device.FormattedComponent(cls, suffix=None, *, lazy=False, trigger_value=None, add_prefix=None, doc=None, kind=<Kind.normal: 1>, **kwargs)

A Component which takes a dynamic format string

This differs from Component in that the parent prefix is not automatically added onto the Component suffix. Additionally, str.format() style strings are accepted, allowing access to Device instance attributes:

>>> from ophyd import (Component as Cpt, FormattedComponent as FCpt)
>>> class MyDevice(Device):
...     # A normal component, where 'suffix' is added to prefix verbatim
...     cpt = Cpt(EpicsSignal, 'suffix')
...     # A formatted component, where 'self' refers to the Device instance
...     ch = FCpt(EpicsSignal, '{self.prefix}{self._ch_name}')
...     # A formatted component, where 'self' is assumed
...     ch = FCpt(EpicsSignal, '{prefix}{_ch_name}')
...
...     def __init__(self, prefix, ch_name=None, **kwargs):
...         self._ch_name = ch_name
...         super().__init__(prefix, **kwargs)
>>> dev = MyDevice('prefix:', ch_name='some_channel', name='dev')
>>> print(dev.cpt.pvname)
prefix:suffix
>>> print(dev.ch.pvname)
prefix:some_channel

For additional documentation, refer to Component.

__init__(cls, suffix=None, *, lazy=False, trigger_value=None, add_prefix=None, doc=None, kind=<Kind.normal: 1>, **kwargs)

Methods

__init__(cls[, suffix, lazy, trigger_value, …])
create_component(instance) Instantiate the object described by this Component for a Device
make_docstring(parent_class) Create a docstring for the Component
maybe_add_prefix(instance, kw, suffix)
sub_default(func) Default subscription decorator
sub_meta(func) Metadata subscription decorator
sub_value(func) Value subscription decorator
subscriptions(event_type) (Decorator) Specify subscriptions callbacks in the Device definition