matterbridge 2.1.1 → 2.1.2-dev.3
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/dist/cli.js +0 -26
- package/dist/cluster/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -23
- package/dist/deviceManager.js +3 -29
- package/dist/frontend.js +51 -245
- 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 +1 -2
- package/dist/matter/types.js +0 -2
- package/dist/matterbridge.js +38 -752
- 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 +0 -96
- package/dist/matterbridgePlatform.js +9 -129
- package/dist/matterbridgeTypes.js +0 -24
- package/dist/pluginManager.js +5 -243
- 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 -251
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -2
- 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 -46
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/frontend.d.ts +0 -109
- 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 -4
- 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 -834
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -2262
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -164
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -165
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.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 +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 -221
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/utils.js.map +0 -1
|
@@ -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';
|
|
@@ -96,7 +90,6 @@ export function createUniqueId(param1, param2, param3, param4) {
|
|
|
96
90
|
return hash.digest('hex');
|
|
97
91
|
}
|
|
98
92
|
export function getBehaviourTypesFromClusterServerIds(clusterServerList) {
|
|
99
|
-
// Map Server ClusterId to Behavior.Type
|
|
100
93
|
const behaviorTypes = [];
|
|
101
94
|
clusterServerList.forEach((clusterId) => {
|
|
102
95
|
behaviorTypes.push(getBehaviourTypeFromClusterServerId(clusterId));
|
|
@@ -104,15 +97,12 @@ export function getBehaviourTypesFromClusterServerIds(clusterServerList) {
|
|
|
104
97
|
return behaviorTypes;
|
|
105
98
|
}
|
|
106
99
|
export function getBehaviourTypesFromClusterClientIds(clusterClientList) {
|
|
107
|
-
// Map Client ClusterId to Behavior.Type
|
|
108
100
|
const behaviorTypes = [];
|
|
109
101
|
clusterClientList.forEach((clusterId) => {
|
|
110
|
-
// behaviorTypes.push(getBehaviourTypeFromClusterClientId(clusterId));
|
|
111
102
|
});
|
|
112
103
|
return behaviorTypes;
|
|
113
104
|
}
|
|
114
105
|
export function getBehaviourTypeFromClusterServerId(clusterId) {
|
|
115
|
-
// Map ClusterId to Server Behavior.Type
|
|
116
106
|
if (clusterId === PowerSource.Cluster.id)
|
|
117
107
|
return PowerSourceServer.with(PowerSource.Feature.Wired);
|
|
118
108
|
if (clusterId === UserLabel.Cluster.id)
|
|
@@ -198,8 +188,6 @@ export function getBehaviourTypeFromClusterServerId(clusterId) {
|
|
|
198
188
|
return MatterbridgeIdentifyServer;
|
|
199
189
|
}
|
|
200
190
|
export function getBehaviourTypeFromClusterClientId(clusterId) {
|
|
201
|
-
// Map ClusterId to Client Behavior.Type
|
|
202
|
-
// return IdentifyClient;
|
|
203
191
|
}
|
|
204
192
|
export function getBehavior(endpoint, cluster) {
|
|
205
193
|
let behavior;
|
|
@@ -245,13 +233,6 @@ export function addOptionalClusterServers(endpoint) {
|
|
|
245
233
|
});
|
|
246
234
|
addClusterServers(endpoint, optionalServerList);
|
|
247
235
|
}
|
|
248
|
-
/**
|
|
249
|
-
* Adds cluster servers to the specified endpoint based on the provided server list.
|
|
250
|
-
*
|
|
251
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
|
|
252
|
-
* @param {ClusterId[]} serverList - The list of cluster IDs to add.
|
|
253
|
-
* @returns void
|
|
254
|
-
*/
|
|
255
236
|
export function addClusterServers(endpoint, serverList) {
|
|
256
237
|
if (serverList.includes(PowerSource.Cluster.id))
|
|
257
238
|
endpoint.createDefaultPowerSourceWiredClusterServer();
|
|
@@ -325,16 +306,7 @@ export function addClusterServers(endpoint, serverList) {
|
|
|
325
306
|
endpoint.createDefaultRadonConcentrationMeasurementClusterServer();
|
|
326
307
|
if (serverList.includes(TotalVolatileOrganicCompoundsConcentrationMeasurement.Cluster.id))
|
|
327
308
|
endpoint.createDefaultTvocMeasurementClusterServer();
|
|
328
|
-
// if (serverList.includes(DeviceEnergyManagement.Cluster.id)) endpoint.createDefaultDeviceEnergyManagementClusterServer();
|
|
329
|
-
// if (serverList.includes(DeviceEnergyManagementMode.Cluster.id)) endpoint.createDefaultDeviceEnergyManagementModeClusterServer();
|
|
330
309
|
}
|
|
331
|
-
/**
|
|
332
|
-
* Adds a fixed label to the FixedLabel cluster. The FixedLabel cluster is created if it does not exist.
|
|
333
|
-
*
|
|
334
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
|
|
335
|
-
* @param {string} label - The label to add.
|
|
336
|
-
* @param {string} value - The value of the label.
|
|
337
|
-
*/
|
|
338
310
|
export async function addFixedLabel(endpoint, label, value) {
|
|
339
311
|
if (!endpoint.hasClusterServer(FixedLabel.Cluster.id)) {
|
|
340
312
|
endpoint.log.debug(`addFixedLabel: add cluster ${hk}FixedLabel${db}:${hk}fixedLabel${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
|
|
@@ -351,13 +323,6 @@ export async function addFixedLabel(endpoint, label, value) {
|
|
|
351
323
|
await endpoint.setAttribute(FixedLabel.Cluster.id, 'labelList', labelList, endpoint.log);
|
|
352
324
|
}
|
|
353
325
|
}
|
|
354
|
-
/**
|
|
355
|
-
* Adds a user label to the UserLabel cluster. The UserLabel cluster is created if it does not exist.
|
|
356
|
-
*
|
|
357
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
|
|
358
|
-
* @param {string} label - The label to add.
|
|
359
|
-
* @param {string} value - The value of the label.
|
|
360
|
-
*/
|
|
361
326
|
export async function addUserLabel(endpoint, label, value) {
|
|
362
327
|
if (!endpoint.hasClusterServer(UserLabel.Cluster.id)) {
|
|
363
328
|
endpoint.log.debug(`addUserLabel: add cluster ${hk}UserLabel${db}:${hk}userLabel${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
|
|
@@ -421,16 +386,6 @@ export function getAttributeId(endpoint, cluster, attribute) {
|
|
|
421
386
|
return endpoint.behaviors.supported[lowercaseFirstLetter(cluster)]?.schema?.children?.find((child) => child.name === capitalizeFirstLetter(attribute))?.id;
|
|
422
387
|
}
|
|
423
388
|
}
|
|
424
|
-
/**
|
|
425
|
-
* Retrieves the value of the provided attribute from the given cluster.
|
|
426
|
-
*
|
|
427
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to retrieve the attribute from.
|
|
428
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to retrieve the attribute from.
|
|
429
|
-
* @param {string} attribute - The name of the attribute to retrieve.
|
|
430
|
-
* @param {AnsiLogger} [log] - (Optional) The logger to use for logging the retrieve. Errors are logged to the endpoint logger.
|
|
431
|
-
* @returns {any} The value of the attribute, or undefined if the attribute is not found.
|
|
432
|
-
*/
|
|
433
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
434
389
|
export function getAttribute(endpoint, cluster, attribute, log) {
|
|
435
390
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
436
391
|
if (!clusterName) {
|
|
@@ -453,16 +408,6 @@ export function getAttribute(endpoint, cluster, attribute, log) {
|
|
|
453
408
|
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}`);
|
|
454
409
|
return value;
|
|
455
410
|
}
|
|
456
|
-
/**
|
|
457
|
-
* Sets the value of an attribute on a cluster server.
|
|
458
|
-
*
|
|
459
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to set the attribute on.
|
|
460
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to set the attribute on.
|
|
461
|
-
* @param {string} attribute - The name of the attribute.
|
|
462
|
-
* @param {boolean | number | bigint | string | object | null} value - The value to set for the attribute.
|
|
463
|
-
* @param {AnsiLogger} [log] - (Optional) The logger to use for logging the set. Errors are logged to the endpoint logger.
|
|
464
|
-
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
|
|
465
|
-
*/
|
|
466
411
|
export async function setAttribute(endpoint, cluster, attribute, value, log) {
|
|
467
412
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
468
413
|
if (!clusterName) {
|
|
@@ -488,16 +433,6 @@ export async function setAttribute(endpoint, cluster, attribute, value, log) {
|
|
|
488
433
|
`to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
|
|
489
434
|
return true;
|
|
490
435
|
}
|
|
491
|
-
/**
|
|
492
|
-
* Sets the value of an attribute on a cluster server.
|
|
493
|
-
*
|
|
494
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to update the attribute on.
|
|
495
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to update the attribute on.
|
|
496
|
-
* @param {string} attribute - The name of the attribute.
|
|
497
|
-
* @param {boolean | number | bigint | string | object | null} value - The value to set for the attribute.
|
|
498
|
-
* @param {AnsiLogger} [log] - (Optional) The logger to use for logging the update. Errors are logged to the endpoint logger.
|
|
499
|
-
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
|
|
500
|
-
*/
|
|
501
436
|
export async function updateAttribute(endpoint, cluster, attribute, value, log) {
|
|
502
437
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
503
438
|
if (!clusterName) {
|
|
@@ -528,11 +463,6 @@ export async function updateAttribute(endpoint, cluster, attribute, value, log)
|
|
|
528
463
|
`to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
|
|
529
464
|
return true;
|
|
530
465
|
}
|
|
531
|
-
/**
|
|
532
|
-
* Get the default TemperatureMeasurement cluster server options.
|
|
533
|
-
*
|
|
534
|
-
* @param {number} measuredValue - The measured value of the temperature x 100.
|
|
535
|
-
*/
|
|
536
466
|
export function getDefaultTemperatureMeasurementClusterServer(measuredValue = 0) {
|
|
537
467
|
return optionsFor(TemperatureMeasurementServer, {
|
|
538
468
|
measuredValue,
|
|
@@ -541,11 +471,6 @@ export function getDefaultTemperatureMeasurementClusterServer(measuredValue = 0)
|
|
|
541
471
|
tolerance: 0,
|
|
542
472
|
});
|
|
543
473
|
}
|
|
544
|
-
/**
|
|
545
|
-
* Get the default RelativeHumidityMeasurement cluster server options.
|
|
546
|
-
*
|
|
547
|
-
* @param {number} measuredValue - The measured value of the relative humidity x 100.
|
|
548
|
-
*/
|
|
549
474
|
export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue = 0) {
|
|
550
475
|
return optionsFor(RelativeHumidityMeasurementServer, {
|
|
551
476
|
measuredValue,
|
|
@@ -554,11 +479,6 @@ export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue
|
|
|
554
479
|
tolerance: 0,
|
|
555
480
|
});
|
|
556
481
|
}
|
|
557
|
-
/**
|
|
558
|
-
* Get the default PressureMeasurement cluster server options.
|
|
559
|
-
*
|
|
560
|
-
* @param {number} measuredValue - The measured value for the pressure.
|
|
561
|
-
*/
|
|
562
482
|
export function getDefaultPressureMeasurementClusterServer(measuredValue = 1000) {
|
|
563
483
|
return optionsFor(PressureMeasurementServer, {
|
|
564
484
|
measuredValue,
|
|
@@ -567,11 +487,6 @@ export function getDefaultPressureMeasurementClusterServer(measuredValue = 1000)
|
|
|
567
487
|
tolerance: 0,
|
|
568
488
|
});
|
|
569
489
|
}
|
|
570
|
-
/**
|
|
571
|
-
* Get the default IlluminanceMeasurement cluster server options.
|
|
572
|
-
*
|
|
573
|
-
* @param {number} measuredValue - The measured value of illuminance.
|
|
574
|
-
*/
|
|
575
490
|
export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = 0) {
|
|
576
491
|
return optionsFor(IlluminanceMeasurementServer, {
|
|
577
492
|
measuredValue,
|
|
@@ -580,11 +495,6 @@ export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = 0)
|
|
|
580
495
|
tolerance: 0,
|
|
581
496
|
});
|
|
582
497
|
}
|
|
583
|
-
/**
|
|
584
|
-
* Get the default FlowMeasurement cluster server options.
|
|
585
|
-
*
|
|
586
|
-
* @param {number} measuredValue - The measured value of the flow in 10 x m3/h.
|
|
587
|
-
*/
|
|
588
498
|
export function getDefaultFlowMeasurementClusterServer(measuredValue = 0) {
|
|
589
499
|
return optionsFor(FlowMeasurementServer, {
|
|
590
500
|
measuredValue,
|
|
@@ -593,11 +503,6 @@ export function getDefaultFlowMeasurementClusterServer(measuredValue = 0) {
|
|
|
593
503
|
tolerance: 0,
|
|
594
504
|
});
|
|
595
505
|
}
|
|
596
|
-
/**
|
|
597
|
-
* Get the default OccupancySensing cluster server options.
|
|
598
|
-
*
|
|
599
|
-
* @param {boolean} occupied - A boolean indicating whether the occupancy is occupied or not. Default is false.
|
|
600
|
-
*/
|
|
601
506
|
export function getDefaultOccupancySensingClusterServer(occupied = false) {
|
|
602
507
|
return optionsFor(OccupancySensingServer, {
|
|
603
508
|
occupancy: { occupied },
|
|
@@ -606,4 +511,3 @@ export function getDefaultOccupancySensingClusterServer(occupied = false) {
|
|
|
606
511
|
pirOccupiedToUnoccupiedDelay: 30,
|
|
607
512
|
});
|
|
608
513
|
}
|
|
609
|
-
//# sourceMappingURL=matterbridgeEndpointHelpers.js.map
|
|
@@ -1,59 +1,23 @@
|
|
|
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 { isValidArray, isValidObject, isValidString } from './utils/utils.js';
|
|
24
|
-
// AnsiLogger module
|
|
25
2
|
import { CYAN, db, nf, wr } from './logger/export.js';
|
|
26
|
-
// Storage module
|
|
27
3
|
import { NodeStorageManager } from './storage/export.js';
|
|
28
|
-
// Node.js module
|
|
29
4
|
import path from 'path';
|
|
30
|
-
/**
|
|
31
|
-
* Represents the base Matterbridge platform.
|
|
32
|
-
*
|
|
33
|
-
*/
|
|
34
5
|
export class MatterbridgePlatform {
|
|
35
6
|
matterbridge;
|
|
36
7
|
log;
|
|
37
8
|
config = {};
|
|
38
|
-
name = '';
|
|
39
|
-
type = '';
|
|
40
|
-
version = '1.0.0';
|
|
9
|
+
name = '';
|
|
10
|
+
type = '';
|
|
11
|
+
version = '1.0.0';
|
|
41
12
|
storage;
|
|
42
13
|
context;
|
|
43
14
|
selectDevice = new Map();
|
|
44
15
|
selectEntity = new Map();
|
|
45
16
|
registeredEndpoints = new Map();
|
|
46
|
-
/**
|
|
47
|
-
* Creates an instance of the base MatterbridgePlatform.
|
|
48
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
49
|
-
* @param {AnsiLogger} log - The logger instance.
|
|
50
|
-
* @param {PlatformConfig} config - The platform configuration.
|
|
51
|
-
*/
|
|
52
17
|
constructor(matterbridge, log, config) {
|
|
53
18
|
this.matterbridge = matterbridge;
|
|
54
19
|
this.log = log;
|
|
55
20
|
this.config = config;
|
|
56
|
-
// create the NodeStorageManager for the plugin platform
|
|
57
21
|
if (!isValidString(this.config.name))
|
|
58
22
|
return;
|
|
59
23
|
this.log.debug(`Creating storage for plugin ${this.config.name} in ${path.join(this.matterbridge.matterbridgeDirectory, this.config.name)}`);
|
|
@@ -65,74 +29,36 @@ export class MatterbridgePlatform {
|
|
|
65
29
|
forgiveParseErrors: true,
|
|
66
30
|
});
|
|
67
31
|
}
|
|
68
|
-
/**
|
|
69
|
-
* This method must be overridden in the extended class.
|
|
70
|
-
* It is called when the platform is started.
|
|
71
|
-
* Use this method to create the MatterbridgeDevice and call this.registerDevice().
|
|
72
|
-
* @param {string} [reason] - The reason for starting.
|
|
73
|
-
* @throws {Error} - Throws an error if the method is not overridden.
|
|
74
|
-
*/
|
|
75
32
|
async onStart(reason) {
|
|
76
33
|
this.log.error('Plugins must override onStart.', reason);
|
|
77
34
|
throw new Error('Plugins must override onStart.');
|
|
78
35
|
}
|
|
79
|
-
/**
|
|
80
|
-
* This method can be overridden in the extended class.
|
|
81
|
-
* It is called after the platform has been commissioned.
|
|
82
|
-
* Use this method to perform any configuration of your devices.
|
|
83
|
-
*/
|
|
84
36
|
async onConfigure() {
|
|
85
37
|
this.log.debug(`Configuring platform ${this.name}`);
|
|
86
38
|
await this.checkEndpointNumbers();
|
|
87
39
|
}
|
|
88
|
-
/**
|
|
89
|
-
* This method can be overridden in the extended class.
|
|
90
|
-
* It is called when the platform is shutting down.
|
|
91
|
-
* Use this method to clean up any resources.
|
|
92
|
-
* @param {string} [reason] - The reason for shutting down.
|
|
93
|
-
*/
|
|
94
40
|
async onShutdown(reason) {
|
|
95
41
|
this.log.debug(`Shutting down platform ${this.name}`, reason);
|
|
96
42
|
await this.checkEndpointNumbers();
|
|
97
43
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Sets the logger level and logs a debug message indicating that the plugin doesn't override this method.
|
|
100
|
-
* @param {LogLevel} logLevel The new logger level.
|
|
101
|
-
*/
|
|
102
44
|
async onChangeLoggerLevel(logLevel) {
|
|
103
45
|
this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
|
|
104
46
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Registers a device with the Matterbridge platform.
|
|
107
|
-
* @param {MatterbridgeEndpoint} device - The device to register.
|
|
108
|
-
*/
|
|
109
47
|
async registerDevice(device) {
|
|
110
48
|
device.plugin = this.name;
|
|
111
49
|
await this.matterbridge.addBridgedEndpoint(this.name, device);
|
|
112
50
|
if (device.uniqueId)
|
|
113
51
|
this.registeredEndpoints.set(device.uniqueId, device);
|
|
114
52
|
}
|
|
115
|
-
/**
|
|
116
|
-
* Unregisters a device registered with the Matterbridge platform.
|
|
117
|
-
* @param {MatterbridgeEndpoint} device - The device to unregister.
|
|
118
|
-
*/
|
|
119
53
|
async unregisterDevice(device) {
|
|
120
54
|
await this.matterbridge.removeBridgedEndpoint(this.name, device);
|
|
121
55
|
if (device.uniqueId)
|
|
122
56
|
this.registeredEndpoints.delete(device.uniqueId);
|
|
123
57
|
}
|
|
124
|
-
/**
|
|
125
|
-
* Unregisters all devices registered with the Matterbridge platform.
|
|
126
|
-
*/
|
|
127
58
|
async unregisterAllDevices() {
|
|
128
59
|
await this.matterbridge.removeAllBridgedEndpoints(this.name);
|
|
129
60
|
this.registeredEndpoints.clear();
|
|
130
61
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Verifies if the Matterbridge version meets the required version.
|
|
133
|
-
* @param {string} requiredVersion - The required version to compare against.
|
|
134
|
-
* @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
|
|
135
|
-
*/
|
|
136
62
|
verifyMatterbridgeVersion(requiredVersion) {
|
|
137
63
|
const compareVersions = (matterbridgeVersion, requiredVersion) => {
|
|
138
64
|
const stripTag = (v) => {
|
|
@@ -157,28 +83,10 @@ export class MatterbridgePlatform {
|
|
|
157
83
|
return false;
|
|
158
84
|
return true;
|
|
159
85
|
}
|
|
160
|
-
/**
|
|
161
|
-
* Validates if a device is allowed based on the whitelist and blacklist configurations.
|
|
162
|
-
* The blacklist has priority over the whitelist.
|
|
163
|
-
*
|
|
164
|
-
* @param {string | string[]} device - The device name(s) to validate.
|
|
165
|
-
* @param {boolean} [log=true] - Whether to log the validation result.
|
|
166
|
-
* @returns {boolean} - Returns true if the device is allowed, false otherwise.
|
|
167
|
-
*/
|
|
168
|
-
validateDevice(device, log = true) {
|
|
169
|
-
return this.validateDeviceWhiteBlackList(device, log);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Validates if a device is allowed based on the whitelist and blacklist configurations.
|
|
173
|
-
* The blacklist has priority over the whitelist.
|
|
174
|
-
*
|
|
175
|
-
* @param {string | string[]} device - The device name(s) to validate.
|
|
176
|
-
* @param {boolean} [log=true] - Whether to log the validation result.
|
|
177
|
-
* @returns {boolean} - Returns true if the device is allowed, false otherwise.
|
|
178
|
-
*
|
|
179
|
-
* @deprecated This method is deprecated and will be removed in future versions. Use validateDevice instead.
|
|
180
|
-
*/
|
|
181
86
|
validateDeviceWhiteBlackList(device, log = true) {
|
|
87
|
+
return this.validateDevice(device, log);
|
|
88
|
+
}
|
|
89
|
+
validateDevice(device, log = true) {
|
|
182
90
|
if (!Array.isArray(device))
|
|
183
91
|
device = [device];
|
|
184
92
|
let blackListBlocked = 0;
|
|
@@ -207,28 +115,10 @@ export class MatterbridgePlatform {
|
|
|
207
115
|
this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
|
|
208
116
|
return false;
|
|
209
117
|
}
|
|
210
|
-
/**
|
|
211
|
-
* Validates if an entity is allowed based on the entity whitelist and blacklist and the device-entity blacklist configurations.
|
|
212
|
-
*
|
|
213
|
-
* @param {string} device - The device to which the entity belongs.
|
|
214
|
-
* @param {string} entity - The entity to validate.
|
|
215
|
-
* @param {boolean} [log=true] - Whether to log the validation result.
|
|
216
|
-
* @returns {boolean} - Returns true if the entity is allowed, false otherwise.
|
|
217
|
-
*/
|
|
218
|
-
validateEntity(device, entity, log = true) {
|
|
219
|
-
return this.validateEntityBlackList(device, entity, log);
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
|
|
223
|
-
*
|
|
224
|
-
* @param {string} device - The device to which the entity belongs.
|
|
225
|
-
* @param {string} entity - The entity to validate.
|
|
226
|
-
* @param {boolean} [log=true] - Whether to log the validation result.
|
|
227
|
-
* @returns {boolean} - Returns true if the entity is allowed, false otherwise.
|
|
228
|
-
*
|
|
229
|
-
* @deprecated This method is deprecated and will be removed in future versions. Use validateEntity instead.
|
|
230
|
-
*/
|
|
231
118
|
validateEntityBlackList(device, entity, log = true) {
|
|
119
|
+
return this.validateEntity(device, entity, log);
|
|
120
|
+
}
|
|
121
|
+
validateEntity(device, entity, log = true) {
|
|
232
122
|
if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
|
|
233
123
|
if (log)
|
|
234
124
|
this.log.info(`Skipping entity ${CYAN}${entity}${nf} because in entityBlackList`);
|
|
@@ -246,15 +136,6 @@ export class MatterbridgePlatform {
|
|
|
246
136
|
}
|
|
247
137
|
return true;
|
|
248
138
|
}
|
|
249
|
-
/**
|
|
250
|
-
* Checks and updates the endpoint numbers for Matterbridge devices.
|
|
251
|
-
*
|
|
252
|
-
* This method retrieves the list of Matterbridge devices and their child endpoints,
|
|
253
|
-
* compares their current endpoint numbers with the stored ones, and updates the storage
|
|
254
|
-
* if there are any changes. It logs the changes and updates the endpoint numbers accordingly.
|
|
255
|
-
*
|
|
256
|
-
* @returns {Promise<number>} The size of the updated endpoint map, or -1 if storage is not available.
|
|
257
|
-
*/
|
|
258
139
|
async checkEndpointNumbers() {
|
|
259
140
|
if (!this.storage)
|
|
260
141
|
return -1;
|
|
@@ -294,4 +175,3 @@ export class MatterbridgePlatform {
|
|
|
294
175
|
return endpointMap.size;
|
|
295
176
|
}
|
|
296
177
|
}
|
|
297
|
-
//# 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
|