matterbridge-test 2.0.18 → 2.0.19

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
@@ -28,7 +28,7 @@ If you like this project and find it useful, please consider giving it a star on
28
28
 
29
29
  <a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="120"></a>
30
30
 
31
- ## [2.0.18] - 2026-06-05
31
+ ## [2.0.19] - 2026-06-05
32
32
 
33
33
  ### Breaking changes
34
34
 
package/dist/module.js CHANGED
@@ -199,18 +199,18 @@ export class TestPlatform extends MatterbridgeDynamicPlatform {
199
199
  this.log.info('Interval called');
200
200
  for (let i = 0; i < this.config.loadSwitches; i++) {
201
201
  const device = this.getDeviceByName('Switch ' + i);
202
- const state = device?.getAttribute(OnOff.id, 'onOff');
203
- await device?.setAttribute(OnOff.id, 'onOff', !state, device?.log);
202
+ const state = device?.getAttribute(OnOff, 'onOff');
203
+ await device?.setAttribute(OnOff, 'onOff', !state, device?.log);
204
204
  if (this.config.enableReachable)
205
- await device?.setAttribute(BridgedDeviceBasicInformation.id, 'reachable', state, device?.log);
205
+ await device?.setAttribute(BridgedDeviceBasicInformation, 'reachable', state ?? false, device?.log);
206
206
  if (this.config.enableElectrical) {
207
207
  const voltage = this.getRandomNumberInRange(220, 240);
208
208
  const current = this.getRandomNumberInRange(20, 30);
209
209
  await device?.setAttribute(ElectricalPowerMeasurement, 'voltage', voltage * 1000, device.log);
210
210
  await device?.setAttribute(ElectricalPowerMeasurement, 'activeCurrent', current * 1000, device.log);
211
211
  await device?.setAttribute(ElectricalPowerMeasurement, 'activePower', voltage * current * 1000, device.log);
212
- const cumulativeEnergy = device?.getAttribute(ElectricalEnergyMeasurement.id, 'cumulativeEnergyImported', device.log);
213
- await device?.setAttribute(ElectricalEnergyMeasurement, 'cumulativeEnergyImported', { energy: cumulativeEnergy ? cumulativeEnergy.energy + 1000 : 1500 * 1000 }, device.log);
212
+ const cumulativeEnergy = device?.getAttribute(ElectricalEnergyMeasurement, 'cumulativeEnergyImported', device.log);
213
+ await device?.setAttribute(ElectricalEnergyMeasurement, 'cumulativeEnergyImported', { energy: cumulativeEnergy ? Number(cumulativeEnergy.energy) + 1000 : 1500 * 1000 }, device.log);
214
214
  }
215
215
  if (this.config.enableModeSelect) {
216
216
  const composed = device?.getChildEndpointById(device.id + '_modeSelect');
@@ -227,57 +227,61 @@ export class TestPlatform extends MatterbridgeDynamicPlatform {
227
227
  }
228
228
  for (let i = 0; i < this.config.loadOutlets; i++) {
229
229
  const device = this.getDeviceByName('Outlet ' + i);
230
- const state = device?.getAttribute(OnOff.id, 'onOff');
231
- await device?.setAttribute(OnOff.id, 'onOff', !state, device?.log);
230
+ const state = device?.getAttribute(OnOff, 'onOff');
231
+ await device?.setAttribute(OnOff, 'onOff', !state, device?.log);
232
232
  if (this.config.enableReachable)
233
- await device?.setAttribute(BridgedDeviceBasicInformation, 'reachable', state, device?.log);
233
+ await device?.setAttribute(BridgedDeviceBasicInformation, 'reachable', state ?? false, device?.log);
234
234
  if (this.config.enableElectrical) {
235
235
  const voltage = this.getRandomNumberInRange(220, 240);
236
236
  const current = this.getRandomNumberInRange(20, 30);
237
- await device?.setAttribute(ElectricalPowerMeasurement.id, 'voltage', voltage * 1000, device.log);
238
- await device?.setAttribute(ElectricalPowerMeasurement.id, 'activeCurrent', current * 1000, device.log);
239
- await device?.setAttribute(ElectricalPowerMeasurement.id, 'activePower', voltage * current * 1000, device.log);
240
- const cumulativeEnergy = device?.getAttribute(ElectricalEnergyMeasurement.id, 'cumulativeEnergyImported', device.log);
241
- await device?.setAttribute(ElectricalEnergyMeasurement.id, 'cumulativeEnergyImported', { energy: cumulativeEnergy ? cumulativeEnergy.energy + 1000 : 1500 * 1000 }, device.log);
237
+ await device?.setAttribute(ElectricalPowerMeasurement, 'voltage', voltage * 1000, device.log);
238
+ await device?.setAttribute(ElectricalPowerMeasurement, 'activeCurrent', current * 1000, device.log);
239
+ await device?.setAttribute(ElectricalPowerMeasurement, 'activePower', voltage * current * 1000, device.log);
240
+ const cumulativeEnergy = device?.getAttribute(ElectricalEnergyMeasurement, 'cumulativeEnergyImported', device.log);
241
+ await device?.setAttribute(ElectricalEnergyMeasurement, 'cumulativeEnergyImported', { energy: cumulativeEnergy ? Number(cumulativeEnergy.energy) + 1000 : 1500 * 1000 }, device.log);
242
242
  }
243
243
  if (this.config.enableModeSelect) {
244
244
  const composed = device?.getChildEndpointById(device.id + '_modeSelect');
245
- const currentMode = composed?.getAttribute(ModeSelect.id, 'currentMode', device?.log);
246
- await composed?.setAttribute(ModeSelect.id, 'currentMode', currentMode === 1 ? 2 : 1, device?.log);
245
+ const currentMode = composed?.getAttribute(ModeSelect, 'currentMode', device?.log);
246
+ await composed?.setAttribute(ModeSelect, 'currentMode', currentMode === 1 ? 2 : 1, device?.log);
247
247
  }
248
248
  if (this.config.enablePowerSource) {
249
- if (device?.hasAttributeServer(PowerSource.id, 'batPercentRemaining')) {
250
- const battery = device?.getAttribute(PowerSource.id, 'batPercentRemaining', device?.log);
251
- await device?.setAttribute(PowerSource.id, 'batPercentRemaining', battery + 20 > 200 ? 20 : battery + 20, device?.log);
252
- await device?.setAttribute(PowerSource.id, 'batChargeLevel', battery + 20 > 200 ? PowerSource.BatChargeLevel.Critical : PowerSource.BatChargeLevel.Ok, device?.log);
249
+ if (device?.hasAttributeServer(PowerSource, 'batPercentRemaining')) {
250
+ const battery = device?.getAttribute(PowerSource, 'batPercentRemaining', device?.log);
251
+ if (battery) {
252
+ await device?.setAttribute(PowerSource, 'batPercentRemaining', battery + 20 > 200 ? 20 : battery + 20, device?.log);
253
+ await device?.setAttribute(PowerSource, 'batChargeLevel', battery + 20 > 200 ? PowerSource.BatChargeLevel.Critical : PowerSource.BatChargeLevel.Ok, device?.log);
254
+ }
253
255
  }
254
256
  }
255
257
  }
256
258
  for (let i = 0; i < this.config.loadLights; i++) {
257
259
  const device = this.getDeviceByName('Light ' + i);
258
- const state = device?.getAttribute(OnOff.id, 'onOff');
259
- await device?.setAttribute(OnOff.id, 'onOff', !state, device?.log);
260
+ const state = device?.getAttribute(OnOff, 'onOff');
261
+ await device?.setAttribute(OnOff, 'onOff', !state, device?.log);
260
262
  if (this.config.enableReachable)
261
- await device?.setAttribute(BridgedDeviceBasicInformation.id, 'reachable', state, device?.log);
263
+ await device?.setAttribute(BridgedDeviceBasicInformation, 'reachable', state ?? false, device?.log);
262
264
  if (this.config.enableElectrical) {
263
265
  const voltage = this.getRandomNumberInRange(220, 240);
264
266
  const current = this.getRandomNumberInRange(20, 30);
265
- await device?.setAttribute(ElectricalPowerMeasurement.id, 'voltage', voltage * 1000, device.log);
266
- await device?.setAttribute(ElectricalPowerMeasurement.id, 'activeCurrent', current * 1000, device.log);
267
- await device?.setAttribute(ElectricalPowerMeasurement.id, 'activePower', voltage * current * 1000, device.log);
268
- const cumulativeEnergy = device?.getAttribute(ElectricalEnergyMeasurement.id, 'cumulativeEnergyImported', device.log);
269
- await device?.setAttribute(ElectricalEnergyMeasurement.id, 'cumulativeEnergyImported', { energy: cumulativeEnergy ? cumulativeEnergy.energy + 1000 : 1500 * 1000 }, device.log);
267
+ await device?.setAttribute(ElectricalPowerMeasurement, 'voltage', voltage * 1000, device.log);
268
+ await device?.setAttribute(ElectricalPowerMeasurement, 'activeCurrent', current * 1000, device.log);
269
+ await device?.setAttribute(ElectricalPowerMeasurement, 'activePower', voltage * current * 1000, device.log);
270
+ const cumulativeEnergy = device?.getAttribute(ElectricalEnergyMeasurement, 'cumulativeEnergyImported', device.log);
271
+ await device?.setAttribute(ElectricalEnergyMeasurement, 'cumulativeEnergyImported', { energy: cumulativeEnergy ? Number(cumulativeEnergy.energy) + 1000 : 1500 * 1000 }, device.log);
270
272
  }
271
273
  if (this.config.enableModeSelect) {
272
274
  const composed = device?.getChildEndpointById(device.id + '_modeSelect');
273
- const currentMode = composed?.getAttribute(ModeSelect.id, 'currentMode', device?.log);
274
- await composed?.setAttribute(ModeSelect.id, 'currentMode', currentMode === 1 ? 2 : 1, device?.log);
275
+ const currentMode = composed?.getAttribute(ModeSelect, 'currentMode', device?.log);
276
+ await composed?.setAttribute(ModeSelect, 'currentMode', currentMode === 1 ? 2 : 1, device?.log);
275
277
  }
276
278
  if (this.config.enablePowerSource) {
277
- if (device?.hasAttributeServer(PowerSource.id, 'batPercentRemaining')) {
278
- const battery = device?.getAttribute(PowerSource.id, 'batPercentRemaining', device?.log);
279
- await device?.setAttribute(PowerSource.id, 'batPercentRemaining', battery + 20 > 200 ? 20 : battery + 20, device?.log);
280
- await device?.setAttribute(PowerSource.id, 'batChargeLevel', battery + 20 > 200 ? PowerSource.BatChargeLevel.Critical : PowerSource.BatChargeLevel.Ok, device?.log);
279
+ if (device?.hasAttributeServer(PowerSource, 'batPercentRemaining')) {
280
+ const battery = device?.getAttribute(PowerSource, 'batPercentRemaining', device?.log);
281
+ if (battery) {
282
+ await device?.setAttribute(PowerSource, 'batPercentRemaining', battery + 20 > 200 ? 20 : battery + 20, device?.log);
283
+ await device?.setAttribute(PowerSource, 'batChargeLevel', battery + 20 > 200 ? PowerSource.BatChargeLevel.Critical : PowerSource.BatChargeLevel.Ok, device?.log);
284
+ }
281
285
  }
282
286
  }
283
287
  }
@@ -315,23 +319,23 @@ export class TestPlatform extends MatterbridgeDynamicPlatform {
315
319
  if (action === 'turnOn') {
316
320
  this.log.info('Turning on all the devices');
317
321
  for (const device of this.getDevices()) {
318
- await device.setAttribute(BridgedDeviceBasicInformation.id, 'reachable', true, device.log);
319
- await device.setAttribute(OnOff.id, 'onOff', true, device.log);
322
+ await device.setAttribute(BridgedDeviceBasicInformation, 'reachable', true, device.log);
323
+ await device.setAttribute(OnOff, 'onOff', true, device.log);
320
324
  }
321
325
  }
322
326
  if (action === 'turnOff') {
323
327
  this.log.info('Turning off all the devices');
324
328
  for (const device of this.getDevices()) {
325
- await device.setAttribute(BridgedDeviceBasicInformation.id, 'reachable', true, device.log);
326
- await device.setAttribute(OnOff.id, 'onOff', false, device.log);
329
+ await device.setAttribute(BridgedDeviceBasicInformation, 'reachable', true, device.log);
330
+ await device.setAttribute(OnOff, 'onOff', false, device.log);
327
331
  }
328
332
  }
329
333
  if (action === 'turnOnDevice' && isValidString(value, 5)) {
330
334
  this.log.info(`Turning on the device ${CYAN}${value}${nf}`);
331
335
  const device = this.getDeviceByName(value);
332
336
  if (device) {
333
- await device.setAttribute(BridgedDeviceBasicInformation.id, 'reachable', true, device.log);
334
- await device.setAttribute(OnOff.id, 'onOff', true, device.log);
337
+ await device.setAttribute(BridgedDeviceBasicInformation, 'reachable', true, device.log);
338
+ await device.setAttribute(OnOff, 'onOff', true, device.log);
335
339
  }
336
340
  else {
337
341
  this.log.error(`Device ${CYAN}${value}${er} not found:`);
@@ -344,8 +348,8 @@ export class TestPlatform extends MatterbridgeDynamicPlatform {
344
348
  this.log.info(`Turning off the device ${CYAN}${value}${nf}`);
345
349
  const device = this.getDeviceByName(value);
346
350
  if (device) {
347
- await device.setAttribute(BridgedDeviceBasicInformation.id, 'reachable', true, device.log);
348
- await device.setAttribute(OnOff.id, 'onOff', false, device.log);
351
+ await device.setAttribute(BridgedDeviceBasicInformation, 'reachable', true, device.log);
352
+ await device.setAttribute(OnOff, 'onOff', false, device.log);
349
353
  }
350
354
  else {
351
355
  this.log.error(`Device ${CYAN}${value}${er} not found:`);
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "matterbridge-test",
3
- "version": "2.0.18",
3
+ "version": "2.0.19",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "matterbridge-test",
9
- "version": "2.0.18",
9
+ "version": "2.0.19",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "node-ansi-logger": "3.2.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matterbridge-test",
3
- "version": "2.0.18",
3
+ "version": "2.0.19",
4
4
  "description": "Matterbridge test plugin",
5
5
  "author": "https://github.com/Luligu",
6
6
  "license": "Apache-2.0",