node-red-contrib-homebridge-automation 0.1.12-beta.9 → 0.2.1-beta.0

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.
Files changed (41) hide show
  1. package/.github/npm-version-script.js +35 -43
  2. package/.github/workflows/Build and Publish.yml +81 -75
  3. package/README.md +7 -4
  4. package/eslint.config.mjs +34 -0
  5. package/package.json +34 -25
  6. package/src/HAP-NodeRed.html +71 -71
  7. package/src/HAP-NodeRed.js +32 -1082
  8. package/src/HapDeviceRoutes.js +59 -0
  9. package/src/hbBaseNode.js +94 -0
  10. package/src/hbConfigNode.js +239 -0
  11. package/src/hbConfigNode.test.js +2179 -0
  12. package/src/hbControlNode.js +77 -0
  13. package/src/hbEventNode.js +23 -0
  14. package/src/hbResumeNode.js +63 -0
  15. package/src/hbStatusNode.js +37 -0
  16. package/test/node-red/.config.nodes.json +453 -0
  17. package/test/node-red/.config.nodes.json.backup +453 -0
  18. package/test/node-red/.config.runtime.json +4 -0
  19. package/test/node-red/.config.runtime.json.backup +3 -0
  20. package/test/node-red/.config.users.json +23 -0
  21. package/test/node-red/.config.users.json.backup +20 -0
  22. package/test/node-red/.flows.json.backup +2452 -0
  23. package/test/node-red/flows.json +2453 -0
  24. package/test/node-red/package.json +6 -0
  25. package/test/node-red/settings.js +593 -0
  26. package/test/node-red/test/node-red/.config.nodes.json +430 -0
  27. package/test/node-red/test/node-red/.config.runtime.json +4 -0
  28. package/test/node-red/test/node-red/.config.runtime.json.backup +3 -0
  29. package/test/node-red/test/node-red/.config.users.json +20 -0
  30. package/test/node-red/test/node-red/.config.users.json.backup +17 -0
  31. package/test/node-red/test/node-red/package.json +6 -0
  32. package/test/node-red/test/node-red/settings.js +593 -0
  33. package/.eslintrc.js +0 -24
  34. package/.nycrc.json +0 -11
  35. package/src/lib/Accessory.js +0 -126
  36. package/src/lib/Characteristic.js +0 -30
  37. package/src/lib/HbAccessories.js +0 -167
  38. package/src/lib/Homebridge.js +0 -71
  39. package/src/lib/Homebridges.js +0 -68
  40. package/src/lib/Service.js +0 -307
  41. package/src/lib/register.js +0 -156
@@ -1,126 +0,0 @@
1
- var debug = require('debug')('Accessory');
2
- var Service = require('./Service.js').Service;
3
-
4
- module.exports = {
5
- Accessory: Accessory
6
- };
7
-
8
- /*
9
- * Homebridges -> Homebridge -> Accessory -> Service -> Characteristic
10
- */
11
-
12
- function Accessory(devices, context) {
13
- // debug("Accessory", devices);
14
- this.aid = devices.aid;
15
- this.host = context.host;
16
- this.port = context.port;
17
- this.homebridge = context.homebridge;
18
- this.id = context.id;
19
- this.services = [];
20
- devices.services.forEach(function (element) {
21
- // debug("Service", element);
22
- switch (element.type.substring(0, 8)) {
23
- case "0000003E": // Accessory Information
24
- this.info = information(element.characteristics);
25
- break;
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;
35
- case "000000D9": // Input Source from webosTV has a dummy input source
36
- var service = new Service(element, this);
37
- if (service.name !== "dummy") {
38
- this.services.push(service);
39
- }
40
- break;
41
- default:
42
- var service = new Service(element, this);
43
- this.services.push(service);
44
- }
45
- }.bind(this));
46
- // debug("Info", this.info);
47
- }
48
-
49
- Accessory.prototype.toList = function (context) {
50
- var list = [];
51
- // debug("toList", context);
52
- context.aid = this.aid;
53
- if (!this.info) {
54
- console.log("ERROR: incorrect version of plugin, please upgrade");
55
- }
56
- context.name = this.info.Name;
57
- context.manufacturer = this.info.Manufacturer;
58
- for (var index in this.services) {
59
- var service = this.services[index].toList(context);
60
- if (service) {
61
- list = list.concat(service);
62
- }
63
- }
64
-
65
- // debug('toList', new Error('test'));
66
- // debug("opt",context.opt,list.length);
67
- return (list);
68
- };
69
-
70
- /*
71
- [ { iid: 2,
72
- type: '00000014-0000-1000-8000-0026BB765291',
73
- perms: [Array],
74
- format: 'bool',
75
- description: 'Identify' },
76
- { iid: 3,
77
- type: '00000020-0000-1000-8000-0026BB765291',
78
- perms: [Array],
79
- format: 'string',
80
- value: 'NorthernMan54',
81
- description: 'Manufacturer' },
82
- { iid: 4,
83
- type: '00000021-0000-1000-8000-0026BB765291',
84
- perms: [Array],
85
- format: 'string',
86
- value: 'dht22',
87
- description: 'Model' },
88
- { iid: 5,
89
- type: '00000023-0000-1000-8000-0026BB765291',
90
- perms: [Array],
91
- format: 'string',
92
- value: 'Basement',
93
- description: 'Name' },
94
- { iid: 6,
95
- type: '00000030-0000-1000-8000-0026BB765291',
96
- perms: [Array],
97
- format: 'string',
98
- value: 'penny-Basement',
99
- description: 'Serial Number' },
100
- { iid: 7,
101
- type: '00000052-0000-1000-8000-0026BB765291',
102
- perms: [Array],
103
- format: 'string',
104
- value: '0.1.21',
105
- description: 'Firmware Revision' } ],
106
- */
107
-
108
- /*
109
- { Identify: undefined,
110
- Manufacturer: 'Default-Manufacturer',
111
- Model: 'Default-Model',
112
- Name: 'FHall',
113
- SerialNumber: 'Default-SerialNumber',
114
- FirmwareRevision: '1.0' }
115
- */
116
-
117
- function information(characteristics) {
118
- var result = {};
119
- characteristics.forEach(function (characteristic) {
120
- if (characteristic.description) {
121
- var key = characteristic.description.replace(/ /g, '').replace(/\./g, '_');
122
- result[key] = characteristic.value;
123
- }
124
- });
125
- return result;
126
- }
@@ -1,30 +0,0 @@
1
- var debug = require('debug')('Characteristic');
2
- // var Service = require('./Service.js').Service;
3
-
4
- module.exports = {
5
- Characteristic: Characteristic
6
- };
7
-
8
- /*
9
- * Homebridges -> Homebridge -> Accessory -> Service -> Characteristic
10
- */
11
-
12
- function Characteristic(devices, context) {
13
- // debug("Characteristic", devices);
14
- this.iid = devices.iid;
15
- this.type = devices.type.substring(0, 8);
16
- this.perms = devices.perms;
17
- this.value = devices.value;
18
- this.description = (devices.description ? devices.description : this.type);
19
- this.characteristic = {};
20
- this.getCharacteristic = context.aid + '.' + this.iid;
21
- this.characteristic[this.getCharacteristic] = {
22
- characteristic: this.description.replace(/ /g, "").replace(/\./g, "_"),
23
- iid: this.iid
24
- };
25
- this.eventRegister = {
26
- aid: context.aid,
27
- iid: this.iid,
28
- "ev": true
29
- };
30
- }
@@ -1,167 +0,0 @@
1
- var debug = require('debug')('HbAccessories');
2
-
3
- module.exports = {
4
- HbAccessories: HbAccessories
5
- };
6
-
7
- function HbAccessories(devices, opt) {
8
- debug("HbAccessories", devices);
9
- if (typeof devices === 'array') {
10
- devices.forEach(function(element) {
11
- // debug('Device', element);
12
- events = events.concat(_instance(element, perms));
13
- });
14
- }
15
- }
16
-
17
- /*
18
- function registerEv(homebridge, devices) {
19
- return register(homebridge, devices, 'ev');
20
- }
21
-
22
- function registerCt(homebridge, devices) {
23
- return register(homebridge, devices, 'pw');
24
- }
25
- */
26
-
27
- function register(homebridge, devices, perms) {
28
- // debug('Discovered', devices);
29
- var events = [];
30
- devices.forEach(function(element) {
31
- // debug('Device', element);
32
- events = events.concat(_instance(element, perms));
33
- });
34
- return (events);
35
- }
36
-
37
- function _instance(instance, perms) {
38
- // debug('Accessories', instance.accessories.accessories);
39
- var events = [];
40
- instance.accessories.accessories.forEach(function(accessory) {
41
- // debug('Accessory', instance.instance.txt);
42
- events = events.concat(_service({
43
- "host": instance.ipAddress,
44
- "port": instance.instance.port,
45
- "homebridge": instance.instance.txt.md,
46
- "id": instance.instance.txt.id,
47
- "aid": accessory.aid
48
- }, accessory.services, perms));
49
- });
50
- return (events);
51
- }
52
-
53
- function _service(context, accessory, perms) {
54
- var events = [];
55
- accessory.forEach(function(service) {
56
- // debug('Service', service);
57
- switch (service.type.substring(0, 8)) {
58
- case "00000043": // Lightbulb
59
- case "00000047": // Outlet
60
- case "00000049": // Switch
61
- case "00000040": // Fan
62
- case "0000008C": // WindowCovering
63
- case "0000008A": // TemperatureSensor
64
- case "000000B7": // Fan 2 aka Dyson
65
- case "00000041": // Garage Door
66
- case "000000D0": // Valve aka sprinkler
67
- // case "0000003E": // AccessoryInformation
68
- case "0000004A": // Thermostat
69
- case "00000080": // Contact Sensor
70
- case "00000085": // Motion Sensor
71
- case "00000111": // Camera
72
- // debug('Supported Service', service);
73
- events = events.concat(_characteristics(context, service, perms));
74
- // debug("Events", events);
75
- break;
76
- case "0000003E": // AccessoryInformation
77
- _name(context, service);
78
- // debug("Events", events);
79
- break;
80
- default:
81
- }
82
- });
83
- return (events);
84
- }
85
-
86
- function _characteristics(context, service, perms) {
87
- // debug("Char", service, Array.isArray(service));
88
-
89
- var events = [];
90
- service.characteristics.forEach(function(characteristic) {
91
- switch (characteristic.type.substring(0, 8)) {
92
- case "00000020": // manufacturer
93
- context.manufacturer = characteristic.value;
94
- break;
95
- case "00000023": // name
96
- context.name = characteristic.value;
97
- break;
98
- }
99
-
100
- if (characteristic.perms.includes(perms)) {
101
- context.iid = characteristic.iid;
102
- context.function = characteristic.description;
103
- context.service = service.type.substring(0, 8);
104
- context.characteristic = characteristic.type.substring(0, 8);
105
- context.deviceType = _normalizeName(context.service);
106
- // debug("Register", context);
107
- context.fullName = context.name + ' - ' + _normalizeName(context.service) + ' - ' + context.function;
108
- context.sortName = context.name + ':' + _normalizeName(context.service) + ':' + context.function;
109
- context.uniqueId = context.homebridge + context.id + context.manufacturer + context.name + context.service + context.characteristic;
110
- // debug("Perms ", context.fullName, characteristic.perms);
111
- events.push(JSON.parse(JSON.stringify(context)));
112
- }
113
- });
114
- // debug("Char Events", events);
115
- return (events);
116
- }
117
-
118
- function _name(context, service) {
119
- // debug("Char", service, Array.isArray(service));
120
-
121
- var manufacturer, name;
122
- service.characteristics.forEach(function(characteristic) {
123
- switch (characteristic.type.substring(0, 8)) {
124
- case "00000020": // manufacturer
125
- context.manufacturer = characteristic.value;
126
- break;
127
- case "00000023": // name
128
- context.name = characteristic.value;
129
- break;
130
- }
131
- });
132
- // debug("Char Events", events);
133
- // return ({ "manufacturer": manufacturer, "name": name});
134
- }
135
-
136
- function _normalizeName(id) {
137
- switch (id) {
138
- case "00000043": // Lightbulb
139
- return ("Lightbulb");
140
- case "00000047": // Outlet
141
- return ("Outlet");
142
- case "00000049": // Switch
143
- return ("Switch");
144
- case "000000B7": // Fan 2 aka Dyson
145
- case "00000040": // Fan
146
- return ("Fan");
147
- case "0000008C": // WindowCovering
148
- return ("Blinds");
149
- case "0000008A": // TemperatureSensor
150
- return ("Temperature");
151
- case "00000041": // Garage Door
152
- return ("Garage Door");
153
- case "000000D0": // Valve aka sprinkler
154
- return ("Sprinkler");
155
- // case "0000003E": // AccessoryInformation
156
- case "0000004A": // Thermostat
157
- return ("Thermostat");
158
- case "00000080": // Contact Sensor
159
- return ("Contact");
160
- case "00000085": // Motion Sensor
161
- return ("Motion");
162
- case "00000111": // Camera
163
- return ("Camera");
164
- default:
165
- debug("Missing HB Type", id);
166
- }
167
- }
@@ -1,71 +0,0 @@
1
- var debug = require('debug')('Homebridge');
2
- var Accessory = require('./Accessory.js').Accessory;
3
-
4
- module.exports = {
5
- Homebridge: Homebridge
6
- };
7
-
8
- /*
9
- * Homebridges -> Homebridge -> Accessory -> Service -> Characteristic
10
- */
11
-
12
- /*
13
-
14
- { ipAddress: '192.168.1.202',
15
- instance:
16
- { addresses: [ '192.168.1.202', 'fe80::eab6:f43b:eb39:9d7f' ],
17
- name: 'Leonard-Aztest-A6F3',
18
- fqdn: 'Leonard-Aztest-A6F3._hap._tcp.local',
19
- host: 'AC_22_3D_E3_CE_32.local',
20
- referer:
21
- { address: '192.168.1.202',
22
- family: 'IPv4',
23
- port: 5353,
24
- size: 374 },
25
- port: 51828,
26
- type: 'hap',
27
- protocol: 'tcp',
28
- subtypes: [],
29
- rawTxt: <Buffer 11 6d 64 3d 4c 65 6f 6e 61 72 64 2d 41 7a 74 65 73 74 06 70 76 3d 31 2e 30 14 69 64 3d 41 43 3a 32 32 3a 33 44 3a 45 33 3a 43 45 3a 33 32 04 63 23 3d ... >,
30
- txt:
31
- { md: 'Leonard-Aztest',
32
- pv: '1.0',
33
- id: 'AC:22:3D:E3:CE:32',
34
- 'c#': '5',
35
- 's#': '1',
36
- ff: '0',
37
- ci: '2',
38
- sf: '1',
39
- sh: 'HjMYzQ==' } },
40
- accessories: { accessories: [ [Object], [Object] ] } }
41
- */
42
-
43
- function Homebridge(devices) {
44
- // debug("Homebridge", devices);
45
- this.accessories = [];
46
- this.host = devices.ipAddress;
47
- this.port = devices.instance.port;
48
- this.homebridge = devices.instance.txt.md;
49
- this.id = devices.instance.txt.id;
50
- devices.accessories.accessories.forEach(function(element) {
51
- var accessory = new Accessory(element, this);
52
- this.accessories.push(accessory);
53
- }.bind(this));
54
- }
55
-
56
- Homebridge.prototype.toList = function(opt) {
57
- var list = [];
58
- for (var index in this.accessories) {
59
- var accessory = this.accessories[index];
60
- list = list.concat(accessory.toList({
61
- host: this.host,
62
- port: this.port,
63
- homebridge: this.homebridge,
64
- id: this.id,
65
- opt: opt
66
- }));
67
- // list.push(accessory.toList());
68
- }
69
- // debug("opt",opt,list.length);
70
- return (list);
71
- };
@@ -1,68 +0,0 @@
1
- // var debug = require('debug')('Homebridges');
2
- var Homebridge = require('./Homebridge.js').Homebridge;
3
-
4
- module.exports = {
5
- Homebridges: Homebridges
6
- };
7
-
8
- /*
9
- * Homebridges -> Homebridge -> Accessory -> Service -> Characteristic
10
- */
11
-
12
- function Homebridges(devices) {
13
- // debug("Homebridges", devices);
14
- this.homebridges = [];
15
- devices.forEach(function(element) {
16
- var homebridge = new Homebridge(element);
17
- this.homebridges.push(homebridge);
18
- }.bind(this));
19
- }
20
-
21
- /**
22
- * Homebridges.toList - description
23
- *
24
- * @param {type} opt description
25
- * @return {type} description
26
- */
27
-
28
- Homebridges.prototype.toList = function(opt) {
29
- var list = [];
30
- for (var index in this.homebridges) {
31
- var homebridge = this.homebridges[index];
32
- // list.push(homebridge.toList());
33
- list = list.concat(homebridge.toList(opt));
34
- }
35
-
36
- list.sort((a, b) => (a.sortName > b.sortName) ? 1 : ((b.sortName > a.sortName) ? -1 : 0));
37
- // debug("opt",opt,list.length);
38
- return (list);
39
- };
40
-
41
- /* {
42
- "characteristics": [{
43
- "aid": endpoint.aid,
44
- "iid": endpoint.iid,
45
- "ev": true
46
- }]
47
- };
48
- */
49
-
50
- Homebridges.prototype.findDevice = function(node, opt) {
51
- var list = [];
52
- for (var index in this.homebridges) {
53
- var homebridge = this.homebridges[index];
54
- // list.push(homebridge.toList());
55
- list = list.concat(homebridge.toList(opt));
56
- }
57
- return (list.find(x => x.uniqueId === node));
58
- };
59
-
60
- Homebridges.prototype.findDeviceByName = function(name, opt) {
61
- var list = [];
62
- for (var index in this.homebridges) {
63
- var homebridge = this.homebridges[index];
64
- // list.push(homebridge.toList());
65
- list = list.concat(homebridge.toList(opt));
66
- }
67
- return (list.find(x => x.name === name));
68
- };