@matterbridge/core 3.11.2-dev-20261104-014189e → 3.11.2-dev-20261105-a15bb91
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/dist/backendWsServer.js +12 -0
- package/dist/behaviors/serviceAreaServer.js +2 -0
- package/dist/behaviors/webRtcTransportRequestorServer.js +9 -0
- package/dist/frontend.d.ts +1 -2
- package/dist/frontend.js +23 -57
- package/dist/matterbridge.js +3 -3
- package/dist/matterbridgePlatform.d.ts +5 -23
- package/dist/matterbridgePlatform.js +96 -4
- package/package.json +5 -5
package/dist/backendWsServer.js
CHANGED
|
@@ -255,6 +255,18 @@ export class BackendWsServer {
|
|
|
255
255
|
sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true, response: matter });
|
|
256
256
|
this.wssSendRefreshRequired('matter', { matter });
|
|
257
257
|
}
|
|
258
|
+
else if (data.method === '/api/unregister-device') {
|
|
259
|
+
this.wssSendSnackbarMessage('Resetting the device...');
|
|
260
|
+
const { pluginName, serialNumber, uniqueId } = data.params;
|
|
261
|
+
this.server.request({ type: 'platform_unregister_device', src: 'frontend', dst: 'platform', params: { pluginName, serialNumber, uniqueId } });
|
|
262
|
+
sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true });
|
|
263
|
+
}
|
|
264
|
+
else if (data.method === '/api/rename-device') {
|
|
265
|
+
this.wssSendSnackbarMessage('Renaming the device...');
|
|
266
|
+
const { pluginName, serialNumber, uniqueId, label } = data.params;
|
|
267
|
+
this.server.request({ type: 'platform_rename_device', src: 'frontend', dst: 'platform', params: { pluginName, serialNumber, uniqueId, label } });
|
|
268
|
+
sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true });
|
|
269
|
+
}
|
|
258
270
|
}
|
|
259
271
|
catch (error) {
|
|
260
272
|
inspectError(this.log, `Error parsing message from websocket client`, error);
|
|
@@ -37,6 +37,8 @@ export class MatterbridgeServiceAreaServer extends ServiceAreaServer.with(Servic
|
|
|
37
37
|
? { areaId: area.areaId, status: ServiceArea.OperationalStatus.Skipped, totalOperationalTime: area.totalOperationalTime, estimatedTime: area.estimatedTime }
|
|
38
38
|
: area);
|
|
39
39
|
}
|
|
40
|
+
if (response.status === ServiceArea.SkipAreaStatus.Success)
|
|
41
|
+
this.endpoint.emitCommand(ServiceArea, 'skipArea', request, this.context);
|
|
40
42
|
return response;
|
|
41
43
|
}
|
|
42
44
|
}
|
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
import { WebRtcTransportRequestorServer } from '@matter/node/behaviors/web-rtc-transport-requestor';
|
|
2
2
|
import { WebRtcTransportRequestor } from '@matter/types/clusters/web-rtc-transport-requestor';
|
|
3
3
|
import { protectPrototype } from '../protectPrototypes.js';
|
|
4
|
+
import { MatterbridgeServer } from './matterbridgeServer.js';
|
|
4
5
|
export class MatterbridgeWebRtcTransportRequestorServer extends WebRtcTransportRequestorServer {
|
|
5
6
|
async offer(request) {
|
|
7
|
+
const device = this.endpoint.stateOf(MatterbridgeServer);
|
|
8
|
+
device.log.info(`MatterbridgeWebRtcTransportRequestorServer: received an SDP offer for session ${request.webRtcSessionId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
6
9
|
await super.offer(request);
|
|
7
10
|
this.endpoint.emitCommand(WebRtcTransportRequestor, 'offer', request, this.context);
|
|
8
11
|
}
|
|
9
12
|
async answer(request) {
|
|
13
|
+
const device = this.endpoint.stateOf(MatterbridgeServer);
|
|
14
|
+
device.log.info(`MatterbridgeWebRtcTransportRequestorServer: received an SDP answer for session ${request.webRtcSessionId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
10
15
|
await super.answer(request);
|
|
11
16
|
this.endpoint.emitCommand(WebRtcTransportRequestor, 'answer', request, this.context);
|
|
12
17
|
}
|
|
13
18
|
async iceCandidates(request) {
|
|
19
|
+
const device = this.endpoint.stateOf(MatterbridgeServer);
|
|
20
|
+
device.log.info(`MatterbridgeWebRtcTransportRequestorServer: received ${request.iceCandidates.length} ICE candidate(s) for session ${request.webRtcSessionId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
14
21
|
await super.iceCandidates(request);
|
|
15
22
|
this.endpoint.emitCommand(WebRtcTransportRequestor, 'iceCandidates', request, this.context);
|
|
16
23
|
}
|
|
17
24
|
async end(request) {
|
|
25
|
+
const device = this.endpoint.stateOf(MatterbridgeServer);
|
|
26
|
+
device.log.info(`MatterbridgeWebRtcTransportRequestorServer: ending session ${request.webRtcSessionId} with reason ${request.reason} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
18
27
|
await super.end(request);
|
|
19
28
|
this.endpoint.emitCommand(WebRtcTransportRequestor, 'end', request, this.context);
|
|
20
29
|
}
|
package/dist/frontend.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import EventEmitter from 'node:events';
|
|
2
|
-
import type { ApiClusters, ApiDevice, ApiMatter, ApiPlugin,
|
|
2
|
+
import type { ApiClusters, ApiDevice, ApiMatter, ApiPlugin, BridgeStatus, PluginStatusUpdate, RefreshRequiredChanged, WsMessageBroadcast } from '@matterbridge/types';
|
|
3
3
|
import { LogLevel } from 'node-ansi-logger';
|
|
4
4
|
import type { Matterbridge } from './matterbridge.js';
|
|
5
5
|
interface FrontendEvents {
|
|
@@ -34,7 +34,6 @@ export declare class Frontend extends EventEmitter<FrontendEvents> {
|
|
|
34
34
|
private validateReq;
|
|
35
35
|
start(port?: number): Promise<void>;
|
|
36
36
|
stop(): Promise<void>;
|
|
37
|
-
getApiSettings(): ApiSettings;
|
|
38
37
|
getApiPlugins(): ApiPlugin[];
|
|
39
38
|
getApiDevices(pluginName?: string, extended?: boolean): ApiDevice[];
|
|
40
39
|
getApiCluster(pluginName: string, endpointNumber: number, serialNumber: string, uniqueId: string): ApiClusters | undefined;
|
package/dist/frontend.js
CHANGED
|
@@ -7,11 +7,11 @@ import { CommissioningOptions } from '@matter/types/commissioning';
|
|
|
7
7
|
import { FabricIndex } from '@matter/types/datatype';
|
|
8
8
|
import { BroadcastServer } from '@matterbridge/thread/server';
|
|
9
9
|
import { MATTER_LOGGER_FILE, MATTER_STORAGE_DIR, MATTERBRIDGE_DIAGNOSTIC_FILE, MATTERBRIDGE_HISTORY_FILE, MATTERBRIDGE_LOGGER_FILE, NODE_STORAGE_DIR, plg, } from '@matterbridge/types';
|
|
10
|
-
import {
|
|
10
|
+
import { isBun } from '@matterbridge/utils/bun';
|
|
11
11
|
import { getParameter, hasAnyParameter, hasParameter } from '@matterbridge/utils/cli';
|
|
12
12
|
import { writeDiagnostic } from '@matterbridge/utils/diagnostic';
|
|
13
13
|
import { getErrorMessage, inspectError, logError } from '@matterbridge/utils/error';
|
|
14
|
-
import { formatBytes
|
|
14
|
+
import { formatBytes } from '@matterbridge/utils/format';
|
|
15
15
|
import { logModuleLoaded } from '@matterbridge/utils/loader';
|
|
16
16
|
import { isValidArray, isValidBoolean, isValidNumber, isValidObject, isValidString } from '@matterbridge/utils/validate';
|
|
17
17
|
import { fireAndForget, withTimeout } from '@matterbridge/utils/wait';
|
|
@@ -517,11 +517,17 @@ export class Frontend extends EventEmitter {
|
|
|
517
517
|
};
|
|
518
518
|
res.status(200).json(memoryReport);
|
|
519
519
|
});
|
|
520
|
-
this.expressApp.get('/api/settings', (req, res) => {
|
|
520
|
+
this.expressApp.get('/api/settings', async (req, res) => {
|
|
521
521
|
this.log.debug('The frontend sent /api/settings');
|
|
522
522
|
if (!this.validateReq(req, res))
|
|
523
523
|
return;
|
|
524
|
-
|
|
524
|
+
try {
|
|
525
|
+
res.json((await this.server.fetch({ type: 'matterbridge_apisettings', src: this.server.name, dst: 'matterbridge', params: {} }, this.serverFetchTimeout)).result.data);
|
|
526
|
+
}
|
|
527
|
+
catch (error) {
|
|
528
|
+
logError(this.log, 'Error in /api/settings fetching the settings from matterbridge', error);
|
|
529
|
+
res.status(500).send('Error fetching the settings.');
|
|
530
|
+
}
|
|
525
531
|
});
|
|
526
532
|
this.expressApp.get('/api/plugins', (req, res) => {
|
|
527
533
|
this.log.debug('The frontend sent /api/plugins');
|
|
@@ -918,58 +924,6 @@ export class Frontend extends EventEmitter {
|
|
|
918
924
|
}
|
|
919
925
|
this.log.debug('Frontend stopped successfully');
|
|
920
926
|
}
|
|
921
|
-
getApiSettings() {
|
|
922
|
-
this.matterbridge.systemInformation.totalMemory = formatBytes(os.totalmem());
|
|
923
|
-
this.matterbridge.systemInformation.constrainedMemory = formatBytes(constrainedMemory());
|
|
924
|
-
this.matterbridge.systemInformation.freeMemory = formatBytes(os.freemem());
|
|
925
|
-
this.matterbridge.systemInformation.systemUptime = formatUptime(os.uptime());
|
|
926
|
-
this.matterbridge.systemInformation.processUptime = formatUptime(Math.floor(process.uptime()));
|
|
927
|
-
this.matterbridge.systemInformation.cpuUsage = formatPercent(0);
|
|
928
|
-
this.matterbridge.systemInformation.processCpuUsage = formatPercent(0);
|
|
929
|
-
this.matterbridge.systemInformation.rss = formatBytes(memoryFootprint());
|
|
930
|
-
this.matterbridge.systemInformation.heapTotal = formatBytes(process.memoryUsage().heapTotal);
|
|
931
|
-
this.matterbridge.systemInformation.heapUsed = formatBytes(process.memoryUsage().heapUsed);
|
|
932
|
-
const info = {
|
|
933
|
-
homeDirectory: this.matterbridge.homeDirectory,
|
|
934
|
-
rootDirectory: this.matterbridge.rootDirectory,
|
|
935
|
-
matterbridgeDirectory: this.matterbridge.matterbridgeDirectory,
|
|
936
|
-
matterbridgePluginDirectory: this.matterbridge.matterbridgePluginDirectory,
|
|
937
|
-
matterbridgeCertDirectory: this.matterbridge.matterbridgeCertDirectory,
|
|
938
|
-
globalModulesDirectory: this.matterbridge.globalModulesDirectory,
|
|
939
|
-
matterbridgeVersion: this.matterbridge.matterbridgeVersion,
|
|
940
|
-
matterbridgeLatestVersion: this.matterbridge.matterbridgeLatestVersion,
|
|
941
|
-
matterbridgeDevVersion: this.matterbridge.matterbridgeDevVersion,
|
|
942
|
-
frontendVersion: this.matterbridge.frontendVersion,
|
|
943
|
-
dockerDev: this.matterbridge.dockerDev,
|
|
944
|
-
dockerVersion: this.matterbridge.dockerVersion,
|
|
945
|
-
dockerLatestVersion: this.matterbridge.dockerLatestVersion,
|
|
946
|
-
dockerDevVersion: this.matterbridge.dockerDevVersion,
|
|
947
|
-
bridgeMode: this.matterbridge.bridgeMode,
|
|
948
|
-
restartMode: this.matterbridge.restartMode,
|
|
949
|
-
virtualMode: this.matterbridge.virtualMode,
|
|
950
|
-
bridgeStatus: this.matterbridge.bridgeStatus,
|
|
951
|
-
profile: this.matterbridge.profile,
|
|
952
|
-
loggerLevel: this.matterbridge.logLevel,
|
|
953
|
-
fileLogger: this.matterbridge.fileLogger,
|
|
954
|
-
matterLoggerLevel: this.matterbridge.matterLogLevel,
|
|
955
|
-
matterFileLogger: this.matterbridge.matterFileLogger,
|
|
956
|
-
matterMdnsInterface: this.matterbridge.mdnsInterface,
|
|
957
|
-
matterIpv4Address: this.matterbridge.ipv4Address,
|
|
958
|
-
matterIpv6Address: this.matterbridge.ipv6Address,
|
|
959
|
-
matterPort: this.matterbridge.initialPort || 5540,
|
|
960
|
-
matterDiscriminator: this.matterbridge.initialDiscriminator,
|
|
961
|
-
matterPasscode: this.matterbridge.initialPasscode,
|
|
962
|
-
readOnly: this.matterbridge.readOnly,
|
|
963
|
-
restartRequired: this.matterbridge.restartRequired,
|
|
964
|
-
fixedRestartRequired: this.matterbridge.fixedRestartRequired,
|
|
965
|
-
updateRequired: this.matterbridge.updateRequired,
|
|
966
|
-
startupAt: this.matterbridge.startupAt,
|
|
967
|
-
shutdownAt: this.matterbridge.shutdownAt,
|
|
968
|
-
runningTimes: this.matterbridge.runningTimes,
|
|
969
|
-
runningDays: this.matterbridge.runningDays,
|
|
970
|
-
};
|
|
971
|
-
return { systemInformation: this.matterbridge.systemInformation, matterbridgeInformation: info };
|
|
972
|
-
}
|
|
973
927
|
getApiPlugins() {
|
|
974
928
|
if (this.matterbridge.hasCleanupStarted)
|
|
975
929
|
return [];
|
|
@@ -1376,6 +1330,18 @@ export class Frontend extends EventEmitter {
|
|
|
1376
1330
|
await this.matterbridge.shutdownProcessAndFactoryReset();
|
|
1377
1331
|
sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true });
|
|
1378
1332
|
}
|
|
1333
|
+
else if (data.method === '/api/unregister-device') {
|
|
1334
|
+
this.wssSendSnackbarMessage('Resetting the device...');
|
|
1335
|
+
const { pluginName, serialNumber, uniqueId } = data.params;
|
|
1336
|
+
this.server.request({ type: 'platform_unregister_device', src: this.server.name, dst: 'platform', params: { pluginName, serialNumber, uniqueId } });
|
|
1337
|
+
sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true });
|
|
1338
|
+
}
|
|
1339
|
+
else if (data.method === '/api/rename-device') {
|
|
1340
|
+
this.wssSendSnackbarMessage('Renaming the device...');
|
|
1341
|
+
const { pluginName, serialNumber, uniqueId, label } = data.params;
|
|
1342
|
+
this.server.request({ type: 'platform_rename_device', src: this.server.name, dst: 'platform', params: { pluginName, serialNumber, uniqueId, label } });
|
|
1343
|
+
sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true });
|
|
1344
|
+
}
|
|
1379
1345
|
else if (data.method === '/api/viewhistorypage') {
|
|
1380
1346
|
generateHistoryPage({ outputPath: path.join(this.matterbridge.matterbridgeDirectory, MATTERBRIDGE_HISTORY_FILE), pageTitle: `Matterbridge Cpu & Memory History` });
|
|
1381
1347
|
sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true });
|
|
@@ -1436,7 +1402,7 @@ export class Frontend extends EventEmitter {
|
|
|
1436
1402
|
}
|
|
1437
1403
|
else if (data.method === '/api/settings') {
|
|
1438
1404
|
const start = performance.now();
|
|
1439
|
-
const settings = this.
|
|
1405
|
+
const settings = (await this.server.fetch({ type: 'matterbridge_apisettings', src: this.server.name, dst: 'matterbridge', params: {} }, this.serverFetchTimeout)).result.data;
|
|
1440
1406
|
if (this.diagnostic)
|
|
1441
1407
|
writeDiagnostic(`Frontend:${data.sender}`, `getApiSettings() took ${(performance.now() - start).toFixed(2)} ms`);
|
|
1442
1408
|
sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true, response: settings });
|
package/dist/matterbridge.js
CHANGED
|
@@ -297,9 +297,9 @@ export class Matterbridge extends EventEmitter {
|
|
|
297
297
|
matterMdnsInterface: this.mdnsInterface,
|
|
298
298
|
matterIpv4Address: this.ipv4Address,
|
|
299
299
|
matterIpv6Address: this.ipv6Address,
|
|
300
|
-
matterPort: this.
|
|
301
|
-
matterDiscriminator: this.
|
|
302
|
-
matterPasscode: this.
|
|
300
|
+
matterPort: this.initialPort ?? 5540,
|
|
301
|
+
matterDiscriminator: this.initialDiscriminator,
|
|
302
|
+
matterPasscode: this.initialPasscode,
|
|
303
303
|
startupAt: this.startupAt,
|
|
304
304
|
shutdownAt: this.shutdownAt,
|
|
305
305
|
runningTimes: this.runningTimes,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { EndpointNumber } from '@matter/types/datatype';
|
|
2
|
-
import type { ApiSelectDevice, ApiSelectEntity, PlatformConfig, PlatformMatterbridge, PlatformSchema } from '@matterbridge/types';
|
|
2
|
+
import type { ApiSelectDevice, ApiSelectEntity, PlatformConfig, PlatformMatterbridge, PlatformSchema, PlatformSelectDevice, PlatformSelectEntity } from '@matterbridge/types';
|
|
3
3
|
import { type AnsiLogger, type LogLevel } from 'node-ansi-logger';
|
|
4
4
|
import { type NodeStorage } from 'node-persist-manager';
|
|
5
5
|
import { type MatterbridgeEndpoint } from './matterbridgeEndpoint.js';
|
|
6
|
-
export type { BasePlatformConfig, PlatformConfig, PlatformConfigValue, PlatformMatterbridge, PlatformSchema, PlatformSchemaValue } from '@matterbridge/types';
|
|
6
|
+
export type { BasePlatformConfig, PlatformConfig, PlatformConfigValue, PlatformMatterbridge, PlatformNodeLabel, PlatformSchema, PlatformSchemaValue, PlatformSelectDevice, PlatformSelectEntity, } from '@matterbridge/types';
|
|
7
7
|
export declare function isMatterbridgePlatform(value: unknown): value is MatterbridgePlatform;
|
|
8
8
|
export declare function assertMatterbridgePlatform(value: unknown, context?: string): asserts value is MatterbridgePlatform;
|
|
9
9
|
export declare class MatterbridgePlatform {
|
|
@@ -54,30 +54,12 @@ export declare class MatterbridgePlatform {
|
|
|
54
54
|
clearSelect(): Promise<void>;
|
|
55
55
|
clearDeviceSelect(serial: string): Promise<void>;
|
|
56
56
|
clearEntitySelect(name: string): Promise<void>;
|
|
57
|
-
setSelectDevice(serial: string, name: string, configUrl?: string, icon?: string, entities?:
|
|
58
|
-
|
|
59
|
-
description: string;
|
|
60
|
-
icon?: string;
|
|
61
|
-
}[]): void;
|
|
62
|
-
getSelectDevice(serial: string): {
|
|
63
|
-
serial: string;
|
|
64
|
-
name: string;
|
|
65
|
-
configUrl?: string;
|
|
66
|
-
icon?: string;
|
|
67
|
-
entities?: {
|
|
68
|
-
name: string;
|
|
69
|
-
description: string;
|
|
70
|
-
icon?: string;
|
|
71
|
-
}[];
|
|
72
|
-
} | undefined;
|
|
57
|
+
setSelectDevice(serial: string, name: string, configUrl?: string, icon?: string, entities?: PlatformSelectEntity[]): void;
|
|
58
|
+
getSelectDevice(serial: string): PlatformSelectDevice | undefined;
|
|
73
59
|
setSelectDeviceEntity(serial: string, entityName: string, entityDescription: string, entityIcon?: string): void;
|
|
74
60
|
getSelectDevices(): ApiSelectDevice[];
|
|
75
61
|
setSelectEntity(name: string, description: string, icon?: string): void;
|
|
76
|
-
getSelectEntity(name: string):
|
|
77
|
-
name: string;
|
|
78
|
-
description: string;
|
|
79
|
-
icon?: string | undefined;
|
|
80
|
-
} | undefined;
|
|
62
|
+
getSelectEntity(name: string): PlatformSelectEntity | undefined;
|
|
81
63
|
getSelectEntities(): ApiSelectEntity[];
|
|
82
64
|
verifyMatterbridgeVersion(requiredVersion: string, destroy?: boolean): boolean;
|
|
83
65
|
validateDevice(device: string | string[], log?: boolean): boolean;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { BasicInformation } from '@matter/types/clusters/basic-information';
|
|
2
3
|
import { BridgedDeviceBasicInformation } from '@matter/types/clusters/bridged-device-basic-information';
|
|
3
4
|
import { Descriptor } from '@matter/types/clusters/descriptor';
|
|
4
5
|
import { BroadcastServer } from '@matterbridge/thread/server';
|
|
5
|
-
import {
|
|
6
|
+
import { hasAnyParameter } from '@matterbridge/utils/cli';
|
|
7
|
+
import { inspectError } from '@matterbridge/utils/error';
|
|
6
8
|
import { logModuleLoaded } from '@matterbridge/utils/loader';
|
|
7
9
|
import { isValidArray, isValidObject, isValidString } from '@matterbridge/utils/validate';
|
|
8
10
|
import { fireAndForget } from '@matterbridge/utils/wait';
|
|
@@ -47,14 +49,16 @@ export class MatterbridgePlatform {
|
|
|
47
49
|
isShuttingDown = false;
|
|
48
50
|
#selectDevices = new Map();
|
|
49
51
|
#selectEntities = new Map();
|
|
52
|
+
#nodeLabels = new Map();
|
|
50
53
|
#contextReady;
|
|
51
54
|
#selectDeviceContextReady;
|
|
52
55
|
#selectEntityContextReady;
|
|
56
|
+
#nodeLabelsContextReady;
|
|
53
57
|
ready;
|
|
54
58
|
#registeredEndpoints = new Map();
|
|
55
59
|
#server;
|
|
56
|
-
#debug =
|
|
57
|
-
#verbose =
|
|
60
|
+
#debug = hasAnyParameter('debug', 'verbose', 'debug-platform', 'verbose-platform');
|
|
61
|
+
#verbose = hasAnyParameter('verbose', 'verbose-platform');
|
|
58
62
|
#addBridgedEndpoint;
|
|
59
63
|
#removeBridgedEndpoint;
|
|
60
64
|
#removeAllBridgedEndpoints;
|
|
@@ -117,7 +121,15 @@ export class MatterbridgePlatform {
|
|
|
117
121
|
this.log.debug(`Loaded ${this.#selectEntities.size} selectEntity for plugin ${this.config.name}`);
|
|
118
122
|
return;
|
|
119
123
|
});
|
|
120
|
-
this.
|
|
124
|
+
this.log.debug(`Loading nodeLabels for plugin ${this.config.name}`);
|
|
125
|
+
this.#nodeLabelsContextReady = this.#storage.createStorage('nodeLabels').then(async (context) => {
|
|
126
|
+
const nodeLabels = await context.get('nodeLabels', []);
|
|
127
|
+
for (const label of nodeLabels)
|
|
128
|
+
this.#nodeLabels.set(label.uniqueId, label.label);
|
|
129
|
+
this.log.debug(`Loaded ${this.#nodeLabels.size} nodeLabels for plugin ${this.config.name}`);
|
|
130
|
+
return;
|
|
131
|
+
});
|
|
132
|
+
this.ready = Promise.all([this.#contextReady, this.#selectDeviceContextReady, this.#selectEntityContextReady, this.#nodeLabelsContextReady]).then(() => {
|
|
121
133
|
this.log.debug(`MatterbridgePlatform for plugin ${this.config.name} is fully initialized`);
|
|
122
134
|
this.isReady = true;
|
|
123
135
|
return;
|
|
@@ -166,6 +178,69 @@ export class MatterbridgePlatform {
|
|
|
166
178
|
return;
|
|
167
179
|
this.#server.respond({ ...msg, result: { entities: this.getSelectEntities().toSorted((keyA, keyB) => keyA.name.localeCompare(keyB.name)) } });
|
|
168
180
|
break;
|
|
181
|
+
case 'platform_unregister_device':
|
|
182
|
+
if (msg.params.pluginName === this.name) {
|
|
183
|
+
this.#server.respond({ ...msg, result: { success: true } });
|
|
184
|
+
const { serialNumber, uniqueId } = msg.params;
|
|
185
|
+
fireAndForget((async () => {
|
|
186
|
+
try {
|
|
187
|
+
const endpoint = this.getDevices().find((device) => device.serialNumber === serialNumber && device.uniqueId === uniqueId);
|
|
188
|
+
if (!endpoint) {
|
|
189
|
+
this.log.warn(`Unregister device: no device found with serialNumber ${CYAN}${serialNumber}${wr} and uniqueId ${CYAN}${uniqueId}${wr}`);
|
|
190
|
+
this.wssSendSnackbarMessage(`Device ${serialNumber} not found`, 5, 'warning');
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
await this.unregisterDevice(endpoint);
|
|
194
|
+
this.wssSendSnackbarMessage(`Device ${endpoint.deviceName} reset`, 5, 'success');
|
|
195
|
+
this.wssSendRestartRequired(true, true);
|
|
196
|
+
}
|
|
197
|
+
finally {
|
|
198
|
+
this.#server.request({ type: 'frontend_closesnackbarmessage', src: 'platform', dst: 'frontend', params: { message: 'Resetting the device...' } });
|
|
199
|
+
}
|
|
200
|
+
})(), this.log, `Unregister device ${serialNumber}`);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
break;
|
|
206
|
+
case 'platform_rename_device':
|
|
207
|
+
if (msg.params.pluginName === this.name) {
|
|
208
|
+
this.#server.respond({ ...msg, result: { success: true } });
|
|
209
|
+
const { serialNumber, uniqueId, label } = msg.params;
|
|
210
|
+
fireAndForget((async () => {
|
|
211
|
+
try {
|
|
212
|
+
const endpoint = this.getDevices().find((device) => device.serialNumber === serialNumber && device.uniqueId === uniqueId);
|
|
213
|
+
if (!endpoint?.uniqueId) {
|
|
214
|
+
this.log.warn(`Rename device: no device found with serialNumber ${CYAN}${serialNumber}${wr} and uniqueId ${CYAN}${uniqueId}${wr}`);
|
|
215
|
+
this.wssSendSnackbarMessage(`Device ${serialNumber} not found`, 5, 'warning');
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (!isValidString(label, 1, 32)) {
|
|
219
|
+
this.log.warn(`Rename device: the new name for device ${CYAN}${endpoint.deviceName}${wr} must be 1 to 32 characters long`);
|
|
220
|
+
this.wssSendSnackbarMessage(`The new name must be 1 to 32 characters long`, 5, 'warning');
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (label === endpoint.deviceName)
|
|
224
|
+
this.#nodeLabels.delete(endpoint.uniqueId);
|
|
225
|
+
else
|
|
226
|
+
this.#nodeLabels.set(endpoint.uniqueId, label);
|
|
227
|
+
const nodeLabels = Array.from(this.#nodeLabels.entries()).map(([key, value]) => ({ uniqueId: key, label: value }));
|
|
228
|
+
const storage = await this.#storage.createStorage('nodeLabels');
|
|
229
|
+
await storage.set('nodeLabels', nodeLabels);
|
|
230
|
+
await this.#setNodeLabel(endpoint, label);
|
|
231
|
+
this.log.info(`Device ${endpoint.deviceName} renamed to ${label}`);
|
|
232
|
+
this.wssSendSnackbarMessage(`Device ${endpoint.deviceName} renamed to ${label}`, 5, 'success');
|
|
233
|
+
this.wssSendRestartRequired(true, true);
|
|
234
|
+
}
|
|
235
|
+
finally {
|
|
236
|
+
this.#server.request({ type: 'frontend_closesnackbarmessage', src: 'platform', dst: 'frontend', params: { message: 'Renaming the device...' } });
|
|
237
|
+
}
|
|
238
|
+
})(), this.log, `Rename device ${serialNumber}`);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
break;
|
|
169
244
|
default:
|
|
170
245
|
if (this.#verbose)
|
|
171
246
|
this.log.debug(`Unknown broadcast request ${CYAN}${msg.type}${db} from ${CYAN}${msg.src}${db}`);
|
|
@@ -176,6 +251,7 @@ export class MatterbridgePlatform {
|
|
|
176
251
|
this.log.debug(`Destroying MatterbridgePlatform for plugin ${this.config.name}`);
|
|
177
252
|
this.#selectDevices.clear();
|
|
178
253
|
this.#selectEntities.clear();
|
|
254
|
+
this.#nodeLabels.clear();
|
|
179
255
|
this.#registeredEndpoints.clear();
|
|
180
256
|
await this.context?.close();
|
|
181
257
|
this.context = undefined;
|
|
@@ -302,6 +378,22 @@ export class MatterbridgePlatform {
|
|
|
302
378
|
}
|
|
303
379
|
await this.#addBridgedEndpoint?.(this.name, device);
|
|
304
380
|
this.#registeredEndpoints.set(device.uniqueId, device);
|
|
381
|
+
const nodeLabel = this.#nodeLabels.get(device.uniqueId);
|
|
382
|
+
if (isValidString(nodeLabel, 1, 32)) {
|
|
383
|
+
await this.#setNodeLabel(device, nodeLabel);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
async #setNodeLabel(device, nodeLabel) {
|
|
387
|
+
this.log.debug(`Setting nodeLabel ${CYAN}${nodeLabel}${db} for device ${CYAN}${device.deviceName}${db}`);
|
|
388
|
+
try {
|
|
389
|
+
if (device.hasClusterServer(BridgedDeviceBasicInformation))
|
|
390
|
+
await device.setAttribute(BridgedDeviceBasicInformation, 'nodeLabel', nodeLabel, this.log);
|
|
391
|
+
else if (device.hasClusterServer(BasicInformation))
|
|
392
|
+
await device.setAttribute(BasicInformation, 'nodeLabel', nodeLabel, this.log);
|
|
393
|
+
}
|
|
394
|
+
catch (error) {
|
|
395
|
+
inspectError(this.log, `Failed to set nodeLabel ${nodeLabel} for device ${device.deviceName}`, error);
|
|
396
|
+
}
|
|
305
397
|
}
|
|
306
398
|
async unregisterDevice(device) {
|
|
307
399
|
assertMatterbridgeEndpoint(device, `MatterbridgePlatform.unregisterDevice for plugin ${this.name}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matterbridge/core",
|
|
3
|
-
"version": "3.11.2-dev-
|
|
3
|
+
"version": "3.11.2-dev-20261105-a15bb91",
|
|
4
4
|
"description": "Matterbridge core library",
|
|
5
5
|
"author": "https://github.com/Luligu",
|
|
6
6
|
"homepage": "https://matterbridge.io/",
|
|
@@ -136,10 +136,10 @@
|
|
|
136
136
|
},
|
|
137
137
|
"dependencies": {
|
|
138
138
|
"@matter/main": "0.18.0",
|
|
139
|
-
"@matterbridge/dgram": "3.11.2-dev-
|
|
140
|
-
"@matterbridge/thread": "3.11.2-dev-
|
|
141
|
-
"@matterbridge/types": "3.11.2-dev-
|
|
142
|
-
"@matterbridge/utils": "3.11.2-dev-
|
|
139
|
+
"@matterbridge/dgram": "3.11.2-dev-20261105-a15bb91",
|
|
140
|
+
"@matterbridge/thread": "3.11.2-dev-20261105-a15bb91",
|
|
141
|
+
"@matterbridge/types": "3.11.2-dev-20261105-a15bb91",
|
|
142
|
+
"@matterbridge/utils": "3.11.2-dev-20261105-a15bb91",
|
|
143
143
|
"escape-html": "1.0.3",
|
|
144
144
|
"express": "5.3.0",
|
|
145
145
|
"express-rate-limit": "8.7.2",
|