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,117 +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 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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
bstate.isOn
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
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,135 +1,135 @@
|
|
|
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 { Filter, FilterCollection, sys } from "../../../controller/Equipment";
|
|
7
|
-
import { FilterState, 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 NixieFilterCollection extends NixieEquipmentCollection<NixieFilter> {
|
|
13
|
-
public async setFilterStateAsync(fstate: FilterState, val: boolean) {
|
|
14
|
-
try {
|
|
15
|
-
let f: NixieFilter = this.find(elem => elem.id === fstate.id) as NixieFilter;
|
|
16
|
-
if (typeof f === 'undefined') return Promise.reject(new Error(`NCP: Filter ${fstate.id}-${fstate.name} could not be found to set the state to ${val}.`));
|
|
17
|
-
await f.setFilterStateAsync(fstate, val);
|
|
18
|
-
}
|
|
19
|
-
catch (err) { return logger.error(`NCP: setCircuitFilterAsync ${fstate.id}-${fstate.name}: ${err.message}`); }
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public async setFilterAsync(filter: Filter, data: any) {
|
|
23
|
-
// By the time we get here we know that we are in control and this is a REMChem.
|
|
24
|
-
try {
|
|
25
|
-
let c: NixieFilter = this.find(elem => elem.id === filter.id) as NixieFilter;
|
|
26
|
-
if (typeof c === 'undefined') {
|
|
27
|
-
filter.master = 1;
|
|
28
|
-
c = new NixieFilter(this.controlPanel, filter);
|
|
29
|
-
this.push(c);
|
|
30
|
-
await c.setFilterAsync(data);
|
|
31
|
-
logger.info(`A Filter was not found for id #${filter.id} creating Filter`);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
await c.setFilterAsync(data);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch (err) { logger.error(`setFilterAsync: ${err.message}`); return Promise.reject(err); }
|
|
38
|
-
}
|
|
39
|
-
public async initAsync(filters: FilterCollection) {
|
|
40
|
-
try {
|
|
41
|
-
this.length = 0;
|
|
42
|
-
for (let i = 0; i < filters.length; i++) {
|
|
43
|
-
let filter = filters.getItemByIndex(i);
|
|
44
|
-
if (filter.master === 1) {
|
|
45
|
-
if (typeof this.find(elem => elem.id === filter.id) === 'undefined') {
|
|
46
|
-
logger.info(`Initializing Filter ${Filter.name}`);
|
|
47
|
-
let nFilter = new NixieFilter(this.controlPanel, filter);
|
|
48
|
-
this.push(nFilter);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
catch (err) { logger.error(`Nixie Filter initAsync: ${err.message}`); return Promise.reject(err); }
|
|
54
|
-
}
|
|
55
|
-
public async closeAsync() {
|
|
56
|
-
try {
|
|
57
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
58
|
-
try {
|
|
59
|
-
await this[i].closeAsync();
|
|
60
|
-
this.splice(i, 1);
|
|
61
|
-
} catch (err) { logger.error(`Error stopping Nixie Filter ${err}`); }
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
} catch (err) { } // Don't bail if we have an errror.
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
export class NixieFilter extends NixieEquipment {
|
|
68
|
-
public pollingInterval: number = 10000;
|
|
69
|
-
private _pollTimer: NodeJS.Timeout = null;
|
|
70
|
-
private _lastState;
|
|
71
|
-
public filter: Filter;
|
|
72
|
-
constructor(ncp: INixieControlPanel, filter: Filter) {
|
|
73
|
-
super(ncp);
|
|
74
|
-
this.filter = filter;
|
|
75
|
-
this.pollEquipmentAsync();
|
|
76
|
-
}
|
|
77
|
-
public get id(): number { return typeof this.filter !== 'undefined' ? this.filter.id : -1; }
|
|
78
|
-
public async setFilterAsync(data: any) {
|
|
79
|
-
try {
|
|
80
|
-
let filter = this.filter;
|
|
81
|
-
}
|
|
82
|
-
catch (err) { logger.error(`Nixie setFilterAsync: ${err.message}`); return Promise.reject(err); }
|
|
83
|
-
}
|
|
84
|
-
public async setFilterStateAsync(fstate: FilterState, val: boolean): Promise<InterfaceServerResponse> {
|
|
85
|
-
try {
|
|
86
|
-
if (utils.isNullOrEmpty(this.filter.connectionId) || utils.isNullOrEmpty(this.filter.deviceBinding)) {
|
|
87
|
-
fstate.isOn = val;
|
|
88
|
-
return new InterfaceServerResponse(200, 'Success');
|
|
89
|
-
}
|
|
90
|
-
if (typeof this._lastState === 'undefined' || val || this._lastState !== val) {
|
|
91
|
-
let res = await NixieEquipment.putDeviceService(this.filter.connectionId, `/state/device/${this.filter.deviceBinding}`, { isOn: val, latch: val ? 10000 : undefined });
|
|
92
|
-
if (res.status.code === 200) this._lastState = fstate.isOn = val;
|
|
93
|
-
return res;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
fstate.isOn = val;
|
|
97
|
-
return new InterfaceServerResponse(200, 'Success');
|
|
98
|
-
}
|
|
99
|
-
} catch (err) { logger.error(`Nixie: Error setting filter state ${fstate.id}-${fstate.name} to ${val}`); }
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public async pollEquipmentAsync() {
|
|
103
|
-
let self = this;
|
|
104
|
-
try {
|
|
105
|
-
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
106
|
-
this._pollTimer = null;
|
|
107
|
-
let success = false;
|
|
108
|
-
}
|
|
109
|
-
catch (err) { logger.error(`Nixie Error polling Filter - ${err}`); }
|
|
110
|
-
finally { this._pollTimer = setTimeout(async () => await self.pollEquipmentAsync(), this.pollingInterval || 10000); }
|
|
111
|
-
}
|
|
112
|
-
private async checkHardwareStatusAsync(connectionId: string, deviceBinding: string) {
|
|
113
|
-
try {
|
|
114
|
-
let dev = await NixieEquipment.getDeviceService(connectionId, `/status/device/${deviceBinding}`);
|
|
115
|
-
return dev;
|
|
116
|
-
} catch (err) { logger.error(`Nixie Filter checkHardwareStatusAsync: ${err.message}`); return { hasFault: true } }
|
|
117
|
-
}
|
|
118
|
-
public async validateSetupAsync(Filter: Filter, temp: FilterState) {
|
|
119
|
-
try {
|
|
120
|
-
// The validation will be different if the Filter is on or not. So lets get that information.
|
|
121
|
-
} catch (err) { logger.error(`Nixie Error checking Filter Hardware ${this.filter.name}: ${err.message}`); return Promise.reject(err); }
|
|
122
|
-
}
|
|
123
|
-
public async closeAsync() {
|
|
124
|
-
try {
|
|
125
|
-
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
126
|
-
this._pollTimer = null;
|
|
127
|
-
let fstate = state.filters.getItemById(this.filter.id);
|
|
128
|
-
logger.info(`Closing filter ${fstate.name}`)
|
|
129
|
-
await this.setFilterStateAsync(fstate, false);
|
|
130
|
-
fstate.emitEquipmentChange();
|
|
131
|
-
}
|
|
132
|
-
catch (err) { logger.error(`Nixie Filter closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
133
|
-
}
|
|
134
|
-
public logData(filename: string, data: any) { this.controlPanel.logData(filename, data); }
|
|
135
|
-
}
|
|
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 { Filter, FilterCollection, sys } from "../../../controller/Equipment";
|
|
7
|
+
import { FilterState, 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 NixieFilterCollection extends NixieEquipmentCollection<NixieFilter> {
|
|
13
|
+
public async setFilterStateAsync(fstate: FilterState, val: boolean) {
|
|
14
|
+
try {
|
|
15
|
+
let f: NixieFilter = this.find(elem => elem.id === fstate.id) as NixieFilter;
|
|
16
|
+
if (typeof f === 'undefined') return Promise.reject(new Error(`NCP: Filter ${fstate.id}-${fstate.name} could not be found to set the state to ${val}.`));
|
|
17
|
+
await f.setFilterStateAsync(fstate, val);
|
|
18
|
+
}
|
|
19
|
+
catch (err) { return logger.error(`NCP: setCircuitFilterAsync ${fstate.id}-${fstate.name}: ${err.message}`); }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public async setFilterAsync(filter: Filter, data: any) {
|
|
23
|
+
// By the time we get here we know that we are in control and this is a REMChem.
|
|
24
|
+
try {
|
|
25
|
+
let c: NixieFilter = this.find(elem => elem.id === filter.id) as NixieFilter;
|
|
26
|
+
if (typeof c === 'undefined') {
|
|
27
|
+
filter.master = 1;
|
|
28
|
+
c = new NixieFilter(this.controlPanel, filter);
|
|
29
|
+
this.push(c);
|
|
30
|
+
await c.setFilterAsync(data);
|
|
31
|
+
logger.info(`A Filter was not found for id #${filter.id} creating Filter`);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
await c.setFilterAsync(data);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (err) { logger.error(`setFilterAsync: ${err.message}`); return Promise.reject(err); }
|
|
38
|
+
}
|
|
39
|
+
public async initAsync(filters: FilterCollection) {
|
|
40
|
+
try {
|
|
41
|
+
this.length = 0;
|
|
42
|
+
for (let i = 0; i < filters.length; i++) {
|
|
43
|
+
let filter = filters.getItemByIndex(i);
|
|
44
|
+
if (filter.master === 1) {
|
|
45
|
+
if (typeof this.find(elem => elem.id === filter.id) === 'undefined') {
|
|
46
|
+
logger.info(`Initializing Filter ${Filter.name}`);
|
|
47
|
+
let nFilter = new NixieFilter(this.controlPanel, filter);
|
|
48
|
+
this.push(nFilter);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (err) { logger.error(`Nixie Filter initAsync: ${err.message}`); return Promise.reject(err); }
|
|
54
|
+
}
|
|
55
|
+
public async closeAsync() {
|
|
56
|
+
try {
|
|
57
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
58
|
+
try {
|
|
59
|
+
await this[i].closeAsync();
|
|
60
|
+
this.splice(i, 1);
|
|
61
|
+
} catch (err) { logger.error(`Error stopping Nixie Filter ${err}`); }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
} catch (err) { } // Don't bail if we have an errror.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export class NixieFilter extends NixieEquipment {
|
|
68
|
+
public pollingInterval: number = 10000;
|
|
69
|
+
private _pollTimer: NodeJS.Timeout = null;
|
|
70
|
+
private _lastState;
|
|
71
|
+
public filter: Filter;
|
|
72
|
+
constructor(ncp: INixieControlPanel, filter: Filter) {
|
|
73
|
+
super(ncp);
|
|
74
|
+
this.filter = filter;
|
|
75
|
+
this.pollEquipmentAsync();
|
|
76
|
+
}
|
|
77
|
+
public get id(): number { return typeof this.filter !== 'undefined' ? this.filter.id : -1; }
|
|
78
|
+
public async setFilterAsync(data: any) {
|
|
79
|
+
try {
|
|
80
|
+
let filter = this.filter;
|
|
81
|
+
}
|
|
82
|
+
catch (err) { logger.error(`Nixie setFilterAsync: ${err.message}`); return Promise.reject(err); }
|
|
83
|
+
}
|
|
84
|
+
public async setFilterStateAsync(fstate: FilterState, val: boolean): Promise<InterfaceServerResponse> {
|
|
85
|
+
try {
|
|
86
|
+
if (utils.isNullOrEmpty(this.filter.connectionId) || utils.isNullOrEmpty(this.filter.deviceBinding)) {
|
|
87
|
+
fstate.isOn = val;
|
|
88
|
+
return new InterfaceServerResponse(200, 'Success');
|
|
89
|
+
}
|
|
90
|
+
if (typeof this._lastState === 'undefined' || val || this._lastState !== val) {
|
|
91
|
+
let res = await NixieEquipment.putDeviceService(this.filter.connectionId, `/state/device/${this.filter.deviceBinding}`, { isOn: val, latch: val ? 10000 : undefined });
|
|
92
|
+
if (res.status.code === 200) this._lastState = fstate.isOn = val;
|
|
93
|
+
return res;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
fstate.isOn = val;
|
|
97
|
+
return new InterfaceServerResponse(200, 'Success');
|
|
98
|
+
}
|
|
99
|
+
} catch (err) { logger.error(`Nixie: Error setting filter state ${fstate.id}-${fstate.name} to ${val}`); }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public async pollEquipmentAsync() {
|
|
103
|
+
let self = this;
|
|
104
|
+
try {
|
|
105
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
106
|
+
this._pollTimer = null;
|
|
107
|
+
let success = false;
|
|
108
|
+
}
|
|
109
|
+
catch (err) { logger.error(`Nixie Error polling Filter - ${err}`); }
|
|
110
|
+
finally { this._pollTimer = setTimeout(async () => await self.pollEquipmentAsync(), this.pollingInterval || 10000); }
|
|
111
|
+
}
|
|
112
|
+
private async checkHardwareStatusAsync(connectionId: string, deviceBinding: string) {
|
|
113
|
+
try {
|
|
114
|
+
let dev = await NixieEquipment.getDeviceService(connectionId, `/status/device/${deviceBinding}`);
|
|
115
|
+
return dev;
|
|
116
|
+
} catch (err) { logger.error(`Nixie Filter checkHardwareStatusAsync: ${err.message}`); return { hasFault: true } }
|
|
117
|
+
}
|
|
118
|
+
public async validateSetupAsync(Filter: Filter, temp: FilterState) {
|
|
119
|
+
try {
|
|
120
|
+
// The validation will be different if the Filter is on or not. So lets get that information.
|
|
121
|
+
} catch (err) { logger.error(`Nixie Error checking Filter Hardware ${this.filter.name}: ${err.message}`); return Promise.reject(err); }
|
|
122
|
+
}
|
|
123
|
+
public async closeAsync() {
|
|
124
|
+
try {
|
|
125
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
126
|
+
this._pollTimer = null;
|
|
127
|
+
let fstate = state.filters.getItemById(this.filter.id);
|
|
128
|
+
logger.info(`Closing filter ${fstate.name}`)
|
|
129
|
+
await this.setFilterStateAsync(fstate, false);
|
|
130
|
+
fstate.emitEquipmentChange();
|
|
131
|
+
}
|
|
132
|
+
catch (err) { logger.error(`Nixie Filter closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
133
|
+
}
|
|
134
|
+
public logData(filename: string, data: any) { this.controlPanel.logData(filename, data); }
|
|
135
|
+
}
|