nodejs-poolcontroller 7.6.1 → 8.0.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.
- package/.eslintrc.json +36 -45
- package/.github/ISSUE_TEMPLATE/1-bug-report.yml +84 -0
- package/.github/ISSUE_TEMPLATE/2-docs.md +12 -0
- package/.github/ISSUE_TEMPLATE/3-proposal.md +28 -0
- package/.github/ISSUE_TEMPLATE/config.yml +8 -0
- package/CONTRIBUTING.md +74 -74
- package/Changelog +242 -215
- package/Dockerfile +17 -17
- package/Gruntfile.js +40 -40
- package/LICENSE +661 -661
- package/README.md +195 -191
- package/anslq25/MessagesMock.ts +218 -0
- package/anslq25/boards/MockBoardFactory.ts +50 -0
- package/anslq25/boards/MockEasyTouchBoard.ts +696 -0
- package/anslq25/boards/MockSystemBoard.ts +217 -0
- package/anslq25/chemistry/MockChlorinator.ts +75 -0
- package/anslq25/pumps/MockPump.ts +84 -0
- package/app.ts +10 -14
- package/config/Config.ts +26 -8
- package/config/VersionCheck.ts +8 -4
- package/controller/Constants.ts +59 -25
- package/controller/Equipment.ts +2667 -2459
- package/controller/Errors.ts +181 -180
- package/controller/Lockouts.ts +534 -436
- package/controller/State.ts +596 -77
- package/controller/boards/AquaLinkBoard.ts +1003 -0
- package/controller/boards/BoardFactory.ts +53 -45
- package/controller/boards/EasyTouchBoard.ts +3079 -2653
- package/controller/boards/IntelliCenterBoard.ts +3821 -4230
- package/controller/boards/IntelliComBoard.ts +69 -63
- package/controller/boards/IntelliTouchBoard.ts +384 -241
- package/controller/boards/NixieBoard.ts +1871 -1675
- package/controller/boards/SunTouchBoard.ts +393 -0
- package/controller/boards/SystemBoard.ts +5244 -4697
- package/controller/comms/Comms.ts +905 -541
- package/controller/comms/ScreenLogic.ts +1663 -0
- package/controller/comms/messages/Messages.ts +382 -54
- package/controller/comms/messages/config/ChlorinatorMessage.ts +8 -4
- package/controller/comms/messages/config/CircuitGroupMessage.ts +5 -2
- package/controller/comms/messages/config/CircuitMessage.ts +82 -13
- package/controller/comms/messages/config/ConfigMessage.ts +3 -1
- package/controller/comms/messages/config/CoverMessage.ts +2 -1
- package/controller/comms/messages/config/CustomNameMessage.ts +31 -30
- package/controller/comms/messages/config/EquipmentMessage.ts +5 -1
- package/controller/comms/messages/config/ExternalMessage.ts +33 -3
- package/controller/comms/messages/config/FeatureMessage.ts +2 -1
- package/controller/comms/messages/config/GeneralMessage.ts +2 -1
- package/controller/comms/messages/config/HeaterMessage.ts +145 -11
- package/controller/comms/messages/config/IntellichemMessage.ts +2 -1
- package/controller/comms/messages/config/OptionsMessage.ts +16 -27
- package/controller/comms/messages/config/PumpMessage.ts +62 -47
- package/controller/comms/messages/config/RemoteMessage.ts +80 -13
- package/controller/comms/messages/config/ScheduleMessage.ts +390 -347
- package/controller/comms/messages/config/SecurityMessage.ts +2 -1
- package/controller/comms/messages/config/ValveMessage.ts +44 -27
- package/controller/comms/messages/status/ChlorinatorStateMessage.ts +44 -91
- package/controller/comms/messages/status/EquipmentStateMessage.ts +139 -30
- package/controller/comms/messages/status/HeaterStateMessage.ts +135 -86
- package/controller/comms/messages/status/IntelliChemStateMessage.ts +448 -445
- package/controller/comms/messages/status/IntelliValveStateMessage.ts +36 -35
- package/controller/comms/messages/status/PumpStateMessage.ts +92 -2
- package/controller/comms/messages/status/VersionMessage.ts +2 -1
- package/controller/nixie/Nixie.ts +173 -162
- package/controller/nixie/NixieEquipment.ts +104 -103
- package/controller/nixie/bodies/Body.ts +120 -120
- package/controller/nixie/bodies/Filter.ts +135 -135
- package/controller/nixie/chemistry/ChemController.ts +2682 -2498
- package/controller/nixie/chemistry/ChemDoser.ts +806 -0
- package/controller/nixie/chemistry/Chlorinator.ts +367 -314
- package/controller/nixie/circuits/Circuit.ts +402 -248
- package/controller/nixie/heaters/Heater.ts +815 -649
- package/controller/nixie/pumps/Pump.ts +934 -661
- package/controller/nixie/schedules/Schedule.ts +319 -257
- package/controller/nixie/valves/Valve.ts +170 -170
- package/defaultConfig.json +346 -286
- package/logger/DataLogger.ts +448 -448
- package/logger/Logger.ts +38 -9
- package/package.json +60 -56
- package/tsconfig.json +25 -25
- package/web/Server.ts +275 -117
- package/web/bindings/aqualinkD.json +560 -0
- package/web/bindings/homeassistant.json +437 -0
- package/web/bindings/influxDB.json +1066 -1021
- package/web/bindings/mqtt.json +721 -654
- package/web/bindings/mqttAlt.json +746 -684
- 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 +188 -136
- package/web/interfaces/httpInterface.ts +148 -124
- package/web/interfaces/influxInterface.ts +283 -245
- package/web/interfaces/mqttInterface.ts +695 -475
- package/web/interfaces/ruleInterface.ts +87 -0
- package/web/services/config/Config.ts +177 -49
- package/web/services/config/ConfigSocket.ts +2 -1
- package/web/services/state/State.ts +154 -3
- package/web/services/state/StateSocket.ts +69 -18
- package/web/services/utilities/Utilities.ts +232 -42
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -52
- package/config copy.json +0 -300
- package/issue_template.md +0 -52
|
@@ -1,649 +1,815 @@
|
|
|
1
|
-
import { EquipmentNotFoundError, InvalidEquipmentDataError, InvalidEquipmentIdError, InvalidOperationError, ParameterOutOfRangeError } from '../../Errors';
|
|
2
|
-
import { utils, Timestamp } from '../../Constants';
|
|
3
|
-
import { logger } from '../../../logger/Logger';
|
|
4
|
-
|
|
5
|
-
import { NixieEquipment, NixieChildEquipment, NixieEquipmentCollection, INixieControlPanel } from "../NixieEquipment";
|
|
6
|
-
import { Heater, HeaterCollection, sys } from "../../../controller/Equipment";
|
|
7
|
-
import { BodyTempState, HeaterState, state, } from "../../State";
|
|
8
|
-
import { setTimeout, clearTimeout } from 'timers';
|
|
9
|
-
import { NixieControlPanel } from '../Nixie';
|
|
10
|
-
import { webApp, InterfaceServerResponse } from "../../../web/Server";
|
|
11
|
-
import { conn } from '../../../controller/comms/Comms';
|
|
12
|
-
import { Outbound, Protocol, Response } from '../../../controller/comms/messages/Messages';
|
|
13
|
-
import { delayMgr } from '../../Lockouts';
|
|
14
|
-
|
|
15
|
-
export class NixieHeaterCollection extends NixieEquipmentCollection<NixieHeaterBase> {
|
|
16
|
-
public async deleteHeaterAsync(id: number) {
|
|
17
|
-
try {
|
|
18
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
19
|
-
let heater = this[i];
|
|
20
|
-
if (heater.id === id) {
|
|
21
|
-
await heater.closeAsync();
|
|
22
|
-
this.splice(i, 1);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
} catch (err) { return Promise.reject(`Nixie Control Panel deleteHeaterAsync ${err.message}`); }
|
|
26
|
-
}
|
|
27
|
-
public async setHeaterStateAsync(hstate: HeaterState, val: boolean, isCooling: boolean) {
|
|
28
|
-
try {
|
|
29
|
-
let h: NixieHeaterBase = this.find(elem => elem.id === hstate.id) as NixieHeaterBase;
|
|
30
|
-
if (typeof h === 'undefined') {
|
|
31
|
-
return Promise.reject(new Error(`NCP: Heater ${hstate.id}-${hstate.name} could not be found to set the state to ${val}.`));
|
|
32
|
-
}
|
|
33
|
-
await h.setHeaterStateAsync(hstate, val, isCooling);
|
|
34
|
-
}
|
|
35
|
-
catch (err) { return logger.error(`NCP: setHeaterStateAsync ${hstate.id}-${hstate.name}: ${err.message}`); }
|
|
36
|
-
}
|
|
37
|
-
public async setHeaterAsync(heater: Heater, data: any) {
|
|
38
|
-
// By the time we get here we know that we are in control and this is a Nixie heater.
|
|
39
|
-
try {
|
|
40
|
-
let h: NixieHeaterBase = this.find(elem => elem.id === heater.id) as NixieHeaterBase;
|
|
41
|
-
if (typeof h === 'undefined') {
|
|
42
|
-
heater.master = 1;
|
|
43
|
-
h = NixieHeaterBase.create(this.controlPanel, heater);
|
|
44
|
-
this.push(h);
|
|
45
|
-
await h.setHeaterAsync(data);
|
|
46
|
-
logger.info(`A Heater was not found for id #${heater.id} creating Heater`);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
await h.setHeaterAsync(data);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch (err) { logger.error(`setHeaterAsync: ${err.message}`); return Promise.reject(err); }
|
|
53
|
-
}
|
|
54
|
-
public async initAsync(heaters: HeaterCollection) {
|
|
55
|
-
try {
|
|
56
|
-
for (let i = 0; i < heaters.length; i++) {
|
|
57
|
-
let heater = heaters.getItemByIndex(i);
|
|
58
|
-
if (heater.master === 1) {
|
|
59
|
-
if (typeof this.find(elem => elem.id === heater.id) === 'undefined') {
|
|
60
|
-
logger.info(`Initializing Heater ${heater.name}`);
|
|
61
|
-
let nHeater = NixieHeaterBase.create(this.controlPanel, heater);
|
|
62
|
-
this.push(nHeater);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
catch (err) { logger.error(`Nixie Heater initAsync: ${err.message}`); return Promise.reject(err); }
|
|
68
|
-
}
|
|
69
|
-
public async closeAsync() {
|
|
70
|
-
try {
|
|
71
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
72
|
-
try {
|
|
73
|
-
await this[i].closeAsync();
|
|
74
|
-
this.splice(i, 1);
|
|
75
|
-
} catch (err) { logger.error(`Error stopping Nixie Heater ${err}`); }
|
|
76
|
-
}
|
|
77
|
-
} catch (err) { } // Don't bail if we have an errror.
|
|
78
|
-
}
|
|
79
|
-
public async initHeaterAsync(heater: Heater): Promise<NixieHeaterBase> {
|
|
80
|
-
try {
|
|
81
|
-
let c: NixieHeaterBase = this.find(elem => elem.id === heater.id) as NixieHeaterBase;
|
|
82
|
-
if (typeof c === 'undefined') {
|
|
83
|
-
c = NixieHeaterBase.create(this.controlPanel, heater);
|
|
84
|
-
this.push(c);
|
|
85
|
-
}
|
|
86
|
-
return c;
|
|
87
|
-
} catch (err) { logger.error(`initHeaterAsync: ${err.message}`); return Promise.reject(err); }
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
protected
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
case '
|
|
122
|
-
return new
|
|
123
|
-
|
|
124
|
-
return new
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
public
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
public
|
|
158
|
-
public
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
try {
|
|
217
|
-
if (typeof
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
} catch (err) { logger.error(`Nixie Error
|
|
338
|
-
}
|
|
339
|
-
public async
|
|
340
|
-
try {
|
|
341
|
-
if (typeof
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
//
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
try {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
443
|
-
this._pollTimer = null;
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
if (
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
catch (err) {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
this.
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
1
|
+
import { EquipmentNotFoundError, InvalidEquipmentDataError, InvalidEquipmentIdError, InvalidOperationError, ParameterOutOfRangeError } from '../../Errors';
|
|
2
|
+
import { utils, Timestamp } from '../../Constants';
|
|
3
|
+
import { logger } from '../../../logger/Logger';
|
|
4
|
+
|
|
5
|
+
import { NixieEquipment, NixieChildEquipment, NixieEquipmentCollection, INixieControlPanel } from "../NixieEquipment";
|
|
6
|
+
import { Body, Heater, HeaterCollection, sys } from "../../../controller/Equipment";
|
|
7
|
+
import { BodyTempState, HeaterState, state, } from "../../State";
|
|
8
|
+
import { setTimeout, clearTimeout } from 'timers';
|
|
9
|
+
import { NixieControlPanel } from '../Nixie';
|
|
10
|
+
import { webApp, InterfaceServerResponse } from "../../../web/Server";
|
|
11
|
+
import { conn } from '../../../controller/comms/Comms';
|
|
12
|
+
import { Inbound, Outbound, Protocol, Response } from '../../../controller/comms/messages/Messages';
|
|
13
|
+
import { delayMgr } from '../../Lockouts';
|
|
14
|
+
|
|
15
|
+
export class NixieHeaterCollection extends NixieEquipmentCollection<NixieHeaterBase> {
|
|
16
|
+
public async deleteHeaterAsync(id: number) {
|
|
17
|
+
try {
|
|
18
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
19
|
+
let heater = this[i];
|
|
20
|
+
if (heater.id === id) {
|
|
21
|
+
await heater.closeAsync();
|
|
22
|
+
this.splice(i, 1);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
} catch (err) { return Promise.reject(`Nixie Control Panel deleteHeaterAsync ${err.message}`); }
|
|
26
|
+
}
|
|
27
|
+
public async setHeaterStateAsync(hstate: HeaterState, val: boolean, isCooling: boolean) {
|
|
28
|
+
try {
|
|
29
|
+
let h: NixieHeaterBase = this.find(elem => elem.id === hstate.id) as NixieHeaterBase;
|
|
30
|
+
if (typeof h === 'undefined') {
|
|
31
|
+
return Promise.reject(new Error(`NCP: Heater ${hstate.id}-${hstate.name} could not be found to set the state to ${val}.`));
|
|
32
|
+
}
|
|
33
|
+
await h.setHeaterStateAsync(hstate, val, isCooling);
|
|
34
|
+
}
|
|
35
|
+
catch (err) { return logger.error(`NCP: setHeaterStateAsync ${hstate.id}-${hstate.name}: ${err.message}`); }
|
|
36
|
+
}
|
|
37
|
+
public async setHeaterAsync(heater: Heater, data: any) {
|
|
38
|
+
// By the time we get here we know that we are in control and this is a Nixie heater.
|
|
39
|
+
try {
|
|
40
|
+
let h: NixieHeaterBase = this.find(elem => elem.id === heater.id) as NixieHeaterBase;
|
|
41
|
+
if (typeof h === 'undefined') {
|
|
42
|
+
heater.master = 1;
|
|
43
|
+
h = NixieHeaterBase.create(this.controlPanel, heater);
|
|
44
|
+
this.push(h);
|
|
45
|
+
await h.setHeaterAsync(data);
|
|
46
|
+
logger.info(`A Heater was not found for id #${heater.id} creating Heater`);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
await h.setHeaterAsync(data);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (err) { logger.error(`setHeaterAsync: ${err.message}`); return Promise.reject(err); }
|
|
53
|
+
}
|
|
54
|
+
public async initAsync(heaters: HeaterCollection) {
|
|
55
|
+
try {
|
|
56
|
+
for (let i = 0; i < heaters.length; i++) {
|
|
57
|
+
let heater = heaters.getItemByIndex(i);
|
|
58
|
+
if (heater.master === 1) {
|
|
59
|
+
if (typeof this.find(elem => elem.id === heater.id) === 'undefined') {
|
|
60
|
+
logger.info(`Initializing Heater ${heater.name}`);
|
|
61
|
+
let nHeater = NixieHeaterBase.create(this.controlPanel, heater);
|
|
62
|
+
this.push(nHeater);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (err) { logger.error(`Nixie Heater initAsync: ${err.message}`); return Promise.reject(err); }
|
|
68
|
+
}
|
|
69
|
+
public async closeAsync() {
|
|
70
|
+
try {
|
|
71
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
72
|
+
try {
|
|
73
|
+
await this[i].closeAsync();
|
|
74
|
+
this.splice(i, 1);
|
|
75
|
+
} catch (err) { logger.error(`Error stopping Nixie Heater ${err}`); }
|
|
76
|
+
}
|
|
77
|
+
} catch (err) { } // Don't bail if we have an errror.
|
|
78
|
+
}
|
|
79
|
+
public async initHeaterAsync(heater: Heater): Promise<NixieHeaterBase> {
|
|
80
|
+
try {
|
|
81
|
+
let c: NixieHeaterBase = this.find(elem => elem.id === heater.id) as NixieHeaterBase;
|
|
82
|
+
if (typeof c === 'undefined') {
|
|
83
|
+
c = NixieHeaterBase.create(this.controlPanel, heater);
|
|
84
|
+
this.push(c);
|
|
85
|
+
}
|
|
86
|
+
return c;
|
|
87
|
+
} catch (err) { logger.error(`initHeaterAsync: ${err.message}`); return Promise.reject(err); }
|
|
88
|
+
}
|
|
89
|
+
public async setServiceModeAsync() {
|
|
90
|
+
try {
|
|
91
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
92
|
+
let heater = this[i] as NixieHeaterBase;
|
|
93
|
+
await heater.setServiceModeAsync();
|
|
94
|
+
}
|
|
95
|
+
} catch (err) { return Promise.reject(`Nixie Control Panel setServiceMode ${err.message}`); }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export class NixieHeaterBase extends NixieEquipment {
|
|
99
|
+
protected _suspendPolling: number = 0;
|
|
100
|
+
public pollingInterval: number = 10000;
|
|
101
|
+
public heater: Heater;
|
|
102
|
+
protected _pollTimer: NodeJS.Timeout = null;
|
|
103
|
+
protected _lastState;
|
|
104
|
+
protected closing = false;
|
|
105
|
+
protected bodyOnTime: number;
|
|
106
|
+
protected isOn: boolean = false;
|
|
107
|
+
protected isCooling: boolean = false;
|
|
108
|
+
protected lastHeatCycle: Date;
|
|
109
|
+
protected lastCoolCycle: Date;
|
|
110
|
+
constructor(ncp: INixieControlPanel, heater: Heater) {
|
|
111
|
+
super(ncp);
|
|
112
|
+
this.heater = heater;
|
|
113
|
+
}
|
|
114
|
+
public get suspendPolling(): boolean { return this._suspendPolling > 0; }
|
|
115
|
+
public set suspendPolling(val: boolean) { this._suspendPolling = Math.max(0, this._suspendPolling + (val ? 1 : -1)); }
|
|
116
|
+
public get id(): number { return typeof this.heater !== 'undefined' ? this.heater.id : -1; }
|
|
117
|
+
public getCooldownTime() { return 0; }
|
|
118
|
+
public static create(ncp: INixieControlPanel, heater: Heater): NixieHeaterBase {
|
|
119
|
+
let type = sys.board.valueMaps.heaterTypes.transform(heater.type);
|
|
120
|
+
switch (type.name) {
|
|
121
|
+
case 'heatpump':
|
|
122
|
+
return new NixieHeatpump(ncp, heater);
|
|
123
|
+
case 'ultratemp':
|
|
124
|
+
return new NixieUltratemp(ncp, heater);
|
|
125
|
+
case 'gas':
|
|
126
|
+
return new NixieGasHeater(ncp, heater);
|
|
127
|
+
case 'mastertemp':
|
|
128
|
+
return new NixieMastertemp(ncp, heater);
|
|
129
|
+
case 'solar':
|
|
130
|
+
return new NixieSolarHeater(ncp, heater);
|
|
131
|
+
case 'hybrid':
|
|
132
|
+
return new NixieUltraTempETi(ncp, heater);
|
|
133
|
+
default:
|
|
134
|
+
return new NixieHeaterBase(ncp, heater);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
public isBodyOn() {
|
|
138
|
+
let isOn = sys.board.bodies.isBodyOn(this.heater.body);
|
|
139
|
+
if (isOn && typeof this.bodyOnTime === 'undefined') {
|
|
140
|
+
this.bodyOnTime = new Date().getTime();
|
|
141
|
+
}
|
|
142
|
+
else if (!isOn) this.bodyOnTime = undefined;
|
|
143
|
+
return isOn;
|
|
144
|
+
}
|
|
145
|
+
public async setHeaterStateAsync(hstate: HeaterState, isOn: boolean, isCooling: boolean) {
|
|
146
|
+
try {
|
|
147
|
+
return Promise.reject(new InvalidOperationError(`You cannot change the state on this type of heater ${hstate.name}`, 'setHeaterStateAsync'));
|
|
148
|
+
} catch (err) { return logger.error(`Nixie Error setting heater state ${hstate.id}-${hstate.name}: ${err.message}`); }
|
|
149
|
+
}
|
|
150
|
+
public async setHeaterAsync(data: any) {
|
|
151
|
+
try {
|
|
152
|
+
let heater = this.heater;
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
catch (err) { logger.error(`Nixie setHeaterAsync: ${err.message}`); return Promise.reject(err); }
|
|
156
|
+
}
|
|
157
|
+
public async closeAsync() { }
|
|
158
|
+
public async setServiceModeAsync() {
|
|
159
|
+
let hstate = state.heaters.getItemById(this.heater.id);
|
|
160
|
+
await this.setHeaterStateAsync(hstate, false, false);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export class NixieGasHeater extends NixieHeaterBase {
|
|
164
|
+
public pollingInterval: number = 10000;
|
|
165
|
+
//declare heater: Heater;
|
|
166
|
+
constructor(ncp: INixieControlPanel, heater: Heater) {
|
|
167
|
+
super(ncp, heater);
|
|
168
|
+
this.heater = heater;
|
|
169
|
+
if (typeof this.heater.stopTempDelta === 'undefined') this.heater.stopTempDelta = 1;
|
|
170
|
+
if (typeof this.heater.minCycleTime === 'undefined') this.heater.minCycleTime = 2;
|
|
171
|
+
this.pollEquipmentAsync();
|
|
172
|
+
}
|
|
173
|
+
public get id(): number { return typeof this.heater !== 'undefined' ? this.heater.id : -1; }
|
|
174
|
+
public getCooldownTime(): number {
|
|
175
|
+
// Delays are always in terms of seconds so convert the minute to seconds.
|
|
176
|
+
if (this.heater.cooldownDelay === 0 || typeof this.lastHeatCycle === 'undefined') return 0;
|
|
177
|
+
let now = new Date().getTime();
|
|
178
|
+
let cooldown = this.isOn ? this.heater.cooldownDelay * 60000 : Math.round(((this.lastHeatCycle.getDate() + this.heater.cooldownDelay * 60000) - now) / 1000);
|
|
179
|
+
return Math.min(Math.max(0, cooldown), this.heater.cooldownDelay * 60);
|
|
180
|
+
}
|
|
181
|
+
public async setHeaterStateAsync(hstate: HeaterState, isOn: boolean) {
|
|
182
|
+
try {
|
|
183
|
+
// Initialize the desired state.
|
|
184
|
+
this.isOn = isOn;
|
|
185
|
+
this.isCooling = false;
|
|
186
|
+
let target = hstate.startupDelay === false && isOn;
|
|
187
|
+
if (target && typeof hstate.endTime !== 'undefined') {
|
|
188
|
+
// Calculate a short cycle time so that the gas heater does not cycle
|
|
189
|
+
// too often. For gas heaters this is 60 seconds. This gives enough time
|
|
190
|
+
// for the heater control circuit to make a full cycle.
|
|
191
|
+
if (new Date().getTime() - hstate.endTime.getTime() < this.heater.minCycleTime * 60000) {
|
|
192
|
+
logger.verbose(`${hstate.name} short cycle detected deferring turn on state`);
|
|
193
|
+
target = false;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// Here we go we need to set the firemans switch state.
|
|
197
|
+
if (hstate.isOn !== target) {
|
|
198
|
+
logger.info(`Nixie: Set Heater ${hstate.id}-${hstate.name} to ${isOn}`);
|
|
199
|
+
}
|
|
200
|
+
if (typeof this._lastState === 'undefined' || target || this._lastState !== target) {
|
|
201
|
+
if (utils.isNullOrEmpty(this.heater.connectionId) || utils.isNullOrEmpty(this.heater.deviceBinding)) {
|
|
202
|
+
this._lastState = hstate.isOn = target;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
let res = await NixieEquipment.putDeviceService(this.heater.connectionId, `/state/device/${this.heater.deviceBinding}`,
|
|
206
|
+
{ isOn: target, latch: target ? 10000 : undefined });
|
|
207
|
+
if (res.status.code === 200) this._lastState = hstate.isOn = target;
|
|
208
|
+
else logger.error(`Nixie Error setting heater state: ${res.status.code} -${res.status.message} ${res.error.message}`);
|
|
209
|
+
}
|
|
210
|
+
if (target) this.lastHeatCycle = new Date();
|
|
211
|
+
}
|
|
212
|
+
} catch (err) { return logger.error(`Nixie Error setting heater state ${hstate.id}-${hstate.name}: ${err.message}`); }
|
|
213
|
+
}
|
|
214
|
+
public async pollEquipmentAsync() {
|
|
215
|
+
let self = this;
|
|
216
|
+
try {
|
|
217
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
218
|
+
this._pollTimer = null;
|
|
219
|
+
let success = false;
|
|
220
|
+
}
|
|
221
|
+
catch (err) { logger.error(`Nixie Error polling Heater - ${err}`); }
|
|
222
|
+
finally { this._pollTimer = setTimeout(async () => await self.pollEquipmentAsync(), this.pollingInterval || 10000); }
|
|
223
|
+
}
|
|
224
|
+
private async checkHardwareStatusAsync(connectionId: string, deviceBinding: string) {
|
|
225
|
+
try {
|
|
226
|
+
let dev = await NixieEquipment.getDeviceService(connectionId, `/status/device/${deviceBinding}`);
|
|
227
|
+
return dev;
|
|
228
|
+
} catch (err) { logger.error(`Nixie Heater Error checkHardwareStatusAsync: ${err.message}`); return { hasFault: true } }
|
|
229
|
+
}
|
|
230
|
+
public async validateSetupAsync(heater: Heater, hstate: HeaterState) {
|
|
231
|
+
try {
|
|
232
|
+
if (typeof heater.connectionId !== 'undefined' && heater.connectionId !== ''
|
|
233
|
+
&& typeof heater.deviceBinding !== 'undefined' && heater.deviceBinding !== '') {
|
|
234
|
+
try {
|
|
235
|
+
let stat = await this.checkHardwareStatusAsync(heater.connectionId, heater.deviceBinding);
|
|
236
|
+
// If we have a status check the return.
|
|
237
|
+
hstate.commStatus = stat.hasFault ? 1 : 0;
|
|
238
|
+
} catch (err) { hstate.commStatus = 1; }
|
|
239
|
+
}
|
|
240
|
+
else
|
|
241
|
+
hstate.commStatus = 0;
|
|
242
|
+
} catch (err) { logger.error(`Nixie Error checking heater Hardware ${this.heater.name}: ${err.message}`); hstate.commStatus = 1; return Promise.reject(err); }
|
|
243
|
+
}
|
|
244
|
+
public async closeAsync() {
|
|
245
|
+
try {
|
|
246
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
247
|
+
this._pollTimer = null;
|
|
248
|
+
let hstate = state.heaters.getItemById(this.heater.id);
|
|
249
|
+
await this.setHeaterStateAsync(hstate, false);
|
|
250
|
+
hstate.emitEquipmentChange();
|
|
251
|
+
}
|
|
252
|
+
catch (err) { logger.error(`Nixie Heater closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
253
|
+
}
|
|
254
|
+
public logData(filename: string, data: any) { this.controlPanel.logData(filename, data); }
|
|
255
|
+
}
|
|
256
|
+
export class NixieSolarHeater extends NixieHeaterBase {
|
|
257
|
+
public pollingInterval: number = 10000;
|
|
258
|
+
declare heater: Heater;
|
|
259
|
+
constructor(ncp: INixieControlPanel, heater: Heater) {
|
|
260
|
+
super(ncp, heater);
|
|
261
|
+
this.heater = heater;
|
|
262
|
+
this.pollEquipmentAsync();
|
|
263
|
+
}
|
|
264
|
+
public get id(): number { return typeof this.heater !== 'undefined' ? this.heater.id : -1; }
|
|
265
|
+
public async setHeaterStateAsync(hstate: HeaterState, isOn: boolean, isCooling: boolean) {
|
|
266
|
+
try {
|
|
267
|
+
let origState = hstate.isOn;
|
|
268
|
+
// Initialize the desired state.
|
|
269
|
+
this.isOn = isOn;
|
|
270
|
+
this.isCooling = isCooling;
|
|
271
|
+
let target = hstate.startupDelay === false && isOn;
|
|
272
|
+
if (target && typeof hstate.endTime !== 'undefined') {
|
|
273
|
+
// Calculate a short cycle time so that the solar heater does not cycle
|
|
274
|
+
// too often. For solar heaters this is 60 seconds. This gives enough time
|
|
275
|
+
// for the valve to rotate and start heating. If the solar and water sensors are
|
|
276
|
+
// not having issues this should be plenty of time.
|
|
277
|
+
if (new Date().getTime() - hstate.endTime.getTime() < 60000) {
|
|
278
|
+
logger.verbose(`${hstate.name} short cycle detected deferring turn on state`);
|
|
279
|
+
target = false;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Here we go we need to set the valve status that is attached to solar.
|
|
284
|
+
if (hstate.isOn !== target) {
|
|
285
|
+
logger.info(`Nixie: Set Heater ${hstate.id}-${hstate.name} to ${isOn}`);
|
|
286
|
+
}
|
|
287
|
+
if (typeof this._lastState === 'undefined' || target || this._lastState !== target) {
|
|
288
|
+
if (utils.isNullOrEmpty(this.heater.connectionId) || utils.isNullOrEmpty(this.heater.deviceBinding)) {
|
|
289
|
+
this._lastState = hstate.isOn = target;
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
let res = await NixieEquipment.putDeviceService(this.heater.connectionId, `/state/device/${this.heater.deviceBinding}`,
|
|
293
|
+
{ isOn: target, latch: target ? 10000 : undefined });
|
|
294
|
+
if (res.status.code === 200) this._lastState = hstate.isOn = target;
|
|
295
|
+
else logger.error(`Nixie Error setting heater state: ${res.status.code} -${res.status.message} ${res.error.message}`);
|
|
296
|
+
}
|
|
297
|
+
if (target) {
|
|
298
|
+
if (isCooling) this.lastCoolCycle = new Date();
|
|
299
|
+
else if (isOn) this.lastHeatCycle = new Date();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// In this instance we need to see if there are cleaner circuits that we need to turn off
|
|
303
|
+
// then delay for the current body because the solar just came on.
|
|
304
|
+
if (hstate.isOn && sys.general.options.cleanerSolarDelay && !origState) {
|
|
305
|
+
let arrTypes = sys.board.valueMaps.circuitFunctions.toArray().filter(x => { return x.name.indexOf('cleaner') !== -1 && x.body === hstate.bodyId });
|
|
306
|
+
let cleaners = sys.circuits.filter(x => { return arrTypes.findIndex(t => { return t.val === x.type }) !== -1 });
|
|
307
|
+
// Turn off all the cleaner circuits and set an on delay if they are on.
|
|
308
|
+
for (let i = 0; i < cleaners.length; i++) {
|
|
309
|
+
let cleaner = cleaners.getItemByIndex(i);
|
|
310
|
+
if (cleaner.isActive) {
|
|
311
|
+
let cstate = state.circuits.getItemById(cleaner.id);
|
|
312
|
+
if (cstate.isOn && sys.general.options.cleanerSolarDelayTime > 0) {
|
|
313
|
+
// Turn off the circuit then set a delay.
|
|
314
|
+
logger.info(`Setting cleaner solar delay for ${cleaner.name} to ${sys.general.options.cleanerSolarDelayTime}`);
|
|
315
|
+
await sys.board.circuits.setCircuitStateAsync(cstate.id, false);
|
|
316
|
+
delayMgr.setCleanerStartDelay(cstate, hstate.bodyId, sys.general.options.cleanerSolarDelayTime);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
} catch (err) { return logger.error(`Nixie Error setting heater state ${hstate.id}-${hstate.name}: ${err.message}`); }
|
|
322
|
+
}
|
|
323
|
+
public async pollEquipmentAsync() {
|
|
324
|
+
let self = this;
|
|
325
|
+
try {
|
|
326
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
327
|
+
this._pollTimer = null;
|
|
328
|
+
let success = false;
|
|
329
|
+
}
|
|
330
|
+
catch (err) { logger.error(`Nixie Error polling Heater - ${err}`); }
|
|
331
|
+
finally { this._pollTimer = setTimeout(async () => await self.pollEquipmentAsync(), this.pollingInterval || 10000); }
|
|
332
|
+
}
|
|
333
|
+
private async checkHardwareStatusAsync(connectionId: string, deviceBinding: string) {
|
|
334
|
+
try {
|
|
335
|
+
let dev = await NixieEquipment.getDeviceService(connectionId, `/status/device/${deviceBinding}`);
|
|
336
|
+
return dev;
|
|
337
|
+
} catch (err) { logger.error(`Nixie Heater Error checkHardwareStatusAsync: ${err.message}`); return { hasFault: true } }
|
|
338
|
+
}
|
|
339
|
+
public async validateSetupAsync(heater: Heater, hstate: HeaterState) {
|
|
340
|
+
try {
|
|
341
|
+
if (typeof heater.connectionId !== 'undefined' && heater.connectionId !== ''
|
|
342
|
+
&& typeof heater.deviceBinding !== 'undefined' && heater.deviceBinding !== '') {
|
|
343
|
+
try {
|
|
344
|
+
let stat = await this.checkHardwareStatusAsync(heater.connectionId, heater.deviceBinding);
|
|
345
|
+
// If we have a status check the return.
|
|
346
|
+
hstate.commStatus = stat.hasFault ? 1 : 0;
|
|
347
|
+
} catch (err) { hstate.commStatus = 1; }
|
|
348
|
+
}
|
|
349
|
+
else
|
|
350
|
+
hstate.commStatus = 0;
|
|
351
|
+
} catch (err) { logger.error(`Nixie Error checking heater Hardware ${this.heater.name}: ${err.message}`); hstate.commStatus = 1; return Promise.reject(err); }
|
|
352
|
+
}
|
|
353
|
+
public async closeAsync() {
|
|
354
|
+
try {
|
|
355
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
356
|
+
this._pollTimer = null;
|
|
357
|
+
let hstate = state.heaters.getItemById(this.heater.id);
|
|
358
|
+
await this.setHeaterStateAsync(hstate, false, false);
|
|
359
|
+
hstate.emitEquipmentChange();
|
|
360
|
+
}
|
|
361
|
+
catch (err) { logger.error(`Nixie Heater closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
362
|
+
}
|
|
363
|
+
public logData(filename: string, data: any) { this.controlPanel.logData(filename, data); }
|
|
364
|
+
}
|
|
365
|
+
export class NixieHeatpump extends NixieHeaterBase {
|
|
366
|
+
public pollingInterval: number = 10000;
|
|
367
|
+
//declare heater: Heater;
|
|
368
|
+
constructor(ncp: INixieControlPanel, heater: Heater) {
|
|
369
|
+
super(ncp, heater);
|
|
370
|
+
this.heater = heater;
|
|
371
|
+
if (typeof this.heater.stopTempDelta === 'undefined') this.heater.stopTempDelta = 1;
|
|
372
|
+
if (typeof this.heater.minCycleTime === 'undefined') this.heater.minCycleTime = 2;
|
|
373
|
+
this.pollEquipmentAsync();
|
|
374
|
+
}
|
|
375
|
+
public get id(): number { return typeof this.heater !== 'undefined' ? this.heater.id : -1; }
|
|
376
|
+
public getCooldownTime(): number { return 0; } // There is no cooldown delay at this time for a heatpump
|
|
377
|
+
public async setHeaterStateAsync(hstate: HeaterState, isOn: boolean) {
|
|
378
|
+
try {
|
|
379
|
+
// Initialize the desired state.
|
|
380
|
+
this.isOn = isOn;
|
|
381
|
+
this.isCooling = false;
|
|
382
|
+
let target = hstate.startupDelay === false && isOn;
|
|
383
|
+
if (target && typeof hstate.endTime !== 'undefined') {
|
|
384
|
+
// Calculate a short cycle time so that the gas heater does not cycle
|
|
385
|
+
// too often. For gas heaters this is 60 seconds. This gives enough time
|
|
386
|
+
// for the heater control circuit to make a full cycle.
|
|
387
|
+
if (new Date().getTime() - hstate.endTime.getTime() < this.heater.minCycleTime * 60000) {
|
|
388
|
+
logger.verbose(`${hstate.name} short cycle detected deferring turn on state`);
|
|
389
|
+
target = false;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
// Here we go we need to set the firemans switch state.
|
|
393
|
+
if (hstate.isOn !== target) {
|
|
394
|
+
logger.info(`Nixie: Set Heatpump ${hstate.id}-${hstate.name} to ${isOn}`);
|
|
395
|
+
}
|
|
396
|
+
if (typeof this._lastState === 'undefined' || target || this._lastState !== target) {
|
|
397
|
+
if (utils.isNullOrEmpty(this.heater.connectionId) || utils.isNullOrEmpty(this.heater.deviceBinding)) {
|
|
398
|
+
this._lastState = hstate.isOn = target;
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
let res = await NixieEquipment.putDeviceService(this.heater.connectionId, `/state/device/${this.heater.deviceBinding}`,
|
|
402
|
+
{ isOn: target, latch: target ? 10000 : undefined });
|
|
403
|
+
if (res.status.code === 200) this._lastState = hstate.isOn = target;
|
|
404
|
+
else logger.error(`Nixie Error setting heatpump state: ${res.status.code} -${res.status.message} ${res.error.message}`);
|
|
405
|
+
}
|
|
406
|
+
if (target) this.lastHeatCycle = new Date();
|
|
407
|
+
}
|
|
408
|
+
} catch (err) { return logger.error(`Nixie Error setting heatpump state ${hstate.id}-${hstate.name}: ${err.message}`); }
|
|
409
|
+
}
|
|
410
|
+
public async pollEquipmentAsync() {
|
|
411
|
+
let self = this;
|
|
412
|
+
try {
|
|
413
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
414
|
+
this._pollTimer = null;
|
|
415
|
+
let success = false;
|
|
416
|
+
}
|
|
417
|
+
catch (err) { logger.error(`Nixie Error polling Heatpump - ${err}`); }
|
|
418
|
+
finally { this._pollTimer = setTimeout(async () => await self.pollEquipmentAsync(), this.pollingInterval || 10000); }
|
|
419
|
+
}
|
|
420
|
+
private async checkHardwareStatusAsync(connectionId: string, deviceBinding: string) {
|
|
421
|
+
try {
|
|
422
|
+
let dev = await NixieEquipment.getDeviceService(connectionId, `/status/device/${deviceBinding}`);
|
|
423
|
+
return dev;
|
|
424
|
+
} catch (err) { logger.error(`Nixie Heatpump Error checkHardwareStatusAsync: ${err.message}`); return { hasFault: true } }
|
|
425
|
+
}
|
|
426
|
+
public async validateSetupAsync(heater: Heater, hstate: HeaterState) {
|
|
427
|
+
try {
|
|
428
|
+
if (typeof heater.connectionId !== 'undefined' && heater.connectionId !== ''
|
|
429
|
+
&& typeof heater.deviceBinding !== 'undefined' && heater.deviceBinding !== '') {
|
|
430
|
+
try {
|
|
431
|
+
let stat = await this.checkHardwareStatusAsync(heater.connectionId, heater.deviceBinding);
|
|
432
|
+
// If we have a status check the return.
|
|
433
|
+
hstate.commStatus = stat.hasFault ? 1 : 0;
|
|
434
|
+
} catch (err) { hstate.commStatus = 1; }
|
|
435
|
+
}
|
|
436
|
+
else
|
|
437
|
+
hstate.commStatus = 0;
|
|
438
|
+
} catch (err) { logger.error(`Nixie Error checking heatpump Hardware ${this.heater.name}: ${err.message}`); hstate.commStatus = 1; return Promise.reject(err); }
|
|
439
|
+
}
|
|
440
|
+
public async closeAsync() {
|
|
441
|
+
try {
|
|
442
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
443
|
+
this._pollTimer = null;
|
|
444
|
+
let hstate = state.heaters.getItemById(this.heater.id);
|
|
445
|
+
await this.setHeaterStateAsync(hstate, false);
|
|
446
|
+
hstate.emitEquipmentChange();
|
|
447
|
+
}
|
|
448
|
+
catch (err) { logger.error(`Nixie Heatpump closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
449
|
+
}
|
|
450
|
+
public logData(filename: string, data: any) { this.controlPanel.logData(filename, data); }
|
|
451
|
+
}
|
|
452
|
+
export class NixieUltratemp extends NixieHeaterBase {
|
|
453
|
+
constructor(ncp: INixieControlPanel, heater: Heater) {
|
|
454
|
+
super(ncp, heater);
|
|
455
|
+
// Set the polling interval to 3 seconds.
|
|
456
|
+
this.pollEquipmentAsync();
|
|
457
|
+
}
|
|
458
|
+
public async setServiceModeAsync() {
|
|
459
|
+
let hstate = state.heaters.getItemById(this.heater.id);
|
|
460
|
+
await this.setHeaterStateAsync(hstate, false, false);
|
|
461
|
+
await this.releaseHeater(hstate);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
public async pollEquipmentAsync() {
|
|
465
|
+
let self = this;
|
|
466
|
+
try {
|
|
467
|
+
this.suspendPolling = true;
|
|
468
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
469
|
+
this._pollTimer = null;
|
|
470
|
+
if (this._suspendPolling > 1) return;
|
|
471
|
+
let sheater = state.heaters.getItemById(this.heater.id, !this.closing);
|
|
472
|
+
// If the body isn't on then we won't communicate with the chem controller. There is no need
|
|
473
|
+
// since most of the time these are attached to the filter relay.
|
|
474
|
+
if (!this.closing) {
|
|
475
|
+
await this.setStatus(sheater);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
catch (err) { logger.error(`Error polling UltraTemp heater - ${err}`); }
|
|
479
|
+
finally {
|
|
480
|
+
this.suspendPolling = false; if (!this.closing) this._pollTimer = setTimeout(async () => {
|
|
481
|
+
try { await self.pollEquipmentAsync() } catch (err) { }
|
|
482
|
+
}, this.pollingInterval || 10000);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
public async setHeaterStateAsync(hstate: HeaterState, isOn: boolean, isCooling: boolean) {
|
|
486
|
+
try {
|
|
487
|
+
// Initialize the desired state.
|
|
488
|
+
this.isCooling = isCooling;
|
|
489
|
+
if (hstate.isOn !== isOn) {
|
|
490
|
+
logger.info(`Nixie: Set Heater ${hstate.id}-${hstate.name} to ${isCooling ? 'cooling' : isOn ? 'heating' : 'off'}`);
|
|
491
|
+
|
|
492
|
+
}
|
|
493
|
+
if (isOn && !hstate.startupDelay) this.lastHeatCycle = new Date();
|
|
494
|
+
this.isOn = hstate.isOn = isOn;
|
|
495
|
+
} catch (err) { return logger.error(`Nixie Error setting heater state ${hstate.id}-${hstate.name}: ${err.message}`); }
|
|
496
|
+
}
|
|
497
|
+
public async releaseHeater(sheater: HeaterState): Promise<boolean> {
|
|
498
|
+
try {
|
|
499
|
+
let out = Outbound.create({
|
|
500
|
+
portId: this.heater.portId || 0,
|
|
501
|
+
protocol: Protocol.Heater,
|
|
502
|
+
source: 16,
|
|
503
|
+
dest: this.heater.address,
|
|
504
|
+
action: 114,
|
|
505
|
+
payload: [],
|
|
506
|
+
retries: 3, // We are going to try 4 times.
|
|
507
|
+
response: Response.create({ protocol: Protocol.Heater, action: 115 }),
|
|
508
|
+
onAbort: () => { }
|
|
509
|
+
});
|
|
510
|
+
out.appendPayloadBytes(0, 10);
|
|
511
|
+
out.setPayloadByte(0, 144);
|
|
512
|
+
out.setPayloadByte(1, 0, 0);
|
|
513
|
+
await out.sendAsync();
|
|
514
|
+
return true;
|
|
515
|
+
|
|
516
|
+
} catch (err) {
|
|
517
|
+
// If the Ultratemp is not responding we need to store that off but at this point we know none of the codes. If a 115 does
|
|
518
|
+
// come across this will be cleared by the processing of that message.
|
|
519
|
+
sheater.commStatus = sys.board.valueMaps.equipmentCommStatus.getValue('commerr');
|
|
520
|
+
state.equipment.messages.setMessageByCode(`heater:${sheater.id}:comms`, 'error', `Communication error with ${sheater.name}`);
|
|
521
|
+
logger.error(`Communication error with Ultratemp : ${err.message}`);
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
public async setStatus(sheater: HeaterState): Promise<boolean> {
|
|
526
|
+
try {
|
|
527
|
+
let out = Outbound.create({
|
|
528
|
+
portId: this.heater.portId || 0,
|
|
529
|
+
protocol: Protocol.Heater,
|
|
530
|
+
source: 16,
|
|
531
|
+
dest: this.heater.address,
|
|
532
|
+
action: 114,
|
|
533
|
+
payload: [],
|
|
534
|
+
retries: 3, // We are going to try 4 times.
|
|
535
|
+
response: Response.create({ protocol: Protocol.Heater, action: 115 }),
|
|
536
|
+
onAbort: () => { }
|
|
537
|
+
});
|
|
538
|
+
out.appendPayloadBytes(0, 10);
|
|
539
|
+
out.setPayloadByte(0, 144);
|
|
540
|
+
// If we are in startup delay simply tell the heater that it is off.
|
|
541
|
+
if (sheater.startupDelay || this.closing)
|
|
542
|
+
out.setPayloadByte(1, 0, 0);
|
|
543
|
+
else {
|
|
544
|
+
if (this.isOn) {
|
|
545
|
+
if (!this.isCooling) this.lastHeatCycle = new Date();
|
|
546
|
+
else this.lastCoolCycle = new Date();
|
|
547
|
+
}
|
|
548
|
+
//console.log(`Setting the heater byte ${this.isOn} ${sheater.isOn} to ${this.isOn ? (this.isCooling ? 2 : 1) : 0}`);
|
|
549
|
+
out.setPayloadByte(1, this.isOn ? (this.isCooling ? 2 : 1) : 0, 0);
|
|
550
|
+
}
|
|
551
|
+
let success = await out.sendAsync();
|
|
552
|
+
return success;
|
|
553
|
+
} catch (err) {
|
|
554
|
+
// If the Ultratemp is not responding we need to store that off but at this point we know none of the codes. If a 115 does
|
|
555
|
+
// come across this will be cleared by the processing of that message.
|
|
556
|
+
sheater.commStatus = sys.board.valueMaps.equipmentCommStatus.getValue('commerr');
|
|
557
|
+
state.equipment.messages.setMessageByCode(`heater:${sheater.id}:comms`, 'error', `Communication error with ${sheater.name}`);
|
|
558
|
+
logger.error(`Communication error with Ultratemp : ${err.message}`);
|
|
559
|
+
return false;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
public async closeAsync() {
|
|
563
|
+
try {
|
|
564
|
+
this.suspendPolling = true;
|
|
565
|
+
this.closing = true;
|
|
566
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
567
|
+
this._pollTimer = null;
|
|
568
|
+
let sheater = state.heaters.getItemById(this.id);
|
|
569
|
+
await this.releaseHeater(sheater);
|
|
570
|
+
logger.info(`Closing Heater ${this.heater.name}`);
|
|
571
|
+
}
|
|
572
|
+
catch (err) { logger.error(`Ultratemp closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
export class NixieMastertemp extends NixieGasHeater {
|
|
576
|
+
constructor(ncp: INixieControlPanel, heater: Heater) {
|
|
577
|
+
super(ncp, heater);
|
|
578
|
+
// Set the polling interval to 3 seconds.
|
|
579
|
+
this.pollEquipmentAsync();
|
|
580
|
+
this.pollingInterval = 3000;
|
|
581
|
+
}
|
|
582
|
+
/* public getCooldownTime(): number {
|
|
583
|
+
// Delays are always in terms of seconds so convert the minute to seconds.
|
|
584
|
+
if (this.heater.cooldownDelay === 0 || typeof this.lastHeatCycle === 'undefined') return 0;
|
|
585
|
+
let now = new Date().getTime();
|
|
586
|
+
let cooldown = this.isOn ? this.heater.cooldownDelay * 60000 : Math.round(((this.lastHeatCycle.getDate() + this.heater.cooldownDelay * 60000) - now) / 1000);
|
|
587
|
+
return Math.min(Math.max(0, cooldown), this.heater.cooldownDelay * 60);
|
|
588
|
+
} */
|
|
589
|
+
public async setHeaterStateAsync(hstate: HeaterState, isOn: boolean) {
|
|
590
|
+
try {
|
|
591
|
+
// Initialize the desired state.
|
|
592
|
+
this.isCooling = false;
|
|
593
|
+
// Here we go we need to set the firemans switch state.
|
|
594
|
+
if (hstate.isOn !== isOn) {
|
|
595
|
+
logger.info(`Nixie: Set Heater ${hstate.id}-${hstate.name} to ${isOn}`);
|
|
596
|
+
}
|
|
597
|
+
if (isOn && !hstate.startupDelay) this.lastHeatCycle = new Date();
|
|
598
|
+
hstate.isOn = isOn;
|
|
599
|
+
} catch (err) { return logger.error(`Nixie Error setting heater state ${hstate.id}-${hstate.name}: ${err.message}`); }
|
|
600
|
+
}
|
|
601
|
+
public async pollEquipmentAsync() {
|
|
602
|
+
let self = this;
|
|
603
|
+
try {
|
|
604
|
+
this.suspendPolling = true;
|
|
605
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
606
|
+
this._pollTimer = null;
|
|
607
|
+
if (this._suspendPolling > 1) return;
|
|
608
|
+
let sheater = state.heaters.getItemById(this.heater.id, !this.closing);
|
|
609
|
+
if (!this.closing) await this.setStatus(sheater);
|
|
610
|
+
}
|
|
611
|
+
catch (err) { logger.error(`Error polling MasterTemp heater - ${err}`); }
|
|
612
|
+
finally {
|
|
613
|
+
this.suspendPolling = false; if (!this.closing) this._pollTimer = setTimeout(async () => {
|
|
614
|
+
try { await self.pollEquipmentAsync() } catch (err) { }
|
|
615
|
+
}, this.pollingInterval || 3000);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
public async setStatus(sheater: HeaterState): Promise<boolean> {
|
|
619
|
+
try {
|
|
620
|
+
let out = Outbound.create({
|
|
621
|
+
portId: this.heater.portId || 0,
|
|
622
|
+
protocol: Protocol.Heater,
|
|
623
|
+
source: 16,
|
|
624
|
+
dest: this.heater.address,
|
|
625
|
+
action: 112,
|
|
626
|
+
payload: [],
|
|
627
|
+
retries: 3, // We are going to try 4 times.
|
|
628
|
+
response: Response.create({ protocol: Protocol.Heater, action: 116 }),
|
|
629
|
+
onAbort: () => { }
|
|
630
|
+
});
|
|
631
|
+
out.appendPayloadBytes(0, 11);
|
|
632
|
+
// If we have a startup delay we need to simply send 0 to the heater to make sure that it is off.
|
|
633
|
+
if (sheater.startupDelay)
|
|
634
|
+
out.setPayloadByte(0, 0);
|
|
635
|
+
else {
|
|
636
|
+
// The cooldown delay is a bit hard to figure out here since I think the heater does it on its own.
|
|
637
|
+
out.setPayloadByte(0, sheater.bodyId <= 2 ? sheater.bodyId : 0);
|
|
638
|
+
}
|
|
639
|
+
out.setPayloadByte(1, sys.bodies.getItemById(1).heatSetpoint || 0);
|
|
640
|
+
out.setPayloadByte(2, sys.bodies.getItemById(2).heatSetpoint || 0);
|
|
641
|
+
let success = await out.sendAsync();
|
|
642
|
+
return success;
|
|
643
|
+
} catch (err) {
|
|
644
|
+
// If the MasterTemp is not responding we need to store that off but at this point we know none of the codes. If a 115 does
|
|
645
|
+
// come across this will be cleared by the processing of that message.
|
|
646
|
+
sheater.commStatus = sys.board.valueMaps.equipmentCommStatus.getValue('commerr');
|
|
647
|
+
state.equipment.messages.setMessageByCode(`heater:${sheater.id}:comms`, 'error', `Communication error with ${sheater.name}`);
|
|
648
|
+
logger.error(`Communication error with MasterTemp : ${err.message}`);
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
public async setServiceModeAsync() {
|
|
653
|
+
let hstate = state.heaters.getItemById(this.heater.id);
|
|
654
|
+
await this.setHeaterStateAsync(hstate, false);
|
|
655
|
+
}
|
|
656
|
+
public async closeAsync() {
|
|
657
|
+
try {
|
|
658
|
+
this.suspendPolling = true;
|
|
659
|
+
this.closing = true;
|
|
660
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
661
|
+
this._pollTimer = null;
|
|
662
|
+
logger.info(`Closing Heater ${this.heater.name}`);
|
|
663
|
+
|
|
664
|
+
}
|
|
665
|
+
catch (err) { logger.error(`MasterTemp closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
export class NixieUltraTempETi extends NixieHeaterBase {
|
|
669
|
+
constructor(ncp: INixieControlPanel, heater: Heater) {
|
|
670
|
+
super(ncp, heater);
|
|
671
|
+
// Set the polling interval to 3 seconds.
|
|
672
|
+
this.pollEquipmentAsync();
|
|
673
|
+
}
|
|
674
|
+
public async pollEquipmentAsync() {
|
|
675
|
+
let self = this;
|
|
676
|
+
try {
|
|
677
|
+
this.suspendPolling = true;
|
|
678
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
679
|
+
this._pollTimer = null;
|
|
680
|
+
if (this._suspendPolling > 1) return;
|
|
681
|
+
let sheater = state.heaters.getItemById(this.heater.id, !this.closing);
|
|
682
|
+
// If the body isn't on then we won't communicate with the chem controller. There is no need
|
|
683
|
+
// since most of the time these are attached to the filter relay.
|
|
684
|
+
if (!this.closing) {
|
|
685
|
+
await this.setStatus(sheater);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
catch (err) { logger.error(`Error polling UltraTemp ETi heater - ${err}`); }
|
|
689
|
+
finally {
|
|
690
|
+
this.suspendPolling = false; if (!this.closing) this._pollTimer = setTimeout(async () => {
|
|
691
|
+
try { await self.pollEquipmentAsync() } catch (err) { }
|
|
692
|
+
}, this.pollingInterval || 10000);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
public async setHeaterStateAsync(hstate: HeaterState, isOn: boolean, isCooling: boolean) {
|
|
696
|
+
try {
|
|
697
|
+
// Initialize the desired state.
|
|
698
|
+
this.isCooling = isCooling;
|
|
699
|
+
if (hstate.isOn !== isOn) {
|
|
700
|
+
logger.info(`Nixie: Set Heater ${hstate.id}-${hstate.name} to ${isCooling ? 'cooling' : isOn ? 'heating' : 'off'}`);
|
|
701
|
+
|
|
702
|
+
}
|
|
703
|
+
if (isOn && !hstate.startupDelay) this.lastHeatCycle = new Date();
|
|
704
|
+
this.isOn = hstate.isOn = isOn;
|
|
705
|
+
} catch (err) { return logger.error(`Nixie Error setting heater state ${hstate.id}-${hstate.name}: ${err.message}`); }
|
|
706
|
+
}
|
|
707
|
+
public async releaseHeater(sheater: HeaterState): Promise<boolean> {
|
|
708
|
+
try {
|
|
709
|
+
let out = Outbound.create({
|
|
710
|
+
portId: this.heater.portId || 0,
|
|
711
|
+
protocol: Protocol.Heater,
|
|
712
|
+
source: 16,
|
|
713
|
+
dest: this.heater.address,
|
|
714
|
+
action: 112,
|
|
715
|
+
payload: [],
|
|
716
|
+
retries: 3, // We are going to try 4 times.
|
|
717
|
+
response: Response.create({ protocol: Protocol.Heater, action: 113 }),
|
|
718
|
+
onAbort: () => { }
|
|
719
|
+
});
|
|
720
|
+
out.appendPayloadBytes(0, 10);
|
|
721
|
+
out.setPayloadByte(0, 0);
|
|
722
|
+
out.setPayloadByte(1, 0);
|
|
723
|
+
out.setPayloadByte(2, 78);
|
|
724
|
+
out.setPayloadByte(3, 1);
|
|
725
|
+
out.setPayloadByte(4, 5);
|
|
726
|
+
let success = await out.sendAsync();
|
|
727
|
+
return success;
|
|
728
|
+
} catch (err) {
|
|
729
|
+
// If the Ultratemp is not responding we need to store that off but at this point we know none of the codes. If a 113 does
|
|
730
|
+
// come across this will be cleared by the processing of that message.
|
|
731
|
+
sheater.commStatus = sys.board.valueMaps.equipmentCommStatus.getValue('commerr');
|
|
732
|
+
state.equipment.messages.setMessageByCode(`heater:${sheater.id}:comms`, 'error', `Communication error with ${sheater.name}`);
|
|
733
|
+
logger.error(`Communication error with Ultratemp : ${err.message}`);
|
|
734
|
+
return false;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
protected calcHeatModeByte(body: Body): number {
|
|
738
|
+
let byte = 0;
|
|
739
|
+
if (this.closing) return 0; // We are closing so just set the heat mode to off.
|
|
740
|
+
let mode = sys.board.valueMaps.heatModes.transform(body.heatMode || 0);
|
|
741
|
+
switch (mode.name) {
|
|
742
|
+
case 'hpump':
|
|
743
|
+
case 'heatpump':
|
|
744
|
+
byte = 1;
|
|
745
|
+
break;
|
|
746
|
+
case 'heater':
|
|
747
|
+
byte = 2;
|
|
748
|
+
break;
|
|
749
|
+
case 'heatpumpref':
|
|
750
|
+
case 'heatpumppref':
|
|
751
|
+
case 'hybrid':
|
|
752
|
+
byte = 3;
|
|
753
|
+
break;
|
|
754
|
+
case 'dual':
|
|
755
|
+
byte = 4;
|
|
756
|
+
break;
|
|
757
|
+
}
|
|
758
|
+
return byte;
|
|
759
|
+
}
|
|
760
|
+
public async setServiceModeAsync() {
|
|
761
|
+
let hstate = state.heaters.getItemById(this.heater.id);
|
|
762
|
+
await this.setHeaterStateAsync(hstate, false, false);
|
|
763
|
+
await this.releaseHeater(hstate);
|
|
764
|
+
}
|
|
765
|
+
public async setStatus(sheater: HeaterState): Promise<boolean> {
|
|
766
|
+
try {
|
|
767
|
+
let out = Outbound.create({
|
|
768
|
+
portId: this.heater.portId || 0,
|
|
769
|
+
protocol: Protocol.Heater,
|
|
770
|
+
source: 16,
|
|
771
|
+
dest: this.heater.address,
|
|
772
|
+
action: 112,
|
|
773
|
+
payload: [],
|
|
774
|
+
retries: 3, // We are going to try 4 times.
|
|
775
|
+
response: Response.create({ protocol: Protocol.Heater, action: 113 }),
|
|
776
|
+
onAbort: () => { }
|
|
777
|
+
});
|
|
778
|
+
out.appendPayloadBytes(0, 10);
|
|
779
|
+
out.setPayloadByte(0, this.isOn && !sheater.startupDelay && !this.closing ? 1 : 0);
|
|
780
|
+
if (sheater.bodyId > 0) {
|
|
781
|
+
let body = sys.bodies.getItemById(sheater.bodyId);
|
|
782
|
+
out.setPayloadByte(1, this.calcHeatModeByte(body));
|
|
783
|
+
out.setPayloadByte(2, body.setPoint);
|
|
784
|
+
}
|
|
785
|
+
else out.setPayloadByte(2, utils.convert.temperature.convertUnits(78, 'F', sys.board.valueMaps.tempUnits.getName(state.temps.units) || 'F')); // Just set it to a valid setpoint and call it a day.
|
|
786
|
+
out.setPayloadByte(3, this.heater.economyTime, 1);
|
|
787
|
+
out.setPayloadByte(4, this.heater.maxBoostTemp, 5);
|
|
788
|
+
if (this.isOn) {
|
|
789
|
+
if (!this.isCooling) this.lastHeatCycle = new Date();
|
|
790
|
+
else this.lastCoolCycle = new Date();
|
|
791
|
+
}
|
|
792
|
+
let success = await out.sendAsync();
|
|
793
|
+
return success;
|
|
794
|
+
} catch (err) {
|
|
795
|
+
// If the Ultratemp ETi is not responding we need to store that off but at this point we know none of the codes. If a 113 does
|
|
796
|
+
// come across this will be cleared by the processing of that message.
|
|
797
|
+
sheater.commStatus = sys.board.valueMaps.equipmentCommStatus.getValue('commerr');
|
|
798
|
+
state.equipment.messages.setMessageByCode(`heater:${sheater.id}:comms`, 'error', `Communication error with ${sheater.name}`);
|
|
799
|
+
logger.error(`Communication error with Ultratemp ETi : ${err.message}`);
|
|
800
|
+
return false;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
public async closeAsync() {
|
|
804
|
+
try {
|
|
805
|
+
this.suspendPolling = true;
|
|
806
|
+
this.closing = true;
|
|
807
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
808
|
+
this._pollTimer = null;
|
|
809
|
+
let sheater = state.heaters.getItemById(this.id);
|
|
810
|
+
await this.releaseHeater(sheater);
|
|
811
|
+
logger.info(`Closing Heater ${this.heater.name}`);
|
|
812
|
+
}
|
|
813
|
+
catch (err) { logger.error(`Ultratemp closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
814
|
+
}
|
|
815
|
+
}
|