@rfranzoi/scrypted-mqtt-securitysystem 1.0.17 → 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.
@@ -34083,6 +34083,9 @@ function normalize(s) {
34083
34083
  function clamp(n, min, max) {
34084
34084
  return Math.max(min, Math.min(max, n));
34085
34085
  }
34086
+ function delay(ms) {
34087
+ return new Promise(res => setTimeout(res, ms));
34088
+ }
34086
34089
  /** SecuritySystem outgoing defaults (PAI-like) */
34087
34090
  const DEFAULT_OUTGOING = {
34088
34091
  [sdk_1.SecuritySystemMode.Disarmed]: 'disarm',
@@ -34275,12 +34278,10 @@ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
34275
34278
  }
34276
34279
  async releaseDevice(id, nativeId) {
34277
34280
  try {
34278
- // chiudi e rimuovi l’istanza locale se esiste
34279
34281
  const dev = this.devices.get(nativeId);
34280
34282
  if (dev) {
34281
34283
  this.devices.delete(nativeId);
34282
34284
  }
34283
- // notifica (best effort) la rimozione al device manager
34284
34285
  try {
34285
34286
  deviceManager.onDeviceRemoved?.(nativeId);
34286
34287
  }
@@ -34302,29 +34303,33 @@ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
34302
34303
  this.sensorsCfg = [];
34303
34304
  }
34304
34305
  }
34306
+ /** ===== discoverSensors con interfacce dinamiche (Battery/Tamper opzionali) ===== */
34305
34307
  async discoverSensors() {
34306
- const announced = new Set();
34307
- for (const cfg of this.sensorsCfg) {
34308
+ const manifests = this.sensorsCfg.map(cfg => {
34308
34309
  const nativeId = `sensor:${cfg.id}`;
34309
- announced.add(nativeId);
34310
- let interfaces = [sdk_1.ScryptedInterface.Online, sdk_1.ScryptedInterface.TamperSensor, sdk_1.ScryptedInterface.Battery];
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
34311
34314
  switch (cfg.kind) {
34312
34315
  case 'contact':
34313
- interfaces = [sdk_1.ScryptedInterface.EntrySensor, ...interfaces];
34316
+ interfaces.unshift(sdk_1.ScryptedInterface.EntrySensor);
34314
34317
  break;
34315
34318
  case 'motion':
34316
- interfaces = [sdk_1.ScryptedInterface.MotionSensor, ...interfaces];
34319
+ interfaces.unshift(sdk_1.ScryptedInterface.MotionSensor);
34317
34320
  break;
34318
34321
  case 'occupancy':
34319
- interfaces = [sdk_1.ScryptedInterface.OccupancySensor, ...interfaces];
34322
+ interfaces.unshift(sdk_1.ScryptedInterface.OccupancySensor);
34320
34323
  break;
34321
34324
  }
34322
- deviceManager.onDeviceDiscovered({
34323
- nativeId,
34324
- name: cfg.name,
34325
- type: sdk_1.ScryptedDeviceType.Sensor,
34326
- interfaces,
34327
- });
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;
34328
34333
  // create/update instance
34329
34334
  let dev = this.devices.get(nativeId);
34330
34335
  if (!dev) {
@@ -34337,16 +34342,43 @@ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
34337
34342
  this.devices.set(nativeId, dev);
34338
34343
  }
34339
34344
  else {
34340
- // update config reference
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
+ }
34353
+ }
34354
+ return {
34355
+ nativeId,
34356
+ name: cfg.name,
34357
+ type,
34358
+ interfaces,
34359
+ };
34360
+ });
34361
+ // Annuncio in batch se disponibile, altrimenti uno per volta con un piccolo delay
34362
+ const dm = deviceManager;
34363
+ if (typeof dm.onDevicesChanged === 'function') {
34364
+ dm.onDevicesChanged({ devices: manifests });
34365
+ this.console.log('Annunciati (batch):', manifests.map(m => m.nativeId).join(', '));
34366
+ }
34367
+ else {
34368
+ for (const m of manifests) {
34369
+ deviceManager.onDeviceDiscovered(m);
34370
+ this.console.log('Annunciato:', m.nativeId);
34371
+ await delay(50);
34342
34372
  }
34343
34373
  }
34344
- // drop removed sensors
34374
+ // Rimuovi eventuali sensori non più presenti
34375
+ const announced = new Set(manifests.map(m => m.nativeId));
34345
34376
  for (const [nativeId] of this.devices) {
34346
34377
  if (!announced.has(nativeId)) {
34347
34378
  try {
34348
34379
  this.devices.delete(nativeId);
34349
34380
  deviceManager.onDeviceRemoved?.(nativeId);
34381
+ this.console.log('Rimosso:', nativeId);
34350
34382
  }
34351
34383
  catch { }
34352
34384
  }
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.17",
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",