@rfranzoi/scrypted-mqtt-securitysystem 1.0.36 → 1.0.37

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.
@@ -34118,22 +34118,133 @@ class BaseMqttSensor extends ScryptedDeviceBase {
34118
34118
  this.handlePrimary(topic, np, p);
34119
34119
  }
34120
34120
  }
34121
+ /** === SENSORI CON PARSING ROBUSTO PER HOMEKIT === */
34121
34122
  class ContactMqttSensor extends BaseMqttSensor {
34122
- handlePrimary(topic, np) {
34123
- if (topic === this.cfg.topics.contact)
34124
- this.entryOpen = truthy(np);
34123
+ handlePrimary(topic, np, raw) {
34124
+ if (topic !== this.cfg.topics.contact)
34125
+ return;
34126
+ // stringhe comuni
34127
+ if (['open', 'opened', '1', 'true', 'on', 'yes'].includes(np)) {
34128
+ this.entryOpen = true;
34129
+ return;
34130
+ }
34131
+ if (['closed', 'close', '0', 'false', 'off', 'no', 'shut'].includes(np)) {
34132
+ this.entryOpen = false;
34133
+ return;
34134
+ }
34135
+ // JSON comuni
34136
+ try {
34137
+ const j = JSON.parse(raw);
34138
+ if (typeof j?.open === 'boolean') {
34139
+ this.entryOpen = !!j.open;
34140
+ return;
34141
+ }
34142
+ if (typeof j?.opened === 'boolean') {
34143
+ this.entryOpen = !!j.opened;
34144
+ return;
34145
+ }
34146
+ if (typeof j?.contact === 'boolean') {
34147
+ this.entryOpen = !j.contact;
34148
+ return;
34149
+ } // contact:false => OPEN
34150
+ if (typeof j?.state === 'string') {
34151
+ const s = String(j.state).toLowerCase();
34152
+ if (s === 'open') {
34153
+ this.entryOpen = true;
34154
+ return;
34155
+ }
34156
+ if (s === 'closed') {
34157
+ this.entryOpen = false;
34158
+ return;
34159
+ }
34160
+ }
34161
+ }
34162
+ catch { }
34163
+ this.console?.debug?.(`Contact payload non gestito (${this.cfg.id}): "${raw}"`);
34125
34164
  }
34126
34165
  }
34127
34166
  class MotionMqttSensor extends BaseMqttSensor {
34128
- handlePrimary(topic, np) {
34129
- if (topic === this.cfg.topics.motion)
34130
- this.motionDetected = truthy(np);
34167
+ handlePrimary(topic, np, raw) {
34168
+ if (topic !== this.cfg.topics.motion)
34169
+ return;
34170
+ if (['motion', 'detected', 'active', '1', 'true', 'on', 'yes'].includes(np)) {
34171
+ this.motionDetected = true;
34172
+ return;
34173
+ }
34174
+ if (['clear', 'inactive', 'no_motion', 'none', '0', 'false', 'off', 'no'].includes(np)) {
34175
+ this.motionDetected = false;
34176
+ return;
34177
+ }
34178
+ try {
34179
+ const j = JSON.parse(raw);
34180
+ if (typeof j?.motion === 'boolean') {
34181
+ this.motionDetected = !!j.motion;
34182
+ return;
34183
+ }
34184
+ if (typeof j?.occupancy === 'boolean') {
34185
+ this.motionDetected = !!j.occupancy;
34186
+ return;
34187
+ }
34188
+ if (typeof j?.presence === 'boolean') {
34189
+ this.motionDetected = !!j.presence;
34190
+ return;
34191
+ }
34192
+ if (typeof j?.state === 'string') {
34193
+ const s = String(j.state).toLowerCase();
34194
+ if (['on', 'motion', 'detected', 'active'].includes(s)) {
34195
+ this.motionDetected = true;
34196
+ return;
34197
+ }
34198
+ if (['off', 'clear', 'inactive'].includes(s)) {
34199
+ this.motionDetected = false;
34200
+ return;
34201
+ }
34202
+ }
34203
+ }
34204
+ catch { }
34205
+ this.console?.debug?.(`Motion payload non gestito (${this.cfg.id}): "${raw}"`);
34131
34206
  }
34132
34207
  }
34133
34208
  class OccupancyMqttSensor extends BaseMqttSensor {
34134
- handlePrimary(topic, np) {
34135
- if (topic === this.cfg.topics.occupancy)
34136
- this.occupied = truthy(np);
34209
+ handlePrimary(topic, np, raw) {
34210
+ if (topic !== this.cfg.topics.occupancy)
34211
+ return;
34212
+ if (['occupied', 'presence', 'present', '1', 'true', 'on', 'yes'].includes(np)) {
34213
+ this.occupied = true;
34214
+ return;
34215
+ }
34216
+ if (['unoccupied', 'vacant', 'absent', '0', 'false', 'off', 'no', 'clear'].includes(np)) {
34217
+ this.occupied = false;
34218
+ return;
34219
+ }
34220
+ try {
34221
+ const j = JSON.parse(raw);
34222
+ if (typeof j?.occupied === 'boolean') {
34223
+ this.occupied = !!j.occupied;
34224
+ return;
34225
+ }
34226
+ if (typeof j?.presence === 'boolean') {
34227
+ this.occupied = !!j.presence;
34228
+ return;
34229
+ }
34230
+ if (typeof j?.occupancy === 'boolean') {
34231
+ this.occupied = !!j.occupancy;
34232
+ return;
34233
+ }
34234
+ if (typeof j?.state === 'string') {
34235
+ const s = String(j.state).toLowerCase();
34236
+ if (['occupied', 'presence', 'present', 'on'].includes(s)) {
34237
+ this.occupied = true;
34238
+ return;
34239
+ }
34240
+ if (['vacant', 'absent', 'clear', 'off'].includes(s)) {
34241
+ this.occupied = false;
34242
+ return;
34243
+ }
34244
+ }
34245
+ }
34246
+ catch { }
34247
+ this.console?.debug?.(`Occupancy payload non gestito (${this.cfg.id}): "${raw}"`);
34137
34248
  }
34138
34249
  }
34139
34250
  /** ----------------- Main Plugin ----------------- */
@@ -34142,8 +34253,8 @@ class ParadoxMqttSecuritySystem extends ScryptedDeviceBase {
34142
34253
  super();
34143
34254
  this.sensorsCfg = [];
34144
34255
  this.devices = new Map();
34145
- // evitiamo spam: ricordiamo se abbiamo già provato ad annunciare
34146
- this.triedDiscoveryOnce = false;
34256
+ // Evita loop di log: tenta una volta finché deviceManager non c’è, poi riprova su eventi utili.
34257
+ this.discoveryPostponed = false;
34147
34258
  // Tipo in UI (best-effort)
34148
34259
  setTimeout(() => {
34149
34260
  try {
@@ -34323,17 +34434,17 @@ class ParadoxMqttSecuritySystem extends ScryptedDeviceBase {
34323
34434
  safeDiscoverSensors(triggeredByChange = false) {
34324
34435
  const dmAny = sdk?.deviceManager;
34325
34436
  if (!dmAny) {
34326
- if (!this.triedDiscoveryOnce) {
34437
+ // Posticipa una sola volta; poi riproviamo su connect MQTT e al primo messaggio
34438
+ if (!this.discoveryPostponed) {
34327
34439
  this.console.log('Device discovery postponed: deviceManager not ready yet.');
34328
- this.triedDiscoveryOnce = true;
34440
+ this.discoveryPostponed = true;
34329
34441
  }
34330
- // Riprovaremo in due casi: a) settaggi cambiati (già chiama safeDiscoverSensors)
34331
- // b) al primo messaggio MQTT (vedi handler sotto).
34332
34442
  return;
34333
34443
  }
34334
- // Se arriviamo qui, il manager c’è: esegui discover.
34335
- this.triedDiscoveryOnce = false;
34444
+ this.discoveryPostponed = false;
34336
34445
  this.discoverSensors(dmAny);
34446
+ if (triggeredByChange)
34447
+ this.console.log('Sensors discovered/updated.');
34337
34448
  }
34338
34449
  /** discoverSensors con deviceManager garantito */
34339
34450
  discoverSensors(dmAny) {
@@ -34495,8 +34606,8 @@ class ParadoxMqttSecuritySystem extends ScryptedDeviceBase {
34495
34606
  return;
34496
34607
  }
34497
34608
  // Dispatch ai sensori
34498
- // (E prova ad annunciare se non l’abbiamo ancora fatto e ora il manager è pronto)
34499
- if (this.triedDiscoveryOnce)
34609
+ // (E prova ad annunciare se era stato posticipato e ora il manager è pronto)
34610
+ if (this.discoveryPostponed)
34500
34611
  this.safeDiscoverSensors(true);
34501
34612
  for (const dev of this.devices.values())
34502
34613
  dev.handleMqtt(topic, payload);
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.36",
3
+ "version": "1.0.37",
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",