Skip to content

Commit 9afb7cc

Browse files
authored
[Python] Unify the nodeId argument name in the controller API (project-chip#41282)
* Update FindAddress/FindAddressAsync API to reflect convention * Fix time type in PendingDiscovery * [Python] Unify the nodeId argument name in the controller API * Update testing code: Rename `nodeid=` to `nodeId=` * Make restyled happy * Add type for consistency * Post merge fixes * Post merge fixes * Post review fixes * Fix mypy issues
1 parent e5e17f6 commit 9afb7cc

File tree

109 files changed

+792
-791
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+792
-791
lines changed

docs/development_controllers/matter-repl/python_chip_controller_advanced_usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ then you can use `bt` (for `backtrace`) to see the backtrace of the call stack.
225225
#0 chip::Controller::DeviceCommissioner::PairDevice
226226
(this=0x7fffd8003a90, remoteDeviceId=1234, setUpCode=0x7fffef2555d0 "MT:-24J0AFN00KA0648G00", params=..., discoveryType=chip::Controller::DiscoveryType::kAll, resolutionData=...)
227227
at ../../src/controller/CHIPDeviceController.cpp:646
228-
#1 0x00007fffed040825 in pychip_DeviceController_ConnectWithCode (devCtrl=0x7fffd8003a90, onboardingPayload=0x7fffef2555d0 "MT:-24J0AFN00KA0648G00", nodeid=1234, discoveryType=2 '\002')
228+
#1 0x00007fffed040825 in pychip_DeviceController_ConnectWithCode (devCtrl=0x7fffd8003a90, onboardingPayload=0x7fffef2555d0 "MT:-24J0AFN00KA0648G00", nodeId=1234, discoveryType=2 '\002')
229229
at ../../src/controller/python/ChipDeviceController-ScriptBinding.cpp:395
230230
#2 0x00007ffff6ad5596 in ??? () at /usr/lib/libffi.so.8
231231
#3 0x00007ffff6ad200e in ??? () at /usr/lib/libffi.so.8

docs/testing/python.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ Example for setting callbacks:
323323
cb = EventSubscriptionHandler(cluster, cluster_id, event_id)
324324

325325
urgent = 1
326-
subscription = await dev_ctrl.ReadEvent(nodeid=1, events=[(1, event, urgent)], reportInterval=[1, 3])
326+
subscription = await dev_ctrl.ReadEvent(nodeId=1, events=[(1, event, urgent)], reportInterval=[1, 3])
327327
subscription.SetEventUpdateCallback(callback=cb)
328328

329329
try:
@@ -344,7 +344,7 @@ PyChipError
344344
Example:
345345

346346
```python
347-
res = await devCtrl.WriteAttribute(nodeid=0, attributes=[(0,Clusters.BasicInformation.Attributes.NodeLabel("Test"))])
347+
res = await devCtrl.WriteAttribute(nodeId=0, attributes=[(0,Clusters.BasicInformation.Attributes.NodeLabel("Test"))])
348348
asserts.assert_equal(ret[0].status, Status.Success, "write failed")
349349
```
350350

src/app/icd/client/DefaultCheckInDelegate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ CHIP_ERROR DefaultCheckInDelegate::Init(ICDClientStorage * storage, InteractionM
3535
void DefaultCheckInDelegate::OnCheckInComplete(const ICDClientInfo & clientInfo)
3636
{
3737
ChipLogProgress(
38-
ICD, "Check In Message processing complete: start_counter=%" PRIu32 " offset=%" PRIu32 " nodeid=" ChipLogFormatScopedNodeId,
38+
ICD, "Check In Message processing complete: start_counter=%" PRIu32 " offset=%" PRIu32 " nodeId=" ChipLogFormatScopedNodeId,
3939
clientInfo.start_icd_counter, clientInfo.offset, ChipLogValueScopedNodeId(clientInfo.peer_node));
4040
}
4141

src/controller/python/matter/ChipDeviceCtrl.py

Lines changed: 116 additions & 113 deletions
Large diffs are not rendered by default.

src/controller/python/matter/ble/commissioning/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _StartAsyncConnection(discriminator: int, pin: int, deprecated_nodeid: Optio
112112
the device
113113
pin: the pin number used to pair with the device (must match the
114114
device secret pin, typically available in a QR code)
115-
deprecated_nodeid: TEMPORARY, TO BE REMOVED nodeid that will be set during
115+
deprecated_nodeid: TEMPORARY, TO BE REMOVED node ID that will be set during
116116
the commissioning. This will be replaced by setting the node id
117117
at the time of setting operational credentials once such
118118
credentials are supported.
@@ -141,7 +141,7 @@ def Connect(discriminator: int, pin: int, deprecated_nodeid: Optional[int] = Non
141141
the device
142142
pin: the pin number used to pair with the device (must match the
143143
device secret pin, typically available in a QR code)
144-
deprecated_nodeid: TEMPORARY, TO BE REMOVED nodeid that will be set during
144+
deprecated_nodeid: TEMPORARY, TO BE REMOVED node ID that will be set during
145145
the commissioning. This will be replaced by setting the node id
146146
at the time of setting operational credentials once such
147147
credentials are supported.

src/controller/python/matter/commissioning/commissioning_flow_blocks.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,16 @@ async def network_commissioning_thread(self, parameter: commissioning.Parameters
170170
raise TypeError("The device requires a Thread network dataset")
171171

172172
self._logger.info("Adding Thread network")
173-
response = await self._devCtrl.SendCommand(nodeid=node_id, endpoint=commissioning.ROOT_ENDPOINT_ID, payload=Clusters.NetworkCommissioning.Commands.AddOrUpdateThreadNetwork(
173+
response = await self._devCtrl.SendCommand(nodeId=node_id, endpoint=commissioning.ROOT_ENDPOINT_ID, payload=Clusters.NetworkCommissioning.Commands.AddOrUpdateThreadNetwork(
174174
operationalDataset=parameter.thread_credentials))
175175
if response.networkingStatus != Clusters.NetworkCommissioning.Enums.NetworkCommissioningStatusEnum.kSuccess:
176176
raise commissioning.CommissionFailure(f"Unexpected result for adding network: {response.networkingStatus}")
177177

178-
network_list = (await self._devCtrl.ReadAttribute(nodeid=node_id, attributes=[(commissioning.ROOT_ENDPOINT_ID, Clusters.NetworkCommissioning.Attributes.Networks)], returnClusterObject=True))[commissioning.ROOT_ENDPOINT_ID][Clusters.NetworkCommissioning].networks
178+
network_list = (await self._devCtrl.ReadAttribute(nodeId=node_id, attributes=[(commissioning.ROOT_ENDPOINT_ID, Clusters.NetworkCommissioning.Attributes.Networks)], returnClusterObject=True))[commissioning.ROOT_ENDPOINT_ID][Clusters.NetworkCommissioning].networks
179179
network_id = network_list[response.networkIndex].networkID
180180

181181
self._logger.info("Enabling Thread network")
182-
response = await self._devCtrl.SendCommand(nodeid=node_id, endpoint=commissioning.ROOT_ENDPOINT_ID, payload=Clusters.NetworkCommissioning.Commands.ConnectNetwork(networkID=network_id), interactionTimeoutMs=self._devCtrl.ComputeRoundTripTimeout(node_id, upperLayerProcessingTimeoutMs=30000))
182+
response = await self._devCtrl.SendCommand(nodeId=node_id, endpoint=commissioning.ROOT_ENDPOINT_ID, payload=Clusters.NetworkCommissioning.Commands.ConnectNetwork(networkID=network_id), interactionTimeoutMs=self._devCtrl.ComputeRoundTripTimeout(node_id, upperLayerProcessingTimeoutMs=30000))
183183
if response.networkingStatus != Clusters.NetworkCommissioning.Enums.NetworkCommissioningStatusEnum.kSuccess:
184184
raise commissioning.CommissionFailure(f"Unexpected result for enabling network: {response.networkingStatus}")
185185

@@ -190,29 +190,29 @@ async def network_commissioning_wifi(self, parameter: commissioning.Parameters,
190190
raise TypeError("The device requires WiFi credentials")
191191

192192
self._logger.info("Adding WiFi network")
193-
response = await self._devCtrl.SendCommand(nodeid=node_id, endpoint=commissioning.ROOT_ENDPOINT_ID, payload=Clusters.NetworkCommissioning.Commands.AddOrUpdateWiFiNetwork(ssid=parameter.wifi_credentials.ssid, credentials=parameter.wifi_credentials.passphrase))
193+
response = await self._devCtrl.SendCommand(nodeId=node_id, endpoint=commissioning.ROOT_ENDPOINT_ID, payload=Clusters.NetworkCommissioning.Commands.AddOrUpdateWiFiNetwork(ssid=parameter.wifi_credentials.ssid, credentials=parameter.wifi_credentials.passphrase))
194194
if response.networkingStatus != Clusters.NetworkCommissioning.Enums.NetworkCommissioningStatusEnum.kSuccess:
195195
raise commissioning.CommissionFailure(f"Unexpected result for adding network: {response.networkingStatus}")
196196

197-
network_list = (await self._devCtrl.ReadAttribute(nodeid=node_id, attributes=[(commissioning.ROOT_ENDPOINT_ID, Clusters.NetworkCommissioning.Attributes.Networks)], returnClusterObject=True))[commissioning.ROOT_ENDPOINT_ID][Clusters.NetworkCommissioning].networks
197+
network_list = (await self._devCtrl.ReadAttribute(nodeId=node_id, attributes=[(commissioning.ROOT_ENDPOINT_ID, Clusters.NetworkCommissioning.Attributes.Networks)], returnClusterObject=True))[commissioning.ROOT_ENDPOINT_ID][Clusters.NetworkCommissioning].networks
198198
network_id = network_list[response.networkIndex].networkID
199199

200200
self._logger.info("Enabling WiFi network")
201-
response = await self._devCtrl.SendCommand(nodeid=node_id, endpoint=commissioning.ROOT_ENDPOINT_ID, payload=Clusters.NetworkCommissioning.Commands.ConnectNetwork(networkID=network_id), interactionTimeoutMs=self._devCtrl.ComputeRoundTripTimeout(node_id, upperLayerProcessingTimeoutMs=30000))
201+
response = await self._devCtrl.SendCommand(nodeId=node_id, endpoint=commissioning.ROOT_ENDPOINT_ID, payload=Clusters.NetworkCommissioning.Commands.ConnectNetwork(networkID=network_id), interactionTimeoutMs=self._devCtrl.ComputeRoundTripTimeout(node_id, upperLayerProcessingTimeoutMs=30000))
202202
if response.networkingStatus != Clusters.NetworkCommissioning.Enums.NetworkCommissioningStatusEnum.kSuccess:
203203
raise commissioning.CommissionFailure(f"Unexpected result for enabling network: {response.networkingStatus}")
204204

205205
self._logger.info("WiFi network commissioning finished")
206206

207207
async def network_commissioning(self, parameter: commissioning.Parameters, node_id: int):
208-
clusters = await self._devCtrl.ReadAttribute(nodeid=node_id, attributes=[(Clusters.Descriptor.Attributes.ServerList)], returnClusterObject=True)
208+
clusters = await self._devCtrl.ReadAttribute(nodeId=node_id, attributes=[(Clusters.Descriptor.Attributes.ServerList)], returnClusterObject=True)
209209
if Clusters.NetworkCommissioning.id not in clusters[commissioning.ROOT_ENDPOINT_ID][Clusters.Descriptor].serverList:
210210
self._logger.info(
211211
f"Network commissioning cluster {commissioning.ROOT_ENDPOINT_ID} is not enabled on this device.")
212212
return
213213

214214
network_commissioning_cluster_state = (await self._devCtrl.ReadAttribute(
215-
nodeid=node_id,
215+
nodeId=node_id,
216216
attributes=[(commissioning.ROOT_ENDPOINT_ID, Clusters.NetworkCommissioning)], returnClusterObject=True))[0][Clusters.NetworkCommissioning]
217217

218218
if network_commissioning_cluster_state.networks:

src/controller/python/matter/discovery/__init__.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ class PendingDiscovery:
7474
"""Accumulator for ongoing discovery."""
7575
result: AggregatedDiscoveryResults
7676
callback: Callable[[AggregatedDiscoveryResults], None]
77-
expireTime: int
78-
firstResultTime: int
77+
expireTime: float
78+
firstResultTime: float
7979

8080

8181
@dataclass
@@ -199,16 +199,14 @@ def ComputeNextEventTimeoutSeconds(self):
199199
# define firstResultTime
200200

201201

202-
# All pending discovery operations awayting callback results
202+
# All pending discovery operations awaiting callback results
203203
_gPendingDiscoveries = _PendingDiscoveries()
204204

205205

206206
@DiscoverSuccessCallback_t
207207
def _DiscoverSuccess(fabric: int, node: int, interface: int, ip: str, port: int):
208208
peerId = PeerId(fabric, node)
209209
address = NodeAddress(interface, ip, port)
210-
211-
global _gPendingDiscoveries
212210
_gPendingDiscoveries.OnSuccess(peerId, address)
213211

214212

@@ -219,26 +217,21 @@ def _DiscoverFailure(fabric: int, node: int, errorCode: PyChipError):
219217
LOGGER.error("Discovery failure, error %d", errorCode.code)
220218

221219

222-
def FindAddressAsync(fabricid: int, nodeid: int, callback, timeout_ms=1000):
220+
def FindAddressAsync(fabricId: int, nodeId: int, callback, timeoutMs=1000):
223221
"""Discovers the IP address(es) of a node.
224222
225223
Args:
226-
fabricid: the fabric to which the node is attached
227-
nodeid: the node id to find
224+
fabricId: The fabric to which the node is attached.
225+
nodeId: The node ID to find.
228226
callback: Will be called once node resolution completes.
229227
"""
230228

231229
_GetDiscoveryLibraryHandle().pychip_discovery_set_callbacks(
232230
_DiscoverSuccess, _DiscoverFailure)
233231

234-
global _gPendingDiscoveries
235-
_gPendingDiscoveries.Start(
236-
PeerId(fabricid, nodeid),
237-
callback,
238-
timeout_ms
239-
)
232+
_gPendingDiscoveries.Start(PeerId(fabricId, nodeId), callback, timeoutMs)
240233

241-
res = _GetDiscoveryLibraryHandle().pychip_discovery_resolve(fabricid, nodeid)
234+
res = _GetDiscoveryLibraryHandle().pychip_discovery_resolve(fabricId, nodeId)
242235
res.raise_on_error()
243236

244237

@@ -258,8 +251,8 @@ def WaitForResult(self):
258251
return self.result
259252

260253

261-
def FindAddress(fabricid, nodeid, timeout_ms=1000):
254+
def FindAddress(fabricId: int, nodeId: int, timeoutMs=1000):
262255
"""Performs an address discovery for a node and returns the result."""
263256
finder = _SyncAddressFinder()
264-
FindAddressAsync(fabricid, nodeid, finder.Callback, timeout_ms)
257+
FindAddressAsync(fabricId, nodeId, finder.Callback, timeoutMs)
265258
return finder.WaitForResult()

src/controller/python/matter/utils/CommissioningBuildingBlocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async def GrantPrivilege(adminCtrl: ChipDeviceController, grantedCtrl: ChipDevic
5858
privilege: Privilege to grant to the granted controller. If None, no privilege is granted.
5959
targetNodeId: Target node to which the controller is granted privilege.
6060
targetCatTag: Target 32-bit CAT tag that is granted privilege.
61-
If provided, this will be used in the subject list instead of the nodeid of that of grantedCtrl.
61+
If provided, this will be used in the subject list instead of the nodeId of that of grantedCtrl.
6262
'''
6363
data = await adminCtrl.ReadAttribute(targetNodeId, [(Clusters.AccessControl.Attributes.Acl)])
6464
if 0 not in data:

0 commit comments

Comments
 (0)