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,307 +0,0 @@
1
- var debug = require('debug')('Service');
2
- var Characteristic = require('./Characteristic.js').Characteristic;
3
-
4
- module.exports = {
5
- Service: Service
6
- };
7
-
8
- /*
9
- * Homebridges -> Homebridge -> Accessory -> Service -> Characteristic
10
- */
11
-
12
- /*
13
-
14
- This is a typical Service
15
-
16
- {
17
- "iid": 8,
18
- "type": "0000008A-0000-1000-8000-0026BB765291",
19
- "characteristics": [{
20
- "iid": 9,
21
- "type": "00000023-0000-1000-8000-0026BB765291",
22
- "perms": ["pr"],
23
- "format": "string",
24
- "value": "Cold Cellar",
25
- "description": "Name"
26
- }, {
27
- "iid": 10,
28
- "type": "00000011-0000-1000-8000-0026BB765291",
29
- "perms": ["pr", "ev"],
30
- "format": "float",
31
- "value": 4.9,
32
- "description": "Current Temperature",
33
- "unit": "celsius",
34
- "maxValue": 100,
35
- "minValue": -100,
36
- "minStep": 0.1
37
- }, {
38
- "iid": 11,
39
- "type": "00000010-0000-1000-8000-0026BB765291",
40
- "perms": ["pr", "ev"],
41
- "format": "float",
42
- "value": 51,
43
- "description": "Current Relative Humidity",
44
- "unit": "percentage",
45
- "maxValue": 100,
46
- "minValue": 0,
47
- "minStep": 1
48
- }, {
49
- "iid": 12,
50
- "type": "E863F10F-079E-48FF-8F27-9C2605A29F52",
51
- "perms": ["pr", "ev"],
52
- "format": "uint8",
53
- "value": 1011,
54
- "description": "Air Pressure",
55
- "unit": "mbar",
56
- "maxValue": 1200,
57
- "minValue": 800,
58
- "minStep": 1
59
- }],
60
- "primary": false,
61
- "hidden": false
62
- }
63
- */
64
-
65
- function Service(devices, context) {
66
- // debug("Service", JSON.stringify(devices));
67
- this.iid = devices.iid;
68
- this.type = devices.type.substring(0, 8);
69
- this.service = _normalizeName(this.type);
70
- this.aid = context.aid;
71
- this.host = context.host;
72
- this.port = context.port;
73
- this.homebridge = context.homebridge;
74
- this.id = context.id;
75
- this.characteristics = [];
76
- // Fix for homebridge 1.3.0
77
- devices.characteristics.forEach(function (element) {
78
- // var service = new Characteristic(element, this);
79
- if (element.type.substring(0, 8) === '00000023' && element.description === "Name") {
80
- this.name = element.value;
81
- } else if (element.type.substring(0, 8) === '000000E3' && element.description === "Configured Name") {
82
- this.configuredName = element.value;
83
- } else {
84
- // this.characteristics.push(service);
85
- }
86
- }.bind(this));
87
- devices.characteristics.forEach(function (element) {
88
- var service = new Characteristic(element, this);
89
- if (element.type.substring(0, 8) === '00000023' && element.description === "Name") {
90
- this.name = element.value;
91
- } else if (element.type.substring(0, 8) === '000000E3' && element.description === "Configured Name") {
92
- this.configuredName = element.value;
93
- } else {
94
- this.characteristics.push(service);
95
- }
96
- }.bind(this));
97
- if (this.configuredName) {
98
- this.name = this.configuredName;
99
- }
100
- // Uncomment to display services not defined
101
- // if (!this.service) {
102
- // console.log('Missing', devices);
103
- // }
104
- }
105
-
106
- Service.prototype.toList = function (context) {
107
- var descriptions;
108
- var getCharacteristics;
109
- var putCharacteristics = [];
110
- var eventRegisters = [];
111
- var characteristics = {};
112
- var fullName = context.name;
113
-
114
- if (this.name) {
115
- // Fix for #30
116
- if (context.manufacturer === "Nest" && (this.name === "Fan" || this.name === "Eco Mode")) {
117
- fullName = context.name + " - " + this.name;
118
- } else if (context.manufacturer === "Mitsubishi" && !fullName.includes(this.name)) {
119
- fullName = context.name + " - " + this.name;
120
- } else if (context.manufacturer === "Allterco") {
121
- fullName = context.name + " - " + this.name;
122
- } else {
123
- context.name = this.name;
124
- fullName = context.name;
125
- }
126
- }
127
-
128
- for (var index in this.characteristics) {
129
- var characteristic = this.characteristics[index];
130
- // debug("characteristic", characteristic)
131
- // debug("perms", context.opt);
132
- // debug("perms", (context.opt ? "perms" + context.opt.perms + characteristic.perms.includes(context.opt.perms) : "noperms"));
133
- if (characteristic.type !== '00000023' && characteristic.perms && (context.opt ? characteristic.perms.includes(context.opt.perms) : true)) {
134
- // debug("Yes", context.name, characteristic.description, characteristic.perms);
135
- descriptions = (descriptions ? descriptions + ', ' : '') + characteristic.description.replace(/ /g, "").replace(/\./g, "_");
136
- getCharacteristics = (getCharacteristics ? getCharacteristics + ',' : '') + characteristic.getCharacteristic;
137
- // characteristics = (characteristics ? characteristics + ',' : '') + characteristic.characteristic;
138
- characteristics = Object.assign(characteristics, characteristic.characteristic);
139
- putCharacteristics = putCharacteristics.concat(characteristic.putCharacteristic);
140
- eventRegisters = eventRegisters.concat(characteristic.eventRegister);
141
- } else {
142
- // debug("No", context.name, characteristic.description, characteristic.perms);
143
- }
144
- }
145
- if (this.service && descriptions) {
146
- return ({
147
- homebridge: context.homebridge,
148
- host: context.host,
149
- port: context.port,
150
- id: context.id,
151
- manufacturer: context.manufacturer,
152
- aid: this.aid,
153
- type: this.type,
154
- name: fullName,
155
- service: this.service,
156
- fullName: fullName + ' - ' + this.service,
157
- sortName: fullName + ':' + this.service,
158
- uniqueId: context.homebridge + this.id + context.manufacturer + fullName + this.type,
159
- descriptions: descriptions,
160
- characteristics: characteristics,
161
- getCharacteristics: getCharacteristics,
162
- eventRegisters: eventRegisters
163
- });
164
- }
165
- };
166
-
167
- function _normalizeName(id) {
168
- switch (id) {
169
- case "00000111":
170
- return ("Camera Control");
171
- case "00000088":
172
- return ("Stateful Programmable Switch");
173
- case "000000A1":
174
- return ("Bridge Configuration");
175
- case "00000062":
176
- return ("Bridging State");
177
- case "00000055":
178
- return ("Pairing");
179
- case "000000A2":
180
- return ("Protocol Information");
181
- case "0000005A":
182
- return ("Relay");
183
- case "00000099":
184
- return ("Time Information");
185
- case "00000056":
186
- return ("Tunneled BTLEAccessory Service");
187
- case "00000129":
188
- return ("Data Stream Transport Management");
189
- case "00000122":
190
- return ("Target Control Management");
191
- case "00000125":
192
- return ("Target Control");
193
- case "00000127":
194
- return ("Audio Stream Management");
195
- case "00000133":
196
- return ("Siri");
197
- case "000000D8":
198
- return ("Television");
199
- case "000000D9":
200
- return ("Input Source");
201
- case "000000DA":
202
- return ("Access Control");
203
- case "0000003E":
204
- return ("Accessory Information");
205
- case "000000BB":
206
- return ("Air Purifier");
207
- case "0000008D":
208
- return ("Air Quality Sensor");
209
- case "00000096":
210
- return ("Battery Service");
211
- case "00000110":
212
- return ("Camera RTPStream Management");
213
- case "00000097":
214
- return ("Carbon Dioxide Sensor");
215
- case "0000007F":
216
- return ("Carbon Monoxide Sensor");
217
- case "00000080":
218
- return ("Contact Sensor");
219
- case "00000081":
220
- return ("Door");
221
- case "00000121":
222
- return ("Doorbell");
223
- case "00000040":
224
- return ("Fan");
225
- case "000000B7":
226
- return ("Fan v2");
227
- case "000000BA":
228
- return ("Filter Maintenance");
229
- case "000000D7":
230
- return ("Faucet");
231
- case "00000041":
232
- return ("Garage Door Opener");
233
- case "000000BC":
234
- return ("Heater Cooler");
235
- case "000000BD":
236
- return ("Humidifier Dehumidifier");
237
- case "00000082":
238
- return ("Humidity Sensor");
239
- case "000000CF":
240
- return ("Irrigation System");
241
- case "00000083":
242
- return ("Leak Sensor");
243
- case "00000084":
244
- return ("Light Sensor");
245
- case "00000043":
246
- return ("Lightbulb");
247
- case "00000044":
248
- return ("Lock Management");
249
- case "00000045":
250
- return ("Lock Mechanism");
251
- case "00000112":
252
- return ("Microphone");
253
- case "00000085":
254
- return ("Motion Sensor");
255
- case "00000086":
256
- return ("Occupancy Sensor");
257
- case "00000047":
258
- return ("Outlet");
259
- case "0000007E":
260
- return ("Security System");
261
- case "000000CC":
262
- return ("Service Label");
263
- case "000000B9":
264
- return ("Slat");
265
- case "00000087":
266
- return ("Smoke Sensor");
267
- case "00000228":
268
- return ("Smart Speaker");
269
- case "00000113":
270
- return ("Speaker");
271
- case "00000089":
272
- return ("Stateless Programmable Switch");
273
- case "00000049":
274
- return ("Switch");
275
- case "0000008A":
276
- return ("Temperature Sensor");
277
- case "0000004A":
278
- return ("Thermostat");
279
- case "000000D0":
280
- return ("Valve");
281
- case "0000008B":
282
- return ("Window");
283
- case "0000008C":
284
- return ("Window Covering");
285
- case "0000021A":
286
- return ("Camera Operating Mode");
287
- case "00000204":
288
- return ("Camera Event Recording Management");
289
- case "0000020A":
290
- return ("WiFi Router");
291
- case "0000020F":
292
- return ("WiFi Satellite");
293
- case "00000221":
294
- return ("Power Management");
295
- case "00000203":
296
- return ("Transfer Transport Management");
297
- case "00000012":
298
- return ("Heartrate");
299
- // Eve types
300
- case "B77831FD":
301
- return ("Air Pressure Service");
302
- case "E863F007":
303
- return ("History Service");
304
- default:
305
- debug("Missing HB Type", id);
306
- }
307
- }
@@ -1,156 +0,0 @@
1
- var debug = require('debug')('register');
2
-
3
- module.exports = {
4
- registerEv: registerEv,
5
- registerCt: registerCt
6
- };
7
-
8
- function registerEv(homebridge, devices) {
9
- return register(homebridge, devices, 'ev');
10
- }
11
-
12
- function registerCt(homebridge, devices) {
13
- return register(homebridge, devices, 'pw');
14
- }
15
-
16
- function register(homebridge, devices, perms) {
17
- // debug('Discovered', devices);
18
- var events = [];
19
- devices.forEach(function(element) {
20
- // debug('Device', element);
21
- events = events.concat(_instance(element, perms));
22
- });
23
- return (events);
24
- }
25
-
26
- function _instance(instance, perms) {
27
- // debug('Accessories', instance.accessories.accessories);
28
- var events = [];
29
- instance.accessories.accessories.forEach(function(accessory) {
30
- // debug('Accessory', instance.instance.txt);
31
- events = events.concat(_service({
32
- "host": instance.ipAddress,
33
- "port": instance.instance.port,
34
- "homebridge": instance.instance.txt.md,
35
- "id": instance.instance.txt.id,
36
- "aid": accessory.aid
37
- }, accessory.services, perms));
38
- });
39
- return (events);
40
- }
41
-
42
- function _service(context, accessory, perms) {
43
- var events = [];
44
- accessory.forEach(function(service) {
45
- // debug('Service', service);
46
- switch (service.type.substring(0, 8)) {
47
- case "00000043": // Lightbulb
48
- case "00000047": // Outlet
49
- case "00000049": // Switch
50
- case "00000040": // Fan
51
- case "0000008C": // WindowCovering
52
- case "0000008A": // TemperatureSensor
53
- case "000000B7": // Fan 2 aka Dyson
54
- case "00000041": // Garage Door
55
- case "000000D0": // Valve aka sprinkler
56
- // case "0000003E": // AccessoryInformation
57
- case "0000004A": // Thermostat
58
- case "00000080": // Contact Sensor
59
- case "00000085": // Motion Sensor
60
- case "00000111": // Camera
61
- // debug('Supported Service', service);
62
- events = events.concat(_characteristics(context, service, perms));
63
- // debug("Events", events);
64
- break;
65
- case "0000003E": // AccessoryInformation
66
- _name(context, service);
67
- // debug("Events", events);
68
- break;
69
- default:
70
- }
71
- });
72
- return (events);
73
- }
74
-
75
- function _characteristics(context, service, perms) {
76
- // debug("Char", service, Array.isArray(service));
77
-
78
- var events = [];
79
- service.characteristics.forEach(function(characteristic) {
80
- switch (characteristic.type.substring(0, 8)) {
81
- case "00000020": // manufacturer
82
- context.manufacturer = characteristic.value;
83
- break;
84
- case "00000023": // name
85
- context.name = characteristic.value;
86
- break;
87
- }
88
-
89
- if (characteristic.perms.includes(perms)) {
90
- context.iid = characteristic.iid;
91
- context.function = characteristic.description;
92
- context.service = service.type.substring(0, 8);
93
- context.characteristic = characteristic.type.substring(0, 8);
94
- context.deviceType = _normalizeName(context.service);
95
- // debug("Register", context);
96
- context.fullName = context.name + ' - ' + _normalizeName(context.service) + ' - ' + context.function;
97
- context.sortName = context.name + ':' + _normalizeName(context.service) + ':' + context.function;
98
- context.uniqueId = context.homebridge + context.id + context.manufacturer + context.name + context.service + context.characteristic;
99
- // debug("Perms ", context.fullName, characteristic.perms);
100
- events.push(JSON.parse(JSON.stringify(context)));
101
- }
102
- });
103
- // debug("Char Events", events);
104
- return (events);
105
- }
106
-
107
- function _name(context, service) {
108
- // debug("Char", service, Array.isArray(service));
109
-
110
- var manufacturer, name;
111
- service.characteristics.forEach(function(characteristic) {
112
- switch (characteristic.type.substring(0, 8)) {
113
- case "00000020": // manufacturer
114
- context.manufacturer = characteristic.value;
115
- break;
116
- case "00000023": // name
117
- context.name = characteristic.value;
118
- break;
119
- }
120
- });
121
- // debug("Char Events", events);
122
- // return ({ "manufacturer": manufacturer, "name": name});
123
- }
124
-
125
- function _normalizeName(id) {
126
- switch (id) {
127
- case "00000043": // Lightbulb
128
- return ("Lightbulb");
129
- case "00000047": // Outlet
130
- return ("Outlet");
131
- case "00000049": // Switch
132
- return ("Switch");
133
- case "000000B7": // Fan 2 aka Dyson
134
- case "00000040": // Fan
135
- return ("Fan");
136
- case "0000008C": // WindowCovering
137
- return ("Blinds");
138
- case "0000008A": // TemperatureSensor
139
- return ("Temperature");
140
- case "00000041": // Garage Door
141
- return ("Garage Door");
142
- case "000000D0": // Valve aka sprinkler
143
- return ("Sprinkler");
144
- // case "0000003E": // AccessoryInformation
145
- case "0000004A": // Thermostat
146
- return ("Thermostat");
147
- case "00000080": // Contact Sensor
148
- return ("Contact");
149
- case "00000085": // Motion Sensor
150
- return ("Motion");
151
- case "00000111": // Camera
152
- return ("Camera");
153
- default:
154
- debug("Missing HB Type", id);
155
- }
156
- }