Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Long name to OphydObj #1187

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ophyd/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
26 changes: 23 additions & 3 deletions ophyd/ophydobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class IFBase(IntFlag, boundary=KEEP):
...

except ImportError:

IFBase = IntFlag


Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions ophyd/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1718,7 +1725,6 @@ def __init__(
name=None,
**kwargs,
):

self._write_pv = None
self._use_limits = bool(limits)
self._put_complete = put_complete
Expand Down Expand Up @@ -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}

Expand Down
14 changes: 11 additions & 3 deletions ophyd/tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand Down
Loading