matterbridge 2.1.5 → 2.1.6-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 +17 -0
- package/README-DOCKER.md +17 -7
- package/dist/cli.js +0 -26
- package/dist/cluster/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -23
- package/dist/deviceManager.js +1 -94
- package/dist/frontend.js +55 -280
- package/dist/index.js +0 -28
- package/dist/logger/export.js +0 -1
- package/dist/matter/behaviors.js +0 -2
- package/dist/matter/clusters.js +0 -2
- package/dist/matter/devices.js +0 -2
- package/dist/matter/endpoints.js +0 -2
- package/dist/matter/export.js +0 -2
- package/dist/matter/types.js +0 -2
- package/dist/matterbridge.js +68 -765
- package/dist/matterbridgeAccessoryPlatform.js +0 -33
- package/dist/matterbridgeBehaviors.js +1 -32
- package/dist/matterbridgeDeviceTypes.js +11 -112
- package/dist/matterbridgeDynamicPlatform.js +0 -33
- package/dist/matterbridgeEndpoint.js +6 -690
- package/dist/matterbridgeEndpointHelpers.js +9 -117
- package/dist/matterbridgePlatform.js +56 -131
- package/dist/matterbridgeTypes.js +0 -24
- package/dist/pluginManager.js +3 -230
- 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 +10 -264
- package/frontend/build/asset-manifest.json +3 -3
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/js/{main.cd192588.js → main.a241d4f0.js} +9 -9
- package/frontend/build/static/js/main.a241d4f0.js.map +1 -0
- package/npm-shrinkwrap.json +50 -50
- package/package.json +2 -3
- package/dist/cli.d.ts +0 -25
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cluster/export.d.ts +0 -2
- package/dist/cluster/export.d.ts.map +0 -1
- package/dist/cluster/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -27
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -114
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/frontend.d.ts +0 -143
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/index.d.ts +0 -35
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger/export.d.ts +0 -2
- package/dist/logger/export.d.ts.map +0 -1
- package/dist/logger/export.js.map +0 -1
- package/dist/matter/behaviors.d.ts +0 -2
- package/dist/matter/behaviors.d.ts.map +0 -1
- package/dist/matter/behaviors.js.map +0 -1
- package/dist/matter/clusters.d.ts +0 -2
- package/dist/matter/clusters.d.ts.map +0 -1
- package/dist/matter/clusters.js.map +0 -1
- package/dist/matter/devices.d.ts +0 -2
- package/dist/matter/devices.d.ts.map +0 -1
- package/dist/matter/devices.js.map +0 -1
- package/dist/matter/endpoints.d.ts +0 -2
- package/dist/matter/endpoints.d.ts.map +0 -1
- package/dist/matter/endpoints.js.map +0 -1
- package/dist/matter/export.d.ts +0 -5
- package/dist/matter/export.d.ts.map +0 -1
- package/dist/matter/export.js.map +0 -1
- package/dist/matter/types.d.ts +0 -3
- package/dist/matter/types.d.ts.map +0 -1
- package/dist/matter/types.js.map +0 -1
- package/dist/matterbridge.d.ts +0 -409
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -39
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1056
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -177
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -39
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -835
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -2275
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -159
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -169
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -236
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/storage/export.d.ts +0 -2
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -61
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/export.d.ts +0 -3
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/utils.d.ts +0 -231
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/utils.js.map +0 -1
- package/frontend/build/static/js/main.cd192588.js.map +0 -1
- /package/frontend/build/static/js/{main.cd192588.js.LICENSE.txt → main.a241d4f0.js.LICENSE.txt} +0 -0
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
// Node.js modules
|
|
3
1
|
import { createHash } from 'crypto';
|
|
4
|
-
// AnsiLogger module
|
|
5
2
|
import { BLUE, CYAN, db, debugStringify, er, hk, or, YELLOW, zb } from './logger/export.js';
|
|
6
3
|
import { MatterbridgeIdentifyServer, MatterbridgeOnOffServer, MatterbridgeLevelControlServer, MatterbridgeColorControlServer, MatterbridgeWindowCoveringServer, MatterbridgeThermostatServer, MatterbridgeFanControlServer, MatterbridgeDoorLockServer, MatterbridgeModeSelectServer, MatterbridgeValveConfigurationAndControlServer, MatterbridgeSmokeCoAlarmServer, MatterbridgeBooleanStateConfigurationServer, } from './matterbridgeBehaviors.js';
|
|
7
|
-
// @matter
|
|
8
4
|
import { Lifecycle } from '@matter/main';
|
|
9
5
|
import { getClusterNameById } from '@matter/main/types';
|
|
10
|
-
// @matter clusters
|
|
11
6
|
import { PowerSource } from '@matter/main/clusters/power-source';
|
|
12
7
|
import { UserLabel } from '@matter/main/clusters/user-label';
|
|
13
8
|
import { FixedLabel } from '@matter/main/clusters/fixed-label';
|
|
@@ -49,7 +44,6 @@ import { Pm25ConcentrationMeasurement } from '@matter/main/clusters/pm25-concent
|
|
|
49
44
|
import { Pm10ConcentrationMeasurement } from '@matter/main/clusters/pm10-concentration-measurement';
|
|
50
45
|
import { RadonConcentrationMeasurement } from '@matter/main/clusters/radon-concentration-measurement';
|
|
51
46
|
import { TotalVolatileOrganicCompoundsConcentrationMeasurement } from '@matter/main/clusters/total-volatile-organic-compounds-concentration-measurement';
|
|
52
|
-
// @matter behaviors
|
|
53
47
|
import { PowerSourceServer } from '@matter/main/behaviors/power-source';
|
|
54
48
|
import { UserLabelServer } from '@matter/main/behaviors/user-label';
|
|
55
49
|
import { FixedLabelServer } from '@matter/main/behaviors/fixed-label';
|
|
@@ -92,19 +86,19 @@ export function lowercaseFirstLetter(name) {
|
|
|
92
86
|
}
|
|
93
87
|
export function checkNotLatinCharacters(deviceName) {
|
|
94
88
|
const nonLatinRegexList = [
|
|
95
|
-
/[\u0400-\u04FF\u0500-\u052F]/,
|
|
96
|
-
/[\u2E80-\u9FFF]/,
|
|
97
|
-
/[\uAC00-\uD7AF]/,
|
|
98
|
-
/[\u0600-\u06FF\u0750-\u077F]/,
|
|
99
|
-
/[\u0590-\u05FF]/,
|
|
100
|
-
/[\u0900-\u097F]/,
|
|
101
|
-
/[\u0E00-\u0E7F]/,
|
|
102
|
-
/[\u1200-\u137F]/,
|
|
89
|
+
/[\u0400-\u04FF\u0500-\u052F]/,
|
|
90
|
+
/[\u2E80-\u9FFF]/,
|
|
91
|
+
/[\uAC00-\uD7AF]/,
|
|
92
|
+
/[\u0600-\u06FF\u0750-\u077F]/,
|
|
93
|
+
/[\u0590-\u05FF]/,
|
|
94
|
+
/[\u0900-\u097F]/,
|
|
95
|
+
/[\u0E00-\u0E7F]/,
|
|
96
|
+
/[\u1200-\u137F]/,
|
|
103
97
|
];
|
|
104
98
|
return nonLatinRegexList.some((regex) => regex.test(deviceName));
|
|
105
99
|
}
|
|
106
100
|
export function generateUniqueId(deviceName) {
|
|
107
|
-
return createHash('md5').update(deviceName).digest('hex');
|
|
101
|
+
return createHash('md5').update(deviceName).digest('hex');
|
|
108
102
|
}
|
|
109
103
|
export function createUniqueId(param1, param2, param3, param4) {
|
|
110
104
|
const hash = createHash('md5');
|
|
@@ -112,7 +106,6 @@ export function createUniqueId(param1, param2, param3, param4) {
|
|
|
112
106
|
return hash.digest('hex');
|
|
113
107
|
}
|
|
114
108
|
export function getBehaviourTypesFromClusterServerIds(clusterServerList) {
|
|
115
|
-
// Map Server ClusterId to Behavior.Type
|
|
116
109
|
const behaviorTypes = [];
|
|
117
110
|
clusterServerList.forEach((clusterId) => {
|
|
118
111
|
behaviorTypes.push(getBehaviourTypeFromClusterServerId(clusterId));
|
|
@@ -120,15 +113,12 @@ export function getBehaviourTypesFromClusterServerIds(clusterServerList) {
|
|
|
120
113
|
return behaviorTypes;
|
|
121
114
|
}
|
|
122
115
|
export function getBehaviourTypesFromClusterClientIds(clusterClientList) {
|
|
123
|
-
// Map Client ClusterId to Behavior.Type
|
|
124
116
|
const behaviorTypes = [];
|
|
125
117
|
clusterClientList.forEach((clusterId) => {
|
|
126
|
-
// behaviorTypes.push(getBehaviourTypeFromClusterClientId(clusterId));
|
|
127
118
|
});
|
|
128
119
|
return behaviorTypes;
|
|
129
120
|
}
|
|
130
121
|
export function getBehaviourTypeFromClusterServerId(clusterId) {
|
|
131
|
-
// Map ClusterId to Server Behavior.Type
|
|
132
122
|
if (clusterId === PowerSource.Cluster.id)
|
|
133
123
|
return PowerSourceServer.with(PowerSource.Feature.Wired);
|
|
134
124
|
if (clusterId === UserLabel.Cluster.id)
|
|
@@ -214,8 +204,6 @@ export function getBehaviourTypeFromClusterServerId(clusterId) {
|
|
|
214
204
|
return MatterbridgeIdentifyServer;
|
|
215
205
|
}
|
|
216
206
|
export function getBehaviourTypeFromClusterClientId(clusterId) {
|
|
217
|
-
// Map ClusterId to Client Behavior.Type
|
|
218
|
-
// return IdentifyClient;
|
|
219
207
|
}
|
|
220
208
|
export function getBehavior(endpoint, cluster) {
|
|
221
209
|
let behavior;
|
|
@@ -261,13 +249,6 @@ export function addOptionalClusterServers(endpoint) {
|
|
|
261
249
|
});
|
|
262
250
|
addClusterServers(endpoint, optionalServerList);
|
|
263
251
|
}
|
|
264
|
-
/**
|
|
265
|
-
* Adds cluster servers to the specified endpoint based on the provided server list.
|
|
266
|
-
*
|
|
267
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
|
|
268
|
-
* @param {ClusterId[]} serverList - The list of cluster IDs to add.
|
|
269
|
-
* @returns void
|
|
270
|
-
*/
|
|
271
252
|
export function addClusterServers(endpoint, serverList) {
|
|
272
253
|
if (serverList.includes(PowerSource.Cluster.id))
|
|
273
254
|
endpoint.createDefaultPowerSourceWiredClusterServer();
|
|
@@ -341,16 +322,7 @@ export function addClusterServers(endpoint, serverList) {
|
|
|
341
322
|
endpoint.createDefaultRadonConcentrationMeasurementClusterServer();
|
|
342
323
|
if (serverList.includes(TotalVolatileOrganicCompoundsConcentrationMeasurement.Cluster.id))
|
|
343
324
|
endpoint.createDefaultTvocMeasurementClusterServer();
|
|
344
|
-
// if (serverList.includes(DeviceEnergyManagement.Cluster.id)) endpoint.createDefaultDeviceEnergyManagementClusterServer();
|
|
345
|
-
// if (serverList.includes(DeviceEnergyManagementMode.Cluster.id)) endpoint.createDefaultDeviceEnergyManagementModeClusterServer();
|
|
346
325
|
}
|
|
347
|
-
/**
|
|
348
|
-
* Adds a fixed label to the FixedLabel cluster. The FixedLabel cluster is created if it does not exist.
|
|
349
|
-
*
|
|
350
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
|
|
351
|
-
* @param {string} label - The label to add.
|
|
352
|
-
* @param {string} value - The value of the label.
|
|
353
|
-
*/
|
|
354
326
|
export async function addFixedLabel(endpoint, label, value) {
|
|
355
327
|
if (!endpoint.hasClusterServer(FixedLabel.Cluster.id)) {
|
|
356
328
|
endpoint.log.debug(`addFixedLabel: add cluster ${hk}FixedLabel${db}:${hk}fixedLabel${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
|
|
@@ -367,13 +339,6 @@ export async function addFixedLabel(endpoint, label, value) {
|
|
|
367
339
|
await endpoint.setAttribute(FixedLabel.Cluster.id, 'labelList', labelList, endpoint.log);
|
|
368
340
|
}
|
|
369
341
|
}
|
|
370
|
-
/**
|
|
371
|
-
* Adds a user label to the UserLabel cluster. The UserLabel cluster is created if it does not exist.
|
|
372
|
-
*
|
|
373
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
|
|
374
|
-
* @param {string} label - The label to add.
|
|
375
|
-
* @param {string} value - The value of the label.
|
|
376
|
-
*/
|
|
377
342
|
export async function addUserLabel(endpoint, label, value) {
|
|
378
343
|
if (!endpoint.hasClusterServer(UserLabel.Cluster.id)) {
|
|
379
344
|
endpoint.log.debug(`addUserLabel: add cluster ${hk}UserLabel${db}:${hk}userLabel${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
|
|
@@ -437,16 +402,6 @@ export function getAttributeId(endpoint, cluster, attribute) {
|
|
|
437
402
|
return endpoint.behaviors.supported[lowercaseFirstLetter(cluster)]?.schema?.children?.find((child) => child.name === capitalizeFirstLetter(attribute))?.id;
|
|
438
403
|
}
|
|
439
404
|
}
|
|
440
|
-
/**
|
|
441
|
-
* Retrieves the value of the provided attribute from the given cluster.
|
|
442
|
-
*
|
|
443
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to retrieve the attribute from.
|
|
444
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to retrieve the attribute from.
|
|
445
|
-
* @param {string} attribute - The name of the attribute to retrieve.
|
|
446
|
-
* @param {AnsiLogger} [log] - (Optional) The logger to use for logging the retrieve. Errors are logged to the endpoint logger.
|
|
447
|
-
* @returns {any} The value of the attribute, or undefined if the attribute is not found.
|
|
448
|
-
*/
|
|
449
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
450
405
|
export function getAttribute(endpoint, cluster, attribute, log) {
|
|
451
406
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
452
407
|
if (!clusterName) {
|
|
@@ -469,16 +424,6 @@ export function getAttribute(endpoint, cluster, attribute, log) {
|
|
|
469
424
|
log?.info(`${db}Get endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} attribute ${hk}${capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db} value ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
|
|
470
425
|
return value;
|
|
471
426
|
}
|
|
472
|
-
/**
|
|
473
|
-
* Sets the value of an attribute on a cluster server.
|
|
474
|
-
*
|
|
475
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to set the attribute on.
|
|
476
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to set the attribute on.
|
|
477
|
-
* @param {string} attribute - The name of the attribute.
|
|
478
|
-
* @param {boolean | number | bigint | string | object | null} value - The value to set for the attribute.
|
|
479
|
-
* @param {AnsiLogger} [log] - (Optional) The logger to use for logging the set. Errors are logged to the endpoint logger.
|
|
480
|
-
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
|
|
481
|
-
*/
|
|
482
427
|
export async function setAttribute(endpoint, cluster, attribute, value, log) {
|
|
483
428
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
484
429
|
if (!clusterName) {
|
|
@@ -504,16 +449,6 @@ export async function setAttribute(endpoint, cluster, attribute, value, log) {
|
|
|
504
449
|
`to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
|
|
505
450
|
return true;
|
|
506
451
|
}
|
|
507
|
-
/**
|
|
508
|
-
* Sets the value of an attribute on a cluster server.
|
|
509
|
-
*
|
|
510
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to update the attribute on.
|
|
511
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to update the attribute on.
|
|
512
|
-
* @param {string} attribute - The name of the attribute.
|
|
513
|
-
* @param {boolean | number | bigint | string | object | null} value - The value to set for the attribute.
|
|
514
|
-
* @param {AnsiLogger} [log] - (Optional) The logger to use for logging the update. Errors are logged to the endpoint logger.
|
|
515
|
-
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
|
|
516
|
-
*/
|
|
517
452
|
export async function updateAttribute(endpoint, cluster, attribute, value, log) {
|
|
518
453
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
519
454
|
if (!clusterName) {
|
|
@@ -544,17 +479,6 @@ export async function updateAttribute(endpoint, cluster, attribute, value, log)
|
|
|
544
479
|
`to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
|
|
545
480
|
return true;
|
|
546
481
|
}
|
|
547
|
-
/**
|
|
548
|
-
* Subscribes to the provided attribute on a cluster.
|
|
549
|
-
*
|
|
550
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to subscribe the attribute to.
|
|
551
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to subscribe the attribute to.
|
|
552
|
-
* @param {string} attribute - The name of the attribute to subscribe to.
|
|
553
|
-
* @param {(newValue: any, oldValue: any) => void} listener - A callback function that will be called when the attribute value changes.
|
|
554
|
-
* @param {AnsiLogger} [log] - Optional logger for logging errors and information.
|
|
555
|
-
* @returns {boolean} - A boolean indicating whether the subscription was successful.
|
|
556
|
-
*/
|
|
557
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
558
482
|
export async function subscribeAttribute(endpoint, cluster, attribute, listener, log) {
|
|
559
483
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
560
484
|
if (!clusterName) {
|
|
@@ -565,7 +489,6 @@ export async function subscribeAttribute(endpoint, cluster, attribute, listener,
|
|
|
565
489
|
endpoint.log.debug(`subscribeAttribute ${hk}${clusterName}.${attribute}${db}: Endpoint ${or}${endpoint.maybeId}${db}:${or}${endpoint.maybeNumber}${db} is in the ${BLUE}${endpoint.construction.status}${db} state`);
|
|
566
490
|
await endpoint.construction.ready;
|
|
567
491
|
}
|
|
568
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
569
492
|
const events = endpoint.events;
|
|
570
493
|
attribute = lowercaseFirstLetter(attribute) + '$Changed';
|
|
571
494
|
if (!(clusterName in events) || !(attribute in events[clusterName])) {
|
|
@@ -576,11 +499,6 @@ export async function subscribeAttribute(endpoint, cluster, attribute, listener,
|
|
|
576
499
|
log?.info(`${db}Subscribed endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} attribute ${hk}${capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db}`);
|
|
577
500
|
return true;
|
|
578
501
|
}
|
|
579
|
-
/**
|
|
580
|
-
* Get the default TemperatureMeasurement cluster server options.
|
|
581
|
-
*
|
|
582
|
-
* @param {number} measuredValue - The measured value of the temperature x 100.
|
|
583
|
-
*/
|
|
584
502
|
export function getDefaultTemperatureMeasurementClusterServer(measuredValue = 0) {
|
|
585
503
|
return optionsFor(TemperatureMeasurementServer, {
|
|
586
504
|
measuredValue,
|
|
@@ -589,11 +507,6 @@ export function getDefaultTemperatureMeasurementClusterServer(measuredValue = 0)
|
|
|
589
507
|
tolerance: 0,
|
|
590
508
|
});
|
|
591
509
|
}
|
|
592
|
-
/**
|
|
593
|
-
* Get the default RelativeHumidityMeasurement cluster server options.
|
|
594
|
-
*
|
|
595
|
-
* @param {number} measuredValue - The measured value of the relative humidity x 100.
|
|
596
|
-
*/
|
|
597
510
|
export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue = 0) {
|
|
598
511
|
return optionsFor(RelativeHumidityMeasurementServer, {
|
|
599
512
|
measuredValue,
|
|
@@ -602,11 +515,6 @@ export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue
|
|
|
602
515
|
tolerance: 0,
|
|
603
516
|
});
|
|
604
517
|
}
|
|
605
|
-
/**
|
|
606
|
-
* Get the default PressureMeasurement cluster server options.
|
|
607
|
-
*
|
|
608
|
-
* @param {number} measuredValue - The measured value for the pressure.
|
|
609
|
-
*/
|
|
610
518
|
export function getDefaultPressureMeasurementClusterServer(measuredValue = 1000) {
|
|
611
519
|
return optionsFor(PressureMeasurementServer, {
|
|
612
520
|
measuredValue,
|
|
@@ -615,11 +523,6 @@ export function getDefaultPressureMeasurementClusterServer(measuredValue = 1000)
|
|
|
615
523
|
tolerance: 0,
|
|
616
524
|
});
|
|
617
525
|
}
|
|
618
|
-
/**
|
|
619
|
-
* Get the default IlluminanceMeasurement cluster server options.
|
|
620
|
-
*
|
|
621
|
-
* @param {number} measuredValue - The measured value of illuminance.
|
|
622
|
-
*/
|
|
623
526
|
export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = 0) {
|
|
624
527
|
return optionsFor(IlluminanceMeasurementServer, {
|
|
625
528
|
measuredValue,
|
|
@@ -628,11 +531,6 @@ export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = 0)
|
|
|
628
531
|
tolerance: 0,
|
|
629
532
|
});
|
|
630
533
|
}
|
|
631
|
-
/**
|
|
632
|
-
* Get the default FlowMeasurement cluster server options.
|
|
633
|
-
*
|
|
634
|
-
* @param {number} measuredValue - The measured value of the flow in 10 x m3/h.
|
|
635
|
-
*/
|
|
636
534
|
export function getDefaultFlowMeasurementClusterServer(measuredValue = 0) {
|
|
637
535
|
return optionsFor(FlowMeasurementServer, {
|
|
638
536
|
measuredValue,
|
|
@@ -641,11 +539,6 @@ export function getDefaultFlowMeasurementClusterServer(measuredValue = 0) {
|
|
|
641
539
|
tolerance: 0,
|
|
642
540
|
});
|
|
643
541
|
}
|
|
644
|
-
/**
|
|
645
|
-
* Get the default OccupancySensing cluster server options.
|
|
646
|
-
*
|
|
647
|
-
* @param {boolean} occupied - A boolean indicating whether the occupancy is occupied or not. Default is false.
|
|
648
|
-
*/
|
|
649
542
|
export function getDefaultOccupancySensingClusterServer(occupied = false) {
|
|
650
543
|
return optionsFor(OccupancySensingServer, {
|
|
651
544
|
occupancy: { occupied },
|
|
@@ -654,4 +547,3 @@ export function getDefaultOccupancySensingClusterServer(occupied = false) {
|
|
|
654
547
|
pirOccupiedToUnoccupiedDelay: 30,
|
|
655
548
|
});
|
|
656
549
|
}
|
|
657
|
-
//# sourceMappingURL=matterbridgeEndpointHelpers.js.map
|
|
@@ -1,65 +1,30 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the class MatterbridgeAccessoryPlatform.
|
|
3
|
-
*
|
|
4
|
-
* @file matterbridgePlatform.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2024-03-21
|
|
7
|
-
* @version 1.1.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2024, 2025, 2026 Luca Liguori.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License. *
|
|
22
|
-
*/
|
|
23
1
|
import { checkNotLatinCharacters } from './matterbridgeEndpointHelpers.js';
|
|
24
2
|
import { isValidArray, isValidObject, isValidString } from './utils/utils.js';
|
|
25
|
-
// AnsiLogger module
|
|
26
3
|
import { CYAN, db, er, nf, wr } from './logger/export.js';
|
|
27
|
-
// Storage module
|
|
28
4
|
import { NodeStorageManager } from './storage/export.js';
|
|
29
|
-
// Node.js module
|
|
30
5
|
import path from 'path';
|
|
31
|
-
/**
|
|
32
|
-
* Represents the base Matterbridge platform. It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
6
|
export class MatterbridgePlatform {
|
|
36
7
|
matterbridge;
|
|
37
8
|
log;
|
|
38
9
|
config = {};
|
|
39
|
-
name = '';
|
|
40
|
-
type = '';
|
|
41
|
-
version = '1.0.0';
|
|
42
|
-
// Platform storage
|
|
10
|
+
name = '';
|
|
11
|
+
type = '';
|
|
12
|
+
version = '1.0.0';
|
|
43
13
|
storage;
|
|
44
14
|
context;
|
|
45
|
-
// Device and entity selection
|
|
46
15
|
selectDevice = new Map();
|
|
47
16
|
selectEntity = new Map();
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
* @param {AnsiLogger} log - The logger instance.
|
|
55
|
-
* @param {PlatformConfig} config - The platform configuration.
|
|
56
|
-
*/
|
|
17
|
+
contextReady;
|
|
18
|
+
selectDeviceContextReady;
|
|
19
|
+
selectEntityContextReady;
|
|
20
|
+
ready;
|
|
21
|
+
registeredEndpoints = new Map();
|
|
22
|
+
registeredEndpointsByName = new Map();
|
|
57
23
|
constructor(matterbridge, log, config) {
|
|
58
24
|
this.matterbridge = matterbridge;
|
|
59
25
|
this.log = log;
|
|
60
26
|
this.config = config;
|
|
61
|
-
|
|
62
|
-
if (!isValidString(this.config.name))
|
|
27
|
+
if (!isValidString(this.config.name) || this.config.name === '')
|
|
63
28
|
return;
|
|
64
29
|
this.log.debug(`Creating storage for plugin ${this.config.name} in ${path.join(this.matterbridge.matterbridgeDirectory, this.config.name)}`);
|
|
65
30
|
this.storage = new NodeStorageManager({
|
|
@@ -69,64 +34,69 @@ export class MatterbridgePlatform {
|
|
|
69
34
|
logging: false,
|
|
70
35
|
forgiveParseErrors: true,
|
|
71
36
|
});
|
|
37
|
+
this.log.debug(`Creating context for plugin ${this.config.name}`);
|
|
38
|
+
this.contextReady = this.storage.createStorage('context').then((context) => {
|
|
39
|
+
this.context = context;
|
|
40
|
+
this.log.debug(`Created context for plugin ${this.config.name}`);
|
|
41
|
+
return context;
|
|
42
|
+
});
|
|
43
|
+
this.log.debug(`Loading selectDevice for plugin ${this.config.name}`);
|
|
44
|
+
this.selectDeviceContextReady = this.storage.createStorage('selectDevice').then(async (context) => {
|
|
45
|
+
const selectDevice = await context.get('selectDevice', []);
|
|
46
|
+
for (const device of selectDevice)
|
|
47
|
+
this.selectDevice.set(device.serial, device);
|
|
48
|
+
this.log.debug(`Loaded ${this.selectDevice.size} selectDevice for plugin ${this.config.name}`);
|
|
49
|
+
});
|
|
50
|
+
this.log.debug(`Loading selectEntity for plugin ${this.config.name}`);
|
|
51
|
+
this.selectEntityContextReady = this.storage.createStorage('selectEntity').then(async (context) => {
|
|
52
|
+
const selectEntity = await context.get('selectEntity', []);
|
|
53
|
+
for (const entity of selectEntity)
|
|
54
|
+
this.selectEntity.set(entity.name, entity);
|
|
55
|
+
this.log.debug(`Loaded ${this.selectEntity.size} selectEntity for plugin ${this.config.name}`);
|
|
56
|
+
});
|
|
57
|
+
this.ready = Promise.all([this.contextReady, this.selectDeviceContextReady, this.selectEntityContextReady]).then(() => {
|
|
58
|
+
this.log.debug(`MatterbridgePlatform for plugin ${this.config.name} is fully initialized`);
|
|
59
|
+
});
|
|
72
60
|
}
|
|
73
|
-
/**
|
|
74
|
-
* This method must be overridden in the extended class.
|
|
75
|
-
* It is called when the platform is started.
|
|
76
|
-
* Use this method to create the MatterbridgeDevice and call this.registerDevice().
|
|
77
|
-
* @param {string} [reason] - The reason for starting.
|
|
78
|
-
* @throws {Error} - Throws an error if the method is not overridden.
|
|
79
|
-
*/
|
|
80
61
|
async onStart(reason) {
|
|
81
62
|
this.log.error('Plugins must override onStart.', reason);
|
|
82
63
|
throw new Error('Plugins must override onStart.');
|
|
83
64
|
}
|
|
84
|
-
/**
|
|
85
|
-
* This method can be overridden in the extended class. Call super.onConfigure() to run checkEndpointNumbers().
|
|
86
|
-
* It is called after the platform has been commissioned.
|
|
87
|
-
* Use this method to perform any configuration of your devices.
|
|
88
|
-
*/
|
|
89
65
|
async onConfigure() {
|
|
90
66
|
this.log.debug(`Configuring platform ${this.name}`);
|
|
91
67
|
await this.checkEndpointNumbers();
|
|
92
68
|
}
|
|
93
|
-
/**
|
|
94
|
-
* This method can be overridden in the extended class. Call super.onShutdown() to run checkEndpointNumbers() and cleanup memory.
|
|
95
|
-
* It is called when the platform is shutting down.
|
|
96
|
-
* Use this method to clean up any resources.
|
|
97
|
-
* @param {string} [reason] - The reason for shutting down.
|
|
98
|
-
*/
|
|
99
69
|
async onShutdown(reason) {
|
|
100
70
|
this.log.debug(`Shutting down platform ${this.name}`, reason);
|
|
71
|
+
if (this.storage) {
|
|
72
|
+
this.log.debug(`Saving ${this.selectDevice.size} selectDevice...`);
|
|
73
|
+
const selectDevice = await this.storage.createStorage('selectDevice');
|
|
74
|
+
await selectDevice.set('selectDevice', Array.from(this.selectDevice.values()));
|
|
75
|
+
await selectDevice.close();
|
|
76
|
+
this.log.debug(`Saving ${this.selectEntity.size} selectEntity...`);
|
|
77
|
+
const selectEntity = await this.storage.createStorage('selectEntity');
|
|
78
|
+
await selectEntity.set('selectEntity', Array.from(this.selectEntity.values()));
|
|
79
|
+
await selectEntity.close();
|
|
80
|
+
}
|
|
101
81
|
await this.checkEndpointNumbers();
|
|
102
82
|
this.selectDevice.clear();
|
|
103
83
|
this.selectEntity.clear();
|
|
104
84
|
this.registeredEndpoints.clear();
|
|
105
85
|
this.registeredEndpointsByName.clear();
|
|
86
|
+
this.contextReady = undefined;
|
|
87
|
+
this.selectDeviceContextReady = undefined;
|
|
88
|
+
this.selectEntityContextReady = undefined;
|
|
106
89
|
await this.context?.close();
|
|
107
90
|
this.context = undefined;
|
|
108
91
|
await this.storage?.close();
|
|
109
92
|
this.storage = undefined;
|
|
110
93
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Sets the logger level and logs a debug message indicating that the plugin doesn't override this method.
|
|
113
|
-
* @param {LogLevel} logLevel The new logger level.
|
|
114
|
-
*/
|
|
115
94
|
async onChangeLoggerLevel(logLevel) {
|
|
116
95
|
this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
|
|
117
96
|
}
|
|
118
|
-
/**
|
|
119
|
-
* Check if a device with this name is already registered in the platform.
|
|
120
|
-
* @param {string} deviceName - The device name to check.
|
|
121
|
-
* @returns {boolean} True if the device is already registered, false otherwise.
|
|
122
|
-
*/
|
|
123
97
|
hasDeviceName(deviceName) {
|
|
124
98
|
return this.registeredEndpointsByName.has(deviceName);
|
|
125
99
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Registers a device with the Matterbridge platform.
|
|
128
|
-
* @param {MatterbridgeEndpoint} device - The device to register.
|
|
129
|
-
*/
|
|
130
100
|
async registerDevice(device) {
|
|
131
101
|
device.plugin = this.name;
|
|
132
102
|
if (device.deviceName && this.registeredEndpointsByName.has(device.deviceName)) {
|
|
@@ -142,10 +112,6 @@ export class MatterbridgePlatform {
|
|
|
142
112
|
if (device.deviceName)
|
|
143
113
|
this.registeredEndpointsByName.set(device.deviceName, device);
|
|
144
114
|
}
|
|
145
|
-
/**
|
|
146
|
-
* Unregisters a device registered with the Matterbridge platform.
|
|
147
|
-
* @param {MatterbridgeEndpoint} device - The device to unregister.
|
|
148
|
-
*/
|
|
149
115
|
async unregisterDevice(device) {
|
|
150
116
|
await this.matterbridge.removeBridgedEndpoint(this.name, device);
|
|
151
117
|
if (device.uniqueId)
|
|
@@ -153,19 +119,11 @@ export class MatterbridgePlatform {
|
|
|
153
119
|
if (device.deviceName)
|
|
154
120
|
this.registeredEndpointsByName.delete(device.deviceName);
|
|
155
121
|
}
|
|
156
|
-
/**
|
|
157
|
-
* Unregisters all devices registered with the Matterbridge platform.
|
|
158
|
-
*/
|
|
159
122
|
async unregisterAllDevices() {
|
|
160
123
|
await this.matterbridge.removeAllBridgedEndpoints(this.name);
|
|
161
124
|
this.registeredEndpoints.clear();
|
|
162
125
|
this.registeredEndpointsByName.clear();
|
|
163
126
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Verifies if the Matterbridge version meets the required version.
|
|
166
|
-
* @param {string} requiredVersion - The required version to compare against.
|
|
167
|
-
* @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
|
|
168
|
-
*/
|
|
169
127
|
verifyMatterbridgeVersion(requiredVersion) {
|
|
170
128
|
const compareVersions = (matterbridgeVersion, requiredVersion) => {
|
|
171
129
|
const stripTag = (v) => {
|
|
@@ -190,21 +148,9 @@ export class MatterbridgePlatform {
|
|
|
190
148
|
return false;
|
|
191
149
|
return true;
|
|
192
150
|
}
|
|
193
|
-
/**
|
|
194
|
-
* @deprecated This method is deprecated and will be removed in future versions. Use validateDevice instead.
|
|
195
|
-
*/
|
|
196
151
|
validateDeviceWhiteBlackList(device, log = true) {
|
|
197
152
|
return this.validateDevice(device, log);
|
|
198
153
|
}
|
|
199
|
-
/**
|
|
200
|
-
* Validates if a device is allowed based on the whitelist and blacklist configurations.
|
|
201
|
-
* The blacklist has priority over the whitelist.
|
|
202
|
-
*
|
|
203
|
-
* @param {string | string[]} device - The device name(s) to validate.
|
|
204
|
-
* @param {boolean} [log=true] - Whether to log the validation result.
|
|
205
|
-
* @returns {boolean} - Returns true if the device is allowed, false otherwise.
|
|
206
|
-
*
|
|
207
|
-
*/
|
|
208
154
|
validateDevice(device, log = true) {
|
|
209
155
|
if (!Array.isArray(device))
|
|
210
156
|
device = [device];
|
|
@@ -234,21 +180,9 @@ export class MatterbridgePlatform {
|
|
|
234
180
|
this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
|
|
235
181
|
return false;
|
|
236
182
|
}
|
|
237
|
-
/**
|
|
238
|
-
* @deprecated This method is deprecated and will be removed in future versions. Use validateEntity instead.
|
|
239
|
-
*/
|
|
240
183
|
validateEntityBlackList(device, entity, log = true) {
|
|
241
184
|
return this.validateEntity(device, entity, log);
|
|
242
185
|
}
|
|
243
|
-
/**
|
|
244
|
-
* Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
|
|
245
|
-
*
|
|
246
|
-
* @param {string} device - The device to which the entity belongs.
|
|
247
|
-
* @param {string} entity - The entity to validate.
|
|
248
|
-
* @param {boolean} [log=true] - Whether to log the validation result.
|
|
249
|
-
* @returns {boolean} - Returns true if the entity is allowed, false otherwise.
|
|
250
|
-
*
|
|
251
|
-
*/
|
|
252
186
|
validateEntity(device, entity, log = true) {
|
|
253
187
|
if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
|
|
254
188
|
if (log)
|
|
@@ -267,20 +201,11 @@ export class MatterbridgePlatform {
|
|
|
267
201
|
}
|
|
268
202
|
return true;
|
|
269
203
|
}
|
|
270
|
-
/**
|
|
271
|
-
* Checks and updates the endpoint numbers for Matterbridge devices.
|
|
272
|
-
*
|
|
273
|
-
* This method retrieves the list of Matterbridge devices and their child endpoints,
|
|
274
|
-
* compares their current endpoint numbers with the stored ones, and updates the storage
|
|
275
|
-
* if there are any changes. It logs the changes and updates the endpoint numbers accordingly.
|
|
276
|
-
*
|
|
277
|
-
* @returns {Promise<number>} The size of the updated endpoint map, or -1 if storage is not available.
|
|
278
|
-
*/
|
|
279
204
|
async checkEndpointNumbers() {
|
|
280
205
|
if (!this.storage)
|
|
281
206
|
return -1;
|
|
282
207
|
this.log.debug('Checking endpoint numbers...');
|
|
283
|
-
const context = await this.storage.createStorage('
|
|
208
|
+
const context = await this.storage.createStorage('endpointNumbers');
|
|
284
209
|
const separator = '|.|';
|
|
285
210
|
const endpointMap = new Map(await context.get('endpointMap', []));
|
|
286
211
|
for (const device of this.matterbridge.getDevices().filter((d) => d.plugin === this.name)) {
|
|
@@ -297,22 +222,22 @@ export class MatterbridgePlatform {
|
|
|
297
222
|
endpointMap.set(device.uniqueId, device.maybeNumber);
|
|
298
223
|
}
|
|
299
224
|
for (const child of device.getChildEndpoints()) {
|
|
300
|
-
|
|
301
|
-
if (!childId || !child.maybeNumber)
|
|
225
|
+
if (!child.maybeId || !child.maybeNumber)
|
|
302
226
|
continue;
|
|
303
|
-
if (endpointMap.has(device.uniqueId + separator +
|
|
304
|
-
this.log.warn(`Child endpoint number for device ${CYAN}${device.deviceName}${wr}.${CYAN}${
|
|
305
|
-
endpointMap.set(device.uniqueId + separator +
|
|
227
|
+
if (endpointMap.has(device.uniqueId + separator + child.id) && endpointMap.get(device.uniqueId + separator + child.id) !== child.maybeNumber) {
|
|
228
|
+
this.log.warn(`Child endpoint number for device ${CYAN}${device.deviceName}${wr}.${CYAN}${child.id}${wr} changed from ${CYAN}${endpointMap.get(device.uniqueId + separator + child.id)}${wr} to ${CYAN}${child.maybeNumber}${wr}`);
|
|
229
|
+
endpointMap.set(device.uniqueId + separator + child.id, child.maybeNumber);
|
|
306
230
|
}
|
|
307
|
-
if (!endpointMap.has(device.uniqueId + separator +
|
|
308
|
-
this.log.debug(`Setting child endpoint number for device ${CYAN}${device.uniqueId}${db}.${CYAN}${
|
|
309
|
-
endpointMap.set(device.uniqueId + separator +
|
|
231
|
+
if (!endpointMap.has(device.uniqueId + separator + child.id)) {
|
|
232
|
+
this.log.debug(`Setting child endpoint number for device ${CYAN}${device.uniqueId}${db}.${CYAN}${child.id}${db} to ${CYAN}${child.maybeNumber}${db}`);
|
|
233
|
+
endpointMap.set(device.uniqueId + separator + child.id, child.maybeNumber);
|
|
310
234
|
}
|
|
311
235
|
}
|
|
312
236
|
}
|
|
237
|
+
this.log.debug('Saving endpointNumbers...');
|
|
313
238
|
await context.set('endpointMap', Array.from(endpointMap.entries()));
|
|
239
|
+
await context.close();
|
|
314
240
|
this.log.debug('Endpoint numbers check completed.');
|
|
315
241
|
return endpointMap.size;
|
|
316
242
|
}
|
|
317
243
|
}
|
|
318
|
-
//# sourceMappingURL=matterbridgePlatform.js.map
|
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the types for Matterbridge.
|
|
3
|
-
*
|
|
4
|
-
* @file matterbridgeTypes.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2024-07-12
|
|
7
|
-
* @version 1.0.2
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2023, 2024, 2025 Luca Liguori.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License. *
|
|
22
|
-
*/
|
|
23
|
-
// Default colors
|
|
24
1
|
export const plg = '\u001B[38;5;33m';
|
|
25
2
|
export const dev = '\u001B[38;5;79m';
|
|
26
3
|
export const typ = '\u001B[38;5;207m';
|
|
27
|
-
//# sourceMappingURL=matterbridgeTypes.js.map
|