nodejs-poolcontroller 7.3.1 → 7.6.1

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 (85) hide show
  1. package/.eslintrc.json +44 -44
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +52 -52
  3. package/CONTRIBUTING.md +74 -74
  4. package/Changelog +215 -195
  5. package/Dockerfile +17 -17
  6. package/Gruntfile.js +40 -40
  7. package/LICENSE +661 -661
  8. package/README.md +191 -186
  9. package/app.ts +2 -0
  10. package/config/Config.ts +27 -2
  11. package/config/VersionCheck.ts +33 -14
  12. package/config copy.json +299 -299
  13. package/controller/Constants.ts +88 -0
  14. package/controller/Equipment.ts +2459 -2225
  15. package/controller/Errors.ts +180 -157
  16. package/controller/Lockouts.ts +437 -0
  17. package/controller/State.ts +364 -79
  18. package/controller/boards/BoardFactory.ts +45 -45
  19. package/controller/boards/EasyTouchBoard.ts +2653 -2489
  20. package/controller/boards/IntelliCenterBoard.ts +4230 -3973
  21. package/controller/boards/IntelliComBoard.ts +63 -63
  22. package/controller/boards/IntelliTouchBoard.ts +241 -167
  23. package/controller/boards/NixieBoard.ts +1675 -1105
  24. package/controller/boards/SystemBoard.ts +4697 -3201
  25. package/controller/comms/Comms.ts +222 -10
  26. package/controller/comms/messages/Messages.ts +13 -9
  27. package/controller/comms/messages/config/ChlorinatorMessage.ts +13 -4
  28. package/controller/comms/messages/config/CircuitGroupMessage.ts +6 -0
  29. package/controller/comms/messages/config/CircuitMessage.ts +0 -0
  30. package/controller/comms/messages/config/ConfigMessage.ts +0 -0
  31. package/controller/comms/messages/config/CoverMessage.ts +1 -0
  32. package/controller/comms/messages/config/CustomNameMessage.ts +30 -30
  33. package/controller/comms/messages/config/EquipmentMessage.ts +4 -0
  34. package/controller/comms/messages/config/ExternalMessage.ts +53 -33
  35. package/controller/comms/messages/config/FeatureMessage.ts +8 -1
  36. package/controller/comms/messages/config/GeneralMessage.ts +8 -0
  37. package/controller/comms/messages/config/HeaterMessage.ts +14 -28
  38. package/controller/comms/messages/config/IntellichemMessage.ts +4 -1
  39. package/controller/comms/messages/config/OptionsMessage.ts +38 -2
  40. package/controller/comms/messages/config/PumpMessage.ts +4 -20
  41. package/controller/comms/messages/config/RemoteMessage.ts +4 -0
  42. package/controller/comms/messages/config/ScheduleMessage.ts +347 -331
  43. package/controller/comms/messages/config/SecurityMessage.ts +1 -0
  44. package/controller/comms/messages/config/ValveMessage.ts +13 -3
  45. package/controller/comms/messages/status/ChlorinatorStateMessage.ts +2 -3
  46. package/controller/comms/messages/status/EquipmentStateMessage.ts +79 -25
  47. package/controller/comms/messages/status/HeaterStateMessage.ts +86 -53
  48. package/controller/comms/messages/status/IntelliChemStateMessage.ts +445 -386
  49. package/controller/comms/messages/status/IntelliValveStateMessage.ts +35 -35
  50. package/controller/comms/messages/status/PumpStateMessage.ts +0 -0
  51. package/controller/comms/messages/status/VersionMessage.ts +0 -0
  52. package/controller/nixie/Nixie.ts +162 -160
  53. package/controller/nixie/NixieEquipment.ts +103 -103
  54. package/controller/nixie/bodies/Body.ts +120 -117
  55. package/controller/nixie/bodies/Filter.ts +135 -135
  56. package/controller/nixie/chemistry/ChemController.ts +2498 -2395
  57. package/controller/nixie/chemistry/Chlorinator.ts +314 -313
  58. package/controller/nixie/circuits/Circuit.ts +248 -210
  59. package/controller/nixie/heaters/Heater.ts +649 -441
  60. package/controller/nixie/pumps/Pump.ts +661 -599
  61. package/controller/nixie/schedules/Schedule.ts +257 -256
  62. package/controller/nixie/valves/Valve.ts +170 -170
  63. package/defaultConfig.json +286 -271
  64. package/issue_template.md +51 -51
  65. package/logger/DataLogger.ts +448 -433
  66. package/logger/Logger.ts +0 -0
  67. package/package.json +56 -54
  68. package/tsconfig.json +25 -25
  69. package/web/Server.ts +522 -31
  70. package/web/bindings/influxDB.json +1022 -894
  71. package/web/bindings/mqtt.json +654 -543
  72. package/web/bindings/mqttAlt.json +684 -574
  73. package/web/bindings/rulesManager.json +54 -54
  74. package/web/bindings/smartThings-Hubitat.json +31 -31
  75. package/web/bindings/valveRelays.json +20 -20
  76. package/web/bindings/vera.json +25 -25
  77. package/web/interfaces/baseInterface.ts +136 -136
  78. package/web/interfaces/httpInterface.ts +124 -122
  79. package/web/interfaces/influxInterface.ts +245 -240
  80. package/web/interfaces/mqttInterface.ts +475 -464
  81. package/web/services/config/Config.ts +181 -152
  82. package/web/services/config/ConfigSocket.ts +0 -0
  83. package/web/services/state/State.ts +118 -7
  84. package/web/services/state/StateSocket.ts +18 -1
  85. package/web/services/utilities/Utilities.ts +42 -42
@@ -1,122 +1,124 @@
1
- /* nodejs-poolController. An application to control pool equipment.
2
- Copyright (C) 2016, 2017, 2018, 2019, 2020. Russell Goldin, tagyoureit. russ.goldin@gmail.com
3
-
4
- This program is free software: you can redistribute it and/or modify
5
- it under the terms of the GNU Affero General Public License as
6
- published by the Free Software Foundation, either version 3 of the
7
- License, or (at your option) any later version.
8
-
9
- This program is distributed in the hope that it will be useful,
10
- but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- GNU Affero General Public License for more details.
13
-
14
- You should have received a copy of the GNU Affero General Public License
15
- along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- */
17
- import { HttpInterfaceServer } from "../../web/Server";
18
- import * as http2 from "http2";
19
- import * as http from "http";
20
- import * as https from "https";
21
- import extend=require("extend");
22
- import { logger } from "../../logger/Logger";
23
- import { sys } from "../../controller/Equipment";
24
- import { state } from "../../controller/State";
25
- import { InterfaceContext, InterfaceEvent, BaseInterfaceBindings } from "./baseInterface";
26
-
27
- export class HttpInterfaceBindings extends BaseInterfaceBindings {
28
- constructor(cfg) {
29
- super(cfg);
30
- }
31
- public bindEvent(evt: string, ...data: any) {
32
- // Find the binding by first looking for the specific event name.
33
- // If that doesn't exist then look for the "*" (all events).
34
- if (typeof this.events !== 'undefined') {
35
- let evts = this.events.filter(elem => elem.name === evt);
36
- // If we don't have an explicitly defined event then see if there is a default.
37
- if (evts.length === 0) {
38
- let e = this.events.find(elem => elem.name === '*');
39
- evts = e ? [e] : [];
40
- }
41
-
42
- let baseOpts = extend(true, { headers: {} }, this.cfg.options, this.context.options);
43
- if ((typeof baseOpts.hostname === 'undefined' || !baseOpts.hostname) && (typeof baseOpts.host === 'undefined' || !baseOpts.host || baseOpts.host === '*')) {
44
- logger.warn(`Interface: ${ this.cfg.name } has not resolved to a valid host.`);
45
- return;
46
- }
47
- if (evts.length > 0) {
48
- let toks = {};
49
- for (let i = 0; i < evts.length; i++) {
50
- let e = evts[i];
51
- if (typeof e.enabled !== 'undefined' && !e.enabled) continue;
52
- let opts = extend(true, baseOpts, e.options);
53
- // Figure out whether we need to check the filter.
54
- if (typeof e.filter !== 'undefined') {
55
- this.buildTokens(e.filter, evt, toks, e, data[0]);
56
- if (eval(this.replaceTokens(e.filter, toks)) === false) continue;
57
- }
58
-
59
- // If we are still waiting on mdns then blow this off.
60
- if ((typeof opts.hostname === 'undefined' || !opts.hostname) && (typeof opts.host === 'undefined' || !opts.host || opts.host === '*')) {
61
- logger.warn(`Interface: ${ this.cfg.name } Event: ${ e.name } has not resolved to a valid host.`);
62
- continue;
63
- }
64
-
65
- // Put together the data object.
66
- let sbody = '';
67
- switch (this.cfg.contentType) {
68
- //case 'application/json':
69
- //case 'json':
70
- default:
71
- sbody = typeof e.body !== 'undefined' ? JSON.stringify(e.body) : '';
72
- break;
73
- // We may need an XML output and can add transforms for that
74
- // later. There isn't a native xslt processor in node and most
75
- // of them that I looked at seemed pretty amatuer hour or overbearing
76
- // as they used SAX. => Need down and clean not down and dirty... we aren't building
77
- // a web client at this point.
78
- }
79
- this.buildTokens(sbody, evt, toks, e, data[0]);
80
- sbody = this.replaceTokens(sbody, toks);
81
- for (let prop in opts) {
82
- if (prop === 'headers') {
83
- for (let header in opts.headers) {
84
- this.buildTokens(opts.headers[header], evt, toks, e, data[0]);
85
- opts.headers[header] = this.replaceTokens(opts.headers[header], toks);
86
- }
87
- }
88
- else if (typeof opts[prop] === 'string') {
89
- this.buildTokens(opts[prop], evt, toks, e, data[0]);
90
- opts[prop] = this.replaceTokens(opts[prop] || '', toks);
91
- }
92
- }
93
- if (typeof opts.path !== 'undefined') opts.path = encodeURI(opts.path); // Encode the data just in case we have spaces.
94
- // opts.headers["CONTENT-LENGTH"] = Buffer.byteLength(sbody || '');
95
- logger.debug(`Sending [${evt}] request to ${this.cfg.name}: ${JSON.stringify(opts)}`);
96
- let req: http.ClientRequest;
97
- // We should now have all the tokens. Put together the request.
98
- if (typeof sbody !== 'undefined') {
99
- if (sbody.charAt(0) === '"' && sbody.charAt(sbody.length - 1) === '"') sbody = sbody.substr(1, sbody.length - 2);
100
- opts.headers["CONTENT-LENGTH"] = Buffer.byteLength(sbody || '');
101
- }
102
- if (opts.port === 443 || (opts.protocol || '').startsWith('https')) {
103
- req = https.request(opts, (response: http.IncomingMessage) => {
104
- //console.log(response);
105
- });
106
- }
107
- else {
108
- req = http.request(opts, (response: http.IncomingMessage) => {
109
- //console.log(response.statusCode);
110
- });
111
- }
112
- req.on('error', (err, req, res) => { logger.error(err); });
113
- if (typeof sbody !== 'undefined') {
114
- req.write(sbody);
115
- }
116
- req.end();
117
- }
118
- }
119
- }
120
- }
121
- }
122
-
1
+ /* nodejs-poolController. An application to control pool equipment.
2
+ Copyright (C) 2016, 2017, 2018, 2019, 2020. Russell Goldin, tagyoureit. russ.goldin@gmail.com
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ import { HttpInterfaceServer } from "../../web/Server";
18
+ import * as http2 from "http2";
19
+ import * as http from "http";
20
+ import * as https from "https";
21
+ import extend=require("extend");
22
+ import { logger } from "../../logger/Logger";
23
+ import { sys } from "../../controller/Equipment";
24
+ import { state } from "../../controller/State";
25
+ import { InterfaceContext, InterfaceEvent, BaseInterfaceBindings } from "./baseInterface";
26
+
27
+ export class HttpInterfaceBindings extends BaseInterfaceBindings {
28
+ constructor(cfg) {
29
+ super(cfg);
30
+ }
31
+ public bindEvent(evt: string, ...data: any) {
32
+ // Find the binding by first looking for the specific event name.
33
+ // If that doesn't exist then look for the "*" (all events).
34
+ if (typeof this.events !== 'undefined') {
35
+ let evts = this.events.filter(elem => elem.name === evt);
36
+ // If we don't have an explicitly defined event then see if there is a default.
37
+ if (evts.length === 0) {
38
+ let e = this.events.find(elem => elem.name === '*');
39
+ evts = e ? [e] : [];
40
+ }
41
+
42
+ let baseOpts = extend(true, { headers: {} }, this.cfg.options, this.context.options);
43
+ if ((typeof baseOpts.hostname === 'undefined' || !baseOpts.hostname) && (typeof baseOpts.host === 'undefined' || !baseOpts.host || baseOpts.host === '*')) {
44
+ logger.warn(`Interface: ${ this.cfg.name } has not resolved to a valid host.`);
45
+ return;
46
+ }
47
+ if (evts.length > 0) {
48
+ let toks = {};
49
+ for (let i = 0; i < evts.length; i++) {
50
+ let e = evts[i];
51
+ if (typeof e.enabled !== 'undefined' && !e.enabled) continue;
52
+ let opts = extend(true, baseOpts, e.options);
53
+ // Figure out whether we need to check the filter.
54
+ if (typeof e.filter !== 'undefined') {
55
+ this.buildTokens(e.filter, evt, toks, e, data[0]);
56
+ if (eval(this.replaceTokens(e.filter, toks)) === false) continue;
57
+ }
58
+
59
+ // If we are still waiting on mdns then blow this off.
60
+ if ((typeof opts.hostname === 'undefined' || !opts.hostname) && (typeof opts.host === 'undefined' || !opts.host || opts.host === '*')) {
61
+ logger.warn(`Interface: ${ this.cfg.name } Event: ${ e.name } has not resolved to a valid host.`);
62
+ continue;
63
+ }
64
+
65
+ // Put together the data object.
66
+ let sbody = '';
67
+ switch (this.cfg.contentType) {
68
+ //case 'application/json':
69
+ //case 'json':
70
+ default:
71
+ sbody = typeof e.body !== 'undefined' ? JSON.stringify(e.body) : '';
72
+ break;
73
+ // We may need an XML output and can add transforms for that
74
+ // later. There isn't a native xslt processor in node and most
75
+ // of them that I looked at seemed pretty amatuer hour or overbearing
76
+ // as they used SAX. => Need down and clean not down and dirty... we aren't building
77
+ // a web client at this point.
78
+ }
79
+ this.buildTokens(sbody, evt, toks, e, data[0]);
80
+ sbody = this.replaceTokens(sbody, toks);
81
+ for (let prop in opts) {
82
+ if (prop === 'headers') {
83
+ for (let header in opts.headers) {
84
+ this.buildTokens(opts.headers[header], evt, toks, e, data[0]);
85
+ opts.headers[header] = this.replaceTokens(opts.headers[header], toks);
86
+ }
87
+ }
88
+ else if (typeof opts[prop] === 'string') {
89
+ this.buildTokens(opts[prop], evt, toks, e, data[0]);
90
+ opts[prop] = this.replaceTokens(opts[prop] || '', toks);
91
+ }
92
+ }
93
+ if (typeof opts.path !== 'undefined') opts.path = encodeURI(opts.path); // Encode the data just in case we have spaces.
94
+ // opts.headers["CONTENT-LENGTH"] = Buffer.byteLength(sbody || '');
95
+ logger.debug(`Sending [${evt}] request to ${this.cfg.name}: ${JSON.stringify(opts)}`);
96
+ let req: http.ClientRequest;
97
+ // We should now have all the tokens. Put together the request.
98
+ if (typeof sbody !== 'undefined') {
99
+ if (sbody.charAt(0) === '"' && sbody.charAt(sbody.length - 1) === '"') sbody = sbody.substr(1, sbody.length - 2);
100
+ opts.headers["CONTENT-LENGTH"] = Buffer.byteLength(sbody || '');
101
+ }
102
+ if (opts.port === 443 || (opts.protocol || '').startsWith('https')) {
103
+ opts.protocol = 'https:';
104
+ req = https.request(opts, (response: http.IncomingMessage) => {
105
+ //console.log(response);
106
+ });
107
+ }
108
+ else {
109
+ opts.protocol = 'http:';
110
+ req = http.request(opts, (response: http.IncomingMessage) => {
111
+ //console.log(response.statusCode);
112
+ });
113
+ }
114
+ req.on('error', (err, req, res) => { logger.error(err); });
115
+ if (typeof sbody !== 'undefined') {
116
+ req.write(sbody);
117
+ }
118
+ req.end();
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+