homebridge-rtl 0.1.1-beta.0 → 0.1.1-beta.2
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/package.json +3 -3
- package/src/sensor.js +27 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-rtl",
|
|
3
|
-
"version": "0.1.1-beta.
|
|
3
|
+
"version": "0.1.1-beta.2",
|
|
4
4
|
"description": "RTL_433 based sensor for Homebridge",
|
|
5
5
|
"main": "src/sensor.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
32
|
"homebridge": "^1.6.0 || ^2.0.0",
|
|
33
|
-
"node": "
|
|
33
|
+
"node": ">=18"
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://github.com/northernman54/homebridge-rtl#readme",
|
|
36
36
|
"dependencies": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
],
|
|
59
59
|
"ext": "js",
|
|
60
60
|
"ignore": [],
|
|
61
|
-
"exec": "~/
|
|
61
|
+
"exec": "NODE_PATH=`pwd`:.. DEBUG=-HAP-NodeJS:*,homebridge-rtl_433* node ~/node_modules/homebridge-config-ui-x/dist/bin/hb-service.js run --stdout -U ./test/hbConfig -T -D -I -P ./",
|
|
62
62
|
"signal": "SIGTERM",
|
|
63
63
|
"env": {
|
|
64
64
|
"NODE_OPTIONS": "--trace-warnings"
|
package/src/sensor.js
CHANGED
|
@@ -6,7 +6,7 @@ const moment = require('moment');
|
|
|
6
6
|
var os = require("os");
|
|
7
7
|
var _ = require('lodash');
|
|
8
8
|
var hostname = os.hostname();
|
|
9
|
-
var homebridgeLib = require('homebridge-lib');
|
|
9
|
+
//var homebridgeLib = require('homebridge-lib');
|
|
10
10
|
|
|
11
11
|
let Service, Characteristic;
|
|
12
12
|
var CustomCharacteristics;
|
|
@@ -17,7 +17,19 @@ var myAccessories = [];
|
|
|
17
17
|
module.exports = (homebridge) => {
|
|
18
18
|
Service = homebridge.hap.Service;
|
|
19
19
|
Characteristic = homebridge.hap.Characteristic;
|
|
20
|
-
CustomCharacteristics = new homebridgeLib.EveHomeKitTypes(homebridge).Characteristics;
|
|
20
|
+
//CustomCharacteristics = new homebridgeLib.EveHomeKitTypes(homebridge).Characteristics;
|
|
21
|
+
var LastActivation = function() {
|
|
22
|
+
Characteristic.call(this, 'Last Activation', 'E863F11A-079E-48FF-8F27-9C2605A29F52');
|
|
23
|
+
this.setProps({
|
|
24
|
+
format: Characteristic.Formats.UINT32,
|
|
25
|
+
unit: Characteristic.Units.SECONDS,
|
|
26
|
+
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
|
|
27
|
+
});
|
|
28
|
+
this.value = this.getDefaultValue();
|
|
29
|
+
};
|
|
30
|
+
require('util').inherits(LastActivation, Characteristic);
|
|
31
|
+
LastActivation.UUID = 'E863F11A-079E-48FF-8F27-9C2605A29F52';
|
|
32
|
+
CustomCharacteristics = { LastActivation: LastActivation };
|
|
21
33
|
FakeGatoHistoryService = require('fakegato-history')(homebridge);
|
|
22
34
|
|
|
23
35
|
homebridge.registerPlatform('homebridge-rtl', 'rtl_433', rtl433Plugin);
|
|
@@ -45,7 +57,7 @@ rtl433Plugin.prototype = {
|
|
|
45
57
|
accessories: function (callback) {
|
|
46
58
|
for (var i in this.devices) {
|
|
47
59
|
this.log("Adding device", i, this.devices[i].name);
|
|
48
|
-
myAccessories.push(new Rtl433Accessory(this.devices[i], this.log, i));
|
|
60
|
+
myAccessories.push(new Rtl433Accessory(this.devices[i], this.log, i, this.storage, this.refresh));
|
|
49
61
|
}
|
|
50
62
|
callback(myAccessories);
|
|
51
63
|
// console.log("Pre-This", this);
|
|
@@ -62,14 +74,14 @@ function rtl433Server() {
|
|
|
62
74
|
// if you start rtl_433 outside homebride to get log: rtl_433 -v -F json -C si -M protocol > /tmp/rtl433.json
|
|
63
75
|
//var proc = childProcess.spawn('/usr/bin/truncate -s 0 /tmp/rtl433.json;/usr/bin/tail', ['-F','/tmp/rtl433.json'], {
|
|
64
76
|
////8/28/2022 JDR added this for Windows. fixed command line arguments. They weren't working for Windows, but should still work for others.
|
|
65
|
-
var proc = childProcess.spawn(this.killCommand + '; ' + this.rtl433Path + this.rtl433Bin
|
|
77
|
+
var proc = childProcess.spawn(this.killCommand + '; ' + this.rtl433Path + this.rtl433Bin + ' -d 0 -F json -C si', [], {
|
|
66
78
|
shell: true
|
|
67
79
|
});
|
|
68
80
|
readline.createInterface({
|
|
69
81
|
input: proc.stdout,
|
|
70
82
|
terminal: false
|
|
71
83
|
}).on('line', function (message) {
|
|
72
|
-
this.log("Message", message.toString());
|
|
84
|
+
//this.log("Message", message.toString());
|
|
73
85
|
debug("Message", message.toString());
|
|
74
86
|
|
|
75
87
|
if (message.toString().startsWith('{')) {
|
|
@@ -117,7 +129,7 @@ function rtl433Server() {
|
|
|
117
129
|
}.bind(this));
|
|
118
130
|
}
|
|
119
131
|
|
|
120
|
-
function Rtl433Accessory(device, log, unit) {
|
|
132
|
+
function Rtl433Accessory(device, log, unit, storage, refresh) {
|
|
121
133
|
this.id = device.id;
|
|
122
134
|
this.type = device.type;
|
|
123
135
|
this.log = log;
|
|
@@ -125,6 +137,8 @@ function Rtl433Accessory(device, log, unit) {
|
|
|
125
137
|
this.alarm = device['alarm']
|
|
126
138
|
this.deviceTimeout = device['timeout'] || 120; // Mark as unavailable after 2 hours
|
|
127
139
|
this.humidity = device['humidity'] || false; // Add humidity data to temerature sensor
|
|
140
|
+
this.storage = storage || 'fs';
|
|
141
|
+
this.refresh = refresh || 60;
|
|
128
142
|
}
|
|
129
143
|
|
|
130
144
|
Rtl433Accessory.prototype = {
|
|
@@ -377,9 +391,9 @@ Rtl433Accessory.prototype = {
|
|
|
377
391
|
}
|
|
378
392
|
|
|
379
393
|
if (this.alarm !== undefined) {
|
|
380
|
-
return [informationService, this.sensorService, this.alarmService, this.loggingService];
|
|
394
|
+
return [informationService, this.sensorService, this.alarmService, this.loggingService].filter(Boolean);
|
|
381
395
|
} else {
|
|
382
|
-
return [informationService, this.sensorService, this.loggingService];
|
|
396
|
+
return [informationService, this.sensorService, this.loggingService].filter(Boolean);
|
|
383
397
|
}
|
|
384
398
|
}
|
|
385
399
|
};
|
|
@@ -405,25 +419,17 @@ function getDevices(unit) {
|
|
|
405
419
|
}
|
|
406
420
|
}
|
|
407
421
|
if (devices.length === 0) {
|
|
408
|
-
|
|
409
|
-
|
|
422
|
+
debug("FYI: Message from unknown device ID", unit);
|
|
423
|
+
debug("Message", this.message.toString());
|
|
410
424
|
}
|
|
411
425
|
return devices;
|
|
412
426
|
}
|
|
413
427
|
|
|
414
|
-
function seconds(dateTime) {
|
|
415
|
-
// "2018-10-01 20:52:33"
|
|
416
|
-
var hms = dateTime.split(" ");
|
|
417
|
-
// debug("TIME", hms[1]);
|
|
418
|
-
var tt = hms[1].split(":");
|
|
419
|
-
var sec = tt[0] * 3600 + tt[1] * 60 + tt[2] * 1;
|
|
420
|
-
return (sec);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
428
|
function duplicateMessage(last, current) {
|
|
424
429
|
if (last) {
|
|
425
|
-
|
|
426
|
-
|
|
430
|
+
var lastMs = Date.parse(last.time.replace(' ', 'T'));
|
|
431
|
+
var currentMs = Date.parse(current.time.replace(' ', 'T'));
|
|
432
|
+
if (!isNaN(lastMs) && !isNaN(currentMs) && Math.abs(currentMs - lastMs) < 2000) {
|
|
427
433
|
var tCurrent = Object.assign({}, current);
|
|
428
434
|
var tLast = Object.assign({}, last);
|
|
429
435
|
delete tCurrent.time;
|