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,104 +1,105 @@
|
|
|
1
|
-
import { webApp, REMInterfaceServer, InterfaceServerResponse } from "../../web/Server";
|
|
2
|
-
import { logger } from "../../logger/Logger";
|
|
3
|
-
import e = require("express");
|
|
4
|
-
export interface INixieControlPanel {
|
|
5
|
-
getREMServers();
|
|
6
|
-
logData(file: string, data: any);
|
|
7
|
-
readLogFile(file: string);
|
|
8
|
-
}
|
|
9
|
-
export class NixieEquipment {
|
|
10
|
-
protected _pmap = new WeakSet();
|
|
11
|
-
//private _dataKey = { id: 'parent' };
|
|
12
|
-
constructor(ncp: INixieControlPanel) { this._pmap['ncp'] = ncp; }
|
|
13
|
-
public get controlPanel(): INixieControlPanel { return this._pmap['ncp']; }
|
|
14
|
-
public get id(): number { return -1; }
|
|
15
|
-
public static get isConnected(): boolean {
|
|
16
|
-
let servers = webApp.findServersByType("rem");
|
|
17
|
-
for (let i = 0; i < servers.length; i++) {
|
|
18
|
-
if (!servers[0].isConnected) return false;
|
|
19
|
-
}
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
public static async putDeviceService(uuid: string, url: string, data?: any, timeout: number = 3600): Promise<InterfaceServerResponse> {
|
|
23
|
-
try {
|
|
24
|
-
let result: InterfaceServerResponse;
|
|
25
|
-
let server = webApp.findServerByGuid(uuid);
|
|
26
|
-
if (typeof server === 'undefined')
|
|
27
|
-
return InterfaceServerResponse.createError(new Error(`Error sending device command: Server [${uuid}] not found.`));
|
|
28
|
-
if (!server.isConnected) {
|
|
29
|
-
logger.warn(`Cannot send PUT ${url} to ${server.name} server is not connected.`);
|
|
30
|
-
return InterfaceServerResponse.createError(new Error(`Error sending device command: [${server.name}] not connected.`));
|
|
31
|
-
}
|
|
32
|
-
if (server.type === 'rem') {
|
|
33
|
-
let rem = server as REMInterfaceServer;
|
|
34
|
-
result = await rem.putApiService(url, data, timeout);
|
|
35
|
-
// If the result code is > 200 we have an issue.
|
|
36
|
-
//if (result.status.code > 200 || result.status.code === -1)
|
|
37
|
-
// return Promise.reject(new Error(`putDeviceService: ${result.error.message}`));
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
catch (err) { return Promise.reject(err); }
|
|
42
|
-
}
|
|
43
|
-
public static async getDeviceService(uuid: string, url: string, data?: any, timeout:number = 3600): Promise<any> {
|
|
44
|
-
try {
|
|
45
|
-
let result: InterfaceServerResponse;
|
|
46
|
-
let server = webApp.findServerByGuid(uuid);
|
|
47
|
-
if (typeof server === 'undefined') return Promise.reject(new Error(`Error sending device command: Server [${uuid}] not found.`));
|
|
48
|
-
if (!server.isConnected) return Promise.reject(new Error(`Error sending device command: [${server.name}] not connected.`));
|
|
49
|
-
if (server.type === 'rem') {
|
|
50
|
-
let rem = server as REMInterfaceServer;
|
|
51
|
-
//console.log(`CALLING GET FROM GETDEVSER`);
|
|
52
|
-
|
|
53
|
-
result = await rem.getApiService(url, data, timeout);
|
|
54
|
-
//console.log(`RETURNING GET FROM GETDEVSER`);
|
|
55
|
-
// If the result code is > 200 we have an issue.
|
|
56
|
-
if (result.status.code > 200) return Promise.reject(new Error(`putDeviceService: ${result.error.message}`));
|
|
57
|
-
}
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
catch (err) { return Promise.reject(err); }
|
|
61
|
-
}
|
|
62
|
-
public async closeAsync() {
|
|
63
|
-
try {
|
|
64
|
-
}
|
|
65
|
-
catch (err) { logger.error(err); }
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
export class NixieChildEquipment extends NixieEquipment {
|
|
69
|
-
constructor(parent: NixieEquipment) {
|
|
70
|
-
super(parent.controlPanel);
|
|
71
|
-
this._pmap['parent'] = parent;
|
|
72
|
-
}
|
|
73
|
-
public getParent(): NixieEquipment { return this._pmap['parent']; }
|
|
74
|
-
}
|
|
75
|
-
export class NixieEquipmentCollection<T> extends Array<NixieEquipment> {
|
|
76
|
-
private _pmap = new WeakSet();
|
|
77
|
-
public get controlPanel(): INixieControlPanel { return this._pmap['ncp']; }
|
|
78
|
-
constructor(ncp: INixieControlPanel) {
|
|
79
|
-
super();
|
|
80
|
-
this._pmap['ncp'] = ncp;
|
|
81
|
-
}
|
|
82
|
-
public async removeById(id: number) {
|
|
83
|
-
try {
|
|
84
|
-
let ndx = this.findIndex(elem => elem.id === id);
|
|
85
|
-
if (ndx >= 0) {
|
|
86
|
-
let eq = this[ndx];
|
|
87
|
-
await eq.closeAsync();
|
|
88
|
-
this.splice(ndx, 1);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
//
|
|
103
|
-
|
|
1
|
+
import { webApp, REMInterfaceServer, InterfaceServerResponse } from "../../web/Server";
|
|
2
|
+
import { logger } from "../../logger/Logger";
|
|
3
|
+
import e = require("express");
|
|
4
|
+
export interface INixieControlPanel {
|
|
5
|
+
getREMServers();
|
|
6
|
+
logData(file: string, data: any);
|
|
7
|
+
readLogFile(file: string);
|
|
8
|
+
}
|
|
9
|
+
export class NixieEquipment {
|
|
10
|
+
protected _pmap = new WeakSet();
|
|
11
|
+
//private _dataKey = { id: 'parent' };
|
|
12
|
+
constructor(ncp: INixieControlPanel) { this._pmap['ncp'] = ncp; }
|
|
13
|
+
public get controlPanel(): INixieControlPanel { return this._pmap['ncp']; }
|
|
14
|
+
public get id(): number { return -1; }
|
|
15
|
+
public static get isConnected(): boolean {
|
|
16
|
+
let servers = webApp.findServersByType("rem");
|
|
17
|
+
for (let i = 0; i < servers.length; i++) {
|
|
18
|
+
if (!servers[0].isConnected) return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
public static async putDeviceService(uuid: string, url: string, data?: any, timeout: number = 3600): Promise<InterfaceServerResponse> {
|
|
23
|
+
try {
|
|
24
|
+
let result: InterfaceServerResponse;
|
|
25
|
+
let server = webApp.findServerByGuid(uuid);
|
|
26
|
+
if (typeof server === 'undefined')
|
|
27
|
+
return InterfaceServerResponse.createError(new Error(`Error sending device command: Server [${uuid}] not found.`));
|
|
28
|
+
if (!server.isConnected) {
|
|
29
|
+
logger.warn(`Cannot send PUT ${url} to ${server.name} server is not connected.`);
|
|
30
|
+
return InterfaceServerResponse.createError(new Error(`Error sending device command: [${server.name}] not connected.`));
|
|
31
|
+
}
|
|
32
|
+
if (server.type === 'rem') {
|
|
33
|
+
let rem = server as REMInterfaceServer;
|
|
34
|
+
result = await rem.putApiService(url, data, timeout);
|
|
35
|
+
// If the result code is > 200 we have an issue.
|
|
36
|
+
//if (result.status.code > 200 || result.status.code === -1)
|
|
37
|
+
// return Promise.reject(new Error(`putDeviceService: ${result.error.message}`));
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
catch (err) { return Promise.reject(err); }
|
|
42
|
+
}
|
|
43
|
+
public static async getDeviceService(uuid: string, url: string, data?: any, timeout:number = 3600): Promise<any> {
|
|
44
|
+
try {
|
|
45
|
+
let result: InterfaceServerResponse;
|
|
46
|
+
let server = webApp.findServerByGuid(uuid);
|
|
47
|
+
if (typeof server === 'undefined') return Promise.reject(new Error(`Error sending device command: Server [${uuid}] not found.`));
|
|
48
|
+
if (!server.isConnected) return Promise.reject(new Error(`Error sending device command: [${server.name}] not connected.`));
|
|
49
|
+
if (server.type === 'rem') {
|
|
50
|
+
let rem = server as REMInterfaceServer;
|
|
51
|
+
//console.log(`CALLING GET FROM GETDEVSER`);
|
|
52
|
+
|
|
53
|
+
result = await rem.getApiService(url, data, timeout);
|
|
54
|
+
//console.log(`RETURNING GET FROM GETDEVSER`);
|
|
55
|
+
// If the result code is > 200 we have an issue.
|
|
56
|
+
if (result.status.code > 200) return Promise.reject(new Error(`putDeviceService: ${result.error.message}`));
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
catch (err) { return Promise.reject(err); }
|
|
61
|
+
}
|
|
62
|
+
public async closeAsync() {
|
|
63
|
+
try {
|
|
64
|
+
}
|
|
65
|
+
catch (err) { logger.error(err); }
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export class NixieChildEquipment extends NixieEquipment {
|
|
69
|
+
constructor(parent: NixieEquipment) {
|
|
70
|
+
super(parent.controlPanel);
|
|
71
|
+
this._pmap['parent'] = parent;
|
|
72
|
+
}
|
|
73
|
+
public getParent(): NixieEquipment { return this._pmap['parent']; }
|
|
74
|
+
}
|
|
75
|
+
export class NixieEquipmentCollection<T> extends Array<NixieEquipment> {
|
|
76
|
+
private _pmap = new WeakSet();
|
|
77
|
+
public get controlPanel(): INixieControlPanel { return this._pmap['ncp']; }
|
|
78
|
+
constructor(ncp: INixieControlPanel) {
|
|
79
|
+
super();
|
|
80
|
+
this._pmap['ncp'] = ncp;
|
|
81
|
+
}
|
|
82
|
+
public async removeById(id: number) {
|
|
83
|
+
try {
|
|
84
|
+
let ndx = this.findIndex(elem => elem.id === id);
|
|
85
|
+
if (ndx >= 0) {
|
|
86
|
+
let eq = this[ndx];
|
|
87
|
+
await eq.closeAsync();
|
|
88
|
+
this.splice(ndx, 1);
|
|
89
|
+
logger.info(`Removing chem doser id# ${id} at index ndx`);
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
logger.warn(`A Nixie equipment item was not found with id ${id}. Equipment not removed.`);
|
|
93
|
+
}
|
|
94
|
+
catch (err) { return Promise.reject(err); }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//export class NixieRelay extends NixieEquipment {
|
|
98
|
+
|
|
99
|
+
//}
|
|
100
|
+
//export class NixieCircuit extends NixieRelay {
|
|
101
|
+
|
|
102
|
+
//}
|
|
103
|
+
//export class NixieValve extends NixieRelay {
|
|
104
|
+
|
|
104
105
|
//}
|
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
import { EquipmentNotFoundError, InvalidEquipmentDataError, InvalidEquipmentIdError, 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, BodyCollection, sys } from "../../../controller/Equipment";
|
|
7
|
-
import { BodyTempState, state, } from "../../State";
|
|
8
|
-
import { setTimeout, clearTimeout } from 'timers';
|
|
9
|
-
import { NixieControlPanel } from '../Nixie';
|
|
10
|
-
import { webApp, InterfaceServerResponse } from "../../../web/Server";
|
|
11
|
-
|
|
12
|
-
export class NixieBodyCollection extends NixieEquipmentCollection<NixieBody> {
|
|
13
|
-
public async setBodyAsync(body: Body, data: any) {
|
|
14
|
-
// By the time we get here we know that we are in control and this is a REMChem.
|
|
15
|
-
try {
|
|
16
|
-
let c: NixieBody = this.find(elem => elem.id === body.id) as NixieBody;
|
|
17
|
-
if (typeof c === 'undefined') {
|
|
18
|
-
body.master = 1;
|
|
19
|
-
c = new NixieBody(this.controlPanel, body);
|
|
20
|
-
this.push(c);
|
|
21
|
-
await c.setBodyAsync(data);
|
|
22
|
-
logger.info(`A body was not found for id #${body.id} creating body`);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
await c.setBodyAsync(data);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
catch (err) { logger.error(`setBodyAsync: ${err.message}`); return Promise.reject(err); }
|
|
29
|
-
}
|
|
30
|
-
public async initAsync(bodies: BodyCollection) {
|
|
31
|
-
try {
|
|
32
|
-
this.length = 0;
|
|
33
|
-
for (let i = 0; i < bodies.length; i++) {
|
|
34
|
-
let body = bodies.getItemByIndex(i);
|
|
35
|
-
if (body.master === 1) {
|
|
36
|
-
if (typeof this.find(elem => elem.id === body.id) === 'undefined') {
|
|
37
|
-
logger.info(`Initializing Nixie body ${body.name}`);
|
|
38
|
-
let nbody = new NixieBody(this.controlPanel, body);
|
|
39
|
-
this.push(nbody);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
catch (err) { logger.error(`Nixie Body initAsync: ${err.message}`); return Promise.reject(err); }
|
|
45
|
-
}
|
|
46
|
-
public async closeAsync() {
|
|
47
|
-
try {
|
|
48
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
49
|
-
try {
|
|
50
|
-
await this[i].closeAsync();
|
|
51
|
-
this.splice(i, 1);
|
|
52
|
-
} catch (err) { logger.error(`Error stopping Nixie Body ${err}`); }
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
} catch (err) { } // Don't bail if we have an errror.
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
export class NixieBody extends NixieEquipment {
|
|
60
|
-
public pollingInterval: number = 10000;
|
|
61
|
-
private _pollTimer: NodeJS.Timeout = null;
|
|
62
|
-
public body: Body;
|
|
63
|
-
constructor(ncp: INixieControlPanel, body: Body) {
|
|
64
|
-
super(ncp);
|
|
65
|
-
this.body = body;
|
|
66
|
-
this.pollEquipmentAsync();
|
|
67
|
-
let bs = state.temps.bodies.getItemById(body.id);
|
|
68
|
-
bs.heaterCooldownDelay = false;
|
|
69
|
-
bs.heatStatus = 0;
|
|
70
|
-
}
|
|
71
|
-
public get id(): number { return typeof this.body !== 'undefined' ? this.body.id : -1; }
|
|
72
|
-
public async setBodyAsync(data: any) {
|
|
73
|
-
try {
|
|
74
|
-
let body = this.body;
|
|
75
|
-
}
|
|
76
|
-
catch (err) { logger.error(`Nixie setBodyAsync: ${err.message}`); return Promise.reject(err); }
|
|
77
|
-
}
|
|
78
|
-
public async setBodyStateAsync(bstate: BodyTempState, isOn: boolean) {
|
|
79
|
-
try {
|
|
80
|
-
// Here we go we need to set the valve state.
|
|
81
|
-
if (bstate.isOn !== isOn) {
|
|
82
|
-
logger.info(`Nixie: Set Body ${bstate.id}-${bstate.name} to ${isOn}`);
|
|
83
|
-
}
|
|
84
|
-
bstate.isOn = isOn;
|
|
85
|
-
} catch (err) { logger.error(`Nixie Error setting body state ${bstate.id}-${bstate.name}: ${err.message}`); }
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
public async pollEquipmentAsync() {
|
|
89
|
-
let self = this;
|
|
90
|
-
try {
|
|
91
|
-
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
92
|
-
this._pollTimer = null;
|
|
93
|
-
let success = false;
|
|
94
|
-
}
|
|
95
|
-
catch (err) { logger.error(`Nixie Error polling body - ${err}`); }
|
|
96
|
-
finally { this._pollTimer = setTimeout(async () => await self.pollEquipmentAsync(), this.pollingInterval || 10000); }
|
|
97
|
-
}
|
|
98
|
-
private async checkHardwareStatusAsync(connectionId: string, deviceBinding: string) {
|
|
99
|
-
try {
|
|
100
|
-
let dev = await NixieEquipment.getDeviceService(connectionId, `/status/device/${deviceBinding}`);
|
|
101
|
-
return dev;
|
|
102
|
-
} catch (err) { logger.error(`Nixie Body checkHardwareStatusAsync: ${err.message}`); return { hasFault: true } }
|
|
103
|
-
}
|
|
104
|
-
public async validateSetupAsync(body: Body, temp: BodyTempState) {
|
|
105
|
-
try {
|
|
106
|
-
// The validation will be different if the body is on or not. So lets get that information.
|
|
107
|
-
} catch (err) { logger.error(`Nixie Error checking Body Hardware ${this.body.name}: ${err.message}`); return Promise.reject(err); }
|
|
108
|
-
}
|
|
109
|
-
public async closeAsync() {
|
|
110
|
-
try {
|
|
111
|
-
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
112
|
-
this._pollTimer = null;
|
|
113
|
-
let bstate = state.temps.bodies.getItemById(this.body.id);
|
|
114
|
-
await this.setBodyStateAsync(bstate, false);
|
|
115
|
-
bstate.emitEquipmentChange();
|
|
116
|
-
}
|
|
117
|
-
catch (err) { logger.error(`Nixie Body closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
118
|
-
}
|
|
119
|
-
public logData(filename: string, data: any) { this.controlPanel.logData(filename, data); }
|
|
120
|
-
}
|
|
1
|
+
import { EquipmentNotFoundError, InvalidEquipmentDataError, InvalidEquipmentIdError, 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, BodyCollection, sys } from "../../../controller/Equipment";
|
|
7
|
+
import { BodyTempState, state, } from "../../State";
|
|
8
|
+
import { setTimeout, clearTimeout } from 'timers';
|
|
9
|
+
import { NixieControlPanel } from '../Nixie';
|
|
10
|
+
import { webApp, InterfaceServerResponse } from "../../../web/Server";
|
|
11
|
+
|
|
12
|
+
export class NixieBodyCollection extends NixieEquipmentCollection<NixieBody> {
|
|
13
|
+
public async setBodyAsync(body: Body, data: any) {
|
|
14
|
+
// By the time we get here we know that we are in control and this is a REMChem.
|
|
15
|
+
try {
|
|
16
|
+
let c: NixieBody = this.find(elem => elem.id === body.id) as NixieBody;
|
|
17
|
+
if (typeof c === 'undefined') {
|
|
18
|
+
body.master = 1;
|
|
19
|
+
c = new NixieBody(this.controlPanel, body);
|
|
20
|
+
this.push(c);
|
|
21
|
+
await c.setBodyAsync(data);
|
|
22
|
+
logger.info(`A body was not found for id #${body.id} creating body`);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
await c.setBodyAsync(data);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (err) { logger.error(`setBodyAsync: ${err.message}`); return Promise.reject(err); }
|
|
29
|
+
}
|
|
30
|
+
public async initAsync(bodies: BodyCollection) {
|
|
31
|
+
try {
|
|
32
|
+
this.length = 0;
|
|
33
|
+
for (let i = 0; i < bodies.length; i++) {
|
|
34
|
+
let body = bodies.getItemByIndex(i);
|
|
35
|
+
if (body.master === 1) {
|
|
36
|
+
if (typeof this.find(elem => elem.id === body.id) === 'undefined') {
|
|
37
|
+
logger.info(`Initializing Nixie body ${body.name}`);
|
|
38
|
+
let nbody = new NixieBody(this.controlPanel, body);
|
|
39
|
+
this.push(nbody);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (err) { logger.error(`Nixie Body initAsync: ${err.message}`); return Promise.reject(err); }
|
|
45
|
+
}
|
|
46
|
+
public async closeAsync() {
|
|
47
|
+
try {
|
|
48
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
49
|
+
try {
|
|
50
|
+
await this[i].closeAsync();
|
|
51
|
+
this.splice(i, 1);
|
|
52
|
+
} catch (err) { logger.error(`Error stopping Nixie Body ${err}`); }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
} catch (err) { } // Don't bail if we have an errror.
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
export class NixieBody extends NixieEquipment {
|
|
60
|
+
public pollingInterval: number = 10000;
|
|
61
|
+
private _pollTimer: NodeJS.Timeout = null;
|
|
62
|
+
public body: Body;
|
|
63
|
+
constructor(ncp: INixieControlPanel, body: Body) {
|
|
64
|
+
super(ncp);
|
|
65
|
+
this.body = body;
|
|
66
|
+
this.pollEquipmentAsync();
|
|
67
|
+
let bs = state.temps.bodies.getItemById(body.id);
|
|
68
|
+
bs.heaterCooldownDelay = false;
|
|
69
|
+
bs.heatStatus = 0;
|
|
70
|
+
}
|
|
71
|
+
public get id(): number { return typeof this.body !== 'undefined' ? this.body.id : -1; }
|
|
72
|
+
public async setBodyAsync(data: any) {
|
|
73
|
+
try {
|
|
74
|
+
let body = this.body;
|
|
75
|
+
}
|
|
76
|
+
catch (err) { logger.error(`Nixie setBodyAsync: ${err.message}`); return Promise.reject(err); }
|
|
77
|
+
}
|
|
78
|
+
public async setBodyStateAsync(bstate: BodyTempState, isOn: boolean) {
|
|
79
|
+
try {
|
|
80
|
+
// Here we go we need to set the valve state.
|
|
81
|
+
if (bstate.isOn !== isOn) {
|
|
82
|
+
logger.info(`Nixie: Set Body ${bstate.id}-${bstate.name} to ${isOn}`);
|
|
83
|
+
}
|
|
84
|
+
bstate.isOn = isOn;
|
|
85
|
+
} catch (err) { logger.error(`Nixie Error setting body state ${bstate.id}-${bstate.name}: ${err.message}`); }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public async pollEquipmentAsync() {
|
|
89
|
+
let self = this;
|
|
90
|
+
try {
|
|
91
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
92
|
+
this._pollTimer = null;
|
|
93
|
+
let success = false;
|
|
94
|
+
}
|
|
95
|
+
catch (err) { logger.error(`Nixie Error polling body - ${err}`); }
|
|
96
|
+
finally { this._pollTimer = setTimeout(async () => await self.pollEquipmentAsync(), this.pollingInterval || 10000); }
|
|
97
|
+
}
|
|
98
|
+
private async checkHardwareStatusAsync(connectionId: string, deviceBinding: string) {
|
|
99
|
+
try {
|
|
100
|
+
let dev = await NixieEquipment.getDeviceService(connectionId, `/status/device/${deviceBinding}`);
|
|
101
|
+
return dev;
|
|
102
|
+
} catch (err) { logger.error(`Nixie Body checkHardwareStatusAsync: ${err.message}`); return { hasFault: true } }
|
|
103
|
+
}
|
|
104
|
+
public async validateSetupAsync(body: Body, temp: BodyTempState) {
|
|
105
|
+
try {
|
|
106
|
+
// The validation will be different if the body is on or not. So lets get that information.
|
|
107
|
+
} catch (err) { logger.error(`Nixie Error checking Body Hardware ${this.body.name}: ${err.message}`); return Promise.reject(err); }
|
|
108
|
+
}
|
|
109
|
+
public async closeAsync() {
|
|
110
|
+
try {
|
|
111
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
112
|
+
this._pollTimer = null;
|
|
113
|
+
let bstate = state.temps.bodies.getItemById(this.body.id);
|
|
114
|
+
await this.setBodyStateAsync(bstate, false);
|
|
115
|
+
bstate.emitEquipmentChange();
|
|
116
|
+
}
|
|
117
|
+
catch (err) { logger.error(`Nixie Body closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
118
|
+
}
|
|
119
|
+
public logData(filename: string, data: any) { this.controlPanel.logData(filename, data); }
|
|
120
|
+
}
|