@rfranzoi/scrypted-mqtt-securitysystem 1.0.43 → 1.0.45

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.
@@ -34024,28 +34024,46 @@ function socketOnError() {
34024
34024
 
34025
34025
  "use strict";
34026
34026
 
34027
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
34028
+ if (k2 === undefined) k2 = k;
34029
+ var desc = Object.getOwnPropertyDescriptor(m, k);
34030
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
34031
+ desc = { enumerable: true, get: function() { return m[k]; } };
34032
+ }
34033
+ Object.defineProperty(o, k2, desc);
34034
+ }) : (function(o, m, k, k2) {
34035
+ if (k2 === undefined) k2 = k;
34036
+ o[k2] = m[k];
34037
+ }));
34038
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
34039
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
34040
+ }) : function(o, v) {
34041
+ o["default"] = v;
34042
+ });
34043
+ var __importStar = (this && this.__importStar) || (function () {
34044
+ var ownKeys = function(o) {
34045
+ ownKeys = Object.getOwnPropertyNames || function (o) {
34046
+ var ar = [];
34047
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34048
+ return ar;
34049
+ };
34050
+ return ownKeys(o);
34051
+ };
34052
+ return function (mod) {
34053
+ if (mod && mod.__esModule) return mod;
34054
+ var result = {};
34055
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34056
+ __setModuleDefault(result, mod);
34057
+ return result;
34058
+ };
34059
+ })();
34027
34060
  var __importDefault = (this && this.__importDefault) || function (mod) {
34028
34061
  return (mod && mod.__esModule) ? mod : { "default": mod };
34029
34062
  };
34030
34063
  Object.defineProperty(exports, "__esModule", ({ value: true }));
34031
- // --- Silence ONLY the optional sdk.json warning from @scrypted/sdk ---
34032
- const __origConsoleError = console.error.bind(console);
34033
- console.error = (...args) => {
34034
- const first = args?.[0];
34035
- const msg = typeof first === 'string' ? first : (first?.message || '');
34036
- if (typeof msg === 'string' && msg.includes('failed to load custom interface descriptors')) {
34037
- // swallow just this warning
34038
- return;
34039
- }
34040
- __origConsoleError(...args);
34041
- };
34042
- // Carica lo SDK (non tipizziamo qui per non perdere le proprietà runtime)
34043
- const sdk = __webpack_require__(/*! @scrypted/sdk */ "./node_modules/@scrypted/sdk/dist/src/index.js");
34044
- // Valori runtime (enum/classi/manager) dal modulo SDK
34045
- const { ScryptedDeviceBase, ScryptedDeviceType, ScryptedInterface, // valore (enum)
34046
- SecuritySystemMode, // valore (enum)
34047
- systemManager, deviceManager, } = sdk;
34064
+ const sdk_1 = __importStar(__webpack_require__(/*! @scrypted/sdk */ "./node_modules/@scrypted/sdk/dist/src/index.js"));
34048
34065
  const mqtt_1 = __importDefault(__webpack_require__(/*! mqtt */ "./node_modules/mqtt/build/index.js"));
34066
+ const { systemManager, deviceManager } = sdk_1.default;
34049
34067
  /** utils */
34050
34068
  function truthy(v) {
34051
34069
  if (!v)
@@ -34065,13 +34083,12 @@ function normalize(s) {
34065
34083
  function clamp(n, min, max) {
34066
34084
  return Math.max(min, Math.min(max, n));
34067
34085
  }
34068
- /** SecuritySystem outgoing defaults (PAI-like)
34069
- * Nota: usare number come chiave evita stranezze con gli enum in TS. */
34086
+ /** SecuritySystem outgoing defaults (PAI-like) */
34070
34087
  const DEFAULT_OUTGOING = {
34071
- [SecuritySystemMode.Disarmed]: 'disarm',
34072
- [SecuritySystemMode.HomeArmed]: 'arm_home',
34073
- [SecuritySystemMode.AwayArmed]: 'arm_away',
34074
- [SecuritySystemMode.NightArmed]: 'arm_night',
34088
+ [sdk_1.SecuritySystemMode.Disarmed]: 'disarm',
34089
+ [sdk_1.SecuritySystemMode.HomeArmed]: 'arm_home',
34090
+ [sdk_1.SecuritySystemMode.AwayArmed]: 'arm_away',
34091
+ [sdk_1.SecuritySystemMode.NightArmed]: 'arm_night',
34075
34092
  };
34076
34093
  /** Parse incoming payload -> final mode (ignore transition states) */
34077
34094
  function payloadToMode(payload) {
@@ -34079,22 +34096,23 @@ function payloadToMode(payload) {
34079
34096
  return;
34080
34097
  const p = normalize(payload.toString());
34081
34098
  if (['disarm', 'disarmed', 'off', '0', 'idle', 'ready'].includes(p))
34082
- return SecuritySystemMode.Disarmed;
34099
+ return sdk_1.SecuritySystemMode.Disarmed;
34083
34100
  if (['arm_home', 'home', 'stay', 'armed_home'].includes(p))
34084
- return SecuritySystemMode.HomeArmed;
34101
+ return sdk_1.SecuritySystemMode.HomeArmed;
34085
34102
  if (['arm_away', 'away', 'armed_away', 'away_armed'].includes(p))
34086
- return SecuritySystemMode.AwayArmed;
34103
+ return sdk_1.SecuritySystemMode.AwayArmed;
34087
34104
  if (['arm_night', 'night', 'armed_night', 'sleep', 'arm_sleep', 'armed_sleep'].includes(p))
34088
- return SecuritySystemMode.NightArmed;
34105
+ return sdk_1.SecuritySystemMode.NightArmed;
34089
34106
  // transitori: non cambiano il mode
34090
34107
  if (['entry_delay', 'exit_delay', 'pending', 'arming', 'disarming'].includes(p))
34091
34108
  return undefined;
34092
34109
  return undefined;
34093
34110
  }
34094
- class BaseMqttSensor extends ScryptedDeviceBase {
34111
+ class BaseMqttSensor extends sdk_1.ScryptedDeviceBase {
34095
34112
  constructor(nativeId, cfg) {
34096
34113
  super(nativeId);
34097
34114
  this.cfg = cfg;
34115
+ // non impostare stati qui: l'annuncio device deve avvenire prima
34098
34116
  }
34099
34117
  /** Called by parent on each MQTT message */
34100
34118
  handleMqtt(topic, payload) {
@@ -34123,7 +34141,9 @@ class BaseMqttSensor extends ScryptedDeviceBase {
34123
34141
  this.batteryLevel = n;
34124
34142
  }
34125
34143
  else if (topic === this.cfg.topics.lowBattery && !this.cfg.topics.batteryLevel) {
34126
- // se abbiamo SOLO lowBattery (bool):
34144
+ // Solo se abbiamo lowBattery (booleano) ma NON batteryLevel:
34145
+ // True -> 10% (warning)
34146
+ // False -> 100% (ok)
34127
34147
  this.batteryLevel = truthy(np) ? 10 : 100;
34128
34148
  }
34129
34149
  // primary handled by subclasses
@@ -34131,28 +34151,37 @@ class BaseMqttSensor extends ScryptedDeviceBase {
34131
34151
  }
34132
34152
  }
34133
34153
  class ContactMqttSensor extends BaseMqttSensor {
34134
- handlePrimary(topic, np) {
34154
+ constructor(nativeId, cfg) {
34155
+ super(nativeId, cfg);
34156
+ }
34157
+ handlePrimary(topic, np, _raw) {
34135
34158
  if (topic === this.cfg.topics.contact) {
34136
34159
  this.entryOpen = truthy(np);
34137
34160
  }
34138
34161
  }
34139
34162
  }
34140
34163
  class MotionMqttSensor extends BaseMqttSensor {
34141
- handlePrimary(topic, np) {
34164
+ constructor(nativeId, cfg) {
34165
+ super(nativeId, cfg);
34166
+ }
34167
+ handlePrimary(topic, np, _raw) {
34142
34168
  if (topic === this.cfg.topics.motion) {
34143
34169
  this.motionDetected = truthy(np);
34144
34170
  }
34145
34171
  }
34146
34172
  }
34147
34173
  class OccupancyMqttSensor extends BaseMqttSensor {
34148
- handlePrimary(topic, np) {
34174
+ constructor(nativeId, cfg) {
34175
+ super(nativeId, cfg);
34176
+ }
34177
+ handlePrimary(topic, np, _raw) {
34149
34178
  if (topic === this.cfg.topics.occupancy) {
34150
34179
  this.occupied = truthy(np);
34151
34180
  }
34152
34181
  }
34153
34182
  }
34154
34183
  /** ----------------- Main Plugin ----------------- */
34155
- class ParadoxMqttSecuritySystem extends ScryptedDeviceBase {
34184
+ class ParadoxMqttSecuritySystem extends sdk_1.ScryptedDeviceBase {
34156
34185
  constructor() {
34157
34186
  super();
34158
34187
  // sensor management
@@ -34161,26 +34190,26 @@ class ParadoxMqttSecuritySystem extends ScryptedDeviceBase {
34161
34190
  // (facoltativo) Imposta il device type in UI
34162
34191
  setTimeout(() => {
34163
34192
  try {
34164
- systemManager.getDeviceById(this.id)?.setType?.(ScryptedDeviceType.SecuritySystem);
34193
+ systemManager.getDeviceById(this.id)?.setType?.(sdk_1.ScryptedDeviceType.SecuritySystem);
34165
34194
  }
34166
34195
  catch { }
34167
34196
  });
34168
34197
  // Default state
34169
34198
  this.securitySystemState = this.securitySystemState || {
34170
- mode: SecuritySystemMode.Disarmed,
34199
+ mode: sdk_1.SecuritySystemMode.Disarmed,
34171
34200
  supportedModes: [
34172
- SecuritySystemMode.Disarmed,
34173
- SecuritySystemMode.HomeArmed,
34174
- SecuritySystemMode.AwayArmed,
34175
- SecuritySystemMode.NightArmed,
34201
+ sdk_1.SecuritySystemMode.Disarmed,
34202
+ sdk_1.SecuritySystemMode.HomeArmed,
34203
+ sdk_1.SecuritySystemMode.AwayArmed,
34204
+ sdk_1.SecuritySystemMode.NightArmed,
34176
34205
  ],
34177
34206
  };
34178
34207
  this.online = this.online ?? false;
34179
34208
  // Load sensors config and announce devices
34180
34209
  this.loadSensorsFromStorage();
34181
- this.discoverSensors().catch((e) => this.console.error('discoverSensors error', e));
34210
+ this.discoverSensors().catch(e => this.console.error('discoverSensors error', e));
34182
34211
  // Connect on start
34183
- this.connectMqtt().catch((e) => this.console.error('MQTT connect error:', e));
34212
+ this.connectMqtt().catch(e => this.console.error('MQTT connect error:', e));
34184
34213
  // chiusura pulita del client MQTT ai reload/stop del plugin
34185
34214
  try {
34186
34215
  process.once('SIGTERM', () => { try {
@@ -34362,22 +34391,22 @@ class ParadoxMqttSecuritySystem extends ScryptedDeviceBase {
34362
34391
  const manifests = this.sensorsCfg.map(cfg => {
34363
34392
  const nativeId = `sensor:${cfg.id}`;
34364
34393
  const t = cfg.topics || {};
34365
- const interfaces = [ScryptedInterface.Online];
34394
+ const interfaces = [sdk_1.ScryptedInterface.Online];
34366
34395
  // Tamper solo se c'è un topic tamper
34367
34396
  if (t.tamper)
34368
- interfaces.push(ScryptedInterface.TamperSensor);
34397
+ interfaces.push(sdk_1.ScryptedInterface.TamperSensor);
34369
34398
  // Interfaccia primaria
34370
34399
  if (cfg.kind === 'contact')
34371
- interfaces.unshift(ScryptedInterface.EntrySensor);
34400
+ interfaces.unshift(sdk_1.ScryptedInterface.EntrySensor);
34372
34401
  else if (cfg.kind === 'motion')
34373
- interfaces.unshift(ScryptedInterface.MotionSensor);
34402
+ interfaces.unshift(sdk_1.ScryptedInterface.MotionSensor);
34374
34403
  else
34375
- interfaces.unshift(ScryptedInterface.OccupancySensor);
34404
+ interfaces.unshift(sdk_1.ScryptedInterface.OccupancySensor);
34376
34405
  // Battery solo se previsto
34377
34406
  if (t.batteryLevel || t.lowBattery) {
34378
- interfaces.push(ScryptedInterface.Battery);
34407
+ interfaces.push(sdk_1.ScryptedInterface.Battery);
34379
34408
  }
34380
- return { nativeId, name: cfg.name, type: ScryptedDeviceType.Sensor, interfaces };
34409
+ return { nativeId, name: cfg.name, type: sdk_1.ScryptedDeviceType.Sensor, interfaces };
34381
34410
  });
34382
34411
  // 2) Annuncio
34383
34412
  const dmAny = deviceManager;
@@ -34522,14 +34551,14 @@ class ParadoxMqttSecuritySystem extends ScryptedDeviceBase {
34522
34551
  if (topic === tCurrent) {
34523
34552
  const mode = payloadToMode(payload);
34524
34553
  const isAlarm = ['alarm', 'triggered'].includes(np);
34525
- const current = this.securitySystemState || { mode: SecuritySystemMode.Disarmed };
34554
+ const current = this.securitySystemState || { mode: sdk_1.SecuritySystemMode.Disarmed };
34526
34555
  const newState = {
34527
34556
  mode: mode ?? current.mode,
34528
34557
  supportedModes: current.supportedModes ?? [
34529
- SecuritySystemMode.Disarmed,
34530
- SecuritySystemMode.HomeArmed,
34531
- SecuritySystemMode.AwayArmed,
34532
- SecuritySystemMode.NightArmed,
34558
+ sdk_1.SecuritySystemMode.Disarmed,
34559
+ sdk_1.SecuritySystemMode.HomeArmed,
34560
+ sdk_1.SecuritySystemMode.AwayArmed,
34561
+ sdk_1.SecuritySystemMode.NightArmed,
34533
34562
  ],
34534
34563
  triggered: isAlarm || undefined,
34535
34564
  };
@@ -34573,17 +34602,17 @@ class ParadoxMqttSecuritySystem extends ScryptedDeviceBase {
34573
34602
  this.publishSetTarget(payload);
34574
34603
  }
34575
34604
  async disarmSecuritySystem() {
34576
- const payload = this.getOutgoing(SecuritySystemMode.Disarmed);
34605
+ const payload = this.getOutgoing(sdk_1.SecuritySystemMode.Disarmed);
34577
34606
  this.console.log('disarmSecuritySystem ->', payload);
34578
- this.pendingTarget = SecuritySystemMode.Disarmed;
34607
+ this.pendingTarget = sdk_1.SecuritySystemMode.Disarmed;
34579
34608
  this.publishSetTarget(payload);
34580
34609
  }
34581
34610
  getOutgoing(mode) {
34582
34611
  const map = {
34583
- [SecuritySystemMode.Disarmed]: this.storage.getItem('payloadDisarm') || DEFAULT_OUTGOING[SecuritySystemMode.Disarmed],
34584
- [SecuritySystemMode.HomeArmed]: this.storage.getItem('payloadHome') || DEFAULT_OUTGOING[SecuritySystemMode.HomeArmed],
34585
- [SecuritySystemMode.AwayArmed]: this.storage.getItem('payloadAway') || DEFAULT_OUTGOING[SecuritySystemMode.AwayArmed],
34586
- [SecuritySystemMode.NightArmed]: this.storage.getItem('payloadNight') || DEFAULT_OUTGOING[SecuritySystemMode.NightArmed],
34612
+ [sdk_1.SecuritySystemMode.Disarmed]: this.storage.getItem('payloadDisarm') || DEFAULT_OUTGOING[sdk_1.SecuritySystemMode.Disarmed],
34613
+ [sdk_1.SecuritySystemMode.HomeArmed]: this.storage.getItem('payloadHome') || DEFAULT_OUTGOING[sdk_1.SecuritySystemMode.HomeArmed],
34614
+ [sdk_1.SecuritySystemMode.AwayArmed]: this.storage.getItem('payloadAway') || DEFAULT_OUTGOING[sdk_1.SecuritySystemMode.AwayArmed],
34615
+ [sdk_1.SecuritySystemMode.NightArmed]: this.storage.getItem('payloadNight') || DEFAULT_OUTGOING[sdk_1.SecuritySystemMode.NightArmed],
34587
34616
  };
34588
34617
  return map[mode];
34589
34618
  }
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.43",
3
+ "version": "1.0.45",
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",