matterbridge 3.0.2-dev-20250513-ae61aa7 → 3.0.2-dev-20250514-175db7e

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 CHANGED
@@ -12,14 +12,15 @@ If you like this project and find it useful, please consider giving it a star on
12
12
 
13
13
  ### Added
14
14
 
15
- - [virtual] Added virtual devices Restart Matterbridge and Update Matterbridge.
15
+ - [virtual] Added virtual devices Restart Matterbridge and Update Matterbridge and full Jest tests.
16
+ - [virtual] Added virtual devices Reboot Matterbridge for Shelly board and full Jest tests.
16
17
 
17
18
  ### Changed
18
19
 
19
20
  - [package]: Updated dependencies.
20
21
  - [utils]: Refactor utils functions.
21
22
  - [utils]: Updated Jest tests on utils functions.
22
- - [devices]: Added RoboticVacuumCleaner class to create the Robotic Vacuum Cleaner device type.
23
+ - [devices]: Added RoboticVacuumCleaner class to create the Robotic Vacuum Cleaner device type in one line of code.
23
24
 
24
25
  ### Fixed
25
26
 
@@ -0,0 +1,67 @@
1
+ import { OnOff } from '@matter/main/clusters/on-off';
2
+ import { Endpoint } from '@matter/node';
3
+ import { BridgedDeviceBasicInformationServer } from '@matter/node/behaviors/bridged-device-basic-information';
4
+ import { OnOffBaseServer } from '@matter/node/behaviors/on-off';
5
+ import { OnOffPlugInUnitDevice } from '@matter/node/devices/on-off-plug-in-unit';
6
+ import { hasParameter } from './utils/commandLine.js';
7
+ export async function addVirtualDevice(aggregatorEndpoint, name, callback) {
8
+ const device = new Endpoint(OnOffPlugInUnitDevice.with(BridgedDeviceBasicInformationServer), {
9
+ id: name.replaceAll(' ', ''),
10
+ bridgedDeviceBasicInformation: { nodeLabel: name },
11
+ onOff: { onOff: false, startUpOnOff: OnOff.StartUpOnOff.Off },
12
+ });
13
+ device.events.onOff.onOff$Changed.on(async (value) => {
14
+ if (value) {
15
+ await device.setStateOf(OnOffBaseServer, { onOff: false });
16
+ callback();
17
+ }
18
+ });
19
+ await aggregatorEndpoint.add(device);
20
+ await device.setStateOf(OnOffBaseServer, { onOff: false });
21
+ return device;
22
+ }
23
+ export async function addVirtualDevices(matterbridge, aggregatorEndpoint) {
24
+ if (!hasParameter('novirtual') && matterbridge.bridgeMode === 'bridge' && aggregatorEndpoint) {
25
+ matterbridge.log.notice(`Creating virtual devices for Matterbridge server node...`);
26
+ await addVirtualDevice(aggregatorEndpoint, 'Restart Matterbridge', async () => {
27
+ if (matterbridge.restartMode === '')
28
+ await matterbridge.restartProcess();
29
+ else
30
+ await matterbridge.shutdownProcess();
31
+ });
32
+ await addVirtualDevice(aggregatorEndpoint, 'Update Matterbridge', async () => {
33
+ if (hasParameter('shelly')) {
34
+ const { getShelly } = await import('./shelly.js');
35
+ getShelly('/api/updates/sys/perform', 10 * 1000)
36
+ .then(() => {
37
+ matterbridge.log.notice('Shelly system updated successfully');
38
+ })
39
+ .catch((error) => {
40
+ matterbridge.log.error(`Error updating shelly system: ${error}`);
41
+ });
42
+ getShelly('/api/updates/main/perform', 10 * 1000)
43
+ .then(() => {
44
+ matterbridge.log.notice('Shelly software updated successfully');
45
+ })
46
+ .catch((error) => {
47
+ matterbridge.log.error(`Error updating shelly software: ${error}`);
48
+ });
49
+ }
50
+ else {
51
+ await matterbridge.updateProcess();
52
+ }
53
+ });
54
+ if (hasParameter('shelly')) {
55
+ await addVirtualDevice(aggregatorEndpoint, 'Reboot Matterbridge', async () => {
56
+ const { postShelly } = await import('./shelly.js');
57
+ postShelly('/api/system/reboot', {}, 60 * 1000)
58
+ .then(() => {
59
+ matterbridge.log.notice('Rebooting shelly board...');
60
+ })
61
+ .catch((error) => {
62
+ matterbridge.log.error(`Error rebooting shelly board: ${error}`);
63
+ });
64
+ });
65
+ }
66
+ }
67
+ }
@@ -7,21 +7,18 @@ import { AnsiLogger, UNDERLINE, UNDERLINEOFF, YELLOW, db, debugStringify, BRIGHT
7
7
  import { NodeStorageManager } from './storage/export.js';
8
8
  import { getParameter, getIntParameter, hasParameter, copyDirectory, withTimeout, waiter, isValidString, parseVersionString, isValidNumber } from './utils/export.js';
9
9
  import { logInterfaces, getGlobalNodeModules } from './utils/network.js';
10
+ import { dev, plg, typ } from './matterbridgeTypes.js';
10
11
  import { PluginManager } from './pluginManager.js';
11
12
  import { DeviceManager } from './deviceManager.js';
12
13
  import { MatterbridgeEndpoint } from './matterbridgeEndpoint.js';
13
14
  import { bridge } from './matterbridgeDeviceTypes.js';
14
15
  import { Frontend } from './frontend.js';
15
- import { DeviceTypeId, Endpoint as EndpointNode, Logger, LogLevel as MatterLogLevel, LogFormat as MatterLogFormat, VendorId, StorageService, Environment, ServerNode, UINT32_MAX, UINT16_MAX, Endpoint, } from '@matter/main';
16
+ import { addVirtualDevices } from './helpers.js';
17
+ import { DeviceTypeId, Endpoint, Logger, LogLevel as MatterLogLevel, LogFormat as MatterLogFormat, VendorId, StorageService, Environment, ServerNode, UINT32_MAX, UINT16_MAX, } from '@matter/main';
16
18
  import { DeviceCommissioner, FabricAction, MdnsService, PaseClient } from '@matter/main/protocol';
17
- import { OnOffPlugInUnitDevice } from '@matter/main/devices/on-off-plug-in-unit';
18
19
  import { AggregatorEndpoint } from '@matter/main/endpoints';
19
20
  import { BasicInformationServer } from '@matter/main/behaviors/basic-information';
20
- import { OnOffBaseServer } from '@matter/main/behaviors/on-off';
21
21
  import { BridgedDeviceBasicInformationServer } from '@matter/main/behaviors/bridged-device-basic-information';
22
- const plg = '\u001B[38;5;33m';
23
- const dev = '\u001B[38;5;79m';
24
- const typ = '\u001B[38;5;207m';
25
22
  export class Matterbridge extends EventEmitter {
26
23
  systemInformation = {
27
24
  interfaceName: '',
@@ -1244,6 +1241,7 @@ export class Matterbridge extends EventEmitter {
1244
1241
  this.serverNode = await this.createServerNode(this.matterbridgeContext, this.port ? this.port++ : undefined, this.passcode ? this.passcode++ : undefined, this.discriminator ? this.discriminator++ : undefined);
1245
1242
  this.aggregatorNode = await this.createAggregatorNode(this.matterbridgeContext);
1246
1243
  await this.serverNode.add(this.aggregatorNode);
1244
+ await addVirtualDevices(this, this.aggregatorNode);
1247
1245
  await this.startPlugins();
1248
1246
  this.log.debug('Starting start matter interval in bridge mode');
1249
1247
  let failCount = 0;
@@ -1521,30 +1519,6 @@ export class Matterbridge extends EventEmitter {
1521
1519
  serverNode.lifecycle.decommissioned.on(() => this.log.notice(`Server node for ${storeId} was fully decommissioned successfully!`));
1522
1520
  serverNode.lifecycle.online.on(async () => {
1523
1521
  this.log.notice(`Server node for ${storeId} is online`);
1524
- if (!hasParameter('novirtual') && this.bridgeMode === 'bridge') {
1525
- this.log.notice(`Creating virtual devices for server node ${storeId}`);
1526
- const virtualRestart = new Endpoint(OnOffPlugInUnitDevice.with(BridgedDeviceBasicInformationServer), { id: 'Restart Matterbridge', bridgedDeviceBasicInformation: { nodeLabel: 'Restart' } });
1527
- virtualRestart.events.onOff.onOff$Changed.on(async (value) => {
1528
- if (value) {
1529
- await virtualRestart.setStateOf(OnOffBaseServer, { onOff: false });
1530
- if (this.restartMode === '')
1531
- this.restartProcess();
1532
- else
1533
- this.shutdownProcess();
1534
- }
1535
- });
1536
- await this.aggregatorNode?.add(virtualRestart);
1537
- await virtualRestart.setStateOf(OnOffBaseServer, { onOff: false });
1538
- const virtualUpdate = new Endpoint(OnOffPlugInUnitDevice.with(BridgedDeviceBasicInformationServer), { id: 'Update Matterbridge', bridgedDeviceBasicInformation: { nodeLabel: 'Update' } });
1539
- virtualUpdate.events.onOff.onOff$Changed.on(async (value) => {
1540
- if (value) {
1541
- await virtualUpdate.setStateOf(OnOffBaseServer, { onOff: false });
1542
- this.updateProcess();
1543
- }
1544
- });
1545
- await this.aggregatorNode?.add(virtualUpdate);
1546
- await virtualUpdate.setStateOf(OnOffBaseServer, { onOff: false });
1547
- }
1548
1522
  if (!serverNode.lifecycle.isCommissioned) {
1549
1523
  this.log.notice(`Server node for ${storeId} is not commissioned. Pair to commission ...`);
1550
1524
  const { qrPairingCode, manualPairingCode } = serverNode.state.commissioning.pairingCodes;
@@ -1719,7 +1693,7 @@ export class Matterbridge extends EventEmitter {
1719
1693
  }
1720
1694
  async createAggregatorNode(storageContext) {
1721
1695
  this.log.notice(`Creating ${await storageContext.get('storeId')} aggregator `);
1722
- const aggregatorNode = new EndpointNode(AggregatorEndpoint, { id: `${await storageContext.get('storeId')}` });
1696
+ const aggregatorNode = new Endpoint(AggregatorEndpoint, { id: `${await storageContext.get('storeId')}` });
1723
1697
  return aggregatorNode;
1724
1698
  }
1725
1699
  async addBridgedEndpoint(pluginName, device) {
@@ -227,17 +227,18 @@ export function getBehavior(endpoint, cluster) {
227
227
  export async function invokeBehaviorCommand(endpoint, cluster, command, params) {
228
228
  const behaviorId = getBehavior(endpoint, cluster)?.id;
229
229
  if (!behaviorId) {
230
- endpoint.log.error(`invokeBehaviorCommand error: command ${hk}${command}${er} not found on endpoint ${or}${endpoint.maybeId}${er}:${or}${endpoint.maybeNumber}${er}`);
231
- return;
230
+ endpoint.log?.error(`invokeBehaviorCommand error: command ${hk}${command}${er} not found on endpoint ${or}${endpoint.maybeId}${er}:${or}${endpoint.maybeNumber}${er}`);
231
+ return false;
232
232
  }
233
233
  await endpoint.act((agent) => {
234
234
  const behavior = agent[behaviorId];
235
235
  if (!(command in behavior) || typeof behavior[command] !== 'function') {
236
- endpoint.log.error(`invokeBehaviorCommand error: command ${hk}${command}${er} not found on agent for endpoint ${or}${endpoint.maybeId}${er}:${or}${endpoint.maybeNumber}${er}`);
237
- return;
236
+ endpoint.log?.error(`invokeBehaviorCommand error: command ${hk}${command}${er} not found on agent for endpoint ${or}${endpoint.maybeId}${er}:${or}${endpoint.maybeNumber}${er}`);
237
+ return false;
238
238
  }
239
239
  behavior[command](params);
240
240
  });
241
+ return true;
241
242
  }
242
243
  export function addRequiredClusterServers(endpoint) {
243
244
  const requiredServerList = [];
package/dist/shelly.js CHANGED
@@ -119,8 +119,6 @@ export async function triggerShellyChangeIp(matterbridge, config) {
119
119
  matterbridge.log.debug(`****Error triggering Shelly network configuration change: ${error instanceof Error ? error.message : error}`);
120
120
  matterbridge.log.error(`Error changing Shelly network configuration: ${error instanceof Error ? error.message : error}`);
121
121
  matterbridge.frontend.wssSendSnackbarMessage('Error changing Shelly network configuration', 10, 'error');
122
- })
123
- .finally(() => {
124
122
  });
125
123
  }
126
124
  export async function triggerShellyReboot(matterbridge) {
@@ -135,8 +133,6 @@ export async function triggerShellyReboot(matterbridge) {
135
133
  matterbridge.log.debug(`****Error triggering Shelly system reboot: ${error instanceof Error ? error.message : error}`);
136
134
  matterbridge.log.error(`Error rebooting Shelly board: ${error instanceof Error ? error.message : error}`);
137
135
  matterbridge.frontend.wssSendSnackbarMessage('Error rebooting Shelly board', 10, 'error');
138
- })
139
- .finally(() => {
140
136
  });
141
137
  }
142
138
  export async function triggerShellySoftReset(matterbridge) {
@@ -151,8 +147,6 @@ export async function triggerShellySoftReset(matterbridge) {
151
147
  matterbridge.log.debug(`****Error triggering Shelly soft reset: ${error instanceof Error ? error.message : error}`);
152
148
  matterbridge.log.error(`Error resetting the network parameters on Shelly board: ${error instanceof Error ? error.message : error}`);
153
149
  matterbridge.frontend.wssSendSnackbarMessage('Error resetting the network parameters on Shelly board', 10, 'error');
154
- })
155
- .finally(() => {
156
150
  });
157
151
  }
158
152
  export async function triggerShellyHardReset(matterbridge) {
@@ -167,8 +161,6 @@ export async function triggerShellyHardReset(matterbridge) {
167
161
  matterbridge.log.debug(`****Error triggering Shelly hard reset: ${error instanceof Error ? error.message : error}`);
168
162
  matterbridge.log.error(`Error while factory resetting the Shelly board: ${error instanceof Error ? error.message : error}`);
169
163
  matterbridge.frontend.wssSendSnackbarMessage('Error while factory resetting the Shelly board', 10, 'error');
170
- })
171
- .finally(() => {
172
164
  });
173
165
  }
174
166
  export async function createShellySystemLog(matterbridge) {
@@ -190,7 +182,7 @@ export async function createShellySystemLog(matterbridge) {
190
182
  matterbridge.log.warn(`Error getting Shelly system log: ${error instanceof Error ? error.message : error}`);
191
183
  });
192
184
  }
193
- async function getShelly(api, timeout = 60000) {
185
+ export async function getShelly(api, timeout = 60000) {
194
186
  const http = await import('node:http');
195
187
  return new Promise((resolve, reject) => {
196
188
  const url = `http://127.0.0.1:8101${api}`;
@@ -233,7 +225,7 @@ async function getShelly(api, timeout = 60000) {
233
225
  });
234
226
  });
235
227
  }
236
- async function postShelly(api, data, timeout = 60000) {
228
+ export async function postShelly(api, data, timeout = 60000) {
237
229
  const http = await import('node:http');
238
230
  return new Promise((resolve, reject) => {
239
231
  const url = `http://127.0.0.1:8101${api}`;
package/dist/update.js CHANGED
@@ -1,22 +1,28 @@
1
+ import { db, nt, wr } from 'node-ansi-logger';
1
2
  import { plg } from './matterbridgeTypes.js';
2
- import { db, nt, wr } from './logger/export.js';
3
3
  export async function checkUpdates(matterbridge) {
4
4
  const { hasParameter } = await import('./utils/commandLine.js');
5
- getMatterbridgeLatestVersion(matterbridge);
6
- getMatterbridgeDevVersion(matterbridge);
5
+ const latestVersion = getMatterbridgeLatestVersion(matterbridge);
6
+ const devVersion = getMatterbridgeDevVersion(matterbridge);
7
+ const pluginsVersions = [];
8
+ const shellyUpdates = [];
7
9
  for (const plugin of matterbridge.plugins) {
8
- getPluginLatestVersion(matterbridge, plugin);
10
+ const pluginVersion = getPluginLatestVersion(matterbridge, plugin);
11
+ pluginsVersions.push(pluginVersion);
9
12
  }
10
13
  if (hasParameter('shelly')) {
11
14
  const { getShellySysUpdate, getShellyMainUpdate } = await import('./shelly.js');
12
- getShellySysUpdate(matterbridge);
13
- getShellyMainUpdate(matterbridge);
15
+ const systemUpdate = getShellySysUpdate(matterbridge);
16
+ shellyUpdates.push(systemUpdate);
17
+ const mainUpdate = getShellyMainUpdate(matterbridge);
18
+ shellyUpdates.push(mainUpdate);
14
19
  }
20
+ await Promise.all([latestVersion, devVersion, ...pluginsVersions, ...shellyUpdates]);
15
21
  }
16
- async function getMatterbridgeLatestVersion(matterbridge) {
22
+ export async function getMatterbridgeLatestVersion(matterbridge) {
17
23
  const { getNpmPackageVersion } = await import('./utils/network.js');
18
- getNpmPackageVersion('matterbridge')
19
- .then(async (version) => {
24
+ try {
25
+ const version = await getNpmPackageVersion('matterbridge');
20
26
  matterbridge.matterbridgeLatestVersion = version;
21
27
  matterbridge.matterbridgeInformation.matterbridgeLatestVersion = version;
22
28
  await matterbridge.nodeContext?.set('matterbridgeLatestVersion', matterbridge.matterbridgeLatestVersion);
@@ -28,15 +34,16 @@ async function getMatterbridgeLatestVersion(matterbridge) {
28
34
  else {
29
35
  matterbridge.log.debug(`Matterbridge is up to date. Current version: ${matterbridge.matterbridgeVersion}. Latest version: ${matterbridge.matterbridgeLatestVersion}.`);
30
36
  }
31
- })
32
- .catch((error) => {
33
- matterbridge.log.warn(`Error getting Matterbridge latest version: ${error.message}`);
34
- });
37
+ return version;
38
+ }
39
+ catch (error) {
40
+ matterbridge.log.warn(`Error getting Matterbridge latest version: ${error instanceof Error ? error.message : error}`);
41
+ }
35
42
  }
36
- async function getMatterbridgeDevVersion(matterbridge) {
43
+ export async function getMatterbridgeDevVersion(matterbridge) {
37
44
  const { getNpmPackageVersion } = await import('./utils/network.js');
38
- getNpmPackageVersion('matterbridge', 'dev')
39
- .then(async (version) => {
45
+ try {
46
+ const version = await getNpmPackageVersion('matterbridge', 'dev');
40
47
  matterbridge.matterbridgeDevVersion = version;
41
48
  matterbridge.matterbridgeInformation.matterbridgeDevVersion = version;
42
49
  await matterbridge.nodeContext?.set('matterbridgeDevVersion', version);
@@ -45,15 +52,19 @@ async function getMatterbridgeDevVersion(matterbridge) {
45
52
  matterbridge.frontend.wssSendRefreshRequired('matterbridgeDevVersion');
46
53
  matterbridge.frontend.wssSendUpdateRequired();
47
54
  }
48
- })
49
- .catch((error) => {
50
- matterbridge.log.warn(`Error getting Matterbridge latest dev version: ${error.message}`);
51
- });
55
+ else {
56
+ matterbridge.log.debug(`Matterbridge@dev is up to date. Current version: ${matterbridge.matterbridgeVersion}. Latest dev version: ${matterbridge.matterbridgeDevVersion}.`);
57
+ }
58
+ return version;
59
+ }
60
+ catch (error) {
61
+ matterbridge.log.warn(`Error getting Matterbridge latest dev version: ${error instanceof Error ? error.message : error}`);
62
+ }
52
63
  }
53
- async function getPluginLatestVersion(matterbridge, plugin) {
64
+ export async function getPluginLatestVersion(matterbridge, plugin) {
54
65
  const { getNpmPackageVersion } = await import('./utils/network.js');
55
- getNpmPackageVersion(plugin.name)
56
- .then((version) => {
66
+ try {
67
+ const version = await getNpmPackageVersion(plugin.name);
57
68
  plugin.latestVersion = version;
58
69
  if (plugin.version !== plugin.latestVersion) {
59
70
  matterbridge.log.notice(`The plugin ${plg}${plugin.name}${nt} is out of date. Current version: ${plugin.version}. Latest version: ${plugin.latestVersion}.`);
@@ -62,8 +73,9 @@ async function getPluginLatestVersion(matterbridge, plugin) {
62
73
  else {
63
74
  matterbridge.log.debug(`The plugin ${plg}${plugin.name}${db} is up to date. Current version: ${plugin.version}. Latest version: ${plugin.latestVersion}.`);
64
75
  }
65
- })
66
- .catch((error) => {
67
- matterbridge.log.warn(`Error getting ${plg}${plugin.name}${wr} latest version: ${error.message}`);
68
- });
76
+ return version;
77
+ }
78
+ catch (error) {
79
+ matterbridge.log.warn(`Error getting plugin ${plg}${plugin.name}${wr} latest version: ${error instanceof Error ? error.message : error}`);
80
+ }
69
81
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "matterbridge",
3
- "version": "3.0.2-dev-20250513-ae61aa7",
3
+ "version": "3.0.2-dev-20250514-175db7e",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "matterbridge",
9
- "version": "3.0.2-dev-20250513-ae61aa7",
9
+ "version": "3.0.2-dev-20250514-175db7e",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@matter/main": "0.13.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matterbridge",
3
- "version": "3.0.2-dev-20250513-ae61aa7",
3
+ "version": "3.0.2-dev-20250514-175db7e",
4
4
  "description": "Matterbridge plugin manager for Matter",
5
5
  "author": "https://github.com/Luligu",
6
6
  "license": "Apache-2.0",