Skip to content

Commit

Permalink
Set parent of children of DeviceVector passed at init
Browse files Browse the repository at this point in the history
Fixes #643
  • Loading branch information
coretl committed Nov 12, 2024
1 parent 3d9f508 commit c1db131
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ophyd_async/core/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions tests/core/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c1db131

Please sign in to comment.