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.
Files changed (91) hide show
  1. package/.eslintrc.json +44 -44
  2. package/.github/ISSUE_TEMPLATE/1-bug-report.yml +84 -0
  3. package/.github/ISSUE_TEMPLATE/2-docs.md +12 -0
  4. package/.github/ISSUE_TEMPLATE/3-proposal.md +28 -0
  5. package/.github/ISSUE_TEMPLATE/config.yml +8 -0
  6. package/CONTRIBUTING.md +74 -74
  7. package/Changelog +220 -215
  8. package/Dockerfile +17 -17
  9. package/Gruntfile.js +40 -40
  10. package/LICENSE +661 -661
  11. package/README.md +191 -191
  12. package/app.ts +1 -1
  13. package/config/Config.ts +14 -0
  14. package/config/VersionCheck.ts +2 -2
  15. package/controller/Constants.ts +2 -1
  16. package/controller/Equipment.ts +2484 -2459
  17. package/controller/Errors.ts +180 -180
  18. package/controller/Lockouts.ts +502 -436
  19. package/controller/State.ts +106 -30
  20. package/controller/boards/AquaLinkBoard.ts +1000 -0
  21. package/controller/boards/BoardFactory.ts +49 -45
  22. package/controller/boards/EasyTouchBoard.ts +2859 -2653
  23. package/controller/boards/IntelliCenterBoard.ts +4198 -4230
  24. package/controller/boards/IntelliComBoard.ts +63 -63
  25. package/controller/boards/IntelliTouchBoard.ts +273 -241
  26. package/controller/boards/NixieBoard.ts +1728 -1675
  27. package/controller/boards/SystemBoard.ts +4925 -4697
  28. package/controller/comms/Comms.ts +442 -479
  29. package/controller/comms/messages/Messages.ts +171 -25
  30. package/controller/comms/messages/config/ChlorinatorMessage.ts +5 -2
  31. package/controller/comms/messages/config/CircuitGroupMessage.ts +0 -0
  32. package/controller/comms/messages/config/CircuitMessage.ts +1 -0
  33. package/controller/comms/messages/config/ConfigMessage.ts +0 -0
  34. package/controller/comms/messages/config/CoverMessage.ts +0 -0
  35. package/controller/comms/messages/config/CustomNameMessage.ts +30 -30
  36. package/controller/comms/messages/config/EquipmentMessage.ts +0 -0
  37. package/controller/comms/messages/config/ExternalMessage.ts +0 -0
  38. package/controller/comms/messages/config/FeatureMessage.ts +0 -0
  39. package/controller/comms/messages/config/GeneralMessage.ts +0 -0
  40. package/controller/comms/messages/config/HeaterMessage.ts +142 -10
  41. package/controller/comms/messages/config/IntellichemMessage.ts +0 -0
  42. package/controller/comms/messages/config/OptionsMessage.ts +4 -21
  43. package/controller/comms/messages/config/PumpMessage.ts +53 -35
  44. package/controller/comms/messages/config/RemoteMessage.ts +0 -0
  45. package/controller/comms/messages/config/ScheduleMessage.ts +350 -347
  46. package/controller/comms/messages/config/SecurityMessage.ts +0 -0
  47. package/controller/comms/messages/config/ValveMessage.ts +1 -1
  48. package/controller/comms/messages/status/ChlorinatorStateMessage.ts +38 -86
  49. package/controller/comms/messages/status/EquipmentStateMessage.ts +58 -22
  50. package/controller/comms/messages/status/HeaterStateMessage.ts +116 -86
  51. package/controller/comms/messages/status/IntelliChemStateMessage.ts +445 -445
  52. package/controller/comms/messages/status/IntelliValveStateMessage.ts +35 -35
  53. package/controller/comms/messages/status/PumpStateMessage.ts +23 -1
  54. package/controller/comms/messages/status/VersionMessage.ts +0 -0
  55. package/controller/nixie/Nixie.ts +162 -162
  56. package/controller/nixie/NixieEquipment.ts +103 -103
  57. package/controller/nixie/bodies/Body.ts +120 -120
  58. package/controller/nixie/bodies/Filter.ts +135 -135
  59. package/controller/nixie/chemistry/ChemController.ts +2511 -2498
  60. package/controller/nixie/chemistry/Chlorinator.ts +363 -314
  61. package/controller/nixie/circuits/Circuit.ts +261 -248
  62. package/controller/nixie/heaters/Heater.ts +650 -648
  63. package/controller/nixie/pumps/Pump.ts +906 -661
  64. package/controller/nixie/schedules/Schedule.ts +313 -257
  65. package/controller/nixie/valves/Valve.ts +170 -170
  66. package/defaultConfig.json +306 -286
  67. package/logger/DataLogger.ts +448 -448
  68. package/logger/Logger.ts +0 -0
  69. package/package.json +56 -56
  70. package/tsconfig.json +25 -25
  71. package/web/Server.ts +92 -47
  72. package/web/bindings/aqualinkD.json +505 -0
  73. package/web/bindings/influxDB.json +1051 -1021
  74. package/web/bindings/mqtt.json +702 -654
  75. package/web/bindings/mqttAlt.json +731 -684
  76. package/web/bindings/rulesManager.json +54 -54
  77. package/web/bindings/smartThings-Hubitat.json +31 -31
  78. package/web/bindings/valveRelays.json +20 -20
  79. package/web/bindings/vera.json +25 -25
  80. package/web/interfaces/baseInterface.ts +137 -136
  81. package/web/interfaces/httpInterface.ts +145 -124
  82. package/web/interfaces/influxInterface.ts +276 -245
  83. package/web/interfaces/mqttInterface.ts +535 -475
  84. package/web/services/config/Config.ts +39 -18
  85. package/web/services/config/ConfigSocket.ts +0 -0
  86. package/web/services/state/State.ts +10 -0
  87. package/web/services/state/StateSocket.ts +4 -4
  88. package/web/services/utilities/Utilities.ts +44 -42
  89. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -52
  90. package/config copy.json +0 -300
  91. package/issue_template.md +0 -52
@@ -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
  }
@@ -55,7 +55,29 @@ export class PumpStateMessage {
55
55
  state.emitEquipmentChanges();
56
56
  // if (msg.action !== 7) this.processDirectPumpMessages(msg);
57
57
  }
58
-
58
+ public static processHayward(msg: Inbound) {
59
+ switch (msg.action) {
60
+ case 12:
61
+ PumpStateMessage.processHaywardStar(msg);
62
+ break;
63
+ }
64
+ }
65
+ public static processHaywardStar(msg: Inbound) {
66
+ // src act dest
67
+ //[0x10, 0x02, 0x00, 0x0C, 0x00][0x00, 0x62, 0x17, 0x81][0x01, 0x18, 0x10, 0x03]
68
+ //[0x10, 0x02, 0x00, 0x0C, 0x00][0x00, 0x2D, 0x02, 0x36][0x00, 0x83, 0x10, 0x03] -- Response from pump
69
+ let ptype = sys.board.valueMaps.pumpTypes.transformByName('hwvs');
70
+ let pump = sys.pumps.find(elem => elem.address === msg.source + 96 && elem.type === 6);
71
+ if (typeof pump !== 'undefined') {
72
+ let pstate = state.pumps.getItemById(pump.id, true);
73
+ // 3450 * .5
74
+ pstate.rpm = Math.round(ptype.maxSpeed * (msg.extractPayloadByte(1) / 100));
75
+ // This is really goofy as the watts are actually the hex string from the two bytes.
76
+ pstate.watts = parseInt(msg.extractPayloadByte(2).toString(16) + msg.extractPayloadByte(3).toString(16), 10);
77
+ pstate.isActive = true;
78
+ state.emitEquipmentChanges();
79
+ }
80
+ }
59
81
  public static processDirectPumpMessages(msg: Inbound) {
60
82
 
61
83
  if (msg.payload.length === 2)
@@ -1,163 +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
- 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
-
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.chemControllers.closeAsync();
122
+ await this.chlorinators.closeAsync();
123
+ await this.heaters.closeAsync();
124
+ await this.circuits.closeAsync();
125
+ await this.pumps.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
+
163
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
  //}