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