node-red-contrib-homebridge-automation 0.1.12-beta.0 → 0.1.12-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/.eslintrc.js +24 -0
- package/.nycrc.json +11 -0
- package/.prettierrc +6 -0
- package/README.md +1 -1
- package/package.json +21 -4
- package/src/HAP-NodeRed.js +1 -1
- package/src/lib/Accessory.js +12 -5
- package/test/flows.js +42 -0
- package/test/test_spec.js +40 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
env: {
|
|
3
|
+
es6: true,
|
|
4
|
+
node: true,
|
|
5
|
+
mocha: true,
|
|
6
|
+
},
|
|
7
|
+
extends: ['eslint:recommended', 'plugin:mocha/recommended'],
|
|
8
|
+
globals: {
|
|
9
|
+
Atomics: 'readonly',
|
|
10
|
+
SharedArrayBuffer: 'readonly',
|
|
11
|
+
},
|
|
12
|
+
parserOptions: {
|
|
13
|
+
ecmaVersion: 2018,
|
|
14
|
+
sourceType: 'module',
|
|
15
|
+
},
|
|
16
|
+
plugins: ['mocha'],
|
|
17
|
+
rules: {
|
|
18
|
+
indent: ['error', 2, { SwitchCase: 1 }],
|
|
19
|
+
'linebreak-style': ['error', 'unix'],
|
|
20
|
+
quotes: ['error', 'single'],
|
|
21
|
+
semi: ['error', 'always'],
|
|
22
|
+
'no-console': 'off',
|
|
23
|
+
},
|
|
24
|
+
};
|
package/.nycrc.json
ADDED
package/.prettierrc
ADDED
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ The above Node-RED Flow, turns on my 'Outside Office' light when the powder room
|
|
|
60
60
|
* [To start Node-RED in DEBUG mode, and output Homebridge-Automation debug logs start Node-RED like this.](#to-start-node-red-in-debug-mode-and-output-homebridge-automation-debug-logs-start-node-red-like-this)
|
|
61
61
|
|
|
62
62
|
<!-- Created by https://github.com/ekalinin/github-markdown-toc -->
|
|
63
|
-
<!-- Added by: runner, at: Fri Jul 5
|
|
63
|
+
<!-- Added by: runner, at: Fri Jul 5 22:24:05 UTC 2024 -->
|
|
64
64
|
|
|
65
65
|
<!--te-->
|
|
66
66
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-homebridge-automation",
|
|
3
|
-
"version": "0.1.12-beta.
|
|
3
|
+
"version": "0.1.12-beta.2",
|
|
4
4
|
"description": "NodeRED Automation for HomeBridge",
|
|
5
5
|
"main": "src/HAP-NodeRed.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
7
|
"api": "documentation build HAP-NodeRed.js -f md --config docs/documentation.yml > docs/API.md",
|
|
9
8
|
"document": "./gh-md-toc --insert README.md; rm README.md.orig.* README.md.toc.*",
|
|
10
|
-
"watch": "nodemon"
|
|
9
|
+
"watch": "nodemon",
|
|
10
|
+
"coverage": "nyc npm t",
|
|
11
|
+
"format": "prettier --write {.,test}/*.js *.html *.md",
|
|
12
|
+
"lint": "eslint {.,test}/*.js",
|
|
13
|
+
"test": "mocha \"test/**/*_spec.js\""
|
|
11
14
|
},
|
|
12
15
|
"keywords": [
|
|
13
16
|
"node-red",
|
|
@@ -23,8 +26,22 @@
|
|
|
23
26
|
"url": "git+https://github.com/NorthernMan54/node-red-contrib-homebridge-automation.git"
|
|
24
27
|
},
|
|
25
28
|
"devDependencies": {
|
|
26
|
-
"
|
|
29
|
+
"@types/node-red": "^0.20.7",
|
|
30
|
+
"@types/jest": "^29.5.12",
|
|
31
|
+
"documentation": "14.0.3",
|
|
32
|
+
"eslint": "^8.57.0",
|
|
33
|
+
"eslint-config-airbnb-typescript": "^18.0.0",
|
|
34
|
+
"eslint-plugin-import": "^2.29.1",
|
|
35
|
+
"eslint-plugin-import-newlines": "^1.4.0",
|
|
36
|
+
"eslint-plugin-jest": "^28.6.0",
|
|
37
|
+
"eslint-plugin-sort-exports": "^0.9.1",
|
|
38
|
+
"mocha": "^10.6.0",
|
|
39
|
+
"node-red": "^4.0.2",
|
|
40
|
+
"node-red-node-test-helper": "^0.3.4",
|
|
27
41
|
"nodemon": "^3.1.4",
|
|
42
|
+
"nyc": "^17.0.0",
|
|
43
|
+
"prettier": "^3.3.2",
|
|
44
|
+
"rimraf": "^5.0.7",
|
|
28
45
|
"semver": "^7.6.2"
|
|
29
46
|
},
|
|
30
47
|
"dependencies": {
|
package/src/HAP-NodeRed.js
CHANGED
|
@@ -233,7 +233,7 @@ module.exports = function (RED) {
|
|
|
233
233
|
}, function (err, message) {
|
|
234
234
|
if (!err) {
|
|
235
235
|
node.state = _convertHBcharactericToNode(message.characteristics, node);
|
|
236
|
-
debug("hbEvent received: %s = %s", node.fullName, JSON.stringify(message.characteristics),
|
|
236
|
+
debug("hbEvent received: %s = %s", node.fullName, JSON.stringify(message.characteristics).slice(0, 80)+'...');
|
|
237
237
|
if (node.sendInitialState) {
|
|
238
238
|
var msg = {
|
|
239
239
|
name: node.name,
|
package/src/lib/Accessory.js
CHANGED
|
@@ -17,14 +17,21 @@ function Accessory(devices, context) {
|
|
|
17
17
|
this.homebridge = context.homebridge;
|
|
18
18
|
this.id = context.id;
|
|
19
19
|
this.services = [];
|
|
20
|
-
devices.services.forEach(function(element) {
|
|
20
|
+
devices.services.forEach(function (element) {
|
|
21
21
|
// debug("Service", element);
|
|
22
22
|
switch (element.type.substring(0, 8)) {
|
|
23
23
|
case "0000003E": // Accessory Information
|
|
24
24
|
this.info = information(element.characteristics);
|
|
25
25
|
break;
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
case "00000110": // Camera RTPStream Management generates duplicates
|
|
27
|
+
var service = new Service(element, this);
|
|
28
|
+
console.log('services', this.services);
|
|
29
|
+
if (this.services.some(e => e.type === '00000110')) {
|
|
30
|
+
|
|
31
|
+
} else {
|
|
32
|
+
this.services.push(service);
|
|
33
|
+
}
|
|
34
|
+
break;
|
|
28
35
|
case "000000D9": // Input Source from webosTV has a dummy input source
|
|
29
36
|
var service = new Service(element, this);
|
|
30
37
|
if (service.name !== "dummy") {
|
|
@@ -39,7 +46,7 @@ function Accessory(devices, context) {
|
|
|
39
46
|
// debug("Info", this.info);
|
|
40
47
|
}
|
|
41
48
|
|
|
42
|
-
Accessory.prototype.toList = function(context) {
|
|
49
|
+
Accessory.prototype.toList = function (context) {
|
|
43
50
|
var list = [];
|
|
44
51
|
// debug("toList", context);
|
|
45
52
|
context.aid = this.aid;
|
|
@@ -109,7 +116,7 @@ Accessory.prototype.toList = function(context) {
|
|
|
109
116
|
|
|
110
117
|
function information(characteristics) {
|
|
111
118
|
var result = {};
|
|
112
|
-
characteristics.forEach(function(characteristic) {
|
|
119
|
+
characteristics.forEach(function (characteristic) {
|
|
113
120
|
if (characteristic.description) {
|
|
114
121
|
var key = characteristic.description.replace(/ /g, '').replace(/\./g, '_');
|
|
115
122
|
result[key] = characteristic.value;
|
package/test/flows.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const Flows = {
|
|
2
|
+
getDefault: function (options) {
|
|
3
|
+
let defaultFlow = [
|
|
4
|
+
{
|
|
5
|
+
id: 'status1',
|
|
6
|
+
type: 'hb-status',
|
|
7
|
+
name: 'StatusNode1',
|
|
8
|
+
Homebridge: 'homebridge',
|
|
9
|
+
Manufacturer: 'TestModule',
|
|
10
|
+
Service: 'Switch',
|
|
11
|
+
device: 'homebridgeAA:BB:CC:DD:EE:FF0StatusNode100000049',
|
|
12
|
+
conf: 'conf1',
|
|
13
|
+
wires: [['n2']],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
id: 'control1',
|
|
17
|
+
type: 'hb-control',
|
|
18
|
+
name: 'ControlNode1',
|
|
19
|
+
Homebridge: 'homebridge',
|
|
20
|
+
Manufacturer: 'TestModule',
|
|
21
|
+
Service: 'Outlet',
|
|
22
|
+
device: 'homebridgeAA:BB:CC:DD:EE:FF0ControlNode1h00000047',
|
|
23
|
+
conf: 'conf1',
|
|
24
|
+
outputs: 0,
|
|
25
|
+
wires: [],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 'conf1',
|
|
29
|
+
type: 'hb-conf',
|
|
30
|
+
username: '031-45-154',
|
|
31
|
+
macAddress: 'AA:BB:CC:DD:EE:FF',
|
|
32
|
+
},
|
|
33
|
+
{ id: 'n2', type: 'helper' },
|
|
34
|
+
{ id: 'n3', type: 'helper' },
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
defaultFlow[0] = Object.assign(defaultFlow[0], options);
|
|
38
|
+
return defaultFlow;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
module.exports = Flows;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// var should = require('should');
|
|
2
|
+
var os = require('os');
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var helper = require('node-red-node-test-helper');
|
|
5
|
+
helper.init(require.resolve('node-red'), { userDir: os.tmpdir() });
|
|
6
|
+
|
|
7
|
+
var flows = require('./flows');
|
|
8
|
+
var hapNode = require('../src/HAP-NodeRed.js');
|
|
9
|
+
|
|
10
|
+
describe('HAP node', function () {
|
|
11
|
+
before(function (done) {
|
|
12
|
+
helper.startServer(done);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
after(function (done) {
|
|
16
|
+
helper.stopServer(done);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(function () {
|
|
20
|
+
helper.unload();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should be loaded', function (done) {
|
|
24
|
+
var flow = flows.getDefault();
|
|
25
|
+
|
|
26
|
+
helper.load(hapNode, flow, function () {
|
|
27
|
+
var conf1 = helper.getNode('conf1');
|
|
28
|
+
conf1.should.have.property('macAddress', 'AA:BB:CC:DD:EE:FF');
|
|
29
|
+
var stat1 = helper.getNode('status1');
|
|
30
|
+
stat1.should.have.property('name', 'StatusNode1');
|
|
31
|
+
var ctl1 = helper.getNode('control1');
|
|
32
|
+
ctl1.should.have.property('name', 'ControlNode1');
|
|
33
|
+
var logEvents = helper.log().args.filter(function (evt) {
|
|
34
|
+
return evt[0].type == 'hb-conf' || evt[0].type == 'hb-status';
|
|
35
|
+
});
|
|
36
|
+
logEvents.should.have.length(0);
|
|
37
|
+
done();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|