nodejs-poolcontroller 7.6.1 → 7.7.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 +44 -44
- 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 +220 -215
- package/Dockerfile +17 -17
- package/Gruntfile.js +40 -40
- package/LICENSE +661 -661
- package/README.md +191 -191
- package/app.ts +1 -1
- package/config/Config.ts +14 -0
- package/config/VersionCheck.ts +2 -2
- package/controller/Constants.ts +2 -1
- package/controller/Equipment.ts +2484 -2459
- package/controller/Errors.ts +180 -180
- package/controller/Lockouts.ts +502 -436
- package/controller/State.ts +106 -30
- package/controller/boards/AquaLinkBoard.ts +1000 -0
- package/controller/boards/BoardFactory.ts +49 -45
- package/controller/boards/EasyTouchBoard.ts +2859 -2653
- package/controller/boards/IntelliCenterBoard.ts +4198 -4230
- package/controller/boards/IntelliComBoard.ts +63 -63
- package/controller/boards/IntelliTouchBoard.ts +273 -241
- package/controller/boards/NixieBoard.ts +1728 -1675
- package/controller/boards/SystemBoard.ts +4925 -4697
- package/controller/comms/Comms.ts +442 -479
- package/controller/comms/messages/Messages.ts +171 -25
- package/controller/comms/messages/config/ChlorinatorMessage.ts +5 -2
- package/controller/comms/messages/config/CircuitGroupMessage.ts +0 -0
- package/controller/comms/messages/config/CircuitMessage.ts +1 -0
- package/controller/comms/messages/config/ConfigMessage.ts +0 -0
- package/controller/comms/messages/config/CoverMessage.ts +0 -0
- package/controller/comms/messages/config/CustomNameMessage.ts +30 -30
- package/controller/comms/messages/config/EquipmentMessage.ts +0 -0
- package/controller/comms/messages/config/ExternalMessage.ts +0 -0
- package/controller/comms/messages/config/FeatureMessage.ts +0 -0
- package/controller/comms/messages/config/GeneralMessage.ts +0 -0
- package/controller/comms/messages/config/HeaterMessage.ts +142 -10
- package/controller/comms/messages/config/IntellichemMessage.ts +0 -0
- package/controller/comms/messages/config/OptionsMessage.ts +4 -21
- package/controller/comms/messages/config/PumpMessage.ts +53 -35
- package/controller/comms/messages/config/RemoteMessage.ts +0 -0
- package/controller/comms/messages/config/ScheduleMessage.ts +350 -347
- package/controller/comms/messages/config/SecurityMessage.ts +0 -0
- package/controller/comms/messages/config/ValveMessage.ts +1 -1
- package/controller/comms/messages/status/ChlorinatorStateMessage.ts +38 -86
- package/controller/comms/messages/status/EquipmentStateMessage.ts +58 -22
- package/controller/comms/messages/status/HeaterStateMessage.ts +116 -86
- package/controller/comms/messages/status/IntelliChemStateMessage.ts +445 -445
- package/controller/comms/messages/status/IntelliValveStateMessage.ts +35 -35
- package/controller/comms/messages/status/PumpStateMessage.ts +23 -1
- package/controller/comms/messages/status/VersionMessage.ts +0 -0
- package/controller/nixie/Nixie.ts +162 -162
- package/controller/nixie/NixieEquipment.ts +103 -103
- package/controller/nixie/bodies/Body.ts +120 -120
- package/controller/nixie/bodies/Filter.ts +135 -135
- package/controller/nixie/chemistry/ChemController.ts +2511 -2498
- package/controller/nixie/chemistry/Chlorinator.ts +363 -314
- package/controller/nixie/circuits/Circuit.ts +261 -248
- package/controller/nixie/heaters/Heater.ts +650 -648
- package/controller/nixie/pumps/Pump.ts +906 -661
- package/controller/nixie/schedules/Schedule.ts +313 -257
- package/controller/nixie/valves/Valve.ts +170 -170
- package/defaultConfig.json +306 -286
- package/logger/DataLogger.ts +448 -448
- package/logger/Logger.ts +0 -0
- package/package.json +56 -56
- package/tsconfig.json +25 -25
- package/web/Server.ts +92 -47
- package/web/bindings/aqualinkD.json +505 -0
- package/web/bindings/influxDB.json +1051 -1021
- package/web/bindings/mqtt.json +702 -654
- package/web/bindings/mqttAlt.json +731 -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 +137 -136
- package/web/interfaces/httpInterface.ts +145 -124
- package/web/interfaces/influxInterface.ts +276 -245
- package/web/interfaces/mqttInterface.ts +535 -475
- package/web/services/config/Config.ts +39 -18
- package/web/services/config/ConfigSocket.ts +0 -0
- package/web/services/state/State.ts +10 -0
- package/web/services/state/StateSocket.ts +4 -4
- package/web/services/utilities/Utilities.ts +44 -42
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -52
- package/config copy.json +0 -300
- package/issue_template.md +0 -52
|
@@ -1,248 +1,261 @@
|
|
|
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 { Circuit, CircuitCollection, sys } from "../../../controller/Equipment";
|
|
7
|
-
import { CircuitState, state, ICircuitState, } from "../../State";
|
|
8
|
-
import { setTimeout, clearTimeout } from 'timers';
|
|
9
|
-
import { NixieControlPanel } from '../Nixie';
|
|
10
|
-
import { webApp, InterfaceServerResponse } from "../../../web/Server";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
this.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
this.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this._pollTimer
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
private
|
|
117
|
-
private
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
cstate
|
|
124
|
-
cstate.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
public get
|
|
128
|
-
public
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
// Party mode
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
//
|
|
153
|
-
//
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
cstate.isOn
|
|
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
|
-
} catch (err) { logger.error(`Error
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
}
|
|
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 { Circuit, CircuitCollection, sys } from "../../../controller/Equipment";
|
|
7
|
+
import { CircuitState, state, ICircuitState, } from "../../State";
|
|
8
|
+
import { setTimeout, clearTimeout } from 'timers';
|
|
9
|
+
import { NixieControlPanel } from '../Nixie';
|
|
10
|
+
import { webApp, InterfaceServerResponse } from "../../../web/Server";
|
|
11
|
+
import { delayMgr } from '../../../controller/Lockouts';
|
|
12
|
+
|
|
13
|
+
export class NixieCircuitCollection extends NixieEquipmentCollection<NixieCircuit> {
|
|
14
|
+
public pollingInterval: number = 2000;
|
|
15
|
+
private _pollTimer: NodeJS.Timeout = null;
|
|
16
|
+
public async deleteCircuitAsync(id: number) {
|
|
17
|
+
try {
|
|
18
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
19
|
+
let circ = this[i];
|
|
20
|
+
if (circ.id === id) {
|
|
21
|
+
await circ.closeAsync();
|
|
22
|
+
this.splice(i, 1);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
} catch (err) { return Promise.reject(`Nixie Control Panel deleteCircuitAsync ${err.message}`); }
|
|
26
|
+
}
|
|
27
|
+
public async sendOnOffSequenceAsync(id: number, count: number | { isOn: boolean, timeout: number }[]) {
|
|
28
|
+
try {
|
|
29
|
+
let c: NixieCircuit = this.find(elem => elem.id === id) as NixieCircuit;
|
|
30
|
+
if (typeof c === 'undefined') return Promise.reject(new Error(`NCP: Circuit ${id} could not be found to send sequence ${count}.`));
|
|
31
|
+
await c.sendOnOffSequenceAsync(count);
|
|
32
|
+
|
|
33
|
+
} catch (err) { return logger.error(`NCP: sendOnOffSequence: ${err.message}`); }
|
|
34
|
+
}
|
|
35
|
+
public async setCircuitStateAsync(cstate: ICircuitState, val: boolean) {
|
|
36
|
+
try {
|
|
37
|
+
let c: NixieCircuit = this.find(elem => elem.id === cstate.id) as NixieCircuit;
|
|
38
|
+
if (typeof c === 'undefined') return Promise.reject(new Error(`NCP: Circuit ${cstate.id}-${cstate.name} could not be found to set the state to ${val}.`));
|
|
39
|
+
await c.setCircuitStateAsync(cstate, val);
|
|
40
|
+
}
|
|
41
|
+
catch (err) { return logger.error(`NCP: setCircuitStateAsync ${cstate.id}-${cstate.name}: ${err.message}`); }
|
|
42
|
+
}
|
|
43
|
+
public async setCircuitAsync(circuit: Circuit, data: any) {
|
|
44
|
+
// By the time we get here we know that we are in control and this is a REMChem.
|
|
45
|
+
try {
|
|
46
|
+
let c: NixieCircuit = this.find(elem => elem.id === circuit.id) as NixieCircuit;
|
|
47
|
+
if (typeof c === 'undefined') {
|
|
48
|
+
circuit.master = 1;
|
|
49
|
+
c = new NixieCircuit(this.controlPanel, circuit);
|
|
50
|
+
this.push(c);
|
|
51
|
+
await c.setCircuitAsync(data);
|
|
52
|
+
logger.debug(`NixieController: A circuit was not found for id #${circuit.id} creating circuit`);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
await c.setCircuitAsync(data);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (err) { logger.error(`setCircuitAsync: ${err.message}`); return Promise.reject(err); }
|
|
59
|
+
}
|
|
60
|
+
public async checkCircuitEggTimerExpirationAsync(cstate: ICircuitState) {
|
|
61
|
+
try {
|
|
62
|
+
let c: NixieCircuit = this.find(elem => elem.id === cstate.id) as NixieCircuit;
|
|
63
|
+
await c.checkCircuitEggTimerExpirationAsync(cstate);
|
|
64
|
+
} catch (err) { logger.error(`NCP: Error synching circuit states: ${err}`); }
|
|
65
|
+
}
|
|
66
|
+
public async initAsync(circuits: CircuitCollection) {
|
|
67
|
+
try {
|
|
68
|
+
for (let i = 0; i < circuits.length; i++) {
|
|
69
|
+
let circuit = circuits.getItemByIndex(i);
|
|
70
|
+
if (circuit.master === 1) {
|
|
71
|
+
if (typeof this.find(elem => elem.id === circuit.id) === 'undefined') {
|
|
72
|
+
logger.info(`Initializing Nixie circuit ${circuit.name}`);
|
|
73
|
+
let ncircuit = new NixieCircuit(this.controlPanel, circuit);
|
|
74
|
+
this.push(ncircuit);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (err) { return Promise.reject(logger.error(`NixieController: Circuit initAsync: ${err.message}`)); }
|
|
80
|
+
}
|
|
81
|
+
public async closeAsync() {
|
|
82
|
+
try {
|
|
83
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
84
|
+
try {
|
|
85
|
+
await this[i].closeAsync();
|
|
86
|
+
this.splice(i, 1);
|
|
87
|
+
} catch (err) { logger.error(`Error stopping Nixie Circuit ${err}`); }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
} catch (err) { } // Don't bail if we have an errror.
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public async initCircuitAsync(circuit: Circuit): Promise<NixieCircuit> {
|
|
94
|
+
try {
|
|
95
|
+
let c: NixieCircuit = this.find(elem => elem.id === circuit.id) as NixieCircuit;
|
|
96
|
+
if (typeof c === 'undefined') {
|
|
97
|
+
c = new NixieCircuit(this.controlPanel, circuit);
|
|
98
|
+
this.push(c);
|
|
99
|
+
}
|
|
100
|
+
return c;
|
|
101
|
+
} catch (err) { logger.error(`initCircuitAsync: ${err.message}`); return Promise.reject(err); }
|
|
102
|
+
}
|
|
103
|
+
public async pollCircuitsAsync() {
|
|
104
|
+
let self = this;
|
|
105
|
+
try {
|
|
106
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
107
|
+
this._pollTimer = null;
|
|
108
|
+
let success = false;
|
|
109
|
+
|
|
110
|
+
} catch (err) { logger.error(`Error polling circuits: ${err.message}`); return Promise.reject(err); }
|
|
111
|
+
finally { this._pollTimer = setTimeout(async () => await self.pollCircuitsAsync(), this.pollingInterval || 10000); }
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export class NixieCircuit extends NixieEquipment {
|
|
115
|
+
public circuit: Circuit;
|
|
116
|
+
private _sequencing = false;
|
|
117
|
+
private scheduled = false;
|
|
118
|
+
private timeOn: Timestamp;
|
|
119
|
+
constructor(ncp: INixieControlPanel, circuit: Circuit) {
|
|
120
|
+
super(ncp);
|
|
121
|
+
this.circuit = circuit;
|
|
122
|
+
// Clear out the delays.
|
|
123
|
+
let cstate = state.circuits.getItemById(circuit.id);
|
|
124
|
+
cstate.startDelay = false;
|
|
125
|
+
cstate.stopDelay = false;
|
|
126
|
+
}
|
|
127
|
+
public get id(): number { return typeof this.circuit !== 'undefined' ? this.circuit.id : -1; }
|
|
128
|
+
public get eggTimerOff(): Timestamp { return typeof this.timeOn !== 'undefined' && !this.circuit.dontStop ? this.timeOn.clone().addMinutes(this.circuit.eggTimer) : undefined; }
|
|
129
|
+
public async setCircuitAsync(data: any) {
|
|
130
|
+
try {
|
|
131
|
+
let circuit = this.circuit;
|
|
132
|
+
}
|
|
133
|
+
catch (err) { logger.error(`Nixie setCircuitAsync: ${err.message}`); return Promise.reject(err); }
|
|
134
|
+
}
|
|
135
|
+
public async sendOnOffSequenceAsync(count: number | { isOn: boolean, timeout: number }[], timeout?:number): Promise<InterfaceServerResponse> {
|
|
136
|
+
try {
|
|
137
|
+
this._sequencing = true;
|
|
138
|
+
let arr = [];
|
|
139
|
+
if (typeof count === 'number') {
|
|
140
|
+
let t = typeof timeout === 'undefined' ? 100 : timeout;
|
|
141
|
+
arr.push({ isOn: false, timeout: t }); // This may not be needed but we always need to start from off.
|
|
142
|
+
//[{ isOn: true, timeout: 1000 }, { isOn: false, timeout: 1000 }]
|
|
143
|
+
for (let i = 0; i < count; i++) {
|
|
144
|
+
arr.push({ isOn: true, timeout: t });
|
|
145
|
+
if (i < count - 1) arr.push({ isOn: false, timeout: t });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else arr = count;
|
|
149
|
+
// The documentation for IntelliBrite is incorrect. The sequence below will give us Party mode.
|
|
150
|
+
// Party mode:2
|
|
151
|
+
// Start: Off
|
|
152
|
+
// On
|
|
153
|
+
// Off
|
|
154
|
+
// On
|
|
155
|
+
// According to the docs this is the sequence they lay out.
|
|
156
|
+
// Party mode:2
|
|
157
|
+
// Start: On
|
|
158
|
+
// Off
|
|
159
|
+
// On
|
|
160
|
+
// Off
|
|
161
|
+
// On
|
|
162
|
+
|
|
163
|
+
let res = await NixieEquipment.putDeviceService(this.circuit.connectionId, `/state/device/${this.circuit.deviceBinding}`, arr, 60000);
|
|
164
|
+
return res;
|
|
165
|
+
} catch (err) { logger.error(`Nixie: Error sending circuit sequence ${this.id}: ${count}`); }
|
|
166
|
+
finally { this._sequencing = false; }
|
|
167
|
+
}
|
|
168
|
+
public async setThemeAsync(cstate: ICircuitState, theme: number): Promise<InterfaceServerResponse> {
|
|
169
|
+
try {
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
return new InterfaceServerResponse(200, 'Sucess');
|
|
174
|
+
} catch (err) { logger.error(`Nixie: Error setting light theme ${cstate.id}-${cstate.name} to ${theme}`); }
|
|
175
|
+
}
|
|
176
|
+
public async setCircuitStateAsync(cstate: ICircuitState, val: boolean, scheduled: boolean = false): Promise<InterfaceServerResponse> {
|
|
177
|
+
try {
|
|
178
|
+
if (val !== cstate.isOn) {
|
|
179
|
+
logger.info(`NCP: Setting Circuit ${cstate.name} to ${val}`);
|
|
180
|
+
if (cstate.isOn && val) {
|
|
181
|
+
// We are already on so lets check the egg timer and shut it off if it has expired.
|
|
182
|
+
let eggOff = this.eggTimerOff;
|
|
183
|
+
if (typeof eggOff !== 'undefined' && eggOff.getTime() <= new Date().getTime()) val = false;
|
|
184
|
+
}
|
|
185
|
+
// Check to see if we should be on by poking the schedules.
|
|
186
|
+
}
|
|
187
|
+
if (utils.isNullOrEmpty(this.circuit.connectionId) || utils.isNullOrEmpty(this.circuit.deviceBinding)) {
|
|
188
|
+
if (val && val !== cstate.isOn){
|
|
189
|
+
sys.board.circuits.setEndTime(sys.circuits.getInterfaceById(cstate.id), cstate, val);
|
|
190
|
+
}
|
|
191
|
+
else if (!val){
|
|
192
|
+
if (cstate.manualPriorityActive) delayMgr.cancelManualPriorityDelay(cstate.id);
|
|
193
|
+
cstate.manualPriorityActive = false; // if the delay was previously cancelled, still need to turn this off
|
|
194
|
+
}
|
|
195
|
+
cstate.isOn = val;
|
|
196
|
+
return new InterfaceServerResponse(200, 'Success');
|
|
197
|
+
}
|
|
198
|
+
if (this._sequencing) return new InterfaceServerResponse(200, 'Success');
|
|
199
|
+
let res = await NixieEquipment.putDeviceService(this.circuit.connectionId, `/state/device/${this.circuit.deviceBinding}`, { isOn: val, latch: val ? 10000 : undefined });
|
|
200
|
+
if (res.status.code === 200) {
|
|
201
|
+
// Set this up so we can process our egg timer.
|
|
202
|
+
//if (!cstate.isOn && val) { cstate.startTime = this.timeOn = new Timestamp(); }
|
|
203
|
+
//else if (!val) cstate.startTime = this.timeOn = undefined;
|
|
204
|
+
if (val && val !== cstate.isOn){
|
|
205
|
+
sys.board.circuits.setEndTime(sys.circuits.getInterfaceById(cstate.id), cstate, val);
|
|
206
|
+
}
|
|
207
|
+
else if (!val){
|
|
208
|
+
delayMgr.cancelManualPriorityDelays();
|
|
209
|
+
cstate.manualPriorityActive = false; // if the delay was previously cancelled, still need to turn this off
|
|
210
|
+
}
|
|
211
|
+
cstate.isOn = val;
|
|
212
|
+
}
|
|
213
|
+
return res;
|
|
214
|
+
} catch (err) { logger.error(`Nixie: Error setting circuit state ${cstate.id}-${cstate.name} to ${val}`); }
|
|
215
|
+
}
|
|
216
|
+
public async checkCircuitEggTimerExpirationAsync(cstate: ICircuitState) {
|
|
217
|
+
// if circuit end time is past current time, either the schedule is finished
|
|
218
|
+
// (this should already be turned off) or the egg timer has expired
|
|
219
|
+
try {
|
|
220
|
+
if (!cstate.isActive || !cstate.isOn) return;
|
|
221
|
+
if (typeof cstate.endTime !== 'undefined') {
|
|
222
|
+
if (cstate.endTime.toDate() < new Timestamp().toDate()) {
|
|
223
|
+
await sys.board.circuits.setCircuitStateAsync(cstate.id, false);
|
|
224
|
+
cstate.emitEquipmentChange();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
} catch (err) { logger.error(`Error syncing circuit: ${err}`); }
|
|
228
|
+
}
|
|
229
|
+
private async checkHardwareStatusAsync(connectionId: string, deviceBinding: string) {
|
|
230
|
+
try {
|
|
231
|
+
let dev = await NixieEquipment.getDeviceService(connectionId, `/status/device/${deviceBinding}`);
|
|
232
|
+
return dev;
|
|
233
|
+
} catch (err) { logger.error(`Nixie Circuit checkHardwareStatusAsync: ${err.message}`); return { hasFault: true } }
|
|
234
|
+
}
|
|
235
|
+
public async validateSetupAsync(circuit: Circuit, cstate: CircuitState) {
|
|
236
|
+
try {
|
|
237
|
+
if (typeof circuit.connectionId !== 'undefined' && circuit.connectionId !== ''
|
|
238
|
+
&& typeof circuit.deviceBinding !== 'undefined' && circuit.deviceBinding !== '') {
|
|
239
|
+
try {
|
|
240
|
+
let stat = await this.checkHardwareStatusAsync(circuit.connectionId, circuit.deviceBinding);
|
|
241
|
+
// If we have a status check the return.
|
|
242
|
+
cstate.commStatus = stat.hasFault ? 1 : 0;
|
|
243
|
+
} catch (err) { cstate.commStatus = 1; }
|
|
244
|
+
}
|
|
245
|
+
else
|
|
246
|
+
cstate.commStatus = 0;
|
|
247
|
+
// The validation will be different if the circuit is on or not. So lets get that information.
|
|
248
|
+
} catch (err) { logger.error(`Nixie Error checking Circuit Hardware ${this.circuit.name}: ${err.message}`); cstate.commStatus = 1; return Promise.reject(err); }
|
|
249
|
+
}
|
|
250
|
+
public async closeAsync() {
|
|
251
|
+
try {
|
|
252
|
+
let cstate = state.circuits.getItemById(this.circuit.id);
|
|
253
|
+
cstate.stopDelay = false;
|
|
254
|
+
cstate.startDelay = false;
|
|
255
|
+
await this.setCircuitStateAsync(cstate, false);
|
|
256
|
+
cstate.emitEquipmentChange();
|
|
257
|
+
}
|
|
258
|
+
catch (err) { logger.error(`Nixie Circuit closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
259
|
+
}
|
|
260
|
+
public logData(filename: string, data: any) { this.controlPanel.logData(filename, data); }
|
|
261
|
+
}
|