@project-chip/matter-node.js-examples 0.9.1 → 0.10.0-alpha.0-20240601-cba311a5

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ import { logEndpoint } from "@project-chip/matter.js/device";
11
11
  import { OnOffLightDevice } from "@project-chip/matter.js/devices/OnOffLightDevice";
12
12
  import { OnOffPlugInUnitDevice } from "@project-chip/matter.js/devices/OnOffPlugInUnitDevice";
13
13
  import { Endpoint, EndpointServer } from "@project-chip/matter.js/endpoint";
14
- import { AggregatorEndpoint } from "@project-chip/matter.js/endpoint/definitions";
14
+ import { AggregatorEndpoint } from "@project-chip/matter.js/endpoints/AggregatorEndpoint";
15
15
  import { Environment, StorageService } from "@project-chip/matter.js/environment";
16
16
  import { ServerNode } from "@project-chip/matter.js/node";
17
17
  import { Time } from "@project-chip/matter.js/time";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/BridgedDevicesNode.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a new device node that is composed of multiple devices.\n * It creates multiple endpoints on the server. For information on how to add a composed device to a bridge please\n * refer to the bridge example!\n * It can be used as CLI script and starting point for your own device node implementation.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { BridgedDeviceBasicInformationServer } from \"@project-chip/matter.js/behavior/definitions/bridged-device-basic-information\";\nimport { VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { OnOffPlugInUnitDevice } from \"@project-chip/matter.js/devices/OnOffPlugInUnitDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { AggregatorEndpoint } from \"@project-chip/matter.js/endpoint/definitions\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { execSync } from \"child_process\";\n\nrequireMinNodeVersion(16);\n\n/** Initialize configuration values */\nconst { isSocket, deviceName, vendorName, passcode, discriminator, vendorId, productName, productId, port, uniqueId } =\n await getConfiguration();\n\n/**\n * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration\n */\nconst server = await ServerNode.create({\n // Required: Give the Node a unique ID which is used to store the state of this node\n id: uniqueId,\n\n // Provide Network relevant configuration like the port\n // Optional when operating only one device on a host, Default port is 5540\n network: {\n port,\n },\n\n // Provide Commissioning relevant settings\n // Optional for development/testing purposes\n commissioning: {\n passcode,\n discriminator,\n },\n\n // Provide Node announcement settings\n // Optional: If Ommitted some development defaults are used\n productDescription: {\n name: deviceName,\n deviceType: AggregatorEndpoint.deviceType,\n },\n\n // Provide defaults for the BasicInformation cluster on the Root endpoint\n // Optional: If Omitted some development defaults are used\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `matterjs-${uniqueId}`,\n uniqueId,\n },\n});\n\n/**\n * Matter Nodes are a composition of endpoints. Create and add a single multiple endpoint to the node to make it a\n * composed device. This example uses the OnOffLightDevice or OnOffPlugInUnitDevice depending on the value of the type\n * parameter. It also assigns each Endpoint a unique ID to store the endpoint number for it in the storage to restore\n * the device on restart.\n *\n * In this case we directly use the default command implementation from matter.js. Check out the DeviceNodeFull example\n * to see how to customize the command handlers.\n */\n\nconst aggregator = new Endpoint(AggregatorEndpoint, { id: \"aggregator\" });\nawait server.add(aggregator);\n\nfor (let idx = 0; idx < isSocket.length; idx++) {\n const i = idx + 1;\n const isASocket = isSocket[idx]; // Is the Device we add a Socket or a Light?\n\n const name = `OnOff ${isASocket ? \"Socket\" : \"Light\"} ${i}`;\n\n const endpoint = new Endpoint(\n isASocket\n ? // For a Bridged Device we need to add a BridgedDeviceBasicInformation cluster as server\n OnOffPlugInUnitDevice.with(BridgedDeviceBasicInformationServer)\n : OnOffLightDevice.with(BridgedDeviceBasicInformationServer),\n {\n id: `onoff-${i}`,\n bridgedDeviceBasicInformation: {\n nodeLabel: name,\n productName: name,\n productLabel: name,\n serialNumber: `node-matter-${uniqueId}-${i}`,\n reachable: true,\n },\n },\n );\n await aggregator.add(endpoint);\n\n /**\n * Register state change handlers and events of the endpoint for identify and onoff states to react to the commands.\n *\n * If the code in these change handlers fail then the change is also rolled back and not executed and an error is\n * reported back to the controller.\n */\n endpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic for ${name}, ideally blink a light every 0.5s ...`);\n });\n\n endpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic for ${name} ...`);\n });\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? `on${i}` : `off${i}`);\n console.log(`${name} is now ${value ? \"ON\" : \"OFF\"}`);\n });\n}\n\n/**\n * In order to start the node and announce it into the network we use the run method which resolves when the node goes\n * offline again because we do not need anything more here. See the Full example for other starting options.\n * The QR Code is printed automatically.\n */\nawait server.bringOnline();\n\n/**\n * Log the endpoint structure for debugging reasons and to allow to verify anything is correct\n */\nlogEndpoint(EndpointServer.forEndpoint(server));\n\n/*\n If you want to dynamically add another device during runtime you can do so by doing the following:\n\n const name = `OnOff Light 3`;\n\n const endpoint = new Endpoint(OnOffLightDevice.with(BridgedDeviceBasicInformationServer), {\n id: `onoff-3`,\n bridgedDeviceBasicInformation: {\n nodeLabel: name,\n productName: name,\n productLabel: name,\n serialNumber: `node-matter-${uniqueId}-3`,\n reachable: true,\n },\n });\n await aggregator.add(endpoint);\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? `on3` : `off3`);\n console.log(`${name} is now ${value ? \"ON\" : \"OFF\"}`);\n });\n\n */\n\n/*\n To remove a device during runtime you can do so by doing the following:\n console.log(\"Removing Light 3 now!!\");\n\n await endpoint.close();\n\n This will automatically remove the endpoint from the bridge.\n */\n\n/*********************************************************************************************************\n * Convenience Methods\n *********************************************************************************************************/\n\n/** Defined a shell command from an environment variable and execute it and log the response. */\nfunction executeCommand(scriptParamName: string) {\n const script = Environment.default.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\nasync function getConfiguration() {\n /**\n * Collect all needed data\n *\n * This block collects all needed data from cli, environment or storage. Replace this with where ever your data come from.\n *\n * Note: This example uses the matter.js process storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own storage contexts\n * (so maybe better not do it ;-)).\n */\n const environment = Environment.default;\n\n const storageService = environment.get(StorageService);\n console.log(`Storage location: ${storageService.location} (Directory)`);\n console.log(\n '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.',\n );\n const deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n const isSocket = Array<boolean>();\n const numDevices = environment.vars.number(\"num\") || 2;\n if (await deviceStorage.has(\"isSocket\")) {\n console.log(`Device types found in storage. --type parameter is ignored.`);\n (await deviceStorage.get<Array<boolean>>(\"isSocket\")).forEach(type => isSocket.push(type));\n }\n for (let i = 1; i <= numDevices; i++) {\n if (isSocket[i - 1] !== undefined) continue;\n isSocket.push(environment.vars.string(`type${i}`) === \"socket\");\n }\n\n const deviceName = \"Matter test device\";\n const vendorName = \"matter-node.js\";\n const passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\n const discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\n const productName = `node-matter OnOff ${isSocket ? \"Socket\" : \"Light\"}`;\n const productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\n const port = environment.vars.number(\"port\") ?? 5540;\n\n const uniqueId =\n environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs().toString()));\n\n // Persist basic data to keep them also on restart\n await deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n isSocket,\n uniqueid: uniqueId,\n });\n\n return {\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n };\n}\n"],
4
+ "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a new device node that is composed of multiple devices.\n * It creates multiple endpoints on the server. For information on how to add a composed device to a bridge please\n * refer to the bridge example!\n * It can be used as CLI script and starting point for your own device node implementation.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { BridgedDeviceBasicInformationServer } from \"@project-chip/matter.js/behavior/definitions/bridged-device-basic-information\";\nimport { VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { OnOffPlugInUnitDevice } from \"@project-chip/matter.js/devices/OnOffPlugInUnitDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { AggregatorEndpoint } from \"@project-chip/matter.js/endpoints/AggregatorEndpoint\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { execSync } from \"child_process\";\n\nrequireMinNodeVersion(16);\n\n/** Initialize configuration values */\nconst { isSocket, deviceName, vendorName, passcode, discriminator, vendorId, productName, productId, port, uniqueId } =\n await getConfiguration();\n\n/**\n * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration\n */\nconst server = await ServerNode.create({\n // Required: Give the Node a unique ID which is used to store the state of this node\n id: uniqueId,\n\n // Provide Network relevant configuration like the port\n // Optional when operating only one device on a host, Default port is 5540\n network: {\n port,\n },\n\n // Provide Commissioning relevant settings\n // Optional for development/testing purposes\n commissioning: {\n passcode,\n discriminator,\n },\n\n // Provide Node announcement settings\n // Optional: If Ommitted some development defaults are used\n productDescription: {\n name: deviceName,\n deviceType: AggregatorEndpoint.deviceType,\n },\n\n // Provide defaults for the BasicInformation cluster on the Root endpoint\n // Optional: If Omitted some development defaults are used\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `matterjs-${uniqueId}`,\n uniqueId,\n },\n});\n\n/**\n * Matter Nodes are a composition of endpoints. Create and add a single multiple endpoint to the node to make it a\n * composed device. This example uses the OnOffLightDevice or OnOffPlugInUnitDevice depending on the value of the type\n * parameter. It also assigns each Endpoint a unique ID to store the endpoint number for it in the storage to restore\n * the device on restart.\n *\n * In this case we directly use the default command implementation from matter.js. Check out the DeviceNodeFull example\n * to see how to customize the command handlers.\n */\n\nconst aggregator = new Endpoint(AggregatorEndpoint, { id: \"aggregator\" });\nawait server.add(aggregator);\n\nfor (let idx = 0; idx < isSocket.length; idx++) {\n const i = idx + 1;\n const isASocket = isSocket[idx]; // Is the Device we add a Socket or a Light?\n\n const name = `OnOff ${isASocket ? \"Socket\" : \"Light\"} ${i}`;\n\n const endpoint = new Endpoint(\n isASocket\n ? // For a Bridged Device we need to add a BridgedDeviceBasicInformation cluster as server\n OnOffPlugInUnitDevice.with(BridgedDeviceBasicInformationServer)\n : OnOffLightDevice.with(BridgedDeviceBasicInformationServer),\n {\n id: `onoff-${i}`,\n bridgedDeviceBasicInformation: {\n nodeLabel: name,\n productName: name,\n productLabel: name,\n serialNumber: `node-matter-${uniqueId}-${i}`,\n reachable: true,\n },\n },\n );\n await aggregator.add(endpoint);\n\n /**\n * Register state change handlers and events of the endpoint for identify and onoff states to react to the commands.\n *\n * If the code in these change handlers fail then the change is also rolled back and not executed and an error is\n * reported back to the controller.\n */\n endpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic for ${name}, ideally blink a light every 0.5s ...`);\n });\n\n endpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic for ${name} ...`);\n });\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? `on${i}` : `off${i}`);\n console.log(`${name} is now ${value ? \"ON\" : \"OFF\"}`);\n });\n}\n\n/**\n * In order to start the node and announce it into the network we use the run method which resolves when the node goes\n * offline again because we do not need anything more here. See the Full example for other starting options.\n * The QR Code is printed automatically.\n */\nawait server.bringOnline();\n\n/**\n * Log the endpoint structure for debugging reasons and to allow to verify anything is correct\n */\nlogEndpoint(EndpointServer.forEndpoint(server));\n\n/*\n If you want to dynamically add another device during runtime you can do so by doing the following:\n\n const name = `OnOff Light 3`;\n\n const endpoint = new Endpoint(OnOffLightDevice.with(BridgedDeviceBasicInformationServer), {\n id: `onoff-3`,\n bridgedDeviceBasicInformation: {\n nodeLabel: name,\n productName: name,\n productLabel: name,\n serialNumber: `node-matter-${uniqueId}-3`,\n reachable: true,\n },\n });\n await aggregator.add(endpoint);\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? `on3` : `off3`);\n console.log(`${name} is now ${value ? \"ON\" : \"OFF\"}`);\n });\n\n */\n\n/*\n To remove a device during runtime you can do so by doing the following:\n console.log(\"Removing Light 3 now!!\");\n\n await endpoint.close();\n\n This will automatically remove the endpoint from the bridge.\n */\n\n/*********************************************************************************************************\n * Convenience Methods\n *********************************************************************************************************/\n\n/** Defined a shell command from an environment variable and execute it and log the response. */\nfunction executeCommand(scriptParamName: string) {\n const script = Environment.default.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\nasync function getConfiguration() {\n /**\n * Collect all needed data\n *\n * This block collects all needed data from cli, environment or storage. Replace this with where ever your data come from.\n *\n * Note: This example uses the matter.js process storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own storage contexts\n * (so maybe better not do it ;-)).\n */\n const environment = Environment.default;\n\n const storageService = environment.get(StorageService);\n console.log(`Storage location: ${storageService.location} (Directory)`);\n console.log(\n '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.',\n );\n const deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n const isSocket = Array<boolean>();\n const numDevices = environment.vars.number(\"num\") || 2;\n if (await deviceStorage.has(\"isSocket\")) {\n console.log(`Device types found in storage. --type parameter is ignored.`);\n (await deviceStorage.get<Array<boolean>>(\"isSocket\")).forEach(type => isSocket.push(type));\n }\n for (let i = 1; i <= numDevices; i++) {\n if (isSocket[i - 1] !== undefined) continue;\n isSocket.push(environment.vars.string(`type${i}`) === \"socket\");\n }\n\n const deviceName = \"Matter test device\";\n const vendorName = \"matter-node.js\";\n const passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\n const discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\n const productName = `node-matter OnOff ${isSocket ? \"Socket\" : \"Light\"}`;\n const productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\n const port = environment.vars.number(\"port\") ?? 5540;\n\n const uniqueId =\n environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs().toString()));\n\n // Persist basic data to keep them also on restart\n await deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n isSocket,\n uniqueid: uniqueId,\n });\n\n return {\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n };\n}\n"],
5
5
  "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,OAAO;AAEP,SAAS,6BAA6B;AACtC,SAAS,2CAA2C;AACpD,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,UAAU,sBAAsB;AACzC,SAAS,0BAA0B;AACnC,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AACrB,SAAS,gBAAgB;AAEzB,sBAAsB,EAAE;AAGxB,MAAM,EAAE,UAAU,YAAY,YAAY,UAAU,eAAe,UAAU,aAAa,WAAW,MAAM,SAAS,IAChH,MAAM,iBAAiB;AAK3B,MAAM,SAAS,MAAM,WAAW,OAAO;AAAA;AAAA,EAEnC,IAAI;AAAA;AAAA;AAAA,EAIJ,SAAS;AAAA,IACL;AAAA,EACJ;AAAA;AAAA;AAAA,EAIA,eAAe;AAAA,IACX;AAAA,IACA;AAAA,EACJ;AAAA;AAAA;AAAA,EAIA,oBAAoB;AAAA,IAChB,MAAM;AAAA,IACN,YAAY,mBAAmB;AAAA,EACnC;AAAA;AAAA;AAAA,EAIA,kBAAkB;AAAA,IACd;AAAA,IACA,UAAU,SAAS,QAAQ;AAAA,IAC3B,WAAW;AAAA,IACX;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA,cAAc,YAAY,QAAQ;AAAA,IAClC;AAAA,EACJ;AACJ,CAAC;AAYD,MAAM,aAAa,IAAI,SAAS,oBAAoB,EAAE,IAAI,aAAa,CAAC;AACxE,MAAM,OAAO,IAAI,UAAU;AAE3B,SAAS,MAAM,GAAG,MAAM,SAAS,QAAQ,OAAO;AAC5C,QA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AUS;AAAA,EACd,CAAC;AAED,SAAO;AAAA,IACH,UAAAT;AAAA,IACA,YAAAC;AAAA,IACA,YAAAC;AAAA,IACA,UAAAC;AAAA,IACA,eAAAC;AAAA,IACA,UAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,MAAAC;AAAA,IACA,UAAAC;AAAA,EACJ;AACJ;",
6
6
  "names": ["isSocket", "deviceName", "vendorName", "passcode", "discriminator", "vendorId", "productName", "productId", "port", "uniqueId"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/DeviceNodeFull.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example is not optimized for simplicity, but to show all the advanced use cases for matter.js.\n * If you want to see a simple minimalistic and more standard example please look at DeviceNode.ts or the other examples.\n *\n * This example shows how to create a simple on-off Matter device as a light or as a socket.\n * It can be used as CLI script and starting point for your own device node implementation.\n * Additional to this it shows the following:\n * * How to modify the existing clusters on Root and also Device Endpoints\n * * How to add own Cluster implementations for Standard clusters\n * * How to add a custom Cluster to an Endpoint\n * * Which events are available to get status information from the Node aon commissioning and session/subscription changes\n * * How to get cluster state values\n * * How to set one or multiple state values in a transaction.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { BleNode } from \"@project-chip/matter-node-ble.js/ble\";\nimport { createFileLogger } from \"@project-chip/matter-node.js/log\";\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { TestEventTriggerRequest } from \"@project-chip/matter.js/behavior/definitions/general-diagnostics\";\nimport { NetworkCommissioningServer } from \"@project-chip/matter.js/behavior/definitions/network-commissioning\";\nimport { OnOffServer } from \"@project-chip/matter.js/behavior/definitions/on-off\";\nimport { Ble } from \"@project-chip/matter.js/ble\";\nimport { NetworkCommissioning } from \"@project-chip/matter.js/cluster\";\nimport { DeviceTypeId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { OnOffPlugInUnitDevice } from \"@project-chip/matter.js/devices/OnOffPlugInUnitDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { RootRequirements } from \"@project-chip/matter.js/endpoint/definitions\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { FabricAction } from \"@project-chip/matter.js/fabric\";\nimport { Level, Logger, levelFromString } from \"@project-chip/matter.js/log\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { QrCode } from \"@project-chip/matter.js/schema\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { ByteArray, singleton } from \"@project-chip/matter.js/util\";\nimport { execSync } from \"child_process\";\nimport { DummyThreadNetworkCommissioningServer } from \"./cluster/DummyThreadNetworkCommissioningServer.js\";\nimport { DummyWifiNetworkCommissioningServer } from \"./cluster/DummyWifiNetworkCommissioningServer.js\";\nimport {\n MyFancyCommandRequest,\n MyFancyCommandResponse,\n MyFancyOwnFunctionalityBehavior,\n} from \"./cluster/MyFancyOwnFunctionality.js\";\n\n/**\n * The following code brings some convenience to the CLI script. It allows to set the log level and format via\n * command line parameters. It also initializes the BLE stack if the `--ble` parameter is present.\n * Some of these parameters can also be replaced by generically accepted parameters or even environment variables. See the comments in the relevant places for information.\n * When using this code as basis for your own device node implementation, you can remove this part or hard code it.\n */\n\nrequireMinNodeVersion(16);\n\n// To configure Logging use\n// * \"--log-level\" or environment variable \"MATTER_LOG_LEVEL\" or \"environment.vars.set('log.level', Level.DEBUG)\"\n// Allowed values are: Level.FATAL, Level.ERROR, Level.WARN, Level.NOTICE, Level.INFO, Level.DEBUG\n// * \"--log-format\" or environment variable \"MATTER_LOG_FORMAT\" or \"environment.vars.set('log.format', Format.PLAIN)\"\n// Allowed values are: Format.PLAIN, Format.HTML, Format.ANSI,\n\nconst environment = Environment.default;\n\n// Alternatively \"--ble-enable\" or environment variable \"BLE_ENABLED\"\n// Alternatively \"--ble-hciId\" or environment variable \"BLE_HCIID\"\nif (environment.vars.get(\"ble.enable\")) {\n // Initialize Ble\n Ble.get = singleton(\n () =>\n new BleNode({\n hciId: environment.vars.number(\"ble.hciId\"),\n }),\n );\n}\n\nfunction executeCommand(scriptParamName: string) {\n const script = environment.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\n/**\n * Collect all needed data\n *\n * This block collects all needed data from cli or storage. Replace this with where ever your data come from.\n *\n * Note: This example uses the matter.js process storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own storage contexts\n * (so maybe better not do it ;-)).\n */\n\nconst logFile = environment.vars.string(\"logfile.filename\");\nif (logFile !== undefined) {\n Logger.addLogger(\"filelogger\", await createFileLogger(logFile), {\n defaultLogLevel: levelFromString(environment.vars.string(\"logfile.loglevel\")) ?? Level.DEBUG,\n });\n}\n\nconst storageService = environment.get(StorageService);\nconsole.log(`Storage location: ${storageService.location} (Directory)`);\nconsole.log(\n '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.',\n);\n\nconst deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\nif (await deviceStorage.has(\"isSocket\")) {\n console.log(\"Device type found in storage. --type parameter is ignored.\");\n}\nconst isSocket = await deviceStorage.get(\"isSocket\", environment.vars.string(\"type\") === \"socket\");\nconst deviceName = \"Matter test device\";\nconst vendorName = \"matter-node.js\";\nconst passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\nconst discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n// product name / id and vendor id should match what is in the device certificate\nconst vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\nconst productName = `node-matter OnOff ${isSocket ? \"Socket\" : \"Light\"}`;\nconst productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\nconst port = environment.vars.number(\"port\") ?? 5540;\n\nconst uniqueId = environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs().toString()));\n\nawait deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n isSocket,\n uniqueid: uniqueId,\n});\n\n// Matter exposes functionality in groups called \"clusters\". For this example device we override the matter.js \"On/Off\"\n// cluster implementation to print status to the console.\nclass OnOffShellExecServer extends OnOffServer {\n // Intercept the \"on\" command to the Matter On/Off cluster to print a log message.\n override async on() {\n executeCommand(\"on\");\n await super.on();\n }\n\n // This is the functional inverse of on() above.\n //\n // For demonstration purposes we update state ourselves rather than deferring to matter.js's default \"off\" handler\n // via super.off().\n override async off() {\n executeCommand(\"off\");\n this.state.onOff = false;\n }\n\n // Use event handlers to log on/off state reactively, after it changes.\n override initialize() {\n this.events.onOff$Changed.on(value => {\n console.log(`Light is now ${value ? \"ON\" : \"OFF\"}`);\n });\n }\n}\n\nclass TestGeneralDiagnosticsServer extends RootRequirements.GeneralDiagnosticsServer {\n override initialize() {\n this.state.testEventTriggersEnabled = true; // set to true if you support test triggers ...\n super.initialize();\n }\n\n override testEventTrigger({ enableKey, eventTrigger }: TestEventTriggerRequest) {\n console.log(`testEventTrigger called on GeneralDiagnostic cluster: ${enableKey} ${eventTrigger}`);\n }\n}\n\nclass MyFancyOwnFunctionalityServer extends MyFancyOwnFunctionalityBehavior {\n /** We return the incoming value and store the length of the string in our attribute and send it out as event */\n override myFancyCommand(request: MyFancyCommandRequest): MyFancyCommandResponse {\n const { value } = request;\n this.state.myFancyValue = value.length;\n\n this.events.myFancyEvent.emit({ eventValue: value }, this.context);\n\n return { response: value };\n }\n\n override initialize() {\n this.state.myFancyValue = -1; // Always initialize with -1\n }\n}\n\n/**\n * Create Device instance and add needed Listener\n *\n * Create an instance of the matter device class you want to use.\n * This example uses the OnOffLightDevice or OnOffPluginUnitDevice depending on the value of the type parameter.\n * To execute the on/off scripts defined as parameters a listener for the onOff attribute is registered via the\n * device specific API.\n *\n * The below logic also adds command handlers for commands of clusters that normally are handled device internally\n * like identify that can be implemented with the logic when these commands are called.\n */\n\n// Devices are compositions of behaviors like OnOffServer above. To extend an existing device you use builder methods.\n//\n// In this case we are using with() to install our On/Off cluster behavior.\n// .with(\"LevelControlForLighting\") not needed because we always have it in by default because we have default implementation\nconst OnOffDevice = isSocket\n ? vendorId === 0xfff4\n ? OnOffPlugInUnitDevice.with(OnOffShellExecServer, MyFancyOwnFunctionalityServer)\n : OnOffPlugInUnitDevice.with(OnOffShellExecServer)\n : vendorId === 0xfff4\n ? OnOffLightDevice.with(OnOffShellExecServer, MyFancyOwnFunctionalityServer)\n : OnOffLightDevice.with(OnOffShellExecServer);\n\n/**\n * Modify automatically added clusters of the Root endpoint if needed\n * In this example we change the networkCommissioning cluster into one for \"Wifi only\" devices when BLE is used\n * for commissioning, to demonstrate how to do this.\n * If you want to implement Ethernet only devices that get connected to the network via LAN/Ethernet cable,\n * then all this is not needed.\n * The same as shown here for Wi-Fi is also possible theoretical for Thread only or combined devices.\n */\n\n// We use the Basic Root Endpoint without a NetworkCommissioning cluster\nlet RootEndpoint = ServerNode.RootEndpoint.with(TestGeneralDiagnosticsServer);\n\nlet wifiOrThreadAdded = false;\nif (Ble.enabled) {\n // matter.js will create a Ethernet-only device by default when ut comes to Network Commissioning Features.\n // To offer e.g. a \"Wi-Fi only device\" (or any other combination) we need to override the Network Commissioning\n // cluster and implement all the need handling here. This is a \"static implementation\" for pure demonstration\n // purposes and just \"simulates\" the actions to be done. In a real world implementation this would be done by\n // the device implementor based on the relevant networking stack.\n // The NetworkCommissioningCluster and all logics are described in Matter Core Specifications section 11.8\n if (environment.vars.has(\"ble.wifi.fake\")) {\n RootEndpoint = RootEndpoint.with(DummyWifiNetworkCommissioningServer);\n wifiOrThreadAdded = true;\n } else if (environment.vars.has(\"ble.thread.fake\")) {\n RootEndpoint = RootEndpoint.with(DummyThreadNetworkCommissioningServer);\n wifiOrThreadAdded = true;\n }\n} else {\n RootEndpoint = RootEndpoint.with(\n NetworkCommissioningServer.with(NetworkCommissioning.Feature.EthernetNetworkInterface),\n );\n}\n\nconst networkId = new ByteArray(32);\n// Physical devices appear as \"nodes\" on a Matter network. As a device implementer you use a NodeServer to bring a\n// device online.\n//\n// Note there are a large number of options to NodeServer that we are allowing to take default values here. See\n// CompositeWindowCovering.ts for a more detailed example.\nconst server = await ServerNode.create(RootEndpoint, {\n id: uniqueId,\n network: {\n port,\n discoveryCapabilities: {\n onIpNetwork: !environment.vars.has(\"ble.enable\"),\n ble: environment.vars.has(\"ble.enable\"),\n },\n ble: environment.vars.has(\"ble.enable\"), // TODO remove when state init is fixed\n },\n commissioning: {\n passcode,\n discriminator,\n },\n productDescription: {\n name: deviceName,\n deviceType: DeviceTypeId(OnOffDevice.deviceType),\n },\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `node-matter-${uniqueId}`,\n uniqueId,\n },\n\n // @ts-expect-error ... TS do not see the types because both next clusters was added conditionally\n networkCommissioning: {\n maxNetworks: 1,\n interfaceEnabled: true,\n lastConnectErrorValue: 0,\n lastNetworkId: wifiOrThreadAdded ? null : networkId,\n lastNetworkingStatus: wifiOrThreadAdded ? null : NetworkCommissioning.NetworkCommissioningStatus.Success,\n networks: [{ networkId: networkId, connected: !wifiOrThreadAdded }],\n scanMaxTimeSeconds: wifiOrThreadAdded ? 3 : undefined,\n connectMaxTimeSeconds: wifiOrThreadAdded ? 3 : undefined,\n },\n myFancyFunctionality: {\n myFancyValue: 0,\n },\n});\n\n// Nodes are a composition of endpoints. Add a single endpoint to the node, our example light device.\nconst endpoint = new Endpoint(OnOffDevice, { id: \"onoff\" });\nawait server.add(endpoint);\n\n/**\n * This event is triggered when the device is initially commissioned successfully.\n * This means: It is added to the first fabric.\n */\nserver.lifecycle.commissioned.on(() => console.log(\"Server was initially commissioned successfully!\"));\n\n/** This event is triggered when all fabrics are removed from the device, usually it also does a factory reset then. */\nserver.lifecycle.decommissioned.on(() => console.log(\"Server was fully decommissioned successfully!\"));\n\n/** This event is triggered when the device went online. This means that it is discoverable in the network. */\nserver.lifecycle.online.on(() => console.log(\"Server is online\"));\n\n/** This event is triggered when the device went offline. it is not longer discoverable or connectable in the network. */\nserver.lifecycle.offline.on(() => console.log(\"Server is offline\"));\n\n/**\n * This event is triggered when a fabric is added, removed or updated on the device. Use this if more granular\n * information is needed.\n */\nserver.events.commissioning.fabricsChanged.on((fabricIndex, fabricAction) => {\n let action = \"\";\n switch (fabricAction) {\n case FabricAction.Added:\n action = \"added\";\n break;\n case FabricAction.Removed:\n action = \"removed\";\n break;\n case FabricAction.Updated:\n action = \"updated\";\n break;\n }\n console.log(`Commissioned Fabrics changed event (${action}) for ${fabricIndex} triggered`);\n console.log(server.state.commissioning.fabrics[fabricIndex]);\n});\n\n/**\n * This event is triggered when an operative new session was opened by a Controller.\n * It is not triggered for the initial commissioning process, just afterwards for real connections.\n */\nserver.events.sessions.opened.on(session => console.log(`Session opened`, session));\n\n/**\n * This event is triggered when an operative session is closed by a Controller or because the Device goes offline.\n */\nserver.events.sessions.closed.on(session => console.log(`Session closed`, session));\n\n/** This event is triggered when a subscription gets added or removed on an operative session. */\nserver.events.sessions.subscriptionsChanged.on(session => {\n console.log(`Session subscriptions changed`, session);\n console.log(`Status of all sessions`, server.state.sessions.sessions);\n});\n\n// React on a change of identificationTime to do Identify stuff for the own device\nendpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic, ideally blink a light every 0.5s ...`);\n});\n\nendpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic ...`);\n});\n\n// Our device is now built and we can bring the node online.\n//\n// Note that you may serve multiple nodes from a single process. We only have one, however, so we can use the run()\n// method of the node.\n\nlogEndpoint(EndpointServer.forEndpoint(server));\n\n/**\n * In order to start the node and announce it into the network we start the node. This method resolves when the Matter\n * node enters his online state. Alternatively, we could also use `await server.run()` which\n * resolves when the node goes offline again, but we want to execute code afterwards, so we use start() here\n */\nawait server.bringOnline();\n\nconsole.log(\"Initial Fabrics\", server.state.operationalCredentials.fabrics);\n\n/**\n * If the node is not commissioned already we display the QR code on console. The QR code is also logged\n */\nif (!server.lifecycle.isCommissioned) {\n const { qrPairingCode, manualPairingCode } = server.state.commissioning.pairingCodes;\n\n console.log(QrCode.get(qrPairingCode));\n console.log(`QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`);\n console.log(`Manual pairing code: ${manualPairingCode}`);\n} else {\n console.log(\"Device is already commissioned. Waiting for controllers to connect ...\");\n\n /**\n * Sometimes reading or writing attributes is required. The following code shows how this works.\n * For read it is basically `endpoint.state.clustername.attributename`.\n * The set method allows to set one or multiple values via the structure of also clustername.attributename. When multiple values are set they are considered being one transaction which would be rolled back completely if one value fails to be set.\n */\n\n // Read onOff attribute from onOff cluster\n const onOffValue = endpoint.state.onOff.onOff;\n console.log(`current OnOff attribute: ${onOffValue}`);\n\n if (vendorId === 0xfff4) {\n // Set onOff attribute from OnOff cluster AND the myFancyValue of the MyFancyOwnFunctionality cluster together\n await endpoint.set({\n onOff: {\n onOff: !onOffValue,\n },\n // @ts-expect-error Needed because the Fancy cluster is added conditionally, so TS do not get that it's there.\n myFancyOwnFunctionality: {\n myFancyValue: 36,\n },\n });\n } else {\n // Set onOff attribute from OnOff cluster only\n await endpoint.set({\n onOff: {\n onOff: !onOffValue,\n },\n });\n }\n}\n\n/**\n * To correctly tear down the now we can use server[Symbol.asyncDispose]().\n */\nprocess.on(\"SIGINT\", () => {\n // Clean up on CTRL-C\n server\n .close()\n .then(() => process.exit(0))\n .catch(err => console.error(err));\n});\n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Q,IAAI,wBAAwB,iBAAiB,EAAE;AAC3D,OAAO;AACH,UAAQ,IAAI,wEAAwE;AASpF,QAAM,aAAa,SAAS,MAAM,MAAM;AACxC,UAAQ,IAAI,4BAA4B,UAAU,EAAE;AAEpD,MAAI,aAAa,OAAQ;AAErB,UAAM,SAAS,IAAI;AAAA,MACf,OAAO;AAAA,QACH,OAAO,CAAC;AAAA,MACZ;AAAA;AAAA,MAEA,yBAAyB;AAAA,QACrB,cAAc;AAAA,MAClB;AAAA,IACJ,CAAC;AAAA,EACL,OAAO;AAEH,UAAM,SAAS,IAAI;AAAA,MACf,OAAO;AAAA,QACH,OAAO,CAAC;AAAA,MACZ;AAAA,IACJ,CAAC;AAAA,EACL;AACJ;AAKA,QAAQ,GAAG,UAAU,MAAM;AAEvB,SACK,MAAM,EACN,KAAK,MAAM,QAAQ,KAAK,CAAC,CAAC,EAC1B,MAAM,SAAO,QAAQ,MAAM,GAAG,CAAC;AACxC,CAAC;",
4
+ "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example is not optimized for simplicity, but to show all the advanced use cases for matter.js.\n * If you want to see a simple minimalistic and more standard example please look at DeviceNode.ts or the other examples.\n *\n * This example shows how to create a simple on-off Matter device as a light or as a socket.\n * It can be used as CLI script and starting point for your own device node implementation.\n * Additional to this it shows the following:\n * * How to modify the existing clusters on Root and also Device Endpoints\n * * How to add own Cluster implementations for Standard clusters\n * * How to add a custom Cluster to an Endpoint\n * * Which events are available to get status information from the Node aon commissioning and session/subscription changes\n * * How to get cluster state values\n * * How to set one or multiple state values in a transaction.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { BleNode } from \"@project-chip/matter-node-ble.js/ble\";\nimport { GeneralDiagnostics } from \"@project-chip/matter-node.js/cluster\";\nimport { createFileLogger } from \"@project-chip/matter-node.js/log\";\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { NetworkCommissioningServer } from \"@project-chip/matter.js/behavior/definitions/network-commissioning\";\nimport { OnOffServer } from \"@project-chip/matter.js/behavior/definitions/on-off\";\nimport { Ble } from \"@project-chip/matter.js/ble\";\nimport { NetworkCommissioning } from \"@project-chip/matter.js/cluster\";\nimport { DeviceTypeId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { OnOffPlugInUnitDevice } from \"@project-chip/matter.js/devices/OnOffPlugInUnitDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { RootRequirements } from \"@project-chip/matter.js/endpoint/definitions\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { FabricAction } from \"@project-chip/matter.js/fabric\";\nimport { Level, Logger, levelFromString } from \"@project-chip/matter.js/log\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { QrCode } from \"@project-chip/matter.js/schema\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { ByteArray, singleton } from \"@project-chip/matter.js/util\";\nimport { execSync } from \"child_process\";\nimport { DummyThreadNetworkCommissioningServer } from \"./cluster/DummyThreadNetworkCommissioningServer.js\";\nimport { DummyWifiNetworkCommissioningServer } from \"./cluster/DummyWifiNetworkCommissioningServer.js\";\nimport {\n MyFancyCommandRequest,\n MyFancyCommandResponse,\n MyFancyOwnFunctionalityBehavior,\n} from \"./cluster/MyFancyOwnFunctionality.js\";\n\n/**\n * The following code brings some convenience to the CLI script. It allows to set the log level and format via\n * command line parameters. It also initializes the BLE stack if the `--ble` parameter is present.\n * Some of these parameters can also be replaced by generically accepted parameters or even environment variables. See the comments in the relevant places for information.\n * When using this code as basis for your own device node implementation, you can remove this part or hard code it.\n */\n\nrequireMinNodeVersion(16);\n\n// To configure Logging use\n// * \"--log-level\" or environment variable \"MATTER_LOG_LEVEL\" or \"environment.vars.set('log.level', Level.DEBUG)\"\n// Allowed values are: Level.FATAL, Level.ERROR, Level.WARN, Level.NOTICE, Level.INFO, Level.DEBUG\n// * \"--log-format\" or environment variable \"MATTER_LOG_FORMAT\" or \"environment.vars.set('log.format', Format.PLAIN)\"\n// Allowed values are: Format.PLAIN, Format.HTML, Format.ANSI,\n\nconst environment = Environment.default;\n\n// Alternatively \"--ble-enable\" or environment variable \"BLE_ENABLED\"\n// Alternatively \"--ble-hciId\" or environment variable \"BLE_HCIID\"\nif (environment.vars.get(\"ble.enable\")) {\n // Initialize Ble\n Ble.get = singleton(\n () =>\n new BleNode({\n hciId: environment.vars.number(\"ble.hciId\"),\n }),\n );\n}\n\nfunction executeCommand(scriptParamName: string) {\n const script = environment.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\n/**\n * Collect all needed data\n *\n * This block collects all needed data from cli or storage. Replace this with where ever your data come from.\n *\n * Note: This example uses the matter.js process storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own storage contexts\n * (so maybe better not do it ;-)).\n */\n\nconst logFile = environment.vars.string(\"logfile.filename\");\nif (logFile !== undefined) {\n Logger.addLogger(\"filelogger\", await createFileLogger(logFile), {\n defaultLogLevel: levelFromString(environment.vars.string(\"logfile.loglevel\")) ?? Level.DEBUG,\n });\n}\n\nconst storageService = environment.get(StorageService);\nconsole.log(`Storage location: ${storageService.location} (Directory)`);\nconsole.log(\n '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.',\n);\n\nconst deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\nif (await deviceStorage.has(\"isSocket\")) {\n console.log(\"Device type found in storage. --type parameter is ignored.\");\n}\nconst isSocket = await deviceStorage.get(\"isSocket\", environment.vars.string(\"type\") === \"socket\");\nconst deviceName = \"Matter test device\";\nconst vendorName = \"matter-node.js\";\nconst passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\nconst discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n// product name / id and vendor id should match what is in the device certificate\nconst vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\nconst productName = `node-matter OnOff ${isSocket ? \"Socket\" : \"Light\"}`;\nconst productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\nconst port = environment.vars.number(\"port\") ?? 5540;\n\nconst uniqueId = environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs().toString()));\n\nawait deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n isSocket,\n uniqueid: uniqueId,\n});\n\n// Matter exposes functionality in groups called \"clusters\". For this example device we override the matter.js \"On/Off\"\n// cluster implementation to print status to the console.\nclass OnOffShellExecServer extends OnOffServer {\n // Intercept the \"on\" command to the Matter On/Off cluster to print a log message.\n override async on() {\n executeCommand(\"on\");\n await super.on();\n }\n\n // This is the functional inverse of on() above.\n //\n // For demonstration purposes we update state ourselves rather than deferring to matter.js's default \"off\" handler\n // via super.off().\n override async off() {\n executeCommand(\"off\");\n this.state.onOff = false;\n }\n\n // Use event handlers to log on/off state reactively, after it changes.\n override initialize() {\n this.events.onOff$Changed.on(value => {\n console.log(`Light is now ${value ? \"ON\" : \"OFF\"}`);\n });\n }\n}\n\nclass TestGeneralDiagnosticsServer extends RootRequirements.GeneralDiagnosticsServer {\n override initialize() {\n this.state.testEventTriggersEnabled = true; // set to true if you support test triggers ...\n super.initialize();\n }\n\n override testEventTrigger({ enableKey, eventTrigger }: GeneralDiagnostics.TestEventTriggerRequest) {\n console.log(`testEventTrigger called on GeneralDiagnostic cluster: ${enableKey} ${eventTrigger}`);\n }\n}\n\nclass MyFancyOwnFunctionalityServer extends MyFancyOwnFunctionalityBehavior {\n /** We return the incoming value and store the length of the string in our attribute and send it out as event */\n override myFancyCommand(request: MyFancyCommandRequest): MyFancyCommandResponse {\n const { value } = request;\n this.state.myFancyValue = value.length;\n\n this.events.myFancyEvent.emit({ eventValue: value }, this.context);\n\n return { response: value };\n }\n\n override initialize() {\n this.state.myFancyValue = -1; // Always initialize with -1\n }\n}\n\n/**\n * Create Device instance and add needed Listener\n *\n * Create an instance of the matter device class you want to use.\n * This example uses the OnOffLightDevice or OnOffPluginUnitDevice depending on the value of the type parameter.\n * To execute the on/off scripts defined as parameters a listener for the onOff attribute is registered via the\n * device specific API.\n *\n * The below logic also adds command handlers for commands of clusters that normally are handled device internally\n * like identify that can be implemented with the logic when these commands are called.\n */\n\n// Devices are compositions of behaviors like OnOffServer above. To extend an existing device you use builder methods.\n//\n// In this case we are using with() to install our On/Off cluster behavior.\n// .with(\"Lighting\") not needed because we always have it in by default because we have default implementation\nconst OnOffDevice = isSocket\n ? vendorId === 0xfff4\n ? OnOffPlugInUnitDevice.with(OnOffShellExecServer, MyFancyOwnFunctionalityServer)\n : OnOffPlugInUnitDevice.with(OnOffShellExecServer)\n : vendorId === 0xfff4\n ? OnOffLightDevice.with(OnOffShellExecServer, MyFancyOwnFunctionalityServer)\n : OnOffLightDevice.with(OnOffShellExecServer);\n\n/**\n * Modify automatically added clusters of the Root endpoint if needed\n * In this example we change the networkCommissioning cluster into one for \"Wifi only\" devices when BLE is used\n * for commissioning, to demonstrate how to do this.\n * If you want to implement Ethernet only devices that get connected to the network via LAN/Ethernet cable,\n * then all this is not needed.\n * The same as shown here for Wi-Fi is also possible theoretical for Thread only or combined devices.\n */\n\n// We use the Basic Root Endpoint without a NetworkCommissioning cluster\nlet RootEndpoint = ServerNode.RootEndpoint.with(TestGeneralDiagnosticsServer);\n\nlet wifiOrThreadAdded = false;\nif (Ble.enabled) {\n // matter.js will create a Ethernet-only device by default when ut comes to Network Commissioning Features.\n // To offer e.g. a \"Wi-Fi only device\" (or any other combination) we need to override the Network Commissioning\n // cluster and implement all the need handling here. This is a \"static implementation\" for pure demonstration\n // purposes and just \"simulates\" the actions to be done. In a real world implementation this would be done by\n // the device implementor based on the relevant networking stack.\n // The NetworkCommissioningCluster and all logics are described in Matter Core Specifications section 11.8\n if (environment.vars.has(\"ble.wifi.fake\")) {\n RootEndpoint = RootEndpoint.with(DummyWifiNetworkCommissioningServer);\n wifiOrThreadAdded = true;\n } else if (environment.vars.has(\"ble.thread.fake\")) {\n RootEndpoint = RootEndpoint.with(DummyThreadNetworkCommissioningServer);\n wifiOrThreadAdded = true;\n }\n} else {\n RootEndpoint = RootEndpoint.with(\n NetworkCommissioningServer.with(NetworkCommissioning.Feature.EthernetNetworkInterface),\n );\n}\n\nconst networkId = new ByteArray(32);\n// Physical devices appear as \"nodes\" on a Matter network. As a device implementer you use a NodeServer to bring a\n// device online.\n//\n// Note there are a large number of options to NodeServer that we are allowing to take default values here. See\n// CompositeWindowCovering.ts for a more detailed example.\nconst server = await ServerNode.create(RootEndpoint, {\n id: uniqueId,\n network: {\n port,\n discoveryCapabilities: {\n onIpNetwork: !environment.vars.has(\"ble.enable\"),\n ble: environment.vars.has(\"ble.enable\"),\n },\n ble: environment.vars.has(\"ble.enable\"), // TODO remove when state init is fixed\n },\n commissioning: {\n passcode,\n discriminator,\n },\n productDescription: {\n name: deviceName,\n deviceType: DeviceTypeId(OnOffDevice.deviceType),\n },\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `node-matter-${uniqueId}`,\n uniqueId,\n },\n\n // @ts-expect-error ... TS do not see the types because both next clusters was added conditionally\n networkCommissioning: {\n maxNetworks: 1,\n interfaceEnabled: true,\n lastConnectErrorValue: 0,\n lastNetworkId: wifiOrThreadAdded ? null : networkId,\n lastNetworkingStatus: wifiOrThreadAdded ? null : NetworkCommissioning.NetworkCommissioningStatus.Success,\n networks: [{ networkId: networkId, connected: !wifiOrThreadAdded }],\n scanMaxTimeSeconds: wifiOrThreadAdded ? 3 : undefined,\n connectMaxTimeSeconds: wifiOrThreadAdded ? 3 : undefined,\n },\n myFancyFunctionality: {\n myFancyValue: 0,\n },\n});\n\n// Nodes are a composition of endpoints. Add a single endpoint to the node, our example light device.\nconst endpoint = new Endpoint(OnOffDevice, { id: \"onoff\" });\nawait server.add(endpoint);\n\n/**\n * This event is triggered when the device is initially commissioned successfully.\n * This means: It is added to the first fabric.\n */\nserver.lifecycle.commissioned.on(() => console.log(\"Server was initially commissioned successfully!\"));\n\n/** This event is triggered when all fabrics are removed from the device, usually it also does a factory reset then. */\nserver.lifecycle.decommissioned.on(() => console.log(\"Server was fully decommissioned successfully!\"));\n\n/** This event is triggered when the device went online. This means that it is discoverable in the network. */\nserver.lifecycle.online.on(() => console.log(\"Server is online\"));\n\n/** This event is triggered when the device went offline. it is not longer discoverable or connectable in the network. */\nserver.lifecycle.offline.on(() => console.log(\"Server is offline\"));\n\n/**\n * This event is triggered when a fabric is added, removed or updated on the device. Use this if more granular\n * information is needed.\n */\nserver.events.commissioning.fabricsChanged.on((fabricIndex, fabricAction) => {\n let action = \"\";\n switch (fabricAction) {\n case FabricAction.Added:\n action = \"added\";\n break;\n case FabricAction.Removed:\n action = \"removed\";\n break;\n case FabricAction.Updated:\n action = \"updated\";\n break;\n }\n console.log(`Commissioned Fabrics changed event (${action}) for ${fabricIndex} triggered`);\n console.log(server.state.commissioning.fabrics[fabricIndex]);\n});\n\n/**\n * This event is triggered when an operative new session was opened by a Controller.\n * It is not triggered for the initial commissioning process, just afterwards for real connections.\n */\nserver.events.sessions.opened.on(session => console.log(`Session opened`, session));\n\n/**\n * This event is triggered when an operative session is closed by a Controller or because the Device goes offline.\n */\nserver.events.sessions.closed.on(session => console.log(`Session closed`, session));\n\n/** This event is triggered when a subscription gets added or removed on an operative session. */\nserver.events.sessions.subscriptionsChanged.on(session => {\n console.log(`Session subscriptions changed`, session);\n console.log(`Status of all sessions`, server.state.sessions.sessions);\n});\n\n// React on a change of identificationTime to do Identify stuff for the own device\nendpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic, ideally blink a light every 0.5s ...`);\n});\n\nendpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic ...`);\n});\n\n// Our device is now built and we can bring the node online.\n//\n// Note that you may serve multiple nodes from a single process. We only have one, however, so we can use the run()\n// method of the node.\n\nlogEndpoint(EndpointServer.forEndpoint(server));\n\n/**\n * In order to start the node and announce it into the network we start the node. This method resolves when the Matter\n * node enters his online state. Alternatively, we could also use `await server.run()` which\n * resolves when the node goes offline again, but we want to execute code afterwards, so we use start() here\n */\nawait server.bringOnline();\n\nconsole.log(\"Initial Fabrics\", server.state.operationalCredentials.fabrics);\n\n/**\n * If the node is not commissioned already we display the QR code on console. The QR code is also logged\n */\nif (!server.lifecycle.isCommissioned) {\n const { qrPairingCode, manualPairingCode } = server.state.commissioning.pairingCodes;\n\n console.log(QrCode.get(qrPairingCode));\n console.log(`QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`);\n console.log(`Manual pairing code: ${manualPairingCode}`);\n} else {\n console.log(\"Device is already commissioned. Waiting for controllers to connect ...\");\n\n /**\n * Sometimes reading or writing attributes is required. The following code shows how this works.\n * For read it is basically `endpoint.state.clustername.attributename`.\n * The set method allows to set one or multiple values via the structure of also clustername.attributename. When multiple values are set they are considered being one transaction which would be rolled back completely if one value fails to be set.\n */\n\n // Read onOff attribute from onOff cluster\n const onOffValue = endpoint.state.onOff.onOff;\n console.log(`current OnOff attribute: ${onOffValue}`);\n\n if (vendorId === 0xfff4) {\n // Set onOff attribute from OnOff cluster AND the myFancyValue of the MyFancyOwnFunctionality cluster together\n await endpoint.set({\n onOff: {\n onOff: !onOffValue,\n },\n // @ts-expect-error Needed because the Fancy cluster is added conditionally, so TS do not get that it's there.\n myFancyOwnFunctionality: {\n myFancyValue: 36,\n },\n });\n } else {\n // Set onOff attribute from OnOff cluster only\n await endpoint.set({\n onOff: {\n onOff: !onOffValue,\n },\n });\n }\n}\n\n/**\n * To correctly tear down the now we can use server[Symbol.asyncDispose]().\n */\nprocess.on(\"SIGINT\", () => {\n // Clean up on CTRL-C\n server\n .close()\n .then(() => process.exit(0))\n .catch(err => console.error(err));\n});\n"],
5
+ "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAyBA,OAAO;AAEP,SAAS,eAAe;AAExB,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,kCAAkC;AAC3C,SAAS,mBAAmB;AAC5B,SAAS,WAAW;AACpB,SAAS,4BAA4B;AACrC,SAAS,cAAc,gBAAgB;AACvC,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,UAAU,sBAAsB;AACzC,SAAS,wBAAwB;AACjC,SAAS,aAAa,sBAAsB;AAC5C,SAAS,oBAAoB;AAC7B,SAAS,OAAO,QAAQ,uBAAuB;AAC/C,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,WAAW,iBAAiB;AACrC,SAAS,gBAAgB;AACzB,SAAS,6CAA6C;AACtD,SAAS,2CAA2C;AACpD;AAAA,EAGI;AAAA,OACG;AASP,sBAAsB,EAAE;AAQxB,MAAM,cAAc,YAAY;AAIhC,IAAI,YAAY,KAAK,IAAI,YAAY,GAAG;AAEpC,MAAI,MAAM;AAAA,IACN,MACI,IAAI,QAAQ;AAAA,MACR,OAAO,YAAY,KAAK,OAAO,WAAW;AAAA,IAC9C,CAAC;AAAA,EACT;AACJ;AAEA,SAAS,eAAe,iBAAyB;AAC7C,QAAM,SAAS,YAAY,KAAK,OAAO,eAAe;AACtD,MAAI,WAAW,OAAW,QAAO;AACjC,UAAQ,IAAI,GAAG,eAAe,KAAK,SAAS,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,EAAE,CAAC,EAAE;AACjF;AAYA,MAAM,UAAU,YAAY,K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OAAO;AAK1E,IAAI,CAAC,OAAO,UAAU,gBAAgB;AAClC,QAAM,EAAE,eAAe,kBAAkB,IAAI,OAAO,MAAM,cAAc;AAExE,UAAQ,IAAI,OAAO,IAAI,aAAa,CAAC;AACrC,UAAQ,IAAI,gFAAgF,aAAa,EAAE;AAC3G,UAAQ,IAAI,wBAAwB,iBAAiB,EAAE;AAC3D,OAAO;AACH,UAAQ,IAAI,wEAAwE;AASpF,QAAM,aAAa,SAAS,MAAM,MAAM;AACxC,UAAQ,IAAI,4BAA4B,UAAU,EAAE;AAEpD,MAAI,aAAa,OAAQ;AAErB,UAAM,SAAS,IAAI;AAAA,MACf,OAAO;AAAA,QACH,OAAO,CAAC;AAAA,MACZ;AAAA;AAAA,MAEA,yBAAyB;AAAA,QACrB,cAAc;AAAA,MAClB;AAAA,IACJ,CAAC;AAAA,EACL,OAAO;AAEH,UAAM,SAAS,IAAI;AAAA,MACf,OAAO;AAAA,QACH,OAAO,CAAC;AAAA,MACZ;AAAA,IACJ,CAAC;AAAA,EACL;AACJ;AAKA,QAAQ,GAAG,UAAU,MAAM;AAEvB,SACK,MAAM,EACN,KAAK,MAAM,QAAQ,KAAK,CAAC,CAAC,EAC1B,MAAM,SAAO,QAAQ,MAAM,GAAG,CAAC;AACxC,CAAC;",
6
6
  "names": []
7
7
  }
@@ -4,9 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { GeneralCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/general-commissioning";
7
- import {
8
- NetworkCommissioningBehavior
9
- } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
7
+ import { NetworkCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
10
8
  import { NetworkCommissioning } from "@project-chip/matter.js/cluster";
11
9
  import { Logger } from "@project-chip/matter.js/log";
12
10
  import { ByteArray } from "@project-chip/matter.js/util";
@@ -14,7 +12,9 @@ const firstNetworkId = new ByteArray(32);
14
12
  class DummyThreadNetworkCommissioningServer extends NetworkCommissioningBehavior.with(
15
13
  NetworkCommissioning.Feature.ThreadNetworkInterface
16
14
  ) {
17
- scanNetworks({ breadcrumb }) {
15
+ scanNetworks({
16
+ breadcrumb
17
+ }) {
18
18
  console.log(`---> scanNetworks called on NetworkCommissioning cluster: ${breadcrumb}`);
19
19
  if (breadcrumb !== void 0) {
20
20
  const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
@@ -42,7 +42,10 @@ class DummyThreadNetworkCommissioningServer extends NetworkCommissioningBehavior
42
42
  threadScanResults
43
43
  };
44
44
  }
45
- addOrUpdateThreadNetwork({ operationalDataset, breadcrumb }) {
45
+ addOrUpdateThreadNetwork({
46
+ operationalDataset,
47
+ breadcrumb
48
+ }) {
46
49
  console.log(
47
50
  `---> addOrUpdateThreadNetwork called on NetworkCommissioning cluster: ${operationalDataset.toHex()} ${breadcrumb}`
48
51
  );
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/examples/cluster/DummyThreadNetworkCommissioningServer.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { GeneralCommissioningBehavior } from \"@project-chip/matter.js/behavior/definitions/general-commissioning\";\nimport {\n AddOrUpdateThreadNetworkRequest,\n ConnectNetworkRequest,\n NetworkCommissioningBehavior,\n RemoveNetworkRequest,\n ReorderNetworkRequest,\n ScanNetworksRequest,\n ScanNetworksResponse,\n} from \"@project-chip/matter.js/behavior/definitions/network-commissioning\";\nimport { NetworkCommissioning } from \"@project-chip/matter.js/cluster\";\nimport { Logger } from \"@project-chip/matter.js/log\";\nimport { ByteArray } from \"@project-chip/matter.js/util\";\n\nconst firstNetworkId = new ByteArray(32);\n\n/**\n * This represents a Dummy version of a Thread Network Commissioning Cluster Server without real thread 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 DummyThreadNetworkCommissioningServer extends NetworkCommissioningBehavior.with(\n NetworkCommissioning.Feature.ThreadNetworkInterface,\n) {\n override scanNetworks({ breadcrumb }: ScanNetworksRequest): ScanNetworksResponse {\n console.log(`---> scanNetworks called on NetworkCommissioning cluster: ${breadcrumb}`);\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 const threadScanResults = [\n {\n panId: this.endpoint.env.vars.number(\"ble.thread.panId\"),\n extendedPanId: BigInt(this.endpoint.env.vars.string(\"ble.thread.extendedPanId\")),\n networkName: this.endpoint.env.vars.string(\"ble.thread.networkName\"),\n channel: this.endpoint.env.vars.number(\"ble.thread.channel\"),\n version: 130,\n extendedAddress: ByteArray.fromString(\n (this.endpoint.env.vars.string(\"ble.thread.address\") ?? \"000000000000\").toLowerCase(),\n ),\n rssi: -50,\n lqi: 50,\n },\n ];\n console.log(Logger.toJSON(threadScanResults));\n\n return {\n networkingStatus,\n threadScanResults,\n };\n }\n\n override addOrUpdateThreadNetwork({ operationalDataset, breadcrumb }: AddOrUpdateThreadNetworkRequest) {\n console.log(\n `---> addOrUpdateThreadNetwork called on NetworkCommissioning cluster: ${operationalDataset.toHex()} ${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 }: RemoveNetworkRequest) {\n console.log(`---> removeNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`);\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 }: ConnectNetworkRequest) {\n console.log(`---> connectNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`);\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 }: ReorderNetworkRequest) {\n console.log(\n `---> reorderNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${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;\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kB;AAE/B,WAAO;AAAA,MACH;AAAA,MACA,YAAY;AAAA,IAChB;AAAA,EACJ;AAAA,EAES,eAAe,EAAE,WAAW,cAAc,WAAW,GAA0B;AACpF,YAAQ;AAAA,MACJ,+DAA+D,UAAU,MAAM,CAAC,IAAI,YAAY,IAAI,UAAU;AAAA,IAClH;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;",
4
+ "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\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\";\nimport { Logger } from \"@project-chip/matter.js/log\";\nimport { ByteArray } from \"@project-chip/matter.js/util\";\n\nconst firstNetworkId = new ByteArray(32);\n\n/**\n * This represents a Dummy version of a Thread Network Commissioning Cluster Server without real thread 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 DummyThreadNetworkCommissioningServer extends NetworkCommissioningBehavior.with(\n NetworkCommissioning.Feature.ThreadNetworkInterface,\n) {\n override scanNetworks({\n breadcrumb,\n }: NetworkCommissioning.ScanNetworksRequest): NetworkCommissioning.ScanNetworksResponse {\n console.log(`---> scanNetworks called on NetworkCommissioning cluster: ${breadcrumb}`);\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 const threadScanResults = [\n {\n panId: this.endpoint.env.vars.number(\"ble.thread.panId\"),\n extendedPanId: BigInt(this.endpoint.env.vars.string(\"ble.thread.extendedPanId\")),\n networkName: this.endpoint.env.vars.string(\"ble.thread.networkName\"),\n channel: this.endpoint.env.vars.number(\"ble.thread.channel\"),\n version: 130,\n extendedAddress: ByteArray.fromString(\n (this.endpoint.env.vars.string(\"ble.thread.address\") ?? \"000000000000\").toLowerCase(),\n ),\n rssi: -50,\n lqi: 50,\n },\n ];\n console.log(Logger.toJSON(threadScanResults));\n\n return {\n networkingStatus,\n threadScanResults,\n };\n }\n\n override addOrUpdateThreadNetwork({\n operationalDataset,\n breadcrumb,\n }: NetworkCommissioning.AddOrUpdateThreadNetworkRequest) {\n console.log(\n `---> addOrUpdateThreadNetwork called on NetworkCommissioning cluster: ${operationalDataset.toHex()} ${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(`---> removeNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`);\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(`---> connectNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`);\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: ${networkId.toHex()} ${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;AAAA;AAMA,SAAS,oCAAoC;AAC7C,SAAS,oCAAoC;AAC7C,SAAS,4BAA4B;AACrC,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAE1B,MAAM,iBAAiB,IAAI,UAAU,EAAE;AAOhC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AAe,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
6
  "names": []
7
7
  }
@@ -4,9 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { GeneralCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/general-commissioning";
7
- import {
8
- NetworkCommissioningBehavior
9
- } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
7
+ import { NetworkCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
10
8
  import { NetworkCommissioning } from "@project-chip/matter.js/cluster";
11
9
  import { ByteArray } from "@project-chip/matter.js/util";
12
10
  const firstNetworkId = new ByteArray(32);
@@ -42,7 +40,11 @@ class DummyWifiNetworkCommissioningServer extends NetworkCommissioningBehavior.w
42
40
  ]
43
41
  };
44
42
  }
45
- addOrUpdateWiFiNetwork({ ssid, credentials, breadcrumb }) {
43
+ addOrUpdateWiFiNetwork({
44
+ ssid,
45
+ credentials,
46
+ breadcrumb
47
+ }) {
46
48
  console.log(
47
49
  `---> addOrUpdateWiFiNetwork called on NetworkCommissioning cluster: ${ssid.toHex()} ${credentials.toHex()} ${breadcrumb}`
48
50
  );
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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 { GeneralCommissioningBehavior } from \"@project-chip/matter.js/behavior/definitions/general-commissioning\";\nimport {\n AddOrUpdateWiFiNetworkRequest,\n ConnectNetworkRequest,\n NetworkCommissioningBehavior,\n RemoveNetworkRequest,\n ReorderNetworkRequest,\n ScanNetworksRequest,\n} from \"@project-chip/matter.js/behavior/definitions/network-commissioning\";\nimport { NetworkCommissioning } from \"@project-chip/matter.js/cluster\";\nimport { ByteArray } from \"@project-chip/matter.js/util\";\n\nconst firstNetworkId = new ByteArray(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 }: ScanNetworksRequest) {\n console.log(`---> scanNetworks called on NetworkCommissioning cluster: ${ssid?.toHex()} ${breadcrumb}`);\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 || ByteArray.fromString(this.endpoint.env.vars.get(\"ble.wifi.scanSsid\") ?? \"TestSSID\"), // Set a valid existing local Wi-Fi SSID here\n bssid: ByteArray.fromString(\n this.endpoint.env.vars.get(\"ble.wifi.scanBssid\") ?? \"00:00:00:00:00:00\",\n ),\n channel: 1,\n },\n ],\n };\n }\n\n override addOrUpdateWiFiNetwork({ ssid, credentials, breadcrumb }: AddOrUpdateWiFiNetworkRequest) {\n console.log(\n `---> addOrUpdateWiFiNetwork called on NetworkCommissioning cluster: ${ssid.toHex()} ${credentials.toHex()} ${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 }: RemoveNetworkRequest) {\n console.log(`---> removeNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`);\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 }: ConnectNetworkRequest) {\n console.log(`---> connectNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`);\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 }: ReorderNetworkRequest) {\n console.log(\n `---> reorderNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${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;AAAA;AAMA,SAAS,oCAAoC;AAC7C;AAAA,EAGI;AAAA,OAIG;AACP,SAAS,4BAA4B;AACrC,SAAS,iBAAiB;AAE1B,MAAM,iBAAiB,IAAI,UAAU,EAAE;AAOhC,MAAM,4CAA4C,6BAA6B;AAAA,EAClF,qBAAqB,QAAQ;AACjC,EAAE;AAAA,EACW,aAAa,EAAE,MAAM,WAAW,GAAwB;AAC7D,YAAQ,IAAI,6DAA6D,MAAM,MAAM,CAAC,IAAI,UAAU,EAAE;AAGtG,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,iBAAiB;AAAA,QACb;AAAA,UACI,UAAU;AAAA,YACN,aAAa;AAAA,YACb,KAAK;AAAA,YACL,aAAa;AAAA,YACb,cAAc;AAAA,YACd,cAAc;AAAA,UAClB;AAAA,UACA,MAAM,QAAQ,UAAU,WAAW,KAAK,SAAS,IAAI,KAAK,IAAI,mBAAmB,KAAK,UAAU;AAAA;AAAA,UAChG,OAAO,UAAU;AAAA,YACb,KAAK,SAAS,IAAI,KAAK,IAAI,oBAAoB,KAAK;AAAA,UACxD;AAAA,UACA,SAAS;AAAA,QACb;AAAA,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C,UAAM,mBAAmB,qBAAqB,2BAA2B;AACzE,SAAK,MAAM,uBAAuB;AAClC,SAAK,MAAM,gBAAgB;AAC3B,SAAK,MAAM,wBAAwB;AAGnC,UAAM,SAAS,KAAK,QAAQ;AAC5B,UAAM,OAAO,kBAAkB;AAE/B,WAAO;AAAA,MACH;AAAA,MACA,YAAY;AAAA,IAChB;AAAA,EACJ;AAAA,EAES,eAAe,EAAE,WAAW,cAAc,WAAW,GAA0B;AACpF,YAAQ;AAAA,MACJ,+DAA+D,UAAU,MAAM,CAAC,IAAI,YAAY,IAAI,UAAU;AAAA,IAClH;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;",
4
+ "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\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\";\nimport { ByteArray } from \"@project-chip/matter.js/util\";\n\nconst firstNetworkId = new ByteArray(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(`---> scanNetworks called on NetworkCommissioning cluster: ${ssid?.toHex()} ${breadcrumb}`);\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 || ByteArray.fromString(this.endpoint.env.vars.get(\"ble.wifi.scanSsid\") ?? \"TestSSID\"), // Set a valid existing local Wi-Fi SSID here\n bssid: ByteArray.fromString(\n this.endpoint.env.vars.get(\"ble.wifi.scanBssid\") ?? \"00:00:00:00:00:00\",\n ),\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: ${ssid.toHex()} ${credentials.toHex()} ${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(`---> removeNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`);\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(`---> connectNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`);\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: ${networkId.toHex()} ${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;AAAA;AAMA,SAAS,oCAAoC;AAC7C,SAAS,oCAAoC;AAC7C,SAAS,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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
6
  "names": []
7
7
  }
@@ -22,7 +22,8 @@ const Server = ClusterServer(
22
22
  lastNetworkingStatus: null,
23
23
  networks: [{ networkId: firstNetworkId, connected: false }],
24
24
  scanMaxTimeSeconds: 3,
25
- connectMaxTimeSeconds: 3
25
+ connectMaxTimeSeconds: 3,
26
+ supportedWiFiBands: [NetworkCommissioning.WiFiBand["2G4"]]
26
27
  },
27
28
  {
28
29
  scanNetworks: async ({ request: { ssid, breadcrumb }, attributes: { lastNetworkingStatus }, endpoint }) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/examples/cluster/DummyWifiNetworkCommissioningServerLegacy.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { getParameter } from \"@project-chip/matter-node.js/util\";\nimport {\n ClusterServer,\n ClusterServerObjForCluster,\n GeneralCommissioningCluster,\n NetworkCommissioning,\n} from \"@project-chip/matter.js/cluster\";\nimport { ByteArray } from \"@project-chip/matter.js/util\";\n\nconst firstNetworkId = new ByteArray(32);\n\nconst WifiNetworkCluster = NetworkCommissioning.Cluster.with(NetworkCommissioning.Feature.WiFiNetworkInterface);\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 */\nconst Server: ClusterServerObjForCluster<typeof WifiNetworkCluster> = ClusterServer(\n NetworkCommissioning.Cluster.with(NetworkCommissioning.Feature.WiFiNetworkInterface),\n {\n maxNetworks: 1,\n interfaceEnabled: true,\n lastConnectErrorValue: 0,\n lastNetworkId: null,\n lastNetworkingStatus: null,\n networks: [{ networkId: firstNetworkId, connected: false }],\n scanMaxTimeSeconds: 3,\n connectMaxTimeSeconds: 3,\n },\n {\n scanNetworks: async ({ request: { ssid, breadcrumb }, attributes: { lastNetworkingStatus }, endpoint }) => {\n console.log(`---> scanNetworks called on NetworkCommissioning cluster: ${ssid?.toHex()} ${breadcrumb}`);\n\n // Simulate successful scan\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(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 || ByteArray.fromString(getParameter(\"ble-wifi-scan-ssid\") ?? \"TestSSID\"), // Set a valid existing local Wi-Fi SSID here\n bssid: ByteArray.fromString(getParameter(\"ble-wifi-scan-bssid\") ?? \"00:00:00:00:00:00\"),\n channel: 1,\n },\n ],\n };\n },\n addOrUpdateWiFiNetwork: async ({\n request: { ssid, credentials, breadcrumb },\n attributes: { lastNetworkingStatus, lastNetworkId },\n endpoint,\n session,\n }) => {\n console.log(\n `---> addOrUpdateWiFiNetwork called on NetworkCommissioning cluster: ${ssid.toHex()} ${credentials.toHex()} ${breadcrumb}`,\n );\n\n 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 = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n lastNetworkId?.setLocal(firstNetworkId);\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n },\n removeNetwork: async ({\n request: { networkId, breadcrumb },\n attributes: { lastNetworkingStatus, lastNetworkId },\n endpoint,\n session,\n }) => {\n console.log(\n `---> removeNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`,\n );\n\n 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 = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n lastNetworkId?.setLocal(firstNetworkId);\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n },\n connectNetwork: async ({\n request: { networkId, breadcrumb },\n attributes: { lastNetworkingStatus, lastNetworkId, lastConnectErrorValue, networks },\n endpoint,\n session,\n }) => {\n console.log(\n `---> connectNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`,\n );\n\n 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 = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkList = networks.getLocal();\n networkList[0].connected = true;\n networks.setLocal(networkList);\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n lastNetworkId?.setLocal(firstNetworkId);\n lastConnectErrorValue?.setLocal(null);\n\n // Announce operational in IP network\n const device = session.context;\n await device.startAnnouncement();\n\n return {\n networkingStatus,\n errorValue: null,\n };\n },\n reorderNetwork: async ({\n request: { networkId, networkIndex, breadcrumb },\n attributes: { lastNetworkingStatus },\n endpoint,\n }) => {\n console.log(\n `---> reorderNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${networkIndex} ${breadcrumb}`,\n );\n\n // Simulate successful connection\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n },\n },\n);\n\nexport default Server;\n"],
5
- "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,SAAS,oBAAoB;AAC7B;AAAA,EACI;AAAA,EAEA;AAAA,EACA;AAAA,OACG;AACP,SAAS,iBAAiB;AAE1B,MAAM,iBAAiB,IAAI,UAAU,EAAE;AAEvC,MAAM,qBAAqB,qBAAqB,QAAQ,KAAK,qBAAqB,QAAQ,oBAAoB;AAO9G,MAAM,SAAgE;AAAA,EAClE,qBAAqB,QAAQ,KAAK,qBAAqB,QAAQ,oBAAoB;AAAA,EACnF;AAAA,IACI,aAAa;AAAA,IACb,kBAAkB;AAAA,IAClB,uBAAuB;AAAA,IACvB,eAAe;AAAA,IACf,sBAAsB;AAAA,IACtB,UAAU,CAAC,EAAE,WAAW,gBAAgB,WAAW,MAAM,CAAC;AAAA,IAC1D,oBAAoB;AAAA,IACpB,uBAAuB;AAAA,EAC3B;AAAA,EACA;AAAA,IACI,cAAc,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,GAAG,YAAY,EAAE,qBAAqB,GAAG,SAAS,MAAM;AACvG,cAAQ,IAAI,6DAA6D,MAAM,MAAM,CAAC,IAAI,UAAU,EAAE;AAGtG,UAAI,eAAe,QAAW;AAC1B,cAAM,8BAA8B,SAAS,iBAAiB,2BAA2B;AACzF,qCAA6B,uBAAuB,UAAU;AAAA,MAClE;AAEA,YAAM,mBAAmB,qBAAqB,2BAA2B;AACzE,4BAAsB,SAAS,gB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ClE;AAEA,YAAM,mBAAmB,qBAAqB,2BAA2B;AACzE,4BAAsB,SAAS,gBAAgB;AAE/C,aAAO;AAAA,QACH;AAAA,QACA,cAAc;AAAA,MAClB;AAAA,IACJ;AAAA,EACJ;AACJ;AAEA,IAAO,oDAAQ;",
4
+ "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { getParameter } from \"@project-chip/matter-node.js/util\";\nimport {\n ClusterServer,\n ClusterServerObjForCluster,\n GeneralCommissioningCluster,\n NetworkCommissioning,\n} from \"@project-chip/matter.js/cluster\";\nimport { ByteArray } from \"@project-chip/matter.js/util\";\n\nconst firstNetworkId = new ByteArray(32);\n\nconst WifiNetworkCluster = NetworkCommissioning.Cluster.with(NetworkCommissioning.Feature.WiFiNetworkInterface);\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 */\nconst Server: ClusterServerObjForCluster<typeof WifiNetworkCluster> = ClusterServer(\n NetworkCommissioning.Cluster.with(NetworkCommissioning.Feature.WiFiNetworkInterface),\n {\n maxNetworks: 1,\n interfaceEnabled: true,\n lastConnectErrorValue: 0,\n lastNetworkId: null,\n lastNetworkingStatus: null,\n networks: [{ networkId: firstNetworkId, connected: false }],\n scanMaxTimeSeconds: 3,\n connectMaxTimeSeconds: 3,\n supportedWiFiBands: [NetworkCommissioning.WiFiBand[\"2G4\"]],\n },\n {\n scanNetworks: async ({ request: { ssid, breadcrumb }, attributes: { lastNetworkingStatus }, endpoint }) => {\n console.log(`---> scanNetworks called on NetworkCommissioning cluster: ${ssid?.toHex()} ${breadcrumb}`);\n\n // Simulate successful scan\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(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 || ByteArray.fromString(getParameter(\"ble-wifi-scan-ssid\") ?? \"TestSSID\"), // Set a valid existing local Wi-Fi SSID here\n bssid: ByteArray.fromString(getParameter(\"ble-wifi-scan-bssid\") ?? \"00:00:00:00:00:00\"),\n channel: 1,\n },\n ],\n };\n },\n addOrUpdateWiFiNetwork: async ({\n request: { ssid, credentials, breadcrumb },\n attributes: { lastNetworkingStatus, lastNetworkId },\n endpoint,\n session,\n }) => {\n console.log(\n `---> addOrUpdateWiFiNetwork called on NetworkCommissioning cluster: ${ssid.toHex()} ${credentials.toHex()} ${breadcrumb}`,\n );\n\n 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 = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n lastNetworkId?.setLocal(firstNetworkId);\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n },\n removeNetwork: async ({\n request: { networkId, breadcrumb },\n attributes: { lastNetworkingStatus, lastNetworkId },\n endpoint,\n session,\n }) => {\n console.log(\n `---> removeNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`,\n );\n\n 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 = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n lastNetworkId?.setLocal(firstNetworkId);\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n },\n connectNetwork: async ({\n request: { networkId, breadcrumb },\n attributes: { lastNetworkingStatus, lastNetworkId, lastConnectErrorValue, networks },\n endpoint,\n session,\n }) => {\n console.log(\n `---> connectNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`,\n );\n\n 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 = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkList = networks.getLocal();\n networkList[0].connected = true;\n networks.setLocal(networkList);\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n lastNetworkId?.setLocal(firstNetworkId);\n lastConnectErrorValue?.setLocal(null);\n\n // Announce operational in IP network\n const device = session.context;\n await device.startAnnouncement();\n\n return {\n networkingStatus,\n errorValue: null,\n };\n },\n reorderNetwork: async ({\n request: { networkId, networkIndex, breadcrumb },\n attributes: { lastNetworkingStatus },\n endpoint,\n }) => {\n console.log(\n `---> reorderNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${networkIndex} ${breadcrumb}`,\n );\n\n // Simulate successful connection\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n },\n },\n);\n\nexport default Server;\n"],
5
+ "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,SAAS,oBAAoB;AAC7B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ACF,cAAQ;AAAA,QACJ,+DAA+D,UAAU,MAAM,CAAC,IAAI,UAAU;AAAA,MAClG;AAEA,cAAQ,QAAQ,oBAAoB,6DAA6D;AAGjG,UAAI,eAAe,QAAW;AAC1B,cAAM,8BAA8B,SAAS,iBAAiB,2BAA2B;AACzF,qCAA6B,uBAAuB,UAAU;AAAA,MAClE;AAEA,YAAM,cAAc,SAAS,SAAS;AACtC,kBAAY,CAAC,EAAE,YAAY;AAC3B,eAAS,SAAS,WAAW;AAE7B,YAAM,mBAAmB,qBAAqB,2BAA2B;AACzE,4BAAsB,SAAS,gBAAgB;AAC/C,qBAAe,SAAS,cAAc;AACtC,6BAAuB,SAAS,IAAI;AAGpC,YAAM,SAAS,QAAQ;AACvB,YAAM,OAAO,kBAAkB;AAE/B,aAAO;AAAA,QACH;AAAA,QACA,YAAY;AAAA,MAChB;AAAA,IACJ;AAAA,IACA,gBAAgB,OAAO;AAAA,MACnB,SAAS,EAAE,WAAW,cAAc,WAAW;AAAA,MAC/C,YAAY,EAAE,qBAAqB;AAAA,MACnC;AAAA,IACJ,MAAM;AACF,cAAQ;AAAA,QACJ,+DAA+D,UAAU,MAAM,CAAC,IAAI,YAAY,IAAI,UAAU;AAAA,MAClH;AAGA,UAAI,eAAe,QAAW;AAC1B,cAAM,8BAA8B,SAAS,iBAAiB,2BAA2B;AACzF,qCAA6B,uBAAuB,UAAU;AAAA,MAClE;AAEA,YAAM,mBAAmB,qBAAqB,2BAA2B;AACzE,4BAAsB,SAAS,gBAAgB;AAE/C,aAAO;AAAA,QACH;AAAA,QACA,cAAc;AAAA,MAClB;AAAA,IACJ;AAAA,EACJ;AACJ;AAEA,IAAO,oDAAQ;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@project-chip/matter-node.js-examples",
3
- "version": "0.9.1",
3
+ "version": "0.10.0-alpha.0-20240601-cba311a5",
4
4
  "description": "CLI/Reference implementation scripts for Matter protocol for node.js",
5
5
  "keywords": [
6
6
  "iot",
@@ -64,10 +64,10 @@
64
64
  "typescript": "~5.4.5"
65
65
  },
66
66
  "dependencies": {
67
- "@project-chip/matter-node-ble.js": "0.9.1",
68
- "@project-chip/matter-node.js": "0.9.1",
69
- "@project-chip/matter.js": "0.9.1",
70
- "@project-chip/matter.js-tools": "0.9.1"
67
+ "@project-chip/matter-node-ble.js": "0.10.0-alpha.0-20240601-cba311a5",
68
+ "@project-chip/matter-node.js": "0.10.0-alpha.0-20240601-cba311a5",
69
+ "@project-chip/matter.js": "0.10.0-alpha.0-20240601-cba311a5",
70
+ "@project-chip/matter.js-tools": "0.10.0-alpha.0-20240601-cba311a5"
71
71
  },
72
72
  "engines": {
73
73
  "_comment": "For Crypto.hkdf support",
@@ -83,5 +83,5 @@
83
83
  "publishConfig": {
84
84
  "access": "public"
85
85
  },
86
- "gitHead": "49679bb96cddf408fa26f0e8dcf3a8f2f1eda5f5"
86
+ "gitHead": "bec9e060652d54f3b7cc621b296d1c1e23ed8be7"
87
87
  }
@@ -24,7 +24,7 @@ import { logEndpoint } from "@project-chip/matter.js/device";
24
24
  import { OnOffLightDevice } from "@project-chip/matter.js/devices/OnOffLightDevice";
25
25
  import { OnOffPlugInUnitDevice } from "@project-chip/matter.js/devices/OnOffPlugInUnitDevice";
26
26
  import { Endpoint, EndpointServer } from "@project-chip/matter.js/endpoint";
27
- import { AggregatorEndpoint } from "@project-chip/matter.js/endpoint/definitions";
27
+ import { AggregatorEndpoint } from "@project-chip/matter.js/endpoints/AggregatorEndpoint";
28
28
  import { Environment, StorageService } from "@project-chip/matter.js/environment";
29
29
  import { ServerNode } from "@project-chip/matter.js/node";
30
30
  import { Time } from "@project-chip/matter.js/time";
@@ -26,9 +26,9 @@
26
26
  import "@project-chip/matter-node.js";
27
27
 
28
28
  import { BleNode } from "@project-chip/matter-node-ble.js/ble";
29
+ import { GeneralDiagnostics } from "@project-chip/matter-node.js/cluster";
29
30
  import { createFileLogger } from "@project-chip/matter-node.js/log";
30
31
  import { requireMinNodeVersion } from "@project-chip/matter-node.js/util";
31
- import { TestEventTriggerRequest } from "@project-chip/matter.js/behavior/definitions/general-diagnostics";
32
32
  import { NetworkCommissioningServer } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
33
33
  import { OnOffServer } from "@project-chip/matter.js/behavior/definitions/on-off";
34
34
  import { Ble } from "@project-chip/matter.js/ble";
@@ -173,7 +173,7 @@ class TestGeneralDiagnosticsServer extends RootRequirements.GeneralDiagnosticsSe
173
173
  super.initialize();
174
174
  }
175
175
 
176
- override testEventTrigger({ enableKey, eventTrigger }: TestEventTriggerRequest) {
176
+ override testEventTrigger({ enableKey, eventTrigger }: GeneralDiagnostics.TestEventTriggerRequest) {
177
177
  console.log(`testEventTrigger called on GeneralDiagnostic cluster: ${enableKey} ${eventTrigger}`);
178
178
  }
179
179
  }
@@ -209,7 +209,7 @@ class MyFancyOwnFunctionalityServer extends MyFancyOwnFunctionalityBehavior {
209
209
  // Devices are compositions of behaviors like OnOffServer above. To extend an existing device you use builder methods.
210
210
  //
211
211
  // In this case we are using with() to install our On/Off cluster behavior.
212
- // .with("LevelControlForLighting") not needed because we always have it in by default because we have default implementation
212
+ // .with("Lighting") not needed because we always have it in by default because we have default implementation
213
213
  const OnOffDevice = isSocket
214
214
  ? vendorId === 0xfff4
215
215
  ? OnOffPlugInUnitDevice.with(OnOffShellExecServer, MyFancyOwnFunctionalityServer)
@@ -5,15 +5,7 @@
5
5
  */
6
6
 
7
7
  import { GeneralCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/general-commissioning";
8
- import {
9
- AddOrUpdateThreadNetworkRequest,
10
- ConnectNetworkRequest,
11
- NetworkCommissioningBehavior,
12
- RemoveNetworkRequest,
13
- ReorderNetworkRequest,
14
- ScanNetworksRequest,
15
- ScanNetworksResponse,
16
- } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
8
+ import { NetworkCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
17
9
  import { NetworkCommissioning } from "@project-chip/matter.js/cluster";
18
10
  import { Logger } from "@project-chip/matter.js/log";
19
11
  import { ByteArray } from "@project-chip/matter.js/util";
@@ -28,7 +20,9 @@ const firstNetworkId = new ByteArray(32);
28
20
  export class DummyThreadNetworkCommissioningServer extends NetworkCommissioningBehavior.with(
29
21
  NetworkCommissioning.Feature.ThreadNetworkInterface,
30
22
  ) {
31
- override scanNetworks({ breadcrumb }: ScanNetworksRequest): ScanNetworksResponse {
23
+ override scanNetworks({
24
+ breadcrumb,
25
+ }: NetworkCommissioning.ScanNetworksRequest): NetworkCommissioning.ScanNetworksResponse {
32
26
  console.log(`---> scanNetworks called on NetworkCommissioning cluster: ${breadcrumb}`);
33
27
 
34
28
  // Simulate successful scan
@@ -62,7 +56,10 @@ export class DummyThreadNetworkCommissioningServer extends NetworkCommissioningB
62
56
  };
63
57
  }
64
58
 
65
- override addOrUpdateThreadNetwork({ operationalDataset, breadcrumb }: AddOrUpdateThreadNetworkRequest) {
59
+ override addOrUpdateThreadNetwork({
60
+ operationalDataset,
61
+ breadcrumb,
62
+ }: NetworkCommissioning.AddOrUpdateThreadNetworkRequest) {
66
63
  console.log(
67
64
  `---> addOrUpdateThreadNetwork called on NetworkCommissioning cluster: ${operationalDataset.toHex()} ${breadcrumb}`,
68
65
  );
@@ -85,7 +82,7 @@ export class DummyThreadNetworkCommissioningServer extends NetworkCommissioningB
85
82
  };
86
83
  }
87
84
 
88
- override removeNetwork({ networkId, breadcrumb }: RemoveNetworkRequest) {
85
+ override removeNetwork({ networkId, breadcrumb }: NetworkCommissioning.RemoveNetworkRequest) {
89
86
  console.log(`---> removeNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`);
90
87
 
91
88
  this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
@@ -106,7 +103,7 @@ export class DummyThreadNetworkCommissioningServer extends NetworkCommissioningB
106
103
  };
107
104
  }
108
105
 
109
- override async connectNetwork({ networkId, breadcrumb }: ConnectNetworkRequest) {
106
+ override async connectNetwork({ networkId, breadcrumb }: NetworkCommissioning.ConnectNetworkRequest) {
110
107
  console.log(`---> connectNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`);
111
108
 
112
109
  this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
@@ -134,7 +131,7 @@ export class DummyThreadNetworkCommissioningServer extends NetworkCommissioningB
134
131
  };
135
132
  }
136
133
 
137
- override reorderNetwork({ networkId, networkIndex, breadcrumb }: ReorderNetworkRequest) {
134
+ override reorderNetwork({ networkId, networkIndex, breadcrumb }: NetworkCommissioning.ReorderNetworkRequest) {
138
135
  console.log(
139
136
  `---> reorderNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${networkIndex} ${breadcrumb}`,
140
137
  );
@@ -5,14 +5,7 @@
5
5
  */
6
6
 
7
7
  import { GeneralCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/general-commissioning";
8
- import {
9
- AddOrUpdateWiFiNetworkRequest,
10
- ConnectNetworkRequest,
11
- NetworkCommissioningBehavior,
12
- RemoveNetworkRequest,
13
- ReorderNetworkRequest,
14
- ScanNetworksRequest,
15
- } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
8
+ import { NetworkCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
16
9
  import { NetworkCommissioning } from "@project-chip/matter.js/cluster";
17
10
  import { ByteArray } from "@project-chip/matter.js/util";
18
11
 
@@ -26,7 +19,7 @@ const firstNetworkId = new ByteArray(32);
26
19
  export class DummyWifiNetworkCommissioningServer extends NetworkCommissioningBehavior.with(
27
20
  NetworkCommissioning.Feature.WiFiNetworkInterface,
28
21
  ) {
29
- override scanNetworks({ ssid, breadcrumb }: ScanNetworksRequest) {
22
+ override scanNetworks({ ssid, breadcrumb }: NetworkCommissioning.ScanNetworksRequest) {
30
23
  console.log(`---> scanNetworks called on NetworkCommissioning cluster: ${ssid?.toHex()} ${breadcrumb}`);
31
24
 
32
25
  // Simulate successful scan
@@ -59,7 +52,11 @@ export class DummyWifiNetworkCommissioningServer extends NetworkCommissioningBeh
59
52
  };
60
53
  }
61
54
 
62
- override addOrUpdateWiFiNetwork({ ssid, credentials, breadcrumb }: AddOrUpdateWiFiNetworkRequest) {
55
+ override addOrUpdateWiFiNetwork({
56
+ ssid,
57
+ credentials,
58
+ breadcrumb,
59
+ }: NetworkCommissioning.AddOrUpdateWiFiNetworkRequest) {
63
60
  console.log(
64
61
  `---> addOrUpdateWiFiNetwork called on NetworkCommissioning cluster: ${ssid.toHex()} ${credentials.toHex()} ${breadcrumb}`,
65
62
  );
@@ -82,7 +79,7 @@ export class DummyWifiNetworkCommissioningServer extends NetworkCommissioningBeh
82
79
  };
83
80
  }
84
81
 
85
- override removeNetwork({ networkId, breadcrumb }: RemoveNetworkRequest) {
82
+ override removeNetwork({ networkId, breadcrumb }: NetworkCommissioning.RemoveNetworkRequest) {
86
83
  console.log(`---> removeNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`);
87
84
 
88
85
  this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
@@ -103,7 +100,7 @@ export class DummyWifiNetworkCommissioningServer extends NetworkCommissioningBeh
103
100
  };
104
101
  }
105
102
 
106
- override async connectNetwork({ networkId, breadcrumb }: ConnectNetworkRequest) {
103
+ override async connectNetwork({ networkId, breadcrumb }: NetworkCommissioning.ConnectNetworkRequest) {
107
104
  console.log(`---> connectNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`);
108
105
 
109
106
  this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
@@ -131,7 +128,7 @@ export class DummyWifiNetworkCommissioningServer extends NetworkCommissioningBeh
131
128
  };
132
129
  }
133
130
 
134
- override reorderNetwork({ networkId, networkIndex, breadcrumb }: ReorderNetworkRequest) {
131
+ override reorderNetwork({ networkId, networkIndex, breadcrumb }: NetworkCommissioning.ReorderNetworkRequest) {
135
132
  console.log(
136
133
  `---> reorderNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${networkIndex} ${breadcrumb}`,
137
134
  );
@@ -33,6 +33,7 @@ const Server: ClusterServerObjForCluster<typeof WifiNetworkCluster> = ClusterSer
33
33
  networks: [{ networkId: firstNetworkId, connected: false }],
34
34
  scanMaxTimeSeconds: 3,
35
35
  connectMaxTimeSeconds: 3,
36
+ supportedWiFiBands: [NetworkCommissioning.WiFiBand["2G4"]],
36
37
  },
37
38
  {
38
39
  scanNetworks: async ({ request: { ssid, breadcrumb }, attributes: { lastNetworkingStatus }, endpoint }) => {