@rfranzoi/scrypted-mqtt-securitysystem 1.0.18 → 1.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.
@@ -34303,30 +34303,34 @@ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
34303
34303
  this.sensorsCfg = [];
34304
34304
  }
34305
34305
  }
34306
- /** ===== discoverSensors con batch/fallback (FIX type) ===== */
34306
+ /** ===== discoverSensors con interfacce dinamiche (Battery/Tamper opzionali) ===== */
34307
34307
  async discoverSensors() {
34308
- // Prepara i manifest e istanzia/aggiorna le classi locali
34309
34308
  const manifests = this.sensorsCfg.map(cfg => {
34310
34309
  const nativeId = `sensor:${cfg.id}`;
34311
- let interfaces = [
34312
- sdk_1.ScryptedInterface.Online,
34313
- sdk_1.ScryptedInterface.TamperSensor,
34314
- sdk_1.ScryptedInterface.Battery,
34315
- ];
34316
- // Il tipo RESTA generico "Sensor" per compatibilità SDK,
34317
- // le capacità sono date dalle interfacce.
34318
- const type = sdk_1.ScryptedDeviceType.Sensor;
34310
+ const t = cfg.topics || {};
34311
+ // Interfacce di base: Online sempre
34312
+ const interfaces = [sdk_1.ScryptedInterface.Online];
34313
+ // Aggiungi primaria in base al kind
34319
34314
  switch (cfg.kind) {
34320
34315
  case 'contact':
34321
- interfaces = [sdk_1.ScryptedInterface.EntrySensor, ...interfaces];
34316
+ interfaces.unshift(sdk_1.ScryptedInterface.EntrySensor);
34322
34317
  break;
34323
34318
  case 'motion':
34324
- interfaces = [sdk_1.ScryptedInterface.MotionSensor, ...interfaces];
34319
+ interfaces.unshift(sdk_1.ScryptedInterface.MotionSensor);
34325
34320
  break;
34326
34321
  case 'occupancy':
34327
- interfaces = [sdk_1.ScryptedInterface.OccupancySensor, ...interfaces];
34322
+ interfaces.unshift(sdk_1.ScryptedInterface.OccupancySensor);
34328
34323
  break;
34329
34324
  }
34325
+ // Tamper solo se presente il topic
34326
+ if (t.tamper)
34327
+ interfaces.push(sdk_1.ScryptedInterface.TamperSensor);
34328
+ // Battery solo se presente batteryLevel o lowBattery
34329
+ if (t.batteryLevel || t.lowBattery)
34330
+ interfaces.push(sdk_1.ScryptedInterface.Battery);
34331
+ // Tipo generico "Sensor": le capacità sono date dalle interfacce
34332
+ const type = sdk_1.ScryptedDeviceType.Sensor;
34333
+ // create/update instance
34330
34334
  let dev = this.devices.get(nativeId);
34331
34335
  if (!dev) {
34332
34336
  if (cfg.kind === 'contact')
@@ -34339,6 +34343,13 @@ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
34339
34343
  }
34340
34344
  else {
34341
34345
  dev.cfg = cfg;
34346
+ // se non c'è più batteria nei topic, pulisci eventuale valore residuo
34347
+ if (!(t.batteryLevel || t.lowBattery)) {
34348
+ try {
34349
+ dev.batteryLevel = undefined;
34350
+ }
34351
+ catch { }
34352
+ }
34342
34353
  }
34343
34354
  return {
34344
34355
  nativeId,
@@ -34357,7 +34368,7 @@ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
34357
34368
  for (const m of manifests) {
34358
34369
  deviceManager.onDeviceDiscovered(m);
34359
34370
  this.console.log('Annunciato:', m.nativeId);
34360
- await new Promise(res => setTimeout(res, 50));
34371
+ await delay(50);
34361
34372
  }
34362
34373
  }
34363
34374
  // Rimuovi eventuali sensori non più presenti
package/dist/plugin.zip CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rfranzoi/scrypted-mqtt-securitysystem",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "Scrypted plugin: Paradox Security System via MQTT (PAI/PAI-MQTT style).",
5
5
  "license": "MIT",
6
6
  "main": "dist/main.nodejs.js",