From d3a281e8abc0194de6f3030c7ecaec841f3b1046 Mon Sep 17 00:00:00 2001 From: Relm-Arrowny Date: Mon, 15 Apr 2024 16:00:15 +0100 Subject: [PATCH 1/3] first attempt --- pyproject.toml | 1 + src/ophyd_async/core/device.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e007a4435c..bac510537c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,6 +65,7 @@ dev = [ "tox-direct", "types-mock", "types-pyyaml", + "bluesky", ] [project.scripts] diff --git a/src/ophyd_async/core/device.py b/src/ophyd_async/core/device.py index 4733a1bc2c..50cf324c77 100644 --- a/src/ophyd_async/core/device.py +++ b/src/ophyd_async/core/device.py @@ -14,7 +14,6 @@ Tuple, TypeVar, ) - from bluesky.protocols import HasName from bluesky.run_engine import call_in_bluesky_event_loop @@ -31,13 +30,24 @@ 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(): From 11a971dab95abaa55654eac01f53b96b9647d76c Mon Sep 17 00:00:00 2001 From: Relm-Arrowny Date: Mon, 15 Apr 2024 15:40:47 +0000 Subject: [PATCH 2/3] added long name to device and test associate with it --- pyproject.toml | 1 - src/ophyd_async/core/device.py | 11 +++++++---- src/ophyd_async/core/signal.py | 3 +++ tests/core/test_device.py | 8 +++++++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bac510537c..e007a4435c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,6 @@ dev = [ "tox-direct", "types-mock", "types-pyyaml", - "bluesky", ] [project.scripts] diff --git a/src/ophyd_async/core/device.py b/src/ophyd_async/core/device.py index 50cf324c77..f1dc64d9e2 100644 --- a/src/ophyd_async/core/device.py +++ b/src/ophyd_async/core/device.py @@ -14,6 +14,7 @@ Tuple, TypeVar, ) + from bluesky.protocols import HasName from bluesky.run_engine import call_in_bluesky_event_loop @@ -30,13 +31,15 @@ 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""" @@ -44,11 +47,11 @@ def long_name(self) -> str: 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): diff --git a/src/ophyd_async/core/signal.py b/src/ophyd_async/core/signal.py index 927faaf402..30364bcaea 100644 --- a/src/ophyd_async/core/signal.py +++ b/src/ophyd_async/core/signal.py @@ -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: diff --git a/tests/core/test_device.py b/tests/core/test_device.py index a2d29dd5ad..0bde52a768 100644 --- a/tests/core/test_device.py +++ b/tests/core/test_device.py @@ -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 @@ -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" @@ -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" From c623f5c67d7fecd5e7db19719b1b57500994bc8d Mon Sep 17 00:00:00 2001 From: Relm-Arrowny Date: Mon, 15 Apr 2024 15:47:45 +0000 Subject: [PATCH 3/3] remove the get/set function in Signal as I think it is inherent from device --- src/ophyd_async/core/signal.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/ophyd_async/core/signal.py b/src/ophyd_async/core/signal.py index 30364bcaea..8a88712244 100644 --- a/src/ophyd_async/core/signal.py +++ b/src/ophyd_async/core/signal.py @@ -52,15 +52,6 @@ def __init__( 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(