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.
Files changed (85) hide show
  1. package/.eslintrc.json +44 -44
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +52 -52
  3. package/CONTRIBUTING.md +74 -74
  4. package/Changelog +215 -195
  5. package/Dockerfile +17 -17
  6. package/Gruntfile.js +40 -40
  7. package/LICENSE +661 -661
  8. package/README.md +191 -186
  9. package/app.ts +2 -0
  10. package/config/Config.ts +27 -2
  11. package/config/VersionCheck.ts +33 -14
  12. package/config copy.json +299 -299
  13. package/controller/Constants.ts +88 -0
  14. package/controller/Equipment.ts +2459 -2225
  15. package/controller/Errors.ts +180 -157
  16. package/controller/Lockouts.ts +437 -0
  17. package/controller/State.ts +364 -79
  18. package/controller/boards/BoardFactory.ts +45 -45
  19. package/controller/boards/EasyTouchBoard.ts +2653 -2489
  20. package/controller/boards/IntelliCenterBoard.ts +4230 -3973
  21. package/controller/boards/IntelliComBoard.ts +63 -63
  22. package/controller/boards/IntelliTouchBoard.ts +241 -167
  23. package/controller/boards/NixieBoard.ts +1675 -1105
  24. package/controller/boards/SystemBoard.ts +4697 -3201
  25. package/controller/comms/Comms.ts +222 -10
  26. package/controller/comms/messages/Messages.ts +13 -9
  27. package/controller/comms/messages/config/ChlorinatorMessage.ts +13 -4
  28. package/controller/comms/messages/config/CircuitGroupMessage.ts +6 -0
  29. package/controller/comms/messages/config/CircuitMessage.ts +0 -0
  30. package/controller/comms/messages/config/ConfigMessage.ts +0 -0
  31. package/controller/comms/messages/config/CoverMessage.ts +1 -0
  32. package/controller/comms/messages/config/CustomNameMessage.ts +30 -30
  33. package/controller/comms/messages/config/EquipmentMessage.ts +4 -0
  34. package/controller/comms/messages/config/ExternalMessage.ts +53 -33
  35. package/controller/comms/messages/config/FeatureMessage.ts +8 -1
  36. package/controller/comms/messages/config/GeneralMessage.ts +8 -0
  37. package/controller/comms/messages/config/HeaterMessage.ts +14 -28
  38. package/controller/comms/messages/config/IntellichemMessage.ts +4 -1
  39. package/controller/comms/messages/config/OptionsMessage.ts +38 -2
  40. package/controller/comms/messages/config/PumpMessage.ts +4 -20
  41. package/controller/comms/messages/config/RemoteMessage.ts +4 -0
  42. package/controller/comms/messages/config/ScheduleMessage.ts +347 -331
  43. package/controller/comms/messages/config/SecurityMessage.ts +1 -0
  44. package/controller/comms/messages/config/ValveMessage.ts +13 -3
  45. package/controller/comms/messages/status/ChlorinatorStateMessage.ts +2 -3
  46. package/controller/comms/messages/status/EquipmentStateMessage.ts +79 -25
  47. package/controller/comms/messages/status/HeaterStateMessage.ts +86 -53
  48. package/controller/comms/messages/status/IntelliChemStateMessage.ts +445 -386
  49. package/controller/comms/messages/status/IntelliValveStateMessage.ts +35 -35
  50. package/controller/comms/messages/status/PumpStateMessage.ts +0 -0
  51. package/controller/comms/messages/status/VersionMessage.ts +0 -0
  52. package/controller/nixie/Nixie.ts +162 -160
  53. package/controller/nixie/NixieEquipment.ts +103 -103
  54. package/controller/nixie/bodies/Body.ts +120 -117
  55. package/controller/nixie/bodies/Filter.ts +135 -135
  56. package/controller/nixie/chemistry/ChemController.ts +2498 -2395
  57. package/controller/nixie/chemistry/Chlorinator.ts +314 -313
  58. package/controller/nixie/circuits/Circuit.ts +248 -210
  59. package/controller/nixie/heaters/Heater.ts +649 -441
  60. package/controller/nixie/pumps/Pump.ts +661 -599
  61. package/controller/nixie/schedules/Schedule.ts +257 -256
  62. package/controller/nixie/valves/Valve.ts +170 -170
  63. package/defaultConfig.json +286 -271
  64. package/issue_template.md +51 -51
  65. package/logger/DataLogger.ts +448 -433
  66. package/logger/Logger.ts +0 -0
  67. package/package.json +56 -54
  68. package/tsconfig.json +25 -25
  69. package/web/Server.ts +522 -31
  70. package/web/bindings/influxDB.json +1022 -894
  71. package/web/bindings/mqtt.json +654 -543
  72. package/web/bindings/mqttAlt.json +684 -574
  73. package/web/bindings/rulesManager.json +54 -54
  74. package/web/bindings/smartThings-Hubitat.json +31 -31
  75. package/web/bindings/valveRelays.json +20 -20
  76. package/web/bindings/vera.json +25 -25
  77. package/web/interfaces/baseInterface.ts +136 -136
  78. package/web/interfaces/httpInterface.ts +124 -122
  79. package/web/interfaces/influxInterface.ts +245 -240
  80. package/web/interfaces/mqttInterface.ts +475 -464
  81. package/web/services/config/Config.ts +181 -152
  82. package/web/services/config/ConfigSocket.ts +0 -0
  83. package/web/services/state/State.ts +118 -7
  84. package/web/services/state/StateSocket.ts +18 -1
  85. package/web/services/utilities/Utilities.ts +42 -42
@@ -1,36 +1,36 @@
1
- /* nodejs-poolController. An application to control pool equipment.
2
- Copyright (C) 2016, 2017, 2018, 2019, 2020. Russell Goldin, tagyoureit. russ.goldin@gmail.com
3
-
4
- This program is free software: you can redistribute it and/or modify
5
- it under the terms of the GNU Affero General Public License as
6
- published by the Free Software Foundation, either version 3 of the
7
- License, or (at your option) any later version.
8
-
9
- This program is distributed in the hope that it will be useful,
10
- but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- GNU Affero General Public License for more details.
13
-
14
- You should have received a copy of the GNU Affero General Public License
15
- along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- */
17
- import { Inbound } from "../Messages";
18
- import { state } from "../../../State";
19
- import { sys, ControllerType } from "../../../Equipment";
20
- import { logger } from "../../../../logger/Logger";
21
-
22
- export class IntelliValveStateMessage {
23
- public static process(msg: Inbound) {
24
- if (sys.controllerType === ControllerType.Unknown) return;
25
- // We only want to process the messages that are coming from IntelliValve.
26
- if (msg.source !== 12) return;
27
- switch (msg.action) {
28
- case 82: // This is hail from the valve that says it is not bound yet.
29
- break;
30
- default:
31
- logger.info(`IntelliValve sent an unknown action ${msg.action}`);
32
- break;
33
- }
34
- state.emitEquipmentChanges();
35
- }
1
+ /* nodejs-poolController. An application to control pool equipment.
2
+ Copyright (C) 2016, 2017, 2018, 2019, 2020. Russell Goldin, tagyoureit. russ.goldin@gmail.com
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ import { Inbound } from "../Messages";
18
+ import { state } from "../../../State";
19
+ import { sys, ControllerType } from "../../../Equipment";
20
+ import { logger } from "../../../../logger/Logger";
21
+
22
+ export class IntelliValveStateMessage {
23
+ public static process(msg: Inbound) {
24
+ if (sys.controllerType === ControllerType.Unknown) return;
25
+ // We only want to process the messages that are coming from IntelliValve.
26
+ if (msg.source !== 12) return;
27
+ switch (msg.action) {
28
+ case 82: // This is hail from the valve that says it is not bound yet.
29
+ break;
30
+ default:
31
+ logger.info(`IntelliValve sent an unknown action ${msg.action}`);
32
+ break;
33
+ }
34
+ state.emitEquipmentChanges();
35
+ }
36
36
  }
@@ -1,161 +1,163 @@
1
- import * as path from 'path';
2
- import * as fs from 'fs';
3
- import * as os from 'os';
4
- import { webApp } from "../../web/Server";
5
- import { logger } from "../../logger/Logger";
6
- import { INixieControlPanel } from "./NixieEquipment";
7
- import { NixieChemControllerCollection } from "./chemistry/ChemController";
8
-
9
- import { sys, PoolSystem } from "../../controller/Equipment";
10
- import { NixieCircuitCollection } from './circuits/Circuit';
11
- import { NixieBodyCollection } from './bodies/Body';
12
- import { NixieValveCollection } from './valves/Valve';
13
- import { NixieHeaterCollection } from './heaters/Heater';
14
- import { config } from '../../config/Config';
15
- import { NixieFilterCollection } from './bodies/Filter';
16
- import { NixieChlorinatorCollection } from './chemistry/Chlorinator';
17
- import { NixiePump, NixiePumpCollection } from './pumps/Pump';
18
- import { NixieScheduleCollection } from './schedules/Schedule';
19
-
20
- /************************************************************************
21
- * Nixie: Nixie is a control panel that controls devices as a master. It
22
- * can extend an existing *Touch or Center control panel. Or it can run
23
- * standalone as a master controller. The NixieControlPanel will always
24
- * be instantiated to control equipment when that equipment is not
25
- * supported or controlled by a traditional OCP. However, if a traditional
26
- * OCP exists, it will be subordinate to that OCP in regard to controlling
27
- * pool bodies.
28
- *
29
- * Equipment: Equipment identified as ncp (Nixie Control Panel) will be
30
- * managed by the Nixie controller. It works hand-in-glove with the REM
31
- * (Relay Equipment Manager) to provide low level hardware support.
32
- *
33
- * RS485: RS485 occurs directly within nixie through the standard RS485
34
- * bus identified for njspc and does not route through REM. This is an
35
- * important distinction to provide robust hardware level communication.
36
- * Items Controlled on this channel include: Pumps, Chlorinators, and
37
- * IntelliChem controllers. When and if IntelliValve functions become
38
- * available these too will be performed through the njspc RS485 bus.
39
- *
40
- * Configuration and State Management:
41
- * Nixie uses the underlying njspc configuration structures. The intent
42
- * is not to replace these rather the intention is to extend them with
43
- * low level control. For this reason, only when a Nixie is the only
44
- * master controller on the pool do commands get routed through NixieBoard.
45
- * this mode is identified at startup. When a particular piece of equipment
46
- * is identified to be controlled by Nixie as a master then the command
47
- * will eventually be marshalled to the NixieControlPanel. Any connected
48
- * OCP will get first crack at it.
49
- *
50
- * LifeCycle: The Nixie controller does not persist data outside of
51
- * the PoolConfig.json and PoolState.json files. It is initialized
52
- * at startup and torn down when the application is stopped.
53
- * */
54
- export class NixieControlPanel implements INixieControlPanel {
55
- // Only equipment controlled by Nixie is represented on the controller. If interaction with
56
- // other equipment is required this should be sent back through the original controller.
57
- // Command sequence is <OCP>Board -> SystemBoard -> NixieController whenever the master is not identified as Nixie.
58
- chemControllers: NixieChemControllerCollection = new NixieChemControllerCollection(this);
59
- chlorinators: NixieChlorinatorCollection = new NixieChlorinatorCollection(this);
60
- circuits: NixieCircuitCollection = new NixieCircuitCollection(this);
61
- bodies: NixieBodyCollection = new NixieBodyCollection(this);
62
- filters: NixieFilterCollection = new NixieFilterCollection(this);
63
- valves: NixieValveCollection = new NixieValveCollection(this);
64
- heaters: NixieHeaterCollection = new NixieHeaterCollection(this);
65
- pumps: NixiePumpCollection = new NixiePumpCollection(this);
66
- schedules: NixieScheduleCollection = new NixieScheduleCollection(this);
67
-
68
- public async initAsync(equipment: PoolSystem) {
69
- try {
70
-
71
- // We need to tell Nixie what her place is. If there is an existing OCP she needs to be a partner. However, if
72
- // she is the only master then she needs to step up and take command. The way we will signify this is
73
- // by using settings in config.json.
74
- // The controller types define the number of bodies and whether they are shared.
75
- logger.info(`Initializing Nixie Controller`);
76
- await this.bodies.initAsync(equipment.bodies);
77
- await this.filters.initAsync(equipment.filters);
78
- await this.circuits.initAsync(equipment.circuits);
79
- await this.valves.initAsync(equipment.valves);
80
- await this.heaters.initAsync(equipment.heaters);
81
- await this.chlorinators.initAsync(equipment.chlorinators);
82
- await this.chemControllers.initAsync(equipment.chemControllers);
83
- await this.pumps.initAsync(equipment.pumps);
84
- await this.schedules.initAsync(equipment.schedules);
85
- logger.info(`Nixie Controller Initialized`)
86
- }
87
- catch (err) { return Promise.reject(err); }
88
- }
89
- public async readLogFile(logFile: string): Promise<string[]> {
90
- try {
91
- let logPath = path.join(process.cwd(), '/logs');
92
- if (!fs.existsSync(logPath)) fs.mkdirSync(logPath);
93
- logPath += (`/${logFile}`);
94
- let lines = [];
95
- if (fs.existsSync(logPath)) {
96
- let buff = fs.readFileSync(logPath);
97
- lines = buff.toString().split('\n');
98
- }
99
- return lines;
100
- } catch (err) { logger.error(err); }
101
- }
102
- public async logData(logFile: string, data: any) {
103
- try {
104
- let logPath = path.join(process.cwd(), '/logs');
105
- if (!fs.existsSync(logPath)) fs.mkdirSync(logPath);
106
- logPath += (`/${logFile}`);
107
- let lines = [];
108
- if (fs.existsSync(logPath)) {
109
- let buff = fs.readFileSync(logPath);
110
- lines = buff.toString().split('\n');
111
- }
112
- if (typeof data === 'object')
113
- lines.unshift(JSON.stringify(data));
114
- else
115
- lines.unshift(data.toString());
116
- fs.writeFileSync(logPath, lines.join('\n'));
117
- } catch (err) { logger.error(err); }
118
- }
119
- public async closeAsync() {
120
- // Close all the associated equipment.
121
- await this.pumps.closeAsync();
122
- await this.chemControllers.closeAsync();
123
- await this.chlorinators.closeAsync();
124
- await this.heaters.closeAsync();
125
- await this.circuits.closeAsync();
126
- await this.filters.closeAsync();
127
- await this.bodies.closeAsync();
128
- await this.valves.closeAsync();
129
- }
130
- /*
131
- * This method is used to obtain a list of existing REM servers for configuration. This returns all servers and
132
- * their potential devices and is not designed to be used at run-time or to detect failure.
133
- *
134
- */
135
- public async getREMServers() {
136
- try {
137
- let srv = [];
138
- let servers = webApp.findServersByType('rem');
139
- for (let i = 0; i < servers.length; i++) {
140
- let server = servers[i];
141
- // Sometimes I hate type safety.
142
- let devices = typeof server['getDevices'] === 'function' ? await server['getDevices']() : [];
143
- let int = config.getInterfaceByUuid(servers[i].uuid);
144
- srv.push({
145
- uuid: servers[i].uuid,
146
- name: servers[i].name,
147
- type: servers[i].type,
148
- isRunning: servers[i].isRunning,
149
- isConnected: servers[i].isConnected,
150
- devices: devices,
151
- remoteConnectionId: servers[i].remoteConnectionId,
152
- interface: int
153
- });
154
- }
155
- await ncp.chemControllers.syncRemoteREMFeeds(srv);
156
- return srv;
157
- } catch (err) { logger.error(err); }
158
- }
159
- }
160
-
1
+ import * as path from 'path';
2
+ import * as fs from 'fs';
3
+ import * as os from 'os';
4
+ import { webApp } from "../../web/Server";
5
+ import { logger } from "../../logger/Logger";
6
+ import { INixieControlPanel } from "./NixieEquipment";
7
+ import { NixieChemControllerCollection } from "./chemistry/ChemController";
8
+
9
+ import { sys, PoolSystem } from "../../controller/Equipment";
10
+ import { NixieCircuitCollection } from './circuits/Circuit';
11
+ import { NixieBodyCollection } from './bodies/Body';
12
+ import { NixieValveCollection } from './valves/Valve';
13
+ import { NixieHeaterCollection } from './heaters/Heater';
14
+ import { config } from '../../config/Config';
15
+ import { NixieFilterCollection } from './bodies/Filter';
16
+ import { NixieChlorinatorCollection } from './chemistry/Chlorinator';
17
+ import { NixiePump, NixiePumpCollection } from './pumps/Pump';
18
+ import { NixieScheduleCollection } from './schedules/Schedule';
19
+
20
+ /************************************************************************
21
+ * Nixie: Nixie is a control panel that controls devices as a master. It
22
+ * can extend an existing *Touch or Center control panel. Or it can run
23
+ * standalone as a master controller. The NixieControlPanel will always
24
+ * be instantiated to control equipment when that equipment is not
25
+ * supported or controlled by a traditional OCP. However, if a traditional
26
+ * OCP exists, it will be subordinate to that OCP in regard to controlling
27
+ * pool bodies.
28
+ *
29
+ * Equipment: Equipment identified as ncp (Nixie Control Panel) will be
30
+ * managed by the Nixie controller. It works hand-in-glove with the REM
31
+ * (Relay Equipment Manager) to provide low level hardware support.
32
+ *
33
+ * RS485: RS485 occurs directly within nixie through the standard RS485
34
+ * bus identified for njspc and does not route through REM. This is an
35
+ * important distinction to provide robust hardware level communication.
36
+ * Items Controlled on this channel include: Pumps, Chlorinators, and
37
+ * IntelliChem controllers. When and if IntelliValve functions become
38
+ * available these too will be performed through the njspc RS485 bus.
39
+ *
40
+ * Configuration and State Management:
41
+ * Nixie uses the underlying njspc configuration structures. The intent
42
+ * is not to replace these rather the intention is to extend them with
43
+ * low level control. For this reason, only when a Nixie is the only
44
+ * master controller on the pool do commands get routed through NixieBoard.
45
+ * this mode is identified at startup. When a particular piece of equipment
46
+ * is identified to be controlled by Nixie as a master then the command
47
+ * will eventually be marshalled to the NixieControlPanel. Any connected
48
+ * OCP will get first crack at it.
49
+ *
50
+ * LifeCycle: The Nixie controller does not persist data outside of
51
+ * the PoolConfig.json and PoolState.json files. It is initialized
52
+ * at startup and torn down when the application is stopped.
53
+ * */
54
+ export class NixieControlPanel implements INixieControlPanel {
55
+ // Only equipment controlled by Nixie is represented on the controller. If interaction with
56
+ // other equipment is required this should be sent back through the original controller.
57
+ // Command sequence is <OCP>Board -> SystemBoard -> NixieController whenever the master is not identified as Nixie.
58
+ chemControllers: NixieChemControllerCollection = new NixieChemControllerCollection(this);
59
+ chlorinators: NixieChlorinatorCollection = new NixieChlorinatorCollection(this);
60
+ circuits: NixieCircuitCollection = new NixieCircuitCollection(this);
61
+ bodies: NixieBodyCollection = new NixieBodyCollection(this);
62
+ filters: NixieFilterCollection = new NixieFilterCollection(this);
63
+ valves: NixieValveCollection = new NixieValveCollection(this);
64
+ heaters: NixieHeaterCollection = new NixieHeaterCollection(this);
65
+ pumps: NixiePumpCollection = new NixiePumpCollection(this);
66
+ schedules: NixieScheduleCollection = new NixieScheduleCollection(this);
67
+
68
+ public async initAsync(equipment: PoolSystem) {
69
+ try {
70
+
71
+ // We need to tell Nixie what her place is. If there is an existing OCP she needs to be a partner. However, if
72
+ // she is the only master then she needs to step up and take command. The way we will signify this is
73
+ // by using settings in config.json.
74
+ // The controller types define the number of bodies and whether they are shared.
75
+ logger.info(`Initializing Nixie Controller`);
76
+ await this.bodies.initAsync(equipment.bodies);
77
+ await this.filters.initAsync(equipment.filters);
78
+ await this.circuits.initAsync(equipment.circuits);
79
+ await this.valves.initAsync(equipment.valves);
80
+ await this.heaters.initAsync(equipment.heaters);
81
+ await this.chlorinators.initAsync(equipment.chlorinators);
82
+ await this.chemControllers.initAsync(equipment.chemControllers);
83
+ await this.pumps.initAsync(equipment.pumps);
84
+ await this.schedules.initAsync(equipment.schedules);
85
+ logger.info(`Nixie Controller Initialized`)
86
+ }
87
+ catch (err) { return Promise.reject(err); }
88
+ }
89
+ public async readLogFile(logFile: string): Promise<string[]> {
90
+ try {
91
+ let logPath = path.join(process.cwd(), '/logs');
92
+ if (!fs.existsSync(logPath)) fs.mkdirSync(logPath);
93
+ logPath += (`/${logFile}`);
94
+ let lines = [];
95
+ if (fs.existsSync(logPath)) {
96
+ let buff = fs.readFileSync(logPath);
97
+ lines = buff.toString().split('\n');
98
+ }
99
+ return lines;
100
+ } catch (err) { logger.error(err); }
101
+ }
102
+ public async logData(logFile: string, data: any) {
103
+ try {
104
+ let logPath = path.join(process.cwd(), '/logs');
105
+ if (!fs.existsSync(logPath)) fs.mkdirSync(logPath);
106
+ logPath += (`/${logFile}`);
107
+ let lines = [];
108
+ if (fs.existsSync(logPath)) {
109
+ let buff = fs.readFileSync(logPath);
110
+ lines = buff.toString().split('\n');
111
+ }
112
+ if (typeof data === 'object')
113
+ lines.unshift(JSON.stringify(data));
114
+ else
115
+ lines.unshift(data.toString());
116
+ fs.writeFileSync(logPath, lines.join('\n'));
117
+ } catch (err) { logger.error(err); }
118
+ }
119
+ public async closeAsync() {
120
+ // Close all the associated equipment.
121
+ await this.pumps.closeAsync();
122
+ await this.chemControllers.closeAsync();
123
+ await this.chlorinators.closeAsync();
124
+ await this.heaters.closeAsync();
125
+ await this.circuits.closeAsync();
126
+ await this.filters.closeAsync();
127
+ await this.bodies.closeAsync();
128
+ await this.valves.closeAsync();
129
+ }
130
+ /*
131
+ * This method is used to obtain a list of existing REM servers for configuration. This returns all servers and
132
+ * their potential devices and is not designed to be used at run-time or to detect failure.
133
+ *
134
+ */
135
+ public async getREMServers() {
136
+ try {
137
+ let srv = [];
138
+ let servers = webApp.findServersByType('rem');
139
+ if (typeof servers !== 'undefined') {
140
+ for (let i = 0; i < servers.length; i++) {
141
+ let server = servers[i];
142
+ // Sometimes I hate type safety.
143
+ let devices = typeof server['getDevices'] === 'function' ? await server['getDevices']() : [];
144
+ let int = config.getInterfaceByUuid(servers[i].uuid);
145
+ srv.push({
146
+ uuid: servers[i].uuid,
147
+ name: servers[i].name,
148
+ type: servers[i].type,
149
+ isRunning: servers[i].isRunning,
150
+ isConnected: servers[i].isConnected,
151
+ devices: devices,
152
+ remoteConnectionId: servers[i].remoteConnectionId,
153
+ interface: int
154
+ });
155
+ }
156
+ await ncp.chemControllers.syncRemoteREMFeeds(srv);
157
+ }
158
+ return srv;
159
+ } catch (err) { logger.error(err); }
160
+ }
161
+ }
162
+
161
163
  export let ncp = new NixieControlPanel();
@@ -1,104 +1,104 @@
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
- else
91
- logger.warn(`A Nixie equipment item was not found with id ${id}. Equipment not removed.`);
92
- }
93
- catch (err) { return Promise.reject(err); }
94
- }
95
- }
96
- //export class NixieRelay extends NixieEquipment {
97
-
98
- //}
99
- //export class NixieCircuit extends NixieRelay {
100
-
101
- //}
102
- //export class NixieValve extends NixieRelay {
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
+ }
90
+ else
91
+ logger.warn(`A Nixie equipment item was not found with id ${id}. Equipment not removed.`);
92
+ }
93
+ catch (err) { return Promise.reject(err); }
94
+ }
95
+ }
96
+ //export class NixieRelay extends NixieEquipment {
97
+
98
+ //}
99
+ //export class NixieCircuit extends NixieRelay {
100
+
101
+ //}
102
+ //export class NixieValve extends NixieRelay {
103
+
104
104
  //}