From 864519d3542ab834b1e7690324ec8c561ade9685 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 19 Jun 2024 17:15:41 +0200 Subject: [PATCH] [Python] Add documentation to the new context managers --- src/controller/python/chip/ChipDeviceCtrl.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 98a7ee7d35db23..9fa0f5089b8485 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -227,6 +227,12 @@ def wrapper(*args, **kwargs): class CallbackContext: + """A context manager for handling callbacks that are expected to be called exactly once. + + The context manager makes sure that no concurrent operations which use the same callback + handlers are executed. + """ + def __init__(self, lock: asyncio.Lock) -> None: self._lock = lock self._future = None @@ -248,6 +254,11 @@ async def __aexit__(self, exc_type, exc_value, traceback): class CommissioningContext(CallbackContext): + """A context manager for handling commissioning callbacks that are expected to be called exactly once. + + This context also resets commissioning related device controller state. + """ + def __init__(self, devCtrl: ChipDeviceController, lock: asyncio.Lock) -> None: super().__init__(lock) self._devCtrl = devCtrl