@rfranzoi/scrypted-mqtt-securitysystem 1.0.52 → 1.0.54

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.
@@ -34139,38 +34139,94 @@ class BaseMqttSensor extends sdk_1.ScryptedDeviceBase {
34139
34139
  handleMqtt(topic, payload) {
34140
34140
  const raw = payload?.toString() ?? '';
34141
34141
  const np = normalize(raw);
34142
- // online
34143
- if (topic === this.cfg.topics.online) {
34144
- if (truthy(np) || np === 'online')
34145
- this.setAndEmit('online', true, sdk_1.ScryptedInterface.Online, { topic, raw, propLabel: 'online' });
34146
- if (falsy(np) || np === 'offline')
34147
- this.setAndEmit('online', false, sdk_1.ScryptedInterface.Online, { topic, raw, propLabel: 'online' });
34148
- }
34149
- // tamper
34150
- if (topic === this.cfg.topics.tamper) {
34151
- if (truthy(np) || ['tamper', 'intrusion', 'cover', 'motion', 'magnetic'].includes(np)) {
34152
- const value = ['cover', 'intrusion', 'motion', 'magnetic'].find(x => x === np) || true;
34153
- this.setAndEmit('tampered', value, sdk_1.ScryptedInterface.TamperSensor, { topic, raw, propLabel: 'tampered' });
34142
+ // CONTACT
34143
+ if (topic === this.topics.contact) {
34144
+ const open = truthy(np) || np === 'open';
34145
+ this.contact = open;
34146
+ try {
34147
+ this.onDeviceEvent(sdk_1.ScryptedInterface.BinarySensor, open);
34148
+ }
34149
+ catch { }
34150
+ return;
34151
+ }
34152
+ // MOTION
34153
+ if (topic === this.topics.motion) {
34154
+ const motion = truthy(np) || np === 'motion';
34155
+ this.motionDetected = motion;
34156
+ try {
34157
+ this.onDeviceEvent(sdk_1.ScryptedInterface.MotionSensor, motion);
34158
+ }
34159
+ catch { }
34160
+ return;
34161
+ }
34162
+ // OCCUPANCY
34163
+ if (topic === this.topics.occupancy) {
34164
+ const occ = truthy(np) || np === 'occupied';
34165
+ this.occupied = occ;
34166
+ try {
34167
+ this.onDeviceEvent(sdk_1.ScryptedInterface.OccupancySensor, occ);
34168
+ }
34169
+ catch { }
34170
+ return;
34171
+ }
34172
+ // TAMPER
34173
+ if (topic === this.topics.tamper) {
34174
+ if (truthy(np) || ['tamper', 'intrusion', 'cover'].includes(np)) {
34175
+ const val = ['cover', 'intrusion'].find(x => x === np) || true;
34176
+ this.tampered = val;
34177
+ try {
34178
+ this.onDeviceEvent(sdk_1.ScryptedInterface.TamperSensor, val);
34179
+ }
34180
+ catch { }
34154
34181
  }
34155
34182
  else if (falsy(np)) {
34156
- this.setAndEmit('tampered', false, sdk_1.ScryptedInterface.TamperSensor, { topic, raw, propLabel: 'tampered' });
34183
+ this.tampered = false;
34184
+ try {
34185
+ this.onDeviceEvent(sdk_1.ScryptedInterface.TamperSensor, false);
34186
+ }
34187
+ catch { }
34157
34188
  }
34189
+ return;
34190
+ }
34191
+ // ONLINE
34192
+ if (topic === this.topics.online) {
34193
+ const online = truthy(np) || np === 'online';
34194
+ this.online = online;
34195
+ try {
34196
+ this.onDeviceEvent(sdk_1.ScryptedInterface.Online, online);
34197
+ }
34198
+ catch { }
34199
+ return;
34158
34200
  }
34159
- // battery
34160
- if (topic === this.cfg.topics.batteryLevel) {
34161
- const n = clamp(parseFloat(raw), 0, 100);
34162
- if (Number.isFinite(n))
34163
- this.setAndEmit('batteryLevel', n, sdk_1.ScryptedInterface.Battery, { topic, raw, propLabel: 'batteryLevel' });
34201
+ // 🔋 LOW BATTERY (bool) – QUI LA PATCH
34202
+ if (topic === this.topics.lowBattery) {
34203
+ const isLow = np === 'true' ||
34204
+ np === '1' ||
34205
+ np === 'on' ||
34206
+ np === 'low' ||
34207
+ np === 'battery_low' ||
34208
+ truthy(np);
34209
+ this.lowBattery = isLow;
34210
+ try {
34211
+ // per l’interfaccia Battery di Scrypted un booleano "low" è sufficiente
34212
+ this.onDeviceEvent(sdk_1.ScryptedInterface.Battery, isLow);
34213
+ }
34214
+ catch { }
34215
+ return;
34164
34216
  }
34165
- else if (topic === this.cfg.topics.lowBattery && !this.cfg.topics.batteryLevel) {
34166
- // solo se abbiamo lowBattery (bool) ma NON batteryLevel
34167
- if (truthy(np))
34168
- this.setAndEmit('batteryLevel', 10, sdk_1.ScryptedInterface.Battery, { topic, raw, propLabel: 'batteryLevel (low)' });
34169
- else if (falsy(np) && this.batteryLevel === undefined)
34170
- this.setAndEmit('batteryLevel', 100, sdk_1.ScryptedInterface.Battery, { topic, raw, propLabel: 'batteryLevel (ok)' });
34217
+ // 🔋 BATTERY LEVEL (0..100) per quando userai Battery Level Topic
34218
+ if (topic === this.topics.batteryLevel) {
34219
+ const n = Number(raw);
34220
+ if (isFinite(n)) {
34221
+ const pct = Math.max(0, Math.min(100, n));
34222
+ this.batteryLevel = pct;
34223
+ try {
34224
+ this.onDeviceEvent(sdk_1.ScryptedInterface.Battery, { level: pct });
34225
+ }
34226
+ catch { }
34227
+ }
34228
+ return;
34171
34229
  }
34172
- // primary handled by subclasses
34173
- this.handlePrimary(topic, np, raw);
34174
34230
  }
34175
34231
  }
34176
34232
  class ContactMqttSensor extends BaseMqttSensor {
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.52",
3
+ "version": "1.0.54",
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",