nodejs-poolcontroller 8.3.0 → 8.4.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 (107) hide show
  1. package/.eslintrc.json +36 -36
  2. package/.github/ISSUE_TEMPLATE/1-bug-report.yml +84 -84
  3. package/.github/ISSUE_TEMPLATE/2-docs.md +12 -12
  4. package/.github/ISSUE_TEMPLATE/3-proposal.md +28 -28
  5. package/.github/ISSUE_TEMPLATE/config.yml +8 -8
  6. package/.github/copilot-instructions.md +63 -63
  7. package/.github/workflows/ghcr-publish.yml +67 -67
  8. package/157_issues.md +101 -0
  9. package/AGENTS.md +613 -0
  10. package/CONTRIBUTING.md +74 -74
  11. package/Changelog +292 -284
  12. package/Dockerfile +62 -62
  13. package/Gruntfile.js +40 -40
  14. package/LICENSE +661 -661
  15. package/README.md +329 -309
  16. package/anslq25/MessagesMock.ts +221 -221
  17. package/anslq25/boards/MockBoardFactory.ts +49 -49
  18. package/anslq25/boards/MockEasyTouchBoard.ts +696 -696
  19. package/anslq25/boards/MockSystemBoard.ts +216 -216
  20. package/anslq25/chemistry/MockChlorinator.ts +98 -98
  21. package/anslq25/pumps/MockPump.ts +83 -83
  22. package/app.ts +115 -115
  23. package/config/Config.ts +0 -0
  24. package/config/VersionCheck.ts +0 -0
  25. package/controller/Constants.ts +809 -805
  26. package/controller/Equipment.ts +2737 -2664
  27. package/controller/Errors.ts +181 -181
  28. package/controller/Lockouts.ts +549 -549
  29. package/controller/State.ts +3746 -3701
  30. package/controller/boards/AquaLinkBoard.ts +1175 -1003
  31. package/controller/boards/BoardFactory.ts +53 -53
  32. package/controller/boards/EasyTouchBoard.ts +3246 -3202
  33. package/controller/boards/IntelliCenterBoard.ts +4581 -3899
  34. package/controller/boards/IntelliComBoard.ts +69 -69
  35. package/controller/boards/IntelliTouchBoard.ts +382 -382
  36. package/controller/boards/NixieBoard.ts +1947 -1944
  37. package/controller/boards/SunTouchBoard.ts +401 -400
  38. package/controller/boards/SystemBoard.ts +5303 -5268
  39. package/controller/comms/Comms.ts +1278 -1255
  40. package/controller/comms/ScreenLogic.ts +1665 -1665
  41. package/controller/comms/messages/Messages.ts +1627 -1406
  42. package/controller/comms/messages/config/ChlorinatorMessage.ts +5 -0
  43. package/controller/comms/messages/config/CircuitGroupMessage.ts +0 -0
  44. package/controller/comms/messages/config/CircuitMessage.ts +0 -0
  45. package/controller/comms/messages/config/ConfigMessage.ts +6 -0
  46. package/controller/comms/messages/config/CoverMessage.ts +0 -0
  47. package/controller/comms/messages/config/CustomNameMessage.ts +31 -31
  48. package/controller/comms/messages/config/EquipmentMessage.ts +250 -210
  49. package/controller/comms/messages/config/ExternalMessage.ts +1051 -903
  50. package/controller/comms/messages/config/FeatureMessage.ts +0 -0
  51. package/controller/comms/messages/config/GeneralMessage.ts +65 -0
  52. package/controller/comms/messages/config/HeaterMessage.ts +0 -0
  53. package/controller/comms/messages/config/IntellichemMessage.ts +0 -0
  54. package/controller/comms/messages/config/OptionsMessage.ts +207 -174
  55. package/controller/comms/messages/config/PumpMessage.ts +427 -421
  56. package/controller/comms/messages/config/RemoteMessage.ts +0 -0
  57. package/controller/comms/messages/config/ScheduleMessage.ts +401 -390
  58. package/controller/comms/messages/config/SecurityMessage.ts +37 -13
  59. package/controller/comms/messages/config/ValveMessage.ts +0 -0
  60. package/controller/comms/messages/status/ChlorinatorStateMessage.ts +0 -0
  61. package/controller/comms/messages/status/EquipmentStateMessage.ts +940 -822
  62. package/controller/comms/messages/status/HeaterStateMessage.ts +147 -135
  63. package/controller/comms/messages/status/IntelliChemStateMessage.ts +448 -448
  64. package/controller/comms/messages/status/IntelliValveStateMessage.ts +36 -36
  65. package/controller/comms/messages/status/NeptuneModbusStateMessage.ts +217 -0
  66. package/controller/comms/messages/status/PumpStateMessage.ts +0 -0
  67. package/controller/comms/messages/status/RegalModbusStateMessage.ts +410 -410
  68. package/controller/comms/messages/status/VersionMessage.ts +152 -41
  69. package/controller/nixie/Nixie.ts +173 -173
  70. package/controller/nixie/NixieEquipment.ts +104 -104
  71. package/controller/nixie/bodies/Body.ts +120 -120
  72. package/controller/nixie/bodies/Filter.ts +135 -135
  73. package/controller/nixie/chemistry/ChemController.ts +2756 -2724
  74. package/controller/nixie/chemistry/ChemDoser.ts +806 -806
  75. package/controller/nixie/chemistry/Chlorinator.ts +367 -367
  76. package/controller/nixie/circuits/Circuit.ts +478 -478
  77. package/controller/nixie/heaters/Heater.ts +843 -834
  78. package/controller/nixie/pumps/Pump.ts +1336 -1193
  79. package/controller/nixie/schedules/Schedule.ts +401 -401
  80. package/controller/nixie/valves/Valve.ts +170 -170
  81. package/defaultConfig.json +352 -352
  82. package/docker-compose.yml +32 -31
  83. package/logger/DataLogger.ts +448 -448
  84. package/logger/Logger.ts +459 -436
  85. package/package.json +58 -58
  86. package/sendSocket.js +32 -32
  87. package/tsconfig.json +26 -25
  88. package/types/express-multer.d.ts +32 -32
  89. package/web/Server.ts +1939 -1927
  90. package/web/bindings/aqualinkD.json +559 -559
  91. package/web/bindings/influxDB.json +1066 -1066
  92. package/web/bindings/mqtt.json +721 -721
  93. package/web/bindings/mqttAlt.json +746 -746
  94. package/web/bindings/rulesManager.json +54 -54
  95. package/web/bindings/smartThings-Hubitat.json +31 -31
  96. package/web/bindings/valveRelays.json +20 -20
  97. package/web/bindings/vera.json +25 -25
  98. package/web/interfaces/baseInterface.ts +188 -188
  99. package/web/interfaces/httpInterface.ts +148 -148
  100. package/web/interfaces/influxInterface.ts +283 -283
  101. package/web/interfaces/mqttInterface.ts +695 -695
  102. package/web/interfaces/ruleInterface.ts +101 -87
  103. package/web/services/config/Config.ts +1212 -1053
  104. package/web/services/config/ConfigSocket.ts +0 -0
  105. package/web/services/state/State.ts +21 -0
  106. package/web/services/state/StateSocket.ts +28 -0
  107. package/web/services/utilities/Utilities.ts +233 -233
@@ -1,904 +1,1052 @@
1
- /* nodejs-poolController. An application to control pool equipment.
2
- Copyright (C) 2016, 2017, 2018, 2019, 2020, 2021, 2022.
3
- Russell Goldin, tagyoureit. russ.goldin@gmail.com
4
-
5
- This program is free software: you can redistribute it and/or modify
6
- it under the terms of the GNU Affero General Public License as
7
- published by the Free Software Foundation, either version 3 of the
8
- License, or (at your option) any later version.
9
-
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU Affero General Public License for more details.
14
-
15
- You should have received a copy of the GNU Affero General Public License
16
- along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
- import { Inbound } from "../Messages";
19
- import { sys, Body, ICircuitGroup, LightGroup, CircuitGroup } from "../../../Equipment";
20
- import { state, ICircuitGroupState, LightGroupState, CircuitGroupState } from "../../../State";
21
- import { Timestamp, utils } from "../../../Constants";
22
- import { logger } from "../../../../logger/Logger";
23
- export class ExternalMessage {
24
- public static processIntelliCenter(msg: Inbound): void {
25
- switch (msg.extractPayloadByte(0)) {
26
- case 0: // Setpoints/HeatMode
27
- ExternalMessage.processTempSettings(msg);
28
- break;
29
- case 1: // Circuit Changes
30
- ExternalMessage.processCircuit(msg);
31
- break;
32
- case 2: // Feature Changes
33
- ExternalMessage.processFeature(msg);
34
- break;
35
- case 3: // Schedule Changes
36
- ExternalMessage.processSchedules(msg);
37
- break;
38
- case 4: // Pump Information
39
- ExternalMessage.processPump(msg);
40
- break;
41
- case 5: // Remotes
42
- break;
43
- case 6: // Light/Circuit group
44
- ExternalMessage.processGroupSettings(msg);
45
- break;
46
- case 7: // Chlorinator
47
- ExternalMessage.processChlorinator(msg);
48
- break;
49
- case 8: // IntelliChem
50
- ExternalMessage.processIntelliChem(msg);
51
- break;
52
- case 9: // Valves
53
- ExternalMessage.processValve(msg);
54
- break;
55
- case 10: // Heaters
56
- ExternalMessage.processHeater(msg);
57
- break;
58
- case 11: // Security
59
- break;
60
- case 12: // Pool Settings Alias, owner...etc.
61
- ExternalMessage.processPool(msg);
62
- break;
63
- case 13: // Bodies (Manual heat, capacities)
64
- ExternalMessage.processBodies(msg);
65
- break;
66
- case 14: // Covers
67
- break;
68
- case 15: // Circuit, feature, group, and schedule States
69
- ExternalMessage.processCircuitState(3, msg);
70
- ExternalMessage.processFeatureState(9, msg);
71
- ExternalMessage.processScheduleState(15, msg);
72
- ExternalMessage.processCircuitGroupState(13, msg);
73
- break;
74
- default:
75
- logger.debug(`Unprocessed Message ${msg.toPacket()}`)
76
- break;
77
- }
78
- }
79
- public static processIntelliChem(msg: Inbound) {
80
- let id = msg.extractPayloadByte(2) + 1;
81
- let isActive = utils.makeBool(msg.extractPayloadByte(6));
82
- //let schem = state.chemchems.getItemById(id, isActive);
83
- //chem.isActive = schem.isActive = isActive;
84
- if (isActive) {
85
- let chem = sys.chemControllers.getItemById(id, true);
86
- let schem = state.chemControllers.getItemById(id, true);
87
- // chem.isVirtual = false;
88
- chem.master = 0;
89
- chem.ph.tank.capacity = chem.orp.tank.capacity = 6;
90
- chem.ph.tank.units = chem.orp.tank.units = '';
91
- schem.type = chem.type = 2;
92
- schem.name = chem.name = (chem.name || 'IntelliChem' + id);
93
- schem.body = chem.body = msg.extractPayloadByte(3);
94
- schem.address = chem.address = msg.extractPayloadByte(5);
95
- chem.ph.setpoint = schem.ph.setpoint = msg.extractPayloadInt(7) / 100;
96
- chem.orp.setpoint = schem.orp.setpoint = msg.extractPayloadInt(9);
97
- chem.calciumHardness = msg.extractPayloadInt(13);
98
- chem.cyanuricAcid = msg.extractPayloadInt(15);
99
- chem.alkalinity = msg.extractPayloadInt(17);
100
- }
101
- else {
102
- sys.chemControllers.removeItemById(id);
103
- state.chemControllers.removeItemById(id);
104
- }
105
- msg.isProcessed = true;
106
- }
107
- public static processValve(msg: Inbound) {
108
- let valve = sys.valves.getItemById(msg.extractPayloadByte(2) + 1);
109
- valve.circuit = msg.extractPayloadByte(3) + 1;
110
- valve.name = msg.extractPayloadString(4, 16);
111
- valve.master = 0;
112
- // valve.isVirtual = false;
113
- msg.isProcessed = true;
114
- }
115
- public static processPool(msg: Inbound) {
116
- switch (msg.extractPayloadByte(2)) {
117
- case 0: // Pool Alias
118
- sys.general.alias = msg.extractPayloadString(3, 16);
119
- msg.isProcessed = true;
120
- break;
121
- case 1: // Address
122
- sys.general.location.address = msg.extractPayloadString(3, 32);
123
- msg.isProcessed = true;
124
- break;
125
- case 2: // Owner
126
- sys.general.owner.name = msg.extractPayloadString(3, 16);
127
- msg.isProcessed = true;
128
- break;
129
- case 3: // Email
130
- sys.general.owner.email = msg.extractPayloadString(3, 32);
131
- msg.isProcessed = true;
132
- break;
133
- case 4: // Email 2
134
- sys.general.owner.email2 = msg.extractPayloadString(3, 32);
135
- msg.isProcessed = true;
136
- break;
137
- case 5: // Phone
138
- sys.general.owner.phone = msg.extractPayloadString(3, 16);
139
- msg.isProcessed = true;
140
- break;
141
- case 6: // Phone 2
142
- sys.general.owner.phone2 = msg.extractPayloadString(3, 16);
143
- msg.isProcessed = true;
144
- break;
145
- case 7: // Zipcode
146
- sys.general.location.zip = msg.extractPayloadString(3, 6);
147
- msg.isProcessed = true;
148
- break;
149
- case 8: // Country
150
- sys.general.location.country = msg.extractPayloadString(3, 16);
151
- msg.isProcessed = true;
152
- break;
153
- case 9: // City
154
- sys.general.location.city = msg.extractPayloadString(3, 32);
155
- msg.isProcessed = true;
156
- break;
157
- case 10: // State
158
- sys.general.location.state = msg.extractPayloadString(3, 16);
159
- msg.isProcessed = true;
160
- break;
161
- case 11: // Latitute
162
- sys.general.location.latitude = ((msg.extractPayloadByte(4) * 256) + msg.extractPayloadByte(3)) / 100;
163
- msg.isProcessed = true;
164
- break;
165
- case 12: // Longitude
166
- sys.general.location.longitude = -((msg.extractPayloadByte(4) * 256) + msg.extractPayloadByte(3)) / 100;
167
- msg.isProcessed = true;
168
- break;
169
- case 13: // Timezone
170
- sys.general.location.timeZone = msg.extractPayloadByte(3);
171
- msg.isProcessed = true;
172
- break;
173
- }
174
- }
175
- public static processGroupSettings(msg: Inbound) {
176
- // We have 3 potential messages.
177
- let groupId = msg.extractPayloadByte(2) + sys.board.equipmentIds.circuitGroups.start;
178
- let group: ICircuitGroup = null;
179
- let sgroup: ICircuitGroupState = null;
180
- switch (msg.extractPayloadByte(1)) {
181
- case 0:
182
- {
183
- // Get the type.
184
- let type = msg.extractPayloadByte(3);
185
- switch (msg.extractPayloadByte(3)) {
186
- case 0:
187
- group = sys.circuitGroups.getInterfaceById(groupId);
188
- sgroup = group.type === 2 ? state.circuitGroups.getItemById(groupId) : state.lightGroups.getItemById(groupId);
189
- sys.lightGroups.removeItemById(groupId);
190
- sys.circuitGroups.removeItemById(groupId);
191
- state.lightGroups.removeItemById(groupId);
192
- sys.circuitGroups.removeItemById(groupId);
193
- sgroup.isActive = false;
194
- state.emitEquipmentChanges();
195
- msg.isProcessed = true;
196
- break;
197
- case 1:
198
- group = sys.lightGroups.getItemById(groupId, true);
199
- sgroup = state.lightGroups.getItemById(groupId, true);
200
- sys.circuitGroups.removeItemById(groupId);
201
- state.circuitGroups.removeItemById(groupId);
202
- sgroup.lightingTheme = group.lightingTheme = msg.extractPayloadByte(4) >> 2;
203
- sgroup.type = group.type = type;
204
- sgroup.isActive = group.isActive = true;
205
- msg.isProcessed = true;
206
- break;
207
- case 2:
208
- group = sys.circuitGroups.getItemById(groupId, true);
209
- sgroup = state.circuitGroups.getItemById(groupId, true);
210
- sgroup.type = group.type = type;
211
- if (typeof group.showInFeatures === 'undefined') group.showInFeatures = sgroup.showInFeatures = true;
212
- sgroup.showInFeatures = group.showInFeatures;
213
- sys.lightGroups.removeItemById(groupId);
214
- state.lightGroups.removeItemById(groupId);
215
- sgroup.isActive = group.isActive = true;
216
- msg.isProcessed = true;
217
- break;
218
- }
219
- if (group.isActive) {
220
- for (let i = 0; i < 16; i++) {
221
- let circuitId = msg.extractPayloadByte(i + 6);
222
- let circuit = group.circuits.getItemById(i + 1, circuitId < 255);
223
- if (circuitId === 255) group.circuits.removeItemById(i + 1);
224
- circuit.circuit = circuitId + 1;
225
-
226
- }
227
- }
228
- group.eggTimer = (msg.extractPayloadByte(38) * 60) + msg.extractPayloadByte(39);
229
- group.dontStop = group.eggTimer === 1440;
230
- // sgroup.eggTimer = group.eggTimer;
231
- if (type === 1) {
232
- let g = group as LightGroup;
233
- for (let i = 0; i < 16; i++) {
234
- g.circuits.getItemById(i + 1).swimDelay = msg.extractPayloadByte(22 + i);
235
- }
236
- }
237
- state.emitEquipmentChanges();
238
- msg.isProcessed = true;
239
- break;
240
- }
241
- case 1:
242
- group = sys.circuitGroups.getInterfaceById(groupId);
243
- sgroup = group.type === 1 ? state.lightGroups.getItemById(groupId) : state.circuitGroups.getItemById(groupId);
244
- sgroup.name = group.name = msg.extractPayloadString(19, 16);
245
- if (group.type === 1) {
246
- let g = group as LightGroup;
247
- for (let i = 0; i < 16; i++) {
248
- let circuit = g.circuits.getItemById(i + 1);
249
- circuit.color = msg.extractPayloadByte(i + 3);
250
- }
251
- }
252
- state.emitEquipmentChanges();
253
- msg.isProcessed = true;
254
- break;
255
- case 2:
256
- group = sys.circuitGroups.getInterfaceById(groupId);
257
- // Process the group states.
258
- if (group.type === 2) {
259
- let g = group as CircuitGroup;
260
- for (let i = 0; i < 16; i++) {
261
- let desiredState = msg.extractPayloadByte(i + 19);
262
- let circuit = g.circuits.getItemById(i + 1);
263
- circuit.desiredState = (desiredState !== 255) ? desiredState : 3;
264
- }
265
- }
266
- msg.isProcessed = true;
267
- break;
268
- }
269
- }
270
- public static processIntelliCenterState(msg) {
271
- ExternalMessage.processCircuitState(2, msg);
272
- ExternalMessage.processFeatureState(8, msg);
273
- ExternalMessage.processScheduleState(14, msg);
274
- ExternalMessage.processCircuitGroupState(12, msg);
275
- }
276
- private static processHeater(msg: Inbound) {
277
- // So a user is changing the heater info. Lets
278
- // hijack it and get it ourselves.
279
- // Installing hybrid heater.
280
- //[165, 63, 15, 16, 168, 30][10, 0, 2, 5, 32, 5, 6, 3, 0, 6, 112, 72, 121, 98, 114, 105, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 1][4, 230]
281
- let isActive = msg.extractPayloadByte(3) !== 0;
282
- let heaterId = msg.extractPayloadByte(2) + 1;
283
- if (isActive) {
284
- let heater = sys.heaters.getItemById(heaterId, true);
285
- let hstate = state.heaters.getItemById(heater.id, true);
286
-
287
- hstate.type = heater.type = msg.extractPayloadByte(3);
288
- heater.body = msg.extractPayloadByte(4);
289
- heater.cooldownDelay = msg.extractPayloadByte(5);
290
- heater.startTempDelta = msg.extractPayloadByte(6);
291
- heater.stopTempDelta = msg.extractPayloadByte(7);
292
- heater.coolingEnabled = msg.extractPayloadByte(8) > 0;
293
- heater.differentialTemp = msg.extractPayloadByte(9);
294
- heater.address = msg.extractPayloadByte(10);
295
- hstate.name = heater.name = msg.extractPayloadString(11, 16);
296
- heater.efficiencyMode = msg.extractPayloadByte(27);
297
- heater.maxBoostTemp = msg.extractPayloadByte(28);
298
- heater.economyTime = msg.extractPayloadByte(29);
299
- heater.master = 0;
300
- }
301
- else {
302
- sys.heaters.removeItemById(heaterId);
303
- state.heaters.removeItemById(heaterId);
304
- }
305
- sys.board.heaters.updateHeaterServices();
306
- // Check anyway to make sure we got it all.
307
- //setTimeout(() => sys.checkConfiguration(), 500);
308
- msg.isProcessed = true;
309
- }
310
-
311
- private static processCircuitState(start: number, msg: Inbound) {
312
- let circuitId = 1;//sys.board.equipmentIds.circuits.start;
313
- for (let i = start; i < msg.payload.length && sys.board.equipmentIds.circuits.isInRange(circuitId); i++) {
314
- let byte = msg.extractPayloadByte(i);
315
- // Shift each bit getting the circuit identified by each value.
316
- for (let j = 0; j < 8; j++) {
317
- let circuit = sys.circuits.getItemById(circuitId);
318
- let cstate = state.circuits.getItemById(circuitId, circuit.isActive);
319
- if (circuit.isActive) {
320
- let isOn = ((byte & (1 << (j))) >> j) > 0;
321
- sys.board.circuits.setEndTime(circuit, cstate, isOn);
322
- cstate.isOn = isOn;
323
- cstate.name = circuit.name;
324
- cstate.showInFeatures = circuit.showInFeatures;
325
- cstate.type = circuit.type;
326
- switch (circuit.type) {
327
- case 6: // Globrite
328
- case 5: // Magicstream
329
- case 8: // Intellibrite
330
- case 10: // Colorcascade
331
- cstate.lightingTheme = circuit.lightingTheme;
332
- if (!isOn) cstate.action = 0;
333
- break;
334
- case 9: // Dimmer
335
- cstate.level = circuit.level;
336
- break;
337
- }
338
- }
339
- else
340
- state.circuits.removeItemById(circuitId);
341
- state.emitEquipmentChanges();
342
- circuitId++;
343
- }
344
- msg.isProcessed = true;
345
- }
346
- // state.body = body;
347
- }
348
- private static processScheduleState(start: number, msg: Inbound) {
349
- let scheduleId = 1;
350
- for (let i = start; i < msg.payload.length && scheduleId <= sys.equipment.maxSchedules; i++) {
351
- let byte = msg.extractPayloadByte(i);
352
- // Shift each bit getting the schedule identified by each value.
353
- for (let j = 0; j < 8; j++) {
354
- let schedule = sys.schedules.getItemById(scheduleId);
355
- if (schedule.isActive) {
356
- if (schedule.circuit > 0) { // Don't get the schedule state if we haven't determined the entire config for it yet.
357
- let sstate = state.schedules.getItemById(scheduleId, schedule.isActive);
358
- let isOn = ((byte & (1 << (j))) >> j) > 0;
359
- sstate.isOn = isOn;
360
- sstate.circuit = schedule.circuit;
361
- sstate.endTime = schedule.endTime;
362
- sstate.startDate = schedule.startDate;
363
- sstate.startTime = schedule.startTime;
364
- sstate.scheduleDays = schedule.scheduleDays;
365
- sstate.scheduleType = schedule.scheduleType;
366
- sstate.heatSetpoint = schedule.heatSetpoint;
367
- sstate.heatSource = schedule.heatSource;
368
- sstate.startTimeType = schedule.startTimeType;
369
- sstate.endTimeType = schedule.endTimeType;
370
- sstate.startDate = schedule.startDate;
371
- }
372
- }
373
- else
374
- state.schedules.removeItemById(scheduleId);
375
- scheduleId++;
376
- }
377
- }
378
- state.emitEquipmentChanges();
379
- msg.isProcessed = true;
380
- }
381
- public static processFeatureState(start: number, msg: Inbound) {
382
- let featureId = sys.board.equipmentIds.features.start;
383
- let maxFeatureId = sys.features.getMaxId(true, 0);
384
- //console.log(`Max Feature Id = ${maxFeatureId}`);
385
- for (let i = start; i < msg.payload.length && featureId <= maxFeatureId; i++) {
386
- let byte = msg.extractPayloadByte(i);
387
- // Shift each bit getting the feature identified by each value.
388
- for (let j = 0; j < 8 && featureId <= maxFeatureId; j++) {
389
- let feature = sys.features.getItemById(featureId, false, { isActive: false });
390
- if (feature.isActive !== false) {
391
- let fstate = state.features.getItemById(featureId, true);
392
- let isOn = (byte & (1 << j)) > 0;
393
- sys.board.circuits.setEndTime(feature, fstate, isOn);
394
- fstate.isOn = isOn;
395
- fstate.name = feature.name;
396
- }
397
- else
398
- // Just a little insurance to remove the feature from the state.
399
- state.features.removeItemById(featureId);
400
- featureId++;
401
- }
402
- }
403
- state.emitEquipmentChanges();
404
- msg.isProcessed = true;
405
-
406
- }
407
- private static processCircuitGroupState(start: number, msg: Inbound) {
408
- let groupId = sys.board.equipmentIds.circuitGroups.start;
409
- let maxGroupId = Math.max(sys.lightGroups.getMaxId(true, 0), sys.circuitGroups.getMaxId(true, 0));
410
- for (let i = start; i < msg.payload.length && groupId <= maxGroupId; i++) {
411
- let byte = msg.extractPayloadByte(i);
412
- // Shift each bit getting the group identified by each value.
413
- for (let j = 0; j < 8; j++) {
414
- let group = sys.circuitGroups.getInterfaceById(groupId);
415
- let gstate = group.type === 1 ? state.lightGroups.getItemById(groupId, group.isActive) : state.circuitGroups.getItemById(groupId, group.isActive);
416
-
417
- if (group.isActive !== false) {
418
- let isOn = ((byte & (1 << (j))) >> j) > 0;
419
- sys.board.circuits.setEndTime(group, gstate, isOn);
420
- gstate.isOn = isOn;
421
- gstate.name = group.name;
422
- gstate.type = group.type;
423
- // Now calculate out the sync/set/swim operations.
424
- if (gstate.dataName === 'lightGroup' && start === 13) {
425
- let lg = gstate as LightGroupState;
426
- let ndx = lg.id - sys.board.equipmentIds.circuitGroups.start;
427
- let byteNdx = Math.floor(ndx / 4);
428
- let bitNdx = (ndx * 2) - (byteNdx * 8);
429
- let byte = msg.extractPayloadByte(start + 15 + byteNdx, 255);
430
- //console.log(`ndx:${start + 15 + byteNdx} byte: ${byte}, bit: ${bitNdx}`);
431
- byte = ((byte >> bitNdx) & 0x0003);
432
- // Each light group is represented by two bits on the status byte. There are 3 status bytes that give us only 12 of the 16 on the config stream but the 168 message
433
- // does acutall send 4 so all are represented there.
434
- // [10] = Set
435
- // [01] = Swim
436
- // [00] = Sync
437
- // [11] = No sequencing underway.
438
- switch (byte) {
439
- case 0: // Sync
440
- lg.action = sys.board.valueMaps.circuitActions.getValue('colorsync');
441
- break;
442
- case 1: // Color swim
443
- lg.action = sys.board.valueMaps.circuitActions.getValue('colorswim');
444
- break;
445
- case 2: // Color set
446
- lg.action = sys.board.valueMaps.circuitActions.getValue('colorset');
447
- break;
448
- default:
449
- lg.action = 0;
450
- break;
451
- }
452
- }
453
- else if(gstate.dataName === 'circuitGroup') {
454
- (gstate as CircuitGroupState).showInFeatures = group.showInFeatures;
455
- }
456
- }
457
- else {
458
- state.circuitGroups.removeItemById(groupId);
459
- state.lightGroups.removeItemById(groupId);
460
- }
461
- groupId++;
462
- }
463
- }
464
- state.emitEquipmentChanges();
465
- msg.isProcessed = true;
466
- }
467
-
468
- private static processBodies(msg: Inbound) {
469
- let bodyId = 0;
470
- let cbody: Body = null;
471
- switch (msg.extractPayloadByte(2)) {
472
- case 0:
473
- case 1:
474
- case 2:
475
- case 3:
476
- bodyId = msg.extractPayloadByte(2);
477
- if (bodyId === 1) bodyId = 3;
478
- else if (bodyId === 0) bodyId = 1;
479
- else if (bodyId === 3) bodyId = 4;
480
- cbody = sys.bodies.getItemById(bodyId);
481
- cbody.name = msg.extractPayloadString(3, 16);
482
- state.temps.bodies.getItemById(bodyId, false).name = cbody.name;
483
- msg.isProcessed = true;
484
- break;
485
- case 4:
486
- case 5:
487
- case 6:
488
- case 7:
489
- bodyId = msg.extractPayloadByte(2) - 4;
490
- if (bodyId === 1) bodyId = 3;
491
- else if (bodyId === 0) bodyId = 1;
492
- else if (bodyId === 3) bodyId = 4;
493
- cbody = sys.bodies.getItemById(bodyId);
494
- cbody.capacity = msg.extractPayloadByte(3) * 1000;
495
- msg.isProcessed = true;
496
- break;
497
- case 13: // Pump notifications
498
- msg.isProcessed = true;
499
- break;
500
- case 14: // Heater notifications
501
- msg.isProcessed = true;
502
- break;
503
- case 15: // Chlorinator notifications
504
- msg.isProcessed = true;
505
- break;
506
- }
507
- state.emitEquipmentChanges();
508
- }
509
- private static processSchedules(msg: Inbound) {
510
- let schedId = msg.extractPayloadByte(2) + 1;
511
- let startTime = msg.extractPayloadInt(3);
512
- let endTime = msg.extractPayloadInt(5);
513
- let circuit = msg.extractPayloadByte(7) + 1;
514
- let isActive = (msg.extractPayloadByte(8) & 128) === 128; // Inactive schedules do not have bit 8 set.
515
- let cfg = sys.schedules.getItemById(schedId, isActive);
516
- let s = state.schedules.getItemById(schedId, cfg.isActive);
517
- //cfg.isActive = (circuit !== 256);
518
- cfg.startTime = startTime;
519
- cfg.endTime = endTime;
520
- cfg.circuit = circuit;
521
- cfg.isActive = isActive;
522
- let byte = msg.extractPayloadByte(8);
523
- cfg.scheduleType = (byte & 1 & 0xFF) === 1 ? 0 : 128;
524
- if ((byte & 4 & 0xFF) === 4) cfg.startTimeType = 1;
525
- else if ((byte & 8 & 0xFF) === 8) cfg.startTimeType = 2;
526
- else cfg.startTimeType = 0;
527
-
528
- if ((byte & 16 & 0xFF) === 16) cfg.endTimeType = 1;
529
- else if ((byte & 32 & 0xFF) === 32) cfg.endTimeType = 2;
530
- else cfg.endTimeType = 0;
531
- //cfg.runOnce = byte;
532
- cfg.scheduleDays = msg.extractPayloadByte(9);
533
- cfg.startMonth = msg.extractPayloadByte(10);
534
- cfg.startDay = msg.extractPayloadByte(11);
535
- cfg.startYear = msg.extractPayloadByte(12);
536
- let hs = msg.extractPayloadByte(13);
537
- // RKS: During the transition to 1.047 the heat sources were all screwed up. O now means no change and 1 means off.
538
- //if (hs === 1) hs = 0; // Shim for 1.047
539
- cfg.heatSource = hs;
540
- cfg.heatSetpoint = msg.extractPayloadByte(14);
541
- cfg.coolSetpoint = msg.extractPayloadByte(15);
542
- if (cfg.isActive) {
543
- let s = state.schedules.getItemById(schedId, cfg.isActive);
544
- s.isActive = cfg.isActive = true;
545
- s.startTime = cfg.startTime;
546
- s.endTime = cfg.endTime;
547
- s.circuit = cfg.circuit;
548
- s.scheduleType = cfg.scheduleType;
549
- s.scheduleDays = cfg.scheduleType === 128 ? cfg.scheduleDays : 0;
550
- s.heatSetpoint = cfg.heatSetpoint;
551
- s.coolSetpoint = cfg.coolSetpoint;
552
- s.heatSource = cfg.heatSource;
553
- s.startDate = cfg.startDate;
554
- s.startTimeType = cfg.startTimeType;
555
- s.endTimeType = cfg.endTimeType;
556
- }
557
- else {
558
- s.isActive = cfg.isActive = false;
559
- sys.schedules.removeItemById(cfg.id);
560
- state.schedules.removeItemById(cfg.id);
561
- s.emitEquipmentChange();
562
- }
563
- state.emitEquipmentChanges();
564
- msg.isProcessed = true;
565
- }
566
- private static processChlorinator(msg: Inbound) {
567
- let isActive = msg.extractPayloadByte(10) > 0;
568
- let chlorId = msg.extractPayloadByte(2) + 1;
569
- let cfg = sys.chlorinators.getItemById(chlorId, isActive);
570
- let s = state.chlorinators.getItemById(chlorId, isActive);
571
- if (!isActive) {
572
- sys.chlorinators.removeItemById(chlorId);
573
- state.chlorinators.removeItemById(chlorId);
574
- s.emitEquipmentChange();
575
- msg.isProcessed = true;
576
- return;
577
- }
578
- else {
579
-
580
- cfg.body = msg.extractPayloadByte(3);
581
- cfg.poolSetpoint = msg.extractPayloadByte(5);
582
- if (!cfg.disabled) {
583
- // RKS: We don't want theses setpoints if our chem controller
584
- // disabled the chlorinator.
585
- cfg.spaSetpoint = msg.extractPayloadByte(6);
586
- cfg.superChlor = msg.extractPayloadByte(7) > 0;
587
- }
588
- cfg.superChlorHours = msg.extractPayloadByte(8);
589
- s.poolSetpoint = cfg.poolSetpoint;
590
- s.spaSetpoint = cfg.spaSetpoint;
591
- s.superChlorHours = cfg.superChlorHours;
592
- s.body = cfg.body;
593
- msg.isProcessed = true;
594
- }
595
- state.emitEquipmentChanges();
596
- }
597
- private static processPump(msg: Inbound) {
598
- let pumpId = msg.extractPayloadByte(2) + 1;
599
- if (msg.extractPayloadByte(1) === 0) {
600
- let type = msg.extractPayloadByte(3);
601
- let cpump = sys.pumps.getItemById(pumpId, type > 0);
602
- let spump = state.pumps.getItemById(pumpId, type > 0);
603
- cpump.type = type;
604
- spump.type = type;
605
- if (cpump.type >= 2) {
606
- cpump.address = msg.extractPayloadByte(5);
607
- cpump.minSpeed = msg.extractPayloadInt(6);
608
- cpump.maxSpeed = msg.extractPayloadInt(8);
609
- cpump.minFlow = msg.extractPayloadByte(10);
610
- cpump.maxFlow = msg.extractPayloadByte(11);
611
- cpump.flowStepSize = msg.extractPayloadByte(12);
612
- cpump.primingSpeed = msg.extractPayloadInt(13);
613
- cpump.speedStepSize = msg.extractPayloadByte(15) * 10;
614
- cpump.primingTime = msg.extractPayloadByte(16);
615
- cpump.circuits.clear();
616
- for (let i = 18; i < msg.payload.length && i <= 25; i++) {
617
- let circuitId = msg.extractPayloadByte(i);
618
- if (circuitId !== 255) {
619
- let circuit = cpump.circuits.getItemById(i - 17, true);
620
- circuit.circuit = circuitId + 1;
621
- circuit.units = msg.extractPayloadByte(i + 8);
622
- }
623
- }
624
- }
625
- else if (cpump.type === 1) {
626
- cpump.circuits.clear();
627
- cpump.circuits.add({ id: 1, body: msg.extractPayloadByte(18) });
628
- }
629
- if (cpump.type === 0) {
630
- sys.pumps.removeItemById(cpump.id);
631
- state.pumps.removeItemById(cpump.id);
632
- }
633
- }
634
- else if (msg.extractPayloadByte(1) === 1) {
635
- let cpump = sys.pumps.getItemById(pumpId);
636
- let spump = state.pumps.getItemById(pumpId);
637
- cpump.name = msg.extractPayloadString(19, 16);
638
- spump.name = cpump.name;
639
- if (cpump.type > 2) {
640
- for (let i = 3, circuitId = 1; i < msg.payload.length && i <= 18; circuitId++) {
641
- let circuit = cpump.circuits.getItemById(circuitId);
642
- let sp = msg.extractPayloadInt(i);
643
- if (sp < 450)
644
- circuit.flow = sp;
645
- else
646
- circuit.speed = sp;
647
- i += 2;
648
- }
649
- }
650
- spump.emitData('pumpExt', spump.getExtended()); // Do this so clients can delete them.
651
- }
652
- msg.isProcessed = true;
653
- }
654
- private static processFeature(msg: Inbound) {
655
- let featureId = msg.extractPayloadByte(2) + sys.board.equipmentIds.features.start;
656
- let type = msg.extractPayloadByte(3);
657
- let feature = sys.features.getItemById(featureId, type !== 255);
658
- let fstate = state.features.getItemById(featureId, type !== 255);
659
- if (type === 255) {
660
- feature.isActive = false;
661
- sys.features.removeItemById(featureId);
662
- state.features.removeItemById(featureId);
663
- }
664
- else {
665
- feature.freeze = msg.extractPayloadByte(4) > 0;
666
- feature.dontStop = msg.extractPayloadByte(8) > 0;
667
- fstate.name = feature.name = msg.extractPayloadString(9, 16);
668
- fstate.type = feature.type = type;
669
- feature.eggTimer = (msg.extractPayloadByte(6) * 60) + msg.extractPayloadByte(7);
670
- fstate.showInFeatures = feature.showInFeatures = msg.extractPayloadByte(5) > 0;
671
- }
672
- state.emitEquipmentChanges();
673
- msg.isProcessed = true;
674
- }
675
- private static processCircuit(msg: Inbound) {
676
- let circuitId = msg.extractPayloadByte(2) + 1;
677
- let circuit = sys.circuits.getItemById(circuitId, false);
678
- let cstate = state.circuits.getItemById(circuitId, false);
679
- circuit.showInFeatures = msg.extractPayloadByte(5) > 0;
680
- circuit.freeze = msg.extractPayloadByte(4) > 0;
681
- circuit.name = msg.extractPayloadString(10, 16);
682
- circuit.type = msg.extractPayloadByte(3);
683
- circuit.eggTimer = (msg.extractPayloadByte(7) * 60) + msg.extractPayloadByte(8);
684
- circuit.showInFeatures = msg.extractPayloadByte(5) > 0;
685
- cstate.type = circuit.type;
686
- cstate.showInFeatures = circuit.showInFeatures;
687
- cstate.name = circuit.name;
688
- switch (circuit.type) {
689
- case 5:
690
- case 6:
691
- case 8:
692
- circuit.lightingTheme = msg.extractPayloadByte(6);
693
- cstate.lightingTheme = circuit.lightingTheme;
694
- break;
695
- case 9:
696
- circuit.level = msg.extractPayloadByte(6);
697
- cstate.level = circuit.level;
698
- break;
699
- }
700
- state.emitEquipmentChanges();
701
- msg.isProcessed = true;
702
- }
703
- private static processTempSettings(msg: Inbound) {
704
- let fnTranslateByte = (byte: number) => { return (byte & 0x007F) * (((byte & 0x0080) > 0) ? -1 : 1); }
705
- // What the developers did is supply an offset index into the payload for the byte that is
706
- // changing. I suppose this may have been easier but we are not using that logic. We want the
707
- // information to remain decoded so that we aren't guessing which byte does what.
708
- // payLoadIndex = byte(2) + 3 where the first 3 bytes indicate what value changed.
709
- let body: Body = null;
710
- switch (msg.extractPayloadByte(2)) {
711
- case 0: // Water Sensor 2 Adj
712
- sys.equipment.tempSensors.setCalibration('water2', fnTranslateByte(msg.extractPayloadByte(3)));
713
- msg.isProcessed = true;
714
- break;
715
- case 1: // Water Sensor 1 Adj
716
- sys.equipment.tempSensors.setCalibration('water1', fnTranslateByte(msg.extractPayloadByte(4)));
717
- msg.isProcessed = true;
718
- break;
719
- case 2: // Solar Sensor 1 Adj
720
- sys.equipment.tempSensors.setCalibration('solar1', fnTranslateByte(msg.extractPayloadByte(5)));
721
- msg.isProcessed = true;
722
- break;
723
- case 3: // Air Sensor Adj
724
- sys.equipment.tempSensors.setCalibration('air', fnTranslateByte(msg.extractPayloadByte(6)));
725
- msg.isProcessed = true;
726
- break;
727
- case 4: // Water Sensor 2 Adj
728
- sys.equipment.tempSensors.setCalibration('water2', fnTranslateByte(msg.extractPayloadByte(7)));
729
- msg.isProcessed = true;
730
- break;
731
- case 5: // Solar Sensor 2 Adj
732
- sys.equipment.tempSensors.setCalibration('solar2', fnTranslateByte(msg.extractPayloadByte(8)));
733
- msg.isProcessed = true;
734
- break;
735
- case 6: // Water Sensor 3 Adj
736
- sys.equipment.tempSensors.setCalibration('water3', fnTranslateByte(msg.extractPayloadByte(9)));
737
- msg.isProcessed = true;
738
- break;
739
- case 7: // Solar Sensor 3 Adj
740
- sys.equipment.tempSensors.setCalibration('solar3', fnTranslateByte(msg.extractPayloadByte(10)));
741
- msg.isProcessed = true;
742
- break;
743
- case 8: // Water Sensor 4 Adj
744
- sys.equipment.tempSensors.setCalibration('water4', fnTranslateByte(msg.extractPayloadByte(11)));
745
- msg.isProcessed = true;
746
- break;
747
- case 9: // Solar Sensor 4 Adj
748
- sys.equipment.tempSensors.setCalibration('water4', fnTranslateByte(msg.extractPayloadByte(12)));
749
- msg.isProcessed = true;
750
- break;
751
- case 11: // Clock mode
752
- sys.general.options.clockMode = (msg.extractPayloadByte(14) & 0x0001) == 1 ? 24 : 12;
753
- msg.isProcessed = true;
754
- break;
755
- case 12: // This is byte 15 but we don't know what it is. Numbers witnessed include 51, 52, 89, 235.
756
- break;
757
- case 14: // Clock source
758
- if ((msg.extractPayloadByte(17) & 0x0040) === 1)
759
- sys.general.options.clockSource = 'internet';
760
- else if (sys.general.options.clockSource !== 'server')
761
- sys.general.options.clockSource = 'manual';
762
- msg.isProcessed = true;
763
- break;
764
- case 15: // This is byte 18 but we don't know what it is. Numbers witnessed include 1, 2, 3, 5, 100.
765
- break;
766
- case 18: // Body 1 Heat Setpoint
767
- body = sys.bodies.getItemById(1, false);
768
- body.heatSetpoint = msg.extractPayloadByte(21);
769
- state.temps.bodies.getItemById(1).heatSetpoint = body.heatSetpoint;
770
- state.emitEquipmentChanges();
771
- msg.isProcessed = true;
772
- break;
773
- case 19: // Body 1 Cool Setpoint
774
- body = sys.bodies.getItemById(1, false);
775
- body.coolSetpoint = msg.extractPayloadByte(22);
776
- state.temps.bodies.getItemById(1).coolSetpoint = body.coolSetpoint;
777
- state.emitEquipmentChanges();
778
- msg.isProcessed = true;
779
- break;
780
- case 20: // Body 2 Heat Setpoint
781
- body = sys.bodies.getItemById(2, false);
782
- body.heatSetpoint = msg.extractPayloadByte(23);
783
- state.temps.bodies.getItemById(2).heatSetpoint = body.heatSetpoint;
784
- state.emitEquipmentChanges();
785
- msg.isProcessed = true;
786
- break;
787
- case 21: // Body 2 Cool Setpoint
788
- body = sys.bodies.getItemById(2, false);
789
- body.coolSetpoint = msg.extractPayloadByte(24);
790
- state.temps.bodies.getItemById(2).coolSetpoint = body.coolSetpoint;
791
- state.emitEquipmentChanges();
792
- msg.isProcessed = true;
793
- break;
794
- case 22: // Body 1 Heat Mode
795
- body = sys.bodies.getItemById(1, false);
796
- body.heatMode = msg.extractPayloadByte(25);
797
- state.temps.bodies.getItemById(1).heatMode = body.heatMode;
798
- state.emitEquipmentChanges();
799
- msg.isProcessed = true;
800
- break;
801
- case 23: // Body 2 Heat Mode
802
- body = sys.bodies.getItemById(2, false);
803
- body.heatMode = msg.extractPayloadByte(26);
804
- state.temps.bodies.getItemById(2).heatMode = body.heatMode;
805
- state.emitEquipmentChanges();
806
- msg.isProcessed = true;
807
- break;
808
- case 24: // Body 3 Heat Mode
809
- body = sys.bodies.getItemById(3, false);
810
- body.heatMode = msg.extractPayloadByte(27);
811
- state.temps.bodies.getItemById(3).heatMode = body.heatMode;
812
- state.emitEquipmentChanges();
813
- msg.isProcessed = true;
814
- break;
815
- case 25: // Body 4 Heat Mode
816
- body = sys.bodies.getItemById(4, false);
817
- body.heatMode = msg.extractPayloadByte(28);
818
- state.temps.bodies.getItemById(4).heatMode = body.heatMode;
819
- state.emitEquipmentChanges();
820
- msg.isProcessed = true;
821
- break;
822
- case 27: // Pump Valve Delay
823
- sys.general.options.pumpDelay = msg.extractPayloadByte(30) !== 0;
824
- msg.isProcessed = true;
825
- break;
826
- case 28: // Cooldown Delay
827
- sys.general.options.cooldownDelay = msg.extractPayloadByte(31) !== 0;
828
- msg.isProcessed = true;
829
- break;
830
- case 36: // Manual Priority
831
- sys.general.options.manualPriority = msg.extractPayloadByte(39) !== 0;
832
- msg.isProcessed = true;
833
- break;
834
- case 37: // Manual Heat
835
- sys.general.options.manualHeat = msg.extractPayloadByte(40) !== 0;
836
- msg.isProcessed = true;
837
- break;
838
- case 64: // Vacation mode
839
- let yy = msg.extractPayloadByte(5) + 2000;
840
- let mm = msg.extractPayloadByte(6);
841
- let dd = msg.extractPayloadByte(7);
842
- sys.general.options.vacation.startDate = new Date(yy, mm - 1, dd);
843
- yy = msg.extractPayloadByte(8) + 2000;
844
- mm = msg.extractPayloadByte(9);
845
- dd = msg.extractPayloadByte(10);
846
- sys.general.options.vacation.endDate = new Date(yy, mm - 1, dd);
847
- sys.general.options.vacation.enabled = msg.extractPayloadByte(3) > 0;
848
- sys.general.options.vacation.useTimeframe = msg.extractPayloadByte(4) > 0;
849
- msg.isProcessed = true;
850
- break;
851
- }
852
- }
853
- public static processTouchChlorinator(msg: Inbound) {
854
- let isActive = (msg.extractPayloadByte(0) & 0x01) === 1;
855
- let chlor = sys.chlorinators.getItemById(1, isActive);
856
- let schlor = state.chlorinators.getItemById(1, isActive);
857
- chlor.isActive = schlor.isActive = isActive;
858
- if (isActive) {
859
- if (!chlor.disabled) {
860
- // RKS: We don't want these setpoints if our chem controller disabled the
861
- // chlorinator. These should be 0 anyway.
862
- schlor.poolSetpoint = chlor.spaSetpoint = msg.extractPayloadByte(0) >> 1;
863
- schlor.spaSetpoint = chlor.poolSetpoint = msg.extractPayloadByte(1);
864
- if (typeof chlor.address === 'undefined') chlor.address = 80; // chlor.id + 79;
865
- schlor.body = chlor.body = sys.equipment.maxBodies >= 1 || sys.equipment.shared === true ? 32 : 0;
866
- }
867
- schlor.superChlor = chlor.superChlor = msg.extractPayloadByte(2) - 128 > 0;
868
- if (schlor.superChlor) {
869
- schlor.superChlorRemaining = (msg.extractPayloadByte(2) - 128) * 3600;
870
- }
871
- else {
872
- schlor.superChlorRemaining = 0;
873
- }
874
- if (state.temps.bodies.getItemById(1).isOn) schlor.targetOutput = chlor.disabled ? 0 : chlor.poolSetpoint;
875
- else if (state.temps.bodies.getItemById(2).isOn) schlor.targetOutput = chlor.disabled ? 0 : chlor.spaSetpoint;
876
- }
877
- else {
878
- sys.chlorinators.removeItemById(1);
879
- state.chlorinators.removeItemById(1);
880
- }
881
- }
882
- public static processTouchSetHeatMode(msg: Inbound) {
883
- // We get here because some other controller is setting the heat
884
- // mode. The OCP will emit an 8 later but it can be very slow
885
- // in doing this. ScreenLogic also captures this message so it
886
- // doesn't get behind.
887
- //[165, 1, 16, 34, 136, 4][86, 100, 3, 0][2, 33]
888
- //payload: [temp1, temp2, mode2 << 2 | mode1, setPoint],
889
- let bstate1 = state.temps.bodies.getItemById(1);
890
- let bstate2 = state.temps.bodies.getItemById(2);
891
- let body1 = sys.bodies.getItemById(1);
892
- let body2 = sys.bodies.getItemById(2);
893
- let mode1 = msg.extractPayloadByte(2) & 0x03;
894
- let mode2 = (msg.extractPayloadByte(2) & 0x0C) >> 2;
895
- bstate1.setPoint = body1.heatSetpoint = msg.extractPayloadByte(0);
896
- bstate1.coolSetpoint = body1.coolSetpoint = msg.extractPayloadByte(3);
897
- bstate2.setPoint = body2.heatSetpoint = msg.extractPayloadByte(1);
898
- bstate1.heatMode = body1.heatMode = mode1;
899
- bstate2.heatMode = body2.heatMode = mode2;
900
- msg.isProcessed = true;
901
- state.emitEquipmentChanges();
902
-
903
- }
1
+ /* nodejs-poolController. An application to control pool equipment.
2
+ Copyright (C) 2016, 2017, 2018, 2019, 2020, 2021, 2022.
3
+ Russell Goldin, tagyoureit. russ.goldin@gmail.com
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Affero General Public License as
7
+ published by the Free Software Foundation, either version 3 of the
8
+ License, or (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Affero General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Affero General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ import { Inbound } from "../Messages";
19
+ import { sys, Body, ICircuitGroup, LightGroup, CircuitGroup } from "../../../Equipment";
20
+ import { state, ICircuitGroupState, LightGroupState, CircuitGroupState } from "../../../State";
21
+ import { ControllerType, Timestamp, utils } from "../../../Constants";
22
+ import { logger } from "../../../../logger/Logger";
23
+ export class ExternalMessage {
24
+ public static processIntelliCenter(msg: Inbound): void {
25
+ // IntelliCenter v3.x: treat Wireless/ICP/Indoor -> OCP packets as requests, not source-of-truth.
26
+ // We are a bus listener, so we will see traffic not addressed to us; do not apply those requests to state.
27
+ // Only accept OCP-originated messages here. If/when OCP applies a request, it will broadcast authoritative
28
+ // state/config via other message types (e.g., Action 30 / 204).
29
+ if (sys.equipment.isIntellicenterV3 && msg.dest === 16 && msg.source !== 16) {
30
+ msg.isProcessed = true;
31
+ return;
32
+ }
33
+ switch (msg.extractPayloadByte(0)) {
34
+ case 0: // Setpoints/HeatMode
35
+ ExternalMessage.processTempSettings(msg);
36
+ break;
37
+ case 1: // Circuit Changes
38
+ ExternalMessage.processCircuit(msg);
39
+ break;
40
+ case 2: // Feature Changes
41
+ ExternalMessage.processFeature(msg);
42
+ break;
43
+ case 3: // Schedule Changes
44
+ ExternalMessage.processSchedules(msg);
45
+ break;
46
+ case 4: // Pump Information
47
+ ExternalMessage.processPump(msg);
48
+ break;
49
+ case 5: // Remotes
50
+ break;
51
+ case 6: // Light/Circuit group
52
+ ExternalMessage.processGroupSettings(msg);
53
+ break;
54
+ case 7: // Chlorinator
55
+ ExternalMessage.processChlorinator(msg);
56
+ break;
57
+ case 8: // IntelliChem
58
+ ExternalMessage.processIntelliChem(msg);
59
+ break;
60
+ case 9: // Valves
61
+ ExternalMessage.processValve(msg);
62
+ break;
63
+ case 10: // Heaters
64
+ ExternalMessage.processHeater(msg);
65
+ break;
66
+ case 11: // Security
67
+ break;
68
+ case 12: // Pool Settings Alias, owner...etc.
69
+ ExternalMessage.processPool(msg);
70
+ break;
71
+ case 13: // Bodies (Manual heat, capacities)
72
+ ExternalMessage.processBodies(msg);
73
+ break;
74
+ case 14: // Covers
75
+ break;
76
+ case 15: // Circuit, feature, group, and schedule States
77
+ ExternalMessage.processCircuitState(3, msg);
78
+ ExternalMessage.processFeatureState(9, msg);
79
+ ExternalMessage.processScheduleState(15, msg);
80
+ ExternalMessage.processCircuitGroupState(13, msg);
81
+ break;
82
+ default:
83
+ logger.debug(`Unprocessed Message ${msg.toPacket()}`)
84
+ break;
85
+ }
86
+ }
87
+ public static processIntelliChem(msg: Inbound) {
88
+ let id = msg.extractPayloadByte(2) + 1;
89
+ let isActive = utils.makeBool(msg.extractPayloadByte(6));
90
+ //let schem = state.chemchems.getItemById(id, isActive);
91
+ //chem.isActive = schem.isActive = isActive;
92
+ if (isActive) {
93
+ let chem = sys.chemControllers.getItemById(id, true);
94
+ let schem = state.chemControllers.getItemById(id, true);
95
+ // chem.isVirtual = false;
96
+ chem.master = 0;
97
+ chem.ph.tank.capacity = chem.orp.tank.capacity = 6;
98
+ chem.ph.tank.units = chem.orp.tank.units = '';
99
+ schem.type = chem.type = 2;
100
+ schem.name = chem.name = (chem.name || 'IntelliChem' + id);
101
+ schem.body = chem.body = msg.extractPayloadByte(3);
102
+ schem.address = chem.address = msg.extractPayloadByte(5);
103
+ chem.ph.setpoint = schem.ph.setpoint = msg.extractPayloadInt(7) / 100;
104
+ chem.orp.setpoint = schem.orp.setpoint = msg.extractPayloadInt(9);
105
+ chem.calciumHardness = msg.extractPayloadInt(13);
106
+ chem.cyanuricAcid = msg.extractPayloadInt(15);
107
+ chem.alkalinity = msg.extractPayloadInt(17);
108
+ }
109
+ else {
110
+ sys.chemControllers.removeItemById(id);
111
+ state.chemControllers.removeItemById(id);
112
+ }
113
+ msg.isProcessed = true;
114
+ }
115
+ public static processValve(msg: Inbound) {
116
+ let valve = sys.valves.getItemById(msg.extractPayloadByte(2) + 1);
117
+ valve.circuit = msg.extractPayloadByte(3) + 1;
118
+ valve.name = msg.extractPayloadString(4, 16);
119
+ valve.master = 0;
120
+ // valve.isVirtual = false;
121
+ msg.isProcessed = true;
122
+ }
123
+ public static processPool(msg: Inbound) {
124
+ switch (msg.extractPayloadByte(2)) {
125
+ case 0: // Pool Alias
126
+ sys.general.alias = msg.extractPayloadString(3, 16);
127
+ msg.isProcessed = true;
128
+ break;
129
+ case 1: // Address
130
+ sys.general.location.address = msg.extractPayloadString(3, 32);
131
+ msg.isProcessed = true;
132
+ break;
133
+ case 2: // Owner
134
+ sys.general.owner.name = msg.extractPayloadString(3, 16);
135
+ msg.isProcessed = true;
136
+ break;
137
+ case 3: // Email
138
+ sys.general.owner.email = msg.extractPayloadString(3, 32);
139
+ msg.isProcessed = true;
140
+ break;
141
+ case 4: // Email 2
142
+ sys.general.owner.email2 = msg.extractPayloadString(3, 32);
143
+ msg.isProcessed = true;
144
+ break;
145
+ case 5: // Phone
146
+ sys.general.owner.phone = msg.extractPayloadString(3, 16);
147
+ msg.isProcessed = true;
148
+ break;
149
+ case 6: // Phone 2
150
+ sys.general.owner.phone2 = msg.extractPayloadString(3, 16);
151
+ msg.isProcessed = true;
152
+ break;
153
+ case 7: // Zipcode
154
+ sys.general.location.zip = msg.extractPayloadString(3, 6);
155
+ msg.isProcessed = true;
156
+ break;
157
+ case 8: // Country
158
+ sys.general.location.country = msg.extractPayloadString(3, 32);
159
+ msg.isProcessed = true;
160
+ break;
161
+ case 9: // City
162
+ sys.general.location.city = msg.extractPayloadString(3, 32);
163
+ msg.isProcessed = true;
164
+ break;
165
+ case 10: // State
166
+ sys.general.location.state = msg.extractPayloadString(3, 16);
167
+ msg.isProcessed = true;
168
+ break;
169
+ case 11: // Latitute
170
+ sys.general.location.latitude = ((msg.extractPayloadByte(4) * 256) + msg.extractPayloadByte(3)) / 100;
171
+ msg.isProcessed = true;
172
+ break;
173
+ case 12: // Longitude
174
+ sys.general.location.longitude = -((msg.extractPayloadByte(4) * 256) + msg.extractPayloadByte(3)) / 100;
175
+ msg.isProcessed = true;
176
+ break;
177
+ case 13: // Timezone
178
+ sys.general.location.timeZone = msg.extractPayloadByte(3);
179
+ msg.isProcessed = true;
180
+ break;
181
+ }
182
+ }
183
+ public static processGroupSettings(msg: Inbound) {
184
+ // We have 3 potential messages.
185
+ let groupId = msg.extractPayloadByte(2) + sys.board.equipmentIds.circuitGroups.start;
186
+ let group: ICircuitGroup = null;
187
+ let sgroup: ICircuitGroupState = null;
188
+ switch (msg.extractPayloadByte(1)) {
189
+ case 0:
190
+ {
191
+ // Get the type.
192
+ let type = msg.extractPayloadByte(3);
193
+ switch (msg.extractPayloadByte(3)) {
194
+ case 0:
195
+ group = sys.circuitGroups.getInterfaceById(groupId);
196
+ sgroup = group.type === 2 ? state.circuitGroups.getItemById(groupId) : state.lightGroups.getItemById(groupId);
197
+ sys.lightGroups.removeItemById(groupId);
198
+ sys.circuitGroups.removeItemById(groupId);
199
+ state.lightGroups.removeItemById(groupId);
200
+ sys.circuitGroups.removeItemById(groupId);
201
+ sgroup.isActive = false;
202
+ state.emitEquipmentChanges();
203
+ msg.isProcessed = true;
204
+ break;
205
+ case 1:
206
+ group = sys.lightGroups.getItemById(groupId, true);
207
+ sgroup = state.lightGroups.getItemById(groupId, true);
208
+ sys.circuitGroups.removeItemById(groupId);
209
+ state.circuitGroups.removeItemById(groupId);
210
+ sgroup.lightingTheme = group.lightingTheme = msg.extractPayloadByte(4) >> 2;
211
+ sgroup.type = group.type = type;
212
+ sgroup.isActive = group.isActive = true;
213
+ msg.isProcessed = true;
214
+ break;
215
+ case 2:
216
+ group = sys.circuitGroups.getItemById(groupId, true);
217
+ sgroup = state.circuitGroups.getItemById(groupId, true);
218
+ sgroup.type = group.type = type;
219
+ if (typeof group.showInFeatures === 'undefined') group.showInFeatures = sgroup.showInFeatures = true;
220
+ sgroup.showInFeatures = group.showInFeatures;
221
+ sys.lightGroups.removeItemById(groupId);
222
+ state.lightGroups.removeItemById(groupId);
223
+ sgroup.isActive = group.isActive = true;
224
+ msg.isProcessed = true;
225
+ break;
226
+ }
227
+ if (group.isActive) {
228
+ for (let i = 0; i < 16; i++) {
229
+ let circuitId = msg.extractPayloadByte(i + 6);
230
+ let circuit = group.circuits.getItemById(i + 1, circuitId < 255);
231
+ if (circuitId === 255) group.circuits.removeItemById(i + 1);
232
+ circuit.circuit = circuitId + 1;
233
+
234
+ }
235
+ }
236
+ group.eggTimer = (msg.extractPayloadByte(38) * 60) + msg.extractPayloadByte(39);
237
+ group.dontStop = group.eggTimer === 1440;
238
+ // sgroup.eggTimer = group.eggTimer;
239
+ if (type === 1) {
240
+ let g = group as LightGroup;
241
+ for (let i = 0; i < 16; i++) {
242
+ g.circuits.getItemById(i + 1).swimDelay = msg.extractPayloadByte(22 + i);
243
+ }
244
+ }
245
+ state.emitEquipmentChanges();
246
+ msg.isProcessed = true;
247
+ break;
248
+ }
249
+ case 1:
250
+ group = sys.circuitGroups.getInterfaceById(groupId);
251
+ sgroup = group.type === 1 ? state.lightGroups.getItemById(groupId) : state.circuitGroups.getItemById(groupId);
252
+ sgroup.name = group.name = msg.extractPayloadString(19, 16);
253
+ if (group.type === 1) {
254
+ let g = group as LightGroup;
255
+ for (let i = 0; i < 16; i++) {
256
+ let circuit = g.circuits.getItemById(i + 1);
257
+ circuit.color = msg.extractPayloadByte(i + 3);
258
+ }
259
+ }
260
+ state.emitEquipmentChanges();
261
+ msg.isProcessed = true;
262
+ break;
263
+ case 2:
264
+ group = sys.circuitGroups.getInterfaceById(groupId);
265
+ // Process the group states.
266
+ if (group.type === 2) {
267
+ let g = group as CircuitGroup;
268
+ for (let i = 0; i < 16; i++) {
269
+ let desiredState = msg.extractPayloadByte(i + 19);
270
+ let circuit = g.circuits.getItemById(i + 1);
271
+ circuit.desiredState = (desiredState !== 255) ? desiredState : 3;
272
+ }
273
+ }
274
+ msg.isProcessed = true;
275
+ break;
276
+ }
277
+ }
278
+ public static processIntelliCenterState(msg) {
279
+ // This is called from Action 30 case 15 (config message) - NOT Action 168 case 15 (wireless message).
280
+ // Action 30 and Action 168 have different payload structures!
281
+ //
282
+ // v1.x: Original offsets (2, 8, 14, 12) - in place since Oct 2019, working.
283
+ // v3.004+: Different structure, requires offsets (3, 9, 15, 13) to match wireless message layout.
284
+ if (sys.equipment.isIntellicenterV3) {
285
+ ExternalMessage.processCircuitState(3, msg);
286
+ ExternalMessage.processFeatureState(9, msg);
287
+ ExternalMessage.processScheduleState(15, msg);
288
+ ExternalMessage.processCircuitGroupState(13, msg);
289
+ } else {
290
+ // v1.x offsets - preserve original behavior since Oct 2019
291
+ ExternalMessage.processCircuitState(2, msg);
292
+ ExternalMessage.processFeatureState(8, msg);
293
+ ExternalMessage.processScheduleState(14, msg);
294
+ ExternalMessage.processCircuitGroupState(12, msg);
295
+ }
296
+ }
297
+ private static processHeater(msg: Inbound) {
298
+ // So a user is changing the heater info. Lets
299
+ // hijack it and get it ourselves.
300
+ // Installing hybrid heater.
301
+ //[165, 63, 15, 16, 168, 30][10, 0, 2, 5, 32, 5, 6, 3, 0, 6, 112, 72, 121, 98, 114, 105, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 1][4, 230]
302
+ let isActive = msg.extractPayloadByte(3) !== 0;
303
+ let heaterId = msg.extractPayloadByte(2) + 1;
304
+ if (isActive) {
305
+ let heater = sys.heaters.getItemById(heaterId, true);
306
+ let hstate = state.heaters.getItemById(heater.id, true);
307
+
308
+ hstate.type = heater.type = msg.extractPayloadByte(3);
309
+ heater.body = msg.extractPayloadByte(4);
310
+ heater.cooldownDelay = msg.extractPayloadByte(5);
311
+ heater.startTempDelta = msg.extractPayloadByte(6);
312
+ heater.stopTempDelta = msg.extractPayloadByte(7);
313
+ heater.coolingEnabled = msg.extractPayloadByte(8) > 0;
314
+ heater.differentialTemp = msg.extractPayloadByte(9);
315
+ heater.address = msg.extractPayloadByte(10);
316
+ hstate.name = heater.name = msg.extractPayloadString(11, 16);
317
+ heater.efficiencyMode = msg.extractPayloadByte(27);
318
+ heater.maxBoostTemp = msg.extractPayloadByte(28);
319
+ heater.economyTime = msg.extractPayloadByte(29);
320
+ heater.master = 0;
321
+ }
322
+ else {
323
+ sys.heaters.removeItemById(heaterId);
324
+ state.heaters.removeItemById(heaterId);
325
+ }
326
+ sys.board.heaters.updateHeaterServices();
327
+ // Check anyway to make sure we got it all.
328
+ //setTimeout(() => sys.checkConfiguration(), 500);
329
+ msg.isProcessed = true;
330
+ }
331
+
332
+ private static processCircuitState(start: number, msg: Inbound) {
333
+ let circuitId = 1;//sys.board.equipmentIds.circuits.start;
334
+ for (let i = start; i < msg.payload.length && sys.board.equipmentIds.circuits.isInRange(circuitId); i++) {
335
+ let byte = msg.extractPayloadByte(i);
336
+ // Shift each bit getting the circuit identified by each value.
337
+ for (let j = 0; j < 8; j++) {
338
+ let circuit = sys.circuits.getItemById(circuitId);
339
+ let cstate = state.circuits.getItemById(circuitId, circuit.isActive);
340
+ if (circuit.isActive) {
341
+ let isOn = ((byte & (1 << (j))) >> j) > 0;
342
+ sys.board.circuits.setEndTime(circuit, cstate, isOn);
343
+ cstate.isOn = isOn;
344
+ cstate.name = circuit.name;
345
+ cstate.showInFeatures = circuit.showInFeatures;
346
+ cstate.type = circuit.type;
347
+ switch (circuit.type) {
348
+ case 6: // Globrite
349
+ case 5: // Magicstream
350
+ case 8: // Intellibrite
351
+ case 10: // Colorcascade
352
+ cstate.lightingTheme = circuit.lightingTheme;
353
+ if (!isOn) cstate.action = 0;
354
+ break;
355
+ case 9: // Dimmer
356
+ cstate.level = circuit.level;
357
+ break;
358
+ }
359
+ }
360
+ else
361
+ state.circuits.removeItemById(circuitId);
362
+ state.emitEquipmentChanges();
363
+ circuitId++;
364
+ }
365
+ msg.isProcessed = true;
366
+ }
367
+ // state.body = body;
368
+ }
369
+ private static processScheduleState(start: number, msg: Inbound) {
370
+ let scheduleId = 1;
371
+ for (let i = start; i < msg.payload.length && scheduleId <= sys.equipment.maxSchedules; i++) {
372
+ let byte = msg.extractPayloadByte(i);
373
+ // Shift each bit getting the schedule identified by each value.
374
+ for (let j = 0; j < 8; j++) {
375
+ let schedule = sys.schedules.getItemById(scheduleId);
376
+ if (schedule.isActive) {
377
+ if (schedule.circuit > 0) { // Don't get the schedule state if we haven't determined the entire config for it yet.
378
+ let sstate = state.schedules.getItemById(scheduleId, schedule.isActive);
379
+ let isOn = ((byte & (1 << (j))) >> j) > 0;
380
+ sstate.isOn = isOn;
381
+ sstate.circuit = schedule.circuit;
382
+ sstate.endTime = schedule.endTime;
383
+ sstate.startDate = schedule.startDate;
384
+ sstate.startTime = schedule.startTime;
385
+ sstate.scheduleDays = schedule.scheduleDays;
386
+ sstate.scheduleType = schedule.scheduleType;
387
+ sstate.heatSetpoint = schedule.heatSetpoint;
388
+ sstate.heatSource = schedule.heatSource;
389
+ sstate.startTimeType = schedule.startTimeType;
390
+ sstate.endTimeType = schedule.endTimeType;
391
+ sstate.startDate = schedule.startDate;
392
+ }
393
+ }
394
+ else
395
+ state.schedules.removeItemById(scheduleId);
396
+ scheduleId++;
397
+ }
398
+ }
399
+ state.emitEquipmentChanges();
400
+ msg.isProcessed = true;
401
+ }
402
+ public static processFeatureState(start: number, msg: Inbound) {
403
+ let featureId = sys.board.equipmentIds.features.start;
404
+ let maxFeatureId = sys.features.getMaxId(true, 0);
405
+ //console.log(`Max Feature Id = ${maxFeatureId}`);
406
+ for (let i = start; i < msg.payload.length && featureId <= maxFeatureId; i++) {
407
+ let byte = msg.extractPayloadByte(i);
408
+ // Shift each bit getting the feature identified by each value.
409
+ for (let j = 0; j < 8 && featureId <= maxFeatureId; j++) {
410
+ let feature = sys.features.getItemById(featureId, false, { isActive: false });
411
+ if (feature.isActive !== false) {
412
+ let fstate = state.features.getItemById(featureId, true);
413
+ let isOn = (byte & (1 << j)) > 0;
414
+ sys.board.circuits.setEndTime(feature, fstate, isOn);
415
+ fstate.isOn = isOn;
416
+ fstate.name = feature.name;
417
+ }
418
+ else
419
+ // Just a little insurance to remove the feature from the state.
420
+ state.features.removeItemById(featureId);
421
+ featureId++;
422
+ }
423
+ }
424
+ state.emitEquipmentChanges();
425
+ msg.isProcessed = true;
426
+
427
+ }
428
+ private static processCircuitGroupState(start: number, msg: Inbound) {
429
+ let groupId = sys.board.equipmentIds.circuitGroups.start;
430
+ let maxGroupId = Math.max(sys.lightGroups.getMaxId(true, 0), sys.circuitGroups.getMaxId(true, 0));
431
+ for (let i = start; i < msg.payload.length && groupId <= maxGroupId; i++) {
432
+ let byte = msg.extractPayloadByte(i);
433
+ // Shift each bit getting the group identified by each value.
434
+ for (let j = 0; j < 8; j++) {
435
+ let group = sys.circuitGroups.getInterfaceById(groupId);
436
+ let gstate = group.type === 1 ? state.lightGroups.getItemById(groupId, group.isActive) : state.circuitGroups.getItemById(groupId, group.isActive);
437
+
438
+ if (group.isActive !== false) {
439
+ let isOn = ((byte & (1 << (j))) >> j) > 0;
440
+ sys.board.circuits.setEndTime(group, gstate, isOn);
441
+ gstate.isOn = isOn;
442
+ gstate.name = group.name;
443
+ gstate.type = group.type;
444
+ // Now calculate out the sync/set/swim operations.
445
+ if (gstate.dataName === 'lightGroup' && start === 13) {
446
+ let lg = gstate as LightGroupState;
447
+ let ndx = lg.id - sys.board.equipmentIds.circuitGroups.start;
448
+ let byteNdx = Math.floor(ndx / 4);
449
+ let bitNdx = (ndx * 2) - (byteNdx * 8);
450
+ let byte = msg.extractPayloadByte(start + 15 + byteNdx, 255);
451
+ //console.log(`ndx:${start + 15 + byteNdx} byte: ${byte}, bit: ${bitNdx}`);
452
+ byte = ((byte >> bitNdx) & 0x0003);
453
+ // Each light group is represented by two bits on the status byte. There are 3 status bytes that give us only 12 of the 16 on the config stream but the 168 message
454
+ // does acutall send 4 so all are represented there.
455
+ // [10] = Set
456
+ // [01] = Swim
457
+ // [00] = Sync
458
+ // [11] = No sequencing underway.
459
+ switch (byte) {
460
+ case 0: // Sync
461
+ lg.action = sys.board.valueMaps.circuitActions.getValue('colorsync');
462
+ break;
463
+ case 1: // Color swim
464
+ lg.action = sys.board.valueMaps.circuitActions.getValue('colorswim');
465
+ break;
466
+ case 2: // Color set
467
+ lg.action = sys.board.valueMaps.circuitActions.getValue('colorset');
468
+ break;
469
+ default:
470
+ lg.action = 0;
471
+ break;
472
+ }
473
+ }
474
+ else if(gstate.dataName === 'circuitGroup') {
475
+ (gstate as CircuitGroupState).showInFeatures = group.showInFeatures;
476
+ }
477
+ }
478
+ else {
479
+ state.circuitGroups.removeItemById(groupId);
480
+ state.lightGroups.removeItemById(groupId);
481
+ }
482
+ groupId++;
483
+ }
484
+ }
485
+ state.emitEquipmentChanges();
486
+ msg.isProcessed = true;
487
+ }
488
+
489
+ private static processBodies(msg: Inbound) {
490
+ let bodyId = 0;
491
+ let cbody: Body = null;
492
+ switch (msg.extractPayloadByte(2)) {
493
+ case 0:
494
+ case 1:
495
+ case 2:
496
+ case 3:
497
+ bodyId = msg.extractPayloadByte(2);
498
+ if (bodyId === 1) bodyId = 3;
499
+ else if (bodyId === 0) bodyId = 1;
500
+ else if (bodyId === 3) bodyId = 4;
501
+ cbody = sys.bodies.getItemById(bodyId);
502
+ cbody.name = msg.extractPayloadString(3, 16);
503
+ state.temps.bodies.getItemById(bodyId, false).name = cbody.name;
504
+ msg.isProcessed = true;
505
+ break;
506
+ case 4:
507
+ case 5:
508
+ case 6:
509
+ case 7:
510
+ bodyId = msg.extractPayloadByte(2) - 4;
511
+ if (bodyId === 1) bodyId = 3;
512
+ else if (bodyId === 0) bodyId = 1;
513
+ else if (bodyId === 3) bodyId = 4;
514
+ cbody = sys.bodies.getItemById(bodyId);
515
+ cbody.capacity = msg.extractPayloadByte(3) * 1000;
516
+ msg.isProcessed = true;
517
+ break;
518
+ case 12: // Circuit notifications
519
+ if (msg.payload.length > 3) {
520
+ const value = msg.extractPayloadByte(3, 0);
521
+ sys.alerts.circuitNotifications = value;
522
+ sys.alerts.setRaw(12, [value]);
523
+ }
524
+ msg.isProcessed = true;
525
+ break;
526
+ case 13: // Pump notifications
527
+ ExternalMessage.applyAlertNotificationFromExternal(msg, 13, 3);
528
+ msg.isProcessed = true;
529
+ break;
530
+ case 14: // Heater notifications
531
+ ExternalMessage.applyAlertNotificationFromExternal(msg, 14, 3);
532
+ msg.isProcessed = true;
533
+ break;
534
+ case 15: // Chlorinator notifications
535
+ ExternalMessage.applyAlertNotificationFromExternal(msg, 15, 3);
536
+ msg.isProcessed = true;
537
+ break;
538
+ }
539
+ state.emitEquipmentChanges();
540
+ }
541
+ private static applyAlertNotificationFromExternal(msg: Inbound, selector: number, startOffset: number) {
542
+ const raw: number[] = [];
543
+ for (let i = startOffset; i < msg.payload.length; i++) raw.push(msg.extractPayloadByte(i, 0));
544
+ sys.alerts.setRaw(selector, raw);
545
+ if (raw.length === 0) return;
546
+ const mask = raw.length === 1 ? (raw[0] & 0xFF) : (((raw[raw.length - 2] & 0xFF) << 8) | (raw[raw.length - 1] & 0xFF));
547
+ switch (selector) {
548
+ case 13:
549
+ sys.alerts.pumpNotifications = mask;
550
+ break;
551
+ case 14:
552
+ sys.alerts.heaterNotifications = mask;
553
+ break;
554
+ case 15:
555
+ sys.alerts.chlorinatorNotifications = mask;
556
+ break;
557
+ }
558
+ }
559
+ private static processSchedules(msg: Inbound) {
560
+ let schedId = msg.extractPayloadByte(2) + 1;
561
+ // v3.004+: schedule times are big-endian (hi,lo) in Action 168 payloads.
562
+ // v1.x: schedule times are little-endian (lo,hi).
563
+ let startTime: number;
564
+ let endTime: number;
565
+ if (sys.controllerType === ControllerType.IntelliCenter && sys.equipment.isIntellicenterV3) {
566
+ startTime = msg.extractPayloadIntBE(3);
567
+ endTime = msg.extractPayloadIntBE(5);
568
+ } else {
569
+ startTime = msg.extractPayloadInt(3);
570
+ endTime = msg.extractPayloadInt(5);
571
+ }
572
+ let circuit = msg.extractPayloadByte(7) + 1;
573
+ let isActive = (msg.extractPayloadByte(8) & 128) === 128; // Inactive schedules do not have bit 8 set.
574
+ let cfg = sys.schedules.getItemById(schedId, isActive);
575
+ let s = state.schedules.getItemById(schedId, cfg.isActive);
576
+ //cfg.isActive = (circuit !== 256);
577
+ cfg.startTime = startTime;
578
+ cfg.endTime = endTime;
579
+ cfg.circuit = circuit;
580
+ cfg.isActive = isActive;
581
+ let byte = msg.extractPayloadByte(8);
582
+ cfg.scheduleType = (byte & 1 & 0xFF) === 1 ? 0 : 128;
583
+ if ((byte & 4 & 0xFF) === 4) cfg.startTimeType = 1;
584
+ else if ((byte & 8 & 0xFF) === 8) cfg.startTimeType = 2;
585
+ else cfg.startTimeType = 0;
586
+
587
+ if ((byte & 16 & 0xFF) === 16) cfg.endTimeType = 1;
588
+ else if ((byte & 32 & 0xFF) === 32) cfg.endTimeType = 2;
589
+ else cfg.endTimeType = 0;
590
+ //cfg.runOnce = byte;
591
+ cfg.scheduleDays = msg.extractPayloadByte(9);
592
+ cfg.startMonth = msg.extractPayloadByte(10);
593
+ cfg.startDay = msg.extractPayloadByte(11);
594
+ cfg.startYear = msg.extractPayloadByte(12);
595
+ let hs = msg.extractPayloadByte(13);
596
+ // RKS: During the transition to 1.047 the heat sources were all screwed up. O now means no change and 1 means off.
597
+ //if (hs === 1) hs = 0; // Shim for 1.047
598
+ cfg.heatSource = hs;
599
+ cfg.heatSetpoint = msg.extractPayloadByte(14);
600
+ cfg.coolSetpoint = msg.extractPayloadByte(15);
601
+ if (cfg.isActive) {
602
+ let s = state.schedules.getItemById(schedId, cfg.isActive);
603
+ s.isActive = cfg.isActive = true;
604
+ s.startTime = cfg.startTime;
605
+ s.endTime = cfg.endTime;
606
+ s.circuit = cfg.circuit;
607
+ s.scheduleType = cfg.scheduleType;
608
+ s.scheduleDays = cfg.scheduleType === 128 ? cfg.scheduleDays : 0;
609
+ s.heatSetpoint = cfg.heatSetpoint;
610
+ s.coolSetpoint = cfg.coolSetpoint;
611
+ s.heatSource = cfg.heatSource;
612
+ s.startDate = cfg.startDate;
613
+ s.startTimeType = cfg.startTimeType;
614
+ s.endTimeType = cfg.endTimeType;
615
+ }
616
+ else {
617
+ s.isActive = cfg.isActive = false;
618
+ sys.schedules.removeItemById(cfg.id);
619
+ state.schedules.removeItemById(cfg.id);
620
+ s.emitEquipmentChange();
621
+ }
622
+ state.emitEquipmentChanges();
623
+ msg.isProcessed = true;
624
+ }
625
+ private static processChlorinator(msg: Inbound) {
626
+ let isActive = msg.extractPayloadByte(10) > 0;
627
+ let chlorId = msg.extractPayloadByte(2) + 1;
628
+ let cfg = sys.chlorinators.getItemById(chlorId, isActive);
629
+ let s = state.chlorinators.getItemById(chlorId, isActive);
630
+ if (!isActive) {
631
+ sys.chlorinators.removeItemById(chlorId);
632
+ state.chlorinators.removeItemById(chlorId);
633
+ s.emitEquipmentChange();
634
+ msg.isProcessed = true;
635
+ return;
636
+ }
637
+ else {
638
+
639
+ cfg.body = msg.extractPayloadByte(3);
640
+ cfg.poolSetpoint = msg.extractPayloadByte(5);
641
+ if (!cfg.disabled) {
642
+ // RKS: We don't want theses setpoints if our chem controller
643
+ // disabled the chlorinator.
644
+ cfg.spaSetpoint = msg.extractPayloadByte(6);
645
+ cfg.superChlor = msg.extractPayloadByte(7) > 0;
646
+ }
647
+ cfg.superChlorHours = msg.extractPayloadByte(8);
648
+ s.poolSetpoint = cfg.poolSetpoint;
649
+ s.spaSetpoint = cfg.spaSetpoint;
650
+ s.superChlorHours = cfg.superChlorHours;
651
+ s.body = cfg.body;
652
+ msg.isProcessed = true;
653
+ }
654
+ state.emitEquipmentChanges();
655
+ }
656
+ private static processPump(msg: Inbound) {
657
+ let pumpId = msg.extractPayloadByte(2) + 1;
658
+ const useBigEndian = sys.controllerType === ControllerType.IntelliCenter && sys.equipment.isIntellicenterV3;
659
+ const readInt = (ndx: number) => useBigEndian ? msg.extractPayloadIntBE(ndx) : msg.extractPayloadInt(ndx);
660
+ if (msg.extractPayloadByte(1) === 0) {
661
+ let type = msg.extractPayloadByte(3);
662
+ let cpump = sys.pumps.getItemById(pumpId, type > 0);
663
+ let spump = state.pumps.getItemById(pumpId, type > 0);
664
+ cpump.type = type;
665
+ spump.type = type;
666
+ if (cpump.type >= 2) {
667
+ cpump.address = msg.extractPayloadByte(5);
668
+ cpump.minSpeed = readInt(6);
669
+ cpump.maxSpeed = readInt(8);
670
+ cpump.minFlow = msg.extractPayloadByte(10);
671
+ cpump.maxFlow = msg.extractPayloadByte(11);
672
+ cpump.flowStepSize = msg.extractPayloadByte(12);
673
+ cpump.primingSpeed = readInt(13);
674
+ cpump.speedStepSize = msg.extractPayloadByte(15) * 10;
675
+ cpump.primingTime = msg.extractPayloadByte(16);
676
+ cpump.circuits.clear();
677
+ for (let i = 18; i < msg.payload.length && i <= 25; i++) {
678
+ let circuitId = msg.extractPayloadByte(i);
679
+ if (circuitId !== 255) {
680
+ let circuit = cpump.circuits.getItemById(i - 17, true);
681
+ circuit.circuit = circuitId + 1;
682
+ circuit.units = msg.extractPayloadByte(i + 8);
683
+ }
684
+ }
685
+ }
686
+ else if (cpump.type === 1) {
687
+ cpump.circuits.clear();
688
+ cpump.circuits.add({ id: 1, body: msg.extractPayloadByte(18) });
689
+ }
690
+ if (cpump.type === 0) {
691
+ sys.pumps.removeItemById(cpump.id);
692
+ state.pumps.removeItemById(cpump.id);
693
+ }
694
+ }
695
+ else if (msg.extractPayloadByte(1) === 1) {
696
+ let cpump = sys.pumps.getItemById(pumpId);
697
+ let spump = state.pumps.getItemById(pumpId);
698
+ cpump.name = msg.extractPayloadString(19, 16);
699
+ spump.name = cpump.name;
700
+ if (cpump.type > 2) {
701
+ for (let i = 3, circuitId = 1; i < msg.payload.length && i <= 18; circuitId++) {
702
+ let circuit = cpump.circuits.getItemById(circuitId);
703
+ let sp = readInt(i);
704
+ if (sp < 450)
705
+ circuit.flow = sp;
706
+ else
707
+ circuit.speed = sp;
708
+ i += 2;
709
+ }
710
+ }
711
+ spump.emitData('pumpExt', spump.getExtended()); // Do this so clients can delete them.
712
+ }
713
+ msg.isProcessed = true;
714
+ }
715
+ private static processFeature(msg: Inbound) {
716
+ let featureId = msg.extractPayloadByte(2) + sys.board.equipmentIds.features.start;
717
+ let type = msg.extractPayloadByte(3);
718
+ let feature = sys.features.getItemById(featureId, type !== 255);
719
+ let fstate = state.features.getItemById(featureId, type !== 255);
720
+ if (type === 255) {
721
+ feature.isActive = false;
722
+ sys.features.removeItemById(featureId);
723
+ state.features.removeItemById(featureId);
724
+ }
725
+ else {
726
+ feature.freeze = msg.extractPayloadByte(4) > 0;
727
+ feature.dontStop = msg.extractPayloadByte(8) > 0;
728
+ fstate.name = feature.name = msg.extractPayloadString(9, 16);
729
+ fstate.type = feature.type = type;
730
+ feature.eggTimer = (msg.extractPayloadByte(6) * 60) + msg.extractPayloadByte(7);
731
+ fstate.showInFeatures = feature.showInFeatures = msg.extractPayloadByte(5) > 0;
732
+ }
733
+ state.emitEquipmentChanges();
734
+ msg.isProcessed = true;
735
+ }
736
+ private static processCircuit(msg: Inbound) {
737
+ let circuitId = msg.extractPayloadByte(2) + 1;
738
+ let circuit = sys.circuits.getItemById(circuitId, false);
739
+ let cstate = state.circuits.getItemById(circuitId, false);
740
+ circuit.showInFeatures = msg.extractPayloadByte(5) > 0;
741
+ circuit.freeze = msg.extractPayloadByte(4) > 0;
742
+ circuit.name = msg.extractPayloadString(10, 16);
743
+ circuit.type = msg.extractPayloadByte(3);
744
+ circuit.eggTimer = (msg.extractPayloadByte(7) * 60) + msg.extractPayloadByte(8);
745
+ circuit.showInFeatures = msg.extractPayloadByte(5) > 0;
746
+ cstate.type = circuit.type;
747
+ cstate.showInFeatures = circuit.showInFeatures;
748
+ cstate.name = circuit.name;
749
+ switch (circuit.type) {
750
+ case 5:
751
+ case 6:
752
+ case 8:
753
+ circuit.lightingTheme = msg.extractPayloadByte(6);
754
+ cstate.lightingTheme = circuit.lightingTheme;
755
+ break;
756
+ case 9:
757
+ circuit.level = msg.extractPayloadByte(6);
758
+ cstate.level = circuit.level;
759
+ break;
760
+ }
761
+ state.emitEquipmentChanges();
762
+ msg.isProcessed = true;
763
+ }
764
+ private static processTempSettings(msg: Inbound) {
765
+ let fnTranslateByte = (byte: number) => { return (byte & 0x007F) * (((byte & 0x0080) > 0) ? -1 : 1); }
766
+ const decodeFreezeOverride = (raw: number) => raw <= 3 ? (30 + (raw * 60)) : raw;
767
+
768
+ // v3.004+: Wireless sends the FULL options block, not a single-field notification.
769
+ // v1.x: Used byte[2] as a pivot/index indicating which field changed, then byte[byte[2]+3] = new value.
770
+ //
771
+ // IMPORTANT: v3 Action 168 from Wireless has DIFFERENT offsets than Action 30 type 0!
772
+ // - Action 30 type 0: poolHeatNdx=19, spaHeatNdx=21, poolModeNdx=23, spaModeNdx=24
773
+ // - Action 168 Wireless: poolHeatNdx=20, spaHeatNdx=22, poolModeNdx=24, spaModeNdx=25
774
+ // The Wireless payload has an extra byte at position 4, shifting everything by +1.
775
+ const isIntellicenterV3 = (sys.controllerType === ControllerType.IntelliCenter && sys.equipment.isIntellicenterV3);
776
+
777
+ // Detect v3 full-block format by payload length (v3 sends 41 bytes for msgType 0)
778
+ if (isIntellicenterV3 && msg.payload.length >= 27) {
779
+ // v3.004+ Wireless full options block - different offsets than Action 30.
780
+ // Most captures use offsets [20..25], but some packets include an extra
781
+ // timestamp-like byte before setpoints, shifting to [21..26].
782
+ const buildCandidate = (shift: number) => ({
783
+ shift,
784
+ poolHeat: msg.extractPayloadByte(20 + shift),
785
+ poolCool: msg.extractPayloadByte(21 + shift),
786
+ spaHeat: msg.extractPayloadByte(22 + shift),
787
+ spaCool: msg.extractPayloadByte(23 + shift),
788
+ poolMode: msg.extractPayloadByte(24 + shift),
789
+ spaMode: msg.extractPayloadByte(25 + shift),
790
+ freezeCycleTime: msg.extractPayloadByte(26 + shift, 255),
791
+ freezeOverrideRaw: msg.extractPayloadByte(27 + shift, 255),
792
+ manualPriority: msg.extractPayloadByte(28 + shift, 255)
793
+ });
794
+ const scoreCandidate = (c: { poolHeat: number, poolCool: number, spaHeat: number, spaCool: number, poolMode: number, spaMode: number }) => {
795
+ let score = 0;
796
+ const isTemp = (v: number) => v > 0 && v <= 120;
797
+ const isMode = (v: number) => v > 0 && v <= 100;
798
+ if (isTemp(c.poolHeat)) score += 3;
799
+ if (isTemp(c.spaHeat)) score += 3;
800
+ if (isTemp(c.poolCool)) score += 2;
801
+ if (isTemp(c.spaCool)) score += 2;
802
+ if (isMode(c.poolMode)) score += 1;
803
+ if (isMode(c.spaMode)) score += 1;
804
+ return score;
805
+ };
806
+ let selected = buildCandidate(0);
807
+ if (msg.payload.length >= 27) {
808
+ const shifted = buildCandidate(1);
809
+ if (scoreCandidate(shifted) > scoreCandidate(selected)) selected = shifted;
810
+ }
811
+ if (selected.shift !== 0) {
812
+ logger.silly(`v3.004+ Action 168: using shifted temp offsets (+${selected.shift})`);
813
+ }
814
+
815
+ // Update Body 1 (Pool)
816
+ let body = sys.bodies.getItemById(1, sys.equipment.maxBodies > 0);
817
+ let sbody = state.temps.bodies.getItemById(1);
818
+ if (body.isActive) {
819
+ const newPoolHeat = selected.poolHeat;
820
+ const newPoolCool = selected.poolCool;
821
+ const newPoolMode = selected.poolMode;
822
+ logger.silly(`v3.004+ Action 168: Pool setpoint ${body.heatSetpoint} → ${newPoolHeat}, coolSetpoint ${body.coolSetpoint} → ${newPoolCool}, mode ${body.heatMode} → ${newPoolMode}`);
823
+ body.heatSetpoint = newPoolHeat;
824
+ body.coolSetpoint = newPoolCool;
825
+ body.heatMode = newPoolMode;
826
+ sbody.heatSetpoint = body.heatSetpoint;
827
+ sbody.coolSetpoint = body.coolSetpoint;
828
+ sbody.heatMode = body.heatMode;
829
+ }
830
+
831
+ // Update Body 2 (Spa)
832
+ body = sys.bodies.getItemById(2, sys.equipment.maxBodies > 1);
833
+ sbody = state.temps.bodies.getItemById(2);
834
+ if (body.isActive) {
835
+ const newSpaHeat = selected.spaHeat;
836
+ const newSpaCool = selected.spaCool;
837
+ const newSpaMode = selected.spaMode;
838
+ logger.silly(`v3.004+ Action 168: Spa setpoint ${body.heatSetpoint} → ${newSpaHeat}, coolSetpoint ${body.coolSetpoint} → ${newSpaCool}, mode ${body.heatMode} → ${newSpaMode}`);
839
+ body.heatSetpoint = newSpaHeat;
840
+ body.coolSetpoint = newSpaCool;
841
+ body.heatMode = newSpaMode;
842
+ sbody.heatSetpoint = body.heatSetpoint;
843
+ sbody.coolSetpoint = body.coolSetpoint;
844
+ sbody.heatMode = body.heatMode;
845
+ }
846
+ if (selected.freezeCycleTime !== 255) sys.general.options.freezeCycleTime = selected.freezeCycleTime;
847
+ if (selected.freezeOverrideRaw !== 255) sys.general.options.freezeOverride = decodeFreezeOverride(selected.freezeOverrideRaw);
848
+ if (selected.manualPriority !== 255) sys.general.options.manualPriority = selected.manualPriority > 0;
849
+
850
+ state.emitEquipmentChanges();
851
+ msg.isProcessed = true;
852
+ return;
853
+ }
854
+
855
+ // v1.x: Single-field-changed notification using byte[2] as pivot index.
856
+ // payLoadIndex = byte(2) + 3 where the first 3 bytes indicate what value changed.
857
+ let body: Body = null;
858
+ switch (msg.extractPayloadByte(2)) {
859
+ case 0: // Water Sensor 2 Adj
860
+ sys.equipment.tempSensors.setCalibration('water2', fnTranslateByte(msg.extractPayloadByte(3)));
861
+ msg.isProcessed = true;
862
+ break;
863
+ case 1: // Water Sensor 1 Adj
864
+ sys.equipment.tempSensors.setCalibration('water1', fnTranslateByte(msg.extractPayloadByte(4)));
865
+ msg.isProcessed = true;
866
+ break;
867
+ case 2: // Solar Sensor 1 Adj
868
+ sys.equipment.tempSensors.setCalibration('solar1', fnTranslateByte(msg.extractPayloadByte(5)));
869
+ msg.isProcessed = true;
870
+ break;
871
+ case 3: // Air Sensor Adj
872
+ sys.equipment.tempSensors.setCalibration('air', fnTranslateByte(msg.extractPayloadByte(6)));
873
+ msg.isProcessed = true;
874
+ break;
875
+ case 4: // Water Sensor 2 Adj
876
+ sys.equipment.tempSensors.setCalibration('water2', fnTranslateByte(msg.extractPayloadByte(7)));
877
+ msg.isProcessed = true;
878
+ break;
879
+ case 5: // Solar Sensor 2 Adj
880
+ sys.equipment.tempSensors.setCalibration('solar2', fnTranslateByte(msg.extractPayloadByte(8)));
881
+ msg.isProcessed = true;
882
+ break;
883
+ case 6: // Water Sensor 3 Adj
884
+ sys.equipment.tempSensors.setCalibration('water3', fnTranslateByte(msg.extractPayloadByte(9)));
885
+ msg.isProcessed = true;
886
+ break;
887
+ case 7: // Solar Sensor 3 Adj
888
+ sys.equipment.tempSensors.setCalibration('solar3', fnTranslateByte(msg.extractPayloadByte(10)));
889
+ msg.isProcessed = true;
890
+ break;
891
+ case 8: // Water Sensor 4 Adj
892
+ sys.equipment.tempSensors.setCalibration('water4', fnTranslateByte(msg.extractPayloadByte(11)));
893
+ msg.isProcessed = true;
894
+ break;
895
+ case 9: // Solar Sensor 4 Adj
896
+ sys.equipment.tempSensors.setCalibration('water4', fnTranslateByte(msg.extractPayloadByte(12)));
897
+ msg.isProcessed = true;
898
+ break;
899
+ case 11: // Clock mode
900
+ sys.general.options.clockMode = (msg.extractPayloadByte(14) & 0x0001) == 1 ? 24 : 12;
901
+ msg.isProcessed = true;
902
+ break;
903
+ case 12: // This is byte 15 but we don't know what it is. Numbers witnessed include 51, 52, 89, 235.
904
+ break;
905
+ case 14: // Clock source
906
+ if ((msg.extractPayloadByte(17) & 0x0040) === 1)
907
+ sys.general.options.clockSource = 'internet';
908
+ else if (sys.general.options.clockSource !== 'server')
909
+ sys.general.options.clockSource = 'manual';
910
+ msg.isProcessed = true;
911
+ break;
912
+ case 15: // This is byte 18 but we don't know what it is. Numbers witnessed include 1, 2, 3, 5, 100.
913
+ break;
914
+ case 18: // Body 1 Heat Setpoint
915
+ body = sys.bodies.getItemById(1, false);
916
+ body.heatSetpoint = msg.extractPayloadByte(21);
917
+ state.temps.bodies.getItemById(1).heatSetpoint = body.heatSetpoint;
918
+ state.emitEquipmentChanges();
919
+ msg.isProcessed = true;
920
+ break;
921
+ case 19: // Body 1 Cool Setpoint
922
+ body = sys.bodies.getItemById(1, false);
923
+ body.coolSetpoint = msg.extractPayloadByte(22);
924
+ state.temps.bodies.getItemById(1).coolSetpoint = body.coolSetpoint;
925
+ state.emitEquipmentChanges();
926
+ msg.isProcessed = true;
927
+ break;
928
+ case 20: // Body 2 Heat Setpoint
929
+ body = sys.bodies.getItemById(2, false);
930
+ body.heatSetpoint = msg.extractPayloadByte(23);
931
+ state.temps.bodies.getItemById(2).heatSetpoint = body.heatSetpoint;
932
+ state.emitEquipmentChanges();
933
+ msg.isProcessed = true;
934
+ break;
935
+ case 21: // Body 2 Cool Setpoint
936
+ body = sys.bodies.getItemById(2, false);
937
+ body.coolSetpoint = msg.extractPayloadByte(24);
938
+ state.temps.bodies.getItemById(2).coolSetpoint = body.coolSetpoint;
939
+ state.emitEquipmentChanges();
940
+ msg.isProcessed = true;
941
+ break;
942
+ case 22: // Body 1 Heat Mode
943
+ body = sys.bodies.getItemById(1, false);
944
+ body.heatMode = msg.extractPayloadByte(25);
945
+ state.temps.bodies.getItemById(1).heatMode = body.heatMode;
946
+ state.emitEquipmentChanges();
947
+ msg.isProcessed = true;
948
+ break;
949
+ case 23: // Body 2 Heat Mode
950
+ body = sys.bodies.getItemById(2, false);
951
+ body.heatMode = msg.extractPayloadByte(26);
952
+ state.temps.bodies.getItemById(2).heatMode = body.heatMode;
953
+ state.emitEquipmentChanges();
954
+ msg.isProcessed = true;
955
+ break;
956
+ case 24: // Body 3 Heat Mode
957
+ body = sys.bodies.getItemById(3, false);
958
+ body.heatMode = msg.extractPayloadByte(27);
959
+ state.temps.bodies.getItemById(3).heatMode = body.heatMode;
960
+ state.emitEquipmentChanges();
961
+ msg.isProcessed = true;
962
+ break;
963
+ case 25: // Body 4 Heat Mode
964
+ body = sys.bodies.getItemById(4, false);
965
+ body.heatMode = msg.extractPayloadByte(28);
966
+ state.temps.bodies.getItemById(4).heatMode = body.heatMode;
967
+ state.emitEquipmentChanges();
968
+ msg.isProcessed = true;
969
+ break;
970
+ case 27: // Pump Valve Delay
971
+ sys.general.options.pumpDelay = msg.extractPayloadByte(30) !== 0;
972
+ msg.isProcessed = true;
973
+ break;
974
+ case 28: // Cooldown Delay
975
+ sys.general.options.cooldownDelay = msg.extractPayloadByte(31) !== 0;
976
+ msg.isProcessed = true;
977
+ break;
978
+ case 36: // Manual Priority
979
+ sys.general.options.manualPriority = msg.extractPayloadByte(39) !== 0;
980
+ msg.isProcessed = true;
981
+ break;
982
+ case 37: // Manual Heat
983
+ sys.general.options.manualHeat = msg.extractPayloadByte(40) !== 0;
984
+ msg.isProcessed = true;
985
+ break;
986
+ case 64: // Vacation mode
987
+ let yy = msg.extractPayloadByte(5) + 2000;
988
+ let mm = msg.extractPayloadByte(6);
989
+ let dd = msg.extractPayloadByte(7);
990
+ sys.general.options.vacation.startDate = new Date(yy, mm - 1, dd);
991
+ yy = msg.extractPayloadByte(8) + 2000;
992
+ mm = msg.extractPayloadByte(9);
993
+ dd = msg.extractPayloadByte(10);
994
+ sys.general.options.vacation.endDate = new Date(yy, mm - 1, dd);
995
+ sys.general.options.vacation.enabled = msg.extractPayloadByte(3) > 0;
996
+ sys.general.options.vacation.useTimeframe = msg.extractPayloadByte(4) > 0;
997
+ msg.isProcessed = true;
998
+ break;
999
+ }
1000
+ }
1001
+ public static processTouchChlorinator(msg: Inbound) {
1002
+ let isActive = (msg.extractPayloadByte(0) & 0x01) === 1;
1003
+ let chlor = sys.chlorinators.getItemById(1, isActive);
1004
+ let schlor = state.chlorinators.getItemById(1, isActive);
1005
+ chlor.isActive = schlor.isActive = isActive;
1006
+ if (isActive) {
1007
+ if (!chlor.disabled) {
1008
+ // RKS: We don't want these setpoints if our chem controller disabled the
1009
+ // chlorinator. These should be 0 anyway.
1010
+ schlor.poolSetpoint = chlor.spaSetpoint = msg.extractPayloadByte(0) >> 1;
1011
+ schlor.spaSetpoint = chlor.poolSetpoint = msg.extractPayloadByte(1);
1012
+ if (typeof chlor.address === 'undefined') chlor.address = 80; // chlor.id + 79;
1013
+ schlor.body = chlor.body = sys.equipment.maxBodies >= 1 || sys.equipment.shared === true ? 32 : 0;
1014
+ }
1015
+ schlor.superChlor = chlor.superChlor = msg.extractPayloadByte(2) - 128 > 0;
1016
+ if (schlor.superChlor) {
1017
+ schlor.superChlorRemaining = (msg.extractPayloadByte(2) - 128) * 3600;
1018
+ }
1019
+ else {
1020
+ schlor.superChlorRemaining = 0;
1021
+ }
1022
+ if (state.temps.bodies.getItemById(1).isOn) schlor.targetOutput = chlor.disabled ? 0 : chlor.poolSetpoint;
1023
+ else if (state.temps.bodies.getItemById(2).isOn) schlor.targetOutput = chlor.disabled ? 0 : chlor.spaSetpoint;
1024
+ }
1025
+ else {
1026
+ sys.chlorinators.removeItemById(1);
1027
+ state.chlorinators.removeItemById(1);
1028
+ }
1029
+ }
1030
+ public static processTouchSetHeatMode(msg: Inbound) {
1031
+ // We get here because some other controller is setting the heat
1032
+ // mode. The OCP will emit an 8 later but it can be very slow
1033
+ // in doing this. ScreenLogic also captures this message so it
1034
+ // doesn't get behind.
1035
+ //[165, 1, 16, 34, 136, 4][86, 100, 3, 0][2, 33]
1036
+ //payload: [temp1, temp2, mode2 << 2 | mode1, setPoint],
1037
+ let bstate1 = state.temps.bodies.getItemById(1);
1038
+ let bstate2 = state.temps.bodies.getItemById(2);
1039
+ let body1 = sys.bodies.getItemById(1);
1040
+ let body2 = sys.bodies.getItemById(2);
1041
+ let mode1 = msg.extractPayloadByte(2) & 0x03;
1042
+ let mode2 = (msg.extractPayloadByte(2) & 0x0C) >> 2;
1043
+ bstate1.setPoint = body1.heatSetpoint = msg.extractPayloadByte(0);
1044
+ bstate1.coolSetpoint = body1.coolSetpoint = msg.extractPayloadByte(3);
1045
+ bstate2.setPoint = body2.heatSetpoint = msg.extractPayloadByte(1);
1046
+ bstate1.heatMode = body1.heatMode = mode1;
1047
+ bstate2.heatMode = body2.heatMode = mode2;
1048
+ msg.isProcessed = true;
1049
+ state.emitEquipmentChanges();
1050
+
1051
+ }
904
1052
  }