matterbridge 2.2.6 → 2.2.8-dev.1
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 +42 -0
- package/README-DEV.md +24 -12
- package/dist/cli.js +2 -37
- package/dist/cluster/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -23
- package/dist/deviceManager.js +1 -94
- package/dist/frontend.js +24 -326
- package/dist/index.js +1 -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 +46 -747
- 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 +45 -696
- package/dist/matterbridgeEndpointHelpers.js +9 -118
- package/dist/matterbridgePlatform.js +12 -221
- package/dist/matterbridgeTypes.js +0 -24
- package/dist/pluginManager.js +104 -251
- package/dist/shelly.js +6 -146
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -45
- package/dist/utils/colorUtils.js +2 -205
- package/dist/utils/copyDirectory.js +1 -37
- package/dist/utils/createZip.js +2 -42
- package/dist/utils/deepCopy.js +0 -40
- package/dist/utils/deepEqual.js +1 -65
- package/dist/utils/export.js +0 -1
- package/dist/utils/isvalid.js +0 -86
- package/dist/utils/network.js +5 -76
- package/dist/utils/parameter.js +0 -41
- package/dist/utils/wait.js +5 -48
- package/frontend/build/asset-manifest.json +3 -3
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/js/{main.f00179ca.js → main.eb2f3e01.js} +3 -3
- package/frontend/build/static/js/{main.f00179ca.js.map → main.eb2f3e01.js.map} +1 -1
- package/npm-shrinkwrap.json +2 -9
- package/package.json +1 -3
- package/dist/cli.d.ts +0 -29
- 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 -221
- 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 -425
- 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 -285
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -179
- 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/shelly.d.ts +0 -92
- package/dist/shelly.d.ts.map +0 -1
- package/dist/shelly.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/update.d.ts +0 -32
- package/dist/update.d.ts.map +0 -1
- package/dist/update.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/copyDirectory.d.ts +0 -32
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -38
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -31
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -53
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/export.d.ts +0 -10
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -87
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/network.d.ts +0 -69
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/parameter.d.ts +0 -44
- package/dist/utils/parameter.d.ts.map +0 -1
- package/dist/utils/parameter.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -43
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
- /package/frontend/build/static/js/{main.f00179ca.js.LICENSE.txt → main.eb2f3e01.js.LICENSE.txt} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -29,6 +29,48 @@ Features:
|
|
|
29
29
|
- It is possible to choose the method: GET or POST.
|
|
30
30
|
- The webhook can be tested directly in the frontend.
|
|
31
31
|
|
|
32
|
+
## [2.2.8] - 2025-04-09
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
|
|
36
|
+
- [platform]: Added stack to errors messages.
|
|
37
|
+
- [endpoint]: Added createLevelTvocMeasurementClusterServer()
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- [package]: Update dependencies.
|
|
42
|
+
- [package]: Use node:https.
|
|
43
|
+
|
|
44
|
+
### Fixed
|
|
45
|
+
|
|
46
|
+
- [homepage]: Fixed warning log for homepage property in package.json.
|
|
47
|
+
- [DevicesIcon]: Fixed rendering of rain, freeze and leak sensors.
|
|
48
|
+
|
|
49
|
+
<a href="https://www.buymeacoffee.com/luligugithub">
|
|
50
|
+
<img src="bmc-button.svg" alt="Buy me a coffee" width="80">
|
|
51
|
+
</a>
|
|
52
|
+
|
|
53
|
+
## [2.2.7] - 2025-04-06
|
|
54
|
+
|
|
55
|
+
### Added
|
|
56
|
+
|
|
57
|
+
- [package]: Process author, homepage, repository, funding, README.md and CHANGELOG.md for third-party plugins. If the default implementation doesn't fit, it is possible to add a custom property "help" and "changelog" to the package.json.
|
|
58
|
+
- [frontend]: Added a link the plugin homepage (click on the plugin name or on the plugin description).
|
|
59
|
+
|
|
60
|
+
### Changed
|
|
61
|
+
|
|
62
|
+
- [frontend]: Frontend v.2.6.1.
|
|
63
|
+
- [package]: Update dependencies.
|
|
64
|
+
|
|
65
|
+
### Fixed
|
|
66
|
+
|
|
67
|
+
- [author]: Fixed case when author is an object in the package.json.
|
|
68
|
+
- [platform]: Fix getSelectDevices and getSelectEntities on node < 22.
|
|
69
|
+
|
|
70
|
+
<a href="https://www.buymeacoffee.com/luligugithub">
|
|
71
|
+
<img src="bmc-button.svg" alt="Buy me a coffee" width="80">
|
|
72
|
+
</a>
|
|
73
|
+
|
|
32
74
|
## [2.2.6] - 2025-04-01
|
|
33
75
|
|
|
34
76
|
### Added
|
package/README-DEV.md
CHANGED
|
@@ -21,11 +21,30 @@ Matterbridge exports from:
|
|
|
21
21
|
"matterbridge"
|
|
22
22
|
|
|
23
23
|
- Matterbridge and all Matterbridge related classes.
|
|
24
|
-
- All relevant matter-node.js or matter.js clusters, classes and functions.
|
|
25
24
|
|
|
26
25
|
"matterbridge/matter"
|
|
27
26
|
|
|
28
|
-
- All relevant matter.js
|
|
27
|
+
- All relevant matter.js exports.
|
|
28
|
+
|
|
29
|
+
"matterbridge/matter/behaviors"
|
|
30
|
+
|
|
31
|
+
- All matter.js behaviors.
|
|
32
|
+
|
|
33
|
+
"matterbridge/matter/clusters"
|
|
34
|
+
|
|
35
|
+
- All matter.js clusters.
|
|
36
|
+
|
|
37
|
+
"matterbridge/matter/devices"
|
|
38
|
+
|
|
39
|
+
- All matter.js devices.
|
|
40
|
+
|
|
41
|
+
"matterbridge/matter/endpoints"
|
|
42
|
+
|
|
43
|
+
- All matter.js endpoints.
|
|
44
|
+
|
|
45
|
+
"matterbridge/matter/types"
|
|
46
|
+
|
|
47
|
+
- All matter.js types.
|
|
29
48
|
|
|
30
49
|
"matterbridge/cluster"
|
|
31
50
|
|
|
@@ -67,15 +86,6 @@ Matterbridge must be linked to the plugin in development only.
|
|
|
67
86
|
|
|
68
87
|
I added some error messages when a plugin has wrong imports or configurations and the plugin will be disabled to prevent instability and crashes.
|
|
69
88
|
|
|
70
|
-
## Migration to matter.js V8
|
|
71
|
-
|
|
72
|
-
I'm working with matter.js team to define the strategy for the migration of Matterbridge to the new API.
|
|
73
|
-
|
|
74
|
-
- First phase: create MatterbridgeEdge class: completed 95%
|
|
75
|
-
- Second phase: create MatterbridgeEndpoint and MatterbridgeBehaviors classes: completed 95%
|
|
76
|
-
- Third phase: modifiy all plugins to support both normal and edge mode of Matterbridge: completed 90%
|
|
77
|
-
- Fourth phase: remove all old api code from Matterbridge and all plugins...
|
|
78
|
-
|
|
79
89
|
## How to create your plugin
|
|
80
90
|
|
|
81
91
|
The easiest way is to clone:
|
|
@@ -84,7 +94,9 @@ The easiest way is to clone:
|
|
|
84
94
|
|
|
85
95
|
- https://github.com/Luligu/matterbridge-example-dynamic-platform if you want to create a Dynamic Platform Plugin.
|
|
86
96
|
|
|
87
|
-
Then change the name (keep matterbridge- at the beginning of the name), version, description and
|
|
97
|
+
Then change the name (keep matterbridge- at the beginning of the name), version, description, author and funding in the package.json.
|
|
98
|
+
|
|
99
|
+
It is possible to add these custom properties to the package.json: help and changelog with a url that will be used in the frontend instead of the default (/blob/main/README.md and /blob/main/CHANGELOG.md).
|
|
88
100
|
|
|
89
101
|
Add your plugin logic in platform.ts.
|
|
90
102
|
|
package/dist/cli.js
CHANGED
|
@@ -1,43 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* This file contains the CLI entry point of Matterbridge.
|
|
4
|
-
*
|
|
5
|
-
* @file cli.ts
|
|
6
|
-
* @author Luca Liguori
|
|
7
|
-
* @date 2023-12-29
|
|
8
|
-
* @version 2.0.0
|
|
9
|
-
*
|
|
10
|
-
* Copyright 2023, 2024, 2025 Luca Liguori.
|
|
11
|
-
*
|
|
12
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License.
|
|
14
|
-
* You may obtain a copy of the License at
|
|
15
|
-
*
|
|
16
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
-
* See the License for the specific language governing permissions and
|
|
22
|
-
* limitations under the License. *
|
|
23
|
-
*/
|
|
24
|
-
// Matterbridge
|
|
25
2
|
import { Matterbridge } from './matterbridge.js';
|
|
26
3
|
import { getIntParameter, hasParameter } from './utils/export.js';
|
|
27
|
-
// AnsiLogger module
|
|
28
4
|
import { AnsiLogger, BRIGHT, CYAN, db, YELLOW } from './logger/export.js';
|
|
29
5
|
import { EventEmitter } from 'node:events';
|
|
30
6
|
export const cliEmitter = new EventEmitter();
|
|
31
7
|
export let instance;
|
|
32
|
-
// Inspectop
|
|
33
8
|
let session;
|
|
34
|
-
// Cpu and memory check
|
|
35
9
|
let memoryCheckInterval;
|
|
36
10
|
let prevCpus;
|
|
37
11
|
export let lastCpuUsage = 0;
|
|
38
12
|
let peakCpu = 0;
|
|
39
13
|
let peakRss = 0;
|
|
40
|
-
const log = new AnsiLogger({ logName: 'Cli', logTimestampFormat: 4
|
|
14
|
+
const log = new AnsiLogger({ logName: 'Cli', logTimestampFormat: 4, logLevel: hasParameter('debug') ? "debug" : "info" });
|
|
41
15
|
const formatMemoryUsage = (bytes) => {
|
|
42
16
|
if (bytes >= 1024 ** 3) {
|
|
43
17
|
return `${(bytes / 1024 ** 3).toFixed(2)} GB`;
|
|
@@ -70,11 +44,9 @@ async function startCpuMemoryCheck() {
|
|
|
70
44
|
prevCpus = os.cpus();
|
|
71
45
|
clearInterval(memoryCheckInterval);
|
|
72
46
|
const interval = () => {
|
|
73
|
-
// Get the os uptime
|
|
74
47
|
const systemUptime = formatOsUpTime(Math.floor(os.uptime()));
|
|
75
48
|
const processUptime = formatOsUpTime(Math.floor(process.uptime()));
|
|
76
49
|
cliEmitter.emit('uptime', systemUptime, processUptime);
|
|
77
|
-
// Get the memory usage
|
|
78
50
|
const totalMememory = formatMemoryUsage(os.totalmem());
|
|
79
51
|
const freeMemory = formatMemoryUsage(os.freemem());
|
|
80
52
|
const memoryUsageRaw = process.memoryUsage();
|
|
@@ -86,11 +58,10 @@ async function startCpuMemoryCheck() {
|
|
|
86
58
|
if (memoryUsageRaw.rss > peakRss)
|
|
87
59
|
peakRss = memoryUsageRaw.rss;
|
|
88
60
|
cliEmitter.emit('memory', totalMememory, freeMemory, rss, heapTotal, heapUsed, external, arrayBuffers);
|
|
89
|
-
// Get the cpu usage
|
|
90
61
|
const currCpus = os.cpus();
|
|
91
62
|
let cpuUsageLog;
|
|
92
63
|
if (currCpus.length !== prevCpus.length) {
|
|
93
|
-
prevCpus = currCpus;
|
|
64
|
+
prevCpus = currCpus;
|
|
94
65
|
log.debug(`Cpu check length failed, resetting previous cpus`);
|
|
95
66
|
return;
|
|
96
67
|
}
|
|
@@ -116,7 +87,6 @@ async function startCpuMemoryCheck() {
|
|
|
116
87
|
cliEmitter.emit('cpu', lastCpuUsage);
|
|
117
88
|
}
|
|
118
89
|
prevCpus = currCpus;
|
|
119
|
-
// Show the cpu and memory usage
|
|
120
90
|
log.debug(`***${YELLOW}${BRIGHT}Cpu usage:${db} ${CYAN}${cpuUsageLog.padStart(6, ' ')} %${db} ${YELLOW}${BRIGHT}Memory usage:${db} rss ${CYAN}${rss}${db} heapTotal ${CYAN}${heapTotal}${db} heapUsed ${CYAN}${heapUsed}${db} external ${external} arrayBuffers ${arrayBuffers}`);
|
|
121
91
|
};
|
|
122
92
|
interval();
|
|
@@ -144,7 +114,6 @@ async function stopInspector() {
|
|
|
144
114
|
return;
|
|
145
115
|
}
|
|
146
116
|
try {
|
|
147
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
148
117
|
const result = await new Promise((resolve, reject) => {
|
|
149
118
|
session?.post('HeapProfiler.stopSampling', (err, result) => (err ? reject(err) : resolve(result)));
|
|
150
119
|
});
|
|
@@ -189,7 +158,6 @@ async function restart() {
|
|
|
189
158
|
}
|
|
190
159
|
async function update() {
|
|
191
160
|
log.debug('Received update event, updating...');
|
|
192
|
-
// TODO: Implement update logic outside of matterbridge
|
|
193
161
|
instance = await Matterbridge.loadInstance(true);
|
|
194
162
|
registerHandlers();
|
|
195
163
|
}
|
|
@@ -209,7 +177,6 @@ async function main() {
|
|
|
209
177
|
log.debug(`***Matterbridge.loadInstance(true) called`);
|
|
210
178
|
instance = await Matterbridge.loadInstance(true);
|
|
211
179
|
log.debug(`***Matterbridge.loadInstance(true) exited`);
|
|
212
|
-
// Check if the instance needs to shut down from parseCommandLine()
|
|
213
180
|
if (!instance || instance.shutdown) {
|
|
214
181
|
shutdown();
|
|
215
182
|
}
|
|
@@ -217,9 +184,7 @@ async function main() {
|
|
|
217
184
|
registerHandlers();
|
|
218
185
|
}
|
|
219
186
|
}
|
|
220
|
-
// Run the main function
|
|
221
187
|
process.title = 'matterbridge';
|
|
222
188
|
main().catch((error) => {
|
|
223
189
|
log.error(`Matterbridge.loadInstance() failed with error: ${error instanceof Error ? error.message : error}`);
|
|
224
190
|
});
|
|
225
|
-
//# sourceMappingURL=cli.js.map
|
package/dist/cluster/export.js
CHANGED
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the default config for the plugins.
|
|
3
|
-
*
|
|
4
|
-
* @file defaultConfigSchema.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2024-05-07
|
|
7
|
-
* @version 1.0.1
|
|
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
|
export const zigbee2mqtt_config = {
|
|
24
2
|
name: 'matterbridge-zigbee2mqtt',
|
|
25
3
|
type: 'DynamicPlatform',
|
|
@@ -78,4 +56,3 @@ export const shelly_config = {
|
|
|
78
56
|
debugWs: false,
|
|
79
57
|
unregisterOnShutdown: false,
|
|
80
58
|
};
|
|
81
|
-
//# sourceMappingURL=defaultConfigSchema.js.map
|
package/dist/deviceManager.js
CHANGED
|
@@ -1,89 +1,28 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the DeviceManager class.
|
|
3
|
-
*
|
|
4
|
-
* @file devices.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2024-07-26
|
|
7
|
-
* @version 1.0.9
|
|
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
|
-
// AnsiLogger module
|
|
24
1
|
import { AnsiLogger, BLUE, er } from './logger/export.js';
|
|
25
2
|
import { dev } from './matterbridgeTypes.js';
|
|
26
|
-
/**
|
|
27
|
-
* Manages Matterbridge devices.
|
|
28
|
-
*/
|
|
29
3
|
export class DeviceManager {
|
|
30
4
|
_devices = new Map();
|
|
31
5
|
matterbridge;
|
|
32
6
|
nodeContext;
|
|
33
7
|
log;
|
|
34
|
-
/**
|
|
35
|
-
* Creates an instance of DeviceManager.
|
|
36
|
-
*
|
|
37
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
38
|
-
* @param {NodeStorage} nodeContext - The node storage context.
|
|
39
|
-
*/
|
|
40
8
|
constructor(matterbridge, nodeContext) {
|
|
41
9
|
this.matterbridge = matterbridge;
|
|
42
10
|
this.nodeContext = nodeContext;
|
|
43
|
-
this.log = new AnsiLogger({ logName: 'DeviceManager', logTimestampFormat: 4
|
|
11
|
+
this.log = new AnsiLogger({ logName: 'DeviceManager', logTimestampFormat: 4, logLevel: matterbridge.log.logLevel });
|
|
44
12
|
this.log.debug('Matterbridge device manager starting...');
|
|
45
13
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Gets the number of devices.
|
|
48
|
-
*
|
|
49
|
-
* @returns {number} The number of devices.
|
|
50
|
-
*/
|
|
51
14
|
get length() {
|
|
52
15
|
return this._devices.size;
|
|
53
16
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Gets the number of devices.
|
|
56
|
-
*
|
|
57
|
-
* @returns {number} The number of devices.
|
|
58
|
-
*/
|
|
59
17
|
get size() {
|
|
60
18
|
return this._devices.size;
|
|
61
19
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Checks if a device with the specified unique ID exists.
|
|
64
|
-
*
|
|
65
|
-
* @param {string} uniqueId - The unique ID of the device.
|
|
66
|
-
* @returns {boolean} True if the device exists, false otherwise.
|
|
67
|
-
*/
|
|
68
20
|
has(uniqueId) {
|
|
69
21
|
return this._devices.has(uniqueId);
|
|
70
22
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Gets a device by its unique ID.
|
|
73
|
-
*
|
|
74
|
-
* @param {string} uniqueId - The unique ID of the device.
|
|
75
|
-
* @returns {MatterbridgeEndpoint | undefined} The device, or undefined if not found.
|
|
76
|
-
*/
|
|
77
23
|
get(uniqueId) {
|
|
78
24
|
return this._devices.get(uniqueId);
|
|
79
25
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Adds a device to the manager.
|
|
82
|
-
*
|
|
83
|
-
* @param {MatterbridgeEndpoint} device - The device to add.
|
|
84
|
-
* @returns {MatterbridgeEndpoint} The added device.
|
|
85
|
-
* @throws {Error} If the device does not have a unique ID.
|
|
86
|
-
*/
|
|
87
26
|
set(device) {
|
|
88
27
|
if (!device.uniqueId)
|
|
89
28
|
throw new Error(`The device ${dev}${device.deviceName}${er} has not been initialized: uniqueId is required`);
|
|
@@ -92,13 +31,6 @@ export class DeviceManager {
|
|
|
92
31
|
this._devices.set(device.uniqueId, device);
|
|
93
32
|
return device;
|
|
94
33
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Removes a device from the manager.
|
|
97
|
-
*
|
|
98
|
-
* @param {MatterbridgeEndpoint} device - The device to remove.
|
|
99
|
-
* @returns {boolean} True if the device was removed, false otherwise.
|
|
100
|
-
* @throws {Error} If the device does not have a unique ID.
|
|
101
|
-
*/
|
|
102
34
|
remove(device) {
|
|
103
35
|
if (!device.uniqueId)
|
|
104
36
|
throw new Error(`The device ${dev}${device.deviceName}${er} has not been initialized: uniqueId is required`);
|
|
@@ -106,34 +38,15 @@ export class DeviceManager {
|
|
|
106
38
|
this.log.error(`The device ${dev}${device.deviceName}${er} with uniqueId ${BLUE}${device.uniqueId}${er} serialNumber ${BLUE}${device.serialNumber}${er} is not registered in the device manager`);
|
|
107
39
|
return this._devices.delete(device.uniqueId);
|
|
108
40
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Clears all devices from the manager.
|
|
111
|
-
*/
|
|
112
41
|
clear() {
|
|
113
42
|
this._devices.clear();
|
|
114
43
|
}
|
|
115
|
-
/**
|
|
116
|
-
* Gets an array of all devices.
|
|
117
|
-
*
|
|
118
|
-
* @returns {MatterbridgeEndpoint[]} An array of all devices.
|
|
119
|
-
*/
|
|
120
44
|
array() {
|
|
121
45
|
return Array.from(this._devices.values());
|
|
122
46
|
}
|
|
123
|
-
/**
|
|
124
|
-
* Iterates over all devices.
|
|
125
|
-
*
|
|
126
|
-
* @returns {IterableIterator<MatterbridgeEndpoint>} An iterator for the devices.
|
|
127
|
-
*/
|
|
128
47
|
[Symbol.iterator]() {
|
|
129
48
|
return this._devices.values();
|
|
130
49
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Asynchronously iterates over each device and calls the provided callback function.
|
|
133
|
-
*
|
|
134
|
-
* @param {Function} callback - The callback function to call with each device.
|
|
135
|
-
* @returns {Promise<void>} A promise that resolves when all callbacks have been called.
|
|
136
|
-
*/
|
|
137
50
|
async forEach(callback) {
|
|
138
51
|
if (this.size === 0)
|
|
139
52
|
return;
|
|
@@ -147,13 +60,7 @@ export class DeviceManager {
|
|
|
147
60
|
});
|
|
148
61
|
await Promise.all(tasks);
|
|
149
62
|
}
|
|
150
|
-
/**
|
|
151
|
-
* Sets the log level.
|
|
152
|
-
*
|
|
153
|
-
* @param {LogLevel} logLevel - The log level to set.
|
|
154
|
-
*/
|
|
155
63
|
set logLevel(logLevel) {
|
|
156
64
|
this.log.logLevel = logLevel;
|
|
157
65
|
}
|
|
158
66
|
}
|
|
159
|
-
//# sourceMappingURL=deviceManager.js.map
|