diff --git a/ophyd/device.py b/ophyd/device.py index 86c43345c..9badcf228 100644 --- a/ophyd/device.py +++ b/ophyd/device.py @@ -258,6 +258,10 @@ def create_component(self, instance): attr_name=self.attr, ) + _long_name = kwargs.get("long_name", self.attr) + _parent_long_name = getattr(instance, "long_name", instance.name) + kwargs["long_name"] = f"{_parent_long_name} {_long_name}" + for kw, val in list(kwargs.items()): kwargs[kw] = self.maybe_add_prefix(instance, kw, val) @@ -1785,7 +1789,6 @@ def wrapped(self, *args, **kwargs): def _wait_for_connection_context(value, doc): @contextlib.contextmanager def wrapped(dev): - orig = dev.lazy_wait_for_connection dev.lazy_wait_for_connection = value try: diff --git a/ophyd/ophydobj.py b/ophyd/ophydobj.py index 471ffedd6..234b75d20 100644 --- a/ophyd/ophydobj.py +++ b/ophyd/ophydobj.py @@ -36,7 +36,6 @@ class IFBase(IntFlag, boundary=KEEP): ... except ImportError: - IFBase = IntFlag @@ -148,7 +147,16 @@ class OphydObject: __any_instantiated = False subscriptions: ClassVar[FrozenSet[str]] = frozenset() - def __init__(self, *, name=None, attr_name="", parent=None, labels=None, kind=None): + def __init__( + self, + *, + name=None, + attr_name="", + parent=None, + labels=None, + kind=None, + long_name=None, + ): if labels is None: labels = set() self._ophyd_labels_ = set(labels) @@ -166,7 +174,7 @@ def __init__(self, *, name=None, attr_name="", parent=None, labels=None, kind=No raise ValueError("name must be a string.") self._name = name self._parent = parent - + self._long_name = long_name # dictionary of wrapped callbacks self._callbacks = {k: {} for k in self.subscriptions} # this is to maintain api on clear_sub @@ -331,6 +339,18 @@ def name(self): def name(self, name): self._name = name + @property + def long_name(self): + """name of the device""" + if self._long_name is not None: + return self._long_name + else: + return self._name + + @long_name.setter + def long_name(self, name): + self._long_name = name + @property def attr_name(self): return self._attr_name diff --git a/ophyd/signal.py b/ophyd/signal.py index f01180dbd..617803928 100644 --- a/ophyd/signal.py +++ b/ophyd/signal.py @@ -105,10 +105,15 @@ def __init__( metadata=None, cl=None, attr_name="", + long_name=None, ): - super().__init__( - name=name, parent=parent, kind=kind, labels=labels, attr_name=attr_name + name=name, + parent=parent, + kind=kind, + labels=labels, + attr_name=attr_name, + long_name=long_name, ) if cl is None: @@ -482,6 +487,7 @@ def describe(self): "source": "SIM:{}".format(self.name), "dtype": data_type(val), "shape": data_shape(val), + "long_name": self.long_name, } } except ValueError as ve: @@ -1486,6 +1492,7 @@ def describe(self): units=self._metadata["units"], lower_ctrl_limit=lower_ctrl_limit, upper_ctrl_limit=upper_ctrl_limit, + long_name=self.long_name, ) if self.precision is not None: @@ -1718,7 +1725,6 @@ def __init__( name=None, **kwargs, ): - self._write_pv = None self._use_limits = bool(limits) self._put_complete = put_complete @@ -2267,6 +2273,7 @@ def describe(self): "source": "PY:{}.{}".format(self.parent.name, self.full_attr), "dtype": data_type(value), "shape": data_shape(value), + "long_name": self.long_name, } return {self.name: desc} diff --git a/ophyd/tests/test_device.py b/ophyd/tests/test_device.py index c3d8b464c..e3ef54bf7 100644 --- a/ophyd/tests/test_device.py +++ b/ophyd/tests/test_device.py @@ -768,14 +768,14 @@ def test_dotted_name(): from ophyd.sim import SynSignal class Inner(Device): - x = Cpt(SynSignal) + x = Cpt(SynSignal, long_name="Inner X") y = Cpt(SynSignal) class Outer(Device): - a = Cpt(Inner) + a = Cpt(Inner, long_name="Outer A") b = Cpt(Inner) - o = Outer(name="test") + o = Outer(name="test", long_name="Test") assert o.dotted_name == "" assert o.a.dotted_name == "a" @@ -797,6 +797,14 @@ class Outer(Device): assert o.a.y.attr_name == "y" assert o.b.y.attr_name == "y" + assert o.long_name == "Test" + assert o.a.long_name == "Test Outer A" + assert o.b.long_name == "Test b" + assert o.a.x.long_name == "Test Outer A Inner X" + assert o.a.y.long_name == "Test Outer A y" + assert o.b.x.long_name == "Test b Inner X" + assert o.b.y.long_name == "Test b y" + def test_create_device(): components = dict(