@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.
- package/dist/main.nodejs.js +65 -26
- package/dist/plugin.zip +0 -0
- package/package.json +1 -1
package/dist/main.nodejs.js
CHANGED
|
@@ -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
|
-
|
|
34143
|
-
|
|
34144
|
-
|
|
34145
|
-
|
|
34146
|
-
|
|
34147
|
-
|
|
34148
|
-
|
|
34149
|
-
|
|
34150
|
-
|
|
34151
|
-
|
|
34152
|
-
|
|
34153
|
-
|
|
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, {
|
|
34156
|
+
this.setAndEmit('tampered', false, sdk_1.ScryptedInterface.TamperSensor, {
|
|
34157
|
+
topic,
|
|
34158
|
+
raw,
|
|
34159
|
+
propLabel: 'tampered',
|
|
34160
|
+
});
|
|
34157
34161
|
}
|
|
34162
|
+
return;
|
|
34158
34163
|
}
|
|
34159
|
-
//
|
|
34160
|
-
if (topic ===
|
|
34161
|
-
const
|
|
34162
|
-
|
|
34163
|
-
|
|
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
|
-
|
|
34166
|
-
|
|
34167
|
-
|
|
34168
|
-
|
|
34169
|
-
|
|
34170
|
-
this.setAndEmit('batteryLevel',
|
|
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