matterbridge 1.6.8-dev.2 → 1.6.8-dev.4
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 +7 -6
- package/dist/cli.js +0 -26
- package/dist/cluster/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -23
- package/dist/deviceManager.js +1 -26
- package/dist/index.js +0 -30
- package/dist/logger/export.js +0 -1
- package/dist/matter/export.js +0 -1
- package/dist/matterbridge.js +165 -660
- package/dist/matterbridgeAccessoryPlatform.js +0 -33
- package/dist/matterbridgeBehaviors.js +1 -29
- package/dist/matterbridgeDevice.js +9 -995
- package/dist/matterbridgeDeviceTypes.js +11 -82
- package/dist/matterbridgeDynamicPlatform.js +0 -33
- package/dist/matterbridgeEdge.js +2 -531
- package/dist/matterbridgeEndpoint.js +11 -1120
- package/dist/matterbridgePlatform.js +3 -91
- package/dist/matterbridgeTypes.js +0 -24
- package/dist/matterbridgeWebsocket.js +0 -45
- package/dist/pluginManager.js +3 -238
- package/dist/storage/export.js +0 -1
- package/dist/utils/colorUtils.js +2 -205
- package/dist/utils/export.js +0 -1
- package/dist/utils/utils.js +7 -252
- package/npm-shrinkwrap.json +6 -6
- package/package.json +1 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cluster/export.d.ts.map +0 -1
- package/dist/cluster/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -46
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger/export.d.ts.map +0 -1
- package/dist/logger/export.js.map +0 -1
- package/dist/matter/export.d.ts.map +0 -1
- package/dist/matter/export.js.map +0 -1
- package/dist/matterbridge.d.ts +0 -466
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -116
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDevice.d.ts +0 -1142
- package/dist/matterbridgeDevice.d.ts.map +0 -1
- package/dist/matterbridgeDevice.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -109
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEdge.d.ts +0 -90
- package/dist/matterbridgeEdge.d.ts.map +0 -1
- package/dist/matterbridgeEdge.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1134
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -114
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/matterbridgeWebsocket.d.ts.map +0 -1
- package/dist/matterbridgeWebsocket.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -238
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/utils.d.ts +0 -221
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/utils.js.map +0 -1
package/dist/matterbridgeEdge.js
CHANGED
|
@@ -1,39 +1,11 @@
|
|
|
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
|
|
26
1
|
import path from 'path';
|
|
27
2
|
import os from 'os';
|
|
28
3
|
import { randomBytes } from 'crypto';
|
|
29
|
-
// NodeStorage and AnsiLogger modules
|
|
30
4
|
import { rs, GREEN, debugStringify, er, zb, nf, db } from 'node-ansi-logger';
|
|
31
|
-
// Matterbridge
|
|
32
5
|
import { Matterbridge } from './matterbridge.js';
|
|
33
6
|
import { bridge } from './matterbridgeDeviceTypes.js';
|
|
34
7
|
import { dev, plg } from './matterbridgeTypes.js';
|
|
35
8
|
import { copyDirectory, getParameter, hasParameter } from './utils/utils.js';
|
|
36
|
-
// @matter
|
|
37
9
|
import { DeviceTypeId, LogLevel as MatterLogLevel, LogFormat as MatterLogFormat, VendorId, EndpointServer } from '@matter/main';
|
|
38
10
|
import { ServerNode, Endpoint as EndpointNode, Environment, StorageService } from '@matter/main';
|
|
39
11
|
import { BasicInformationCluster } from '@matter/main/clusters';
|
|
@@ -42,18 +14,11 @@ import { GenericSwitchDevice } from '@matter/main/devices';
|
|
|
42
14
|
import { AggregatorEndpoint } from '@matter/main/endpoints';
|
|
43
15
|
import { BridgedDeviceBasicInformationServer, SwitchServer } from '@matter/main/behaviors';
|
|
44
16
|
import { Device, logEndpoint } from '@project-chip/matter.js/device';
|
|
45
|
-
/**
|
|
46
|
-
* Represents the MatterbridgeEdge application.
|
|
47
|
-
*/
|
|
48
17
|
export class MatterbridgeEdge extends Matterbridge {
|
|
49
18
|
static instance;
|
|
50
|
-
// Matter environment
|
|
51
19
|
environment = Environment.default;
|
|
52
|
-
// Matter storage
|
|
53
20
|
matterStorageService;
|
|
54
|
-
// Mapping of CommissioningServer to ServerNode
|
|
55
21
|
csToServerNode = new Map();
|
|
56
|
-
// Mapping of Aggregator to AggregatorEndpoint
|
|
57
22
|
agToAggregatorEndpoint = new Map();
|
|
58
23
|
constructor() {
|
|
59
24
|
super();
|
|
@@ -71,30 +36,24 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
71
36
|
async initialize() {
|
|
72
37
|
if (hasParameter('debug'))
|
|
73
38
|
console.log('Initializing MatterbridgeEdge...');
|
|
74
|
-
// Set the matterbridge directory
|
|
75
39
|
this.homeDirectory = getParameter('homedir') ?? os.homedir();
|
|
76
40
|
this.matterbridgeDirectory = path.join(this.homeDirectory, '.matterbridge');
|
|
77
41
|
this.matterStorageName = 'matterstorage' + (getParameter('profile') ? '.' + getParameter('profile') : '');
|
|
78
|
-
// Setup matter environment
|
|
79
42
|
this.environment.vars.set('log.level', MatterLogLevel.INFO);
|
|
80
43
|
this.environment.vars.set('log.format', MatterLogFormat.ANSI);
|
|
81
44
|
this.environment.vars.set('path.root', path.join(this.matterbridgeDirectory, this.matterStorageName));
|
|
82
45
|
this.environment.vars.set('runtime.signals', false);
|
|
83
46
|
this.environment.vars.set('runtime.exitcode', false);
|
|
84
|
-
// Setup Matter commissioning server
|
|
85
47
|
this.port = 5540;
|
|
86
48
|
this.passcode = PaseClient.generateRandomPasscode();
|
|
87
49
|
this.discriminator = PaseClient.generateRandomDiscriminator();
|
|
88
50
|
if (hasParameter('debug'))
|
|
89
51
|
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
|
|
91
52
|
await super.initialize();
|
|
92
|
-
// Setup Matter mdnsInterface
|
|
93
53
|
if (this.mdnsInterface)
|
|
94
54
|
this.environment.vars.set('mdns.networkInterface', this.mdnsInterface);
|
|
95
55
|
}
|
|
96
56
|
async startMatterStorage(storageType, storageName) {
|
|
97
|
-
// Setup Matter storage
|
|
98
57
|
this.log.info(`Starting matter node storage...`);
|
|
99
58
|
this.matterStorageService = this.environment.get(StorageService);
|
|
100
59
|
this.log.info(`Matter node storage service created: ${this.matterStorageService.location}`);
|
|
@@ -102,7 +61,6 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
102
61
|
this.log.info('Matter node storage manager "Matterbridge" created');
|
|
103
62
|
this.matterbridgeContext = await this.createServerNodeContext('Matterbridge', 'Matterbridge', bridge.code, this.aggregatorVendorId, 'Matterbridge', this.aggregatorProductId, 'Matterbridge aggregator');
|
|
104
63
|
this.log.info('Matter node storage started');
|
|
105
|
-
// Backup matter storage since it is created/opened correctly
|
|
106
64
|
await this.backupMatterStorage(path.join(this.matterbridgeDirectory, this.matterStorageName), path.join(this.matterbridgeDirectory, this.matterStorageName + '.backup'));
|
|
107
65
|
}
|
|
108
66
|
async backupMatterStorage(storageName, backupName) {
|
|
@@ -118,24 +76,6 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
118
76
|
this.matterbridgeContext = undefined;
|
|
119
77
|
this.log.info('Matter node storage closed');
|
|
120
78
|
}
|
|
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
|
-
*/
|
|
139
79
|
async createServerNodeContext(pluginName, deviceName, deviceType, vendorId, vendorName, productId, productName, serialNumber) {
|
|
140
80
|
if (!this.matterStorageService)
|
|
141
81
|
throw new Error('No storage service initialized');
|
|
@@ -177,33 +117,21 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
177
117
|
this.log.debug(`- uniqueId: ${await storageContext.get('uniqueId')}`);
|
|
178
118
|
this.log.debug(`- softwareVersion: ${await storageContext.get('softwareVersion')} softwareVersionString: ${await storageContext.get('softwareVersionString')}`);
|
|
179
119
|
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
|
-
*/
|
|
183
120
|
const serverNode = await ServerNode.create({
|
|
184
|
-
// Required: Give the Node a unique ID which is used to store the state of this node
|
|
185
121
|
id: storeId,
|
|
186
|
-
// Provide Network relevant configuration like the port
|
|
187
|
-
// Optional when operating only one device on a host, Default port is 5540
|
|
188
122
|
network: {
|
|
189
123
|
listeningAddressIpv4: this.ipv4address,
|
|
190
124
|
listeningAddressIpv6: this.ipv6address,
|
|
191
125
|
port,
|
|
192
126
|
},
|
|
193
|
-
// Provide Commissioning relevant settings
|
|
194
|
-
// Optional for development/testing purposes
|
|
195
127
|
commissioning: {
|
|
196
128
|
passcode,
|
|
197
129
|
discriminator,
|
|
198
130
|
},
|
|
199
|
-
// Provide Node announcement settings
|
|
200
|
-
// Optional: If Ommitted some development defaults are used
|
|
201
131
|
productDescription: {
|
|
202
132
|
name: await storageContext.get('deviceName'),
|
|
203
133
|
deviceType: DeviceTypeId(await storageContext.get('deviceType')),
|
|
204
134
|
},
|
|
205
|
-
// Provide defaults for the BasicInformation cluster on the Root endpoint
|
|
206
|
-
// Optional: If Omitted some development defaults are used
|
|
207
135
|
basicInformation: {
|
|
208
136
|
vendorId: VendorId(await storageContext.get('vendorId')),
|
|
209
137
|
vendorName: await storageContext.get('vendorName'),
|
|
@@ -220,7 +148,6 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
220
148
|
},
|
|
221
149
|
});
|
|
222
150
|
const sanitizeFabrics = (fabrics) => {
|
|
223
|
-
// New type of fabric information: Record<FabricIndex, ExposedFabricInformation>
|
|
224
151
|
const sanitizedFabrics = this.sanitizeFabricInformations(Array.from(Object.values(fabrics)));
|
|
225
152
|
this.log.info(`Fabrics: ${debugStringify(sanitizedFabrics)}`);
|
|
226
153
|
if (this.bridgeMode === 'bridge') {
|
|
@@ -237,14 +164,8 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
237
164
|
}
|
|
238
165
|
}
|
|
239
166
|
};
|
|
240
|
-
/**
|
|
241
|
-
* This event is triggered when the device is initially commissioned successfully.
|
|
242
|
-
* This means: It is added to the first fabric.
|
|
243
|
-
*/
|
|
244
167
|
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. */
|
|
246
168
|
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. */
|
|
248
169
|
serverNode.lifecycle.online.on(() => {
|
|
249
170
|
this.log.notice(`Server node for ${storeId} is online`);
|
|
250
171
|
if (!serverNode.lifecycle.isCommissioned) {
|
|
@@ -279,7 +200,6 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
279
200
|
sanitizeFabrics(serverNode.state.commissioning.fabrics);
|
|
280
201
|
}
|
|
281
202
|
});
|
|
282
|
-
/** This event is triggered when the device went offline. it is not longer discoverable or connectable in the network. */
|
|
283
203
|
serverNode.lifecycle.offline.on(() => {
|
|
284
204
|
this.log.notice(`Server node for ${storeId} is offline`);
|
|
285
205
|
if (this.bridgeMode === 'bridge') {
|
|
@@ -291,10 +211,6 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
291
211
|
this.matterbridgeConnected = false;
|
|
292
212
|
}
|
|
293
213
|
});
|
|
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
|
-
*/
|
|
298
214
|
serverNode.events.commissioning.fabricsChanged.on((fabricIndex, fabricAction) => {
|
|
299
215
|
let action = '';
|
|
300
216
|
switch (fabricAction) {
|
|
@@ -327,22 +243,14 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
327
243
|
}
|
|
328
244
|
}
|
|
329
245
|
};
|
|
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
|
-
*/
|
|
334
246
|
serverNode.events.sessions.opened.on((session) => {
|
|
335
247
|
this.log.notice(`Session opened on server node for ${storeId}: ${debugStringify(session)}`);
|
|
336
248
|
sanitizeSessions(Object.values(serverNode.state.sessions.sessions));
|
|
337
249
|
});
|
|
338
|
-
/**
|
|
339
|
-
* This event is triggered when an operative session is closed by a Controller or because the Device goes offline.
|
|
340
|
-
*/
|
|
341
250
|
serverNode.events.sessions.closed.on((session) => {
|
|
342
251
|
this.log.notice(`Session closed on server node for ${storeId}: ${debugStringify(session)}`);
|
|
343
252
|
sanitizeSessions(Object.values(serverNode.state.sessions.sessions));
|
|
344
253
|
});
|
|
345
|
-
/** This event is triggered when a subscription gets added or removed on an operative session. */
|
|
346
254
|
serverNode.events.sessions.subscriptionsChanged.on((session) => {
|
|
347
255
|
this.log.notice(`Session subscriptions changed on server node for ${storeId}: ${debugStringify(session)}`);
|
|
348
256
|
sanitizeSessions(Object.values(serverNode.state.sessions.sessions));
|
|
@@ -364,17 +272,15 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
364
272
|
}
|
|
365
273
|
async createAggregatorNode(storageContext) {
|
|
366
274
|
this.log.notice(`Creating ${await storageContext.get('storeId')} aggregator `);
|
|
367
|
-
const
|
|
368
|
-
return
|
|
275
|
+
const aggregatorNode = new EndpointNode(AggregatorEndpoint, { id: `${await storageContext.get('storeId')}` });
|
|
276
|
+
return aggregatorNode;
|
|
369
277
|
}
|
|
370
278
|
async addBridgedEndpoint(pluginName, device) {
|
|
371
|
-
// Check if the plugin is registered
|
|
372
279
|
const plugin = this.plugins.get(pluginName);
|
|
373
280
|
if (!plugin) {
|
|
374
281
|
this.log.error(`Error adding bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.id}${er}) plugin ${plg}${pluginName}${er} not found`);
|
|
375
282
|
return;
|
|
376
283
|
}
|
|
377
|
-
// Register and add the device to the matterbridge aggregator node
|
|
378
284
|
if (this.bridgeMode === 'bridge') {
|
|
379
285
|
this.log.info(`Adding ${pluginName}:${device.deviceName} to Matterbridge aggregator node`);
|
|
380
286
|
const aggregatorNode = this.agToAggregatorEndpoint.get('Matterbridge')?.aggregatorNode;
|
|
@@ -410,19 +316,16 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
410
316
|
plugin.registeredDevices++;
|
|
411
317
|
if (plugin.addedDevices !== undefined)
|
|
412
318
|
plugin.addedDevices++;
|
|
413
|
-
// Add the device to the DeviceManager
|
|
414
319
|
this.devices.set(device);
|
|
415
320
|
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}`);
|
|
416
321
|
}
|
|
417
322
|
async removeBridgedEndpoint(pluginName, device) {
|
|
418
323
|
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
|
|
420
324
|
const plugin = this.plugins.get(pluginName);
|
|
421
325
|
if (!plugin) {
|
|
422
326
|
this.log.error(`Error removing bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.name}${er}) for plugin ${plg}${pluginName}${er}: plugin not found`);
|
|
423
327
|
return;
|
|
424
328
|
}
|
|
425
|
-
// Register and add the device to the matterbridge aggregator node
|
|
426
329
|
if (this.bridgeMode === 'bridge') {
|
|
427
330
|
const aggregatoreNode = this.agToAggregatorEndpoint.get('Matterbridge')?.aggregatorNode;
|
|
428
331
|
if (!aggregatoreNode) {
|
|
@@ -438,7 +341,6 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
438
341
|
}
|
|
439
342
|
else if (this.bridgeMode === 'childbridge') {
|
|
440
343
|
if (plugin.type === 'AccessoryPlatform') {
|
|
441
|
-
// Nothing to do
|
|
442
344
|
}
|
|
443
345
|
else if (plugin.type === 'DynamicPlatform') {
|
|
444
346
|
const aggregatoreNode = this.agToAggregatorEndpoint.get(pluginName)?.aggregatorNode;
|
|
@@ -453,7 +355,6 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
453
355
|
plugin.registeredDevices--;
|
|
454
356
|
if (plugin.addedDevices !== undefined)
|
|
455
357
|
plugin.addedDevices--;
|
|
456
|
-
// Close the server node
|
|
457
358
|
if (plugin.registeredDevices === 0 && plugin.addedDevices === 0) {
|
|
458
359
|
const serverNode = this.csToServerNode.get(pluginName)?.serverNode;
|
|
459
360
|
if (serverNode)
|
|
@@ -462,7 +363,6 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
462
363
|
this.log.info(`Removed server node for plugin ${plg}${pluginName}${nf}`);
|
|
463
364
|
}
|
|
464
365
|
}
|
|
465
|
-
// Remove the device from the DeviceManager
|
|
466
366
|
this.devices.remove(device);
|
|
467
367
|
}
|
|
468
368
|
async removeAllBridgedEndpoints(pluginName) {
|
|
@@ -471,9 +371,6 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
471
371
|
await this.removeBridgedEndpoint(pluginName, device);
|
|
472
372
|
}
|
|
473
373
|
}
|
|
474
|
-
/**
|
|
475
|
-
* override from Matterbridge
|
|
476
|
-
*/
|
|
477
374
|
createMatterServer(storageManager) {
|
|
478
375
|
if (hasParameter('debug'))
|
|
479
376
|
this.log.warn('createMatterServer() => mock MatterServer.addCommissioningServer()');
|
|
@@ -537,7 +434,6 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
537
434
|
const commissioningServer = {
|
|
538
435
|
getPort: () => port,
|
|
539
436
|
addDevice: async (device) => {
|
|
540
|
-
// if (hasParameter('debug')) this.log.warn('CommissioningServer.addDevice()', device.name);
|
|
541
437
|
if (device instanceof Device) {
|
|
542
438
|
if (hasParameter('debug'))
|
|
543
439
|
this.log.warn('CommissioningServer.addDevice() => Device');
|
|
@@ -552,7 +448,6 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
552
448
|
await serverNode.add(aggregatorNode);
|
|
553
449
|
if (!this.test) {
|
|
554
450
|
this.test = true;
|
|
555
|
-
// await this.testEndpoints();
|
|
556
451
|
}
|
|
557
452
|
}
|
|
558
453
|
},
|
|
@@ -609,37 +504,6 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
609
504
|
const aggregatorNode = this.agToAggregatorEndpoint.get('Matterbridge')?.aggregatorNode;
|
|
610
505
|
if (!aggregatorNode)
|
|
611
506
|
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
|
-
*/
|
|
643
507
|
this.log.notice(`Creating switchEnpoint1`);
|
|
644
508
|
const switchEnpoint1 = new EndpointNode(GenericSwitchDevice.with(BridgedDeviceBasicInformationServer, SwitchServer.with('MomentarySwitch', 'MomentarySwitchLongPress', 'MomentarySwitchMultiPress', 'MomentarySwitchRelease')), {
|
|
645
509
|
id: 'GenericSwitch',
|
|
@@ -662,398 +526,5 @@ export class MatterbridgeEdge extends Matterbridge {
|
|
|
662
526
|
this.log.notice(`Adding switchEnpoint1 to ${await this.matterbridgeContext.get('storeId')} aggregator`);
|
|
663
527
|
await aggregatorNode.add(switchEnpoint1);
|
|
664
528
|
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
|
-
*/
|
|
864
529
|
}
|
|
865
530
|
}
|
|
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
|