@matterbridge/core 3.11.2-dev-20261104-014189e → 3.11.2-dev-20261104-98c7a1f
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/frontend.js +12 -0
- 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);
|
package/dist/frontend.js
CHANGED
|
@@ -1376,6 +1376,18 @@ export class Frontend extends EventEmitter {
|
|
|
1376
1376
|
await this.matterbridge.shutdownProcessAndFactoryReset();
|
|
1377
1377
|
sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true });
|
|
1378
1378
|
}
|
|
1379
|
+
else if (data.method === '/api/unregister-device') {
|
|
1380
|
+
this.wssSendSnackbarMessage('Resetting the device...');
|
|
1381
|
+
const { pluginName, serialNumber, uniqueId } = data.params;
|
|
1382
|
+
this.server.request({ type: 'platform_unregister_device', src: this.server.name, dst: 'platform', params: { pluginName, serialNumber, uniqueId } });
|
|
1383
|
+
sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true });
|
|
1384
|
+
}
|
|
1385
|
+
else if (data.method === '/api/rename-device') {
|
|
1386
|
+
this.wssSendSnackbarMessage('Renaming the device...');
|
|
1387
|
+
const { pluginName, serialNumber, uniqueId, label } = data.params;
|
|
1388
|
+
this.server.request({ type: 'platform_rename_device', src: this.server.name, dst: 'platform', params: { pluginName, serialNumber, uniqueId, label } });
|
|
1389
|
+
sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true });
|
|
1390
|
+
}
|
|
1379
1391
|
else if (data.method === '/api/viewhistorypage') {
|
|
1380
1392
|
generateHistoryPage({ outputPath: path.join(this.matterbridge.matterbridgeDirectory, MATTERBRIDGE_HISTORY_FILE), pageTitle: `Matterbridge Cpu & Memory History` });
|
|
1381
1393
|
sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true });
|
|
@@ -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-20261104-
|
|
3
|
+
"version": "3.11.2-dev-20261104-98c7a1f",
|
|
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-20261104-
|
|
140
|
-
"@matterbridge/thread": "3.11.2-dev-20261104-
|
|
141
|
-
"@matterbridge/types": "3.11.2-dev-20261104-
|
|
142
|
-
"@matterbridge/utils": "3.11.2-dev-20261104-
|
|
139
|
+
"@matterbridge/dgram": "3.11.2-dev-20261104-98c7a1f",
|
|
140
|
+
"@matterbridge/thread": "3.11.2-dev-20261104-98c7a1f",
|
|
141
|
+
"@matterbridge/types": "3.11.2-dev-20261104-98c7a1f",
|
|
142
|
+
"@matterbridge/utils": "3.11.2-dev-20261104-98c7a1f",
|
|
143
143
|
"escape-html": "1.0.3",
|
|
144
144
|
"express": "5.3.0",
|
|
145
145
|
"express-rate-limit": "8.7.2",
|