matterbridge 3.0.4 → 3.0.5-dev-20250528-9314890
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 +81 -52
- package/dist/cluster/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -23
- package/dist/deviceManager.js +1 -94
- package/dist/frontend.js +16 -363
- package/dist/helpers.js +0 -51
- package/dist/index.js +1 -27
- package/dist/laundryWasher.js +125 -0
- 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 +47 -747
- package/dist/matterbridgeAccessoryPlatform.js +0 -34
- package/dist/matterbridgeBehaviors.js +4 -63
- package/dist/matterbridgeDeviceTypes.js +15 -563
- package/dist/matterbridgeDynamicPlatform.js +0 -34
- package/dist/matterbridgeEndpoint.js +23 -903
- package/dist/matterbridgeEndpointHelpers.js +11 -173
- package/dist/matterbridgePlatform.js +7 -225
- package/dist/matterbridgeTypes.js +0 -24
- package/dist/pluginManager.js +3 -264
- package/dist/roboticVacuumCleaner.js +3 -78
- package/dist/shelly.js +7 -155
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -53
- package/dist/utils/colorUtils.js +2 -205
- package/dist/utils/commandLine.js +0 -53
- package/dist/utils/copyDirectory.js +1 -37
- package/dist/utils/createZip.js +2 -42
- package/dist/utils/deepCopy.js +0 -38
- package/dist/utils/deepEqual.js +1 -71
- package/dist/utils/export.js +0 -1
- package/dist/utils/hex.js +0 -57
- package/dist/utils/isvalid.js +0 -100
- package/dist/utils/network.js +5 -76
- package/dist/utils/wait.js +9 -58
- package/dist/waterHeater.js +0 -52
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -2
- 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 -256
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/helpers.d.ts +0 -47
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.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 -445
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -40
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1398
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -629
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -40
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1053
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -2749
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -294
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -196
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -273
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/roboticVacuumCleaner.d.ts +0 -82
- package/dist/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/roboticVacuumCleaner.js.map +0 -1
- package/dist/shelly.d.ts +0 -153
- 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 -58
- 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/commandLine.d.ts +0 -58
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.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 -11
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/hex.d.ts +0 -48
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -102
- 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/wait.d.ts +0 -52
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
- package/dist/waterHeater.d.ts +0 -75
- package/dist/waterHeater.d.ts.map +0 -1
- package/dist/waterHeater.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,23 @@ If you like this project and find it useful, please consider giving it a star on
|
|
|
8
8
|
<img src="bmc-button.svg" alt="Buy me a coffee" width="120">
|
|
9
9
|
</a>
|
|
10
10
|
|
|
11
|
+
## [3.0.5] - 2025-05-??
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- [cli]: Added takeHeapSnapshot() and triggerGarbageCollection().
|
|
16
|
+
- [LaundryWasher]: Add LaundryWasher class and Jest test.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- [selectAreas]: Fixed MatterbridgeServiceAreaServer.selectAreas.
|
|
23
|
+
|
|
24
|
+
<a href="https://www.buymeacoffee.com/luligugithub">
|
|
25
|
+
<img src="bmc-button.svg" alt="Buy me a coffee" width="80">
|
|
26
|
+
</a>
|
|
27
|
+
|
|
11
28
|
## [3.0.4] - 2025-05-26
|
|
12
29
|
|
|
13
30
|
### Added
|
package/dist/cli.js
CHANGED
|
@@ -1,44 +1,19 @@
|
|
|
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
|
import { inspect } from 'node:util';
|
|
31
7
|
export const cliEmitter = new EventEmitter();
|
|
32
8
|
export let instance;
|
|
33
|
-
// Inspectop
|
|
34
9
|
let session;
|
|
35
|
-
|
|
10
|
+
let snapshotInterval;
|
|
36
11
|
let memoryCheckInterval;
|
|
37
12
|
let prevCpus;
|
|
38
13
|
export let lastCpuUsage = 0;
|
|
39
14
|
let peakCpu = 0;
|
|
40
15
|
let peakRss = 0;
|
|
41
|
-
const log = new AnsiLogger({ logName: 'Cli', logTimestampFormat: 4
|
|
16
|
+
const log = new AnsiLogger({ logName: 'Cli', logTimestampFormat: 4, logLevel: hasParameter('debug') ? "debug" : "info" });
|
|
42
17
|
const formatMemoryUsage = (bytes) => {
|
|
43
18
|
if (bytes >= 1024 ** 3) {
|
|
44
19
|
return `${(bytes / 1024 ** 3).toFixed(2)} GB`;
|
|
@@ -71,11 +46,9 @@ async function startCpuMemoryCheck() {
|
|
|
71
46
|
prevCpus = os.cpus();
|
|
72
47
|
clearInterval(memoryCheckInterval);
|
|
73
48
|
const interval = () => {
|
|
74
|
-
// Get the os uptime
|
|
75
49
|
const systemUptime = formatOsUpTime(Math.floor(os.uptime()));
|
|
76
50
|
const processUptime = formatOsUpTime(Math.floor(process.uptime()));
|
|
77
51
|
cliEmitter.emit('uptime', systemUptime, processUptime);
|
|
78
|
-
// Get the memory usage
|
|
79
52
|
const totalMememory = formatMemoryUsage(os.totalmem());
|
|
80
53
|
const freeMemory = formatMemoryUsage(os.freemem());
|
|
81
54
|
const memoryUsageRaw = process.memoryUsage();
|
|
@@ -87,11 +60,10 @@ async function startCpuMemoryCheck() {
|
|
|
87
60
|
if (memoryUsageRaw.rss > peakRss)
|
|
88
61
|
peakRss = memoryUsageRaw.rss;
|
|
89
62
|
cliEmitter.emit('memory', totalMememory, freeMemory, rss, heapTotal, heapUsed, external, arrayBuffers);
|
|
90
|
-
// Get the cpu usage
|
|
91
63
|
const currCpus = os.cpus();
|
|
92
64
|
let cpuUsageLog;
|
|
93
65
|
if (currCpus.length !== prevCpus.length) {
|
|
94
|
-
prevCpus = currCpus;
|
|
66
|
+
prevCpus = currCpus;
|
|
95
67
|
log.debug(`Cpu check length failed, resetting previous cpus`);
|
|
96
68
|
return;
|
|
97
69
|
}
|
|
@@ -117,7 +89,6 @@ async function startCpuMemoryCheck() {
|
|
|
117
89
|
cliEmitter.emit('cpu', lastCpuUsage);
|
|
118
90
|
}
|
|
119
91
|
prevCpus = currCpus;
|
|
120
|
-
// Show the cpu and memory usage
|
|
121
92
|
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}`);
|
|
122
93
|
};
|
|
123
94
|
interval();
|
|
@@ -129,37 +100,99 @@ async function stopCpuMemoryCheck() {
|
|
|
129
100
|
}
|
|
130
101
|
async function startInspector() {
|
|
131
102
|
const { Session } = await import('node:inspector');
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
session
|
|
137
|
-
|
|
138
|
-
|
|
103
|
+
const { mkdirSync } = await import('node:fs');
|
|
104
|
+
log.debug(`***Starting heap sampling...`);
|
|
105
|
+
mkdirSync('heap_profile', { recursive: true });
|
|
106
|
+
try {
|
|
107
|
+
session = new Session();
|
|
108
|
+
session.connect();
|
|
109
|
+
await new Promise((resolve, reject) => {
|
|
110
|
+
session?.post('HeapProfiler.startSampling', (err) => (err ? reject(err) : resolve()));
|
|
111
|
+
});
|
|
112
|
+
log.debug(`***Started heap sampling`);
|
|
113
|
+
const interval = getIntParameter('snapshotinterval');
|
|
114
|
+
if (interval && interval >= 30000) {
|
|
115
|
+
log.debug(`***Started heap snapshot interval of ${CYAN}${interval}${db} ms`);
|
|
116
|
+
snapshotInterval = setInterval(async () => {
|
|
117
|
+
await takeHeapSnapshot();
|
|
118
|
+
}, interval);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
log.error(`***Failed to start heap sampling: ${err instanceof Error ? err.message : err}`);
|
|
123
|
+
session?.disconnect();
|
|
124
|
+
session = undefined;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
139
127
|
}
|
|
140
128
|
async function stopInspector() {
|
|
141
129
|
const { writeFileSync } = await import('node:fs');
|
|
142
|
-
|
|
130
|
+
const path = await import('node:path');
|
|
131
|
+
log.debug(`***Stopping heap sampling...`);
|
|
132
|
+
if (snapshotInterval) {
|
|
133
|
+
log.debug(`***Clearing heap snapshot interval...`);
|
|
134
|
+
clearInterval(snapshotInterval);
|
|
135
|
+
await takeHeapSnapshot();
|
|
136
|
+
}
|
|
143
137
|
if (!session) {
|
|
144
|
-
log.error('No active inspector session.');
|
|
138
|
+
log.error('***No active inspector session.');
|
|
145
139
|
return;
|
|
146
140
|
}
|
|
147
141
|
try {
|
|
148
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
149
142
|
const result = await new Promise((resolve, reject) => {
|
|
150
143
|
session?.post('HeapProfiler.stopSampling', (err, result) => (err ? reject(err) : resolve(result)));
|
|
151
144
|
});
|
|
152
145
|
const profile = JSON.stringify(result.profile);
|
|
153
|
-
|
|
154
|
-
|
|
146
|
+
const filename = path.join('heap_profile', `Heap-profile-${new Date().toISOString().replace(/[:]/g, '-')}.heapprofile`);
|
|
147
|
+
writeFileSync(filename, profile);
|
|
148
|
+
log.debug(`***Heap sampling profile saved to ${CYAN}${filename}${db}`);
|
|
155
149
|
}
|
|
156
150
|
catch (err) {
|
|
157
|
-
log.error(
|
|
151
|
+
log.error(`***Failed to stop heap sampling: ${err instanceof Error ? err.message : err}`);
|
|
158
152
|
}
|
|
159
153
|
finally {
|
|
160
154
|
session.disconnect();
|
|
161
155
|
session = undefined;
|
|
162
|
-
log.debug(
|
|
156
|
+
log.debug(`***Stopped heap sampling`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function takeHeapSnapshot() {
|
|
160
|
+
const { writeFileSync } = await import('node:fs');
|
|
161
|
+
const path = await import('node:path');
|
|
162
|
+
const filename = path.join('heap_profile', `Heap-snapshot-${new Date().toISOString().replace(/[:]/g, '-')}.heapsnapshot`);
|
|
163
|
+
if (!session) {
|
|
164
|
+
log.error('No active inspector session.');
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const chunks = [];
|
|
168
|
+
const chunksListener = (notification) => {
|
|
169
|
+
chunks.push(Buffer.from(notification.params.chunk));
|
|
170
|
+
};
|
|
171
|
+
session.on('HeapProfiler.addHeapSnapshotChunk', chunksListener);
|
|
172
|
+
await new Promise((resolve) => {
|
|
173
|
+
session?.post('HeapProfiler.takeHeapSnapshot', (err) => {
|
|
174
|
+
if (!err) {
|
|
175
|
+
session?.off('HeapProfiler.addHeapSnapshotChunk', chunksListener);
|
|
176
|
+
writeFileSync(filename, Buffer.concat(chunks));
|
|
177
|
+
log.debug(`***Heap sampling snapshot saved to ${CYAN}${filename}${db}`);
|
|
178
|
+
triggerGarbageCollection();
|
|
179
|
+
resolve();
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
session?.off('HeapProfiler.addHeapSnapshotChunk', chunksListener);
|
|
183
|
+
log.error(`***Failed to take heap snapshot: ${err instanceof Error ? err.message : err}`);
|
|
184
|
+
resolve();
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function triggerGarbageCollection() {
|
|
190
|
+
if (typeof global.gc === 'function') {
|
|
191
|
+
global.gc();
|
|
192
|
+
log.debug('***Manual garbage collection triggered via global.gc().');
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
log.debug('***Garbage collection is not exposed. Start Node.js with --expose-gc to enable manual GC.');
|
|
163
196
|
}
|
|
164
197
|
}
|
|
165
198
|
function registerHandlers() {
|
|
@@ -190,17 +223,16 @@ async function restart() {
|
|
|
190
223
|
}
|
|
191
224
|
async function update() {
|
|
192
225
|
log.debug('Received update event, updating...');
|
|
193
|
-
// TODO: Implement update logic outside of matterbridge
|
|
194
226
|
instance = await Matterbridge.loadInstance(true);
|
|
195
227
|
registerHandlers();
|
|
196
228
|
}
|
|
197
229
|
async function start() {
|
|
198
230
|
log.debug('Received start memory check event');
|
|
199
|
-
startCpuMemoryCheck();
|
|
231
|
+
await startCpuMemoryCheck();
|
|
200
232
|
}
|
|
201
233
|
async function stop() {
|
|
202
234
|
log.debug('Received stop memory check event');
|
|
203
|
-
stopCpuMemoryCheck();
|
|
235
|
+
await stopCpuMemoryCheck();
|
|
204
236
|
}
|
|
205
237
|
async function main() {
|
|
206
238
|
log.debug(`Cli main() started`);
|
|
@@ -210,7 +242,6 @@ async function main() {
|
|
|
210
242
|
log.debug(`***Matterbridge.loadInstance(true) called`);
|
|
211
243
|
instance = await Matterbridge.loadInstance(true);
|
|
212
244
|
log.debug(`***Matterbridge.loadInstance(true) exited`);
|
|
213
|
-
// Check if the instance needs to shut down from parseCommandLine()
|
|
214
245
|
if (!instance || instance.shutdown) {
|
|
215
246
|
shutdown();
|
|
216
247
|
}
|
|
@@ -218,11 +249,9 @@ async function main() {
|
|
|
218
249
|
registerHandlers();
|
|
219
250
|
}
|
|
220
251
|
}
|
|
221
|
-
// Run the main function
|
|
222
252
|
process.title = 'matterbridge';
|
|
223
253
|
main().catch((error) => {
|
|
224
254
|
const errorMessage = error instanceof Error ? error.message : error;
|
|
225
255
|
const errorInspect = inspect(error, { depth: 10 });
|
|
226
256
|
log.error(`Matterbridge.loadInstance() failed with error: ${errorMessage}\nstack: ${errorInspect}`);
|
|
227
257
|
});
|
|
228
|
-
//# 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.10
|
|
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 {(device: MatterbridgeEndpoint) => Promise<void>} 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
|