@rfranzoi/scrypted-mqtt-securitysystem 1.0.45 → 1.0.46
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 +88 -25
- package/dist/plugin.zip +0 -0
- package/package.json +1 -1
package/dist/main.nodejs.js
CHANGED
|
@@ -34112,7 +34112,19 @@ class BaseMqttSensor extends sdk_1.ScryptedDeviceBase {
|
|
|
34112
34112
|
constructor(nativeId, cfg) {
|
|
34113
34113
|
super(nativeId);
|
|
34114
34114
|
this.cfg = cfg;
|
|
34115
|
-
|
|
34115
|
+
}
|
|
34116
|
+
/** setter centralizzato: cambia lo stato SOLO se diverso e poi emette l'evento relativo */
|
|
34117
|
+
setAndEmit(prop, val, iface) {
|
|
34118
|
+
const prev = this[prop];
|
|
34119
|
+
if (prev === val)
|
|
34120
|
+
return;
|
|
34121
|
+
this[prop] = val;
|
|
34122
|
+
try {
|
|
34123
|
+
this.onDeviceEvent(iface, val);
|
|
34124
|
+
}
|
|
34125
|
+
catch (e) {
|
|
34126
|
+
this.console?.warn?.('onDeviceEvent error', iface, e);
|
|
34127
|
+
}
|
|
34116
34128
|
}
|
|
34117
34129
|
/** Called by parent on each MQTT message */
|
|
34118
34130
|
handleMqtt(topic, payload) {
|
|
@@ -34121,62 +34133,75 @@ class BaseMqttSensor extends sdk_1.ScryptedDeviceBase {
|
|
|
34121
34133
|
// online
|
|
34122
34134
|
if (topic === this.cfg.topics.online) {
|
|
34123
34135
|
if (truthy(np) || np === 'online')
|
|
34124
|
-
this.online
|
|
34136
|
+
this.setAndEmit('online', true, sdk_1.ScryptedInterface.Online);
|
|
34125
34137
|
if (falsy(np) || np === 'offline')
|
|
34126
|
-
this.online
|
|
34138
|
+
this.setAndEmit('online', false, sdk_1.ScryptedInterface.Online);
|
|
34127
34139
|
}
|
|
34128
34140
|
// tamper
|
|
34129
34141
|
if (topic === this.cfg.topics.tamper) {
|
|
34130
34142
|
if (truthy(np) || ['tamper', 'intrusion', 'cover', 'motion', 'magnetic'].includes(np)) {
|
|
34131
|
-
|
|
34143
|
+
const value = ['cover', 'intrusion', 'motion', 'magnetic'].find(x => x === np) || true;
|
|
34144
|
+
this.setAndEmit('tampered', value, sdk_1.ScryptedInterface.TamperSensor);
|
|
34132
34145
|
}
|
|
34133
34146
|
else if (falsy(np)) {
|
|
34134
|
-
this.tampered
|
|
34147
|
+
this.setAndEmit('tampered', false, sdk_1.ScryptedInterface.TamperSensor);
|
|
34135
34148
|
}
|
|
34136
34149
|
}
|
|
34137
34150
|
// battery
|
|
34138
34151
|
if (topic === this.cfg.topics.batteryLevel) {
|
|
34139
34152
|
const n = clamp(parseFloat(p), 0, 100);
|
|
34140
34153
|
if (isFinite(n))
|
|
34141
|
-
this.batteryLevel
|
|
34154
|
+
this.setAndEmit('batteryLevel', n, sdk_1.ScryptedInterface.Battery);
|
|
34142
34155
|
}
|
|
34143
34156
|
else if (topic === this.cfg.topics.lowBattery && !this.cfg.topics.batteryLevel) {
|
|
34144
34157
|
// Solo se abbiamo lowBattery (booleano) ma NON batteryLevel:
|
|
34145
|
-
|
|
34146
|
-
// False -> 100% (ok)
|
|
34147
|
-
this.batteryLevel = truthy(np) ? 10 : 100;
|
|
34158
|
+
this.setAndEmit('batteryLevel', truthy(np) ? 10 : 100, sdk_1.ScryptedInterface.Battery);
|
|
34148
34159
|
}
|
|
34149
34160
|
// primary handled by subclasses
|
|
34150
34161
|
this.handlePrimary(topic, np, p);
|
|
34151
34162
|
}
|
|
34152
34163
|
}
|
|
34153
34164
|
class ContactMqttSensor extends BaseMqttSensor {
|
|
34154
|
-
constructor(nativeId, cfg) {
|
|
34155
|
-
super(nativeId, cfg);
|
|
34156
|
-
}
|
|
34157
34165
|
handlePrimary(topic, np, _raw) {
|
|
34158
34166
|
if (topic === this.cfg.topics.contact) {
|
|
34159
|
-
|
|
34167
|
+
const v = truthy(np);
|
|
34168
|
+
// usa il setter che emette l'evento di EntrySensor
|
|
34169
|
+
this.setAndEmit?.('entryOpen', v, sdk_1.ScryptedInterface.EntrySensor);
|
|
34170
|
+
// fallback per sicurezza (in alcune minifiche setAndEmit non è visibile):
|
|
34171
|
+
if (this.setAndEmit === undefined) {
|
|
34172
|
+
if (this.entryOpen !== v) {
|
|
34173
|
+
this.entryOpen = v;
|
|
34174
|
+
this.onDeviceEvent(sdk_1.ScryptedInterface.EntrySensor, v);
|
|
34175
|
+
}
|
|
34176
|
+
}
|
|
34160
34177
|
}
|
|
34161
34178
|
}
|
|
34162
34179
|
}
|
|
34163
34180
|
class MotionMqttSensor extends BaseMqttSensor {
|
|
34164
|
-
constructor(nativeId, cfg) {
|
|
34165
|
-
super(nativeId, cfg);
|
|
34166
|
-
}
|
|
34167
34181
|
handlePrimary(topic, np, _raw) {
|
|
34168
34182
|
if (topic === this.cfg.topics.motion) {
|
|
34169
|
-
|
|
34183
|
+
const v = truthy(np);
|
|
34184
|
+
this.setAndEmit?.('motionDetected', v, sdk_1.ScryptedInterface.MotionSensor);
|
|
34185
|
+
if (this.setAndEmit === undefined) {
|
|
34186
|
+
if (this.motionDetected !== v) {
|
|
34187
|
+
this.motionDetected = v;
|
|
34188
|
+
this.onDeviceEvent(sdk_1.ScryptedInterface.MotionSensor, v);
|
|
34189
|
+
}
|
|
34190
|
+
}
|
|
34170
34191
|
}
|
|
34171
34192
|
}
|
|
34172
34193
|
}
|
|
34173
34194
|
class OccupancyMqttSensor extends BaseMqttSensor {
|
|
34174
|
-
constructor(nativeId, cfg) {
|
|
34175
|
-
super(nativeId, cfg);
|
|
34176
|
-
}
|
|
34177
34195
|
handlePrimary(topic, np, _raw) {
|
|
34178
34196
|
if (topic === this.cfg.topics.occupancy) {
|
|
34179
|
-
|
|
34197
|
+
const v = truthy(np);
|
|
34198
|
+
this.setAndEmit?.('occupied', v, sdk_1.ScryptedInterface.OccupancySensor);
|
|
34199
|
+
if (this.setAndEmit === undefined) {
|
|
34200
|
+
if (this.occupied !== v) {
|
|
34201
|
+
this.occupied = v;
|
|
34202
|
+
this.onDeviceEvent(sdk_1.ScryptedInterface.OccupancySensor, v);
|
|
34203
|
+
}
|
|
34204
|
+
}
|
|
34180
34205
|
}
|
|
34181
34206
|
}
|
|
34182
34207
|
}
|
|
@@ -34440,6 +34465,10 @@ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
|
|
|
34440
34465
|
const hasBattery = !!(cfg.topics.batteryLevel || cfg.topics.lowBattery);
|
|
34441
34466
|
if (hasBattery && dev.batteryLevel === undefined) {
|
|
34442
34467
|
dev.batteryLevel = 100;
|
|
34468
|
+
try {
|
|
34469
|
+
dev.onDeviceEvent(sdk_1.ScryptedInterface.Battery, 100);
|
|
34470
|
+
}
|
|
34471
|
+
catch { }
|
|
34443
34472
|
}
|
|
34444
34473
|
}
|
|
34445
34474
|
// 4) Rimuovi quelli spariti
|
|
@@ -34517,6 +34546,10 @@ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
|
|
|
34517
34546
|
client.on('connect', () => {
|
|
34518
34547
|
this.console.log('MQTT connected');
|
|
34519
34548
|
this.online = true;
|
|
34549
|
+
try {
|
|
34550
|
+
this.onDeviceEvent(sdk_1.ScryptedInterface.Online, true);
|
|
34551
|
+
}
|
|
34552
|
+
catch { }
|
|
34520
34553
|
if (subs.length) {
|
|
34521
34554
|
client.subscribe(subs, { qos: 0 }, (err) => {
|
|
34522
34555
|
if (err)
|
|
@@ -34525,7 +34558,14 @@ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
|
|
|
34525
34558
|
}
|
|
34526
34559
|
});
|
|
34527
34560
|
client.on('reconnect', () => this.console.log('MQTT reconnecting...'));
|
|
34528
|
-
client.on('close', () => {
|
|
34561
|
+
client.on('close', () => {
|
|
34562
|
+
this.console.log('MQTT closed');
|
|
34563
|
+
this.online = false;
|
|
34564
|
+
try {
|
|
34565
|
+
this.onDeviceEvent(sdk_1.ScryptedInterface.Online, false);
|
|
34566
|
+
}
|
|
34567
|
+
catch { }
|
|
34568
|
+
});
|
|
34529
34569
|
client.on('error', (e) => { this.console.error('MQTT error', e); });
|
|
34530
34570
|
client.on('message', (topic, payload) => {
|
|
34531
34571
|
try {
|
|
@@ -34533,18 +34573,37 @@ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
|
|
|
34533
34573
|
const np = normalize(p);
|
|
34534
34574
|
// ---- Alarm handling ----
|
|
34535
34575
|
if (topic === tOnline) {
|
|
34536
|
-
if (truthy(np) || np === 'online')
|
|
34576
|
+
if (truthy(np) || np === 'online') {
|
|
34537
34577
|
this.online = true;
|
|
34538
|
-
|
|
34578
|
+
try {
|
|
34579
|
+
this.onDeviceEvent(sdk_1.ScryptedInterface.Online, true);
|
|
34580
|
+
}
|
|
34581
|
+
catch { }
|
|
34582
|
+
}
|
|
34583
|
+
if (falsy(np) || np === 'offline') {
|
|
34539
34584
|
this.online = false;
|
|
34585
|
+
try {
|
|
34586
|
+
this.onDeviceEvent(sdk_1.ScryptedInterface.Online, false);
|
|
34587
|
+
}
|
|
34588
|
+
catch { }
|
|
34589
|
+
}
|
|
34540
34590
|
return;
|
|
34541
34591
|
}
|
|
34542
34592
|
if (topic === tTamper) {
|
|
34543
34593
|
if (truthy(np) || ['tamper', 'intrusion', 'cover'].includes(np)) {
|
|
34544
|
-
|
|
34594
|
+
const val = ['cover', 'intrusion'].find(x => x === np) || true;
|
|
34595
|
+
this.tampered = val;
|
|
34596
|
+
try {
|
|
34597
|
+
this.onDeviceEvent(sdk_1.ScryptedInterface.TamperSensor, val);
|
|
34598
|
+
}
|
|
34599
|
+
catch { }
|
|
34545
34600
|
}
|
|
34546
34601
|
else if (falsy(np)) {
|
|
34547
34602
|
this.tampered = false;
|
|
34603
|
+
try {
|
|
34604
|
+
this.onDeviceEvent(sdk_1.ScryptedInterface.TamperSensor, false);
|
|
34605
|
+
}
|
|
34606
|
+
catch { }
|
|
34548
34607
|
}
|
|
34549
34608
|
return;
|
|
34550
34609
|
}
|
|
@@ -34563,6 +34622,10 @@ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
|
|
|
34563
34622
|
triggered: isAlarm || undefined,
|
|
34564
34623
|
};
|
|
34565
34624
|
this.securitySystemState = newState;
|
|
34625
|
+
try {
|
|
34626
|
+
this.onDeviceEvent(sdk_1.ScryptedInterface.SecuritySystem, newState);
|
|
34627
|
+
}
|
|
34628
|
+
catch { }
|
|
34566
34629
|
return;
|
|
34567
34630
|
}
|
|
34568
34631
|
if (topic === tTarget) {
|
package/dist/plugin.zip
CHANGED
|
Binary file
|
package/package.json
CHANGED