31
31
import os
32
32
from ctypes import CFUNCTYPE , Structure , c_bool , c_char_p , c_uint16 , c_uint32 , c_void_p , py_object , pythonapi
33
33
from threading import Condition , Lock
34
+ from typing import Any , Optional
34
35
35
36
import chip .native
36
37
from chip .native import PyChipError
@@ -90,7 +91,7 @@ def __call__(self):
90
91
self ._cv .notify_all ()
91
92
pythonapi .Py_DecRef (py_object (self ))
92
93
93
- def Wait (self , timeoutMs : int = None ):
94
+ def Wait (self , timeoutMs : Optional [ int ] = None ):
94
95
timeout = None
95
96
if timeoutMs is not None :
96
97
timeout = float (timeoutMs ) / 1000
@@ -143,7 +144,7 @@ class ChipStack(object):
143
144
def __init__ (self , persistentStoragePath : str , enableServerInteractions = True ):
144
145
builtins .enableDebugMode = False
145
146
146
- self ._ChipStackLib = None
147
+ self ._ChipStackLib : Any = None
147
148
self ._chipDLLPath = None
148
149
self .devMgr = None
149
150
self ._enableServerInteractions = enableServerInteractions
@@ -209,14 +210,14 @@ def Shutdown(self):
209
210
210
211
delattr (builtins , "chipStack" )
211
212
212
- def Call (self , callFunct , timeoutMs : int = None ):
213
+ def Call (self , callFunct , timeoutMs : Optional [ int ] = None ):
213
214
'''Run a Python function on CHIP stack, and wait for the response.
214
215
This function is a wrapper of PostTaskOnChipThread, which includes some handling of application specific logics.
215
216
Calling this function on CHIP on CHIP mainloop thread will cause deadlock.
216
217
'''
217
218
return self .PostTaskOnChipThread (callFunct ).Wait (timeoutMs )
218
219
219
- async def CallAsyncWithResult (self , callFunct , timeoutMs : int = None ):
220
+ async def CallAsyncWithResult (self , callFunct , timeoutMs : Optional [ int ] = None ):
220
221
'''Run a Python function on CHIP stack, and wait for the response.
221
222
This function will post a task on CHIP mainloop and waits for the call response in a asyncio friendly manner.
222
223
'''
@@ -232,7 +233,7 @@ async def CallAsyncWithResult(self, callFunct, timeoutMs: int = None):
232
233
233
234
return await asyncio .wait_for (callObj .future , timeoutMs / 1000 if timeoutMs else None )
234
235
235
- async def CallAsync (self , callFunct , timeoutMs : int = None ) -> None :
236
+ async def CallAsync (self , callFunct , timeoutMs : Optional [ int ] = None ) -> None :
236
237
'''Run a Python function on CHIP stack, and wait for the response.'''
237
238
res : PyChipError = await self .CallAsyncWithResult (callFunct , timeoutMs )
238
239
res .raise_on_error ()
0 commit comments