@rfranzoi/scrypted-mqtt-securitysystem 1.0.41 → 1.0.43
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 +16 -23
- package/dist/plugin.zip +0 -0
- package/package.json +1 -1
package/dist/main.nodejs.js
CHANGED
|
@@ -34044,9 +34044,7 @@ const sdk = __webpack_require__(/*! @scrypted/sdk */ "./node_modules/@scrypted/s
|
|
|
34044
34044
|
// Valori runtime (enum/classi/manager) dal modulo SDK
|
|
34045
34045
|
const { ScryptedDeviceBase, ScryptedDeviceType, ScryptedInterface, // valore (enum)
|
|
34046
34046
|
SecuritySystemMode, // valore (enum)
|
|
34047
|
-
systemManager,
|
|
34048
|
-
// ⚠️ NON destrutturare deviceManager: va letto sempre "al volo" da sdk.deviceManager.
|
|
34049
|
-
} = sdk;
|
|
34047
|
+
systemManager, deviceManager, } = sdk;
|
|
34050
34048
|
const mqtt_1 = __importDefault(__webpack_require__(/*! mqtt */ "./node_modules/mqtt/build/index.js"));
|
|
34051
34049
|
/** utils */
|
|
34052
34050
|
function truthy(v) {
|
|
@@ -34292,7 +34290,7 @@ class ParadoxMqttSecuritySystem extends ScryptedDeviceBase {
|
|
|
34292
34290
|
this.saveSensorsToStorage();
|
|
34293
34291
|
try {
|
|
34294
34292
|
this.devices.delete(`sensor:${sid}`);
|
|
34295
|
-
|
|
34293
|
+
deviceManager.onDeviceRemoved?.(`sensor:${sid}`);
|
|
34296
34294
|
}
|
|
34297
34295
|
catch { }
|
|
34298
34296
|
// pulisci flag
|
|
@@ -34338,7 +34336,7 @@ class ParadoxMqttSecuritySystem extends ScryptedDeviceBase {
|
|
|
34338
34336
|
this.devices.delete(nativeId);
|
|
34339
34337
|
}
|
|
34340
34338
|
try {
|
|
34341
|
-
|
|
34339
|
+
deviceManager.onDeviceRemoved?.(nativeId);
|
|
34342
34340
|
}
|
|
34343
34341
|
catch { }
|
|
34344
34342
|
}
|
|
@@ -34358,48 +34356,42 @@ class ParadoxMqttSecuritySystem extends ScryptedDeviceBase {
|
|
|
34358
34356
|
this.sensorsCfg = [];
|
|
34359
34357
|
}
|
|
34360
34358
|
}
|
|
34361
|
-
/** ===== discoverSensors: annuncia PRIMA, istanzia DOPO
|
|
34359
|
+
/** ===== discoverSensors: annuncia PRIMA, istanzia DOPO ===== */
|
|
34362
34360
|
async discoverSensors() {
|
|
34363
|
-
|
|
34364
|
-
if (!dmAny) {
|
|
34365
|
-
this.console.warn('deviceManager not ready yet, retrying in 1s…');
|
|
34366
|
-
setTimeout(() => this.discoverSensors().catch(e => this.console.error('discoverSensors retry error', e)), 1000);
|
|
34367
|
-
return;
|
|
34368
|
-
}
|
|
34369
|
-
// 1) Prepara i manifest
|
|
34361
|
+
// 1) Prepara i manifest (niente istanze qui)
|
|
34370
34362
|
const manifests = this.sensorsCfg.map(cfg => {
|
|
34371
34363
|
const nativeId = `sensor:${cfg.id}`;
|
|
34372
34364
|
const t = cfg.topics || {};
|
|
34373
34365
|
const interfaces = [ScryptedInterface.Online];
|
|
34366
|
+
// Tamper solo se c'è un topic tamper
|
|
34374
34367
|
if (t.tamper)
|
|
34375
34368
|
interfaces.push(ScryptedInterface.TamperSensor);
|
|
34369
|
+
// Interfaccia primaria
|
|
34376
34370
|
if (cfg.kind === 'contact')
|
|
34377
34371
|
interfaces.unshift(ScryptedInterface.EntrySensor);
|
|
34378
34372
|
else if (cfg.kind === 'motion')
|
|
34379
34373
|
interfaces.unshift(ScryptedInterface.MotionSensor);
|
|
34380
34374
|
else
|
|
34381
34375
|
interfaces.unshift(ScryptedInterface.OccupancySensor);
|
|
34382
|
-
|
|
34376
|
+
// Battery solo se previsto
|
|
34377
|
+
if (t.batteryLevel || t.lowBattery) {
|
|
34383
34378
|
interfaces.push(ScryptedInterface.Battery);
|
|
34379
|
+
}
|
|
34384
34380
|
return { nativeId, name: cfg.name, type: ScryptedDeviceType.Sensor, interfaces };
|
|
34385
34381
|
});
|
|
34386
34382
|
// 2) Annuncio
|
|
34383
|
+
const dmAny = deviceManager;
|
|
34387
34384
|
if (typeof dmAny.onDevicesChanged === 'function') {
|
|
34388
34385
|
dmAny.onDevicesChanged({ devices: manifests });
|
|
34389
34386
|
this.console.log('Annunciati (batch):', manifests.map(m => m.nativeId).join(', '));
|
|
34390
34387
|
}
|
|
34391
|
-
else
|
|
34388
|
+
else {
|
|
34392
34389
|
for (const m of manifests) {
|
|
34393
|
-
|
|
34390
|
+
deviceManager.onDeviceDiscovered(m);
|
|
34394
34391
|
this.console.log('Annunciato:', m.nativeId);
|
|
34395
34392
|
}
|
|
34396
34393
|
}
|
|
34397
|
-
|
|
34398
|
-
this.console.warn('deviceManager has no discovery methods yet, retrying in 1s…');
|
|
34399
|
-
setTimeout(() => this.discoverSensors().catch(e => this.console.error('discoverSensors retry error', e)), 1000);
|
|
34400
|
-
return;
|
|
34401
|
-
}
|
|
34402
|
-
// 3) Istanzia/aggiorna
|
|
34394
|
+
// 3) Istanzia/aggiorna DOPO l’annuncio
|
|
34403
34395
|
for (const cfg of this.sensorsCfg) {
|
|
34404
34396
|
const nativeId = `sensor:${cfg.id}`;
|
|
34405
34397
|
let dev = this.devices.get(nativeId);
|
|
@@ -34415,6 +34407,7 @@ class ParadoxMqttSecuritySystem extends ScryptedDeviceBase {
|
|
|
34415
34407
|
else {
|
|
34416
34408
|
dev.cfg = cfg;
|
|
34417
34409
|
}
|
|
34410
|
+
// Default “OK” se abbiamo Battery ma nessun valore ancora ricevuto
|
|
34418
34411
|
const hasBattery = !!(cfg.topics.batteryLevel || cfg.topics.lowBattery);
|
|
34419
34412
|
if (hasBattery && dev.batteryLevel === undefined) {
|
|
34420
34413
|
dev.batteryLevel = 100;
|
|
@@ -34426,7 +34419,7 @@ class ParadoxMqttSecuritySystem extends ScryptedDeviceBase {
|
|
|
34426
34419
|
if (!announced.has(nativeId)) {
|
|
34427
34420
|
try {
|
|
34428
34421
|
this.devices.delete(nativeId);
|
|
34429
|
-
|
|
34422
|
+
deviceManager.onDeviceRemoved?.(nativeId);
|
|
34430
34423
|
this.console.log('Rimosso:', nativeId);
|
|
34431
34424
|
}
|
|
34432
34425
|
catch { }
|
package/dist/plugin.zip
CHANGED
|
Binary file
|
package/package.json
CHANGED