@rfranzoi/scrypted-mqtt-securitysystem 1.0.52 → 1.0.55

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,77 @@ 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
+ const topics = this.cfg.topics || {};
34143
+ // 1) stato primario (contact / motion / occupancy)
34144
+ this.handlePrimary(topic, np, raw);
34145
+ // 2) TAMPER
34146
+ if (topic === topics.tamper) {
34147
+ if (truthy(np) || ['tamper', 'intrusion', 'cover'].includes(np)) {
34148
+ const val = ['cover', 'intrusion'].find(x => x === np) || true;
34149
+ this.setAndEmit('tampered', val, sdk_1.ScryptedInterface.TamperSensor, {
34150
+ topic,
34151
+ raw,
34152
+ propLabel: 'tampered',
34153
+ });
34154
34154
  }
34155
34155
  else if (falsy(np)) {
34156
- this.setAndEmit('tampered', false, sdk_1.ScryptedInterface.TamperSensor, { topic, raw, propLabel: 'tampered' });
34156
+ this.setAndEmit('tampered', false, sdk_1.ScryptedInterface.TamperSensor, {
34157
+ topic,
34158
+ raw,
34159
+ propLabel: 'tampered',
34160
+ });
34157
34161
  }
34162
+ return;
34158
34163
  }
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' });
34164
+ // 3) ONLINE
34165
+ if (topic === topics.online) {
34166
+ const online = truthy(np) || np === 'online';
34167
+ this.setAndEmit('online', online, sdk_1.ScryptedInterface.Online, {
34168
+ topic,
34169
+ raw,
34170
+ propLabel: 'online',
34171
+ });
34172
+ return;
34173
+ }
34174
+ // 4) LOW BATTERY (bool)
34175
+ if (topic === topics.lowBattery) {
34176
+ const isLow = np === 'true' ||
34177
+ np === '1' ||
34178
+ np === 'on' ||
34179
+ np === 'low' ||
34180
+ np === 'battery_low' ||
34181
+ truthy(np);
34182
+ this.lowBattery = isLow;
34183
+ try {
34184
+ this.onDeviceEvent(sdk_1.ScryptedInterface.Battery, isLow);
34185
+ }
34186
+ catch (e) {
34187
+ this.console?.warn?.('Battery low event error', e);
34188
+ }
34189
+ if (RUNTIME.logSensors) {
34190
+ this.console?.log?.(`[Sensor] ${this.cfg.name} [${this.cfg.id}] lowBattery -> ${isLow} (${topic}="${raw}")`);
34191
+ }
34192
+ return;
34164
34193
  }
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)' });
34194
+ // 5) BATTERY LEVEL (0..100)
34195
+ if (topic === topics.batteryLevel) {
34196
+ const n = Number(raw);
34197
+ if (isFinite(n)) {
34198
+ const pct = clamp(n, 0, 100);
34199
+ this.setAndEmit('batteryLevel', pct, sdk_1.ScryptedInterface.Battery, {
34200
+ topic,
34201
+ raw,
34202
+ propLabel: 'batteryLevel',
34203
+ });
34204
+ try {
34205
+ this.onDeviceEvent(sdk_1.ScryptedInterface.Battery, { level: pct });
34206
+ }
34207
+ catch (e) {
34208
+ this.console?.warn?.('Battery level event error', e);
34209
+ }
34210
+ }
34211
+ return;
34171
34212
  }
34172
- // primary handled by subclasses
34173
- this.handlePrimary(topic, np, raw);
34174
34213
  }
34175
34214
  }
34176
34215
  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.55",
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",