nodejs-poolcontroller 7.6.0 → 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 -215
  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 +0 -0
  10. package/config/Config.ts +24 -2
  11. package/config/VersionCheck.ts +27 -12
  12. package/config copy.json +299 -299
  13. package/controller/Constants.ts +0 -0
  14. package/controller/Equipment.ts +2459 -2405
  15. package/controller/Errors.ts +180 -180
  16. package/controller/Lockouts.ts +436 -422
  17. package/controller/State.ts +51 -26
  18. package/controller/boards/BoardFactory.ts +45 -45
  19. package/controller/boards/EasyTouchBoard.ts +2653 -2537
  20. package/controller/boards/IntelliCenterBoard.ts +4230 -4034
  21. package/controller/boards/IntelliComBoard.ts +63 -63
  22. package/controller/boards/IntelliTouchBoard.ts +241 -241
  23. package/controller/boards/NixieBoard.ts +1675 -1660
  24. package/controller/boards/SystemBoard.ts +4697 -4463
  25. package/controller/comms/Comms.ts +138 -1
  26. package/controller/comms/messages/Messages.ts +3 -5
  27. package/controller/comms/messages/config/ChlorinatorMessage.ts +1 -1
  28. package/controller/comms/messages/config/CircuitGroupMessage.ts +0 -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 +0 -0
  32. package/controller/comms/messages/config/CustomNameMessage.ts +30 -30
  33. package/controller/comms/messages/config/EquipmentMessage.ts +0 -0
  34. package/controller/comms/messages/config/ExternalMessage.ts +9 -7
  35. package/controller/comms/messages/config/FeatureMessage.ts +0 -0
  36. package/controller/comms/messages/config/GeneralMessage.ts +0 -0
  37. package/controller/comms/messages/config/HeaterMessage.ts +0 -20
  38. package/controller/comms/messages/config/IntellichemMessage.ts +0 -0
  39. package/controller/comms/messages/config/OptionsMessage.ts +25 -1
  40. package/controller/comms/messages/config/PumpMessage.ts +0 -0
  41. package/controller/comms/messages/config/RemoteMessage.ts +0 -0
  42. package/controller/comms/messages/config/ScheduleMessage.ts +347 -342
  43. package/controller/comms/messages/config/SecurityMessage.ts +0 -0
  44. package/controller/comms/messages/config/ValveMessage.ts +0 -0
  45. package/controller/comms/messages/status/ChlorinatorStateMessage.ts +0 -0
  46. package/controller/comms/messages/status/EquipmentStateMessage.ts +1 -1
  47. package/controller/comms/messages/status/HeaterStateMessage.ts +86 -86
  48. package/controller/comms/messages/status/IntelliChemStateMessage.ts +445 -397
  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 -162
  53. package/controller/nixie/NixieEquipment.ts +103 -103
  54. package/controller/nixie/bodies/Body.ts +120 -120
  55. package/controller/nixie/bodies/Filter.ts +135 -135
  56. package/controller/nixie/chemistry/ChemController.ts +2498 -2398
  57. package/controller/nixie/chemistry/Chlorinator.ts +314 -314
  58. package/controller/nixie/circuits/Circuit.ts +248 -245
  59. package/controller/nixie/heaters/Heater.ts +648 -600
  60. package/controller/nixie/pumps/Pump.ts +661 -661
  61. package/controller/nixie/schedules/Schedule.ts +257 -257
  62. package/controller/nixie/valves/Valve.ts +170 -170
  63. package/defaultConfig.json +286 -286
  64. package/issue_template.md +51 -51
  65. package/logger/DataLogger.ts +448 -448
  66. package/logger/Logger.ts +0 -0
  67. package/package.json +56 -56
  68. package/tsconfig.json +25 -25
  69. package/web/Server.ts +2 -2
  70. package/web/bindings/influxDB.json +1021 -981
  71. package/web/bindings/mqtt.json +654 -654
  72. package/web/bindings/mqttAlt.json +684 -684
  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 -124
  79. package/web/interfaces/influxInterface.ts +245 -241
  80. package/web/interfaces/mqttInterface.ts +475 -475
  81. package/web/services/config/Config.ts +10 -108
  82. package/web/services/config/ConfigSocket.ts +0 -0
  83. package/web/services/state/State.ts +71 -4
  84. package/web/services/state/StateSocket.ts +0 -0
  85. package/web/services/utilities/Utilities.ts +42 -42
@@ -1,241 +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
- 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
- }
119
- })
120
- _point.fields.forEach(_field => {
121
- try {
122
- let sname = _field.name;
123
- this.buildTokens(sname, evt, toks, e, data[0]);
124
- //console.log(toks);
125
- sname = this.replaceTokens(sname, toks);
126
- let svalue = _field.value;
127
- this.buildTokens(svalue, evt, toks, e, data[0]);
128
- svalue = this.replaceTokens(svalue, toks);
129
- if (typeof sname !== 'undefined' && typeof svalue !== 'undefined' && !sname.includes('@bind') && !svalue.includes('@bind') && svalue !== null)
130
- switch (_field.type) {
131
- case 'int':
132
- case 'integer':
133
- let int = parseInt(svalue, 10);
134
- if (!isNaN(int)) point.intField(sname, int);
135
- // if (!isNaN(int) && typeof _point.storePrevState !== 'undefined' && _point.storePrevState) point2.intField(sname, int);
136
- break;
137
- case 'string':
138
- point.stringField(sname, svalue);
139
- // if (typeof _point.storePrevState !== 'undefined' && _point.storePrevState) point2.stringField(sname, svalue);
140
- break;
141
- case 'boolean':
142
- point.booleanField(sname, utils.makeBool(svalue));
143
- if (typeof _point.storePrevState !== 'undefined' && _point.storePrevState) point2.booleanField(sname, !utils.makeBool(svalue));
144
- break;
145
- case 'float':
146
- let float = parseFloat(svalue);
147
- if (!isNaN(float)) point.floatField(sname, float);
148
- // if (!isNaN(float) && typeof _point.storePrevState !== 'undefined' && _point.storePrevState) point2.intField(sname, int);
149
- break;
150
- case 'timestamp':
151
- case 'datetime':
152
- case 'date':
153
- //let dt = Date.parse(svalue.replace(/^["'](.+(?=["']$))["']$/, '$1'));
154
- // 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
155
- // maybe we need to create a closure and execute it as a code segment for variable data.
156
- let sdt = eval(svalue);
157
- if (sdt !== null && typeof sdt !== 'undefined') {
158
- let dt = Date.parse(sdt);
159
- if (!isNaN(dt)) point.intField(sname, dt);
160
- else if (svalue !== '') logger.warn(`Influx error parsing date from ${sname}: ${svalue}`);
161
- }
162
- break;
163
- }
164
- else {
165
- logger.error(`InfluxDB point binding failure on ${evt}:${_field.name}/${_field.value} --> ${svalue || 'undefined'}`);
166
- }
167
- } catch (err) { logger.error(`Error binding InfluxDB point fields ${err.message}`); }
168
- });
169
- if (typeof _point.series !== 'undefined') {
170
- try {
171
- this.buildTokens(_point.series.value, evt, toks, e, data[0]);
172
- let ser = eval(this.replaceTokens(_point.series.value, toks));
173
- let ts = Date.parse(ser);
174
- if (isNaN(ts)) {
175
- logger.error(`Influx series timestamp is invalid ${ser}`);
176
- }
177
- else
178
- point.timestamp(new Date(ts));
179
- } catch (err) { logger.error(`Error parsing Influx point series for ${evt} - ${_point.series.value}`); }
180
- }
181
- else
182
- point.timestamp(new Date());
183
- try {
184
-
185
- if (typeof _point.storePrevState !== 'undefined' && _point.storePrevState) {
186
- // copy the point and subtract a second and keep inverse value
187
- let ts = new Date();
188
- let sec = ts.getSeconds() - 1;
189
- ts.setSeconds(sec);
190
- point2.timestamp(ts);
191
- logger.silly(`Writing influx ${e.name} inverse data point ${point2.toString()})`)
192
- this.writeApi.writePoint(point2);
193
- }
194
- if (typeof point.toLineProtocol() !== 'undefined') {
195
- logger.silly(`Writing influx ${e.name} data point ${point.toString()}`)
196
- this.writeApi.writePoint(point);
197
- this.writeApi.flush()
198
- .catch(error => { logger.error(error); });
199
- //logger.info(`INFLUX: ${point.toLineProtocol()}`)
200
- }
201
- else {
202
- logger.silly(`Skipping INFLUX write because some data is missing with ${e.name} event on measurement ${_point.measurement}.`)
203
- }
204
- }
205
- catch (err) {
206
- logger.error(`Error writing to Influx: ${err.message}`)
207
- }
208
- }
209
- }
210
- }
211
- }
212
- }
213
- public close = () => {
214
-
215
- }
216
- }
217
-
218
- class InfluxInterfaceEvent extends InterfaceEvent {
219
- public points: IPoint[];
220
- }
221
-
222
- export interface IPoint {
223
- measurement: string;
224
- series?: ISeries;
225
- tags: ITag[];
226
- fields: IFields[];
227
- storePrevState?: boolean;
228
- filter?: any;
229
- }
230
- export interface ITag {
231
- name: string;
232
- value: string;
233
- }
234
- export interface IFields {
235
- name: string;
236
- value: string;
237
- type: string;
238
- }
239
- export interface ISeries {
240
- value: string;
241
- }
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
+ }