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

197 add long name to device #218

Open
wants to merge 3 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
15 changes: 14 additions & 1 deletion src/ophyd_async/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,27 @@ class Device(HasName):
#: The parent Device if it exists
parent: Optional[Device] = None

def __init__(self, name: str = "") -> None:
def __init__(self, name: str = "", long_name: Optional[str] = None) -> None:
self.set_name(name)
self._long_name = long_name

@property
def name(self) -> str:
"""Return the name of the Device"""
return self._name

@property
def long_name(self) -> str:
"""long 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) -> None:
self._long_name = name

def children(self) -> Iterator[Tuple[str, Device]]:
for attr_name, attr in self.__dict__.items():
if attr_name != "parent" and isinstance(attr, Device):
Expand Down
8 changes: 1 addition & 7 deletions src/ophyd_async/core/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,10 @@ def __init__(
self, backend: SignalBackend[T], timeout: Optional[float] = DEFAULT_TIMEOUT
) -> None:
self._name = ""
self._long_name = None
self._timeout = timeout
self._init_backend = self._backend = backend

@property
def name(self) -> str:
return self._name

def set_name(self, name: str = ""):
self._name = name

async def connect(self, sim=False, timeout=DEFAULT_TIMEOUT):
if sim:
self._backend = SimSignalBackend(
Expand Down
8 changes: 7 additions & 1 deletion tests/core/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, name: str) -> None:
self.dict_with_children: DeviceVector[DummyBaseDevice] = DeviceVector(
{123: DummyBaseDevice()}
)
self.set_name(name)
super().__init__(name=name)


@pytest.fixture
Expand Down Expand Up @@ -61,6 +61,9 @@ async def test_children_of_device_have_set_names_and_get_connected(
parent: DummyDeviceGroup,
):
assert parent.name == "parent"
assert parent.long_name == "parent"
parent.long_name = "dancing device that make you jump"
assert parent.long_name == "dancing device that make you jump"
assert parent.child1.name == "parent-child1"
assert parent.child2.name == "parent-child2"
assert parent.dict_with_children.name == "parent-dict_with_children"
Expand All @@ -77,6 +80,9 @@ async def test_device_with_device_collector():
parent = DummyDeviceGroup("parent")

assert parent.name == "parent"
assert parent.long_name == parent.name
parent.long_name = "dancing device that make you jump"
assert parent.long_name == "dancing device that make you jump"
assert parent.child1.name == "parent-child1"
assert parent.child2.name == "parent-child2"
assert parent.dict_with_children.name == "parent-dict_with_children"
Expand Down
Loading