nodejs-poolcontroller 7.6.1 → 7.7.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 (91) hide show
  1. package/.eslintrc.json +44 -44
  2. package/.github/ISSUE_TEMPLATE/1-bug-report.yml +84 -0
  3. package/.github/ISSUE_TEMPLATE/2-docs.md +12 -0
  4. package/.github/ISSUE_TEMPLATE/3-proposal.md +28 -0
  5. package/.github/ISSUE_TEMPLATE/config.yml +8 -0
  6. package/CONTRIBUTING.md +74 -74
  7. package/Changelog +220 -215
  8. package/Dockerfile +17 -17
  9. package/Gruntfile.js +40 -40
  10. package/LICENSE +661 -661
  11. package/README.md +191 -191
  12. package/app.ts +1 -1
  13. package/config/Config.ts +14 -0
  14. package/config/VersionCheck.ts +2 -2
  15. package/controller/Constants.ts +2 -1
  16. package/controller/Equipment.ts +2484 -2459
  17. package/controller/Errors.ts +180 -180
  18. package/controller/Lockouts.ts +502 -436
  19. package/controller/State.ts +106 -30
  20. package/controller/boards/AquaLinkBoard.ts +1000 -0
  21. package/controller/boards/BoardFactory.ts +49 -45
  22. package/controller/boards/EasyTouchBoard.ts +2859 -2653
  23. package/controller/boards/IntelliCenterBoard.ts +4198 -4230
  24. package/controller/boards/IntelliComBoard.ts +63 -63
  25. package/controller/boards/IntelliTouchBoard.ts +273 -241
  26. package/controller/boards/NixieBoard.ts +1728 -1675
  27. package/controller/boards/SystemBoard.ts +4925 -4697
  28. package/controller/comms/Comms.ts +442 -479
  29. package/controller/comms/messages/Messages.ts +171 -25
  30. package/controller/comms/messages/config/ChlorinatorMessage.ts +5 -2
  31. package/controller/comms/messages/config/CircuitGroupMessage.ts +0 -0
  32. package/controller/comms/messages/config/CircuitMessage.ts +1 -0
  33. package/controller/comms/messages/config/ConfigMessage.ts +0 -0
  34. package/controller/comms/messages/config/CoverMessage.ts +0 -0
  35. package/controller/comms/messages/config/CustomNameMessage.ts +30 -30
  36. package/controller/comms/messages/config/EquipmentMessage.ts +0 -0
  37. package/controller/comms/messages/config/ExternalMessage.ts +0 -0
  38. package/controller/comms/messages/config/FeatureMessage.ts +0 -0
  39. package/controller/comms/messages/config/GeneralMessage.ts +0 -0
  40. package/controller/comms/messages/config/HeaterMessage.ts +142 -10
  41. package/controller/comms/messages/config/IntellichemMessage.ts +0 -0
  42. package/controller/comms/messages/config/OptionsMessage.ts +4 -21
  43. package/controller/comms/messages/config/PumpMessage.ts +53 -35
  44. package/controller/comms/messages/config/RemoteMessage.ts +0 -0
  45. package/controller/comms/messages/config/ScheduleMessage.ts +350 -347
  46. package/controller/comms/messages/config/SecurityMessage.ts +0 -0
  47. package/controller/comms/messages/config/ValveMessage.ts +1 -1
  48. package/controller/comms/messages/status/ChlorinatorStateMessage.ts +38 -86
  49. package/controller/comms/messages/status/EquipmentStateMessage.ts +58 -22
  50. package/controller/comms/messages/status/HeaterStateMessage.ts +116 -86
  51. package/controller/comms/messages/status/IntelliChemStateMessage.ts +445 -445
  52. package/controller/comms/messages/status/IntelliValveStateMessage.ts +35 -35
  53. package/controller/comms/messages/status/PumpStateMessage.ts +23 -1
  54. package/controller/comms/messages/status/VersionMessage.ts +0 -0
  55. package/controller/nixie/Nixie.ts +162 -162
  56. package/controller/nixie/NixieEquipment.ts +103 -103
  57. package/controller/nixie/bodies/Body.ts +120 -120
  58. package/controller/nixie/bodies/Filter.ts +135 -135
  59. package/controller/nixie/chemistry/ChemController.ts +2511 -2498
  60. package/controller/nixie/chemistry/Chlorinator.ts +363 -314
  61. package/controller/nixie/circuits/Circuit.ts +261 -248
  62. package/controller/nixie/heaters/Heater.ts +650 -648
  63. package/controller/nixie/pumps/Pump.ts +906 -661
  64. package/controller/nixie/schedules/Schedule.ts +313 -257
  65. package/controller/nixie/valves/Valve.ts +170 -170
  66. package/defaultConfig.json +306 -286
  67. package/logger/DataLogger.ts +448 -448
  68. package/logger/Logger.ts +0 -0
  69. package/package.json +56 -56
  70. package/tsconfig.json +25 -25
  71. package/web/Server.ts +92 -47
  72. package/web/bindings/aqualinkD.json +505 -0
  73. package/web/bindings/influxDB.json +1051 -1021
  74. package/web/bindings/mqtt.json +702 -654
  75. package/web/bindings/mqttAlt.json +731 -684
  76. package/web/bindings/rulesManager.json +54 -54
  77. package/web/bindings/smartThings-Hubitat.json +31 -31
  78. package/web/bindings/valveRelays.json +20 -20
  79. package/web/bindings/vera.json +25 -25
  80. package/web/interfaces/baseInterface.ts +137 -136
  81. package/web/interfaces/httpInterface.ts +145 -124
  82. package/web/interfaces/influxInterface.ts +276 -245
  83. package/web/interfaces/mqttInterface.ts +535 -475
  84. package/web/services/config/Config.ts +39 -18
  85. package/web/services/config/ConfigSocket.ts +0 -0
  86. package/web/services/state/State.ts +10 -0
  87. package/web/services/state/StateSocket.ts +4 -4
  88. package/web/services/utilities/Utilities.ts +44 -42
  89. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -52
  90. package/config copy.json +0 -300
  91. package/issue_template.md +0 -52
@@ -1,124 +1,145 @@
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
-
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 { PoolSystem, sys } from "../../controller/Equipment";
24
+ import { State, 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
+ declare sockets: HttpInterfaceSocketEvent[];
32
+ public bindEvent(evt: string, ...data: any) {
33
+ // Find the binding by first looking for the specific event name.
34
+ // If that doesn't exist then look for the "*" (all events).
35
+ if (typeof this.events !== 'undefined') {
36
+ let evts = this.events.filter(elem => elem.name === evt);
37
+ // If we don't have an explicitly defined event then see if there is a default.
38
+ if (evts.length === 0) {
39
+ let e = this.events.find(elem => elem.name === '*');
40
+ evts = e ? [e] : [];
41
+ }
42
+
43
+ let baseOpts = extend(true, { headers: {} }, this.cfg.options, this.context.options);
44
+ if ((typeof baseOpts.hostname === 'undefined' || !baseOpts.hostname) && (typeof baseOpts.host === 'undefined' || !baseOpts.host || baseOpts.host === '*')) {
45
+ logger.warn(`Interface: ${ this.cfg.name } has not resolved to a valid host.`);
46
+ return;
47
+ }
48
+ if (evts.length > 0) {
49
+ let toks = {};
50
+ for (let i = 0; i < evts.length; i++) {
51
+ let e = evts[i];
52
+ if (typeof e.enabled !== 'undefined' && !e.enabled) continue;
53
+ let opts = extend(true, baseOpts, e.options);
54
+ // Figure out whether we need to check the filter.
55
+ if (typeof e.filter !== 'undefined') {
56
+ this.buildTokens(e.filter, evt, toks, e, data[0]);
57
+ if (eval(this.replaceTokens(e.filter, toks)) === false) continue;
58
+ }
59
+
60
+ // If we are still waiting on mdns then blow this off.
61
+ if ((typeof opts.hostname === 'undefined' || !opts.hostname) && (typeof opts.host === 'undefined' || !opts.host || opts.host === '*')) {
62
+ logger.warn(`Interface: ${ this.cfg.name } Event: ${ e.name } has not resolved to a valid host.`);
63
+ continue;
64
+ }
65
+
66
+ // Put together the data object.
67
+ let sbody = '';
68
+ switch (this.cfg.contentType) {
69
+ //case 'application/json':
70
+ //case 'json':
71
+ default:
72
+ sbody = typeof e.body !== 'undefined' ? JSON.stringify(e.body) : '';
73
+ break;
74
+ // We may need an XML output and can add transforms for that
75
+ // later. There isn't a native xslt processor in node and most
76
+ // of them that I looked at seemed pretty amatuer hour or overbearing
77
+ // as they used SAX. => Need down and clean not down and dirty... we aren't building
78
+ // a web client at this point.
79
+ }
80
+ this.buildTokens(sbody, evt, toks, e, data[0]);
81
+ sbody = this.replaceTokens(sbody, toks);
82
+ for (let prop in opts) {
83
+ if (prop === 'headers') {
84
+ for (let header in opts.headers) {
85
+ this.buildTokens(opts.headers[header], evt, toks, e, data[0]);
86
+ opts.headers[header] = this.replaceTokens(opts.headers[header], toks);
87
+ }
88
+ }
89
+ else if (typeof opts[prop] === 'string') {
90
+ this.buildTokens(opts[prop], evt, toks, e, data[0]);
91
+ opts[prop] = this.replaceTokens(opts[prop] || '', toks);
92
+ }
93
+ }
94
+ if (typeof opts.path !== 'undefined') opts.path = encodeURI(opts.path); // Encode the data just in case we have spaces.
95
+ // opts.headers["CONTENT-LENGTH"] = Buffer.byteLength(sbody || '');
96
+ logger.debug(`Sending [${evt}] request to ${this.cfg.name}: ${JSON.stringify(opts)}`);
97
+ let req: http.ClientRequest;
98
+ // We should now have all the tokens. Put together the request.
99
+ if (typeof sbody !== 'undefined') {
100
+ if (sbody.charAt(0) === '"' && sbody.charAt(sbody.length - 1) === '"') sbody = sbody.substr(1, sbody.length - 2);
101
+ opts.headers["CONTENT-LENGTH"] = Buffer.byteLength(sbody || '');
102
+ }
103
+ if (opts.port === 443 || (opts.protocol || '').startsWith('https')) {
104
+ opts.protocol = 'https:';
105
+ req = https.request(opts, (response: http.IncomingMessage) => {
106
+ //console.log(response);
107
+ });
108
+ }
109
+ else {
110
+ opts.protocol = 'http:';
111
+ req = http.request(opts, (response: http.IncomingMessage) => {
112
+ //console.log(response.statusCode);
113
+ });
114
+ }
115
+ req.on('error', (err, req, res) => { logger.error(err); });
116
+ if (typeof sbody !== 'undefined') {
117
+ req.write(sbody);
118
+ }
119
+ req.end();
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+ class HttpInterfaceSocketEvent {
126
+ event: string;
127
+ description: string;
128
+ processor: (sock: HttpInterfaceSocketEvent, sys: PoolSystem, state: State, value: any) => void;
129
+ constructor(sock: any) {
130
+ this.event = sock.event;
131
+ if (typeof sock.processor !== 'undefined') {
132
+ let fnBody = Array.isArray(sock.processor) ? sock.processor.join('\n') : sock.processor;
133
+ try {
134
+ this.processor = new Function('sock', 'sys', 'state', 'value', fnBody) as (sock: HttpInterfaceSocketEvent, sys: PoolSystem, state: State, value: any) => void;
135
+ } catch (err) { logger.error(`Error compiling socket event processor: ${err} -- ${fnBody}`); }
136
+ }
137
+ }
138
+ }
139
+ export interface IHTTPInterfaceSocketEvent {
140
+ event: string,
141
+ description: string,
142
+ processor?: string
143
+ }
144
+
145
+