nodejs-poolcontroller 8.4.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 (35) hide show
  1. package/.github/workflows/ghcr-publish.yml +1 -1
  2. package/157_issues.md +101 -0
  3. package/AGENTS.md +17 -1
  4. package/README.md +13 -2
  5. package/controller/Equipment.ts +49 -0
  6. package/controller/State.ts +8 -0
  7. package/controller/boards/AquaLinkBoard.ts +174 -2
  8. package/controller/boards/EasyTouchBoard.ts +44 -0
  9. package/controller/boards/IntelliCenterBoard.ts +360 -172
  10. package/controller/boards/NixieBoard.ts +7 -4
  11. package/controller/boards/SunTouchBoard.ts +1 -0
  12. package/controller/boards/SystemBoard.ts +39 -4
  13. package/controller/comms/Comms.ts +9 -3
  14. package/controller/comms/messages/Messages.ts +218 -24
  15. package/controller/comms/messages/config/EquipmentMessage.ts +34 -0
  16. package/controller/comms/messages/config/ExternalMessage.ts +1051 -989
  17. package/controller/comms/messages/config/GeneralMessage.ts +65 -0
  18. package/controller/comms/messages/config/OptionsMessage.ts +15 -2
  19. package/controller/comms/messages/config/PumpMessage.ts +427 -421
  20. package/controller/comms/messages/config/SecurityMessage.ts +37 -13
  21. package/controller/comms/messages/status/EquipmentStateMessage.ts +0 -218
  22. package/controller/comms/messages/status/HeaterStateMessage.ts +27 -15
  23. package/controller/comms/messages/status/NeptuneModbusStateMessage.ts +217 -0
  24. package/controller/comms/messages/status/VersionMessage.ts +67 -18
  25. package/controller/nixie/chemistry/ChemController.ts +65 -33
  26. package/controller/nixie/heaters/Heater.ts +10 -1
  27. package/controller/nixie/pumps/Pump.ts +145 -2
  28. package/docker-compose.yml +1 -0
  29. package/logger/Logger.ts +75 -64
  30. package/package.json +1 -1
  31. package/tsconfig.json +2 -1
  32. package/web/Server.ts +3 -1
  33. package/web/services/config/Config.ts +150 -1
  34. package/web/services/state/State.ts +21 -0
  35. package/web/services/state/StateSocket.ts +28 -0
@@ -1,990 +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 { 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, 16);
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 13: // Pump notifications
519
- msg.isProcessed = true;
520
- break;
521
- case 14: // Heater notifications
522
- msg.isProcessed = true;
523
- break;
524
- case 15: // Chlorinator notifications
525
- msg.isProcessed = true;
526
- break;
527
- }
528
- state.emitEquipmentChanges();
529
- }
530
- private static processSchedules(msg: Inbound) {
531
- let schedId = msg.extractPayloadByte(2) + 1;
532
- // v3.004+: schedule times are big-endian (hi,lo) in Action 168 payloads.
533
- // v1.x: schedule times are little-endian (lo,hi).
534
- let startTime: number;
535
- let endTime: number;
536
- if (sys.controllerType === ControllerType.IntelliCenter && sys.equipment.isIntellicenterV3) {
537
- startTime = msg.extractPayloadIntBE(3);
538
- endTime = msg.extractPayloadIntBE(5);
539
- } else {
540
- startTime = msg.extractPayloadInt(3);
541
- endTime = msg.extractPayloadInt(5);
542
- }
543
- let circuit = msg.extractPayloadByte(7) + 1;
544
- let isActive = (msg.extractPayloadByte(8) & 128) === 128; // Inactive schedules do not have bit 8 set.
545
- let cfg = sys.schedules.getItemById(schedId, isActive);
546
- let s = state.schedules.getItemById(schedId, cfg.isActive);
547
- //cfg.isActive = (circuit !== 256);
548
- cfg.startTime = startTime;
549
- cfg.endTime = endTime;
550
- cfg.circuit = circuit;
551
- cfg.isActive = isActive;
552
- let byte = msg.extractPayloadByte(8);
553
- cfg.scheduleType = (byte & 1 & 0xFF) === 1 ? 0 : 128;
554
- if ((byte & 4 & 0xFF) === 4) cfg.startTimeType = 1;
555
- else if ((byte & 8 & 0xFF) === 8) cfg.startTimeType = 2;
556
- else cfg.startTimeType = 0;
557
-
558
- if ((byte & 16 & 0xFF) === 16) cfg.endTimeType = 1;
559
- else if ((byte & 32 & 0xFF) === 32) cfg.endTimeType = 2;
560
- else cfg.endTimeType = 0;
561
- //cfg.runOnce = byte;
562
- cfg.scheduleDays = msg.extractPayloadByte(9);
563
- cfg.startMonth = msg.extractPayloadByte(10);
564
- cfg.startDay = msg.extractPayloadByte(11);
565
- cfg.startYear = msg.extractPayloadByte(12);
566
- let hs = msg.extractPayloadByte(13);
567
- // RKS: During the transition to 1.047 the heat sources were all screwed up. O now means no change and 1 means off.
568
- //if (hs === 1) hs = 0; // Shim for 1.047
569
- cfg.heatSource = hs;
570
- cfg.heatSetpoint = msg.extractPayloadByte(14);
571
- cfg.coolSetpoint = msg.extractPayloadByte(15);
572
- if (cfg.isActive) {
573
- let s = state.schedules.getItemById(schedId, cfg.isActive);
574
- s.isActive = cfg.isActive = true;
575
- s.startTime = cfg.startTime;
576
- s.endTime = cfg.endTime;
577
- s.circuit = cfg.circuit;
578
- s.scheduleType = cfg.scheduleType;
579
- s.scheduleDays = cfg.scheduleType === 128 ? cfg.scheduleDays : 0;
580
- s.heatSetpoint = cfg.heatSetpoint;
581
- s.coolSetpoint = cfg.coolSetpoint;
582
- s.heatSource = cfg.heatSource;
583
- s.startDate = cfg.startDate;
584
- s.startTimeType = cfg.startTimeType;
585
- s.endTimeType = cfg.endTimeType;
586
- }
587
- else {
588
- s.isActive = cfg.isActive = false;
589
- sys.schedules.removeItemById(cfg.id);
590
- state.schedules.removeItemById(cfg.id);
591
- s.emitEquipmentChange();
592
- }
593
- state.emitEquipmentChanges();
594
- msg.isProcessed = true;
595
- }
596
- private static processChlorinator(msg: Inbound) {
597
- let isActive = msg.extractPayloadByte(10) > 0;
598
- let chlorId = msg.extractPayloadByte(2) + 1;
599
- let cfg = sys.chlorinators.getItemById(chlorId, isActive);
600
- let s = state.chlorinators.getItemById(chlorId, isActive);
601
- if (!isActive) {
602
- sys.chlorinators.removeItemById(chlorId);
603
- state.chlorinators.removeItemById(chlorId);
604
- s.emitEquipmentChange();
605
- msg.isProcessed = true;
606
- return;
607
- }
608
- else {
609
-
610
- cfg.body = msg.extractPayloadByte(3);
611
- cfg.poolSetpoint = msg.extractPayloadByte(5);
612
- if (!cfg.disabled) {
613
- // RKS: We don't want theses setpoints if our chem controller
614
- // disabled the chlorinator.
615
- cfg.spaSetpoint = msg.extractPayloadByte(6);
616
- cfg.superChlor = msg.extractPayloadByte(7) > 0;
617
- }
618
- cfg.superChlorHours = msg.extractPayloadByte(8);
619
- s.poolSetpoint = cfg.poolSetpoint;
620
- s.spaSetpoint = cfg.spaSetpoint;
621
- s.superChlorHours = cfg.superChlorHours;
622
- s.body = cfg.body;
623
- msg.isProcessed = true;
624
- }
625
- state.emitEquipmentChanges();
626
- }
627
- private static processPump(msg: Inbound) {
628
- let pumpId = msg.extractPayloadByte(2) + 1;
629
- if (msg.extractPayloadByte(1) === 0) {
630
- let type = msg.extractPayloadByte(3);
631
- let cpump = sys.pumps.getItemById(pumpId, type > 0);
632
- let spump = state.pumps.getItemById(pumpId, type > 0);
633
- cpump.type = type;
634
- spump.type = type;
635
- if (cpump.type >= 2) {
636
- cpump.address = msg.extractPayloadByte(5);
637
- cpump.minSpeed = msg.extractPayloadInt(6);
638
- cpump.maxSpeed = msg.extractPayloadInt(8);
639
- cpump.minFlow = msg.extractPayloadByte(10);
640
- cpump.maxFlow = msg.extractPayloadByte(11);
641
- cpump.flowStepSize = msg.extractPayloadByte(12);
642
- cpump.primingSpeed = msg.extractPayloadInt(13);
643
- cpump.speedStepSize = msg.extractPayloadByte(15) * 10;
644
- cpump.primingTime = msg.extractPayloadByte(16);
645
- cpump.circuits.clear();
646
- for (let i = 18; i < msg.payload.length && i <= 25; i++) {
647
- let circuitId = msg.extractPayloadByte(i);
648
- if (circuitId !== 255) {
649
- let circuit = cpump.circuits.getItemById(i - 17, true);
650
- circuit.circuit = circuitId + 1;
651
- circuit.units = msg.extractPayloadByte(i + 8);
652
- }
653
- }
654
- }
655
- else if (cpump.type === 1) {
656
- cpump.circuits.clear();
657
- cpump.circuits.add({ id: 1, body: msg.extractPayloadByte(18) });
658
- }
659
- if (cpump.type === 0) {
660
- sys.pumps.removeItemById(cpump.id);
661
- state.pumps.removeItemById(cpump.id);
662
- }
663
- }
664
- else if (msg.extractPayloadByte(1) === 1) {
665
- let cpump = sys.pumps.getItemById(pumpId);
666
- let spump = state.pumps.getItemById(pumpId);
667
- cpump.name = msg.extractPayloadString(19, 16);
668
- spump.name = cpump.name;
669
- if (cpump.type > 2) {
670
- for (let i = 3, circuitId = 1; i < msg.payload.length && i <= 18; circuitId++) {
671
- let circuit = cpump.circuits.getItemById(circuitId);
672
- let sp = msg.extractPayloadInt(i);
673
- if (sp < 450)
674
- circuit.flow = sp;
675
- else
676
- circuit.speed = sp;
677
- i += 2;
678
- }
679
- }
680
- spump.emitData('pumpExt', spump.getExtended()); // Do this so clients can delete them.
681
- }
682
- msg.isProcessed = true;
683
- }
684
- private static processFeature(msg: Inbound) {
685
- let featureId = msg.extractPayloadByte(2) + sys.board.equipmentIds.features.start;
686
- let type = msg.extractPayloadByte(3);
687
- let feature = sys.features.getItemById(featureId, type !== 255);
688
- let fstate = state.features.getItemById(featureId, type !== 255);
689
- if (type === 255) {
690
- feature.isActive = false;
691
- sys.features.removeItemById(featureId);
692
- state.features.removeItemById(featureId);
693
- }
694
- else {
695
- feature.freeze = msg.extractPayloadByte(4) > 0;
696
- feature.dontStop = msg.extractPayloadByte(8) > 0;
697
- fstate.name = feature.name = msg.extractPayloadString(9, 16);
698
- fstate.type = feature.type = type;
699
- feature.eggTimer = (msg.extractPayloadByte(6) * 60) + msg.extractPayloadByte(7);
700
- fstate.showInFeatures = feature.showInFeatures = msg.extractPayloadByte(5) > 0;
701
- }
702
- state.emitEquipmentChanges();
703
- msg.isProcessed = true;
704
- }
705
- private static processCircuit(msg: Inbound) {
706
- let circuitId = msg.extractPayloadByte(2) + 1;
707
- let circuit = sys.circuits.getItemById(circuitId, false);
708
- let cstate = state.circuits.getItemById(circuitId, false);
709
- circuit.showInFeatures = msg.extractPayloadByte(5) > 0;
710
- circuit.freeze = msg.extractPayloadByte(4) > 0;
711
- circuit.name = msg.extractPayloadString(10, 16);
712
- circuit.type = msg.extractPayloadByte(3);
713
- circuit.eggTimer = (msg.extractPayloadByte(7) * 60) + msg.extractPayloadByte(8);
714
- circuit.showInFeatures = msg.extractPayloadByte(5) > 0;
715
- cstate.type = circuit.type;
716
- cstate.showInFeatures = circuit.showInFeatures;
717
- cstate.name = circuit.name;
718
- switch (circuit.type) {
719
- case 5:
720
- case 6:
721
- case 8:
722
- circuit.lightingTheme = msg.extractPayloadByte(6);
723
- cstate.lightingTheme = circuit.lightingTheme;
724
- break;
725
- case 9:
726
- circuit.level = msg.extractPayloadByte(6);
727
- cstate.level = circuit.level;
728
- break;
729
- }
730
- state.emitEquipmentChanges();
731
- msg.isProcessed = true;
732
- }
733
- private static processTempSettings(msg: Inbound) {
734
- let fnTranslateByte = (byte: number) => { return (byte & 0x007F) * (((byte & 0x0080) > 0) ? -1 : 1); }
735
-
736
- // v3.004+: Wireless sends the FULL options block, not a single-field notification.
737
- // v1.x: Used byte[2] as a pivot/index indicating which field changed, then byte[byte[2]+3] = new value.
738
- //
739
- // IMPORTANT: v3 Action 168 from Wireless has DIFFERENT offsets than Action 30 type 0!
740
- // - Action 30 type 0: poolHeatNdx=19, spaHeatNdx=21, poolModeNdx=23, spaModeNdx=24
741
- // - Action 168 Wireless: poolHeatNdx=20, spaHeatNdx=22, poolModeNdx=24, spaModeNdx=25
742
- // The Wireless payload has an extra byte at position 4, shifting everything by +1.
743
- const isIntellicenterV3 = (sys.controllerType === ControllerType.IntelliCenter && sys.equipment.isIntellicenterV3);
744
-
745
- // Detect v3 full-block format by payload length (v3 sends 41 bytes for msgType 0)
746
- if (isIntellicenterV3 && msg.payload.length >= 27) {
747
- // v3.004+ Wireless full options block - different offsets than Action 30!
748
- // Verified from replay 48: Pool setpoint at byte 20, Spa setpoint at byte 22
749
- const poolHeatNdx = 20;
750
- const poolCoolNdx = 21;
751
- const spaHeatNdx = 22;
752
- const spaCoolNdx = 23;
753
- const poolModeNdx = 24;
754
- const spaModeNdx = 25;
755
-
756
- // Update Body 1 (Pool)
757
- let body = sys.bodies.getItemById(1, sys.equipment.maxBodies > 0);
758
- let sbody = state.temps.bodies.getItemById(1);
759
- if (body.isActive) {
760
- const newPoolHeat = msg.extractPayloadByte(poolHeatNdx);
761
- const newPoolCool = msg.extractPayloadByte(poolCoolNdx);
762
- const newPoolMode = msg.extractPayloadByte(poolModeNdx);
763
- logger.silly(`v3.004+ Action 168: Pool setpoint ${body.heatSetpoint} → ${newPoolHeat}, coolSetpoint ${body.coolSetpoint} → ${newPoolCool}, mode ${body.heatMode} → ${newPoolMode}`);
764
- body.heatSetpoint = newPoolHeat;
765
- body.coolSetpoint = newPoolCool;
766
- body.heatMode = newPoolMode;
767
- sbody.heatSetpoint = body.heatSetpoint;
768
- sbody.coolSetpoint = body.coolSetpoint;
769
- sbody.heatMode = body.heatMode;
770
- }
771
-
772
- // Update Body 2 (Spa)
773
- body = sys.bodies.getItemById(2, sys.equipment.maxBodies > 1);
774
- sbody = state.temps.bodies.getItemById(2);
775
- if (body.isActive) {
776
- const newSpaHeat = msg.extractPayloadByte(spaHeatNdx);
777
- const newSpaCool = msg.extractPayloadByte(spaCoolNdx);
778
- const newSpaMode = msg.extractPayloadByte(spaModeNdx);
779
- logger.silly(`v3.004+ Action 168: Spa setpoint ${body.heatSetpoint} ${newSpaHeat}, coolSetpoint ${body.coolSetpoint} → ${newSpaCool}, mode ${body.heatMode} → ${newSpaMode}`);
780
- body.heatSetpoint = newSpaHeat;
781
- body.coolSetpoint = newSpaCool;
782
- body.heatMode = newSpaMode;
783
- sbody.heatSetpoint = body.heatSetpoint;
784
- sbody.coolSetpoint = body.coolSetpoint;
785
- sbody.heatMode = body.heatMode;
786
- }
787
-
788
- state.emitEquipmentChanges();
789
- msg.isProcessed = true;
790
- return;
791
- }
792
-
793
- // v1.x: Single-field-changed notification using byte[2] as pivot index.
794
- // payLoadIndex = byte(2) + 3 where the first 3 bytes indicate what value changed.
795
- let body: Body = null;
796
- switch (msg.extractPayloadByte(2)) {
797
- case 0: // Water Sensor 2 Adj
798
- sys.equipment.tempSensors.setCalibration('water2', fnTranslateByte(msg.extractPayloadByte(3)));
799
- msg.isProcessed = true;
800
- break;
801
- case 1: // Water Sensor 1 Adj
802
- sys.equipment.tempSensors.setCalibration('water1', fnTranslateByte(msg.extractPayloadByte(4)));
803
- msg.isProcessed = true;
804
- break;
805
- case 2: // Solar Sensor 1 Adj
806
- sys.equipment.tempSensors.setCalibration('solar1', fnTranslateByte(msg.extractPayloadByte(5)));
807
- msg.isProcessed = true;
808
- break;
809
- case 3: // Air Sensor Adj
810
- sys.equipment.tempSensors.setCalibration('air', fnTranslateByte(msg.extractPayloadByte(6)));
811
- msg.isProcessed = true;
812
- break;
813
- case 4: // Water Sensor 2 Adj
814
- sys.equipment.tempSensors.setCalibration('water2', fnTranslateByte(msg.extractPayloadByte(7)));
815
- msg.isProcessed = true;
816
- break;
817
- case 5: // Solar Sensor 2 Adj
818
- sys.equipment.tempSensors.setCalibration('solar2', fnTranslateByte(msg.extractPayloadByte(8)));
819
- msg.isProcessed = true;
820
- break;
821
- case 6: // Water Sensor 3 Adj
822
- sys.equipment.tempSensors.setCalibration('water3', fnTranslateByte(msg.extractPayloadByte(9)));
823
- msg.isProcessed = true;
824
- break;
825
- case 7: // Solar Sensor 3 Adj
826
- sys.equipment.tempSensors.setCalibration('solar3', fnTranslateByte(msg.extractPayloadByte(10)));
827
- msg.isProcessed = true;
828
- break;
829
- case 8: // Water Sensor 4 Adj
830
- sys.equipment.tempSensors.setCalibration('water4', fnTranslateByte(msg.extractPayloadByte(11)));
831
- msg.isProcessed = true;
832
- break;
833
- case 9: // Solar Sensor 4 Adj
834
- sys.equipment.tempSensors.setCalibration('water4', fnTranslateByte(msg.extractPayloadByte(12)));
835
- msg.isProcessed = true;
836
- break;
837
- case 11: // Clock mode
838
- sys.general.options.clockMode = (msg.extractPayloadByte(14) & 0x0001) == 1 ? 24 : 12;
839
- msg.isProcessed = true;
840
- break;
841
- case 12: // This is byte 15 but we don't know what it is. Numbers witnessed include 51, 52, 89, 235.
842
- break;
843
- case 14: // Clock source
844
- if ((msg.extractPayloadByte(17) & 0x0040) === 1)
845
- sys.general.options.clockSource = 'internet';
846
- else if (sys.general.options.clockSource !== 'server')
847
- sys.general.options.clockSource = 'manual';
848
- msg.isProcessed = true;
849
- break;
850
- case 15: // This is byte 18 but we don't know what it is. Numbers witnessed include 1, 2, 3, 5, 100.
851
- break;
852
- case 18: // Body 1 Heat Setpoint
853
- body = sys.bodies.getItemById(1, false);
854
- body.heatSetpoint = msg.extractPayloadByte(21);
855
- state.temps.bodies.getItemById(1).heatSetpoint = body.heatSetpoint;
856
- state.emitEquipmentChanges();
857
- msg.isProcessed = true;
858
- break;
859
- case 19: // Body 1 Cool Setpoint
860
- body = sys.bodies.getItemById(1, false);
861
- body.coolSetpoint = msg.extractPayloadByte(22);
862
- state.temps.bodies.getItemById(1).coolSetpoint = body.coolSetpoint;
863
- state.emitEquipmentChanges();
864
- msg.isProcessed = true;
865
- break;
866
- case 20: // Body 2 Heat Setpoint
867
- body = sys.bodies.getItemById(2, false);
868
- body.heatSetpoint = msg.extractPayloadByte(23);
869
- state.temps.bodies.getItemById(2).heatSetpoint = body.heatSetpoint;
870
- state.emitEquipmentChanges();
871
- msg.isProcessed = true;
872
- break;
873
- case 21: // Body 2 Cool Setpoint
874
- body = sys.bodies.getItemById(2, false);
875
- body.coolSetpoint = msg.extractPayloadByte(24);
876
- state.temps.bodies.getItemById(2).coolSetpoint = body.coolSetpoint;
877
- state.emitEquipmentChanges();
878
- msg.isProcessed = true;
879
- break;
880
- case 22: // Body 1 Heat Mode
881
- body = sys.bodies.getItemById(1, false);
882
- body.heatMode = msg.extractPayloadByte(25);
883
- state.temps.bodies.getItemById(1).heatMode = body.heatMode;
884
- state.emitEquipmentChanges();
885
- msg.isProcessed = true;
886
- break;
887
- case 23: // Body 2 Heat Mode
888
- body = sys.bodies.getItemById(2, false);
889
- body.heatMode = msg.extractPayloadByte(26);
890
- state.temps.bodies.getItemById(2).heatMode = body.heatMode;
891
- state.emitEquipmentChanges();
892
- msg.isProcessed = true;
893
- break;
894
- case 24: // Body 3 Heat Mode
895
- body = sys.bodies.getItemById(3, false);
896
- body.heatMode = msg.extractPayloadByte(27);
897
- state.temps.bodies.getItemById(3).heatMode = body.heatMode;
898
- state.emitEquipmentChanges();
899
- msg.isProcessed = true;
900
- break;
901
- case 25: // Body 4 Heat Mode
902
- body = sys.bodies.getItemById(4, false);
903
- body.heatMode = msg.extractPayloadByte(28);
904
- state.temps.bodies.getItemById(4).heatMode = body.heatMode;
905
- state.emitEquipmentChanges();
906
- msg.isProcessed = true;
907
- break;
908
- case 27: // Pump Valve Delay
909
- sys.general.options.pumpDelay = msg.extractPayloadByte(30) !== 0;
910
- msg.isProcessed = true;
911
- break;
912
- case 28: // Cooldown Delay
913
- sys.general.options.cooldownDelay = msg.extractPayloadByte(31) !== 0;
914
- msg.isProcessed = true;
915
- break;
916
- case 36: // Manual Priority
917
- sys.general.options.manualPriority = msg.extractPayloadByte(39) !== 0;
918
- msg.isProcessed = true;
919
- break;
920
- case 37: // Manual Heat
921
- sys.general.options.manualHeat = msg.extractPayloadByte(40) !== 0;
922
- msg.isProcessed = true;
923
- break;
924
- case 64: // Vacation mode
925
- let yy = msg.extractPayloadByte(5) + 2000;
926
- let mm = msg.extractPayloadByte(6);
927
- let dd = msg.extractPayloadByte(7);
928
- sys.general.options.vacation.startDate = new Date(yy, mm - 1, dd);
929
- yy = msg.extractPayloadByte(8) + 2000;
930
- mm = msg.extractPayloadByte(9);
931
- dd = msg.extractPayloadByte(10);
932
- sys.general.options.vacation.endDate = new Date(yy, mm - 1, dd);
933
- sys.general.options.vacation.enabled = msg.extractPayloadByte(3) > 0;
934
- sys.general.options.vacation.useTimeframe = msg.extractPayloadByte(4) > 0;
935
- msg.isProcessed = true;
936
- break;
937
- }
938
- }
939
- public static processTouchChlorinator(msg: Inbound) {
940
- let isActive = (msg.extractPayloadByte(0) & 0x01) === 1;
941
- let chlor = sys.chlorinators.getItemById(1, isActive);
942
- let schlor = state.chlorinators.getItemById(1, isActive);
943
- chlor.isActive = schlor.isActive = isActive;
944
- if (isActive) {
945
- if (!chlor.disabled) {
946
- // RKS: We don't want these setpoints if our chem controller disabled the
947
- // chlorinator. These should be 0 anyway.
948
- schlor.poolSetpoint = chlor.spaSetpoint = msg.extractPayloadByte(0) >> 1;
949
- schlor.spaSetpoint = chlor.poolSetpoint = msg.extractPayloadByte(1);
950
- if (typeof chlor.address === 'undefined') chlor.address = 80; // chlor.id + 79;
951
- schlor.body = chlor.body = sys.equipment.maxBodies >= 1 || sys.equipment.shared === true ? 32 : 0;
952
- }
953
- schlor.superChlor = chlor.superChlor = msg.extractPayloadByte(2) - 128 > 0;
954
- if (schlor.superChlor) {
955
- schlor.superChlorRemaining = (msg.extractPayloadByte(2) - 128) * 3600;
956
- }
957
- else {
958
- schlor.superChlorRemaining = 0;
959
- }
960
- if (state.temps.bodies.getItemById(1).isOn) schlor.targetOutput = chlor.disabled ? 0 : chlor.poolSetpoint;
961
- else if (state.temps.bodies.getItemById(2).isOn) schlor.targetOutput = chlor.disabled ? 0 : chlor.spaSetpoint;
962
- }
963
- else {
964
- sys.chlorinators.removeItemById(1);
965
- state.chlorinators.removeItemById(1);
966
- }
967
- }
968
- public static processTouchSetHeatMode(msg: Inbound) {
969
- // We get here because some other controller is setting the heat
970
- // mode. The OCP will emit an 8 later but it can be very slow
971
- // in doing this. ScreenLogic also captures this message so it
972
- // doesn't get behind.
973
- //[165, 1, 16, 34, 136, 4][86, 100, 3, 0][2, 33]
974
- //payload: [temp1, temp2, mode2 << 2 | mode1, setPoint],
975
- let bstate1 = state.temps.bodies.getItemById(1);
976
- let bstate2 = state.temps.bodies.getItemById(2);
977
- let body1 = sys.bodies.getItemById(1);
978
- let body2 = sys.bodies.getItemById(2);
979
- let mode1 = msg.extractPayloadByte(2) & 0x03;
980
- let mode2 = (msg.extractPayloadByte(2) & 0x0C) >> 2;
981
- bstate1.setPoint = body1.heatSetpoint = msg.extractPayloadByte(0);
982
- bstate1.coolSetpoint = body1.coolSetpoint = msg.extractPayloadByte(3);
983
- bstate2.setPoint = body2.heatSetpoint = msg.extractPayloadByte(1);
984
- bstate1.heatMode = body1.heatMode = mode1;
985
- bstate2.heatMode = body2.heatMode = mode2;
986
- msg.isProcessed = true;
987
- state.emitEquipmentChanges();
988
-
989
- }
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
+ }
990
1052
  }