From c1db131bc829a1c241e28d3a3fe298f41c21c318 Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Tue, 12 Nov 2024 09:12:29 +0000 Subject: [PATCH] Set parent of children of DeviceVector passed at init Fixes #643 --- src/ophyd_async/core/_device.py | 3 ++- tests/core/test_device.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ophyd_async/core/_device.py b/src/ophyd_async/core/_device.py index eb43abff5..9aef7d136 100644 --- a/src/ophyd_async/core/_device.py +++ b/src/ophyd_async/core/_device.py @@ -193,7 +193,8 @@ def __init__( children: Mapping[int, DeviceT], name: str = "", ) -> None: - self._children = dict(children) + self._children: dict[int, DeviceT] = {} + self.update(children) super().__init__(name=name) def __setattr__(self, name: str, child: Any) -> None: diff --git a/tests/core/test_device.py b/tests/core/test_device.py index 39a9b70a5..833ca5541 100644 --- a/tests/core/test_device.py +++ b/tests/core/test_device.py @@ -117,10 +117,15 @@ async def test_device_with_device_collector(): parent = DummyDeviceGroup("parent") assert parent.name == "parent" + assert parent.parent is None assert parent.child1.name == "parent-child1" + assert parent.child1.parent == parent assert parent._child2.name == "parent-child2" + assert parent._child2.parent == parent assert parent.dict_with_children.name == "parent-dict_with_children" + assert parent.dict_with_children.parent == parent assert parent.dict_with_children[123].name == "parent-dict_with_children-123" + assert parent.dict_with_children[123].parent == parent.dict_with_children assert parent.child1.connected assert parent.dict_with_children[123].connected