matterbridge-mqtt 0.0.4 → 0.0.5-dev-20260609-e4b3a62
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 +24 -0
- package/README.md +10 -9
- package/dist/module.js +66 -55
- package/dist/mqtt.js +6 -5
- package/dist/publishTest.js +35 -35
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,30 @@ If you like this project and find it useful, please consider giving it a star on
|
|
|
8
8
|
|
|
9
9
|
<a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="120"></a>
|
|
10
10
|
|
|
11
|
+
## [0.0.5] - 2026-06-09
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Add handler to create all device types.
|
|
16
|
+
- Add MQTT packet metadata forwarding to message handlers.
|
|
17
|
+
- Add retained MQTT message logging.
|
|
18
|
+
- Add explicit MQTT 5 retained message replay on subscribe.
|
|
19
|
+
- Add `destroyDevice()` support when a config topic receives an empty payload.
|
|
20
|
+
- Add handling for empty state payloads without JSON parse errors.
|
|
21
|
+
- Add validation against white/black list selections when creating devices.
|
|
22
|
+
- Add tests for `mqttMessageHandler()`, `createDevice()`, `destroyDevice()`, and `updateHandler()`.
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- Publish test config and state messages with QoS 2 and retain enabled.
|
|
27
|
+
- Subscribe to MQTT topics with QoS 2.
|
|
28
|
+
- Bump `@typescript/native-preview` to v.7.0.0-dev.20260608.1.
|
|
29
|
+
- Bump `@typescript/native-preview` to v.7.0.0-dev.20260609.1.
|
|
30
|
+
- Bump `oxlint` to v.1.69.0.
|
|
31
|
+
- Bump `oxfmt` to v.0.54.0.
|
|
32
|
+
|
|
33
|
+
<a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="80"></a>
|
|
34
|
+
|
|
11
35
|
## [0.0.4] - 2026-06-08
|
|
12
36
|
|
|
13
37
|
### Added
|
package/README.md
CHANGED
|
@@ -89,7 +89,9 @@ All topics follow the pattern `<topic>/<deviceId>/<subTopic>/root`, where `<topi
|
|
|
89
89
|
|
|
90
90
|
## Publish
|
|
91
91
|
|
|
92
|
-
Each device shall publish
|
|
92
|
+
Each device shall publish retained `config` messages and retained `state` messages:
|
|
93
|
+
|
|
94
|
+
Device types, clusters and attributes all use their Matter names without spaces: device types (e.g. `PowerSource`, `DimmableLight`), clusters (e.g. `PowerSource`, `OnOff`, `LevelControl`) and attributes (e.g. `onOff`, `currentLevel`).
|
|
93
95
|
|
|
94
96
|
### config
|
|
95
97
|
|
|
@@ -99,10 +101,10 @@ only the fixed and optional attributes shall be published here
|
|
|
99
101
|
|
|
100
102
|
```typescript
|
|
101
103
|
const config = {
|
|
102
|
-
deviceTypes: ['
|
|
104
|
+
deviceTypes: ['DimmableLight'],
|
|
103
105
|
clusters: { BridgedDeviceBasicInformation: { nodeLabel: 'Light 1', serialNumber: 'xxx-yyy-xxx' }, LevelControl: { onLevel: 128 } },
|
|
104
106
|
};
|
|
105
|
-
publish('matterbridge/light1/config/root', JSON.stringify(config));
|
|
107
|
+
publish('matterbridge/light1/config/root', JSON.stringify(config), { retain: true, qos: 2 });
|
|
106
108
|
```
|
|
107
109
|
|
|
108
110
|
### state
|
|
@@ -113,7 +115,7 @@ only the current attributes shall be published here
|
|
|
113
115
|
|
|
114
116
|
```typescript
|
|
115
117
|
const state = { OnOff: { onOff: false }, LevelControl: { currentLevel: 254 } };
|
|
116
|
-
publish('matterbridge/deviceid/state/root', JSON.stringify(state));
|
|
118
|
+
publish('matterbridge/deviceid/state/root', JSON.stringify(state), { retain: true, qos: 2 });
|
|
117
119
|
```
|
|
118
120
|
|
|
119
121
|
## Subscribe
|
|
@@ -135,9 +137,8 @@ Payload: "{"cluster":"OnOff","command":"on","request": MatterRequest | undefined
|
|
|
135
137
|
|
|
136
138
|
# Todo
|
|
137
139
|
|
|
138
|
-
- [
|
|
139
|
-
- [
|
|
140
|
-
- [ ]
|
|
141
|
-
- [ ]
|
|
142
|
-
- [ ] Add Chapter 9. HVAC Device Types
|
|
140
|
+
- [x] Add white and black list
|
|
141
|
+
- [x] Attributes handler in config
|
|
142
|
+
- [ ] Matter command handler
|
|
143
|
+
- [ ] Matter Subscribe handler
|
|
143
144
|
- [ ] Add composed device types
|
package/dist/module.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bridgedNode, getBehaviourTypeFromClusterServerId, getSupportedCluster, getSupportedDeviceType, MatterbridgeDynamicPlatform, MatterbridgeEndpoint, } from 'matterbridge';
|
|
2
2
|
import { debugStringify, info, warn } from 'matterbridge/logger';
|
|
3
|
-
import { SoilMeasurementServer } from 'matterbridge/matter/behaviors';
|
|
4
|
-
import { MeasurementType } from 'matterbridge/matter/types';
|
|
5
3
|
import { fireAndForget, inspectError } from 'matterbridge/utils';
|
|
6
4
|
import { MqttService } from './mqtt.js';
|
|
7
5
|
export default function initializePlugin(matterbridge, log, config) {
|
|
@@ -24,6 +22,7 @@ export class MqttPlatform extends MatterbridgeDynamicPlatform {
|
|
|
24
22
|
async onStart(reason) {
|
|
25
23
|
this.log.info(`onStart called with reason: ${reason}`);
|
|
26
24
|
await this.ready;
|
|
25
|
+
await this.clearSelect();
|
|
27
26
|
this.mqtt.on('connect', () => {
|
|
28
27
|
this.log.info('MQTT connected');
|
|
29
28
|
void this.mqtt.subscribe(`${this.config.topic}/#`);
|
|
@@ -43,8 +42,8 @@ export class MqttPlatform extends MatterbridgeDynamicPlatform {
|
|
|
43
42
|
this.mqtt.on('error', (error) => {
|
|
44
43
|
this.log.error(`MQTT error: ${error.message}`);
|
|
45
44
|
});
|
|
46
|
-
this.mqtt.on('message', (topic, payload) => {
|
|
47
|
-
this.mqttMessageHandler(topic, payload);
|
|
45
|
+
this.mqtt.on('message', (topic, payload, packet) => {
|
|
46
|
+
this.mqttMessageHandler(topic, payload, packet);
|
|
48
47
|
});
|
|
49
48
|
await this.mqtt.connect();
|
|
50
49
|
}
|
|
@@ -71,23 +70,45 @@ export class MqttPlatform extends MatterbridgeDynamicPlatform {
|
|
|
71
70
|
const [, deviceId, subTopic, endpointName] = match;
|
|
72
71
|
return { deviceId, subTopic, endpointName };
|
|
73
72
|
}
|
|
74
|
-
mqttMessageHandler(topic, payload) {
|
|
73
|
+
mqttMessageHandler(topic, payload, packet) {
|
|
75
74
|
try {
|
|
76
|
-
const message = JSON.parse(payload);
|
|
77
|
-
this.log.debug(`MQTT message on '${topic}': ${debugStringify(message)}`);
|
|
78
75
|
const parsed = this.mqttTopicParser(topic);
|
|
79
76
|
if (!parsed) {
|
|
80
77
|
this.log.warn(`Received MQTT message on topic '${topic}' that does not match expected format. Ignoring.`);
|
|
81
78
|
return;
|
|
82
79
|
}
|
|
83
80
|
const { deviceId, subTopic, endpointName } = parsed;
|
|
81
|
+
if (subTopic === 'config' && payload === '') {
|
|
82
|
+
this.log.debug(`MQTT ${packet.retain ? 'retained ' : ''}message on '${topic}': empty payload`);
|
|
83
|
+
this.log.info(`Received empty payload on config topic '${topic}', treating as device deletion request.`);
|
|
84
|
+
this.destroyDevice(deviceId);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (subTopic === 'state' && payload === '') {
|
|
88
|
+
this.log.debug(`MQTT ${packet.retain ? 'retained ' : ''}message on '${topic}': empty payload`);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const message = JSON.parse(payload);
|
|
92
|
+
this.log.debug(`MQTT ${packet.retain ? 'retained ' : ''}message on '${topic}': ${debugStringify(message)}`);
|
|
84
93
|
if (subTopic === 'config') {
|
|
85
94
|
this.log.info(`Received ${info.bgMagenta.black.bold ` config `} message for device ${info.bgCyan.black.bold ` ${deviceId} `} endpoint ${info.bgGreen.black.bold ` ${endpointName} `}`);
|
|
86
|
-
|
|
95
|
+
if (typeof message.deviceTypes !== 'object' && !Array.isArray(message.deviceTypes)) {
|
|
96
|
+
this.log.warn(`Received MQTT message on topic '${topic}' with invalid format: 'deviceTypes' field is missing or not an array. Ignoring.`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (typeof message.clusters !== 'object' || Array.isArray(message.clusters)) {
|
|
100
|
+
this.log.warn(`Received MQTT message on topic '${topic}' with invalid format: 'clusters' field is missing or not an object. Ignoring.`);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
this.createDevice(deviceId, endpointName, message);
|
|
87
104
|
}
|
|
88
105
|
else if (subTopic === 'state') {
|
|
89
106
|
this.log.info(`Received ${info.bgMagenta.black.bold ` state `} message for device ${info.bgCyan.black.bold ` ${deviceId} `} endpoint ${info.bgGreen.black.bold ` ${endpointName} `}`);
|
|
90
107
|
this.state.set(topic, payload);
|
|
108
|
+
if (typeof message !== 'object' || Array.isArray(message)) {
|
|
109
|
+
this.log.warn(`Received MQTT message on topic '${topic}' with invalid format: state is missing or not an object. Ignoring.`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
91
112
|
if (this.isConfigured)
|
|
92
113
|
fireAndForget(this.updateHandler(topic, payload), this.log, `Failed to handle state update for device ${deviceId} on endpoint ${endpointName}`);
|
|
93
114
|
}
|
|
@@ -99,53 +120,32 @@ export class MqttPlatform extends MatterbridgeDynamicPlatform {
|
|
|
99
120
|
inspectError(this.log, `Failed to parse MQTT message on '${topic}' with payload ${payload.replaceAll('\n', '')}`, error);
|
|
100
121
|
}
|
|
101
122
|
}
|
|
102
|
-
|
|
123
|
+
createDevice(deviceId, endpointName, jsonPayload) {
|
|
103
124
|
this.log.debug(`Creating device with ID ${deviceId} and endpoint ${endpointName} based on config: ${debugStringify(jsonPayload)}`);
|
|
104
125
|
const deviceTypes = [];
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
{ name: 'Dimmable PlugIn Unit', deviceType: dimmableOutlet },
|
|
114
|
-
{ name: 'Mounted OnOff Control', deviceType: onOffMountedSwitch },
|
|
115
|
-
{ name: 'Mounted Dimmable Load Control', deviceType: dimmableMountedSwitch },
|
|
116
|
-
{ name: 'Pump', deviceType: pumpDevice },
|
|
117
|
-
{ name: 'Water Valve', deviceType: waterValve },
|
|
118
|
-
{ name: 'Contact Sensor', deviceType: contactSensor },
|
|
119
|
-
{ name: 'Light Sensor', deviceType: lightSensor },
|
|
120
|
-
{ name: 'Occupancy Sensor', deviceType: occupancySensor },
|
|
121
|
-
{ name: 'Temperature Sensor', deviceType: temperatureSensor },
|
|
122
|
-
{ name: 'Pressure Sensor', deviceType: pressureSensor },
|
|
123
|
-
{ name: 'Flow Sensor', deviceType: flowSensor },
|
|
124
|
-
{ name: 'Humidity Sensor', deviceType: humiditySensor },
|
|
125
|
-
{ name: 'Smoke CO Alarm', deviceType: smokeCoAlarm },
|
|
126
|
-
{ name: 'Air Quality Sensor', deviceType: airQualitySensor },
|
|
127
|
-
{ name: 'Water Freeze Detector', deviceType: waterFreezeDetector },
|
|
128
|
-
{ name: 'Water Leak Detector', deviceType: waterLeakDetector },
|
|
129
|
-
{ name: 'Rain Sensor', deviceType: rainSensor },
|
|
130
|
-
{ name: 'Soil Sensor', deviceType: soilSensor },
|
|
131
|
-
];
|
|
132
|
-
for (const name of jsonPayload.deviceTypes) {
|
|
133
|
-
const found = supportedDeviceTypes.find((dt) => dt.name === name);
|
|
126
|
+
const bridgedDeviceBasicInformationCluster = jsonPayload.clusters.BridgedDeviceBasicInformation || {};
|
|
127
|
+
const deviceName = bridgedDeviceBasicInformationCluster.nodeLabel ?? deviceId;
|
|
128
|
+
const serialNumber = bridgedDeviceBasicInformationCluster.serialNumber ?? deviceId;
|
|
129
|
+
this.setSelectDevice(serialNumber, deviceName);
|
|
130
|
+
if (!this.validateDevice([serialNumber, deviceName]))
|
|
131
|
+
return;
|
|
132
|
+
for (const name of jsonPayload.deviceTypes.filter((dt) => dt !== 'BridgedNode')) {
|
|
133
|
+
const found = getSupportedDeviceType(name);
|
|
134
134
|
if (found) {
|
|
135
|
-
deviceTypes.push(found
|
|
135
|
+
deviceTypes.push(found);
|
|
136
136
|
}
|
|
137
137
|
else {
|
|
138
138
|
this.log.warn(`Device type '${name}' is not supported. Skipping.`);
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
deviceTypes.push(bridgedNode);
|
|
142
|
-
const bridgedDeviceBasicInformationCluster = jsonPayload.clusters.BridgedDeviceBasicInformation || {};
|
|
143
|
-
const powerSourceCluster = jsonPayload.clusters.PowerSource || {};
|
|
144
142
|
const device = new MatterbridgeEndpoint(deviceTypes, {
|
|
145
143
|
id: deviceId,
|
|
146
144
|
});
|
|
147
|
-
device.createDefaultBridgedDeviceBasicInformationClusterServer(
|
|
148
|
-
|
|
145
|
+
device.createDefaultBridgedDeviceBasicInformationClusterServer(deviceName, serialNumber, bridgedDeviceBasicInformationCluster.vendorId, bridgedDeviceBasicInformationCluster.vendorName, bridgedDeviceBasicInformationCluster.productName, bridgedDeviceBasicInformationCluster.softwareVersion, bridgedDeviceBasicInformationCluster.softwareVersionString, bridgedDeviceBasicInformationCluster.hardwareVersion, bridgedDeviceBasicInformationCluster.hardwareVersionString);
|
|
146
|
+
this.log.debug(`Created Bridged Device Basic Information Cluster for device ${deviceId} with attributes: ${debugStringify(bridgedDeviceBasicInformationCluster)}`);
|
|
147
|
+
if (jsonPayload.deviceTypes.includes('PowerSource')) {
|
|
148
|
+
const powerSourceCluster = jsonPayload.clusters.PowerSource || {};
|
|
149
149
|
if (powerSourceCluster.batReplacementDescription !== undefined || powerSourceCluster.batQuantity !== undefined) {
|
|
150
150
|
device.createDefaultPowerSourceReplaceableBatteryClusterServer(powerSourceCluster.batPercentRemaining, powerSourceCluster.batChargeLevel, powerSourceCluster.batVoltage, powerSourceCluster.batReplacementDescription, powerSourceCluster.batQuantity, powerSourceCluster.batReplaceability);
|
|
151
151
|
this.log.debug(`Created Power Source Replaceable Battery Cluster for device ${deviceId} with attributes: ${debugStringify(powerSourceCluster)}`);
|
|
@@ -163,21 +163,32 @@ export class MqttPlatform extends MatterbridgeDynamicPlatform {
|
|
|
163
163
|
this.log.debug(`Created Power Source Wired Cluster for device ${deviceId} with attributes: ${debugStringify(powerSourceCluster)}`);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
}
|
|
166
|
+
for (const cluster of Object.keys(jsonPayload.clusters).filter((c) => c !== 'BridgedDeviceBasicInformation' && c !== 'PowerSource')) {
|
|
167
|
+
const found = getSupportedCluster(cluster);
|
|
168
|
+
if (!found?.id) {
|
|
169
|
+
this.log.warn(`Cluster '${cluster}' is not supported. Skipping.`);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const behavior = getBehaviourTypeFromClusterServerId(found.id);
|
|
173
|
+
if (!behavior) {
|
|
174
|
+
this.log.warn(`Cluster '${cluster}' does not have a defined behavior. Skipping.`);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
this.log.debug(`*Adding behavior '${behavior.name}' to device '${deviceId}' for cluster '${cluster}' with configuration: ${debugStringify(jsonPayload.clusters[cluster])}`);
|
|
178
|
+
device.behaviors.require(behavior, jsonPayload.clusters[cluster]);
|
|
177
179
|
}
|
|
178
180
|
device.addRequiredClusters();
|
|
179
181
|
fireAndForget(this.registerDevice(device), this.log, `Failed to register device ${deviceId}`);
|
|
180
182
|
}
|
|
183
|
+
destroyDevice(deviceId) {
|
|
184
|
+
this.log.info(`Destroying device with ID '${deviceId}'`);
|
|
185
|
+
const device = this.getDeviceById(deviceId);
|
|
186
|
+
if (!device) {
|
|
187
|
+
this.log.warn(`Cannot destroy device with ID '${deviceId}' because it is not registered.`);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
fireAndForget(this.unregisterDevice(device), this.log, `Failed to unregister device ${deviceId}`);
|
|
191
|
+
}
|
|
181
192
|
async updateHandler(topic, payload) {
|
|
182
193
|
const { deviceId, subTopic, endpointName } = this.mqttTopicParser(topic) ?? {};
|
|
183
194
|
if (!deviceId || !subTopic || !endpointName) {
|
package/dist/mqtt.js
CHANGED
|
@@ -89,9 +89,9 @@ export class MqttService extends EventEmitter {
|
|
|
89
89
|
inspectError(this.log, `MqttService: error on ${error.bold.success `${brokerUrl}`}`, err);
|
|
90
90
|
this.emit('error', err);
|
|
91
91
|
});
|
|
92
|
-
client.on('message', (topic, payload) => {
|
|
93
|
-
this.log.debug(`MqttService: message on ${debug.bold.success `${topic}`}: "${payload.toString().replaceAll('\n', '')}"`);
|
|
94
|
-
this.emit('message', topic, payload.toString());
|
|
92
|
+
client.on('message', (topic, payload, packet) => {
|
|
93
|
+
this.log.debug(`MqttService: ${packet.retain ? 'retained ' : ''}message on ${debug.bold.success `${topic}`}: "${payload.toString().replaceAll('\n', '')}"`);
|
|
94
|
+
this.emit('message', topic, payload.toString(), packet);
|
|
95
95
|
});
|
|
96
96
|
return true;
|
|
97
97
|
}
|
|
@@ -116,8 +116,9 @@ export class MqttService extends EventEmitter {
|
|
|
116
116
|
return false;
|
|
117
117
|
}
|
|
118
118
|
try {
|
|
119
|
-
|
|
120
|
-
this.
|
|
119
|
+
const options = this.config.protocolVersion === 5 ? { qos: 2, rh: 0 } : { qos: 2 };
|
|
120
|
+
await this.client.subscribeAsync(topic, options);
|
|
121
|
+
this.log.debug(`MqttService: subscribed to '${debug.bold.success `${topic}`}' with options: ${debugStringify(options)}`);
|
|
121
122
|
this.emit('subscribed', topic);
|
|
122
123
|
return true;
|
|
123
124
|
}
|
package/dist/publishTest.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { PowerSource } from 'matterbridge/matter/clusters';
|
|
4
|
+
import { AirQuality, PowerSource, SmokeCoAlarm, ValveConfigurationAndControl } from 'matterbridge/matter/clusters';
|
|
5
|
+
import { hasParameter } from 'matterbridge/utils';
|
|
5
6
|
import { connectAsync } from 'mqtt';
|
|
6
7
|
const configPath = path.join(homedir(), '.matterbridge', 'matterbridge-mqtt.config.json');
|
|
7
8
|
let config;
|
|
@@ -17,175 +18,175 @@ const DEVICES = [
|
|
|
17
18
|
{
|
|
18
19
|
id: 'test-power-source',
|
|
19
20
|
name: 'Power Source',
|
|
20
|
-
deviceTypes: ['
|
|
21
|
+
deviceTypes: ['PowerSource'],
|
|
21
22
|
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 200, batVoltage: 3000 } },
|
|
22
23
|
state: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Warning, batPercentRemaining: 150, batVoltage: 2800 } },
|
|
23
24
|
},
|
|
24
25
|
{
|
|
25
26
|
id: 'test-electrical-sensor',
|
|
26
27
|
name: 'Electrical Sensor',
|
|
27
|
-
deviceTypes: ['
|
|
28
|
+
deviceTypes: ['ElectricalSensor'],
|
|
28
29
|
configClusters: {},
|
|
29
30
|
state: { ElectricalPowerMeasurement: { activePower: 1200, voltage: 2300, activeCurrent: 520 } },
|
|
30
31
|
},
|
|
31
32
|
{
|
|
32
33
|
id: 'test-onoff-light',
|
|
33
34
|
name: 'OnOff Light',
|
|
34
|
-
deviceTypes: ['
|
|
35
|
+
deviceTypes: ['OnOffLight', 'PowerSource'],
|
|
35
36
|
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
36
37
|
state: { OnOff: { onOff: false } },
|
|
37
38
|
},
|
|
38
39
|
{
|
|
39
40
|
id: 'test-dimmable-light',
|
|
40
41
|
name: 'Dimmable Light',
|
|
41
|
-
deviceTypes: ['
|
|
42
|
+
deviceTypes: ['DimmableLight', 'PowerSource'],
|
|
42
43
|
configClusters: { LevelControl: { onLevel: 128 }, PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
43
44
|
state: { OnOff: { onOff: true }, LevelControl: { currentLevel: 128 } },
|
|
44
45
|
},
|
|
45
46
|
{
|
|
46
47
|
id: 'test-color-temp-light',
|
|
47
48
|
name: 'Color Temperature Light',
|
|
48
|
-
deviceTypes: ['
|
|
49
|
+
deviceTypes: ['ColorTemperatureLight', 'PowerSource'],
|
|
49
50
|
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
50
51
|
state: { OnOff: { onOff: true }, LevelControl: { currentLevel: 200 }, ColorControl: { colorTemperatureMireds: 370 } },
|
|
51
52
|
},
|
|
52
53
|
{
|
|
53
54
|
id: 'test-extended-color-light',
|
|
54
55
|
name: 'Extended Color Light',
|
|
55
|
-
deviceTypes: ['
|
|
56
|
+
deviceTypes: ['ExtendedColorLight', 'PowerSource'],
|
|
56
57
|
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
57
58
|
state: { OnOff: { onOff: true }, LevelControl: { currentLevel: 200 }, ColorControl: { currentHue: 128, currentSaturation: 200 } },
|
|
58
59
|
},
|
|
59
60
|
{
|
|
60
61
|
id: 'test-onoff-plugin-unit',
|
|
61
62
|
name: 'OnOff Plugin Unit',
|
|
62
|
-
deviceTypes: ['
|
|
63
|
+
deviceTypes: ['OnOffPlugInUnit', 'PowerSource'],
|
|
63
64
|
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
64
65
|
state: { OnOff: { onOff: false } },
|
|
65
66
|
},
|
|
66
67
|
{
|
|
67
68
|
id: 'test-dimmable-plugin-unit',
|
|
68
69
|
name: 'Dimmable PlugIn Unit',
|
|
69
|
-
deviceTypes: ['
|
|
70
|
+
deviceTypes: ['DimmablePlugInUnit', 'PowerSource'],
|
|
70
71
|
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
71
72
|
state: { OnOff: { onOff: true }, LevelControl: { currentLevel: 200 } },
|
|
72
73
|
},
|
|
73
74
|
{
|
|
74
75
|
id: 'test-mounted-onoff-control',
|
|
75
76
|
name: 'Mounted OnOff Control',
|
|
76
|
-
deviceTypes: ['
|
|
77
|
+
deviceTypes: ['MountedOnOffControl', 'PowerSource'],
|
|
77
78
|
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
78
79
|
state: { OnOff: { onOff: false } },
|
|
79
80
|
},
|
|
80
81
|
{
|
|
81
82
|
id: 'test-mounted-dimmable-control',
|
|
82
83
|
name: 'Mounted Dimmable Load Control',
|
|
83
|
-
deviceTypes: ['
|
|
84
|
+
deviceTypes: ['MountedDimmableLoadControl', 'PowerSource'],
|
|
84
85
|
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
85
86
|
state: { OnOff: { onOff: false }, LevelControl: { currentLevel: 100 } },
|
|
86
87
|
},
|
|
87
88
|
{
|
|
88
89
|
id: 'test-pump',
|
|
89
90
|
name: 'Pump',
|
|
90
|
-
deviceTypes: ['Pump', '
|
|
91
|
+
deviceTypes: ['Pump', 'PowerSource'],
|
|
91
92
|
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
92
93
|
state: { OnOff: { onOff: false }, PumpConfigurationAndControl: { effectiveOperationMode: 0, effectiveControlMode: 0 } },
|
|
93
94
|
},
|
|
94
95
|
{
|
|
95
96
|
id: 'test-water-valve',
|
|
96
97
|
name: 'Water Valve',
|
|
97
|
-
deviceTypes: ['
|
|
98
|
+
deviceTypes: ['WaterValve', 'PowerSource'],
|
|
98
99
|
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
99
|
-
state: { ValveConfigurationAndControl: { currentState:
|
|
100
|
+
state: { ValveConfigurationAndControl: { currentState: ValveConfigurationAndControl.ValveState.Closed, targetState: ValveConfigurationAndControl.ValveState.Closed } },
|
|
100
101
|
},
|
|
101
102
|
{
|
|
102
103
|
id: 'test-contact-sensor',
|
|
103
104
|
name: 'Contact Sensor',
|
|
104
|
-
deviceTypes: ['
|
|
105
|
+
deviceTypes: ['ContactSensor', 'PowerSource'],
|
|
105
106
|
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 200 } },
|
|
106
107
|
state: { BooleanState: { stateValue: false } },
|
|
107
108
|
},
|
|
108
109
|
{
|
|
109
110
|
id: 'test-light-sensor',
|
|
110
111
|
name: 'Light Sensor',
|
|
111
|
-
deviceTypes: ['
|
|
112
|
+
deviceTypes: ['LightSensor', 'PowerSource'],
|
|
112
113
|
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 200 } },
|
|
113
114
|
state: { IlluminanceMeasurement: { measuredValue: 10000 } },
|
|
114
115
|
},
|
|
115
116
|
{
|
|
116
117
|
id: 'test-occupancy-sensor',
|
|
117
118
|
name: 'Occupancy Sensor',
|
|
118
|
-
deviceTypes: ['
|
|
119
|
+
deviceTypes: ['OccupancySensor', 'PowerSource'],
|
|
119
120
|
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 200 } },
|
|
120
121
|
state: { OccupancySensing: { occupancy: { occupied: false } } },
|
|
121
122
|
},
|
|
122
123
|
{
|
|
123
124
|
id: 'test-temperature-sensor',
|
|
124
125
|
name: 'Temperature Sensor',
|
|
125
|
-
deviceTypes: ['
|
|
126
|
+
deviceTypes: ['TemperatureSensor', 'PowerSource'],
|
|
126
127
|
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 180 } },
|
|
127
128
|
state: { TemperatureMeasurement: { measuredValue: 2100 } },
|
|
128
129
|
},
|
|
129
130
|
{
|
|
130
131
|
id: 'test-pressure-sensor',
|
|
131
132
|
name: 'Pressure Sensor',
|
|
132
|
-
deviceTypes: ['
|
|
133
|
+
deviceTypes: ['PressureSensor', 'PowerSource'],
|
|
133
134
|
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 160 } },
|
|
134
135
|
state: { PressureMeasurement: { measuredValue: 1013 } },
|
|
135
136
|
},
|
|
136
137
|
{
|
|
137
138
|
id: 'test-flow-sensor',
|
|
138
139
|
name: 'Flow Sensor',
|
|
139
|
-
deviceTypes: ['
|
|
140
|
+
deviceTypes: ['FlowSensor', 'PowerSource'],
|
|
140
141
|
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 140 } },
|
|
141
142
|
state: { FlowMeasurement: { measuredValue: 100 } },
|
|
142
143
|
},
|
|
143
144
|
{
|
|
144
145
|
id: 'test-humidity-sensor',
|
|
145
146
|
name: 'Humidity Sensor',
|
|
146
|
-
deviceTypes: ['
|
|
147
|
+
deviceTypes: ['HumiditySensor', 'PowerSource'],
|
|
147
148
|
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 130 } },
|
|
148
149
|
state: { RelativeHumidityMeasurement: { measuredValue: 5500 } },
|
|
149
150
|
},
|
|
150
151
|
{
|
|
151
152
|
id: 'test-smoke-co-alarm',
|
|
152
153
|
name: 'Smoke CO Alarm',
|
|
153
|
-
deviceTypes: ['
|
|
154
|
+
deviceTypes: ['SmokeCOAlarm', 'PowerSource'],
|
|
154
155
|
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 200 } },
|
|
155
|
-
state: { SmokeCoAlarm: { smokeState:
|
|
156
|
+
state: { SmokeCoAlarm: { smokeState: SmokeCoAlarm.AlarmState.Normal, coState: SmokeCoAlarm.AlarmState.Normal } },
|
|
156
157
|
},
|
|
157
158
|
{
|
|
158
159
|
id: 'test-air-quality-sensor',
|
|
159
160
|
name: 'Air Quality Sensor',
|
|
160
|
-
deviceTypes: ['
|
|
161
|
-
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 200 } },
|
|
162
|
-
state: { AirQuality: { airQuality:
|
|
161
|
+
deviceTypes: ['AirQualitySensor', 'PowerSource'],
|
|
162
|
+
configClusters: { PowerSource: { batChargeState: PowerSource.BatChargeState.IsNotCharging, batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 200 } },
|
|
163
|
+
state: { AirQuality: { airQuality: AirQuality.AirQualityEnum.Good } },
|
|
163
164
|
},
|
|
164
165
|
{
|
|
165
166
|
id: 'test-water-freeze-detector',
|
|
166
167
|
name: 'Water Freeze Detector',
|
|
167
|
-
deviceTypes: ['
|
|
168
|
+
deviceTypes: ['WaterFreezeDetector', 'PowerSource'],
|
|
168
169
|
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 170 } },
|
|
169
170
|
state: { BooleanState: { stateValue: false } },
|
|
170
171
|
},
|
|
171
172
|
{
|
|
172
173
|
id: 'test-water-leak-detector',
|
|
173
174
|
name: 'Water Leak Detector',
|
|
174
|
-
deviceTypes: ['
|
|
175
|
+
deviceTypes: ['WaterLeakDetector', 'PowerSource'],
|
|
175
176
|
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 150 } },
|
|
176
177
|
state: { BooleanState: { stateValue: false } },
|
|
177
178
|
},
|
|
178
179
|
{
|
|
179
180
|
id: 'test-rain-sensor',
|
|
180
181
|
name: 'Rain Sensor',
|
|
181
|
-
deviceTypes: ['
|
|
182
|
+
deviceTypes: ['RainSensor', 'PowerSource'],
|
|
182
183
|
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 160 } },
|
|
183
184
|
state: { BooleanState: { stateValue: false } },
|
|
184
185
|
},
|
|
185
186
|
{
|
|
186
187
|
id: 'test-soil-sensor',
|
|
187
188
|
name: 'Soil Sensor',
|
|
188
|
-
deviceTypes: ['
|
|
189
|
+
deviceTypes: ['SoilSensor', 'PowerSource'],
|
|
189
190
|
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 140 } },
|
|
190
191
|
state: { SoilMeasurement: { soilMoistureMeasuredValue: 60 } },
|
|
191
192
|
},
|
|
@@ -194,9 +195,8 @@ const clientOptions = {
|
|
|
194
195
|
port: config.port,
|
|
195
196
|
protocolVersion: config.protocolVersion,
|
|
196
197
|
rejectUnauthorized: config.rejectUnauthorized,
|
|
198
|
+
clientId: `test-${Math.random().toString(16).slice(2, 8)}`,
|
|
197
199
|
};
|
|
198
|
-
if (config.clientId)
|
|
199
|
-
clientOptions.clientId = config.clientId;
|
|
200
200
|
if (config.username)
|
|
201
201
|
clientOptions.username = config.username;
|
|
202
202
|
if (config.password)
|
|
@@ -225,9 +225,9 @@ for (const device of DEVICES) {
|
|
|
225
225
|
const statePayload = JSON.stringify(device.state);
|
|
226
226
|
const configTopic = `${baseTopic}/${device.id}/config/root`;
|
|
227
227
|
const stateTopic = `${baseTopic}/${device.id}/state/root`;
|
|
228
|
-
await client.publishAsync(configTopic, configPayload, pubOptions);
|
|
229
|
-
await client.publishAsync(stateTopic, statePayload, pubOptions);
|
|
230
|
-
console.log(
|
|
228
|
+
await client.publishAsync(configTopic, hasParameter('delete') ? '' : configPayload, pubOptions);
|
|
229
|
+
await client.publishAsync(stateTopic, hasParameter('delete') ? '' : statePayload, pubOptions);
|
|
230
|
+
console.log(`${hasParameter('delete') ? 'Deleted' : 'Published'} [${device.name}]`);
|
|
231
231
|
console.log(` config → ${configTopic}`);
|
|
232
232
|
console.log(` state → ${stateTopic}`);
|
|
233
233
|
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matterbridge-mqtt",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5-dev-20260609-e4b3a62",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "matterbridge-mqtt",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.5-dev-20260609-e4b3a62",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"mqtt": "5.15.1",
|