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.
- package/.eslintrc.json +44 -44
- package/.github/ISSUE_TEMPLATE/bug_report.md +52 -52
- package/CONTRIBUTING.md +74 -74
- package/Changelog +215 -195
- package/Dockerfile +17 -17
- package/Gruntfile.js +40 -40
- package/LICENSE +661 -661
- package/README.md +191 -186
- package/app.ts +2 -0
- package/config/Config.ts +27 -2
- package/config/VersionCheck.ts +33 -14
- package/config copy.json +299 -299
- package/controller/Constants.ts +88 -0
- package/controller/Equipment.ts +2459 -2225
- package/controller/Errors.ts +180 -157
- package/controller/Lockouts.ts +437 -0
- package/controller/State.ts +364 -79
- package/controller/boards/BoardFactory.ts +45 -45
- package/controller/boards/EasyTouchBoard.ts +2653 -2489
- package/controller/boards/IntelliCenterBoard.ts +4230 -3973
- package/controller/boards/IntelliComBoard.ts +63 -63
- package/controller/boards/IntelliTouchBoard.ts +241 -167
- package/controller/boards/NixieBoard.ts +1675 -1105
- package/controller/boards/SystemBoard.ts +4697 -3201
- package/controller/comms/Comms.ts +222 -10
- package/controller/comms/messages/Messages.ts +13 -9
- package/controller/comms/messages/config/ChlorinatorMessage.ts +13 -4
- package/controller/comms/messages/config/CircuitGroupMessage.ts +6 -0
- package/controller/comms/messages/config/CircuitMessage.ts +0 -0
- package/controller/comms/messages/config/ConfigMessage.ts +0 -0
- package/controller/comms/messages/config/CoverMessage.ts +1 -0
- package/controller/comms/messages/config/CustomNameMessage.ts +30 -30
- package/controller/comms/messages/config/EquipmentMessage.ts +4 -0
- package/controller/comms/messages/config/ExternalMessage.ts +53 -33
- package/controller/comms/messages/config/FeatureMessage.ts +8 -1
- package/controller/comms/messages/config/GeneralMessage.ts +8 -0
- package/controller/comms/messages/config/HeaterMessage.ts +14 -28
- package/controller/comms/messages/config/IntellichemMessage.ts +4 -1
- package/controller/comms/messages/config/OptionsMessage.ts +38 -2
- package/controller/comms/messages/config/PumpMessage.ts +4 -20
- package/controller/comms/messages/config/RemoteMessage.ts +4 -0
- package/controller/comms/messages/config/ScheduleMessage.ts +347 -331
- package/controller/comms/messages/config/SecurityMessage.ts +1 -0
- package/controller/comms/messages/config/ValveMessage.ts +13 -3
- package/controller/comms/messages/status/ChlorinatorStateMessage.ts +2 -3
- package/controller/comms/messages/status/EquipmentStateMessage.ts +79 -25
- package/controller/comms/messages/status/HeaterStateMessage.ts +86 -53
- package/controller/comms/messages/status/IntelliChemStateMessage.ts +445 -386
- package/controller/comms/messages/status/IntelliValveStateMessage.ts +35 -35
- package/controller/comms/messages/status/PumpStateMessage.ts +0 -0
- package/controller/comms/messages/status/VersionMessage.ts +0 -0
- package/controller/nixie/Nixie.ts +162 -160
- package/controller/nixie/NixieEquipment.ts +103 -103
- package/controller/nixie/bodies/Body.ts +120 -117
- package/controller/nixie/bodies/Filter.ts +135 -135
- package/controller/nixie/chemistry/ChemController.ts +2498 -2395
- package/controller/nixie/chemistry/Chlorinator.ts +314 -313
- package/controller/nixie/circuits/Circuit.ts +248 -210
- package/controller/nixie/heaters/Heater.ts +649 -441
- package/controller/nixie/pumps/Pump.ts +661 -599
- package/controller/nixie/schedules/Schedule.ts +257 -256
- package/controller/nixie/valves/Valve.ts +170 -170
- package/defaultConfig.json +286 -271
- package/issue_template.md +51 -51
- package/logger/DataLogger.ts +448 -433
- package/logger/Logger.ts +0 -0
- package/package.json +56 -54
- package/tsconfig.json +25 -25
- package/web/Server.ts +522 -31
- package/web/bindings/influxDB.json +1022 -894
- package/web/bindings/mqtt.json +654 -543
- package/web/bindings/mqttAlt.json +684 -574
- package/web/bindings/rulesManager.json +54 -54
- package/web/bindings/smartThings-Hubitat.json +31 -31
- package/web/bindings/valveRelays.json +20 -20
- package/web/bindings/vera.json +25 -25
- package/web/interfaces/baseInterface.ts +136 -136
- package/web/interfaces/httpInterface.ts +124 -122
- package/web/interfaces/influxInterface.ts +245 -240
- package/web/interfaces/mqttInterface.ts +475 -464
- package/web/services/config/Config.ts +181 -152
- package/web/services/config/ConfigSocket.ts +0 -0
- package/web/services/state/State.ts +118 -7
- package/web/services/state/StateSocket.ts +18 -1
- 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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
36
|
-
|
|
37
|
-
let
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
let
|
|
72
|
-
let
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
let
|
|
104
|
-
_point.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
case '
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
break;
|
|
149
|
-
case '
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
//
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this.writeApi.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
export interface
|
|
239
|
-
|
|
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
|
+
}
|