@project-chip/matter-node.js-examples 0.11.0-alpha.0-20240911-db8f7c80 → 0.11.0-alpha.0-20241007-547af42a8
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +3 -271
- package/dist/esm/examples/BridgedDevicesNodeLegacy.js +5 -4
- package/dist/esm/examples/BridgedDevicesNodeLegacy.js.map +1 -2
- package/dist/esm/examples/ComposedDeviceNodeLegacy.js +4 -3
- package/dist/esm/examples/ComposedDeviceNodeLegacy.js.map +1 -2
- package/dist/esm/examples/ControllerNodeLegacy.js +7 -6
- package/dist/esm/examples/ControllerNodeLegacy.js.map +1 -2
- package/dist/esm/examples/DeviceNodeFullLegacy.js +8 -6
- package/dist/esm/examples/DeviceNodeFullLegacy.js.map +1 -2
- package/dist/esm/examples/LegacyStorageConverter.js +2 -2
- package/dist/esm/examples/LegacyStorageConverter.js.map +0 -1
- package/dist/esm/examples/MultiDeviceNodeLegacy.js +5 -4
- package/dist/esm/examples/MultiDeviceNodeLegacy.js.map +1 -2
- package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServerLegacy.js +7 -6
- package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServerLegacy.js.map +1 -2
- package/dist/esm/package.json +3 -0
- package/package.json +16 -37
- package/src/examples/BridgedDevicesNodeLegacy.ts +4 -3
- package/src/examples/ComposedDeviceNodeLegacy.ts +4 -3
- package/src/examples/ControllerNodeLegacy.ts +6 -5
- package/src/examples/DeviceNodeFullLegacy.ts +7 -5
- package/src/examples/LegacyStorageConverter.ts +2 -2
- package/src/examples/MultiDeviceNodeLegacy.ts +4 -4
- package/src/examples/cluster/DummyWifiNetworkCommissioningServerLegacy.ts +7 -6
- package/src/tsconfig.json +13 -13
- package/dist/esm/examples/BridgedDevicesNode.js +0 -144
- package/dist/esm/examples/BridgedDevicesNode.js.map +0 -7
- package/dist/esm/examples/ComposedDeviceNode.js +0 -123
- package/dist/esm/examples/ComposedDeviceNode.js.map +0 -7
- package/dist/esm/examples/ControllerNode.js +0 -194
- package/dist/esm/examples/ControllerNode.js.map +0 -7
- package/dist/esm/examples/DeviceNode.js +0 -127
- package/dist/esm/examples/DeviceNode.js.map +0 -7
- package/dist/esm/examples/DeviceNodeFull.js +0 -253
- package/dist/esm/examples/DeviceNodeFull.js.map +0 -7
- package/dist/esm/examples/IlluminatedRollerShade.js +0 -60
- package/dist/esm/examples/IlluminatedRollerShade.js.map +0 -7
- package/dist/esm/examples/LightDevice.js +0 -35
- package/dist/esm/examples/LightDevice.js.map +0 -7
- package/dist/esm/examples/MultiDeviceNode.js +0 -140
- package/dist/esm/examples/MultiDeviceNode.js.map +0 -7
- package/dist/esm/examples/SensorDeviceNode.js +0 -175
- package/dist/esm/examples/SensorDeviceNode.js.map +0 -7
- package/dist/esm/examples/cluster/DummyThreadNetworkCommissioningServer.js +0 -121
- package/dist/esm/examples/cluster/DummyThreadNetworkCommissioningServer.js.map +0 -7
- package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServer.js +0 -121
- package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServer.js.map +0 -7
- package/dist/esm/examples/cluster/MyFancyOwnFunctionality.js +0 -110
- package/dist/esm/examples/cluster/MyFancyOwnFunctionality.js.map +0 -7
- package/dist/esm/tutorial/example01.js +0 -5
- package/dist/esm/tutorial/example01.js.map +0 -7
- package/dist/esm/tutorial/example02.js +0 -7
- package/dist/esm/tutorial/example02.js.map +0 -7
- package/dist/esm/tutorial/example03.js +0 -15
- package/dist/esm/tutorial/example03.js.map +0 -7
- package/dist/esm/tutorial/example04.js +0 -10
- package/dist/esm/tutorial/example04.js.map +0 -7
- package/dist/esm/tutorial/example05.js +0 -14
- package/dist/esm/tutorial/example05.js.map +0 -7
- package/src/examples/BridgedDevicesNode.ts +0 -259
- package/src/examples/ComposedDeviceNode.ts +0 -196
- package/src/examples/ControllerNode.ts +0 -314
- package/src/examples/DeviceNode.ts +0 -201
- package/src/examples/DeviceNodeFull.ts +0 -440
- package/src/examples/IlluminatedRollerShade.ts +0 -96
- package/src/examples/LightDevice.ts +0 -61
- package/src/examples/MultiDeviceNode.ts +0 -208
- package/src/examples/SensorDeviceNode.ts +0 -247
- package/src/examples/cluster/DummyThreadNetworkCommissioningServer.ts +0 -156
- package/src/examples/cluster/DummyWifiNetworkCommissioningServer.ts +0 -154
- package/src/examples/cluster/MyFancyOwnFunctionality.ts +0 -185
- package/src/tutorial/example01.ts +0 -6
- package/src/tutorial/example02.ts +0 -9
- package/src/tutorial/example03.ts +0 -19
- package/src/tutorial/example04.ts +0 -13
- package/src/tutorial/example05.ts +0 -19
@@ -1,156 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @license
|
3
|
-
* Copyright 2022-2024 Matter.js Authors
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
5
|
-
*/
|
6
|
-
|
7
|
-
import { Bytes, Logger } from "@project-chip/matter.js-general";
|
8
|
-
import { GeneralCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/general-commissioning";
|
9
|
-
import { NetworkCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
|
10
|
-
import { NetworkCommissioning } from "@project-chip/matter.js/cluster";
|
11
|
-
|
12
|
-
const firstNetworkId = new Uint8Array(32);
|
13
|
-
|
14
|
-
/**
|
15
|
-
* This represents a Dummy version of a Thread Network Commissioning Cluster Server without real thread related logic, beside
|
16
|
-
* returning some values provided as CLI parameters. This dummy implementation is only there for tests/as showcase for BLE
|
17
|
-
* commissioning of a device.
|
18
|
-
*/
|
19
|
-
export class DummyThreadNetworkCommissioningServer extends NetworkCommissioningBehavior.with(
|
20
|
-
NetworkCommissioning.Feature.ThreadNetworkInterface,
|
21
|
-
) {
|
22
|
-
override scanNetworks({
|
23
|
-
breadcrumb,
|
24
|
-
}: NetworkCommissioning.ScanNetworksRequest): NetworkCommissioning.ScanNetworksResponse {
|
25
|
-
console.log(`---> scanNetworks called on NetworkCommissioning cluster: ${breadcrumb}`);
|
26
|
-
|
27
|
-
// Simulate successful scan
|
28
|
-
if (breadcrumb !== undefined) {
|
29
|
-
const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
|
30
|
-
generalCommissioningCluster.state.breadcrumb = breadcrumb;
|
31
|
-
}
|
32
|
-
|
33
|
-
const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
|
34
|
-
this.state.lastNetworkingStatus = networkingStatus;
|
35
|
-
|
36
|
-
const threadScanResults = [
|
37
|
-
{
|
38
|
-
panId: this.endpoint.env.vars.number("ble.thread.panId"),
|
39
|
-
extendedPanId: BigInt(this.endpoint.env.vars.string("ble.thread.extendedPanId")),
|
40
|
-
networkName: this.endpoint.env.vars.string("ble.thread.networkName"),
|
41
|
-
channel: this.endpoint.env.vars.number("ble.thread.channel"),
|
42
|
-
version: 130,
|
43
|
-
extendedAddress: Bytes.fromString(
|
44
|
-
(this.endpoint.env.vars.string("ble.thread.address") ?? "000000000000").toLowerCase(),
|
45
|
-
),
|
46
|
-
rssi: -50,
|
47
|
-
lqi: 50,
|
48
|
-
},
|
49
|
-
];
|
50
|
-
console.log(Logger.toJSON(threadScanResults));
|
51
|
-
|
52
|
-
return {
|
53
|
-
networkingStatus,
|
54
|
-
threadScanResults,
|
55
|
-
};
|
56
|
-
}
|
57
|
-
|
58
|
-
override addOrUpdateThreadNetwork({
|
59
|
-
operationalDataset,
|
60
|
-
breadcrumb,
|
61
|
-
}: NetworkCommissioning.AddOrUpdateThreadNetworkRequest) {
|
62
|
-
console.log(
|
63
|
-
`---> addOrUpdateThreadNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(operationalDataset)} ${breadcrumb}`,
|
64
|
-
);
|
65
|
-
|
66
|
-
this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
|
67
|
-
|
68
|
-
// Simulate successful add or update
|
69
|
-
if (breadcrumb !== undefined) {
|
70
|
-
const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
|
71
|
-
generalCommissioningCluster.state.breadcrumb = breadcrumb;
|
72
|
-
}
|
73
|
-
|
74
|
-
const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
|
75
|
-
this.state.lastNetworkingStatus = networkingStatus;
|
76
|
-
this.state.lastNetworkId = firstNetworkId;
|
77
|
-
|
78
|
-
return {
|
79
|
-
networkingStatus,
|
80
|
-
networkIndex: 0,
|
81
|
-
};
|
82
|
-
}
|
83
|
-
|
84
|
-
override removeNetwork({ networkId, breadcrumb }: NetworkCommissioning.RemoveNetworkRequest) {
|
85
|
-
console.log(
|
86
|
-
`---> removeNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`,
|
87
|
-
);
|
88
|
-
|
89
|
-
this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
|
90
|
-
|
91
|
-
// Simulate successful add or update
|
92
|
-
if (breadcrumb !== undefined) {
|
93
|
-
const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
|
94
|
-
generalCommissioningCluster.state.breadcrumb = breadcrumb;
|
95
|
-
}
|
96
|
-
|
97
|
-
const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
|
98
|
-
this.state.lastNetworkingStatus = networkingStatus;
|
99
|
-
this.state.lastNetworkId = firstNetworkId;
|
100
|
-
|
101
|
-
return {
|
102
|
-
networkingStatus,
|
103
|
-
networkIndex: 0,
|
104
|
-
};
|
105
|
-
}
|
106
|
-
|
107
|
-
override async connectNetwork({ networkId, breadcrumb }: NetworkCommissioning.ConnectNetworkRequest) {
|
108
|
-
console.log(
|
109
|
-
`---> connectNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`,
|
110
|
-
);
|
111
|
-
|
112
|
-
this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
|
113
|
-
|
114
|
-
// Simulate successful connection
|
115
|
-
if (breadcrumb !== undefined) {
|
116
|
-
const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
|
117
|
-
generalCommissioningCluster.state.breadcrumb = breadcrumb;
|
118
|
-
}
|
119
|
-
|
120
|
-
this.state.networks[0].connected = true;
|
121
|
-
|
122
|
-
const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
|
123
|
-
this.state.lastNetworkingStatus = networkingStatus;
|
124
|
-
this.state.lastNetworkId = firstNetworkId;
|
125
|
-
this.state.lastConnectErrorValue = null;
|
126
|
-
|
127
|
-
// Announce operational in IP network
|
128
|
-
const device = this.session.context;
|
129
|
-
await device.startAnnouncement();
|
130
|
-
|
131
|
-
return {
|
132
|
-
networkingStatus,
|
133
|
-
errorValue: null,
|
134
|
-
};
|
135
|
-
}
|
136
|
-
|
137
|
-
override reorderNetwork({ networkId, networkIndex, breadcrumb }: NetworkCommissioning.ReorderNetworkRequest) {
|
138
|
-
console.log(
|
139
|
-
`---> reorderNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${networkIndex} ${breadcrumb}`,
|
140
|
-
);
|
141
|
-
|
142
|
-
// Simulate successful connection
|
143
|
-
if (breadcrumb !== undefined) {
|
144
|
-
const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
|
145
|
-
generalCommissioningCluster.state.breadcrumb = breadcrumb;
|
146
|
-
}
|
147
|
-
|
148
|
-
const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
|
149
|
-
this.state.lastNetworkingStatus = networkingStatus;
|
150
|
-
|
151
|
-
return {
|
152
|
-
networkingStatus,
|
153
|
-
networkIndex: 0,
|
154
|
-
};
|
155
|
-
}
|
156
|
-
}
|
@@ -1,154 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @license
|
3
|
-
* Copyright 2022-2024 Matter.js Authors
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
5
|
-
*/
|
6
|
-
|
7
|
-
import { Bytes } from "@project-chip/matter.js-general";
|
8
|
-
import { GeneralCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/general-commissioning";
|
9
|
-
import { NetworkCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
|
10
|
-
import { NetworkCommissioning } from "@project-chip/matter.js/cluster";
|
11
|
-
|
12
|
-
const firstNetworkId = new Uint8Array(32);
|
13
|
-
|
14
|
-
/**
|
15
|
-
* This represents a Dummy version of a Wifi Network Commissioning Cluster Server without real Wifi related logic, beside
|
16
|
-
* returning some values provided as CLI parameters. This dummy implementation is only there for tests/as showcase for BLE
|
17
|
-
* commissioning of a device.
|
18
|
-
*/
|
19
|
-
export class DummyWifiNetworkCommissioningServer extends NetworkCommissioningBehavior.with(
|
20
|
-
NetworkCommissioning.Feature.WiFiNetworkInterface,
|
21
|
-
) {
|
22
|
-
override scanNetworks({ ssid, breadcrumb }: NetworkCommissioning.ScanNetworksRequest) {
|
23
|
-
console.log(
|
24
|
-
`---> scanNetworks called on NetworkCommissioning cluster: ${ssid ? Bytes.toHex(ssid) : undefined} ${breadcrumb}`,
|
25
|
-
);
|
26
|
-
|
27
|
-
// Simulate successful scan
|
28
|
-
if (breadcrumb !== undefined) {
|
29
|
-
const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
|
30
|
-
generalCommissioningCluster.state.breadcrumb = breadcrumb;
|
31
|
-
}
|
32
|
-
|
33
|
-
const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
|
34
|
-
this.state.lastNetworkingStatus = networkingStatus;
|
35
|
-
|
36
|
-
return {
|
37
|
-
networkingStatus,
|
38
|
-
wiFiScanResults: [
|
39
|
-
{
|
40
|
-
security: {
|
41
|
-
unencrypted: false,
|
42
|
-
wep: false,
|
43
|
-
wpaPersonal: false,
|
44
|
-
wpa2Personal: true,
|
45
|
-
wpa3Personal: true,
|
46
|
-
},
|
47
|
-
ssid: ssid || Bytes.fromString(this.endpoint.env.vars.get("ble.wifi.scanSsid") ?? "TestSSID"), // Set a valid existing local Wi-Fi SSID here
|
48
|
-
bssid: Bytes.fromString(this.endpoint.env.vars.get("ble.wifi.scanBssid") ?? "00:00:00:00:00:00"),
|
49
|
-
channel: 1,
|
50
|
-
},
|
51
|
-
],
|
52
|
-
};
|
53
|
-
}
|
54
|
-
|
55
|
-
override addOrUpdateWiFiNetwork({
|
56
|
-
ssid,
|
57
|
-
credentials,
|
58
|
-
breadcrumb,
|
59
|
-
}: NetworkCommissioning.AddOrUpdateWiFiNetworkRequest) {
|
60
|
-
console.log(
|
61
|
-
`---> addOrUpdateWiFiNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(ssid)} ${Bytes.toHex(credentials)} ${breadcrumb}`,
|
62
|
-
);
|
63
|
-
|
64
|
-
this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
|
65
|
-
|
66
|
-
// Simulate successful add or update
|
67
|
-
if (breadcrumb !== undefined) {
|
68
|
-
const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
|
69
|
-
generalCommissioningCluster.state.breadcrumb = breadcrumb;
|
70
|
-
}
|
71
|
-
|
72
|
-
const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
|
73
|
-
this.state.lastNetworkingStatus = networkingStatus;
|
74
|
-
this.state.lastNetworkId = firstNetworkId;
|
75
|
-
|
76
|
-
return {
|
77
|
-
networkingStatus,
|
78
|
-
networkIndex: 0,
|
79
|
-
};
|
80
|
-
}
|
81
|
-
|
82
|
-
override removeNetwork({ networkId, breadcrumb }: NetworkCommissioning.RemoveNetworkRequest) {
|
83
|
-
console.log(
|
84
|
-
`---> removeNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`,
|
85
|
-
);
|
86
|
-
|
87
|
-
this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
|
88
|
-
|
89
|
-
// Simulate successful add or update
|
90
|
-
if (breadcrumb !== undefined) {
|
91
|
-
const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
|
92
|
-
generalCommissioningCluster.state.breadcrumb = breadcrumb;
|
93
|
-
}
|
94
|
-
|
95
|
-
const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
|
96
|
-
this.state.lastNetworkingStatus = networkingStatus;
|
97
|
-
this.state.lastNetworkId = firstNetworkId;
|
98
|
-
|
99
|
-
return {
|
100
|
-
networkingStatus,
|
101
|
-
networkIndex: 0,
|
102
|
-
};
|
103
|
-
}
|
104
|
-
|
105
|
-
override async connectNetwork({ networkId, breadcrumb }: NetworkCommissioning.ConnectNetworkRequest) {
|
106
|
-
console.log(
|
107
|
-
`---> connectNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`,
|
108
|
-
);
|
109
|
-
|
110
|
-
this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
|
111
|
-
|
112
|
-
// Simulate successful connection
|
113
|
-
if (breadcrumb !== undefined) {
|
114
|
-
const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
|
115
|
-
generalCommissioningCluster.state.breadcrumb = breadcrumb;
|
116
|
-
}
|
117
|
-
|
118
|
-
this.state.networks[0].connected = true;
|
119
|
-
|
120
|
-
const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
|
121
|
-
this.state.lastNetworkingStatus = networkingStatus;
|
122
|
-
this.state.lastNetworkId = firstNetworkId;
|
123
|
-
this.state.lastConnectErrorValue = null;
|
124
|
-
|
125
|
-
// Announce operational in IP network
|
126
|
-
const device = this.session.context;
|
127
|
-
await device.startAnnouncement();
|
128
|
-
|
129
|
-
return {
|
130
|
-
networkingStatus,
|
131
|
-
errorValue: null,
|
132
|
-
};
|
133
|
-
}
|
134
|
-
|
135
|
-
override reorderNetwork({ networkId, networkIndex, breadcrumb }: NetworkCommissioning.ReorderNetworkRequest) {
|
136
|
-
console.log(
|
137
|
-
`---> reorderNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${networkIndex} ${breadcrumb}`,
|
138
|
-
);
|
139
|
-
|
140
|
-
// Simulate successful connection
|
141
|
-
if (breadcrumb !== undefined) {
|
142
|
-
const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
|
143
|
-
generalCommissioningCluster.state.breadcrumb = breadcrumb;
|
144
|
-
}
|
145
|
-
|
146
|
-
const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
|
147
|
-
this.state.lastNetworkingStatus = networkingStatus;
|
148
|
-
|
149
|
-
return {
|
150
|
-
networkingStatus,
|
151
|
-
networkIndex: 0,
|
152
|
-
};
|
153
|
-
}
|
154
|
-
}
|
@@ -1,185 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @license
|
3
|
-
* Copyright 2022-2024 Matter.js Authors
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
5
|
-
*/
|
6
|
-
|
7
|
-
import { Identity, MaybePromise } from "@project-chip/matter.js-general";
|
8
|
-
import {
|
9
|
-
AttributeElement,
|
10
|
-
ClusterElement,
|
11
|
-
ClusterModel,
|
12
|
-
CommandElement,
|
13
|
-
EventElement,
|
14
|
-
FieldElement,
|
15
|
-
} from "@project-chip/matter.js-model";
|
16
|
-
import { ClusterBehavior } from "@project-chip/matter.js/behavior/cluster";
|
17
|
-
import {
|
18
|
-
Attribute,
|
19
|
-
ClusterRegistry,
|
20
|
-
Command,
|
21
|
-
Event,
|
22
|
-
EventPriority,
|
23
|
-
MutableCluster,
|
24
|
-
} from "@project-chip/matter.js/cluster";
|
25
|
-
import { ClusterId, VendorId } from "@project-chip/matter.js/datatype";
|
26
|
-
import { TlvField, TlvInt16, TlvNullable, TlvObject, TlvString, TypeFromSchema } from "@project-chip/matter.js/tlv";
|
27
|
-
|
28
|
-
/** Define the Cluster ID, custom clusters use a special extended formt that also contains the Vendor Id */
|
29
|
-
const myFancyClusterId = ClusterId.buildVendorSpecific(VendorId(0xfff4), 0xfc00);
|
30
|
-
|
31
|
-
/**
|
32
|
-
* Defines the Cluster on Tlv Schema level in a special namespace structure to match the official cluster
|
33
|
-
* structures of matter.js.
|
34
|
-
* All places that contains "MyFancy..." belong to the custom cluster details, all rest can be left statically like the
|
35
|
-
* given names.
|
36
|
-
* For more examples and usages of features in such clusters and how the code should look then check the standard
|
37
|
-
* cluster Tlv definitions in packages/matter.js/cluster/definitions/*
|
38
|
-
*/
|
39
|
-
export namespace MyFancyOwnFunctionality {
|
40
|
-
/**
|
41
|
-
* Input to the MyFancyOwnFunctionality myFancyCommand command
|
42
|
-
*/
|
43
|
-
export const TlvMyFancyCommandRequest = TlvObject({ value: TlvField(0, TlvString) });
|
44
|
-
|
45
|
-
/**
|
46
|
-
* Response of the MyFancyOwnFunctionality myFancyCommand command
|
47
|
-
*/
|
48
|
-
export const TlvMyFancyCommandResponse = TlvObject({ response: TlvField(0, TlvString) });
|
49
|
-
|
50
|
-
/**
|
51
|
-
* Event for the MyFancyOwnFunctionality myFancyEvent event
|
52
|
-
*/
|
53
|
-
export const TlvMyFancyEvent = TlvObject({ eventValue: TlvField(0, TlvString) });
|
54
|
-
|
55
|
-
/**
|
56
|
-
* @see {@link Cluster}
|
57
|
-
*/
|
58
|
-
export const ClusterInstance = MutableCluster({
|
59
|
-
id: myFancyClusterId,
|
60
|
-
name: "MyFancyOwnFunctionality",
|
61
|
-
revision: 1,
|
62
|
-
|
63
|
-
attributes: {
|
64
|
-
/** My fancy attribute */
|
65
|
-
myFancyValue: Attribute(0x0, TlvNullable(TlvInt16)),
|
66
|
-
},
|
67
|
-
|
68
|
-
commands: {
|
69
|
-
/** My fancy command */
|
70
|
-
myFancyCommand: Command(0x1, TlvMyFancyCommandRequest, 0x2, TlvMyFancyCommandResponse),
|
71
|
-
},
|
72
|
-
|
73
|
-
events: {
|
74
|
-
/** My fancy event */
|
75
|
-
myFancyEvent: Event(0x5, EventPriority.Info, TlvMyFancyEvent),
|
76
|
-
},
|
77
|
-
});
|
78
|
-
|
79
|
-
/**
|
80
|
-
* My Fancy Cluster
|
81
|
-
*
|
82
|
-
* This cluster provides an interface to some fancy custom functions.
|
83
|
-
*/
|
84
|
-
export interface Cluster extends Identity<typeof ClusterInstance> {}
|
85
|
-
|
86
|
-
export const Cluster: Cluster = ClusterInstance;
|
87
|
-
|
88
|
-
export const Complete = Cluster;
|
89
|
-
}
|
90
|
-
|
91
|
-
export type MyFancyOwnFunctionalityCluster = MyFancyOwnFunctionality.Cluster;
|
92
|
-
export const MyFancyOwnFunctionalityCluster = MyFancyOwnFunctionality.Cluster;
|
93
|
-
ClusterRegistry.register(MyFancyOwnFunctionality.Complete);
|
94
|
-
|
95
|
-
/**
|
96
|
-
* matter.js Model Schema for the cluster, need to match with the Tlv Schema above.
|
97
|
-
* See more details in packages/matter.js/behavior/definitions/*
|
98
|
-
*/
|
99
|
-
const MyFancySchema = ClusterElement({
|
100
|
-
name: "MyFancyOwnFunctionality",
|
101
|
-
id: myFancyClusterId,
|
102
|
-
classification: "application",
|
103
|
-
description: "My Fancy Functionality",
|
104
|
-
|
105
|
-
children: [
|
106
|
-
AttributeElement({ name: "ClusterRevision", id: 0xfffd, type: "ClusterRevision", default: 1 }),
|
107
|
-
|
108
|
-
AttributeElement({
|
109
|
-
name: "MyFancyValue",
|
110
|
-
id: 0x0,
|
111
|
-
type: "int16",
|
112
|
-
access: "R V",
|
113
|
-
conformance: "M",
|
114
|
-
quality: "X",
|
115
|
-
}),
|
116
|
-
|
117
|
-
CommandElement({
|
118
|
-
name: "MyFancyCommand",
|
119
|
-
id: 0x1,
|
120
|
-
access: "O",
|
121
|
-
conformance: "M",
|
122
|
-
direction: "request",
|
123
|
-
response: "MyFancyCommandResponse",
|
124
|
-
|
125
|
-
children: [FieldElement({ name: "value", id: 0x0, type: "string", conformance: "M" })],
|
126
|
-
}),
|
127
|
-
CommandElement({
|
128
|
-
name: "MyFancyCommandResponse",
|
129
|
-
id: 0x2,
|
130
|
-
conformance: "M",
|
131
|
-
direction: "request",
|
132
|
-
|
133
|
-
children: [FieldElement({ name: "response", id: 0x0, type: "string", conformance: "M" })],
|
134
|
-
}),
|
135
|
-
|
136
|
-
EventElement({
|
137
|
-
name: "MyFancyEvent",
|
138
|
-
id: 0x5,
|
139
|
-
access: "V",
|
140
|
-
conformance: "O",
|
141
|
-
priority: "info",
|
142
|
-
children: [
|
143
|
-
FieldElement({
|
144
|
-
name: "EventValue",
|
145
|
-
id: 0x0,
|
146
|
-
type: "string",
|
147
|
-
conformance: "M",
|
148
|
-
}),
|
149
|
-
],
|
150
|
-
}),
|
151
|
-
],
|
152
|
-
});
|
153
|
-
|
154
|
-
/**
|
155
|
-
* Interface definitions - exposes the Implementation interface for the cluster and some types to be used in the
|
156
|
-
* cluster implementations.
|
157
|
-
*/
|
158
|
-
export type MyFancyCommandRequest = TypeFromSchema<typeof MyFancyOwnFunctionality.TlvMyFancyCommandRequest>;
|
159
|
-
export type MyFancyCommandResponse = TypeFromSchema<typeof MyFancyOwnFunctionality.TlvMyFancyCommandResponse>;
|
160
|
-
export type MyFancyEvent = TypeFromSchema<typeof MyFancyOwnFunctionality.TlvMyFancyEvent>;
|
161
|
-
|
162
|
-
export namespace MyFancyOwnFunctionalityInterface {
|
163
|
-
export interface Base {
|
164
|
-
myFancyCommand(request: MyFancyCommandRequest): MaybePromise<MyFancyCommandResponse>;
|
165
|
-
}
|
166
|
-
}
|
167
|
-
|
168
|
-
export type MyFancyOwnFunctionalityInterface = {
|
169
|
-
components: [{ flags: {}; methods: MyFancyOwnFunctionalityInterface.Base }];
|
170
|
-
};
|
171
|
-
|
172
|
-
/**
|
173
|
-
* Behavior definition for the cluster command handler implementation
|
174
|
-
*/
|
175
|
-
export const MyFancyOwnFunctionalityBehavior = ClusterBehavior.withInterface<MyFancyOwnFunctionalityInterface>().for(
|
176
|
-
MyFancyOwnFunctionality.Cluster,
|
177
|
-
new ClusterModel(MyFancySchema),
|
178
|
-
);
|
179
|
-
|
180
|
-
type MyFancyOwnFunctionalityBehaviorType = InstanceType<typeof MyFancyOwnFunctionalityBehavior>;
|
181
|
-
export interface MyFancyOwnFunctionalityBehavior extends MyFancyOwnFunctionalityBehaviorType {}
|
182
|
-
type StateType = InstanceType<typeof MyFancyOwnFunctionalityBehavior.State>;
|
183
|
-
export namespace MyFancyOwnFunctionalityBehavior {
|
184
|
-
export interface State extends StateType {}
|
185
|
-
}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import "@project-chip/matter.js-nodejs";
|
2
|
-
import { OnOffLightDevice } from "@project-chip/matter.js/devices/OnOffLightDevice";
|
3
|
-
import { ServerNode } from "@project-chip/matter.js/node";
|
4
|
-
|
5
|
-
const node = await ServerNode.create();
|
6
|
-
|
7
|
-
await node.add(OnOffLightDevice);
|
8
|
-
|
9
|
-
await node.run();
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import "@project-chip/matter.js-nodejs";
|
2
|
-
import { OnOffLightDevice, OnOffLightRequirements } from "@project-chip/matter.js/devices/OnOffLightDevice";
|
3
|
-
import { ServerNode } from "@project-chip/matter.js/node";
|
4
|
-
|
5
|
-
class MyOnOffServer extends OnOffLightRequirements.OnOffServer {
|
6
|
-
override on() {
|
7
|
-
console.log("Turning on");
|
8
|
-
}
|
9
|
-
|
10
|
-
override off() {
|
11
|
-
console.log("Turning off");
|
12
|
-
}
|
13
|
-
}
|
14
|
-
|
15
|
-
const node = await ServerNode.create();
|
16
|
-
|
17
|
-
await node.add(OnOffLightDevice.with(MyOnOffServer));
|
18
|
-
|
19
|
-
await node.run();
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import "@project-chip/matter.js-nodejs";
|
2
|
-
import { OnOffLightDevice } from "@project-chip/matter.js/devices/OnOffLightDevice";
|
3
|
-
import { ServerNode } from "@project-chip/matter.js/node";
|
4
|
-
|
5
|
-
const node = await ServerNode.create();
|
6
|
-
|
7
|
-
const light = await node.add(OnOffLightDevice);
|
8
|
-
|
9
|
-
light.events.onOff.onOff$Changed.on(newValue => {
|
10
|
-
console.log(`Light is ${newValue ? "on" : "off"}`);
|
11
|
-
});
|
12
|
-
|
13
|
-
await node.run();
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import "@project-chip/matter.js-nodejs";
|
2
|
-
import { OnOffLightDevice } from "@project-chip/matter.js/devices/OnOffLightDevice";
|
3
|
-
import { ServerNode } from "@project-chip/matter.js/node";
|
4
|
-
|
5
|
-
const node = await ServerNode.create();
|
6
|
-
|
7
|
-
const light = await node.add(OnOffLightDevice);
|
8
|
-
|
9
|
-
await node.start();
|
10
|
-
|
11
|
-
await light.act(async agent => {
|
12
|
-
await agent.onOff.toggle();
|
13
|
-
console.log("On/off state after first toggle", agent.onOff.state);
|
14
|
-
|
15
|
-
await agent.onOff.toggle();
|
16
|
-
console.log("On/off state after second toggle", agent.onOff.state);
|
17
|
-
});
|
18
|
-
|
19
|
-
await node.close();
|