Skip to content

Commit 9da6eaa

Browse files
committed
Rename AsyncSimpleCallableHandle to AsyncioCallableHandle
1 parent 3fdbbbe commit 9da6eaa

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/controller/python/chip/ChipStack.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,20 @@ def Wait(self, timeoutMs: int = None):
165165
return self._res
166166

167167

168-
class AsyncSimpleCallableHandle:
168+
class AsyncioCallableHandle:
169169
"""Class which handles Matter SDK Calls asyncio friendly"""
170170

171-
def __init__(self, callback, loop, future):
171+
def __init__(self, callback):
172172
self._callback = callback
173-
self._loop = loop
174-
self._future = future
173+
self._loop = asyncio.get_event_loop()
174+
self._future = self._loop.create_future()
175175
self._result = None
176176
self._exception = None
177177

178+
@property
179+
def future(self):
180+
return self._future
181+
178182
def _done(self):
179183
if self._exception:
180184
self._future.set_exception(self._exception)
@@ -397,9 +401,7 @@ async def CallAsync(self, callFunct, timeoutMs: int = None):
397401
'''Run a Python function on CHIP stack, and wait for the response.
398402
This function will post a task on CHIP mainloop and waits for the call response in a asyncio friendly manner.
399403
'''
400-
loop = asyncio.get_event_loop()
401-
future = loop.create_future()
402-
callObj = AsyncSimpleCallableHandle(callFunct, loop, future)
404+
callObj = AsyncioCallableHandle(callFunct)
403405
pythonapi.Py_IncRef(py_object(callObj))
404406

405407
res = self._ChipStackLib.pychip_DeviceController_PostTaskOnChipThread(
@@ -409,7 +411,7 @@ async def CallAsync(self, callFunct, timeoutMs: int = None):
409411
pythonapi.Py_DecRef(py_object(callObj))
410412
raise res.to_exception()
411413

412-
return await asyncio.wait_for(future, timeoutMs / 1000 if timeoutMs else None)
414+
return await asyncio.wait_for(callObj.future, timeoutMs / 1000 if timeoutMs else None)
413415

414416
def CallAsyncWithCallback(self, callFunct):
415417
'''Run a Python function on CHIP stack, and wait for the application specific response.

0 commit comments

Comments
 (0)