Skip to content

Commit 6dea2bd

Browse files
committed
Add docstrings
1 parent 81a9d51 commit 6dea2bd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/dodal/device_manager.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ def __repr__(self) -> str:
194194

195195

196196
class V1DeviceFactory(Generic[V1]):
197+
"""
198+
Wrapper around an ophyd v1 device that holds a reference to a device
199+
manager that can provide dependencies, along with default connection
200+
information for how the created device should be connected.
201+
"""
202+
197203
def __init__(
198204
self,
199205
*,
@@ -289,17 +295,22 @@ def build(self, mock: bool = False, fixtures: dict[str, Any] | None = None) -> V
289295

290296

291297
class ConnectionSpec(NamedTuple):
298+
"""A device paired with the options used to configure it"""
299+
292300
device: OphydV2Device
293301
mock: bool
294302
timeout: float
295303

296304

297305
class ConnectionResult(NamedTuple):
306+
"""Wrapper around results of building and connecting devices"""
307+
298308
devices: dict[str, AnyDevice]
299309
build_errors: dict[str, Exception]
300310
connection_errors: dict[str, Exception]
301311

302312
def or_raise(self) -> dict[str, Any]:
313+
"""Re-raise any errors from build or connect stage or return devices"""
303314
if self.build_errors or self.connection_errors:
304315
all_exc = []
305316
for name, exc in (self.build_errors | self.connection_errors).items():
@@ -310,10 +321,13 @@ def or_raise(self) -> dict[str, Any]:
310321

311322

312323
class DeviceBuildResult(NamedTuple):
324+
"""Wrapper around the results of building devices"""
325+
313326
devices: dict[str, ConnectionSpec]
314327
errors: dict[str, Exception]
315328

316329
def connect(self, timeout: float | None = None) -> ConnectionResult:
330+
"""Connect all devices that didn't fail to build"""
317331
connections = {}
318332
connected = {}
319333
loop: asyncio.EventLoop = get_bluesky_event_loop() # type: ignore
@@ -339,6 +353,7 @@ def connect(self, timeout: float | None = None) -> ConnectionResult:
339353
return ConnectionResult(connected, self.errors, connection_errors)
340354

341355
def or_raise(self) -> Self:
356+
"""Re-raise any build errors"""
342357
if self.errors:
343358
for name, exc in self.errors.items():
344359
exc.add_note(name)
@@ -347,6 +362,8 @@ def or_raise(self) -> Self:
347362

348363

349364
class DeviceManager:
365+
"""Manager to handle building and connecting interdependent devices"""
366+
350367
_factories: dict[str, DeviceFactory]
351368
_fixtures: dict[str, Callable[[], Any]]
352369
_v1_factories: dict[str, V1DeviceFactory]

0 commit comments

Comments
 (0)