@matter/examples 0.15.2-alpha.0-20250703-2e16aba2b → 0.15.2-alpha.0-20250708-b8eb61a5e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2025 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { ServerNode } from "@matter/main";
7
+ import { OnOffClient } from "@matter/main/behaviors/on-off";
8
+ const controller = await ServerNode.create();
9
+ const [, , command, ...args] = process.argv.slice(2);
10
+ switch (command) {
11
+ case "commission":
12
+ if (controller.nodes.get("device")) {
13
+ die("There is already a device commissioned");
14
+ }
15
+ if (args.length !== 1) {
16
+ die(`Usage: ${process.argv[0]} commission <pairingcode>`);
17
+ }
18
+ const [pairingCode] = args;
19
+ await controller.nodes.commission({ id: "device", pairingCode });
20
+ break;
21
+ case "toggle":
22
+ {
23
+ const endpointNo = Number.parseInt(args[0]);
24
+ if (args.length !== 1 || Number.isNaN(endpointNo)) {
25
+ die(`Usage: ${process.argv[0]} toggle <endpoint number>`);
26
+ }
27
+ const node = controller.nodes.get("device");
28
+ if (node === void 0) {
29
+ die("Cannot toggle because there is no commissioned device");
30
+ }
31
+ const endpoint = node.parts.get(endpointNo);
32
+ if (endpoint === void 0) {
33
+ die(`Cannot toggle because endpoint ${endpointNo} does not exist`);
34
+ }
35
+ await endpoint.commandsOf(OnOffClient).toggle();
36
+ }
37
+ break;
38
+ case "decommission":
39
+ {
40
+ const node = controller.nodes.get("device");
41
+ if (node === void 0) {
42
+ die("Cannot decommission because there is no commissioned device");
43
+ }
44
+ await node.delete();
45
+ }
46
+ break;
47
+ default:
48
+ die(
49
+ `Unsupported command ${process.argv[1] ?? "(none)"}. Supported commands: commission, toggle, decommission`
50
+ );
51
+ }
52
+ function die(message) {
53
+ console.log(message);
54
+ process.exit(1);
55
+ }
56
+ //# sourceMappingURL=OnOffController.js.map
@@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AAAA,MACI,uBAAuB,QAAQ,KAAK,CAAC,KAAK,QAAQ;AAAA,IACtD;AACR;AAKA,SAAS,IAAI,SAAwB;AACjC,UAAQ,IAAI,OAAO;AACnB,UAAQ,KAAK,CAAC;AAClB;",
5
+ "names": []
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matter/examples",
3
- "version": "0.15.2-alpha.0-20250703-2e16aba2b",
3
+ "version": "0.15.2-alpha.0-20250708-b8eb61a5e",
4
4
  "description": "Matter.js examples and reference implementations",
5
5
  "keywords": [
6
6
  "iot",
@@ -55,14 +55,14 @@
55
55
  "matter-controller": "dist/esm/controller/ControllerNode.js"
56
56
  },
57
57
  "dependencies": {
58
- "@matter/main": "0.15.2-alpha.0-20250703-2e16aba2b",
59
- "@matter/nodejs": "0.15.2-alpha.0-20250703-2e16aba2b",
60
- "@matter/tools": "0.15.2-alpha.0-20250703-2e16aba2b",
61
- "@project-chip/matter.js": "0.15.2-alpha.0-20250703-2e16aba2b",
58
+ "@matter/main": "0.15.2-alpha.0-20250708-b8eb61a5e",
59
+ "@matter/nodejs": "0.15.2-alpha.0-20250708-b8eb61a5e",
60
+ "@matter/tools": "0.15.2-alpha.0-20250708-b8eb61a5e",
61
+ "@project-chip/matter.js": "0.15.2-alpha.0-20250708-b8eb61a5e",
62
62
  "esbuild": "^0.25.2"
63
63
  },
64
64
  "optionalDependencies": {
65
- "@matter/nodejs-ble": "0.15.2-alpha.0-20250703-2e16aba2b"
65
+ "@matter/nodejs-ble": "0.15.2-alpha.0-20250708-b8eb61a5e"
66
66
  },
67
67
  "engines": {
68
68
  "node": ">=18.0.0"
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2025 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ /**
8
+ * This is simple command line application that demonstrates device control using the @matter/node API.
9
+ *
10
+ * This API is a work in progress and is not yet fully implemented.
11
+ */
12
+
13
+ import { ServerNode } from "@matter/main";
14
+ import { OnOffClient } from "@matter/main/behaviors/on-off";
15
+
16
+ // Create the controller
17
+ const controller = await ServerNode.create();
18
+
19
+ const [, , command, ...args] = process.argv.slice(2);
20
+
21
+ switch (command) {
22
+ case "commission":
23
+ // Validation
24
+ if (controller.nodes.get("device")) {
25
+ die("There is already a device commissioned");
26
+ }
27
+ if (args.length !== 1) {
28
+ die(`Usage: ${process.argv[0]} commission <pairingcode>`);
29
+ }
30
+ const [pairingCode] = args;
31
+
32
+ // This is the actual commissioning
33
+ await controller.nodes.commission({ id: "device", pairingCode });
34
+
35
+ break;
36
+
37
+ case "toggle":
38
+ {
39
+ // Validation
40
+ const endpointNo = Number.parseInt(args[0]);
41
+ if (args.length !== 1 || Number.isNaN(endpointNo)) {
42
+ die(`Usage: ${process.argv[0]} toggle <endpoint number>`);
43
+ }
44
+ const node = controller.nodes.get("device");
45
+ if (node === undefined) {
46
+ die("Cannot toggle because there is no commissioned device");
47
+ }
48
+ const endpoint = node.parts.get(endpointNo);
49
+ if (endpoint === undefined) {
50
+ die(`Cannot toggle because endpoint ${endpointNo} does not exist`);
51
+ }
52
+
53
+ // Invocation
54
+ await endpoint.commandsOf(OnOffClient).toggle();
55
+ }
56
+
57
+ break;
58
+
59
+ case "decommission":
60
+ {
61
+ // Validation
62
+ const node = controller.nodes.get("device");
63
+ if (node === undefined) {
64
+ die("Cannot decommission because there is no commissioned device");
65
+ }
66
+
67
+ // Decommission
68
+ await node.delete();
69
+ }
70
+ break;
71
+
72
+ default:
73
+ die(
74
+ `Unsupported command ${process.argv[1] ?? "(none)"}. Supported commands: commission, toggle, decommission`,
75
+ );
76
+ }
77
+
78
+ /**
79
+ * Report command line error and exit.
80
+ */
81
+ function die(message: string): never {
82
+ console.log(message);
83
+ process.exit(1);
84
+ }
@@ -0,0 +1,6 @@
1
+ # Simple light controller
2
+
3
+ This is an example of a simple Matter controller. A "controller" is a device that can add another device to a Matter
4
+ network. This process is called "commissioning".
5
+
6
+ In this case the device can add another device that supports the "on/off" cluster and toggle it on or off.