@rfranzoi/scrypted-mqtt-securitysystem 1.0.17 → 1.0.18
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/dist/main.nodejs.js +36 -15
- package/dist/plugin.zip +0 -0
- package/package.json +1 -1
package/dist/main.nodejs.js
CHANGED
|
@@ -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,12 +34303,19 @@ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
|
|
|
34302
34303
|
this.sensorsCfg = [];
|
|
34303
34304
|
}
|
|
34304
34305
|
}
|
|
34306
|
+
/** ===== discoverSensors con batch/fallback (FIX type) ===== */
|
|
34305
34307
|
async discoverSensors() {
|
|
34306
|
-
|
|
34307
|
-
|
|
34308
|
+
// Prepara i manifest e istanzia/aggiorna le classi locali
|
|
34309
|
+
const manifests = this.sensorsCfg.map(cfg => {
|
|
34308
34310
|
const nativeId = `sensor:${cfg.id}`;
|
|
34309
|
-
|
|
34310
|
-
|
|
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;
|
|
34311
34319
|
switch (cfg.kind) {
|
|
34312
34320
|
case 'contact':
|
|
34313
34321
|
interfaces = [sdk_1.ScryptedInterface.EntrySensor, ...interfaces];
|
|
@@ -34319,13 +34327,6 @@ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
|
|
|
34319
34327
|
interfaces = [sdk_1.ScryptedInterface.OccupancySensor, ...interfaces];
|
|
34320
34328
|
break;
|
|
34321
34329
|
}
|
|
34322
|
-
deviceManager.onDeviceDiscovered({
|
|
34323
|
-
nativeId,
|
|
34324
|
-
name: cfg.name,
|
|
34325
|
-
type: sdk_1.ScryptedDeviceType.Sensor,
|
|
34326
|
-
interfaces,
|
|
34327
|
-
});
|
|
34328
|
-
// create/update instance
|
|
34329
34330
|
let dev = this.devices.get(nativeId);
|
|
34330
34331
|
if (!dev) {
|
|
34331
34332
|
if (cfg.kind === 'contact')
|
|
@@ -34337,16 +34338,36 @@ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
|
|
|
34337
34338
|
this.devices.set(nativeId, dev);
|
|
34338
34339
|
}
|
|
34339
34340
|
else {
|
|
34340
|
-
// update config reference
|
|
34341
34341
|
dev.cfg = cfg;
|
|
34342
34342
|
}
|
|
34343
|
+
return {
|
|
34344
|
+
nativeId,
|
|
34345
|
+
name: cfg.name,
|
|
34346
|
+
type,
|
|
34347
|
+
interfaces,
|
|
34348
|
+
};
|
|
34349
|
+
});
|
|
34350
|
+
// Annuncio in batch se disponibile, altrimenti uno per volta con un piccolo delay
|
|
34351
|
+
const dm = deviceManager;
|
|
34352
|
+
if (typeof dm.onDevicesChanged === 'function') {
|
|
34353
|
+
dm.onDevicesChanged({ devices: manifests });
|
|
34354
|
+
this.console.log('Annunciati (batch):', manifests.map(m => m.nativeId).join(', '));
|
|
34355
|
+
}
|
|
34356
|
+
else {
|
|
34357
|
+
for (const m of manifests) {
|
|
34358
|
+
deviceManager.onDeviceDiscovered(m);
|
|
34359
|
+
this.console.log('Annunciato:', m.nativeId);
|
|
34360
|
+
await new Promise(res => setTimeout(res, 50));
|
|
34361
|
+
}
|
|
34343
34362
|
}
|
|
34344
|
-
//
|
|
34363
|
+
// Rimuovi eventuali sensori non più presenti
|
|
34364
|
+
const announced = new Set(manifests.map(m => m.nativeId));
|
|
34345
34365
|
for (const [nativeId] of this.devices) {
|
|
34346
34366
|
if (!announced.has(nativeId)) {
|
|
34347
34367
|
try {
|
|
34348
34368
|
this.devices.delete(nativeId);
|
|
34349
34369
|
deviceManager.onDeviceRemoved?.(nativeId);
|
|
34370
|
+
this.console.log('Rimosso:', nativeId);
|
|
34350
34371
|
}
|
|
34351
34372
|
catch { }
|
|
34352
34373
|
}
|
package/dist/plugin.zip
CHANGED
|
Binary file
|
package/package.json
CHANGED