Skip to content

Commit

Permalink
Release 1.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Luligu committed Apr 10, 2024
1 parent 26e1097 commit 7fe7de7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.

### Added

- [matterbridge]: Added -factoryreset parameter to factory reset Matterbridge (see the readme.md for more explanations).
- [matterbridge]: Added -reset parameter to reset the commissioning of Matterbridge (bridge mode).
- [matterbridge]: Added -reset [plugin] parameter to reset the commissioning of a plugin (childbridge mode).
- [matterbridge]: Added -port [port] parameter to set the starting port for the commissioning servers (both bridge and childbridge modes).
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,26 @@ matterbridge -disable [plugin path or plugin name]
matterbridge -enable [plugin path or plugin name]
```

## How to remove the commissioning information for Matterbridge so you can pair it again (bridge mode)
## How to remove the commissioning information for Matterbridge so you can pair it again (bridge mode). Shutdown Matterbridge before!

```
matterbridge -reset
```

## How to remove the commissioning information for a registered plugin so you can pair it again (childbridge mode)
## How to remove the commissioning information for a registered plugin so you can pair it again (childbridge mode). Shutdown Matterbridge before!

```
matterbridge -reset [plugin path or plugin name]
```

## How to factory reset Matterbridge. Shutdown Matterbridge before!

```
matterbridge -factoryreset
```

This will remove the internal starages. All commissioning information will be lost. All plugins will be unregistered.

## How to create your plugin

The easiest way is to clone:
Expand Down
60 changes: 53 additions & 7 deletions src/matterbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@ import os from 'os';
import path from 'path';

import { CommissioningController, CommissioningServer, MatterServer, NodeCommissioningOptions } from '@project-chip/matter-node.js';
import { BasicInformationCluster, BooleanStateCluster, BridgedDeviceBasicInformationCluster, ClusterServer, GeneralCommissioning, PowerSourceCluster, ThreadNetworkDiagnosticsCluster, getClusterNameById } from '@project-chip/matter-node.js/cluster';
import {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
BasicInformation,
BasicInformationCluster,
BooleanStateCluster,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
BridgedDeviceBasicInformation,
BridgedDeviceBasicInformationCluster,
ClusterServer,
GeneralCommissioning,
PowerSourceCluster,
ThreadNetworkDiagnosticsCluster,
getClusterNameById,
} from '@project-chip/matter-node.js/cluster';
import { DeviceTypeId, EndpointNumber, VendorId } from '@project-chip/matter-node.js/datatype';
import { Aggregator, Device, DeviceTypes, NodeStateInformation } from '@project-chip/matter-node.js/device';
import { Format, Level, Logger } from '@project-chip/matter-node.js/log';
Expand Down Expand Up @@ -226,6 +239,7 @@ export class Matterbridge extends EventEmitter {
- frontend [port]: start the frontend on the given port (default 3000)
- debug: enable debug mode (default false)
- reset: remove the commissioning for Matterbridge (bridge mode). Shutdown Matterbridge before using it!
- factoryreset: remove all commissioning information and reset all internal storages. Shutdown Matterbridge before using it!
- list: list the registered plugins
- add [plugin path]: register the plugin from the given absolute or relative path
- add [plugin name]: register the globally installed plugin with the given name
Expand Down Expand Up @@ -409,6 +423,16 @@ export class Matterbridge extends EventEmitter {
process.exit(0);
}

if (hasParameter('factoryreset')) {
// Delete matter storage file
await fs.unlink(path.join(this.matterbridgeDirectory, 'matterbridge.json'));
// Delete node storage directory with its subdirectories
await fs.rmdir(path.join(this.matterbridgeDirectory, 'storage'), { recursive: true });
this.log.info('Factory reset done! Remove all paired devices from the controllers.');
this.emit('shutdown');
process.exit(0);
}

// Start the storage and create matterbridgeContext (we need it now for frontend and later for matterbridge)
await this.startStorage('json', path.join(this.matterbridgeDirectory, 'matterbridge.json'));
this.matterbridgeContext = await this.createCommissioningServerContext('Matterbridge', 'Matterbridge', DeviceTypes.AGGREGATOR.code, 0xfff1, 'Matterbridge', 0x8000, 'Matterbridge aggregator');
Expand All @@ -417,7 +441,7 @@ export class Matterbridge extends EventEmitter {
this.log.info('Resetting Matterbridge commissioning information...');
await this.matterbridgeContext?.clearAll();
await this.stopStorage();
this.log.info('Factory reset done! Remove the device from the controller.');
this.log.info('Reset done! Remove the device from the controller.');
this.emit('shutdown');
process.exit(0);
}
Expand Down Expand Up @@ -687,12 +711,34 @@ export class Matterbridge extends EventEmitter {
this.log.error(`Plugin ${plg}${registeredDevice.plugin}${er} not found`);
return;
}
this.log.debug(`*-- device: ${dev}${registeredDevice.device.name}${db} plugin ${plg}${registeredDevice.plugin}${db} type ${GREEN}${plugin.type}${db}`);
if (this.bridgeMode === 'bridge') registeredDevice.device.setBridgedDeviceReachability(false);
if (this.bridgeMode === 'childbridge') plugin.commissioningServer?.setReachability(false);
if (this.bridgeMode === 'childbridge' && plugin.type === 'AccessoryPlatform') this.setReachableAttribute(registeredDevice.device, false);
if (this.bridgeMode === 'childbridge' && plugin.type === 'DynamicPlatform') registeredDevice.device.setBridgedDeviceReachability(false);
if (this.bridgeMode === 'bridge' && registeredDevice.device.number) {
this.log.debug(`*-- device: ${dev}${registeredDevice.device.name}${db} plugin ${plg}${registeredDevice.plugin}${db} type ${plugin.type}${db}`);
registeredDevice.device.setBridgedDeviceReachability(false);
registeredDevice.device.getClusterServerById(BridgedDeviceBasicInformation.Cluster.id)?.triggerReachableChangedEvent({ reachableNewValue: false });
}
if (this.bridgeMode === 'childbridge') {
if (plugin.type === 'DynamicPlatform' && registeredDevice.device.number) {
this.log.debug(`*-- device: ${dev}${registeredDevice.device.name}${db} plugin ${plg}${registeredDevice.plugin}${db} type ${plugin.type}${db}`);
registeredDevice.device.setBridgedDeviceReachability(false);
registeredDevice.device.getClusterServerById(BridgedDeviceBasicInformation.Cluster.id)?.triggerReachableChangedEvent({ reachableNewValue: false });
}
}
});
if (this.bridgeMode === 'bridge') {
this.log.debug('*Changing reachability to false for Matterbridge');
this.matterAggregator?.getClusterServerById(BasicInformation.Cluster.id)?.setReachableAttribute(false);
this.matterAggregator?.getClusterServerById(BasicInformation.Cluster.id)?.triggerReachableChangedEvent({ reachableNewValue: false });
this.commissioningServer?.setReachability(false);
}
if (this.bridgeMode === 'childbridge') {
for (const plugin of this.registeredPlugins) {
if (!plugin.enabled || plugin.error) continue;
this.log.debug(`*Changing reachability to false for plugin ${plg}${plugin.name}${db} type ${plugin.type}`);
plugin.aggregator?.getClusterServerById(BasicInformation.Cluster.id)?.setReachableAttribute(false);
plugin.aggregator?.getClusterServerById(BasicInformation.Cluster.id)?.triggerReachableChangedEvent({ reachableNewValue: false });
plugin.commissioningServer?.setReachability(false);
}
}
*/

// Close the express server
Expand Down

0 comments on commit 7fe7de7

Please sign in to comment.