@rfranzoi/scrypted-mqtt-securitysystem 1.0.54 → 1.0.56

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,67 +34139,40 @@ class BaseMqttSensor extends sdk_1.ScryptedDeviceBase {
34139
34139
  handleMqtt(topic, payload) {
34140
34140
  const raw = payload?.toString() ?? '';
34141
34141
  const np = normalize(raw);
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) {
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) {
34174
34147
  if (truthy(np) || ['tamper', 'intrusion', 'cover'].includes(np)) {
34175
34148
  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 { }
34149
+ this.setAndEmit('tampered', val, sdk_1.ScryptedInterface.TamperSensor, {
34150
+ topic,
34151
+ raw,
34152
+ propLabel: 'tampered',
34153
+ });
34181
34154
  }
34182
34155
  else if (falsy(np)) {
34183
- this.tampered = false;
34184
- try {
34185
- this.onDeviceEvent(sdk_1.ScryptedInterface.TamperSensor, false);
34186
- }
34187
- catch { }
34156
+ this.setAndEmit('tampered', false, sdk_1.ScryptedInterface.TamperSensor, {
34157
+ topic,
34158
+ raw,
34159
+ propLabel: 'tampered',
34160
+ });
34188
34161
  }
34189
34162
  return;
34190
34163
  }
34191
- // ONLINE
34192
- if (topic === this.topics.online) {
34164
+ // 3) ONLINE
34165
+ if (topic === topics.online) {
34193
34166
  const online = truthy(np) || np === 'online';
34194
- this.online = online;
34195
- try {
34196
- this.onDeviceEvent(sdk_1.ScryptedInterface.Online, online);
34197
- }
34198
- catch { }
34167
+ this.setAndEmit('online', online, sdk_1.ScryptedInterface.Online, {
34168
+ topic,
34169
+ raw,
34170
+ propLabel: 'online',
34171
+ });
34199
34172
  return;
34200
34173
  }
34201
- // 🔋 LOW BATTERY (bool) – QUI LA PATCH
34202
- if (topic === this.topics.lowBattery) {
34174
+ // 4) LOW BATTERY (bool)
34175
+ if (topic === topics.lowBattery) {
34203
34176
  const isLow = np === 'true' ||
34204
34177
  np === '1' ||
34205
34178
  np === 'on' ||
@@ -34207,23 +34180,36 @@ class BaseMqttSensor extends sdk_1.ScryptedDeviceBase {
34207
34180
  np === 'battery_low' ||
34208
34181
  truthy(np);
34209
34182
  this.lowBattery = isLow;
34210
- try {
34211
- // per l’interfaccia Battery di Scrypted un booleano "low" è sufficiente
34212
- this.onDeviceEvent(sdk_1.ScryptedInterface.Battery, isLow);
34183
+ // Simula anche la percentuale per HomeKit/Scrypted:
34184
+ // low -> 10%
34185
+ // ok -> 100%
34186
+ const level = isLow ? 10 : 100;
34187
+ this.setAndEmit('batteryLevel', level, sdk_1.ScryptedInterface.Battery, {
34188
+ topic,
34189
+ raw,
34190
+ propLabel: 'batteryLevel(from lowBattery)',
34191
+ });
34192
+ if (RUNTIME.logSensors) {
34193
+ this.console?.log?.(`[Sensor] ${this.cfg.name} [${this.cfg.id}] lowBattery -> ${isLow}, level -> ${level} (${topic}="${raw}")`);
34213
34194
  }
34214
- catch { }
34215
34195
  return;
34216
34196
  }
34217
- // 🔋 BATTERY LEVEL (0..100) – per quando userai Battery Level Topic
34218
- if (topic === this.topics.batteryLevel) {
34197
+ // 5) BATTERY LEVEL (0..100)
34198
+ if (topic === topics.batteryLevel) {
34219
34199
  const n = Number(raw);
34220
34200
  if (isFinite(n)) {
34221
- const pct = Math.max(0, Math.min(100, n));
34222
- this.batteryLevel = pct;
34201
+ const pct = clamp(n, 0, 100);
34202
+ this.setAndEmit('batteryLevel', pct, sdk_1.ScryptedInterface.Battery, {
34203
+ topic,
34204
+ raw,
34205
+ propLabel: 'batteryLevel',
34206
+ });
34223
34207
  try {
34224
34208
  this.onDeviceEvent(sdk_1.ScryptedInterface.Battery, { level: pct });
34225
34209
  }
34226
- catch { }
34210
+ catch (e) {
34211
+ this.console?.warn?.('Battery level event error', e);
34212
+ }
34227
34213
  }
34228
34214
  return;
34229
34215
  }
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.54",
3
+ "version": "1.0.56",
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",