Skip to content

Commit 2be8556

Browse files
Alami-Aminepimpalemahesh
authored andcommitted
[chip-repl] Fix Jupyter Notebooks and run them in CI (#37209)
* jupyterlab-git * Update Basic Interactions Notebook * Update Notebook: Access Control * Updating Multi Fabric Notebook * replace deprecated API get_loader * import chip.clusters within script * doc fix * Running Jupyter as part of CI
1 parent ff117fc commit 2be8556

9 files changed

+9308
-4505
lines changed

.github/workflows/tests.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,22 @@ jobs:
546546
scripts/run_in_python_env.sh out/venv 'src/python_testing/execute_python_tests.py --env-file /tmp/test_env.yaml --search-directory src/python_testing'
547547
scripts/run_in_python_env.sh out/venv 'scripts/tests/TestTimeSyncTrustedTimeSourceRunner.py --all-clusters out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app'
548548
549+
- name: Execute Jupyter Notebooks
550+
run: |
551+
scripts/run_in_build_env.sh './scripts/build_python.sh --jupyter-lab --install_virtual_env out/venv'
552+
./scripts/run_in_build_env.sh \
553+
"./scripts/build/build_examples.py \
554+
--target linux-x64-all-clusters-ipv6only-no-ble-no-wifi-clang-test \
555+
build \
556+
--copy-artifacts-to objdir-clone \
557+
"
558+
scripts/run_in_python_env.sh out/venv \
559+
"jupyter execute docs/development_controllers/chip-repl/Matter_REPL_Intro.ipynb \
560+
docs/development_controllers/chip-repl/Matter_Basic_Interactions.ipynb \
561+
docs/development_controllers/chip-repl/Matter_Access_Control.ipynb \
562+
docs/development_controllers/chip-repl/Matter_Multi_Fabric_Commissioning.ipynb \
563+
"
564+
549565
- name: Uploading core files
550566
uses: actions/upload-artifact@v4
551567
if: ${{ failure() && !env.ACT }}

docs/development_controllers/chip-repl/Matter_Access_Control.ipynb

+510-405
Large diffs are not rendered by default.

docs/development_controllers/chip-repl/Matter_Basic_Interactions.ipynb

+6,325-2,898
Large diffs are not rendered by default.

docs/development_controllers/chip-repl/Matter_Multi_Fabric_Commissioning.ipynb

+563-479
Large diffs are not rendered by default.

docs/development_controllers/chip-repl/Matter_REPL_Intro.ipynb

+1,867-700
Large diffs are not rendered by default.

docs/development_controllers/chip-repl/python_chip_controller_building.md

+17-15
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ To build and run the Python CHIP controller:
103103
chip-repl
104104
```
105105
106+
NOTE: To get more verbose logs, pass the debug flag: `chip-repl --debug`
107+
106108
<hr>
107109
108110
## Using Python CHIP Controller REPL for Matter accessory testing
@@ -133,8 +135,8 @@ An uncommissioned accessory device advertises over Bluetooth LE or via mDNS if
133135
already on the network. Run the following command to scan all advertised Matter
134136
devices:
135137
136-
```
137-
devCtrl.DiscoverCommissionableNodes()
138+
```python
139+
await devCtrl.DiscoverCommissionableNodes()
138140
```
139141

140142
### Step 4: Set network pairing credentials
@@ -173,7 +175,7 @@ network interface, such as Thread or Wi-Fi.
173175
2. Set the previously obtained Active Operational Dataset as a byte array using
174176
the following command:
175177
176-
```
178+
```python
177179
thread_dataset = bytes.fromhex("0e080000000000010000000300001335060004001fffe002084fe76e9a8b5edaf50708fde46f999f0698e20510d47f5027a414ffeebaefa92285cc84fa030f4f70656e5468726561642d653439630102e49c0410b92f8c7fbb4f9f3e08492ee3915fbd2f0c0402a0fff8")
178180
devCtrl.SetThreadOperationalDataset(thread_dataset)
179181
```
@@ -183,7 +185,7 @@ network interface, such as Thread or Wi-Fi.
183185
Assuming your Wi-Fi SSID is _TESTSSID_, and your Wi-Fi password is _P455W4RD_,
184186
set the credentials to the controller by executing the following command:
185187
186-
```
188+
```python
187189
devCtrl.SetWiFiCredentials(<ssid>, <password>)
188190
```
189191

@@ -213,8 +215,8 @@ with the following assumptions for the Matter accessory device:
213215
- The setup pin code of the device is _20202021_
214216
- The temporary Node ID is _1234_
215217

216-
```
217-
devCtrl.ConnectBLE(3840, 20202021, 1234)
218+
```python
219+
await devCtrl.ConnectBLE(3840, 20202021, 1234)
218220
```
219221

220222
You can skip the last parameter, the Node ID, in the command. If you skip it,
@@ -230,8 +232,8 @@ CHIP:SVR: SetupQRCode: [MT:-24J0AFN00KA0648G00]
230232

231233
Use the following command to commission the device with the QR code:
232234

233-
```
234-
devCtrl.CommissionWithCode("MT:-24J0AFN00KA0648G00", 1234)
235+
```python
236+
await devCtrl.CommissionWithCode("MT:-24J0AFN00KA0648G00", 1234)
235237
```
236238

237239
After connecting the device over Bluetooth LE, the controller will go through
@@ -262,14 +264,14 @@ the following stages:
262264
For the light bulb example, execute the following command to toggle the LED
263265
state:
264266

265-
```
267+
```python
266268
await devCtrl.SendCommand(1234, 1, Clusters.OnOff.Commands.Toggle())
267269
```
268270

269271
To change the brightness of the LED, use the following command, with the level
270272
value somewhere between 0 and 255.
271273

272-
```
274+
```python
273275
commandToSend = LevelControl.Commands.MoveToLevel(level=50, transitionTime=Null, optionsMask=0, optionsOverride=0)
274276
await devCtrl.SendCommand(1234, 1, commandToSend)
275277
```
@@ -281,7 +283,7 @@ maintains collection of attributes that a controller can obtain from a device,
281283
such as the vendor name, the product name, or software version. Use
282284
`ReadAttribute()` command to read those values from the device:
283285

284-
```
286+
```python
285287
attributes = [
286288
(0, Clusters.BasicInformation.Attributes.VendorName),
287289
(0, Clusters.BasicInformation.Attributes.ProductName),
@@ -309,7 +311,7 @@ the full list of available commands.
309311
Provides the controller with Thread network credentials that will be used in the
310312
device commissioning procedure to configure the device with a Thread interface.
311313

312-
```
314+
```python
313315
thread_dataset = bytes.fromhex("0e080000000000010000000300001335060004001fffe002084fe76e9a8b5edaf50708fde46f999f0698e20510d47f5027a414ffeebaefa92285cc84fa030f4f70656e5468726561642d653439630102e49c0410b92f8c7fbb4f9f3e08492ee3915fbd2f0c0402a0fff8")
314316
devCtrl.SetThreadOperationalDataset(thread_dataset)
315317
```
@@ -319,7 +321,7 @@ devCtrl.SetThreadOperationalDataset(thread_dataset)
319321
Provides the controller with Wi-Fi network credentials that will be used in the
320322
device commissioning procedure to configure the device with a Wi-Fi interface.
321323

322-
```
324+
```python
323325
devCtrl.SetWiFiCredentials('TESTSSID', 'P455W4RD')
324326
```
325327

@@ -328,8 +330,8 @@ devCtrl.SetWiFiCredentials('TESTSSID', 'P455W4RD')
328330
Commission with the given nodeid from the setupPayload. setupPayload may be a QR
329331
or the manual setup code.
330332

331-
```
332-
devCtrl.CommissionWithCode("MT:-24J0AFN00KA0648G00", 1234)
333+
```python
334+
await devCtrl.CommissionWithCode("MT:-24J0AFN00KA0648G00", 1234)
333335
```
334336

335337
### `SendCommand(<nodeid>: int, <endpoint>: int, Clusters.<cluster>.Commands.<command>(<arguments>))`

scripts/jupyterlab_requirements.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
# jupyter-lab
55
#
66
# --------------------------------------
7-
# import chip.native
8-
# import pkgutil
9-
# module = pkgutil.get_loader('chip.ChipReplStartup')
10-
# %run {module.path}
7+
# %reset -f
8+
# import importlib.util
9+
# spec = importlib.util.find_spec('chip.ChipReplStartup')
10+
# %run {spec.origin}
1111
# --------------------------------------
1212
#
1313

1414
jupyterlab
1515
ipykernel
1616
jupyterlab-lsp
1717
python-lsp-server
18+
jupyterlab-git

src/controller/python/chip-repl.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
def main():
2727
c = Config()
2828
c.InteractiveShellApp.exec_lines = [
29-
"import pkgutil",
30-
"module = pkgutil.get_loader('chip.ChipReplStartup')",
31-
"%run {module.path} " + " ".join(sys.argv[1:])
29+
"import importlib.util",
30+
"spec = importlib.util.find_spec('chip.ChipReplStartup')",
31+
"%run {spec.origin} " + " ".join(sys.argv[1:])
3232
]
3333

3434
sys.argv = [sys.argv[0]]

src/controller/python/chip/ChipReplStartup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pathlib
77

88
import chip.CertificateAuthority
9+
import chip.clusters as Clusters # noqa: F401
910
import chip.FabricAdmin
1011
import chip.logging
1112
import chip.native
@@ -163,7 +164,7 @@ def main():
163164
console.print(
164165
'''\t[red]certificateAuthorityManager[blue]:\tManages a list of CertificateAuthority instances.
165166
\t[red]caList[blue]:\t\t\t\tThe list of CertificateAuthority instances.
166-
\t[red]caList[n][m][blue]:\t\t\tA specific FabricAdmin object at index m for the nth CertificateAuthority instance.''')
167+
\t[red]caList\[n].adminList\[m][blue]:\t\tA specific FabricAdmin object at index m for the nth CertificateAuthority instance.''')
167168

168169
console.print(
169170
f'\n\n[blue]Default CHIP Device Controller (NodeId: {devCtrl.nodeId}): '

0 commit comments

Comments
 (0)