Skip to content

Commit 2a751f7

Browse files
feat: Add method to unregister devices from BlueskyContext (mx-bluesky#987) (#1048)
This PR adds a method `unregister_all_devices()` to `BlueskyContext` ### Review Notes This functionality is required in the implementation of * DiamondLightSource/mx-bluesky#987 this PR also raised along with * DiamondLightSource/dodal#1271 See associated mx-bluesky PR #TBD --------- Co-authored-by: Joseph Ware <53935796+DiamondJoseph@users.noreply.github.com>
1 parent 3822344 commit 2a751f7

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/blueapi/core/context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ def register_device(self, device: Device, name: str | None = None) -> None:
232232

233233
self.devices[name] = device
234234

235+
def unregister_all_devices(self):
236+
"""Unregister all devices from the context."""
237+
self.devices.clear()
238+
235239
def _reference(self, target: type) -> type:
236240
"""
237241
Create an intermediate reference type for the required ``target`` type that

tests/unit_tests/core/test_context.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,13 @@ def test_device_reference_cache_with_generics(empty_context: BlueskyContext) ->
385385
assert empty_context._reference(motor) is not empty_context._reference(Movable)
386386

387387

388+
def test_unregister_all_devices(devicey_context: BlueskyContext) -> None:
389+
assert len(devicey_context.devices) > 0
390+
devicey_context.unregister_all_devices()
391+
392+
assert len(devicey_context.devices) == 0
393+
394+
388395
def test_reference_type_conversion(empty_context: BlueskyContext) -> None:
389396
movable_ref: type = empty_context._reference(Movable)
390397
assert empty_context._convert_type(Movable) == movable_ref

0 commit comments

Comments
 (0)