@project-chip/matter-node.js-examples 0.11.0-alpha.0-20240911-db8f7c80 → 0.11.0-alpha.0-20241007-547af42a8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. package/README.md +3 -271
  2. package/dist/esm/examples/BridgedDevicesNodeLegacy.js +5 -4
  3. package/dist/esm/examples/BridgedDevicesNodeLegacy.js.map +1 -2
  4. package/dist/esm/examples/ComposedDeviceNodeLegacy.js +4 -3
  5. package/dist/esm/examples/ComposedDeviceNodeLegacy.js.map +1 -2
  6. package/dist/esm/examples/ControllerNodeLegacy.js +7 -6
  7. package/dist/esm/examples/ControllerNodeLegacy.js.map +1 -2
  8. package/dist/esm/examples/DeviceNodeFullLegacy.js +8 -6
  9. package/dist/esm/examples/DeviceNodeFullLegacy.js.map +1 -2
  10. package/dist/esm/examples/LegacyStorageConverter.js +2 -2
  11. package/dist/esm/examples/LegacyStorageConverter.js.map +0 -1
  12. package/dist/esm/examples/MultiDeviceNodeLegacy.js +5 -4
  13. package/dist/esm/examples/MultiDeviceNodeLegacy.js.map +1 -2
  14. package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServerLegacy.js +7 -6
  15. package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServerLegacy.js.map +1 -2
  16. package/dist/esm/package.json +3 -0
  17. package/package.json +16 -37
  18. package/src/examples/BridgedDevicesNodeLegacy.ts +4 -3
  19. package/src/examples/ComposedDeviceNodeLegacy.ts +4 -3
  20. package/src/examples/ControllerNodeLegacy.ts +6 -5
  21. package/src/examples/DeviceNodeFullLegacy.ts +7 -5
  22. package/src/examples/LegacyStorageConverter.ts +2 -2
  23. package/src/examples/MultiDeviceNodeLegacy.ts +4 -4
  24. package/src/examples/cluster/DummyWifiNetworkCommissioningServerLegacy.ts +7 -6
  25. package/src/tsconfig.json +13 -13
  26. package/dist/esm/examples/BridgedDevicesNode.js +0 -144
  27. package/dist/esm/examples/BridgedDevicesNode.js.map +0 -7
  28. package/dist/esm/examples/ComposedDeviceNode.js +0 -123
  29. package/dist/esm/examples/ComposedDeviceNode.js.map +0 -7
  30. package/dist/esm/examples/ControllerNode.js +0 -194
  31. package/dist/esm/examples/ControllerNode.js.map +0 -7
  32. package/dist/esm/examples/DeviceNode.js +0 -127
  33. package/dist/esm/examples/DeviceNode.js.map +0 -7
  34. package/dist/esm/examples/DeviceNodeFull.js +0 -253
  35. package/dist/esm/examples/DeviceNodeFull.js.map +0 -7
  36. package/dist/esm/examples/IlluminatedRollerShade.js +0 -60
  37. package/dist/esm/examples/IlluminatedRollerShade.js.map +0 -7
  38. package/dist/esm/examples/LightDevice.js +0 -35
  39. package/dist/esm/examples/LightDevice.js.map +0 -7
  40. package/dist/esm/examples/MultiDeviceNode.js +0 -140
  41. package/dist/esm/examples/MultiDeviceNode.js.map +0 -7
  42. package/dist/esm/examples/SensorDeviceNode.js +0 -175
  43. package/dist/esm/examples/SensorDeviceNode.js.map +0 -7
  44. package/dist/esm/examples/cluster/DummyThreadNetworkCommissioningServer.js +0 -121
  45. package/dist/esm/examples/cluster/DummyThreadNetworkCommissioningServer.js.map +0 -7
  46. package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServer.js +0 -121
  47. package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServer.js.map +0 -7
  48. package/dist/esm/examples/cluster/MyFancyOwnFunctionality.js +0 -110
  49. package/dist/esm/examples/cluster/MyFancyOwnFunctionality.js.map +0 -7
  50. package/dist/esm/tutorial/example01.js +0 -5
  51. package/dist/esm/tutorial/example01.js.map +0 -7
  52. package/dist/esm/tutorial/example02.js +0 -7
  53. package/dist/esm/tutorial/example02.js.map +0 -7
  54. package/dist/esm/tutorial/example03.js +0 -15
  55. package/dist/esm/tutorial/example03.js.map +0 -7
  56. package/dist/esm/tutorial/example04.js +0 -10
  57. package/dist/esm/tutorial/example04.js.map +0 -7
  58. package/dist/esm/tutorial/example05.js +0 -14
  59. package/dist/esm/tutorial/example05.js.map +0 -7
  60. package/src/examples/BridgedDevicesNode.ts +0 -259
  61. package/src/examples/ComposedDeviceNode.ts +0 -196
  62. package/src/examples/ControllerNode.ts +0 -314
  63. package/src/examples/DeviceNode.ts +0 -201
  64. package/src/examples/DeviceNodeFull.ts +0 -440
  65. package/src/examples/IlluminatedRollerShade.ts +0 -96
  66. package/src/examples/LightDevice.ts +0 -61
  67. package/src/examples/MultiDeviceNode.ts +0 -208
  68. package/src/examples/SensorDeviceNode.ts +0 -247
  69. package/src/examples/cluster/DummyThreadNetworkCommissioningServer.ts +0 -156
  70. package/src/examples/cluster/DummyWifiNetworkCommissioningServer.ts +0 -154
  71. package/src/examples/cluster/MyFancyOwnFunctionality.ts +0 -185
  72. package/src/tutorial/example01.ts +0 -6
  73. package/src/tutorial/example02.ts +0 -9
  74. package/src/tutorial/example03.ts +0 -19
  75. package/src/tutorial/example04.ts +0 -13
  76. package/src/tutorial/example05.ts +0 -19
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/examples/cluster/DummyWifiNetworkCommissioningServer.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Bytes } from \"@project-chip/matter.js-general\";\nimport { GeneralCommissioningBehavior } from \"@project-chip/matter.js/behavior/definitions/general-commissioning\";\nimport { NetworkCommissioningBehavior } from \"@project-chip/matter.js/behavior/definitions/network-commissioning\";\nimport { NetworkCommissioning } from \"@project-chip/matter.js/cluster\";\n\nconst firstNetworkId = new Uint8Array(32);\n\n/**\n * This represents a Dummy version of a Wifi Network Commissioning Cluster Server without real Wifi related logic, beside\n * returning some values provided as CLI parameters. This dummy implementation is only there for tests/as showcase for BLE\n * commissioning of a device.\n */\nexport class DummyWifiNetworkCommissioningServer extends NetworkCommissioningBehavior.with(\n NetworkCommissioning.Feature.WiFiNetworkInterface,\n) {\n override scanNetworks({ ssid, breadcrumb }: NetworkCommissioning.ScanNetworksRequest) {\n console.log(\n `---> scanNetworks called on NetworkCommissioning cluster: ${ssid ? Bytes.toHex(ssid) : undefined} ${breadcrumb}`,\n );\n\n // Simulate successful scan\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);\n generalCommissioningCluster.state.breadcrumb = breadcrumb;\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n this.state.lastNetworkingStatus = networkingStatus;\n\n return {\n networkingStatus,\n wiFiScanResults: [\n {\n security: {\n unencrypted: false,\n wep: false,\n wpaPersonal: false,\n wpa2Personal: true,\n wpa3Personal: true,\n },\n ssid: ssid || Bytes.fromString(this.endpoint.env.vars.get(\"ble.wifi.scanSsid\") ?? \"TestSSID\"), // Set a valid existing local Wi-Fi SSID here\n bssid: Bytes.fromString(this.endpoint.env.vars.get(\"ble.wifi.scanBssid\") ?? \"00:00:00:00:00:00\"),\n channel: 1,\n },\n ],\n };\n }\n\n override addOrUpdateWiFiNetwork({\n ssid,\n credentials,\n breadcrumb,\n }: NetworkCommissioning.AddOrUpdateWiFiNetworkRequest) {\n console.log(\n `---> addOrUpdateWiFiNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(ssid)} ${Bytes.toHex(credentials)} ${breadcrumb}`,\n );\n\n this.session.context.assertFailSafeArmed(\"Failsafe timer needs to be armed to add or update networks.\");\n\n // Simulate successful add or update\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);\n generalCommissioningCluster.state.breadcrumb = breadcrumb;\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n this.state.lastNetworkingStatus = networkingStatus;\n this.state.lastNetworkId = firstNetworkId;\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n }\n\n override removeNetwork({ networkId, breadcrumb }: NetworkCommissioning.RemoveNetworkRequest) {\n console.log(\n `---> removeNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`,\n );\n\n this.session.context.assertFailSafeArmed(\"Failsafe timer needs to be armed to add or update networks.\");\n\n // Simulate successful add or update\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);\n generalCommissioningCluster.state.breadcrumb = breadcrumb;\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n this.state.lastNetworkingStatus = networkingStatus;\n this.state.lastNetworkId = firstNetworkId;\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n }\n\n override async connectNetwork({ networkId, breadcrumb }: NetworkCommissioning.ConnectNetworkRequest) {\n console.log(\n `---> connectNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`,\n );\n\n this.session.context.assertFailSafeArmed(\"Failsafe timer needs to be armed to add or update networks.\");\n\n // Simulate successful connection\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);\n generalCommissioningCluster.state.breadcrumb = breadcrumb;\n }\n\n this.state.networks[0].connected = true;\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n this.state.lastNetworkingStatus = networkingStatus;\n this.state.lastNetworkId = firstNetworkId;\n this.state.lastConnectErrorValue = null;\n\n // Announce operational in IP network\n const device = this.session.context;\n await device.startAnnouncement();\n\n return {\n networkingStatus,\n errorValue: null,\n };\n }\n\n override reorderNetwork({ networkId, networkIndex, breadcrumb }: NetworkCommissioning.ReorderNetworkRequest) {\n console.log(\n `---> reorderNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${networkIndex} ${breadcrumb}`,\n );\n\n // Simulate successful connection\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);\n generalCommissioningCluster.state.breadcrumb = breadcrumb;\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n this.state.lastNetworkingStatus = networkingStatus;\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n }\n}\n"],
5
- "mappings": "AAAA;AAAA;AAAA;AAAA;A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AA+C;AACzG,YAAQ;AAAA,MACJ,+DAA+D,MAAM,MAAM,SAAS,CAAC,IAAI,YAAY,IAAI,UAAU;AAAA,IACvH;AAGA,QAAI,eAAe,QAAW;AAC1B,YAAM,8BAA8B,KAAK,MAAM,IAAI,4BAA4B;AAC/E,kCAA4B,MAAM,aAAa;AAAA,IACnD;AAEA,UAAM,mBAAmB,qBAAqB,2BAA2B;AACzE,SAAK,MAAM,uBAAuB;AAElC,WAAO;AAAA,MACH;AAAA,MACA,cAAc;AAAA,IAClB;AAAA,EACJ;AACJ;",
6
- "names": []
7
- }
@@ -1,110 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2022-2024 Matter.js Authors
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import {
7
- AttributeElement,
8
- ClusterElement,
9
- ClusterModel,
10
- CommandElement,
11
- EventElement,
12
- FieldElement
13
- } from "@project-chip/matter.js-model";
14
- import { ClusterBehavior } from "@project-chip/matter.js/behavior/cluster";
15
- import {
16
- Attribute,
17
- ClusterRegistry,
18
- Command,
19
- Event,
20
- EventPriority,
21
- MutableCluster
22
- } from "@project-chip/matter.js/cluster";
23
- import { ClusterId, VendorId } from "@project-chip/matter.js/datatype";
24
- import { TlvField, TlvInt16, TlvNullable, TlvObject, TlvString } from "@project-chip/matter.js/tlv";
25
- const myFancyClusterId = ClusterId.buildVendorSpecific(VendorId(65524), 64512);
26
- var MyFancyOwnFunctionality;
27
- ((MyFancyOwnFunctionality2) => {
28
- MyFancyOwnFunctionality2.TlvMyFancyCommandRequest = TlvObject({ value: TlvField(0, TlvString) });
29
- MyFancyOwnFunctionality2.TlvMyFancyCommandResponse = TlvObject({ response: TlvField(0, TlvString) });
30
- MyFancyOwnFunctionality2.TlvMyFancyEvent = TlvObject({ eventValue: TlvField(0, TlvString) });
31
- MyFancyOwnFunctionality2.ClusterInstance = MutableCluster({
32
- id: myFancyClusterId,
33
- name: "MyFancyOwnFunctionality",
34
- revision: 1,
35
- attributes: {
36
- /** My fancy attribute */
37
- myFancyValue: Attribute(0, TlvNullable(TlvInt16))
38
- },
39
- commands: {
40
- /** My fancy command */
41
- myFancyCommand: Command(1, MyFancyOwnFunctionality2.TlvMyFancyCommandRequest, 2, MyFancyOwnFunctionality2.TlvMyFancyCommandResponse)
42
- },
43
- events: {
44
- /** My fancy event */
45
- myFancyEvent: Event(5, EventPriority.Info, MyFancyOwnFunctionality2.TlvMyFancyEvent)
46
- }
47
- });
48
- MyFancyOwnFunctionality2.Cluster = MyFancyOwnFunctionality2.ClusterInstance;
49
- MyFancyOwnFunctionality2.Complete = MyFancyOwnFunctionality2.Cluster;
50
- })(MyFancyOwnFunctionality || (MyFancyOwnFunctionality = {}));
51
- const MyFancyOwnFunctionalityCluster = MyFancyOwnFunctionality.Cluster;
52
- ClusterRegistry.register(MyFancyOwnFunctionality.Complete);
53
- const MyFancySchema = ClusterElement({
54
- name: "MyFancyOwnFunctionality",
55
- id: myFancyClusterId,
56
- classification: "application",
57
- description: "My Fancy Functionality",
58
- children: [
59
- AttributeElement({ name: "ClusterRevision", id: 65533, type: "ClusterRevision", default: 1 }),
60
- AttributeElement({
61
- name: "MyFancyValue",
62
- id: 0,
63
- type: "int16",
64
- access: "R V",
65
- conformance: "M",
66
- quality: "X"
67
- }),
68
- CommandElement({
69
- name: "MyFancyCommand",
70
- id: 1,
71
- access: "O",
72
- conformance: "M",
73
- direction: "request",
74
- response: "MyFancyCommandResponse",
75
- children: [FieldElement({ name: "value", id: 0, type: "string", conformance: "M" })]
76
- }),
77
- CommandElement({
78
- name: "MyFancyCommandResponse",
79
- id: 2,
80
- conformance: "M",
81
- direction: "request",
82
- children: [FieldElement({ name: "response", id: 0, type: "string", conformance: "M" })]
83
- }),
84
- EventElement({
85
- name: "MyFancyEvent",
86
- id: 5,
87
- access: "V",
88
- conformance: "O",
89
- priority: "info",
90
- children: [
91
- FieldElement({
92
- name: "EventValue",
93
- id: 0,
94
- type: "string",
95
- conformance: "M"
96
- })
97
- ]
98
- })
99
- ]
100
- });
101
- const MyFancyOwnFunctionalityBehavior = ClusterBehavior.withInterface().for(
102
- MyFancyOwnFunctionality.Cluster,
103
- new ClusterModel(MyFancySchema)
104
- );
105
- export {
106
- MyFancyOwnFunctionality,
107
- MyFancyOwnFunctionalityBehavior,
108
- MyFancyOwnFunctionalityCluster
109
- };
110
- //# sourceMappingURL=MyFancyOwnFunctionality.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/examples/cluster/MyFancyOwnFunctionality.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Identity, MaybePromise } from \"@project-chip/matter.js-general\";\nimport {\n AttributeElement,\n ClusterElement,\n ClusterModel,\n CommandElement,\n EventElement,\n FieldElement,\n} from \"@project-chip/matter.js-model\";\nimport { ClusterBehavior } from \"@project-chip/matter.js/behavior/cluster\";\nimport {\n Attribute,\n ClusterRegistry,\n Command,\n Event,\n EventPriority,\n MutableCluster,\n} from \"@project-chip/matter.js/cluster\";\nimport { ClusterId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport { TlvField, TlvInt16, TlvNullable, TlvObject, TlvString, TypeFromSchema } from \"@project-chip/matter.js/tlv\";\n\n/** Define the Cluster ID, custom clusters use a special extended formt that also contains the Vendor Id */\nconst myFancyClusterId = ClusterId.buildVendorSpecific(VendorId(0xfff4), 0xfc00);\n\n/**\n * Defines the Cluster on Tlv Schema level in a special namespace structure to match the official cluster\n * structures of matter.js.\n * All places that contains \"MyFancy...\" belong to the custom cluster details, all rest can be left statically like the\n * given names.\n * For more examples and usages of features in such clusters and how the code should look then check the standard\n * cluster Tlv definitions in packages/matter.js/cluster/definitions/*\n */\nexport namespace MyFancyOwnFunctionality {\n /**\n * Input to the MyFancyOwnFunctionality myFancyCommand command\n */\n export const TlvMyFancyCommandRequest = TlvObject({ value: TlvField(0, TlvString) });\n\n /**\n * Response of the MyFancyOwnFunctionality myFancyCommand command\n */\n export const TlvMyFancyCommandResponse = TlvObject({ response: TlvField(0, TlvString) });\n\n /**\n * Event for the MyFancyOwnFunctionality myFancyEvent event\n */\n export const TlvMyFancyEvent = TlvObject({ eventValue: TlvField(0, TlvString) });\n\n /**\n * @see {@link Cluster}\n */\n export const ClusterInstance = MutableCluster({\n id: myFancyClusterId,\n name: \"MyFancyOwnFunctionality\",\n revision: 1,\n\n attributes: {\n /** My fancy attribute */\n myFancyValue: Attribute(0x0, TlvNullable(TlvInt16)),\n },\n\n commands: {\n /** My fancy command */\n myFancyCommand: Command(0x1, TlvMyFancyCommandRequest, 0x2, TlvMyFancyCommandResponse),\n },\n\n events: {\n /** My fancy event */\n myFancyEvent: Event(0x5, EventPriority.Info, TlvMyFancyEvent),\n },\n });\n\n /**\n * My Fancy Cluster\n *\n * This cluster provides an interface to some fancy custom functions.\n */\n export interface Cluster extends Identity<typeof ClusterInstance> {}\n\n export const Cluster: Cluster = ClusterInstance;\n\n export const Complete = Cluster;\n}\n\nexport type MyFancyOwnFunctionalityCluster = MyFancyOwnFunctionality.Cluster;\nexport const MyFancyOwnFunctionalityCluster = MyFancyOwnFunctionality.Cluster;\nClusterRegistry.register(MyFancyOwnFunctionality.Complete);\n\n/**\n * matter.js Model Schema for the cluster, need to match with the Tlv Schema above.\n * See more details in packages/matter.js/behavior/definitions/*\n */\nconst MyFancySchema = ClusterElement({\n name: \"MyFancyOwnFunctionality\",\n id: myFancyClusterId,\n classification: \"application\",\n description: \"My Fancy Functionality\",\n\n children: [\n AttributeElement({ name: \"ClusterRevision\", id: 0xfffd, type: \"ClusterRevision\", default: 1 }),\n\n AttributeElement({\n name: \"MyFancyValue\",\n id: 0x0,\n type: \"int16\",\n access: \"R V\",\n conformance: \"M\",\n quality: \"X\",\n }),\n\n CommandElement({\n name: \"MyFancyCommand\",\n id: 0x1,\n access: \"O\",\n conformance: \"M\",\n direction: \"request\",\n response: \"MyFancyCommandResponse\",\n\n children: [FieldElement({ name: \"value\", id: 0x0, type: \"string\", conformance: \"M\" })],\n }),\n CommandElement({\n name: \"MyFancyCommandResponse\",\n id: 0x2,\n conformance: \"M\",\n direction: \"request\",\n\n children: [FieldElement({ name: \"response\", id: 0x0, type: \"string\", conformance: \"M\" })],\n }),\n\n EventElement({\n name: \"MyFancyEvent\",\n id: 0x5,\n access: \"V\",\n conformance: \"O\",\n priority: \"info\",\n children: [\n FieldElement({\n name: \"EventValue\",\n id: 0x0,\n type: \"string\",\n conformance: \"M\",\n }),\n ],\n }),\n ],\n});\n\n/**\n * Interface definitions - exposes the Implementation interface for the cluster and some types to be used in the\n * cluster implementations.\n */\nexport type MyFancyCommandRequest = TypeFromSchema<typeof MyFancyOwnFunctionality.TlvMyFancyCommandRequest>;\nexport type MyFancyCommandResponse = TypeFromSchema<typeof MyFancyOwnFunctionality.TlvMyFancyCommandResponse>;\nexport type MyFancyEvent = TypeFromSchema<typeof MyFancyOwnFunctionality.TlvMyFancyEvent>;\n\nexport namespace MyFancyOwnFunctionalityInterface {\n export interface Base {\n myFancyCommand(request: MyFancyCommandRequest): MaybePromise<MyFancyCommandResponse>;\n }\n}\n\nexport type MyFancyOwnFunctionalityInterface = {\n components: [{ flags: {}; methods: MyFancyOwnFunctionalityInterface.Base }];\n};\n\n/**\n * Behavior definition for the cluster command handler implementation\n */\nexport const MyFancyOwnFunctionalityBehavior = ClusterBehavior.withInterface<MyFancyOwnFunctionalityInterface>().for(\n MyFancyOwnFunctionality.Cluster,\n new ClusterModel(MyFancySchema),\n);\n\ntype MyFancyOwnFunctionalityBehaviorType = InstanceType<typeof MyFancyOwnFunctionalityBehavior>;\nexport interface MyFancyOwnFunctionalityBehavior extends MyFancyOwnFunctionalityBehaviorType {}\ntype StateType = InstanceType<typeof MyFancyOwnFunctionalityBehavior.State>;\nexport namespace MyFancyOwnFunctionalityBehavior {\n export interface State extends StateType {}\n}\n"],
5
- "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAOA;AAAA,EACI;AA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AAAA,IACN,iBAAiB,EAAE,MAAM,mBAAmB,IAAI,OAAQ,MAAM,mBAAmB,SAAS,EAAE,CAAC;AAAA,IAE7F,iBAAiB;AAAA,MACb,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,SAAS;AAAA,IACb,CAAC;AAAA,IAED,eAAe;AAAA,MACX,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,WAAW;AAAA,MACX,UAAU;AAAA,MAEV,UAAU,CAAC,aAAa,EAAE,MAAM,SAAS,IAAI,GAAK,MAAM,UAAU,aAAa,IAAI,CAAC,CAAC;AAAA,IACzF,CAAC;AAAA,IACD,eAAe;AAAA,MACX,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,aAAa;AAAA,MACb,WAAW;AAAA,MAEX,UAAU,CAAC,aAAa,EAAE,MAAM,YAAY,IAAI,GAAK,MAAM,UAAU,aAAa,IAAI,CAAC,CAAC;AAAA,IAC5F,CAAC;AAAA,IAED,aAAa;AAAA,MACT,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,UAAU;AAAA,MACV,UAAU;AAAA,QACN,aAAa;AAAA,UACT,MAAM;AAAA,UACN,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,aAAa;AAAA,QACjB,CAAC;AAAA,MACL;AAAA,IACJ,CAAC;AAAA,EACL;AACJ,CAAC;AAuBM,MAAM,kCAAkC,gBAAgB,cAAgD,EAAE;AAAA,EAC7G,wBAAwB;AAAA,EACxB,IAAI,aAAa,aAAa;AAClC;",
6
- "names": ["MyFancyOwnFunctionality"]
7
- }
@@ -1,5 +0,0 @@
1
- import "@project-chip/matter.js-nodejs";
2
- import { ServerNode } from "@project-chip/matter.js/node";
3
- const node = await ServerNode.create();
4
- await node.run();
5
- //# sourceMappingURL=example01.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/tutorial/example01.ts"],
4
- "sourcesContent": ["import \"@project-chip/matter.js-nodejs\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\n\nconst node = await ServerNode.create();\n\nawait node.run();\n"],
5
- "mappings": "AAAA,OAAO;AACP,SAAS,kBAAkB;AAE3B,MAAM,OAAO,MAAM,WAAW,OAAO;AAErC,MAAM,KAAK,IAAI;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- import "@project-chip/matter.js-nodejs";
2
- import { OnOffLightDevice } from "@project-chip/matter.js/devices/OnOffLightDevice";
3
- import { ServerNode } from "@project-chip/matter.js/node";
4
- const node = await ServerNode.create();
5
- await node.add(OnOffLightDevice);
6
- await node.run();
7
- //# sourceMappingURL=example02.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/tutorial/example02.ts"],
4
- "sourcesContent": ["import \"@project-chip/matter.js-nodejs\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\n\nconst node = await ServerNode.create();\n\nawait node.add(OnOffLightDevice);\n\nawait node.run();\n"],
5
- "mappings": "AAAA,OAAO;AACP,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAE3B,MAAM,OAAO,MAAM,WAAW,OAAO;AAErC,MAAM,KAAK,IAAI,gBAAgB;AAE/B,MAAM,KAAK,IAAI;",
6
- "names": []
7
- }
@@ -1,15 +0,0 @@
1
- import "@project-chip/matter.js-nodejs";
2
- import { OnOffLightDevice, OnOffLightRequirements } from "@project-chip/matter.js/devices/OnOffLightDevice";
3
- import { ServerNode } from "@project-chip/matter.js/node";
4
- class MyOnOffServer extends OnOffLightRequirements.OnOffServer {
5
- on() {
6
- console.log("Turning on");
7
- }
8
- off() {
9
- console.log("Turning off");
10
- }
11
- }
12
- const node = await ServerNode.create();
13
- await node.add(OnOffLightDevice.with(MyOnOffServer));
14
- await node.run();
15
- //# sourceMappingURL=example03.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/tutorial/example03.ts"],
4
- "sourcesContent": ["import \"@project-chip/matter.js-nodejs\";\nimport { OnOffLightDevice, OnOffLightRequirements } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\n\nclass MyOnOffServer extends OnOffLightRequirements.OnOffServer {\n override on() {\n console.log(\"Turning on\");\n }\n\n override off() {\n console.log(\"Turning off\");\n }\n}\n\nconst node = await ServerNode.create();\n\nawait node.add(OnOffLightDevice.with(MyOnOffServer));\n\nawait node.run();\n"],
5
- "mappings": "AAAA,OAAO;AACP,SAAS,kBAAkB,8BAA8B;AACzD,SAAS,kBAAkB;AAE3B,MAAM,sBAAsB,uBAAuB,YAAY;AAAA,EAClD,KAAK;AACV,YAAQ,IAAI,YAAY;AAAA,EAC5B;AAAA,EAES,MAAM;AACX,YAAQ,IAAI,aAAa;AAAA,EAC7B;AACJ;AAEA,MAAM,OAAO,MAAM,WAAW,OAAO;AAErC,MAAM,KAAK,IAAI,iBAAiB,KAAK,aAAa,CAAC;AAEnD,MAAM,KAAK,IAAI;",
6
- "names": []
7
- }
@@ -1,10 +0,0 @@
1
- import "@project-chip/matter.js-nodejs";
2
- import { OnOffLightDevice } from "@project-chip/matter.js/devices/OnOffLightDevice";
3
- import { ServerNode } from "@project-chip/matter.js/node";
4
- const node = await ServerNode.create();
5
- const light = await node.add(OnOffLightDevice);
6
- light.events.onOff.onOff$Changed.on((newValue) => {
7
- console.log(`Light is ${newValue ? "on" : "off"}`);
8
- });
9
- await node.run();
10
- //# sourceMappingURL=example04.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/tutorial/example04.ts"],
4
- "sourcesContent": ["import \"@project-chip/matter.js-nodejs\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\n\nconst node = await ServerNode.create();\n\nconst light = await node.add(OnOffLightDevice);\n\nlight.events.onOff.onOff$Changed.on(newValue => {\n console.log(`Light is ${newValue ? \"on\" : \"off\"}`);\n});\n\nawait node.run();\n"],
5
- "mappings": "AAAA,OAAO;AACP,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAE3B,MAAM,OAAO,MAAM,WAAW,OAAO;AAErC,MAAM,QAAQ,MAAM,KAAK,IAAI,gBAAgB;AAE7C,MAAM,OAAO,MAAM,cAAc,GAAG,cAAY;AAC5C,UAAQ,IAAI,YAAY,WAAW,OAAO,KAAK,EAAE;AACrD,CAAC;AAED,MAAM,KAAK,IAAI;",
6
- "names": []
7
- }
@@ -1,14 +0,0 @@
1
- import "@project-chip/matter.js-nodejs";
2
- import { OnOffLightDevice } from "@project-chip/matter.js/devices/OnOffLightDevice";
3
- import { ServerNode } from "@project-chip/matter.js/node";
4
- const node = await ServerNode.create();
5
- const light = await node.add(OnOffLightDevice);
6
- await node.start();
7
- await light.act(async (agent) => {
8
- await agent.onOff.toggle();
9
- console.log("On/off state after first toggle", agent.onOff.state);
10
- await agent.onOff.toggle();
11
- console.log("On/off state after second toggle", agent.onOff.state);
12
- });
13
- await node.close();
14
- //# sourceMappingURL=example05.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/tutorial/example05.ts"],
4
- "sourcesContent": ["import \"@project-chip/matter.js-nodejs\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\n\nconst node = await ServerNode.create();\n\nconst light = await node.add(OnOffLightDevice);\n\nawait node.start();\n\nawait light.act(async agent => {\n await agent.onOff.toggle();\n console.log(\"On/off state after first toggle\", agent.onOff.state);\n\n await agent.onOff.toggle();\n console.log(\"On/off state after second toggle\", agent.onOff.state);\n});\n\nawait node.close();\n"],
5
- "mappings": "AAAA,OAAO;AACP,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAE3B,MAAM,OAAO,MAAM,WAAW,OAAO;AAErC,MAAM,QAAQ,MAAM,KAAK,IAAI,gBAAgB;AAE7C,MAAM,KAAK,MAAM;AAEjB,MAAM,MAAM,IAAI,OAAM,UAAS;AAC3B,QAAM,MAAM,MAAM,OAAO;AACzB,UAAQ,IAAI,mCAAmC,MAAM,MAAM,KAAK;AAEhE,QAAM,MAAM,MAAM,OAAO;AACzB,UAAQ,IAAI,oCAAoC,MAAM,MAAM,KAAK;AACrE,CAAC;AAED,MAAM,KAAK,MAAM;",
6
- "names": []
7
- }
@@ -1,259 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * @license
4
- * Copyright 2022-2024 Matter.js Authors
5
- * SPDX-License-Identifier: Apache-2.0
6
- */
7
-
8
- /**
9
- * This example shows how to create a new device node that is composed of multiple devices.
10
- * It creates multiple endpoints on the server. For information on how to add a composed device to a bridge please
11
- * refer to the bridge example!
12
- * It can be used as CLI script and starting point for your own device node implementation.
13
- */
14
-
15
- /**
16
- * Import needed modules from @project-chip/matter-node.js
17
- */
18
- // Include this first to auto-register Crypto, Network and Time Node.js implementations
19
- import { requireMinNodeVersion } from "@project-chip/matter.js-nodejs";
20
-
21
- import { Time } from "@project-chip/matter.js-general";
22
- import { BridgedDeviceBasicInformationServer } from "@project-chip/matter.js/behavior/definitions/bridged-device-basic-information";
23
- import { VendorId } from "@project-chip/matter.js/datatype";
24
- import { logEndpoint } from "@project-chip/matter.js/device";
25
- import { OnOffLightDevice } from "@project-chip/matter.js/devices/OnOffLightDevice";
26
- import { OnOffPlugInUnitDevice } from "@project-chip/matter.js/devices/OnOffPlugInUnitDevice";
27
- import { Endpoint, EndpointServer } from "@project-chip/matter.js/endpoint";
28
- import { AggregatorEndpoint } from "@project-chip/matter.js/endpoints/AggregatorEndpoint";
29
- import { Environment, StorageService } from "@project-chip/matter.js/environment";
30
- import { ServerNode } from "@project-chip/matter.js/node";
31
- import { execSync } from "child_process";
32
-
33
- requireMinNodeVersion(16);
34
-
35
- /** Initialize configuration values */
36
- const { isSocket, deviceName, vendorName, passcode, discriminator, vendorId, productName, productId, port, uniqueId } =
37
- await getConfiguration();
38
-
39
- /**
40
- * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration
41
- */
42
- const server = await ServerNode.create({
43
- // Required: Give the Node a unique ID which is used to store the state of this node
44
- id: uniqueId,
45
-
46
- // Provide Network relevant configuration like the port
47
- // Optional when operating only one device on a host, Default port is 5540
48
- network: {
49
- port,
50
- },
51
-
52
- // Provide Commissioning relevant settings
53
- // Optional for development/testing purposes
54
- commissioning: {
55
- passcode,
56
- discriminator,
57
- },
58
-
59
- // Provide Node announcement settings
60
- // Optional: If Ommitted some development defaults are used
61
- productDescription: {
62
- name: deviceName,
63
- deviceType: AggregatorEndpoint.deviceType,
64
- },
65
-
66
- // Provide defaults for the BasicInformation cluster on the Root endpoint
67
- // Optional: If Omitted some development defaults are used
68
- basicInformation: {
69
- vendorName,
70
- vendorId: VendorId(vendorId),
71
- nodeLabel: productName,
72
- productName,
73
- productLabel: productName,
74
- productId,
75
- serialNumber: `matterjs-${uniqueId}`,
76
- uniqueId,
77
- },
78
- });
79
-
80
- /**
81
- * Matter Nodes are a composition of endpoints. Create and add a single multiple endpoint to the node to make it a
82
- * composed device. This example uses the OnOffLightDevice or OnOffPlugInUnitDevice depending on the value of the type
83
- * parameter. It also assigns each Endpoint a unique ID to store the endpoint number for it in the storage to restore
84
- * the device on restart.
85
- *
86
- * In this case we directly use the default command implementation from matter.js. Check out the DeviceNodeFull example
87
- * to see how to customize the command handlers.
88
- */
89
-
90
- const aggregator = new Endpoint(AggregatorEndpoint, { id: "aggregator" });
91
- await server.add(aggregator);
92
-
93
- for (let idx = 0; idx < isSocket.length; idx++) {
94
- const i = idx + 1;
95
- const isASocket = isSocket[idx]; // Is the Device we add a Socket or a Light?
96
-
97
- const name = `OnOff ${isASocket ? "Socket" : "Light"} ${i}`;
98
-
99
- const endpoint = new Endpoint(
100
- isASocket
101
- ? // For a Bridged Device we need to add a BridgedDeviceBasicInformation cluster as server
102
- OnOffPlugInUnitDevice.with(BridgedDeviceBasicInformationServer)
103
- : OnOffLightDevice.with(BridgedDeviceBasicInformationServer),
104
- {
105
- id: `onoff-${i}`,
106
- bridgedDeviceBasicInformation: {
107
- nodeLabel: name, // Main end user name for the device
108
- productName: name,
109
- productLabel: name,
110
- serialNumber: `node-matter-${uniqueId}-${i}`,
111
- reachable: true,
112
- },
113
- },
114
- );
115
- await aggregator.add(endpoint);
116
-
117
- /**
118
- * Register state change handlers and events of the endpoint for identify and onoff states to react to the commands.
119
- *
120
- * If the code in these change handlers fail then the change is also rolled back and not executed and an error is
121
- * reported back to the controller.
122
- */
123
- endpoint.events.identify.startIdentifying.on(() => {
124
- console.log(`Run identify logic for ${name}, ideally blink a light every 0.5s ...`);
125
- });
126
-
127
- endpoint.events.identify.stopIdentifying.on(() => {
128
- console.log(`Stop identify logic for ${name} ...`);
129
- });
130
-
131
- endpoint.events.onOff.onOff$Changed.on(value => {
132
- executeCommand(value ? `on${i}` : `off${i}`);
133
- console.log(`${name} is now ${value ? "ON" : "OFF"}`);
134
- });
135
- }
136
-
137
- /**
138
- * In order to start the node and announce it into the network we use the run method which resolves when the node goes
139
- * offline again because we do not need anything more here. See the Full example for other starting options.
140
- * The QR Code is printed automatically.
141
- */
142
- await server.start();
143
-
144
- /**
145
- * Log the endpoint structure for debugging reasons and to allow to verify anything is correct
146
- */
147
- logEndpoint(EndpointServer.forEndpoint(server));
148
-
149
- /*
150
- If you want to dynamically add another device during runtime you can do so by doing the following:
151
-
152
- const name = `OnOff Light 3`;
153
-
154
- const endpoint = new Endpoint(OnOffLightDevice.with(BridgedDeviceBasicInformationServer), {
155
- id: `onoff-3`,
156
- bridgedDeviceBasicInformation: {
157
- nodeLabel: name,
158
- productName: name,
159
- productLabel: name,
160
- serialNumber: `node-matter-${uniqueId}-3`,
161
- reachable: true,
162
- },
163
- });
164
- await aggregator.add(endpoint);
165
-
166
- endpoint.events.onOff.onOff$Changed.on(value => {
167
- executeCommand(value ? `on3` : `off3`);
168
- console.log(`${name} is now ${value ? "ON" : "OFF"}`);
169
- });
170
-
171
- */
172
-
173
- /*
174
- To remove a device during runtime you can do so by doing the following:
175
- console.log("Removing Light 3 now!!");
176
-
177
- await endpoint.close();
178
-
179
- This will automatically remove the endpoint from the bridge.
180
- */
181
-
182
- /*********************************************************************************************************
183
- * Convenience Methods
184
- *********************************************************************************************************/
185
-
186
- /** Defined a shell command from an environment variable and execute it and log the response. */
187
- function executeCommand(scriptParamName: string) {
188
- const script = Environment.default.vars.string(scriptParamName);
189
- if (script === undefined) return undefined;
190
- console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);
191
- }
192
-
193
- async function getConfiguration() {
194
- /**
195
- * Collect all needed data
196
- *
197
- * This block collects all needed data from cli, environment or storage. Replace this with where ever your data come from.
198
- *
199
- * Note: This example uses the matter.js process storage system to store the device parameter data for convenience
200
- * and easy reuse. When you also do that be careful to not overlap with Matter-Server own storage contexts
201
- * (so maybe better not do it ;-)).
202
- */
203
- const environment = Environment.default;
204
-
205
- const storageService = environment.get(StorageService);
206
- console.log(`Storage location: ${storageService.location} (Directory)`);
207
- console.log(
208
- 'Use the parameter "--storage-path=NAME-OR-PATH" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',
209
- );
210
- const deviceStorage = (await storageService.open("device")).createContext("data");
211
-
212
- const isSocket = Array<boolean>();
213
- const numDevices = environment.vars.number("num") || 2;
214
- if (await deviceStorage.has("isSocket")) {
215
- console.log(`Device types found in storage. --type parameter is ignored.`);
216
- (await deviceStorage.get<Array<boolean>>("isSocket")).forEach(type => isSocket.push(type));
217
- }
218
- for (let i = 1; i <= numDevices; i++) {
219
- if (isSocket[i - 1] !== undefined) continue;
220
- isSocket.push(environment.vars.string(`type${i}`) === "socket");
221
- }
222
-
223
- const deviceName = "Matter test device";
224
- const vendorName = "matter-node.js";
225
- const passcode = environment.vars.number("passcode") ?? (await deviceStorage.get("passcode", 20202021));
226
- const discriminator = environment.vars.number("discriminator") ?? (await deviceStorage.get("discriminator", 3840));
227
- // product name / id and vendor id should match what is in the device certificate
228
- const vendorId = environment.vars.number("vendorid") ?? (await deviceStorage.get("vendorid", 0xfff1));
229
- const productName = `node-matter OnOff ${isSocket ? "Socket" : "Light"}`;
230
- const productId = environment.vars.number("productid") ?? (await deviceStorage.get("productid", 0x8000));
231
-
232
- const port = environment.vars.number("port") ?? 5540;
233
-
234
- const uniqueId =
235
- environment.vars.string("uniqueid") ?? (await deviceStorage.get("uniqueid", Time.nowMs().toString()));
236
-
237
- // Persist basic data to keep them also on restart
238
- await deviceStorage.set({
239
- passcode,
240
- discriminator,
241
- vendorid: vendorId,
242
- productid: productId,
243
- isSocket,
244
- uniqueid: uniqueId,
245
- });
246
-
247
- return {
248
- isSocket,
249
- deviceName,
250
- vendorName,
251
- passcode,
252
- discriminator,
253
- vendorId,
254
- productName,
255
- productId,
256
- port,
257
- uniqueId,
258
- };
259
- }