matterbridge 1.6.8-dev.1 → 1.6.8-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -1
- package/README-SERVICE.md +12 -3
- package/README.md +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +26 -0
- package/dist/cli.js.map +1 -0
- package/dist/cluster/export.d.ts.map +1 -0
- package/dist/cluster/export.js +2 -0
- package/dist/cluster/export.js.map +1 -0
- package/dist/defaultConfigSchema.d.ts.map +1 -0
- package/dist/defaultConfigSchema.js +23 -0
- package/dist/defaultConfigSchema.js.map +1 -0
- package/dist/deviceManager.d.ts +46 -0
- package/dist/deviceManager.d.ts.map +1 -0
- package/dist/deviceManager.js +26 -1
- package/dist/deviceManager.js.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/export.d.ts.map +1 -0
- package/dist/logger/export.js +1 -0
- package/dist/logger/export.js.map +1 -0
- package/dist/matter/export.d.ts.map +1 -0
- package/dist/matter/export.js +1 -0
- package/dist/matter/export.js.map +1 -0
- package/dist/matterbridge.d.ts +466 -0
- package/dist/matterbridge.d.ts.map +1 -0
- package/dist/matterbridge.js +661 -62
- package/dist/matterbridge.js.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.js +33 -0
- package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
- package/dist/matterbridgeBehaviors.d.ts +116 -0
- package/dist/matterbridgeBehaviors.d.ts.map +1 -0
- package/dist/matterbridgeBehaviors.js +29 -1
- package/dist/matterbridgeBehaviors.js.map +1 -0
- package/dist/matterbridgeDevice.d.ts +1142 -0
- package/dist/matterbridgeDevice.d.ts.map +1 -0
- package/dist/matterbridgeDevice.js +1009 -8
- package/dist/matterbridgeDevice.js.map +1 -0
- package/dist/matterbridgeDeviceTypes.d.ts +109 -0
- package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
- package/dist/matterbridgeDeviceTypes.js +82 -11
- package/dist/matterbridgeDeviceTypes.js.map +1 -0
- package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
- package/dist/matterbridgeDynamicPlatform.js +33 -0
- package/dist/matterbridgeDynamicPlatform.js.map +1 -0
- package/dist/matterbridgeEdge.d.ts +90 -0
- package/dist/matterbridgeEdge.d.ts.map +1 -0
- package/dist/matterbridgeEdge.js +529 -0
- package/dist/matterbridgeEdge.js.map +1 -0
- package/dist/matterbridgeEndpoint.d.ts +1134 -0
- package/dist/matterbridgeEndpoint.d.ts.map +1 -0
- package/dist/matterbridgeEndpoint.js +1134 -11
- package/dist/matterbridgeEndpoint.js.map +1 -0
- package/dist/matterbridgePlatform.d.ts +114 -0
- package/dist/matterbridgePlatform.d.ts.map +1 -0
- package/dist/matterbridgePlatform.js +91 -3
- package/dist/matterbridgePlatform.js.map +1 -0
- package/dist/matterbridgeTypes.d.ts.map +1 -0
- package/dist/matterbridgeTypes.js +24 -0
- package/dist/matterbridgeTypes.js.map +1 -0
- package/dist/matterbridgeWebsocket.d.ts.map +1 -0
- package/dist/matterbridgeWebsocket.js +45 -0
- package/dist/matterbridgeWebsocket.js.map +1 -0
- package/dist/pluginManager.d.ts +238 -0
- package/dist/pluginManager.d.ts.map +1 -0
- package/dist/pluginManager.js +238 -3
- package/dist/pluginManager.js.map +1 -0
- package/dist/storage/export.d.ts.map +1 -0
- package/dist/storage/export.js +1 -0
- package/dist/storage/export.js.map +1 -0
- package/dist/utils/colorUtils.d.ts.map +1 -0
- package/dist/utils/colorUtils.js +205 -2
- package/dist/utils/colorUtils.js.map +1 -0
- package/dist/utils/export.d.ts.map +1 -0
- package/dist/utils/export.js +1 -0
- package/dist/utils/export.js.map +1 -0
- package/dist/utils/utils.d.ts +221 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +252 -7
- package/dist/utils/utils.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/matterbridgeEdge.js
CHANGED
|
@@ -1,11 +1,39 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/**
|
|
3
|
+
* This file contains the class MatterbridgeEdge that extends the Matterbridge class.
|
|
4
|
+
*
|
|
5
|
+
* @file matterbridgeEdge.ts
|
|
6
|
+
* @author Luca Liguori
|
|
7
|
+
* @date 2024-10-01
|
|
8
|
+
* @version 1.0.0
|
|
9
|
+
*
|
|
10
|
+
* Copyright 2024, 2025, 2026 Luca Liguori.
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License. *
|
|
23
|
+
*/
|
|
24
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
25
|
+
// Node.js modules
|
|
1
26
|
import path from 'path';
|
|
2
27
|
import os from 'os';
|
|
3
28
|
import { randomBytes } from 'crypto';
|
|
29
|
+
// NodeStorage and AnsiLogger modules
|
|
4
30
|
import { rs, GREEN, debugStringify, er, zb, nf, db } from 'node-ansi-logger';
|
|
31
|
+
// Matterbridge
|
|
5
32
|
import { Matterbridge } from './matterbridge.js';
|
|
6
33
|
import { bridge } from './matterbridgeDeviceTypes.js';
|
|
7
34
|
import { dev, plg } from './matterbridgeTypes.js';
|
|
8
35
|
import { copyDirectory, getParameter, hasParameter } from './utils/utils.js';
|
|
36
|
+
// @matter
|
|
9
37
|
import { DeviceTypeId, LogLevel as MatterLogLevel, LogFormat as MatterLogFormat, VendorId, EndpointServer } from '@matter/main';
|
|
10
38
|
import { ServerNode, Endpoint as EndpointNode, Environment, StorageService } from '@matter/main';
|
|
11
39
|
import { BasicInformationCluster } from '@matter/main/clusters';
|
|
@@ -14,11 +42,18 @@ import { GenericSwitchDevice } from '@matter/main/devices';
|
|
|
14
42
|
import { AggregatorEndpoint } from '@matter/main/endpoints';
|
|
15
43
|
import { BridgedDeviceBasicInformationServer, SwitchServer } from '@matter/main/behaviors';
|
|
16
44
|
import { Device, logEndpoint } from '@project-chip/matter.js/device';
|
|
45
|
+
/**
|
|
46
|
+
* Represents the MatterbridgeEdge application.
|
|
47
|
+
*/
|
|
17
48
|
export class MatterbridgeEdge extends Matterbridge {
|
|
18
49
|
static instance;
|
|
50
|
+
// Matter environment
|
|
19
51
|
environment = Environment.default;
|
|
52
|
+
// Matter storage
|
|
20
53
|
matterStorageService;
|
|
54
|
+
// Mapping of CommissioningServer to ServerNode
|
|
21
55
|
csToServerNode = new Map();
|
|
56
|
+
// Mapping of Aggregator to AggregatorEndpoint
|
|
22
57
|
agToAggregatorEndpoint = new Map();
|
|
23
58
|
constructor() {
|
|
24
59
|
super();
|
|
@@ -36,24 +71,30 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
36
71
|
async initialize() {
|
|
37
72
|
if (hasParameter('debug'))
|
|
38
73
|
console.log('Initializing MatterbridgeEdge...');
|
|
74
|
+
// Set the matterbridge directory
|
|
39
75
|
this.homeDirectory = getParameter('homedir') ?? os.homedir();
|
|
40
76
|
this.matterbridgeDirectory = path.join(this.homeDirectory, '.matterbridge');
|
|
41
77
|
this.matterStorageName = 'matterstorage' + (getParameter('profile') ? '.' + getParameter('profile') : '');
|
|
78
|
+
// Setup matter environment
|
|
42
79
|
this.environment.vars.set('log.level', MatterLogLevel.INFO);
|
|
43
80
|
this.environment.vars.set('log.format', MatterLogFormat.ANSI);
|
|
44
81
|
this.environment.vars.set('path.root', path.join(this.matterbridgeDirectory, this.matterStorageName));
|
|
45
82
|
this.environment.vars.set('runtime.signals', false);
|
|
46
83
|
this.environment.vars.set('runtime.exitcode', false);
|
|
84
|
+
// Setup Matter commissioning server
|
|
47
85
|
this.port = 5540;
|
|
48
86
|
this.passcode = PaseClient.generateRandomPasscode();
|
|
49
87
|
this.discriminator = PaseClient.generateRandomDiscriminator();
|
|
50
88
|
if (hasParameter('debug'))
|
|
51
89
|
console.log(`Initializing server node for Matterbridge... on port ${this.port} with passcode ${this.passcode} and discriminator ${this.discriminator}`);
|
|
90
|
+
// Initialize the base Matterbridge class
|
|
52
91
|
await super.initialize();
|
|
92
|
+
// Setup Matter mdnsInterface
|
|
53
93
|
if (this.mdnsInterface)
|
|
54
94
|
this.environment.vars.set('mdns.networkInterface', this.mdnsInterface);
|
|
55
95
|
}
|
|
56
96
|
async startMatterStorage(storageType, storageName) {
|
|
97
|
+
// Setup Matter storage
|
|
57
98
|
this.log.info(`Starting matter node storage...`);
|
|
58
99
|
this.matterStorageService = this.environment.get(StorageService);
|
|
59
100
|
this.log.info(`Matter node storage service created: ${this.matterStorageService.location}`);
|
|
@@ -61,6 +102,7 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
61
102
|
this.log.info('Matter node storage manager "Matterbridge" created');
|
|
62
103
|
this.matterbridgeContext = await this.createServerNodeContext('Matterbridge', 'Matterbridge', bridge.code, this.aggregatorVendorId, 'Matterbridge', this.aggregatorProductId, 'Matterbridge aggregator');
|
|
63
104
|
this.log.info('Matter node storage started');
|
|
105
|
+
// Backup matter storage since it is created/opened correctly
|
|
64
106
|
await this.backupMatterStorage(path.join(this.matterbridgeDirectory, this.matterStorageName), path.join(this.matterbridgeDirectory, this.matterStorageName + '.backup'));
|
|
65
107
|
}
|
|
66
108
|
async backupMatterStorage(storageName, backupName) {
|
|
@@ -76,6 +118,24 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
76
118
|
this.matterbridgeContext = undefined;
|
|
77
119
|
this.log.info('Matter node storage closed');
|
|
78
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Creates a server node storage context.
|
|
123
|
+
*
|
|
124
|
+
* @param pluginName - The name of the plugin.
|
|
125
|
+
* @param deviceName - The name of the device.
|
|
126
|
+
* @param deviceType - The deviceType of the device.
|
|
127
|
+
* @param vendorId - The vendor ID.
|
|
128
|
+
* @param vendorName - The vendor name.
|
|
129
|
+
* @param productId - The product ID.
|
|
130
|
+
* @param productName - The product name.
|
|
131
|
+
* @param serialNumber - The serial number of the device (optional).
|
|
132
|
+
* @param uniqueId - The unique ID of the device (optional).
|
|
133
|
+
* @param softwareVersion - The software version of the device (optional).
|
|
134
|
+
* @param softwareVersionString - The software version string of the device (optional).
|
|
135
|
+
* @param hardwareVersion - The hardware version of the device (optional).
|
|
136
|
+
* @param hardwareVersionString - The hardware version string of the device (optional).
|
|
137
|
+
* @returns The storage context for the commissioning server.
|
|
138
|
+
*/
|
|
79
139
|
async createServerNodeContext(pluginName, deviceName, deviceType, vendorId, vendorName, productId, productName, serialNumber) {
|
|
80
140
|
if (!this.matterStorageService)
|
|
81
141
|
throw new Error('No storage service initialized');
|
|
@@ -117,21 +177,33 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
117
177
|
this.log.debug(`- uniqueId: ${await storageContext.get('uniqueId')}`);
|
|
118
178
|
this.log.debug(`- softwareVersion: ${await storageContext.get('softwareVersion')} softwareVersionString: ${await storageContext.get('softwareVersionString')}`);
|
|
119
179
|
this.log.debug(`- hardwareVersion: ${await storageContext.get('hardwareVersion')} hardwareVersionString: ${await storageContext.get('hardwareVersionString')}`);
|
|
180
|
+
/**
|
|
181
|
+
* Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration
|
|
182
|
+
*/
|
|
120
183
|
const serverNode = await ServerNode.create({
|
|
184
|
+
// Required: Give the Node a unique ID which is used to store the state of this node
|
|
121
185
|
id: storeId,
|
|
186
|
+
// Provide Network relevant configuration like the port
|
|
187
|
+
// Optional when operating only one device on a host, Default port is 5540
|
|
122
188
|
network: {
|
|
123
189
|
listeningAddressIpv4: this.ipv4address,
|
|
124
190
|
listeningAddressIpv6: this.ipv6address,
|
|
125
191
|
port,
|
|
126
192
|
},
|
|
193
|
+
// Provide Commissioning relevant settings
|
|
194
|
+
// Optional for development/testing purposes
|
|
127
195
|
commissioning: {
|
|
128
196
|
passcode,
|
|
129
197
|
discriminator,
|
|
130
198
|
},
|
|
199
|
+
// Provide Node announcement settings
|
|
200
|
+
// Optional: If Ommitted some development defaults are used
|
|
131
201
|
productDescription: {
|
|
132
202
|
name: await storageContext.get('deviceName'),
|
|
133
203
|
deviceType: DeviceTypeId(await storageContext.get('deviceType')),
|
|
134
204
|
},
|
|
205
|
+
// Provide defaults for the BasicInformation cluster on the Root endpoint
|
|
206
|
+
// Optional: If Omitted some development defaults are used
|
|
135
207
|
basicInformation: {
|
|
136
208
|
vendorId: VendorId(await storageContext.get('vendorId')),
|
|
137
209
|
vendorName: await storageContext.get('vendorName'),
|
|
@@ -148,6 +220,7 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
148
220
|
},
|
|
149
221
|
});
|
|
150
222
|
const sanitizeFabrics = (fabrics) => {
|
|
223
|
+
// New type of fabric information: Record<FabricIndex, ExposedFabricInformation>
|
|
151
224
|
const sanitizedFabrics = this.sanitizeFabricInformations(Array.from(Object.values(fabrics)));
|
|
152
225
|
this.log.info(`Fabrics: ${debugStringify(sanitizedFabrics)}`);
|
|
153
226
|
if (this.bridgeMode === 'bridge') {
|
|
@@ -164,8 +237,14 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
164
237
|
}
|
|
165
238
|
}
|
|
166
239
|
};
|
|
240
|
+
/**
|
|
241
|
+
* This event is triggered when the device is initially commissioned successfully.
|
|
242
|
+
* This means: It is added to the first fabric.
|
|
243
|
+
*/
|
|
167
244
|
serverNode.lifecycle.commissioned.on(() => this.log.notice(`Server node for ${storeId} was initially commissioned successfully!`));
|
|
245
|
+
/** This event is triggered when all fabrics are removed from the device, usually it also does a factory reset then. */
|
|
168
246
|
serverNode.lifecycle.decommissioned.on(() => this.log.notice(`Server node for ${storeId} was fully decommissioned successfully!`));
|
|
247
|
+
/** This event is triggered when the device went online. This means that it is discoverable in the network. */
|
|
169
248
|
serverNode.lifecycle.online.on(() => {
|
|
170
249
|
this.log.notice(`Server node for ${storeId} is online`);
|
|
171
250
|
if (!serverNode.lifecycle.isCommissioned) {
|
|
@@ -200,6 +279,7 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
200
279
|
sanitizeFabrics(serverNode.state.commissioning.fabrics);
|
|
201
280
|
}
|
|
202
281
|
});
|
|
282
|
+
/** This event is triggered when the device went offline. it is not longer discoverable or connectable in the network. */
|
|
203
283
|
serverNode.lifecycle.offline.on(() => {
|
|
204
284
|
this.log.notice(`Server node for ${storeId} is offline`);
|
|
205
285
|
if (this.bridgeMode === 'bridge') {
|
|
@@ -211,6 +291,10 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
211
291
|
this.matterbridgeConnected = false;
|
|
212
292
|
}
|
|
213
293
|
});
|
|
294
|
+
/**
|
|
295
|
+
* This event is triggered when a fabric is added, removed or updated on the device. Use this if more granular
|
|
296
|
+
* information is needed.
|
|
297
|
+
*/
|
|
214
298
|
serverNode.events.commissioning.fabricsChanged.on((fabricIndex, fabricAction) => {
|
|
215
299
|
let action = '';
|
|
216
300
|
switch (fabricAction) {
|
|
@@ -243,14 +327,22 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
243
327
|
}
|
|
244
328
|
}
|
|
245
329
|
};
|
|
330
|
+
/**
|
|
331
|
+
* This event is triggered when an operative new session was opened by a Controller.
|
|
332
|
+
* It is not triggered for the initial commissioning process, just afterwards for real connections.
|
|
333
|
+
*/
|
|
246
334
|
serverNode.events.sessions.opened.on((session) => {
|
|
247
335
|
this.log.notice(`Session opened on server node for ${storeId}: ${debugStringify(session)}`);
|
|
248
336
|
sanitizeSessions(Object.values(serverNode.state.sessions.sessions));
|
|
249
337
|
});
|
|
338
|
+
/**
|
|
339
|
+
* This event is triggered when an operative session is closed by a Controller or because the Device goes offline.
|
|
340
|
+
*/
|
|
250
341
|
serverNode.events.sessions.closed.on((session) => {
|
|
251
342
|
this.log.notice(`Session closed on server node for ${storeId}: ${debugStringify(session)}`);
|
|
252
343
|
sanitizeSessions(Object.values(serverNode.state.sessions.sessions));
|
|
253
344
|
});
|
|
345
|
+
/** This event is triggered when a subscription gets added or removed on an operative session. */
|
|
254
346
|
serverNode.events.sessions.subscriptionsChanged.on((session) => {
|
|
255
347
|
this.log.notice(`Session subscriptions changed on server node for ${storeId}: ${debugStringify(session)}`);
|
|
256
348
|
sanitizeSessions(Object.values(serverNode.state.sessions.sessions));
|
|
@@ -276,11 +368,13 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
276
368
|
return aggregator;
|
|
277
369
|
}
|
|
278
370
|
async addBridgedEndpoint(pluginName, device) {
|
|
371
|
+
// Check if the plugin is registered
|
|
279
372
|
const plugin = this.plugins.get(pluginName);
|
|
280
373
|
if (!plugin) {
|
|
281
374
|
this.log.error(`Error adding bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.id}${er}) plugin ${plg}${pluginName}${er} not found`);
|
|
282
375
|
return;
|
|
283
376
|
}
|
|
377
|
+
// Register and add the device to the matterbridge aggregator node
|
|
284
378
|
if (this.bridgeMode === 'bridge') {
|
|
285
379
|
this.log.info(`Adding ${pluginName}:${device.deviceName} to Matterbridge aggregator node`);
|
|
286
380
|
const aggregatorNode = this.agToAggregatorEndpoint.get('Matterbridge')?.aggregatorNode;
|
|
@@ -316,16 +410,19 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
316
410
|
plugin.registeredDevices++;
|
|
317
411
|
if (plugin.addedDevices !== undefined)
|
|
318
412
|
plugin.addedDevices++;
|
|
413
|
+
// Add the device to the DeviceManager
|
|
319
414
|
this.devices.set(device);
|
|
320
415
|
this.log.info(`Added and registered bridged endpoint (${plugin.registeredDevices}/${plugin.addedDevices}) ${dev}${device.deviceName}${nf} (${dev}${device.id}${nf}) for plugin ${plg}${pluginName}${nf}`);
|
|
321
416
|
}
|
|
322
417
|
async removeBridgedEndpoint(pluginName, device) {
|
|
323
418
|
this.log.debug(`Removing bridged endpoint ${dev}${device.deviceName}${db} (${zb}${device.name}${db}) for plugin ${plg}${pluginName}${db}`);
|
|
419
|
+
// Check if the plugin is registered
|
|
324
420
|
const plugin = this.plugins.get(pluginName);
|
|
325
421
|
if (!plugin) {
|
|
326
422
|
this.log.error(`Error removing bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.name}${er}) for plugin ${plg}${pluginName}${er}: plugin not found`);
|
|
327
423
|
return;
|
|
328
424
|
}
|
|
425
|
+
// Register and add the device to the matterbridge aggregator node
|
|
329
426
|
if (this.bridgeMode === 'bridge') {
|
|
330
427
|
const aggregatoreNode = this.agToAggregatorEndpoint.get('Matterbridge')?.aggregatorNode;
|
|
331
428
|
if (!aggregatoreNode) {
|
|
@@ -341,6 +438,7 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
341
438
|
}
|
|
342
439
|
else if (this.bridgeMode === 'childbridge') {
|
|
343
440
|
if (plugin.type === 'AccessoryPlatform') {
|
|
441
|
+
// Nothing to do
|
|
344
442
|
}
|
|
345
443
|
else if (plugin.type === 'DynamicPlatform') {
|
|
346
444
|
const aggregatoreNode = this.agToAggregatorEndpoint.get(pluginName)?.aggregatorNode;
|
|
@@ -355,6 +453,7 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
355
453
|
plugin.registeredDevices--;
|
|
356
454
|
if (plugin.addedDevices !== undefined)
|
|
357
455
|
plugin.addedDevices--;
|
|
456
|
+
// Close the server node
|
|
358
457
|
if (plugin.registeredDevices === 0 && plugin.addedDevices === 0) {
|
|
359
458
|
const serverNode = this.csToServerNode.get(pluginName)?.serverNode;
|
|
360
459
|
if (serverNode)
|
|
@@ -363,6 +462,7 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
363
462
|
this.log.info(`Removed server node for plugin ${plg}${pluginName}${nf}`);
|
|
364
463
|
}
|
|
365
464
|
}
|
|
465
|
+
// Remove the device from the DeviceManager
|
|
366
466
|
this.devices.remove(device);
|
|
367
467
|
}
|
|
368
468
|
async removeAllBridgedEndpoints(pluginName) {
|
|
@@ -371,6 +471,9 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
371
471
|
await this.removeBridgedEndpoint(pluginName, device);
|
|
372
472
|
}
|
|
373
473
|
}
|
|
474
|
+
/**
|
|
475
|
+
* override from Matterbridge
|
|
476
|
+
*/
|
|
374
477
|
createMatterServer(storageManager) {
|
|
375
478
|
if (hasParameter('debug'))
|
|
376
479
|
this.log.warn('createMatterServer() => mock MatterServer.addCommissioningServer()');
|
|
@@ -434,6 +537,7 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
434
537
|
const commissioningServer = {
|
|
435
538
|
getPort: () => port,
|
|
436
539
|
addDevice: async (device) => {
|
|
540
|
+
// if (hasParameter('debug')) this.log.warn('CommissioningServer.addDevice()', device.name);
|
|
437
541
|
if (device instanceof Device) {
|
|
438
542
|
if (hasParameter('debug'))
|
|
439
543
|
this.log.warn('CommissioningServer.addDevice() => Device');
|
|
@@ -448,6 +552,7 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
448
552
|
await serverNode.add(aggregatorNode);
|
|
449
553
|
if (!this.test) {
|
|
450
554
|
this.test = true;
|
|
555
|
+
// await this.testEndpoints();
|
|
451
556
|
}
|
|
452
557
|
}
|
|
453
558
|
},
|
|
@@ -504,6 +609,37 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
504
609
|
const aggregatorNode = this.agToAggregatorEndpoint.get('Matterbridge')?.aggregatorNode;
|
|
505
610
|
if (!aggregatorNode)
|
|
506
611
|
return;
|
|
612
|
+
/*
|
|
613
|
+
this.log.notice(`Creating OnOffLight1`);
|
|
614
|
+
const lightEndpoint = new MatterbridgeEndpoint(onOffLight, { uniqueStorageKey: 'OnOffLight1' }, true);
|
|
615
|
+
lightEndpoint.addDeviceType(bridgedNode);
|
|
616
|
+
lightEndpoint.createDefaultBridgedDeviceBasicInformationClusterServer('OnOffLight 1', '123456789', 0xfff1, 'Matterbridge', 'Light');
|
|
617
|
+
lightEndpoint.addDeviceType(powerSource);
|
|
618
|
+
lightEndpoint.createDefaultPowerSourceWiredClusterServer();
|
|
619
|
+
lightEndpoint.addDeviceType(electricalSensor);
|
|
620
|
+
lightEndpoint.addClusterServer(lightEndpoint.getDefaultElectricalEnergyMeasurementClusterServer());
|
|
621
|
+
lightEndpoint.addClusterServer(lightEndpoint.getDefaultElectricalPowerMeasurementClusterServer());
|
|
622
|
+
lightEndpoint.addRequiredClusterServers(lightEndpoint);
|
|
623
|
+
this.log.notice(`Adding OnOffLight1 to ${await this.matterbridgeContext.get<string>('storeId')} aggregator`);
|
|
624
|
+
await aggregatorNode.add(lightEndpoint);
|
|
625
|
+
logEndpoint(EndpointServer.forEndpoint(lightEndpoint));
|
|
626
|
+
|
|
627
|
+
this.log.notice(`Creating Outlet1`);
|
|
628
|
+
const outletEndpoint = new MatterbridgeEndpoint(onOffOutlet, { uniqueStorageKey: 'OnOffOutlet1' }, true);
|
|
629
|
+
outletEndpoint.addDeviceType(bridgedNode);
|
|
630
|
+
outletEndpoint.createDefaultBridgedDeviceBasicInformationClusterServer('OnOffOutlet 1', '123456789', 0xfff1, 'Matterbridge', 'Outlet');
|
|
631
|
+
outletEndpoint.addDeviceType(powerSource);
|
|
632
|
+
outletEndpoint.createDefaultPowerSourceReplaceableBatteryClusterServer();
|
|
633
|
+
outletEndpoint.addDeviceType(electricalSensor);
|
|
634
|
+
outletEndpoint.addClusterServer(outletEndpoint.getDefaultElectricalEnergyMeasurementClusterServer());
|
|
635
|
+
outletEndpoint.addClusterServer(outletEndpoint.getDefaultElectricalPowerMeasurementClusterServer());
|
|
636
|
+
outletEndpoint.addRequiredClusterServers(outletEndpoint);
|
|
637
|
+
const input0 = outletEndpoint.addChildDeviceTypeWithClusterServer('Input:0', [genericSwitch], undefined, undefined, true);
|
|
638
|
+
const input1 = outletEndpoint.addChildDeviceTypeWithClusterServer('Input:1', [genericSwitch], undefined, undefined, true);
|
|
639
|
+
this.log.notice(`Adding OnOffOutlet1 to ${await this.matterbridgeContext.get<string>('storeId')} aggregator`);
|
|
640
|
+
await aggregatorNode.add(outletEndpoint);
|
|
641
|
+
logEndpoint(EndpointServer.forEndpoint(outletEndpoint));
|
|
642
|
+
*/
|
|
507
643
|
this.log.notice(`Creating switchEnpoint1`);
|
|
508
644
|
const switchEnpoint1 = new EndpointNode(GenericSwitchDevice.with(BridgedDeviceBasicInformationServer, SwitchServer.with('MomentarySwitch', 'MomentarySwitchLongPress', 'MomentarySwitchMultiPress', 'MomentarySwitchRelease')), {
|
|
509
645
|
id: 'GenericSwitch',
|
|
@@ -526,5 +662,398 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
526
662
|
this.log.notice(`Adding switchEnpoint1 to ${await this.matterbridgeContext.get('storeId')} aggregator`);
|
|
527
663
|
await aggregatorNode.add(switchEnpoint1);
|
|
528
664
|
logEndpoint(EndpointServer.forEndpoint(switchEnpoint1), { logNotSupportedClusterAttributes: true, logNotSupportedClusterEvents: true, logNotSupportedClusterCommands: true });
|
|
665
|
+
// if (switchEnpoint2.behaviors.has(SwitchServer)) this.log.notice(`SwitchServer found`);
|
|
666
|
+
// switchEnpoint2.act((agent) => agent['switch'].events['initialPress'].emit({ newPosition: 1 }, agent.context));
|
|
667
|
+
/*
|
|
668
|
+
const device = new MatterbridgeEndpoint(genericSwitch, { uniqueStorageKey: 'GenericSwitch 2' }, true);
|
|
669
|
+
device.createDefaultSwitchClusterServer();
|
|
670
|
+
device.addRequiredClusterServers(device);
|
|
671
|
+
await aggregatorNode.add(device);
|
|
672
|
+
logEndpoint(EndpointServer.forEndpoint(device));
|
|
673
|
+
await device.triggerSwitchEvent('Single', this.log);
|
|
674
|
+
await device.triggerSwitchEvent('Double', this.log);
|
|
675
|
+
await device.triggerSwitchEvent('Long', this.log);
|
|
676
|
+
|
|
677
|
+
const device1 = new MatterbridgeEndpoint(genericSwitch, { uniqueStorageKey: 'GenericSwitch 3' }, true);
|
|
678
|
+
device1.createDefaultLatchingSwitchClusterServer();
|
|
679
|
+
device1.addRequiredClusterServers(device1);
|
|
680
|
+
await aggregatorNode.add(device1);
|
|
681
|
+
logEndpoint(EndpointServer.forEndpoint(device1));
|
|
682
|
+
await device1.triggerSwitchEvent('Press', this.log);
|
|
683
|
+
await device1.triggerSwitchEvent('Release', this.log);
|
|
684
|
+
|
|
685
|
+
this.log.notice(`Creating TestLight`);
|
|
686
|
+
const matterbridgeDevice = new MatterbridgeEndpoint(onOffLight, { uniqueStorageKey: 'Test .Light:2' }, true);
|
|
687
|
+
matterbridgeDevice.behaviors.require(MatterbridgeIdentifyServer, {
|
|
688
|
+
identifyTime: 0,
|
|
689
|
+
identifyType: Identify.IdentifyType.None,
|
|
690
|
+
});
|
|
691
|
+
matterbridgeDevice.behaviors.require(GroupsServer);
|
|
692
|
+
matterbridgeDevice.behaviors.require(MatterbridgeOnOffServer, {
|
|
693
|
+
onOff: false,
|
|
694
|
+
});
|
|
695
|
+
matterbridgeDevice.behaviors.require(MatterbridgeLevelControlServer, {
|
|
696
|
+
currentLevel: 0,
|
|
697
|
+
options: { executeIfOff: false },
|
|
698
|
+
});
|
|
699
|
+
matterbridgeDevice.behaviors.require(MatterbridgeColorControlServer.with(ColorControl.Feature.HueSaturation, ColorControl.Feature.Xy, ColorControl.Feature.ColorTemperature), {
|
|
700
|
+
colorCapabilities: { xy: true, hueSaturation: true, colorLoop: false, enhancedHue: false, colorTemperature: true },
|
|
701
|
+
colorMode: ColorControl.ColorMode.ColorTemperatureMireds,
|
|
702
|
+
enhancedColorMode: ColorControl.EnhancedColorMode.ColorTemperatureMireds,
|
|
703
|
+
options: { executeIfOff: false },
|
|
704
|
+
numberOfPrimaries: null,
|
|
705
|
+
currentX: 24939,
|
|
706
|
+
currentY: 24701,
|
|
707
|
+
currentHue: 0,
|
|
708
|
+
currentSaturation: 0,
|
|
709
|
+
colorTemperatureMireds: 450,
|
|
710
|
+
colorTempPhysicalMinMireds: 150,
|
|
711
|
+
colorTempPhysicalMaxMireds: 450,
|
|
712
|
+
coupleColorTempToLevelMinMireds: 150,
|
|
713
|
+
startUpColorTemperatureMireds: null,
|
|
714
|
+
});
|
|
715
|
+
matterbridgeDevice.behaviors.require(BridgedDeviceBasicInformationServer, {
|
|
716
|
+
vendorId: VendorId(await this.matterbridgeContext.get<number>('vendorId')),
|
|
717
|
+
vendorName: await this.matterbridgeContext.get<string>('vendorName'),
|
|
718
|
+
productName: 'TestLight2',
|
|
719
|
+
productLabel: 'TestLight2',
|
|
720
|
+
nodeLabel: 'TestLight2',
|
|
721
|
+
serialNumber: 'SN 0x123456789',
|
|
722
|
+
uniqueId: '0x123456789',
|
|
723
|
+
reachable: true,
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
// await matterbridgeDevice.setTagList(null, 0x07, 1, 'endpoint 2');
|
|
727
|
+
// await matterbridgeDevice.configureColorControlCluster(false, false, true, ColorControl.ColorMode.ColorTemperatureMireds);
|
|
728
|
+
|
|
729
|
+
this.log.notice(`Adding TestLight`);
|
|
730
|
+
await aggregatorNode?.add(matterbridgeDevice);
|
|
731
|
+
|
|
732
|
+
this.log.notice(`Creating switchEnpoint1`);
|
|
733
|
+
const switchEnpoint2 = new EndpointNode(
|
|
734
|
+
GenericSwitchDevice.with(DescriptorServer.with(Descriptor.Feature.TagList), BridgedDeviceBasicInformationServer, SwitchServer.with('MomentarySwitch', 'MomentarySwitchLongPress', 'MomentarySwitchMultiPress', 'MomentarySwitchRelease')),
|
|
735
|
+
{
|
|
736
|
+
id: 'GenericSwitch1',
|
|
737
|
+
descriptor: {
|
|
738
|
+
tagList: [{ mfgCode: null, namespaceId: 0x07, tag: 1, label: 'Switch1' }],
|
|
739
|
+
},
|
|
740
|
+
bridgedDeviceBasicInformation: {
|
|
741
|
+
vendorId: VendorId(await this.matterbridgeContext.get<number>('vendorId')),
|
|
742
|
+
vendorName: await this.matterbridgeContext.get<string>('vendorName'),
|
|
743
|
+
|
|
744
|
+
productName: 'GenericSwitch',
|
|
745
|
+
productLabel: 'GenericSwitch',
|
|
746
|
+
nodeLabel: 'GenericSwitch',
|
|
747
|
+
|
|
748
|
+
serialNumber: 'SN 0x1234567397',
|
|
749
|
+
uniqueId: '0x1234567397',
|
|
750
|
+
reachable: true,
|
|
751
|
+
},
|
|
752
|
+
switch: {
|
|
753
|
+
numberOfPositions: 2,
|
|
754
|
+
currentPosition: 0,
|
|
755
|
+
multiPressMax: 2,
|
|
756
|
+
},
|
|
757
|
+
},
|
|
758
|
+
);
|
|
759
|
+
this.log.notice(`Creating switchEnpoint2`);
|
|
760
|
+
await aggregatorNode?.add(switchEnpoint2);
|
|
761
|
+
*/
|
|
762
|
+
/*
|
|
763
|
+
const lightEndpoint1 = new EndpointNode(ColorTemperatureLightDevice.with(BridgedDeviceBasicInformationServer), {
|
|
764
|
+
// }, MatterbridgeIdentifyServer, MatterbridgeOnOffServer, MatterbridgeLevelControlServer, MatterbridgeColorControlServer), {
|
|
765
|
+
id: 'OnOffLight',
|
|
766
|
+
bridgedDeviceBasicInformation: {
|
|
767
|
+
vendorId: VendorId(await this.matterbridgeContext.get<number>('vendorId')),
|
|
768
|
+
vendorName: await this.matterbridgeContext.get<string>('vendorName'),
|
|
769
|
+
|
|
770
|
+
productName: 'Light',
|
|
771
|
+
productLabel: 'Light',
|
|
772
|
+
nodeLabel: 'Light',
|
|
773
|
+
|
|
774
|
+
serialNumber: 'SN 0x123456789',
|
|
775
|
+
uniqueId: '0x123456789',
|
|
776
|
+
reachable: true,
|
|
777
|
+
},
|
|
778
|
+
levelControl: {
|
|
779
|
+
currentLevel: 0,
|
|
780
|
+
options: { executeIfOff: false, coupleColorTempToLevel: false },
|
|
781
|
+
},
|
|
782
|
+
colorControl: {
|
|
783
|
+
colorTemperatureMireds: 450,
|
|
784
|
+
colorMode: ColorControl.ColorMode.ColorTemperatureMireds,
|
|
785
|
+
colorTempPhysicalMinMireds: 150,
|
|
786
|
+
colorTempPhysicalMaxMireds: 450,
|
|
787
|
+
coupleColorTempToLevelMinMireds: 150,
|
|
788
|
+
startUpColorTemperatureMireds: 450,
|
|
789
|
+
},
|
|
790
|
+
});
|
|
791
|
+
lightEndpoint1.behaviors.require(ColorControlServer.with('ColorTemperature'), {
|
|
792
|
+
colorTemperatureMireds: 450,
|
|
793
|
+
colorMode: ColorControl.ColorMode.ColorTemperatureMireds,
|
|
794
|
+
colorTempPhysicalMinMireds: 150,
|
|
795
|
+
colorTempPhysicalMaxMireds: 450,
|
|
796
|
+
coupleColorTempToLevelMinMireds: 150,
|
|
797
|
+
startUpColorTemperatureMireds: 450,
|
|
798
|
+
});
|
|
799
|
+
await aggregatorNode?.add(lightEndpoint1);
|
|
800
|
+
|
|
801
|
+
/*
|
|
802
|
+
lightEndpoint1.behaviors.require(MatterbridgeIdentifyServer);
|
|
803
|
+
lightEndpoint1.behaviors.require(MatterbridgeOnOffServer);
|
|
804
|
+
lightEndpoint1.behaviors.require(MatterbridgeLevelControlServer);
|
|
805
|
+
lightEndpoint1.behaviors.require(MatterbridgeColorControlServer, {
|
|
806
|
+
colorTemperatureMireds: 250,
|
|
807
|
+
colorMode: ColorControl.ColorMode.ColorTemperatureMireds,
|
|
808
|
+
colorTempPhysicalMinMireds: 150,
|
|
809
|
+
colorTempPhysicalMaxMireds: 450,
|
|
810
|
+
coupleColorTempToLevelMinMireds: 150,
|
|
811
|
+
startUpColorTemperatureMireds: 450,
|
|
812
|
+
});
|
|
813
|
+
await aggregatorNode?.add(lightEndpoint1);
|
|
814
|
+
|
|
815
|
+
this.log.notice(`Creating switchEnpoint2`);
|
|
816
|
+
const switchEnpoint2 = new EndpointNode(GenericSwitchDevice.with(BridgedDeviceBasicInformationServer, SwitchServer.with('MomentarySwitch', 'MomentarySwitchLongPress', 'MomentarySwitchMultiPress', 'MomentarySwitchRelease')), {
|
|
817
|
+
id: 'GenericSwitch',
|
|
818
|
+
bridgedDeviceBasicInformation: {
|
|
819
|
+
vendorId: VendorId(await this.matterbridgeContext.get<number>('vendorId')),
|
|
820
|
+
vendorName: await this.matterbridgeContext.get<string>('vendorName'),
|
|
821
|
+
|
|
822
|
+
productName: 'GenericSwitch',
|
|
823
|
+
productLabel: 'GenericSwitch',
|
|
824
|
+
nodeLabel: 'GenericSwitch',
|
|
825
|
+
|
|
826
|
+
serialNumber: 'SN 0x123456739',
|
|
827
|
+
uniqueId: '0x123456739',
|
|
828
|
+
reachable: true,
|
|
829
|
+
},
|
|
830
|
+
switch: {
|
|
831
|
+
numberOfPositions: 2,
|
|
832
|
+
currentPosition: 0,
|
|
833
|
+
multiPressMax: 2,
|
|
834
|
+
},
|
|
835
|
+
});
|
|
836
|
+
await aggregatorNode?.add(switchEnpoint2);
|
|
837
|
+
*/
|
|
838
|
+
/*
|
|
839
|
+
for (let i = 1; i <= max; i++) {
|
|
840
|
+
this.log.notice(`Creating lightEndpoint${i}`);
|
|
841
|
+
const lightEndpoint = new MatterbridgeEndpoint(onOffLight, { uniqueStorageKey: 'OnOffLight' + i });
|
|
842
|
+
lightEndpoint.addClusterServer(lightEndpoint.getDefaultBridgedDeviceBasicInformationClusterServer('OnOffLight' + i, '123456789', 0xfff1, 'Matterbridge', 'Light'));
|
|
843
|
+
this.log.notice(`Adding lightEndpoint${i} to ${await this.matterbridgeContext.get<string>('storeId')} aggregator`);
|
|
844
|
+
await aggregatorNode?.add(lightEndpoint);
|
|
845
|
+
setInterval(async () => {
|
|
846
|
+
const state = lightEndpoint.getAttribute(OnOffCluster.id, 'onOff');
|
|
847
|
+
lightEndpoint.setAttribute(OnOffCluster.id, 'onOff', !state);
|
|
848
|
+
this.log.notice(`Setting state for lightEndpoint${i} from:`, state, 'to:', !state);
|
|
849
|
+
}, 10000);
|
|
850
|
+
}
|
|
851
|
+
for (let i = 1; i <= max; i++) {
|
|
852
|
+
this.log.notice(`Creating outletEndpoint${i}`);
|
|
853
|
+
const lightEndpoint = new MatterbridgeEndpoint(onOffOutlet, { uniqueStorageKey: 'OnOffOutlet' + i });
|
|
854
|
+
lightEndpoint.addClusterServer(lightEndpoint.getDefaultBridgedDeviceBasicInformationClusterServer('OnOffOutlet' + i, '123456789', 0xfff1, 'Matterbridge', 'Outlet'));
|
|
855
|
+
this.log.notice(`Adding outletEndpoint${i} to ${await this.matterbridgeContext.get<string>('storeId')} aggregator`);
|
|
856
|
+
await aggregatorNode?.add(lightEndpoint);
|
|
857
|
+
setInterval(async () => {
|
|
858
|
+
const state = lightEndpoint.getAttribute(OnOffCluster.id, 'onOff');
|
|
859
|
+
lightEndpoint.setAttribute(OnOffCluster.id, 'onOff', !state);
|
|
860
|
+
this.log.notice(`Setting state for outletEndpoint${i} from:`, state, 'to:', !state);
|
|
861
|
+
}, 10000);
|
|
862
|
+
}
|
|
863
|
+
*/
|
|
529
864
|
}
|
|
530
865
|
}
|
|
866
|
+
/*
|
|
867
|
+
/*
|
|
868
|
+
matterbridgeDevice.behaviors.require(MatterbridgeColorControlServer.with(ColorControl.Feature.HueSaturation, ColorControl.Feature.Xy, ColorControl.Feature.ColorTemperature), {
|
|
869
|
+
colorCapabilities: { xy: true, hueSaturation: true, colorLoop: false, enhancedHue: false, colorTemperature: true },
|
|
870
|
+
colorMode: ColorControl.ColorMode.ColorTemperatureMireds,
|
|
871
|
+
enhancedColorMode: ColorControl.EnhancedColorMode.ColorTemperatureMireds,
|
|
872
|
+
options: { executeIfOff: false },
|
|
873
|
+
numberOfPrimaries: null,
|
|
874
|
+
currentX: 24939,
|
|
875
|
+
currentY: 24701,
|
|
876
|
+
currentHue: 0,
|
|
877
|
+
currentSaturation: 0,
|
|
878
|
+
colorTemperatureMireds: 450,
|
|
879
|
+
colorTempPhysicalMinMireds: 150,
|
|
880
|
+
colorTempPhysicalMaxMireds: 450,
|
|
881
|
+
coupleColorTempToLevelMinMireds: 150,
|
|
882
|
+
startUpColorTemperatureMireds: null,
|
|
883
|
+
});
|
|
884
|
+
matterbridgeDevice.behaviors.require(MatterbridgeColorControlServer.with(ColorControl.Feature.ColorTemperature), {
|
|
885
|
+
colorCapabilities: { xy: false, hueSaturation: false, colorLoop: false, enhancedHue: false, colorTemperature: true },
|
|
886
|
+
colorMode: ColorControl.ColorMode.ColorTemperatureMireds,
|
|
887
|
+
enhancedColorMode: ColorControl.EnhancedColorMode.ColorTemperatureMireds,
|
|
888
|
+
options: { executeIfOff: false },
|
|
889
|
+
numberOfPrimaries: null,
|
|
890
|
+
colorTemperatureMireds: 450,
|
|
891
|
+
colorTempPhysicalMinMireds: 150,
|
|
892
|
+
colorTempPhysicalMaxMireds: 450,
|
|
893
|
+
coupleColorTempToLevelMinMireds: 150,
|
|
894
|
+
startUpColorTemperatureMireds: null,
|
|
895
|
+
});
|
|
896
|
+
*/
|
|
897
|
+
/*
|
|
898
|
+
matterbridgeDevice.behaviors.require(MatterbridgeColorControlServer.with(ColorControl.Feature.HueSaturation, ColorControl.Feature.Xy), {
|
|
899
|
+
colorCapabilities: { xy: true, hueSaturation: true, colorLoop: false, enhancedHue: false, colorTemperature: false },
|
|
900
|
+
colorMode: ColorControl.ColorMode.CurrentHueAndCurrentSaturation,
|
|
901
|
+
enhancedColorMode: ColorControl.EnhancedColorMode.CurrentHueAndCurrentSaturation,
|
|
902
|
+
options: { executeIfOff: false },
|
|
903
|
+
numberOfPrimaries: null,
|
|
904
|
+
currentX: 24939,
|
|
905
|
+
currentY: 24701,
|
|
906
|
+
currentHue: 0,
|
|
907
|
+
currentSaturation: 0,
|
|
908
|
+
});
|
|
909
|
+
// node dist/matterbridgeEdge.js MatterbridgeEdge -debug -ssl -frontend 443
|
|
910
|
+
if (process.argv.includes('MatterbridgeEdge')) {
|
|
911
|
+
const matterbridge = await MatterbridgeEdge.loadInstance(true);
|
|
912
|
+
|
|
913
|
+
process.on('SIGINT', async function () {
|
|
914
|
+
// eslint-disable-next-line no-console
|
|
915
|
+
console.log('Caught interrupt signal');
|
|
916
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
917
|
+
if (matterbridge) await (matterbridge as any).cleanup('shutting down...', false);
|
|
918
|
+
// if (matterbridge && matterbridge.matterServerNode && matterbridge.matterServerNodeContext) await matterbridge.stopServerNode(matterbridge.matterServerNode, matterbridge.matterServerNodeContext);
|
|
919
|
+
const exit = setTimeout(() => {
|
|
920
|
+
// eslint-disable-next-line no-console
|
|
921
|
+
console.log('Exiting after caught interrupt signal');
|
|
922
|
+
process.exit();
|
|
923
|
+
}, 10000);
|
|
924
|
+
exit.unref();
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
*/
|
|
928
|
+
/*
|
|
929
|
+
async startBridgeNode(): Promise<void> {
|
|
930
|
+
this.log.notice(`Creating lightEndpoint1`);
|
|
931
|
+
const lightEndpoint1 = new Endpoint(OnOffLightDevice.with(BridgedDeviceBasicInformationServer), {
|
|
932
|
+
id: 'OnOffLight',
|
|
933
|
+
bridgedDeviceBasicInformation: {
|
|
934
|
+
vendorId: VendorId(await storageContext.get<number>('vendorId')),
|
|
935
|
+
vendorName: await storageContext.get<string>('vendorName'),
|
|
936
|
+
|
|
937
|
+
productName: 'Light',
|
|
938
|
+
productLabel: 'Light',
|
|
939
|
+
nodeLabel: 'Light',
|
|
940
|
+
|
|
941
|
+
serialNumber: 'SN 0x123456789',
|
|
942
|
+
uniqueId: '0x123456789',
|
|
943
|
+
reachable: true,
|
|
944
|
+
},
|
|
945
|
+
});
|
|
946
|
+
this.log.notice(`Adding lightEndpoint1 to ${await storageContext.get<string>('storeId')} aggregator`);
|
|
947
|
+
await this.matterAggregatorNode.add(lightEndpoint1);
|
|
948
|
+
// logEndpoint(EndpointServer.forEndpoint(lightEndpoint1));
|
|
949
|
+
|
|
950
|
+
this.log.notice(`Creating switchEnpoint2`);
|
|
951
|
+
const switchEnpoint2 = new Endpoint(GenericSwitchDevice.with(BridgedDeviceBasicInformationServer, SwitchServer.with('MomentarySwitch', 'MomentarySwitchLongPress', 'MomentarySwitchMultiPress', 'MomentarySwitchRelease')), {
|
|
952
|
+
id: 'GenericSwitch',
|
|
953
|
+
bridgedDeviceBasicInformation: {
|
|
954
|
+
vendorId: VendorId(await storageContext.get<number>('vendorId')),
|
|
955
|
+
vendorName: await storageContext.get<string>('vendorName'),
|
|
956
|
+
|
|
957
|
+
productName: 'GenericSwitch',
|
|
958
|
+
productLabel: 'GenericSwitch',
|
|
959
|
+
nodeLabel: 'GenericSwitch',
|
|
960
|
+
|
|
961
|
+
serialNumber: 'SN 0x123456739',
|
|
962
|
+
uniqueId: '0x123456739',
|
|
963
|
+
reachable: true,
|
|
964
|
+
},
|
|
965
|
+
switch: {
|
|
966
|
+
numberOfPositions: 2,
|
|
967
|
+
currentPosition: 0,
|
|
968
|
+
multiPressMax: 2,
|
|
969
|
+
},
|
|
970
|
+
});
|
|
971
|
+
this.log.notice(`Adding switchEnpoint2 to ${await storageContext.get<string>('storeId')} aggregator`);
|
|
972
|
+
await this.matterAggregatorNode.add(switchEnpoint2);
|
|
973
|
+
// logEndpoint(EndpointServer.forEndpoint(switchEnpoint2));
|
|
974
|
+
|
|
975
|
+
// switchEnpoint2.events.identify.startIdentifying.on(() => this.log.notice('GenericSwitch.identify logic, ideally blink a light every 0.5s ...'));
|
|
976
|
+
// switchEnpoint2.events.switch.currentPosition$Changed.on(() => this.log.notice('GenericSwitch.currentPosition changed ...'));
|
|
977
|
+
// switchEnpoint2.act((agent) => agent.switch.events.initialPress.emit({ newPosition: 1 }, agent.context));
|
|
978
|
+
// switchEnpoint2.events.switch.emit('initialPress', { newPosition: 1 }, switchEnpoint2.events.switch.context);
|
|
979
|
+
*/
|
|
980
|
+
/*
|
|
981
|
+
log.notice(`Creating matterbridge device ClimateSensor`);
|
|
982
|
+
const matterbridgeDevice3 = new MatterbridgeDeviceV8(DeviceTypes.TEMPERATURE_SENSOR, { uniqueStorageKey: 'ClimateSensor' });
|
|
983
|
+
matterbridgeDevice3.addDeviceTypeWithClusterServer([DeviceTypes.TEMPERATURE_SENSOR], [TemperatureMeasurement.Cluster.id]);
|
|
984
|
+
matterbridgeDevice3.addDeviceTypeWithClusterServer([DeviceTypes.HUMIDITY_SENSOR], [RelativeHumidityMeasurement.Cluster.id]);
|
|
985
|
+
matterbridgeDevice3.addDeviceTypeWithClusterServer([DeviceTypes.PRESSURE_SENSOR], [PressureMeasurement.Cluster.id]);
|
|
986
|
+
matterbridgeDevice3.behaviors.require(IdentifyServer, {
|
|
987
|
+
identifyTime: 5,
|
|
988
|
+
});
|
|
989
|
+
matterbridgeDevice3.behaviors.require(TemperatureMeasurementServer, {
|
|
990
|
+
measuredValue: 25.0,
|
|
991
|
+
minMeasuredValue: null,
|
|
992
|
+
maxMeasuredValue: null,
|
|
993
|
+
});
|
|
994
|
+
*/
|
|
995
|
+
/*
|
|
996
|
+
log.notice(`Adding BridgedDeviceBasicInformationServer to ClimateSensor`);
|
|
997
|
+
matterbridgeDevice3.behaviors.require(BridgedDeviceBasicInformationServer, {
|
|
998
|
+
vendorId: VendorId(await storageContext.get<number>('vendorId')),
|
|
999
|
+
vendorName: await storageContext.get<string>('vendorName'),
|
|
1000
|
+
|
|
1001
|
+
productName: 'ClimateSensor',
|
|
1002
|
+
productLabel: 'ClimateSensor',
|
|
1003
|
+
nodeLabel: 'ClimateSensor',
|
|
1004
|
+
|
|
1005
|
+
serialNumber: '0x145433356739',
|
|
1006
|
+
uniqueId: '0x1254446739',
|
|
1007
|
+
reachable: true,
|
|
1008
|
+
});
|
|
1009
|
+
|
|
1010
|
+
log.notice(`Adding DescriptorServer to ClimateSensor`);
|
|
1011
|
+
matterbridgeDevice3.behaviors.require(DescriptorServer, {
|
|
1012
|
+
deviceTypeList: [
|
|
1013
|
+
{ deviceType: 0x0302, revision: 2 },
|
|
1014
|
+
{ deviceType: 0x0307, revision: 2 },
|
|
1015
|
+
{ deviceType: 0x0305, revision: 2 },
|
|
1016
|
+
],
|
|
1017
|
+
});
|
|
1018
|
+
|
|
1019
|
+
this.log.notice(`Adding ClimateSensor to ${await storageContext.get<string>('storeId')} aggregator`);
|
|
1020
|
+
await this.matterAggregator.add(matterbridgeDevice3);
|
|
1021
|
+
logEndpoint(EndpointServer.forEndpoint(matterbridgeDevice3));
|
|
1022
|
+
*/
|
|
1023
|
+
/*
|
|
1024
|
+
await lightEndpoint1.set({
|
|
1025
|
+
onOff: {
|
|
1026
|
+
onOff: true,
|
|
1027
|
+
},
|
|
1028
|
+
});
|
|
1029
|
+
await switchEnpoint2.set({
|
|
1030
|
+
switch: {
|
|
1031
|
+
currentPosition: 1,
|
|
1032
|
+
},
|
|
1033
|
+
});
|
|
1034
|
+
switchEnpoint2.act((agent) => agent.switch.events.initialPress.emit({ newPosition: 1 }, agent.context));
|
|
1035
|
+
*/
|
|
1036
|
+
/*
|
|
1037
|
+
await matterbridgeDevice3.set({
|
|
1038
|
+
temperatureMeasurement: {
|
|
1039
|
+
measuredValue: 20 * 100,
|
|
1040
|
+
},
|
|
1041
|
+
relativeHumidityMeasurement: {
|
|
1042
|
+
measuredValue: 50 * 100,
|
|
1043
|
+
},
|
|
1044
|
+
});
|
|
1045
|
+
*/
|
|
1046
|
+
// logEndpoint(EndpointServer.forEndpoint(this.matterServerNode));
|
|
1047
|
+
/*
|
|
1048
|
+
logEndpoint(EndpointServer.forEndpoint(this.matterServerNode));
|
|
1049
|
+
logEndpoint(EndpointServer.forEndpoint(matterbridgeDevice3));
|
|
1050
|
+
console.log('matterbridgeDevice3\n', matterbridgeDevice3);
|
|
1051
|
+
console.log('matterbridgeDevice3.events\n', matterbridgeDevice3.events);
|
|
1052
|
+
console.log('matterbridgeDevice3.events.identify\n', matterbridgeDevice3.eventsOf(IdentifyServer));
|
|
1053
|
+
console.log('matterbridgeDevice3.state\n', matterbridgeDevice3.state);
|
|
1054
|
+
console.log('matterbridgeDevice3.state.temperatureMeasurement\n', matterbridgeDevice3.stateOf(TemperatureMeasurementServer));
|
|
1055
|
+
// matterbridgeDevice3.eventsOf(IdentifyServer);
|
|
1056
|
+
// matterbridgeDevice3.events.identify.startIdentifying.on(() => log.notice('Run identify logic, ideally blink a light every 0.5s ...'));
|
|
1057
|
+
}
|
|
1058
|
+
*/
|
|
1059
|
+
//# sourceMappingURL=matterbridgeEdge.js.map
|