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,63 +1,63 @@
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 * as extend from 'extend';
18
- import { EventEmitter } from 'events';
19
- import { EasyTouchBoard } from './EasyTouchBoard';
20
- import { sys, PoolSystem } from '../Equipment';
21
- import { byteValueMap } from './SystemBoard';
22
- import { state } from '../State';
23
-
24
- export class IntelliComBoard extends EasyTouchBoard {
25
- constructor(system: PoolSystem) {
26
- super(system); // graph chain to EasyTouchBoard constructor.
27
- this.valueMaps.expansionBoards = new byteValueMap([
28
- [11, { name: 'INTCOM2', part: 'INTCOM2', desc: 'IntelliComm II', circuits: 6, shared: true }]
29
- ]);
30
- }
31
- public initExpansionModules(byte1: number, byte2: number) {
32
- console.log(`Pentair IntelliCom System Detected!`);
33
-
34
- sys.equipment.model = 'Suntouch/Intellicom';
35
-
36
- // Initialize the installed personality board.
37
- let mt = this.valueMaps.expansionBoards.transform(0);
38
- let mod = sys.equipment.modules.getItemById(0, true);
39
- mod.name = mt.name;
40
- mod.desc = mt.desc;
41
- mod.type = byte1;
42
- mod.part = mt.part;
43
- let eq = sys.equipment;
44
- let md = mod.get();
45
- eq.maxBodies = md.bodies = typeof mt.bodies !== 'undefined' ? mt.bodies : mt.shared ? 2 : 1;
46
- eq.maxCircuits = md.circuits = typeof mt.circuits !== 'undefined' ? mt.circuits : 4;
47
- eq.maxFeatures = md.features = typeof mt.features !== 'undefined' ? mt.features : 0
48
- eq.maxValves = md.valves = typeof mt.valves !== 'undefined' ? mt.valves : 2;
49
- eq.maxPumps = md.maxPumps = typeof mt.pumps !== 'undefined' ? mt.pumps : 2;
50
- eq.shared = mt.shared;
51
- eq.dual = false;
52
- eq.maxChlorinators = md.chlorinators = 1;
53
- eq.maxChemControllers = md.chemControllers = 1;
54
- eq.maxCustomNames = 10;
55
- // Calculate out the invalid ids.
56
- sys.board.equipmentIds.invalidIds.set([]);
57
- sys.board.equipmentIds.invalidIds.merge([5, 7, 8, 9, 13, 14, 15, 16, 17, 18])
58
- sys.equipment.model = mt.desc;
59
- this.initBodyDefaults();
60
- state.emitControllerChange();
61
- }
62
-
63
- }
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 * as extend from 'extend';
18
+ import { EventEmitter } from 'events';
19
+ import { EasyTouchBoard } from './EasyTouchBoard';
20
+ import { sys, PoolSystem } from '../Equipment';
21
+ import { byteValueMap } from './SystemBoard';
22
+ import { state } from '../State';
23
+
24
+ export class IntelliComBoard extends EasyTouchBoard {
25
+ constructor(system: PoolSystem) {
26
+ super(system); // graph chain to EasyTouchBoard constructor.
27
+ this.valueMaps.expansionBoards = new byteValueMap([
28
+ [11, { name: 'INTCOM2', part: 'INTCOM2', desc: 'IntelliComm II', circuits: 6, shared: true }]
29
+ ]);
30
+ }
31
+ public initExpansionModules(byte1: number, byte2: number) {
32
+ console.log(`Pentair IntelliCom System Detected!`);
33
+
34
+ sys.equipment.model = 'Suntouch/Intellicom';
35
+
36
+ // Initialize the installed personality board.
37
+ let mt = this.valueMaps.expansionBoards.transform(0);
38
+ let mod = sys.equipment.modules.getItemById(0, true);
39
+ mod.name = mt.name;
40
+ mod.desc = mt.desc;
41
+ mod.type = byte1;
42
+ mod.part = mt.part;
43
+ let eq = sys.equipment;
44
+ let md = mod.get();
45
+ eq.maxBodies = md.bodies = typeof mt.bodies !== 'undefined' ? mt.bodies : mt.shared ? 2 : 1;
46
+ eq.maxCircuits = md.circuits = typeof mt.circuits !== 'undefined' ? mt.circuits : 4;
47
+ eq.maxFeatures = md.features = typeof mt.features !== 'undefined' ? mt.features : 0
48
+ eq.maxValves = md.valves = typeof mt.valves !== 'undefined' ? mt.valves : 2;
49
+ eq.maxPumps = md.maxPumps = typeof mt.pumps !== 'undefined' ? mt.pumps : 2;
50
+ eq.shared = mt.shared;
51
+ eq.dual = false;
52
+ eq.maxChlorinators = md.chlorinators = 1;
53
+ eq.maxChemControllers = md.chemControllers = 1;
54
+ eq.maxCustomNames = 10;
55
+ // Calculate out the invalid ids.
56
+ sys.board.equipmentIds.invalidIds.set([]);
57
+ sys.board.equipmentIds.invalidIds.merge([5, 7, 8, 9, 13, 14, 15, 16, 17, 18])
58
+ sys.equipment.model = mt.desc;
59
+ this.initBodyDefaults();
60
+ state.emitControllerChange();
61
+ }
62
+
63
+ }
@@ -1,168 +1,242 @@
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 {byteValueMap} from './SystemBoard';
18
- import {logger} from '../../logger/Logger';
19
- import { EasyTouchBoard, TouchConfigQueue, GetTouchConfigCategories, TouchCircuitCommands } from './EasyTouchBoard';
20
- import { state, ICircuitGroupState } from '../State';
21
- import { PoolSystem, sys, ExpansionPanel, ExpansionModule } from '../Equipment';
22
- import { Protocol, Outbound, Message, Response } from '../comms/messages/Messages';
23
-
24
- import {conn} from '../comms/Comms';
25
- export class IntelliTouchBoard extends EasyTouchBoard {
26
- constructor (system: PoolSystem){
27
- super(system);
28
- this.equipmentIds.features.start = 41;
29
- this.equipmentIds.features.end = 50;
30
- this._configQueue = new ITTouchConfigQueue();
31
- this.valueMaps.expansionBoards = new byteValueMap([
32
- [0, { name: 'IT5', part: 'i5+3', desc: 'IntelliTouch i5+3', circuits: 6, shared: true }],
33
- [1, { name: 'IT7', part: 'i7+3', desc: 'IntelliTouch i7+3', circuits: 8, shared: true }],
34
- [2, { name: 'IT9', part: 'i9+3', desc: 'IntelliTouch i9+3', circuits: 10, shared: true }],
35
- [3, { name: 'IT5S', part: 'i5+3S', desc: 'IntelliTouch i5+3S', circuits: 5, shared: false }],
36
- [4, { name: 'IT9S', part: 'i9+3S', desc: 'IntelliTouch i9+3S', circuits: 9, shared: false }],
37
- [5, { name: 'IT10D', part: 'i10D', desc: 'IntelliTouch i10D', circuits: 10, shared: false, dual: true }],
38
- [32, { name: 'IT10X', part: 'i10X', desc: 'IntelliTouch i10X', circuits: 10, shared: false }]
39
- ]);
40
- }
41
- public initExpansionModules(byte1: number, byte2: number) {
42
- console.log(`Pentair IntelliTouch System Detected!`);
43
- // Initialize the installed personality board.
44
- let mt = this.valueMaps.expansionBoards.transform(byte1);
45
- let mod = sys.equipment.modules.getItemById(0, true);
46
- mod.name = mt.name;
47
- mod.desc = mt.desc;
48
- mod.type = byte1;
49
- mod.part = mt.part;
50
- let eq = sys.equipment;
51
- let md = mod.get();
52
-
53
- eq.maxBodies = md.bodies = typeof mt.bodies !== 'undefined' ? mt.bodies : mt.shared || mt.dual ? 2 : 1;
54
- eq.maxCircuits = md.circuits = typeof mt.circuits !== 'undefined' ? mt.circuits : 6;
55
- eq.maxFeatures = md.features = typeof mt.features !== 'undefined' ? mt.features : 10
56
- eq.maxValves = md.valves = typeof mt.valves !== 'undefined' ? mt.valves : mt.shared ? 4 : 2;
57
- eq.maxPumps = md.maxPumps = typeof mt.pumps !== 'undefined' ? mt.pumps : 8;
58
- eq.shared = mt.shared;
59
- eq.dual = typeof mt.dual !== 'undefined' ? mt.dual : false;
60
- eq.maxChlorinators = md.chlorinators = 1;
61
- eq.maxChemControllers = md.chemControllers = 1;
62
- eq.maxCustomNames = 20;
63
- eq.maxCircuitGroups = 10; // Not sure why this is 10 other than to allow for those that we are in control of.
64
-
65
- // Calculate out the invalid ids.
66
- sys.board.equipmentIds.invalidIds.set([]);
67
- if (!eq.shared) sys.board.equipmentIds.invalidIds.merge([1]);
68
- // Add in all the invalid ids from the base personality board.
69
- sys.board.equipmentIds.invalidIds.set([16, 17, 18]); // These appear to alway be invalid in IntelliTouch.
70
- //if (eq.maxCircuits < 9) sys.board.equipmentIds.invalidIds.merge([9]);
71
- for (let i = 7; i <= 10; i++) {
72
- // This will add all the invalid ids between 7 and 10 that are omitted for IntelliTouch models.
73
- // For instance an i7+3 can have up to 8 circuits since 1 and 6 are shared but an i7+3S will only have 7.
74
- if (i > eq.maxCircuits) sys.board.equipmentIds.invalidIds.merge([i]);
75
- }
76
- // This code should be repeated if we ever see a panel with more than one expansion panel.
77
- let pnl: ExpansionPanel;
78
- pnl = sys.equipment.expansions.getItemById(1, true);
79
- pnl.type = byte2 & 0x20;
80
- pnl.name = pnl.type === 32 ? 'i10X' : 'none';
81
- pnl.isActive = pnl.type !== 0;
82
- // if type is i9 or i10 we can have up to 3 expansion boards. These expansion boards only add
83
- // circuits.
84
- if (pnl.isActive) {
85
- let emt = this.valueMaps.expansionBoards.transform(pnl.type);
86
- let emd = pnl.modules.getItemById(1, true).get();
87
- eq.maxCircuits += emd.circuits = typeof emt.circuits !== 'undefined' ? emt.circuits : 0;
88
- }
89
- else pnl.modules.removeItemById(1);
90
-
91
- if (byte1 !== 14) sys.board.equipmentIds.invalidIds.merge([10, 19]);
92
- state.equipment.model = sys.equipment.model = mt.desc;
93
- state.equipment.controllerType = 'intellitouch';
94
- // The code above should be repeated if we ever see a panel with more than one expansion panel.
95
- sys.equipment.expansions.getItemById(2, true).isActive = false;
96
- sys.equipment.expansions.getItemById(3, true).isActive = false;
97
- sys.equipment.shared ? sys.board.equipmentIds.circuits.start = 1 : sys.board.equipmentIds.circuits.start = 2;
98
- this.initBodyDefaults();
99
- this.initHeaterDefaults();
100
- (async () => {
101
- try { sys.board.bodies.initFilters(); } catch (err) {
102
- logger.error(`Error initializing IntelliTouch Filters`);
103
- }
104
- })();
105
- for (let i = 0; i < sys.circuits.length; i++) {
106
- let c = sys.circuits.getItemByIndex(i);
107
- if (c.id <= 40) c.master = 0;
108
- }
109
- for (let i = 0; i < sys.valves.length; i++) {
110
- let v = sys.valves.getItemByIndex(i);
111
- if (v.id < 50) v.master = 0;
112
- }
113
- for (let i = 0; i < sys.bodies.length; i++) {
114
- let b = sys.bodies.getItemByIndex(i);
115
- b.master = 0;
116
- }
117
- state.emitControllerChange();
118
- }
119
- public circuits: ITTouchCircuitCommands = new ITTouchCircuitCommands(this);
120
- }
121
- class ITTouchConfigQueue extends TouchConfigQueue {
122
- public queueChanges() {
123
- this.reset();
124
- if (conn.mockPort) {
125
- logger.info(`Skipping configuration request from OCP because MockPort enabled.`);
126
- } else {
127
- logger.info(`Requesting ${sys.controllerType} configuration`);
128
- this.queueItems(GetTouchConfigCategories.dateTime, [0]);
129
- this.queueItems(GetTouchConfigCategories.heatTemperature, [0]);
130
- this.queueItems(GetTouchConfigCategories.solarHeatPump, [0]);
131
- this.queueRange(GetTouchConfigCategories.customNames, 0, sys.equipment.maxCustomNames - 1);
132
- this.queueRange(GetTouchConfigCategories.circuits, 1, sys.equipment.maxCircuits); // circuits
133
- this.queueRange(GetTouchConfigCategories.circuits, 41, 41 + sys.equipment.maxFeatures); // features
134
- this.queueRange(GetTouchConfigCategories.schedules, 1, sys.equipment.maxSchedules);
135
- this.queueItems(GetTouchConfigCategories.delays, [0]);
136
- this.queueItems(GetTouchConfigCategories.settings, [0]);
137
- this.queueItems(GetTouchConfigCategories.intellifloSpaSideRemotes, [0]);
138
- this.queueItems(GetTouchConfigCategories.is4is10, [0]);
139
- this.queueItems(GetTouchConfigCategories.spaSideRemote, [0]);
140
- this.queueItems(GetTouchConfigCategories.valves, [0]);
141
- this.queueItems(GetTouchConfigCategories.lightGroupPositions);
142
- this.queueItems(GetTouchConfigCategories.highSpeedCircuits, [0]);
143
- this.queueRange(GetTouchConfigCategories.pumpConfig, 1, sys.equipment.maxPumps);
144
- this.queueRange(GetTouchConfigCategories.circuitGroups, 0, sys.equipment.maxFeatures - 1);
145
- // items not required by ScreenLogic
146
- if (sys.chlorinators.getItemById(1).isActive)
147
- this.queueItems(GetTouchConfigCategories.intellichlor, [0]);
148
- }
149
- if (this.remainingItems > 0) {
150
- var self = this;
151
- setTimeout(() => {self.processNext();}, 50);
152
- } else state.status = 1;
153
- state.emitControllerChange();
154
- }
155
- }
156
- class ITTouchCircuitCommands extends TouchCircuitCommands {
157
- public async setCircuitGroupStateAsync(id: number, val: boolean): Promise<ICircuitGroupState> {
158
- // intellitouch supports groups/macros with id's 41-50 with a macro flag
159
- let grp = sys.circuitGroups.getItemById(id, false, { isActive: false });
160
- return new Promise<ICircuitGroupState>(async (resolve, reject) => {
161
- try {
162
- await sys.board.circuits.setCircuitStateAsync(id, val);
163
- resolve(state.circuitGroups.getInterfaceById(id));
164
- }
165
- catch (err) { reject(err); }
166
- });
167
- }
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 { byteValueMap } from './SystemBoard';
18
+ import { logger } from '../../logger/Logger';
19
+ import { EasyTouchBoard, TouchConfigQueue, GetTouchConfigCategories, TouchCircuitCommands } from './EasyTouchBoard';
20
+ import { state, ICircuitGroupState } from '../State';
21
+ import { PoolSystem, sys, ExpansionPanel, Equipment } from '../Equipment';
22
+
23
+ import { conn } from '../comms/Comms';
24
+ import { InvalidEquipmentDataError } from '../Errors';
25
+
26
+ export class IntelliTouchBoard extends EasyTouchBoard {
27
+ constructor(system: PoolSystem) {
28
+ super(system);
29
+ this.equipmentIds.features.start = 41;
30
+ this.equipmentIds.features.end = 50;
31
+ this._configQueue = new ITTouchConfigQueue();
32
+ this.valueMaps.expansionBoards = new byteValueMap([
33
+ [0, { name: 'IT5', part: 'i5+3', desc: 'IntelliTouch i5+3', circuits: 6, shared: true }],
34
+ [1, { name: 'IT7', part: 'i7+3', desc: 'IntelliTouch i7+3', circuits: 8, shared: true }],
35
+ [2, { name: 'IT9', part: 'i9+3', desc: 'IntelliTouch i9+3', circuits: 10, shared: true }],
36
+ [3, { name: 'IT5S', part: 'i5+3S', desc: 'IntelliTouch i5+3S', circuits: 5, shared: false, bodies: 1, intakeReturnValves: false }],
37
+ [4, { name: 'IT9S', part: 'i9+3S', desc: 'IntelliTouch i9+3S', circuits: 9, shared: false, bodies: 1, intakeReturnValves: false }],
38
+ [5, { name: 'IT10D', part: 'i10D', desc: 'IntelliTouch i10D', circuits: 10, shared: false, dual: true }],
39
+ [32, { name: 'IT5X', part: 'i5X', desc: 'IntelliTouch i5X', circuits: 5 }],
40
+ [33, { name: 'IT10X', part: 'i10X', desc: 'IntelliTouch i10X', circuits: 10 }]
41
+ ]);
42
+ }
43
+ public initExpansionModules(byte1: number, byte2: number) {
44
+ console.log(`Pentair IntelliTouch System Detected!`);
45
+ // Initialize the installed personality board.
46
+ let mt = this.valueMaps.expansionBoards.transform(byte1);
47
+ let mod = sys.equipment.modules.getItemById(0, true);
48
+ mod.name = mt.name;
49
+ mod.desc = mt.desc;
50
+ mod.type = byte1;
51
+ mod.part = mt.part;
52
+ let eq = sys.equipment;
53
+ let bd = sys.board;
54
+ let md = mod.get();
55
+
56
+ eq.maxBodies = md.bodies = typeof mt.bodies !== 'undefined' ? mt.bodies : mt.shared || mt.dual ? 2 : 1;
57
+ eq.maxCircuits = md.circuits = typeof mt.circuits !== 'undefined' ? mt.circuits : 6;
58
+ eq.maxFeatures = md.features = typeof mt.features !== 'undefined' ? mt.features : 8;
59
+ eq.maxValves = md.valves = typeof mt.valves !== 'undefined' ? mt.valves : mt.shared ? 4 : 2;
60
+ eq.maxPumps = md.maxPumps = typeof mt.pumps !== 'undefined' ? mt.pumps : 8;
61
+ eq.shared = mt.shared;
62
+ eq.dual = typeof mt.dual !== 'undefined' ? mt.dual : false;
63
+ eq.intakeReturnValves = md.intakeReturnValves = typeof mt.intakeReturnValves !== 'undefined' ? mt.intakeReturnValves : false;
64
+ eq.maxChlorinators = md.chlorinators = 1;
65
+ eq.maxChemControllers = md.chemControllers = 1;
66
+ eq.maxCustomNames = 20;
67
+ eq.maxCircuitGroups = 10; // Not sure why this is 10 other than to allow for those that we are in control of.
68
+
69
+ // Calculate out the invalid ids.
70
+ // sys.board.equipmentIds.invalidIds.set([]);
71
+ // Add in all the invalid ids from the base personality board.
72
+ sys.board.equipmentIds.invalidIds.set([16, 17, 18]); // These appear to alway be invalid in IntelliTouch.
73
+ // RGS 10-7-21: Since single bodies have hi-temp/lo-temp we will always want ID 1.
74
+ // if (!eq.shared) sys.board.equipmentIds.invalidIds.merge([1]);
75
+ //if (eq.maxCircuits < 9) sys.board.equipmentIds.invalidIds.merge([9]);
76
+ for (let i = 7; i <= 10; i++) {
77
+ // This will add all the invalid ids between 7 and 10 that are omitted for IntelliTouch models.
78
+ // For instance an i7+3 can have up to 8 circuits since 1 and 6 are shared but an i7+3S will only have 7.
79
+ if (i > eq.maxCircuits) sys.board.equipmentIds.invalidIds.merge([i]);
80
+ }
81
+ // This code should be repeated if we ever see a panel with more than one expansion panel.
82
+ let pnl1: ExpansionPanel;
83
+ if ((byte2 & 0x40) === 64) {
84
+ // 64 indicates one expansion panel; SL defaults to i10x but it could also be i5x until we know better
85
+ pnl1 = sys.equipment.expansions.getItemById(1, true);
86
+ pnl1.type = 32;
87
+ let emt = this.valueMaps.expansionBoards.transform(pnl1.type);
88
+ pnl1.name = emt.desc;
89
+ pnl1.isActive = true;
90
+ eq.maxCircuits += emt.circuits;
91
+ }
92
+ else sys.equipment.expansions.removeItemById(1);
93
+ let pnl2: ExpansionPanel;
94
+ if ((byte2 & 0x80) === 128) {
95
+ // SL defaults to i5x but it could also be i10x until we know better
96
+ pnl2 = sys.equipment.expansions.getItemById(2, true);
97
+ pnl2.type = 32;
98
+ let emt = this.valueMaps.expansionBoards.transform(pnl2.type);
99
+ pnl2.name = emt.desc;
100
+ pnl2.isActive = true;
101
+ eq.maxCircuits += emt.circuits;
102
+ }
103
+ else sys.equipment.expansions.removeItemById(2);
104
+ let pnl3: ExpansionPanel;
105
+ if ((byte2 & 0xC0) === 192) {
106
+ // SL defaults to i5x but it could also be i10x until we know better
107
+ pnl3 = sys.equipment.expansions.getItemById(3, true);
108
+ pnl3.type = 32;
109
+ let emt = this.valueMaps.expansionBoards.transform(pnl3.type);
110
+ pnl3.name = emt.desc;
111
+ pnl3.isActive = true;
112
+ eq.maxCircuits += emt.circuits;
113
+ }
114
+ else sys.equipment.expansions.removeItemById(3);
115
+ if (byte1 !== 14) sys.board.equipmentIds.invalidIds.merge([10, 19]);
116
+ state.equipment.model = sys.equipment.model = mt.desc;
117
+ state.equipment.controllerType = 'intellitouch';
118
+ sys.equipment.shared ? sys.board.equipmentIds.circuits.start = 1 : sys.board.equipmentIds.circuits.start = 2;
119
+ this.initBodyDefaults();
120
+ this.initHeaterDefaults();
121
+ (async () => {
122
+ try { sys.board.bodies.initFilters(); } catch (err) {
123
+ logger.error(`Error initializing IntelliTouch Filters`);
124
+ }
125
+ })();
126
+ for (let i = 0; i < sys.circuits.length; i++) {
127
+ let c = sys.circuits.getItemByIndex(i);
128
+ if (c.id <= 40) c.master = 0;
129
+ }
130
+ for (let i = 0; i < sys.valves.length; i++) {
131
+ let v = sys.valves.getItemByIndex(i);
132
+ if (v.id < 50) v.master = 0;
133
+ }
134
+ for (let i = 0; i < sys.bodies.length; i++) {
135
+ let b = sys.bodies.getItemByIndex(i);
136
+ b.master = 0;
137
+ }
138
+ state.emitControllerChange();
139
+ }
140
+ public circuits: ITTouchCircuitCommands = new ITTouchCircuitCommands(this);
141
+ public async setControllerType(obj): Promise<Equipment> {
142
+ try {
143
+ if (obj.controllerType !== sys.controllerType) {
144
+ return Promise.reject(new InvalidEquipmentDataError(`You may not change the controller type data for ${sys.controllerType} controllers`, 'controllerType', obj.controllerType));
145
+ }
146
+
147
+ let mod = sys.equipment.modules.getItemById(0);
148
+ let mt = this.valueMaps.expansionBoards.get(mod.type);
149
+ let _circuits = mt.circuits;
150
+ let pnl1 = sys.equipment.expansions.getItemById(1);
151
+ if (typeof obj.expansion1 !== 'undefined' && obj.expansion1 !== pnl1.type) {
152
+ let emt = this.valueMaps.expansionBoards.transform(obj.expansion1);
153
+ logger.info(`Changing expansion 1 to ${emt.desc}.`);
154
+ pnl1.type = emt.val;
155
+ pnl1.name = emt.desc;
156
+ pnl1.isActive = true;
157
+ }
158
+ let pnl2 = sys.equipment.expansions.getItemById(2);
159
+ if (typeof obj.expansion2 !== 'undefined' && obj.expansion2 !== pnl2.type) {
160
+ let emt = this.valueMaps.expansionBoards.transform(obj.expansion2);
161
+ logger.info(`Changing expansion 2 to ${emt.desc}.`);
162
+ pnl2.type = emt.val;
163
+ pnl2.name = emt.desc;
164
+ pnl2.isActive = true;
165
+ }
166
+ let pnl3 = sys.equipment.expansions.getItemById(3);
167
+ if (typeof obj.expansion3 !== 'undefined' && obj.expansion3 !== pnl3.type) {
168
+ let emt = this.valueMaps.expansionBoards.transform(obj.expansion3);
169
+ logger.info(`Changing expansion 3 to ${emt.desc}.`);
170
+ pnl3.type = emt.val;
171
+ pnl3.name = emt.desc;
172
+ pnl3.isActive = true;
173
+ }
174
+ let prevMaxCircuits = sys.equipment.maxCircuits;
175
+ if (pnl1.isActive) _circuits += this.valueMaps.expansionBoards.get(pnl1.type).circuits;
176
+ if (pnl2.isActive) _circuits += this.valueMaps.expansionBoards.get(pnl2.type).circuits;
177
+ if (pnl3.isActive) _circuits += this.valueMaps.expansionBoards.get(pnl3.type).circuits;
178
+ if (_circuits < prevMaxCircuits) {
179
+ // if we downsize expansions, remove circuits
180
+ for (let i = _circuits + 1; i <= prevMaxCircuits; i++) {
181
+ sys.circuits.removeItemById(i);
182
+ state.circuits.removeItemById(i);
183
+ }
184
+ }
185
+ else if (_circuits > prevMaxCircuits) {
186
+ this._configQueue.queueChanges();
187
+ }
188
+ sys.equipment.maxCircuits = _circuits;
189
+ return sys.equipment;
190
+ } catch (err) {
191
+ logger.error(`Error setting expansion panels: ${err.message}`);
192
+ }
193
+ }
194
+ }
195
+ class ITTouchConfigQueue extends TouchConfigQueue {
196
+ public queueChanges() {
197
+ this.reset();
198
+ if (conn.mockPort) {
199
+ logger.info(`Skipping configuration request from OCP because MockPort enabled.`);
200
+ } else {
201
+ logger.info(`Requesting ${sys.controllerType} configuration`);
202
+ this.queueItems(GetTouchConfigCategories.dateTime, [0]);
203
+ this.queueItems(GetTouchConfigCategories.heatTemperature, [0]);
204
+ this.queueItems(GetTouchConfigCategories.solarHeatPump, [0]);
205
+ this.queueRange(GetTouchConfigCategories.customNames, 0, sys.equipment.maxCustomNames - 1);
206
+ this.queueRange(GetTouchConfigCategories.circuits, 1, sys.equipment.maxCircuits); // circuits
207
+ this.queueRange(GetTouchConfigCategories.circuits, 41, 41 + sys.equipment.maxFeatures); // features
208
+ this.queueRange(GetTouchConfigCategories.schedules, 1, sys.equipment.maxSchedules);
209
+ this.queueItems(GetTouchConfigCategories.delays, [0]);
210
+ this.queueItems(GetTouchConfigCategories.settings, [0]);
211
+ this.queueItems(GetTouchConfigCategories.intellifloSpaSideRemotes, [0]);
212
+ this.queueItems(GetTouchConfigCategories.is4is10, [0]);
213
+ this.queueItems(GetTouchConfigCategories.spaSideRemote, [0]);
214
+ this.queueItems(GetTouchConfigCategories.valves, [0]);
215
+ this.queueItems(GetTouchConfigCategories.lightGroupPositions);
216
+ this.queueItems(GetTouchConfigCategories.highSpeedCircuits, [0]);
217
+ this.queueRange(GetTouchConfigCategories.pumpConfig, 1, sys.equipment.maxPumps);
218
+ this.queueRange(GetTouchConfigCategories.circuitGroups, 0, sys.equipment.maxFeatures - 1);
219
+ // items not required by ScreenLogic
220
+ if (sys.chlorinators.getItemById(1).isActive)
221
+ this.queueItems(GetTouchConfigCategories.intellichlor, [0]);
222
+ }
223
+ if (this.remainingItems > 0) {
224
+ var self = this;
225
+ setTimeout(() => { self.processNext(); }, 50);
226
+ } else state.status = 1;
227
+ state.emitControllerChange();
228
+ }
229
+ }
230
+ class ITTouchCircuitCommands extends TouchCircuitCommands {
231
+ public async setCircuitGroupStateAsync(id: number, val: boolean): Promise<ICircuitGroupState> {
232
+ // intellitouch supports groups/macros with id's 41-50 with a macro flag
233
+ let grp = sys.circuitGroups.getItemById(id, false, { isActive: false });
234
+ return new Promise<ICircuitGroupState>(async (resolve, reject) => {
235
+ try {
236
+ await sys.board.circuits.setCircuitStateAsync(id, val);
237
+ resolve(state.circuitGroups.getInterfaceById(id));
238
+ }
239
+ catch (err) { reject(err); }
240
+ });
241
+ }
168
242
  }