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,170 +1,170 @@
|
|
|
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 { Valve, ValveCollection, sys } from "../../../controller/Equipment";
|
|
7
|
-
import { ValveState, 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 NixieValveCollection extends NixieEquipmentCollection<NixieValve> {
|
|
13
|
-
public async deleteValveAsync(id: number) {
|
|
14
|
-
try {
|
|
15
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
16
|
-
let valve = this[i];
|
|
17
|
-
if (valve.id === id) {
|
|
18
|
-
await valve.closeAsync();
|
|
19
|
-
this.splice(i, 1);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
} catch (err) { return Promise.reject(`Nixie Control Panel deleteValveAsync ${err.message}`); }
|
|
23
|
-
}
|
|
24
|
-
public async setValveStateAsync(vstate: ValveState, isDiverted: boolean) {
|
|
25
|
-
try {
|
|
26
|
-
let valve: NixieValve = this.find(elem => elem.id === vstate.id) as NixieValve;
|
|
27
|
-
if (typeof valve === 'undefined') {
|
|
28
|
-
vstate.isDiverted = isDiverted;
|
|
29
|
-
return logger.error(`Nixie Control Panel Error setValveState could not find valve ${vstate.id}-${vstate.name}`);
|
|
30
|
-
}
|
|
31
|
-
await valve.setValveStateAsync(vstate, isDiverted);
|
|
32
|
-
} catch (err) { return Promise.reject(new Error(`Nixie Error setting valve state ${vstate.id}-${vstate.name}: ${err.message}`)); }
|
|
33
|
-
}
|
|
34
|
-
public async setValveAsync(valve: Valve, data: any) {
|
|
35
|
-
// By the time we get here we know that we are in control and this is a Nixie valve.
|
|
36
|
-
try {
|
|
37
|
-
let c: NixieValve = this.find(elem => elem.id === valve.id) as NixieValve;
|
|
38
|
-
if (typeof c === 'undefined') {
|
|
39
|
-
valve.master = 1;
|
|
40
|
-
c = new NixieValve(this.controlPanel, valve);
|
|
41
|
-
this.push(c);
|
|
42
|
-
await c.setValveAsync(data);
|
|
43
|
-
logger.info(`A valve was not found for id #${valve.id} creating valve`);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
await c.setValveAsync(data);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
catch (err) { logger.error(`setValveAsync: ${err.message}`); return Promise.reject(err); }
|
|
50
|
-
}
|
|
51
|
-
public async initAsync(valves: ValveCollection) {
|
|
52
|
-
try {
|
|
53
|
-
for (let i = 0; i < valves.length; i++) {
|
|
54
|
-
let valve = valves.getItemByIndex(i);
|
|
55
|
-
if (valve.master === 1) {
|
|
56
|
-
if (typeof this.find(elem => elem.id === valve.id) === 'undefined') {
|
|
57
|
-
let nvalve = new NixieValve(this.controlPanel, valve);
|
|
58
|
-
logger.info(`Initializing Nixie Valve ${nvalve.id}-${valve.name}`);
|
|
59
|
-
this.push(nvalve);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
catch (err) { logger.error(`Nixie Valve initAsync Error: ${err.message}`); return Promise.reject(err); }
|
|
65
|
-
}
|
|
66
|
-
public async closeAsync() {
|
|
67
|
-
try {
|
|
68
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
69
|
-
try {
|
|
70
|
-
await this[i].closeAsync();
|
|
71
|
-
this.splice(i, 1);
|
|
72
|
-
} catch (err) { logger.error(`Error stopping Nixie Valve ${err}`); }
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
} catch (err) { } // Don't bail if we have an errror.
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public async initValveAsync(valve: Valve): Promise<NixieValve> {
|
|
79
|
-
try {
|
|
80
|
-
let c: NixieValve = this.find(elem => elem.id === valve.id) as NixieValve;
|
|
81
|
-
if (typeof c === 'undefined') {
|
|
82
|
-
c = new NixieValve(this.controlPanel, valve);
|
|
83
|
-
this.push(c);
|
|
84
|
-
}
|
|
85
|
-
return c;
|
|
86
|
-
} catch (err) { return Promise.reject(logger.error(`Nixie Controller: initValveAsync Error: ${err.message}`)); }
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
export class NixieValve extends NixieEquipment {
|
|
91
|
-
public pollingInterval: number = 10000;
|
|
92
|
-
private _pollTimer: NodeJS.Timeout = null;
|
|
93
|
-
public valve: Valve;
|
|
94
|
-
private _lastState;
|
|
95
|
-
constructor(ncp: INixieControlPanel, valve: Valve) {
|
|
96
|
-
super(ncp);
|
|
97
|
-
this.valve = valve;
|
|
98
|
-
this.pollEquipmentAsync();
|
|
99
|
-
}
|
|
100
|
-
public get id(): number { return typeof this.valve !== 'undefined' ? this.valve.id : -1; }
|
|
101
|
-
public async setValveStateAsync(vstate: ValveState, isDiverted: boolean) {
|
|
102
|
-
try {
|
|
103
|
-
// Here we go we need to set the valve state.
|
|
104
|
-
if (vstate.isDiverted !== isDiverted) {
|
|
105
|
-
logger.
|
|
106
|
-
}
|
|
107
|
-
if (utils.isNullOrEmpty(this.valve.connectionId) || utils.isNullOrEmpty(this.valve.deviceBinding)) {
|
|
108
|
-
vstate.isDiverted = isDiverted;
|
|
109
|
-
return new InterfaceServerResponse(200, 'Success');
|
|
110
|
-
}
|
|
111
|
-
if (typeof this._lastState === 'undefined' || isDiverted || this._lastState !== isDiverted) {
|
|
112
|
-
let res = await NixieEquipment.putDeviceService(this.valve.connectionId, `/state/device/${this.valve.deviceBinding}`, { isOn: isDiverted, latch: isDiverted ? 10000 : undefined });
|
|
113
|
-
if (res.status.code === 200) this._lastState = vstate.isDiverted = isDiverted;
|
|
114
|
-
return res;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
vstate.isDiverted = isDiverted;
|
|
118
|
-
return new InterfaceServerResponse(200, 'Success');
|
|
119
|
-
}
|
|
120
|
-
} catch (err) { return logger.error(`Nixie Error setting valve state ${vstate.id}-${vstate.name}: ${err.message}`); }
|
|
121
|
-
}
|
|
122
|
-
public async setValveAsync(data: any) {
|
|
123
|
-
try {
|
|
124
|
-
let valve = this.valve;
|
|
125
|
-
}
|
|
126
|
-
catch (err) { logger.error(`Nixie setValveAsync: ${err.message}`); return Promise.reject(err); }
|
|
127
|
-
}
|
|
128
|
-
public async pollEquipmentAsync() {
|
|
129
|
-
let self = this;
|
|
130
|
-
try {
|
|
131
|
-
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
132
|
-
this._pollTimer = null;
|
|
133
|
-
let success = false;
|
|
134
|
-
}
|
|
135
|
-
catch (err) { logger.error(`Nixie Error polling valve - ${err}`); }
|
|
136
|
-
finally { this._pollTimer = setTimeout(async () => await self.pollEquipmentAsync(), this.pollingInterval || 10000); }
|
|
137
|
-
}
|
|
138
|
-
private async checkHardwareStatusAsync(connectionId: string, deviceBinding: string) {
|
|
139
|
-
try {
|
|
140
|
-
let dev = await NixieEquipment.getDeviceService(connectionId, `/status/device/${deviceBinding}`);
|
|
141
|
-
return dev;
|
|
142
|
-
} catch (err) { logger.error(`Nixie Valve checkHardwareStatusAsync: ${err.message}`); return { hasFault: true } }
|
|
143
|
-
}
|
|
144
|
-
public async validateSetupAsync(valve: Valve, vstate: ValveState) {
|
|
145
|
-
try {
|
|
146
|
-
if (typeof valve.connectionId !== 'undefined' && valve.connectionId !== ''
|
|
147
|
-
&& typeof valve.deviceBinding !== 'undefined' && valve.deviceBinding !== '') {
|
|
148
|
-
try {
|
|
149
|
-
let stat = await this.checkHardwareStatusAsync(valve.connectionId, valve.deviceBinding);
|
|
150
|
-
// If we have a status check the return.
|
|
151
|
-
vstate.commStatus = stat.hasFault ? 1 : 0;
|
|
152
|
-
} catch (err) { vstate.commStatus = 1; }
|
|
153
|
-
}
|
|
154
|
-
else
|
|
155
|
-
vstate.commStatus = 0;
|
|
156
|
-
// The validation will be different if the valve is on or not. So lets get that information.
|
|
157
|
-
} catch (err) { logger.error(`Nixie Error checking Valve Hardware ${this.valve.name}: ${err.message}`); vstate.commStatus = 1; return Promise.reject(err); }
|
|
158
|
-
}
|
|
159
|
-
public async closeAsync() {
|
|
160
|
-
try {
|
|
161
|
-
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
162
|
-
this._pollTimer = null;
|
|
163
|
-
let vstate = state.valves.getItemById(this.valve.id);
|
|
164
|
-
this.setValveStateAsync(vstate, false);
|
|
165
|
-
vstate.emitEquipmentChange();
|
|
166
|
-
}
|
|
167
|
-
catch (err) { logger.error(`Nixie Valve closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
168
|
-
}
|
|
169
|
-
public logData(filename: string, data: any) { this.controlPanel.logData(filename, data); }
|
|
170
|
-
}
|
|
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 { Valve, ValveCollection, sys } from "../../../controller/Equipment";
|
|
7
|
+
import { ValveState, 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 NixieValveCollection extends NixieEquipmentCollection<NixieValve> {
|
|
13
|
+
public async deleteValveAsync(id: number) {
|
|
14
|
+
try {
|
|
15
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
16
|
+
let valve = this[i];
|
|
17
|
+
if (valve.id === id) {
|
|
18
|
+
await valve.closeAsync();
|
|
19
|
+
this.splice(i, 1);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
} catch (err) { return Promise.reject(`Nixie Control Panel deleteValveAsync ${err.message}`); }
|
|
23
|
+
}
|
|
24
|
+
public async setValveStateAsync(vstate: ValveState, isDiverted: boolean) {
|
|
25
|
+
try {
|
|
26
|
+
let valve: NixieValve = this.find(elem => elem.id === vstate.id) as NixieValve;
|
|
27
|
+
if (typeof valve === 'undefined') {
|
|
28
|
+
vstate.isDiverted = isDiverted;
|
|
29
|
+
return logger.error(`Nixie Control Panel Error setValveState could not find valve ${vstate.id}-${vstate.name}`);
|
|
30
|
+
}
|
|
31
|
+
await valve.setValveStateAsync(vstate, isDiverted);
|
|
32
|
+
} catch (err) { return Promise.reject(new Error(`Nixie Error setting valve state ${vstate.id}-${vstate.name}: ${err.message}`)); }
|
|
33
|
+
}
|
|
34
|
+
public async setValveAsync(valve: Valve, data: any) {
|
|
35
|
+
// By the time we get here we know that we are in control and this is a Nixie valve.
|
|
36
|
+
try {
|
|
37
|
+
let c: NixieValve = this.find(elem => elem.id === valve.id) as NixieValve;
|
|
38
|
+
if (typeof c === 'undefined') {
|
|
39
|
+
valve.master = 1;
|
|
40
|
+
c = new NixieValve(this.controlPanel, valve);
|
|
41
|
+
this.push(c);
|
|
42
|
+
await c.setValveAsync(data);
|
|
43
|
+
logger.info(`A valve was not found for id #${valve.id} creating valve`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
await c.setValveAsync(data);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (err) { logger.error(`setValveAsync: ${err.message}`); return Promise.reject(err); }
|
|
50
|
+
}
|
|
51
|
+
public async initAsync(valves: ValveCollection) {
|
|
52
|
+
try {
|
|
53
|
+
for (let i = 0; i < valves.length; i++) {
|
|
54
|
+
let valve = valves.getItemByIndex(i);
|
|
55
|
+
if (valve.master === 1) {
|
|
56
|
+
if (typeof this.find(elem => elem.id === valve.id) === 'undefined') {
|
|
57
|
+
let nvalve = new NixieValve(this.controlPanel, valve);
|
|
58
|
+
logger.info(`Initializing Nixie Valve ${nvalve.id}-${valve.name}`);
|
|
59
|
+
this.push(nvalve);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (err) { logger.error(`Nixie Valve initAsync Error: ${err.message}`); return Promise.reject(err); }
|
|
65
|
+
}
|
|
66
|
+
public async closeAsync() {
|
|
67
|
+
try {
|
|
68
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
69
|
+
try {
|
|
70
|
+
await this[i].closeAsync();
|
|
71
|
+
this.splice(i, 1);
|
|
72
|
+
} catch (err) { logger.error(`Error stopping Nixie Valve ${err}`); }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
} catch (err) { } // Don't bail if we have an errror.
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public async initValveAsync(valve: Valve): Promise<NixieValve> {
|
|
79
|
+
try {
|
|
80
|
+
let c: NixieValve = this.find(elem => elem.id === valve.id) as NixieValve;
|
|
81
|
+
if (typeof c === 'undefined') {
|
|
82
|
+
c = new NixieValve(this.controlPanel, valve);
|
|
83
|
+
this.push(c);
|
|
84
|
+
}
|
|
85
|
+
return c;
|
|
86
|
+
} catch (err) { return Promise.reject(logger.error(`Nixie Controller: initValveAsync Error: ${err.message}`)); }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
export class NixieValve extends NixieEquipment {
|
|
91
|
+
public pollingInterval: number = 10000;
|
|
92
|
+
private _pollTimer: NodeJS.Timeout = null;
|
|
93
|
+
public valve: Valve;
|
|
94
|
+
private _lastState;
|
|
95
|
+
constructor(ncp: INixieControlPanel, valve: Valve) {
|
|
96
|
+
super(ncp);
|
|
97
|
+
this.valve = valve;
|
|
98
|
+
this.pollEquipmentAsync();
|
|
99
|
+
}
|
|
100
|
+
public get id(): number { return typeof this.valve !== 'undefined' ? this.valve.id : -1; }
|
|
101
|
+
public async setValveStateAsync(vstate: ValveState, isDiverted: boolean) {
|
|
102
|
+
try {
|
|
103
|
+
// Here we go we need to set the valve state.
|
|
104
|
+
if (vstate.isDiverted !== isDiverted) {
|
|
105
|
+
logger.verbose(`Nixie: Set valve ${vstate.id}-${vstate.name} to ${isDiverted}`);
|
|
106
|
+
}
|
|
107
|
+
if (utils.isNullOrEmpty(this.valve.connectionId) || utils.isNullOrEmpty(this.valve.deviceBinding)) {
|
|
108
|
+
vstate.isDiverted = isDiverted;
|
|
109
|
+
return new InterfaceServerResponse(200, 'Success');
|
|
110
|
+
}
|
|
111
|
+
if (typeof this._lastState === 'undefined' || isDiverted || this._lastState !== isDiverted) {
|
|
112
|
+
let res = await NixieEquipment.putDeviceService(this.valve.connectionId, `/state/device/${this.valve.deviceBinding}`, { isOn: isDiverted, latch: isDiverted ? 10000 : undefined });
|
|
113
|
+
if (res.status.code === 200) this._lastState = vstate.isDiverted = isDiverted;
|
|
114
|
+
return res;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
vstate.isDiverted = isDiverted;
|
|
118
|
+
return new InterfaceServerResponse(200, 'Success');
|
|
119
|
+
}
|
|
120
|
+
} catch (err) { return logger.error(`Nixie Error setting valve state ${vstate.id}-${vstate.name}: ${err.message}`); }
|
|
121
|
+
}
|
|
122
|
+
public async setValveAsync(data: any) {
|
|
123
|
+
try {
|
|
124
|
+
let valve = this.valve;
|
|
125
|
+
}
|
|
126
|
+
catch (err) { logger.error(`Nixie setValveAsync: ${err.message}`); return Promise.reject(err); }
|
|
127
|
+
}
|
|
128
|
+
public async pollEquipmentAsync() {
|
|
129
|
+
let self = this;
|
|
130
|
+
try {
|
|
131
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
132
|
+
this._pollTimer = null;
|
|
133
|
+
let success = false;
|
|
134
|
+
}
|
|
135
|
+
catch (err) { logger.error(`Nixie Error polling valve - ${err}`); }
|
|
136
|
+
finally { this._pollTimer = setTimeout(async () => await self.pollEquipmentAsync(), this.pollingInterval || 10000); }
|
|
137
|
+
}
|
|
138
|
+
private async checkHardwareStatusAsync(connectionId: string, deviceBinding: string) {
|
|
139
|
+
try {
|
|
140
|
+
let dev = await NixieEquipment.getDeviceService(connectionId, `/status/device/${deviceBinding}`);
|
|
141
|
+
return dev;
|
|
142
|
+
} catch (err) { logger.error(`Nixie Valve checkHardwareStatusAsync: ${err.message}`); return { hasFault: true } }
|
|
143
|
+
}
|
|
144
|
+
public async validateSetupAsync(valve: Valve, vstate: ValveState) {
|
|
145
|
+
try {
|
|
146
|
+
if (typeof valve.connectionId !== 'undefined' && valve.connectionId !== ''
|
|
147
|
+
&& typeof valve.deviceBinding !== 'undefined' && valve.deviceBinding !== '') {
|
|
148
|
+
try {
|
|
149
|
+
let stat = await this.checkHardwareStatusAsync(valve.connectionId, valve.deviceBinding);
|
|
150
|
+
// If we have a status check the return.
|
|
151
|
+
vstate.commStatus = stat.hasFault ? 1 : 0;
|
|
152
|
+
} catch (err) { vstate.commStatus = 1; }
|
|
153
|
+
}
|
|
154
|
+
else
|
|
155
|
+
vstate.commStatus = 0;
|
|
156
|
+
// The validation will be different if the valve is on or not. So lets get that information.
|
|
157
|
+
} catch (err) { logger.error(`Nixie Error checking Valve Hardware ${this.valve.name}: ${err.message}`); vstate.commStatus = 1; return Promise.reject(err); }
|
|
158
|
+
}
|
|
159
|
+
public async closeAsync() {
|
|
160
|
+
try {
|
|
161
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
162
|
+
this._pollTimer = null;
|
|
163
|
+
let vstate = state.valves.getItemById(this.valve.id);
|
|
164
|
+
this.setValveStateAsync(vstate, false);
|
|
165
|
+
vstate.emitEquipmentChange();
|
|
166
|
+
}
|
|
167
|
+
catch (err) { logger.error(`Nixie Valve closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
168
|
+
}
|
|
169
|
+
public logData(filename: string, data: any) { this.controlPanel.logData(filename, data); }
|
|
170
|
+
}
|