55
55
from .crypto import p256keypair
56
56
from .interaction_model import SessionParameters , SessionParametersStruct
57
57
from .native import PyChipError
58
+ from typing import Optional
58
59
59
60
__all__ = ["ChipDeviceController" , "CommissioningParameters" ]
60
61
@@ -267,7 +268,7 @@ class CommissioningContext(CallbackContext):
267
268
This context also resets commissioning related device controller state.
268
269
"""
269
270
270
- def __init__ (self , devCtrl : ChipDeviceController , lock : asyncio .Lock ) -> None :
271
+ def __init__ (self , devCtrl : ChipDeviceControllerBase , lock : asyncio .Lock ) -> None :
271
272
super ().__init__ (lock )
272
273
self ._devCtrl = devCtrl
273
274
@@ -388,12 +389,12 @@ def attestationChallenge(self) -> bytes:
388
389
389
390
390
391
class ChipDeviceControllerBase ():
391
- activeList = set ()
392
+ activeList : typing . Set = set ()
392
393
393
394
def __init__ (self , name : str = '' ):
394
395
self .devCtrl = None
395
396
self ._ChipStack = builtins .chipStack
396
- self ._dmLib = None
397
+ self ._dmLib : typing . Any = None
397
398
398
399
self ._InitLib ()
399
400
@@ -553,10 +554,6 @@ def _enablePairingCompleteCallback(self, value: bool):
553
554
self ._dmLib .pychip_ScriptDevicePairingDelegate_SetExpectingPairingComplete (
554
555
self .pairingDelegate , value )
555
556
556
- @property
557
- def fabricAdmin (self ) -> FabricAdmin .FabricAdmin :
558
- return self ._fabricAdmin
559
-
560
557
@property
561
558
def nodeId (self ) -> int :
562
559
return self ._nodeId
@@ -595,7 +592,7 @@ def Shutdown(self):
595
592
ChipDeviceController .activeList .remove (self )
596
593
self ._isActive = False
597
594
598
- def ShutdownAll ():
595
+ def ShutdownAll (self ):
599
596
''' Shut down all active controllers and reclaim any used resources.
600
597
'''
601
598
#
@@ -766,7 +763,7 @@ def GetAddressAndPort(self, nodeid):
766
763
767
764
return (address .value .decode (), port .value ) if error == 0 else None
768
765
769
- async def DiscoverCommissionableNodes (self , filterType : discovery .FilterType = discovery .FilterType .NONE , filter : typing .Any = None ,
766
+ async def DiscoverCommissionableNodes (self , filterType : discovery .FilterType = discovery .FilterType .NONE , filter : Optional [ typing .Any ] = None ,
770
767
stopOnFirst : bool = False , timeoutSecond : int = 5 ) -> typing .Union [None , CommissionableNode , typing .List [CommissionableNode ]]:
771
768
''' Discover commissionable nodes via DNS-SD with specified filters.
772
769
Supported filters are:
@@ -928,7 +925,7 @@ def GetClusterHandler(self):
928
925
929
926
return self ._Cluster
930
927
931
- async def FindOrEstablishPASESession (self , setupCode : str , nodeid : int , timeoutMs : int = None ) -> typing .Optional [DeviceProxyWrapper ]:
928
+ async def FindOrEstablishPASESession (self , setupCode : str , nodeid : int , timeoutMs : Optional [ int ] = None ) -> typing .Optional [DeviceProxyWrapper ]:
932
929
''' Returns CommissioneeDeviceProxy if we can find or establish a PASE connection to the specified device'''
933
930
self .CheckIsActive ()
934
931
returnDevice = c_void_p (None )
@@ -944,7 +941,9 @@ async def FindOrEstablishPASESession(self, setupCode: str, nodeid: int, timeoutM
944
941
if res .is_success :
945
942
return DeviceProxyWrapper (returnDevice , DeviceProxyWrapper .DeviceProxyType .COMMISSIONEE , self ._dmLib )
946
943
947
- def GetConnectedDeviceSync (self , nodeid , allowPASE = True , timeoutMs : int = None ):
944
+ return None
945
+
946
+ def GetConnectedDeviceSync (self , nodeid , allowPASE = True , timeoutMs : Optional [int ] = None ):
948
947
''' Gets an OperationalDeviceProxy or CommissioneeDeviceProxy for the specified Node.
949
948
950
949
nodeId: Target's Node ID
@@ -956,8 +955,8 @@ def GetConnectedDeviceSync(self, nodeid, allowPASE=True, timeoutMs: int = None):
956
955
'''
957
956
self .CheckIsActive ()
958
957
959
- returnDevice = c_void_p (None )
960
- returnErr = None
958
+ returnDevice : ctypes . c_void_p = c_void_p (None )
959
+ returnErr : typing . Any = None
961
960
deviceAvailableCV = threading .Condition ()
962
961
963
962
if allowPASE :
@@ -1014,7 +1013,7 @@ async def WaitForActive(self, nodeid, *, timeoutSeconds=30.0, stayActiveDuration
1014
1013
await WaitForCheckIn (ScopedNodeId (nodeid , self ._fabricIndex ), timeoutSeconds = timeoutSeconds )
1015
1014
return await self .SendCommand (nodeid , 0 , Clusters .IcdManagement .Commands .StayActiveRequest (stayActiveDuration = stayActiveDurationMs ))
1016
1015
1017
- async def GetConnectedDevice (self , nodeid , allowPASE : bool = True , timeoutMs : int = None ):
1016
+ async def GetConnectedDevice (self , nodeid , allowPASE : bool = True , timeoutMs : Optional [ int ] = None ):
1018
1017
''' Gets an OperationalDeviceProxy or CommissioneeDeviceProxy for the specified Node.
1019
1018
1020
1019
nodeId: Target's Node ID
@@ -1412,7 +1411,7 @@ def _parseEventPathTuple(self, pathTuple: typing.Union[
1412
1411
else :
1413
1412
raise ValueError ("Unsupported Attribute Path" )
1414
1413
1415
- async def Read (self , nodeid : int , attributes : typing .List [typing .Union [
1414
+ async def Read (self , nodeid : int , attributes : Optional [ typing .List [typing .Union [
1416
1415
None , # Empty tuple, all wildcard
1417
1416
typing .Tuple [int ], # Endpoint
1418
1417
# Wildcard endpoint, Cluster id present
@@ -1423,9 +1422,9 @@ async def Read(self, nodeid: int, attributes: typing.List[typing.Union[
1423
1422
typing .Tuple [int , typing .Type [ClusterObjects .Cluster ]],
1424
1423
# Concrete path
1425
1424
typing .Tuple [int , typing .Type [ClusterObjects .ClusterAttributeDescriptor ]]
1426
- ]] = None ,
1427
- dataVersionFilters : typing .List [typing .Tuple [int , typing .Type [ClusterObjects .Cluster ], int ]] = None , events : typing .List [
1428
- typing .Union [
1425
+ ]]] = None ,
1426
+ dataVersionFilters : Optional [ typing .List [typing .Tuple [int , typing .Type [ClusterObjects .Cluster ], int ]]] = None , events : Optional [ typing .List [
1427
+ typing .Union [
1429
1428
None , # Empty tuple, all wildcard
1430
1429
typing .Tuple [str , int ], # all wildcard with urgency set
1431
1430
typing .Tuple [int , int ], # Endpoint,
@@ -1437,9 +1436,9 @@ async def Read(self, nodeid: int, attributes: typing.List[typing.Union[
1437
1436
typing .Tuple [int , typing .Type [ClusterObjects .Cluster ], int ],
1438
1437
# Concrete path
1439
1438
typing .Tuple [int , typing .Type [ClusterObjects .ClusterEvent ], int ]
1440
- ]] = None ,
1439
+ ] ]] = None ,
1441
1440
eventNumberFilter : typing .Optional [int ] = None ,
1442
- returnClusterObject : bool = False , reportInterval : typing .Tuple [int , int ] = None ,
1441
+ returnClusterObject : bool = False , reportInterval : Optional [ typing .Tuple [int , int ] ] = None ,
1443
1442
fabricFiltered : bool = True , keepSubscriptions : bool = False , autoResubscribe : bool = True ):
1444
1443
'''
1445
1444
Read a list of attributes and/or events from a target node
@@ -1528,9 +1527,9 @@ async def ReadAttribute(self, nodeid: int, attributes: typing.List[typing.Union[
1528
1527
typing .Tuple [int , typing .Type [ClusterObjects .Cluster ]],
1529
1528
# Concrete path
1530
1529
typing .Tuple [int , typing .Type [ClusterObjects .ClusterAttributeDescriptor ]]
1531
- ]], dataVersionFilters : typing .List [typing .Tuple [int , typing .Type [ClusterObjects .Cluster ], int ]] = None ,
1530
+ ]], dataVersionFilters : Optional [ typing .List [typing .Tuple [int , typing .Type [ClusterObjects .Cluster ], int ] ]] = None ,
1532
1531
returnClusterObject : bool = False ,
1533
- reportInterval : typing .Tuple [int , int ] = None ,
1532
+ reportInterval : Optional [ typing .Tuple [int , int ] ] = None ,
1534
1533
fabricFiltered : bool = True , keepSubscriptions : bool = False , autoResubscribe : bool = True ):
1535
1534
'''
1536
1535
Read a list of attributes from a target node, this is a wrapper of DeviceController.Read()
@@ -1611,7 +1610,7 @@ async def ReadEvent(self, nodeid: int, events: typing.List[typing.Union[
1611
1610
typing .Tuple [int , typing .Type [ClusterObjects .ClusterEvent ], int ]
1612
1611
]], eventNumberFilter : typing .Optional [int ] = None ,
1613
1612
fabricFiltered : bool = True ,
1614
- reportInterval : typing .Tuple [int , int ] = None ,
1613
+ reportInterval : Optional [ typing .Tuple [int , int ] ] = None ,
1615
1614
keepSubscriptions : bool = False ,
1616
1615
autoResubscribe : bool = True ):
1617
1616
'''
@@ -1928,7 +1927,7 @@ class ChipDeviceController(ChipDeviceControllerBase):
1928
1927
'''
1929
1928
1930
1929
def __init__ (self , opCredsContext : ctypes .c_void_p , fabricId : int , nodeId : int , adminVendorId : int , catTags : typing .List [int ] = [
1931
- ], paaTrustStorePath : str = "" , useTestCommissioner : bool = False , fabricAdmin : FabricAdmin = None , name : str = None , keypair : p256keypair .P256Keypair = None ):
1930
+ ], paaTrustStorePath : str = "" , useTestCommissioner : bool = False , fabricAdmin : Optional [ FabricAdmin ] = None , name : Optional [ str ] = None , keypair : Optional [ p256keypair .P256Keypair ] = None ):
1932
1931
super ().__init__ (
1933
1932
name or
1934
1933
f"caIndex({ fabricAdmin .caIndex :x} )/fabricId(0x{ fabricId :016X} )/nodeId(0x{ nodeId :016X} )"
@@ -1971,7 +1970,7 @@ def caIndex(self) -> int:
1971
1970
return self ._caIndex
1972
1971
1973
1972
@property
1974
- def fabricAdmin (self ) -> FabricAdmin :
1973
+ def fabricAdmin (self ) -> FabricAdmin . FabricAdmin :
1975
1974
return self ._fabricAdmin
1976
1975
1977
1976
async def Commission (self , nodeid ) -> int :
@@ -2114,7 +2113,7 @@ def GetFabricCheckResult(self) -> int:
2114
2113
return self ._fabricCheckNodeId
2115
2114
2116
2115
async def CommissionOnNetwork (self , nodeId : int , setupPinCode : int ,
2117
- filterType : DiscoveryFilterType = DiscoveryFilterType .NONE , filter : typing .Any = None ,
2116
+ filterType : DiscoveryFilterType = DiscoveryFilterType .NONE , filter : Optional [ typing .Any ] = None ,
2118
2117
discoveryTimeoutMsec : int = 30000 ) -> int :
2119
2118
'''
2120
2119
Does the routine for OnNetworkCommissioning, with a filter for mDNS discovery.
@@ -2217,7 +2216,7 @@ class BareChipDeviceController(ChipDeviceControllerBase):
2217
2216
'''
2218
2217
2219
2218
def __init__ (self , operationalKey : p256keypair .P256Keypair , noc : bytes ,
2220
- icac : typing .Union [bytes , None ], rcac : bytes , ipk : typing .Union [bytes , None ], adminVendorId : int , name : str = None ):
2219
+ icac : typing .Union [bytes , None ], rcac : bytes , ipk : typing .Union [bytes , None ], adminVendorId : int , name : Optional [ str ] = None ):
2221
2220
'''Creates a controller without AutoCommissioner.
2222
2221
2223
2222
The allocated controller uses the noc, icac, rcac and ipk instead of the default,
0 commit comments