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,240 +1,245 @@
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
-
18
- import extend = require("extend");
19
- import { ClientOptions, InfluxDB, Point, WriteApi, WritePrecisionType } from '@influxdata/influxdb-client';
20
- import { utils, Timestamp } from '../../controller/Constants';
21
- import { logger } from "../../logger/Logger";
22
- import { BaseInterfaceBindings, InterfaceContext, InterfaceEvent } from "./baseInterface";
23
- export class InfluxInterfaceBindings extends BaseInterfaceBindings {
24
- constructor(cfg) {
25
- super(cfg);
26
- }
27
- private writeApi: WriteApi;
28
- public context: InterfaceContext;
29
- public cfg;
30
- public events: InfluxInterfaceEvent[];
31
- private init = () => {
32
- let baseOpts = extend(true, this.cfg.options, this.context.options);
33
- let url = 'http';
34
- if (typeof baseOpts.protocol !== 'undefined' && baseOpts.protocol) url = baseOpts.protocol;
35
- url = `${url}://${baseOpts.host}:${baseOpts.port}`;
36
- let influxDB: InfluxDB;
37
- let bucket;
38
- let org;
39
- if (typeof baseOpts.host === 'undefined' || !baseOpts.host) {
40
- logger.warn(`Interface: ${this.cfg.name} has not resolved to a valid host.`);
41
- return;
42
- }
43
- if (baseOpts.version === 1) {
44
- if (typeof baseOpts.database === 'undefined' || !baseOpts.database) {
45
- logger.warn(`Interface: ${this.cfg.name} has not resolved to a valid database.`);
46
- return;
47
- }
48
- bucket = `${baseOpts.database}/${baseOpts.retentionPolicy}`;
49
- const clientOptions: ClientOptions = {
50
- url,
51
- token: `${baseOpts.username}:${baseOpts.password}`,
52
- }
53
- influxDB = new InfluxDB(clientOptions);
54
- }
55
- else if (baseOpts.version === 2) {
56
- org = baseOpts.org;
57
- bucket = baseOpts.bucket;
58
- const clientOptions: ClientOptions = {
59
- url,
60
- token: baseOpts.token,
61
- }
62
- influxDB = new InfluxDB(clientOptions);
63
- }
64
- this.writeApi = influxDB.getWriteApi(org, bucket, 'ms');
65
-
66
-
67
- // set global tags from context
68
- let baseTags = {}
69
- baseOpts.tags.forEach(tag => {
70
- let toks = {};
71
- let sname = this.tokensReplacer(tag.name, undefined, toks, undefined, {})
72
- let svalue = this.tokensReplacer(tag.value, undefined, toks, { vars: {} } as any, {});
73
- if (typeof sname !== 'undefined' && typeof svalue !== 'undefined' && !sname.includes('@bind') && !svalue.includes('@bind'))
74
- baseTags[sname] = svalue;
75
- })
76
- this.writeApi.useDefaultTags(baseTags);
77
- }
78
- public bindEvent(evt: string, ...data: any) {
79
-
80
- // if (state.status.value !== sys.board.valueMaps.controllerStatus.getValue('ready')) return; // miss values? or show errors? or?
81
- if (typeof this.events !== 'undefined') {
82
- if (typeof this.writeApi === 'undefined') this.init();
83
- let evts = this.events.filter(elem => elem.name === evt);
84
- if (evts.length > 0) {
85
- let toks = {};
86
- for (let i = 0; i < evts.length; i++) {
87
- let e = evts[i];
88
- if (typeof e.enabled !== 'undefined' && !e.enabled) continue;
89
- // Figure out whether we need to check the filter.
90
- if (typeof e.filter !== 'undefined') {
91
- this.buildTokens(e.filter, evt, toks, e, data[0]);
92
- if (eval(this.replaceTokens(e.filter, toks)) === false) continue;
93
- }
94
- for (let j = 0; j < e.points.length; j++) {
95
- let _point = e.points[j];
96
- // Figure out whether we need to check the filter for each point.
97
- if (typeof _point.filter !== 'undefined') {
98
- this.buildTokens(_point.filter, evt, toks, e, data[0]);
99
- if (eval(this.replaceTokens(_point.filter, toks)) === false) continue;
100
- }
101
- // iterate through points array
102
- let point = new Point(_point.measurement)
103
- let point2 = new Point(_point.measurement);
104
- _point.tags.forEach(_tag => {
105
- let sname = _tag.name;
106
- this.buildTokens(sname, evt, toks, e, data[0]);
107
- sname = this.replaceTokens(sname, toks);
108
- let svalue = _tag.value;
109
- this.buildTokens(svalue, evt, toks, e, data[0]);
110
- svalue = this.replaceTokens(svalue, toks);
111
- if (typeof sname !== 'undefined' && typeof svalue !== 'undefined' && !sname.includes('@bind') && !svalue.includes('@bind') && svalue !== null) {
112
- point.tag(sname, svalue);
113
- if (typeof _point.storePrevState !== 'undefined' && _point.storePrevState) point2.tag(sname, svalue);
114
- }
115
- else {
116
- logger.error(`InfluxDB tag binding failure on ${evt}:${_tag.name}/${_tag.value} --> ${svalue || 'undefined'} ${JSON.stringify(data[0])}`);
117
- }
118
- })
119
- _point.fields.forEach(_field => {
120
- try {
121
- let sname = _field.name;
122
- this.buildTokens(sname, evt, toks, e, data[0]);
123
- //console.log(toks);
124
- sname = this.replaceTokens(sname, toks);
125
- let svalue = _field.value;
126
- this.buildTokens(svalue, evt, toks, e, data[0]);
127
- svalue = this.replaceTokens(svalue, toks);
128
- if (typeof sname !== 'undefined' && typeof svalue !== 'undefined' && !sname.includes('@bind') && !svalue.includes('@bind') && svalue !== null)
129
- switch (_field.type) {
130
- case 'int':
131
- case 'integer':
132
- let int = parseInt(svalue, 10);
133
- if (!isNaN(int)) point.intField(sname, int);
134
- // if (!isNaN(int) && typeof _point.storePrevState !== 'undefined' && _point.storePrevState) point2.intField(sname, int);
135
- break;
136
- case 'string':
137
- point.stringField(sname, svalue);
138
- // if (typeof _point.storePrevState !== 'undefined' && _point.storePrevState) point2.stringField(sname, svalue);
139
- break;
140
- case 'boolean':
141
- point.booleanField(sname, utils.makeBool(svalue));
142
- if (typeof _point.storePrevState !== 'undefined' && _point.storePrevState) point2.booleanField(sname, !utils.makeBool(svalue));
143
- break;
144
- case 'float':
145
- let float = parseFloat(svalue);
146
- if (!isNaN(float)) point.floatField(sname, float);
147
- // if (!isNaN(float) && typeof _point.storePrevState !== 'undefined' && _point.storePrevState) point2.intField(sname, int);
148
- break;
149
- case 'timestamp':
150
- case 'datetime':
151
- case 'date':
152
- //let dt = Date.parse(svalue.replace(/^["'](.+(?=["']$))["']$/, '$1'));
153
- // RKS: 07-06-21 - I think this is missing the eval function around all of this. The strings still have the quotes around them. I think
154
- // maybe we need to create a closure and execute it as a code segment for variable data.
155
- let sdt = eval(svalue);
156
- if (sdt !== null && typeof sdt !== 'undefined') {
157
- let dt = Date.parse(sdt);
158
- if (!isNaN(dt)) point.intField(sname, dt);
159
- else if (svalue !== '') logger.warn(`Influx error parsing date from ${sname}: ${svalue}`);
160
- }
161
- break;
162
- }
163
- else {
164
- logger.error(`InfluxDB point binding failure on ${evt}:${_field.name}/${_field.value} --> ${svalue || 'undefined'}`);
165
- }
166
- } catch (err) { logger.error(`Error binding InfluxDB point fields ${err.message}`); }
167
- });
168
- if (typeof _point.series !== 'undefined') {
169
- try {
170
- this.buildTokens(_point.series.value, evt, toks, e, data[0]);
171
- let ser = eval(this.replaceTokens(_point.series.value, toks));
172
- let ts = Date.parse(ser);
173
- if (isNaN(ts)) {
174
- logger.error(`Influx series timestamp is invalid ${ser}`);
175
- }
176
- else
177
- point.timestamp(new Date(ts));
178
- } catch (err) { logger.error(`Error parsing Influx point series for ${evt} - ${_point.series.value}`); }
179
- }
180
- else
181
- point.timestamp(new Date());
182
- try {
183
-
184
- if (typeof _point.storePrevState !== 'undefined' && _point.storePrevState) {
185
- // copy the point and subtract a second and keep inverse value
186
- let ts = new Date();
187
- let sec = ts.getSeconds() - 1;
188
- ts.setSeconds(sec);
189
- point2.timestamp(ts);
190
- logger.silly(`Writing influx ${e.name} inverse data point ${point2.toString()})`)
191
- this.writeApi.writePoint(point2);
192
- }
193
- if (typeof point.toLineProtocol() !== 'undefined') {
194
- logger.silly(`Writing influx ${e.name} data point ${point.toString()}`)
195
- this.writeApi.writePoint(point);
196
- this.writeApi.flush()
197
- .catch(error => { logger.error(error); });
198
- //logger.info(`INFLUX: ${point.toLineProtocol()}`)
199
- }
200
- else {
201
- logger.silly(`Skipping INFLUX write because some data is missing with ${e.name} event on measurement ${_point.measurement}.`)
202
- }
203
- }
204
- catch (err) {
205
- logger.error(`Error writing to Influx: ${err.message}`)
206
- }
207
- }
208
- }
209
- }
210
- }
211
- }
212
- public close = () => {
213
-
214
- }
215
- }
216
-
217
- class InfluxInterfaceEvent extends InterfaceEvent {
218
- public points: IPoint[];
219
- }
220
-
221
- export interface IPoint {
222
- measurement: string;
223
- series?: ISeries;
224
- tags: ITag[];
225
- fields: IFields[];
226
- storePrevState?: boolean;
227
- filter?: any;
228
- }
229
- export interface ITag {
230
- name: string;
231
- value: string;
232
- }
233
- export interface IFields {
234
- name: string;
235
- value: string;
236
- type: string;
237
- }
238
- export interface ISeries {
239
- value: string;
240
- }
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
+
18
+ import extend = require("extend");
19
+ import { ClientOptions, InfluxDB, Point, WriteApi, WritePrecisionType } from '@influxdata/influxdb-client';
20
+ import { utils, Timestamp } from '../../controller/Constants';
21
+ import { logger } from "../../logger/Logger";
22
+ import { BaseInterfaceBindings, InterfaceContext, InterfaceEvent } from "./baseInterface";
23
+ export class InfluxInterfaceBindings extends BaseInterfaceBindings {
24
+ constructor(cfg) {
25
+ super(cfg);
26
+ }
27
+ private writeApi: WriteApi;
28
+ declare context: InterfaceContext;
29
+ declare cfg;
30
+ declare events: InfluxInterfaceEvent[];
31
+ private init = () => {
32
+ let baseOpts = extend(true, this.cfg.options, this.context.options);
33
+ let url = 'http://';
34
+ if (typeof baseOpts.protocol !== 'undefined' && baseOpts.protocol) url = baseOpts.protocol;
35
+ if (!url.endsWith('://')) url += '://';
36
+ url = `${url}${baseOpts.host}:${baseOpts.port}`;
37
+ let influxDB: InfluxDB;
38
+ let bucket;
39
+ let org;
40
+ if (typeof baseOpts.host === 'undefined' || !baseOpts.host) {
41
+ logger.warn(`Interface: ${this.cfg.name} has not resolved to a valid host.`);
42
+ return;
43
+ }
44
+ if (baseOpts.version === 1) {
45
+ if (typeof baseOpts.database === 'undefined' || !baseOpts.database) {
46
+ logger.warn(`Interface: ${this.cfg.name} has not resolved to a valid database.`);
47
+ return;
48
+ }
49
+ bucket = `${baseOpts.database}/${baseOpts.retentionPolicy}`;
50
+ const clientOptions: ClientOptions = {
51
+ url,
52
+ token: `${baseOpts.username}:${baseOpts.password}`,
53
+ }
54
+ influxDB = new InfluxDB(clientOptions);
55
+ }
56
+ else if (baseOpts.version === 2) {
57
+ org = baseOpts.org;
58
+ bucket = baseOpts.bucket;
59
+ const clientOptions: ClientOptions = {
60
+ url,
61
+ token: baseOpts.token,
62
+ }
63
+ influxDB = new InfluxDB(clientOptions);
64
+ }
65
+ this.writeApi = influxDB.getWriteApi(org, bucket, 'ms');
66
+
67
+
68
+ // set global tags from context
69
+ let baseTags = {}
70
+ baseOpts.tags.forEach(tag => {
71
+ let toks = {};
72
+ let sname = this.tokensReplacer(tag.name, undefined, toks, undefined, {})
73
+ let svalue = this.tokensReplacer(tag.value, undefined, toks, { vars: {} } as any, {});
74
+ if (typeof sname !== 'undefined' && typeof svalue !== 'undefined' && !sname.includes('@bind') && !svalue.includes('@bind'))
75
+ baseTags[sname] = svalue;
76
+ })
77
+ this.writeApi.useDefaultTags(baseTags);
78
+ }
79
+ public bindEvent(evt: string, ...data: any) {
80
+
81
+ // if (state.status.value !== sys.board.valueMaps.controllerStatus.getValue('ready')) return; // miss values? or show errors? or?
82
+ if (typeof this.events !== 'undefined') {
83
+ if (typeof this.writeApi === 'undefined') this.init();
84
+ let evts = this.events.filter(elem => elem.name === evt);
85
+ if (evts.length > 0) {
86
+ let toks = {};
87
+ for (let i = 0; i < evts.length; i++) {
88
+ let e = evts[i];
89
+ if (typeof e.enabled !== 'undefined' && !e.enabled) continue;
90
+ // Figure out whether we need to check the filter.
91
+ if (typeof e.filter !== 'undefined') {
92
+ this.buildTokens(e.filter, evt, toks, e, data[0]);
93
+ if (eval(this.replaceTokens(e.filter, toks)) === false) continue;
94
+ }
95
+ for (let j = 0; j < e.points.length; j++) {
96
+ let _point = e.points[j];
97
+ // Figure out whether we need to check the filter for each point.
98
+ if (typeof _point.filter !== 'undefined') {
99
+ this.buildTokens(_point.filter, evt, toks, e, data[0]);
100
+ if (eval(this.replaceTokens(_point.filter, toks)) === false) continue;
101
+ }
102
+ // iterate through points array
103
+ let point = new Point(_point.measurement)
104
+ let point2 = new Point(_point.measurement);
105
+ _point.tags.forEach(_tag => {
106
+ let sname = _tag.name;
107
+ this.buildTokens(sname, evt, toks, e, data[0]);
108
+ sname = this.replaceTokens(sname, toks);
109
+ let svalue = _tag.value;
110
+ this.buildTokens(svalue, evt, toks, e, data[0]);
111
+ svalue = this.replaceTokens(svalue, toks);
112
+ if (typeof sname !== 'undefined' && typeof svalue !== 'undefined' && !sname.includes('@bind') && !svalue.includes('@bind') && svalue !== null) {
113
+ point.tag(sname, svalue);
114
+ if (typeof _point.storePrevState !== 'undefined' && _point.storePrevState) point2.tag(sname, svalue);
115
+ }
116
+ else {
117
+ logger.error(`InfluxDB tag binding failure on ${evt}:${_tag.name}/${_tag.value} --> ${svalue || 'undefined'} ${JSON.stringify(data[0])}`);
118
+ if (typeof sname === 'undefined') logger.error(`InfluxDB tag name is undefined`);
119
+ if (typeof svalue === 'undefined') logger.error(`InfluxDB value is undefined`);
120
+ if (svalue.includes('@bind')) logger.error(`InfluxDB value not bound`);
121
+ if (svalue === null) logger.error(`InfluxDB value is null`);
122
+ }
123
+ })
124
+ _point.fields.forEach(_field => {
125
+ try {
126
+ let sname = _field.name;
127
+ this.buildTokens(sname, evt, toks, e, data[0]);
128
+ //console.log(toks);
129
+ sname = this.replaceTokens(sname, toks);
130
+ let svalue = _field.value;
131
+ this.buildTokens(svalue, evt, toks, e, data[0]);
132
+ svalue = this.replaceTokens(svalue, toks);
133
+ if (typeof sname !== 'undefined' && typeof svalue !== 'undefined' && !sname.includes('@bind') && !svalue.includes('@bind') && svalue !== null)
134
+ switch (_field.type) {
135
+ case 'int':
136
+ case 'integer':
137
+ let int = parseInt(svalue, 10);
138
+ if (!isNaN(int)) point.intField(sname, int);
139
+ // if (!isNaN(int) && typeof _point.storePrevState !== 'undefined' && _point.storePrevState) point2.intField(sname, int);
140
+ break;
141
+ case 'string':
142
+ point.stringField(sname, svalue);
143
+ // if (typeof _point.storePrevState !== 'undefined' && _point.storePrevState) point2.stringField(sname, svalue);
144
+ break;
145
+ case 'boolean':
146
+ point.booleanField(sname, utils.makeBool(svalue));
147
+ if (typeof _point.storePrevState !== 'undefined' && _point.storePrevState) point2.booleanField(sname, !utils.makeBool(svalue));
148
+ break;
149
+ case 'float':
150
+ let float = parseFloat(svalue);
151
+ if (!isNaN(float)) point.floatField(sname, float);
152
+ // if (!isNaN(float) && typeof _point.storePrevState !== 'undefined' && _point.storePrevState) point2.intField(sname, int);
153
+ break;
154
+ case 'timestamp':
155
+ case 'datetime':
156
+ case 'date':
157
+ //let dt = Date.parse(svalue.replace(/^["'](.+(?=["']$))["']$/, '$1'));
158
+ // RKS: 07-06-21 - I think this is missing the eval function around all of this. The strings still have the quotes around them. I think
159
+ // maybe we need to create a closure and execute it as a code segment for variable data.
160
+ let sdt = eval(svalue);
161
+ if (sdt !== null && typeof sdt !== 'undefined') {
162
+ let dt = Date.parse(sdt);
163
+ if (!isNaN(dt)) point.intField(sname, dt);
164
+ else if (svalue !== '') logger.warn(`Influx error parsing date from ${sname}: ${svalue}`);
165
+ }
166
+ break;
167
+ }
168
+ else {
169
+ logger.error(`InfluxDB point binding failure on ${evt}:${_field.name}/${_field.value} --> ${svalue || 'undefined'}`);
170
+ }
171
+ } catch (err) { logger.error(`Error binding InfluxDB point fields ${err.message}`); }
172
+ });
173
+ if (typeof _point.series !== 'undefined') {
174
+ try {
175
+ this.buildTokens(_point.series.value, evt, toks, e, data[0]);
176
+ let ser = eval(this.replaceTokens(_point.series.value, toks));
177
+ let ts = Date.parse(ser);
178
+ if (isNaN(ts)) {
179
+ logger.error(`Influx series timestamp is invalid ${ser}`);
180
+ }
181
+ else
182
+ point.timestamp(new Date(ts));
183
+ } catch (err) { logger.error(`Error parsing Influx point series for ${evt} - ${_point.series.value}`); }
184
+ }
185
+ else
186
+ point.timestamp(new Date());
187
+ try {
188
+
189
+ if (typeof _point.storePrevState !== 'undefined' && _point.storePrevState) {
190
+ // copy the point and subtract a second and keep inverse value
191
+ let ts = new Date();
192
+ let sec = ts.getSeconds() - 1;
193
+ ts.setSeconds(sec);
194
+ point2.timestamp(ts);
195
+ logger.silly(`Writing influx ${e.name} inverse data point ${point2.toString()})`)
196
+ this.writeApi.writePoint(point2);
197
+ }
198
+ if (typeof point.toLineProtocol() !== 'undefined') {
199
+ logger.silly(`Writing influx ${e.name} data point ${point.toString()}`)
200
+ this.writeApi.writePoint(point);
201
+ this.writeApi.flush()
202
+ .catch(error => { logger.error(`Error flushing Influx data point ${point.toString()} ${error}`); });
203
+ //logger.info(`INFLUX: ${point.toLineProtocol()}`)
204
+ }
205
+ else {
206
+ logger.silly(`Skipping INFLUX write because some data is missing with ${e.name} event on measurement ${_point.measurement}.`)
207
+ }
208
+ }
209
+ catch (err) {
210
+ logger.error(`Error writing to Influx: ${err.message}`)
211
+ }
212
+ }
213
+ }
214
+ }
215
+ }
216
+ }
217
+ public close = () => {
218
+
219
+ }
220
+ }
221
+
222
+ class InfluxInterfaceEvent extends InterfaceEvent {
223
+ public points: IPoint[];
224
+ }
225
+
226
+ export interface IPoint {
227
+ measurement: string;
228
+ series?: ISeries;
229
+ tags: ITag[];
230
+ fields: IFields[];
231
+ storePrevState?: boolean;
232
+ filter?: any;
233
+ }
234
+ export interface ITag {
235
+ name: string;
236
+ value: string;
237
+ }
238
+ export interface IFields {
239
+ name: string;
240
+ value: string;
241
+ type: string;
242
+ }
243
+ export interface ISeries {
244
+ value: string;
245
+ }