Skip to content

Commit

Permalink
added long name to device and test associate with it
Browse files Browse the repository at this point in the history
  • Loading branch information
Relm-Arrowny committed Apr 15, 2024
1 parent d3a281e commit 11a971d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ dev = [
"tox-direct",
"types-mock",
"types-pyyaml",
"bluesky",
]

[project.scripts]
Expand Down
11 changes: 7 additions & 4 deletions src/ophyd_async/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Tuple,
TypeVar,
)

from bluesky.protocols import HasName
from bluesky.run_engine import call_in_bluesky_event_loop

Expand All @@ -30,25 +31,27 @@ class Device(HasName):
#: The parent Device if it exists
parent: Optional[Device] = None

def __init__(self, name: str = "", long_name:Optional[str] = None) -> None:
def __init__(self, name: str = "", long_name: Optional[str] = None) -> None:
self.set_name(name)
self._long_name(long_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:
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
3 changes: 3 additions & 0 deletions src/ophyd_async/core/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@ 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:
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

0 comments on commit 11a971d

Please sign in to comment.