Skip to content

Commit d028ed9

Browse files
committed
Migrate PumpStatuses + update gitignore
1 parent 7c8921d commit d028ed9

7 files changed

Lines changed: 128 additions & 146 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
.vscode/ipch
66
.vscode/extensions.json
77
.DS_Store
8+
.vscode/extensions.json

lib/SpaInterface/SpaInterface.cpp

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ SpaInterface::SpaInterface() : port(SPA_SERIAL) {
1111

1212
SpaInterface::~SpaInterface() {}
1313

14+
SpaInterface::PumpStatus SpaInterface::pumpStatuses[] = {
15+
&SpaInterface::RB_TP_Pump1,
16+
&SpaInterface::RB_TP_Pump2,
17+
&SpaInterface::RB_TP_Pump3,
18+
&SpaInterface::RB_TP_Pump4,
19+
&SpaInterface::RB_TP_Pump5,
20+
};
1421

1522
void SpaInterface::setSpaPollFrequency(int updateFrequency) {
1623
_updateFrequency = updateFrequency;
@@ -75,70 +82,85 @@ bool SpaInterface::sendCommandCheckResult(String cmd, String expected){
7582
}
7683

7784
bool SpaInterface::setRB_TP_Pump1(int mode){
78-
debugD("setRB_TP_Pump1 - %i",mode);
79-
if (mode == getRB_TP_Pump1()) {
80-
debugD("No Pump1 change detected - current %i, new %i", getRB_TP_Pump1(), mode);
85+
debugD("setRB_TP_Pump1 - %i", mode);
86+
if (mode < 0 || mode > 4) {
87+
throw std::out_of_range("RB_TP_Pump1 value out of range (0..4)");
88+
}
89+
if (mode == RB_TP_Pump1.get()) {
90+
debugD("No Pump1 change detected - current %i, new %i", RB_TP_Pump1.get(), mode);
8191
return true;
8292
}
8393

8494
if (sendCommandCheckResult("S22:"+String(mode),"S22-OK")) {
85-
update_RB_TP_Pump1(String(mode));
95+
RB_TP_Pump1.update(mode);
8696
return true;
8797
}
8898
return false;
8999
}
90100

91101
bool SpaInterface::setRB_TP_Pump2(int mode){
92-
debugD("setRB_TP_Pump2 - %i",mode);
93-
if (mode == getRB_TP_Pump2()) {
94-
debugD("No Pump2 change detected - current %i, new %i", getRB_TP_Pump2(), mode);
102+
debugD("setRB_TP_Pump2 - %i", mode);
103+
if (mode < 0 || mode > 4) {
104+
throw std::out_of_range("RB_TP_Pump2 value out of range (0..4)");
105+
}
106+
if (mode == RB_TP_Pump2.get()) {
107+
debugD("No Pump2 change detected - current %i, new %i", RB_TP_Pump2.get(), mode);
95108
return true;
96109
}
97110

98111
if (sendCommandCheckResult("S23:"+String(mode),"S23-OK")) {
99-
update_RB_TP_Pump2(String(mode));
112+
RB_TP_Pump2.update(mode);
100113
return true;
101114
}
102115
return false;
103116
}
104117

105118
bool SpaInterface::setRB_TP_Pump3(int mode){
106-
debugD("setRB_TP_Pump3 - %i",mode);
107-
if (mode == getRB_TP_Pump3()) {
108-
debugD("No Pump3 change detected - current %i, new %i", getRB_TP_Pump3(), mode);
119+
debugD("setRB_TP_Pump3 - %i", mode);
120+
if (mode < 0 || mode > 4) {
121+
throw std::out_of_range("RB_TP_Pump3 value out of range (0..4)");
122+
}
123+
if (mode == RB_TP_Pump3.get()) {
124+
debugD("No Pump3 change detected - current %i, new %i", RB_TP_Pump3.get(), mode);
109125
return true;
110126
}
111127

112128
if (sendCommandCheckResult("S24:"+String(mode),"S24-OK")) {
113-
update_RB_TP_Pump3(String(mode));
129+
RB_TP_Pump3.update(mode);
114130
return true;
115131
}
116132
return false;
117133
}
118134

119135
bool SpaInterface::setRB_TP_Pump4(int mode){
120-
debugD("setRB_TP_Pump4 - %i",mode);
121-
if (mode == getRB_TP_Pump4()) {
122-
debugD("No Pump4 change detected - current %i, new %i", getRB_TP_Pump4(), mode);
136+
debugD("setRB_TP_Pump4 - %i", mode);
137+
if (mode < 0 || mode > 4) {
138+
throw std::out_of_range("RB_TP_Pump4 value out of range (0..4)");
139+
}
140+
if (mode == RB_TP_Pump4.get()) {
141+
debugD("No Pump4 change detected - current %i, new %i", RB_TP_Pump4.get(), mode);
123142
return true;
124143
}
125144

126145
if (sendCommandCheckResult("S25:"+String(mode),"S25-OK")) {
127-
update_RB_TP_Pump4(String(mode));
146+
RB_TP_Pump4.update(mode);
128147
return true;
129148
}
130149
return false;
131150
}
132151

133152
bool SpaInterface::setRB_TP_Pump5(int mode){
134-
debugD("setRB_TP_Pump5 - %i",mode);
135-
if (mode == getRB_TP_Pump5()) {
136-
debugD("No Pump5 change detected - current %i, new %i", getRB_TP_Pump5(), mode);
153+
debugD("setRB_TP_Pump5 - %i", mode);
154+
if (mode < 0 || mode > 4) {
155+
throw std::out_of_range("RB_TP_Pump5 value out of range (0..4)");
156+
}
157+
if (mode == RB_TP_Pump5.get()) {
158+
debugD("No Pump5 change detected - current %i, new %i", RB_TP_Pump5.get(), mode);
137159
return true;
138160
}
139161

140162
if (sendCommandCheckResult("S26:"+String(mode),"S26-OK")) {
141-
update_RB_TP_Pump5(String(mode));
163+
RB_TP_Pump5.update(mode);
142164
return true;
143165
}
144166
return false;
@@ -887,11 +909,11 @@ void SpaInterface::updateMeasures() {
887909
update_RB_TP_Light(statusResponseRaw[R5 + 14]);
888910
update_WTMP(statusResponseRaw[R5 + 15]);
889911
update_CleanCycle(statusResponseRaw[R5 + 16]);
890-
update_RB_TP_Pump1(statusResponseRaw[R5 + 18]);
891-
update_RB_TP_Pump2(statusResponseRaw[R5 + 19]);
892-
update_RB_TP_Pump3(statusResponseRaw[R5 + 20]);
893-
update_RB_TP_Pump4(statusResponseRaw[R5 + 21]);
894-
update_RB_TP_Pump5(statusResponseRaw[R5 + 22]);
912+
RB_TP_Pump1.update(statusResponseRaw[R5 + 18].toInt());
913+
RB_TP_Pump2.update(statusResponseRaw[R5 + 19].toInt());
914+
RB_TP_Pump3.update(statusResponseRaw[R5 + 20].toInt());
915+
RB_TP_Pump4.update(statusResponseRaw[R5 + 21].toInt());
916+
RB_TP_Pump5.update(statusResponseRaw[R5 + 22].toInt());
895917
#pragma endregion
896918
#pragma region R6
897919
update_VARIValue(statusResponseRaw[R6 + 1]);

lib/SpaInterface/SpaInterface.h

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,32 @@ class SpaInterface : public SpaProperties {
151151
bool setL_2SNZ_BGN(int mode);
152152
bool setL_2SNZ_END(int mode);
153153

154+
/// @brief Internal writer used by `RB_TP_Pump1` RWProperty.
155+
/// @details Sends `S22:<mode>` to the controller and only updates
156+
/// the cached property value when the command succeeds.
157+
/// Throws std::out_of_range for invalid values (0..4).
158+
bool setRB_TP_Pump1(int mode);
159+
/// @brief Internal writer used by `RB_TP_Pump2` RWProperty.
160+
/// @details Sends `S23:<mode>` to the controller and only updates
161+
/// the cached property value when the command succeeds.
162+
/// Throws std::out_of_range for invalid values (0..4).
163+
bool setRB_TP_Pump2(int mode);
164+
/// @brief Internal writer used by `RB_TP_Pump3` RWProperty.
165+
/// @details Sends `S24:<mode>` to the controller and only updates
166+
/// the cached property value when the command succeeds.
167+
/// Throws std::out_of_range for invalid values (0..4).
168+
bool setRB_TP_Pump3(int mode);
169+
/// @brief Internal writer used by `RB_TP_Pump4` RWProperty.
170+
/// @details Sends `S25:<mode>` to the controller and only updates
171+
/// the cached property value when the command succeeds.
172+
/// Throws std::out_of_range for invalid values (0..4).
173+
bool setRB_TP_Pump4(int mode);
174+
/// @brief Internal writer used by `RB_TP_Pump5` RWProperty.
175+
/// @details Sends `S26:<mode>` to the controller and only updates
176+
/// the cached property value when the command succeeds.
177+
/// Throws std::out_of_range for invalid values (0..4).
178+
bool setRB_TP_Pump5(int mode);
179+
154180
public:
155181
/// @brief Init SpaInterface.
156182
SpaInterface();
@@ -404,6 +430,22 @@ class SpaInterface : public SpaProperties {
404430
/// @details Read/write. Valid range 0..5947 encoded as h*256+m (24-hour clock).
405431
RWProperty<int> L_2SNZ_END{this, &SpaInterface::setL_2SNZ_END};
406432

433+
/// @brief Pump 1 operating state.
434+
/// @details Read/write. 0=Off, 1=On, 4=Auto (if supported).
435+
RWProperty<int> RB_TP_Pump1{this, &SpaInterface::setRB_TP_Pump1};
436+
/// @brief Pump 2 operating state.
437+
/// @details Read/write. 0=Off, 1=On, 4=Auto (if supported).
438+
RWProperty<int> RB_TP_Pump2{this, &SpaInterface::setRB_TP_Pump2};
439+
/// @brief Pump 3 operating state.
440+
/// @details Read/write. 0=Off, 1=On, 4=Auto (if supported).
441+
RWProperty<int> RB_TP_Pump3{this, &SpaInterface::setRB_TP_Pump3};
442+
/// @brief Pump 4 operating state.
443+
/// @details Read/write. 0=Off, 1=On, 4=Auto (if supported).
444+
RWProperty<int> RB_TP_Pump4{this, &SpaInterface::setRB_TP_Pump4};
445+
/// @brief Pump 5 operating state.
446+
/// @details Read/write. 0=Off, 1=On, 4=Auto (if supported).
447+
RWProperty<int> RB_TP_Pump5{this, &SpaInterface::setRB_TP_Pump5};
448+
407449
/// @brief To be called by loop function of main sketch. Does regular updates, etc.
408450
void loop();
409451

@@ -422,31 +464,6 @@ class SpaInterface : public SpaProperties {
422464
/// @brief Clear the call back function.
423465
void clearUpdateCallback();
424466

425-
/// @brief Set the operating mode for pump 1
426-
/// @param mode 0 = off, 1 = on, 4 = auto (if supported)
427-
/// @return True if successful
428-
bool setRB_TP_Pump1(int mode);
429-
430-
/// @brief Set the operating mode for pump 2
431-
/// @param mode 0 = off, 1 = on, 4 = auto (if supported)
432-
/// @return True if successful
433-
bool setRB_TP_Pump2(int mode);
434-
435-
/// @brief Set the operating mode for pump 3
436-
/// @param mode 0 = off, 1 = on, 4 = auto (if supported)
437-
/// @return True if successful
438-
bool setRB_TP_Pump3(int mode);
439-
440-
/// @brief Set the operating mode for pump 4
441-
/// @param mode 0 = off, 1 = on, 4 = auto (if supported)
442-
/// @return True if successful
443-
bool setRB_TP_Pump4(int mode);
444-
445-
/// @brief Set the operating mode for pump 5
446-
/// @param mode 0 = off, 1 = on, 4 = auto (if supported)
447-
/// @return True if successful
448-
bool setRB_TP_Pump5(int mode);
449-
450467
bool setRB_TP_Light(int mode);
451468

452469
/// @brief Set aux element operating mode
@@ -490,6 +507,12 @@ class SpaInterface : public SpaProperties {
490507
bool setFiltHrs(String duration);
491508

492509
bool setLockMode(int mode);
510+
511+
/// @brief Unified array of RWProperty pointers for each migrated pump, used for
512+
/// both reading state and sending commands. Grows as pumps are migrated.
513+
using PumpStatus = RWProperty<int> SpaInterface::*;
514+
static PumpStatus pumpStatuses[];
515+
static const int pumpStatusesCount = 5;
493516
};
494517

495518

@@ -505,28 +528,5 @@ static GetPumpStateInstallFunction pumpInstallStateFunctions[] = {
505528
&SpaInterface::getPump5InstallState
506529
};
507530

508-
// Define the function pointer type for getPumpState functions
509-
typedef int (SpaInterface::*GetPumpStateFunction)();
510-
511-
// Declare the array of function pointers for each pump's state as static
512-
static GetPumpStateFunction pumpStateFunctions[] = {
513-
&SpaInterface::getRB_TP_Pump1,
514-
&SpaInterface::getRB_TP_Pump2,
515-
&SpaInterface::getRB_TP_Pump3,
516-
&SpaInterface::getRB_TP_Pump4,
517-
&SpaInterface::getRB_TP_Pump5
518-
};
519-
520-
// Define the function pointer type for getPumpState functions
521-
typedef bool (SpaInterface::*SetPumpFunction)(int);
522-
523-
// Declare the array of function pointers for each pump's state as static
524-
static SetPumpFunction setPumpFunctions[] = {
525-
&SpaInterface::setRB_TP_Pump1,
526-
&SpaInterface::setRB_TP_Pump2,
527-
&SpaInterface::setRB_TP_Pump3,
528-
&SpaInterface::setRB_TP_Pump4,
529-
&SpaInterface::setRB_TP_Pump5
530-
};
531531

532532
#endif

lib/SpaInterface/SpaProperties.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -335,26 +335,6 @@ boolean SpaProperties::update_Vari_Mode(const String& s){
335335
return updateIntProperty(Vari_Mode, s);
336336
}
337337

338-
boolean SpaProperties::update_RB_TP_Pump1(const String& s){
339-
return updateIntProperty(RB_TP_Pump1, s);
340-
}
341-
342-
boolean SpaProperties::update_RB_TP_Pump2(const String& s){
343-
return updateIntProperty(RB_TP_Pump2, s);
344-
}
345-
346-
boolean SpaProperties::update_RB_TP_Pump3(const String& s){
347-
return updateIntProperty(RB_TP_Pump3, s);
348-
}
349-
350-
boolean SpaProperties::update_RB_TP_Pump4(const String& s){
351-
return updateIntProperty(RB_TP_Pump4, s);
352-
}
353-
354-
boolean SpaProperties::update_RB_TP_Pump5(const String& s){
355-
return updateIntProperty(RB_TP_Pump5, s);
356-
}
357-
358338
boolean SpaProperties::update_RB_TP_Blower(const String& s){
359339
return updateIntProperty(RB_TP_Blower, s);
360340
}

lib/SpaInterface/SpaProperties.h

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -209,26 +209,6 @@ Property<bool> HV_2;
209209
// R5
210210
// Unknown encoding - Attribute<int> TouchPad2;
211211
// Unknown encoding - Attribute<int> TouchPad1;
212-
/// @brief Pump 1 state
213-
///
214-
/// 0 = off, 1 = running, 4 = auto
215-
Property<int> RB_TP_Pump1;
216-
/// @brief Pump 2 state
217-
///
218-
/// 0 = off, 1 = running, 4 = auto
219-
Property<int> RB_TP_Pump2;
220-
/// @brief Pump 3 state
221-
///
222-
/// 0 = off, 1 = running, 4 = auto
223-
Property<int> RB_TP_Pump3;
224-
/// @brief Pump 4 state
225-
///
226-
/// 0 = off, 1 = running, 4 = auto
227-
Property<int> RB_TP_Pump4;
228-
/// @brief Pump 5 state
229-
///
230-
/// 0 = off, 1 = running, 4 = auto
231-
Property<int> RB_TP_Pump5;
232212
Property<int> RB_TP_Blower;
233213
Property<int> RB_TP_Light;
234214
/// @brief Auto enabled
@@ -673,11 +653,6 @@ Property<bool> HV_2;
673653
// R5
674654
// Unknown encoding - TouchPad2.update_Value();
675655
// Unknown encoding - TouchPad1.update_Value();
676-
boolean update_RB_TP_Pump1(const String&);
677-
boolean update_RB_TP_Pump2(const String&);
678-
boolean update_RB_TP_Pump3(const String&);
679-
boolean update_RB_TP_Pump4(const String&);
680-
boolean update_RB_TP_Pump5(const String&);
681656
boolean update_RB_TP_Blower(const String&);
682657
boolean update_RB_TP_Light(const String&);
683658
boolean update_RB_TP_Auto(const String&);
@@ -1089,20 +1064,6 @@ Property<bool> HV_2;
10891064
int getVari_Mode() { return Vari_Mode.getValue(); }
10901065
void setVari_ModeCallback(void (*callback)(int)) { Vari_Mode.setCallback(callback); }
10911066

1092-
int getRB_TP_Pump1() { return RB_TP_Pump1.getValue(); }
1093-
void setRB_TP_Pump1Callback(void (*callback)(int)) { RB_TP_Pump1.setCallback(callback); }
1094-
1095-
int getRB_TP_Pump2() { return RB_TP_Pump2.getValue(); }
1096-
void setRB_TP_Pump2Callback(void (*callback)(int)) { RB_TP_Pump2.setCallback(callback); }
1097-
1098-
int getRB_TP_Pump3() { return RB_TP_Pump3.getValue(); }
1099-
void setRB_TP_Pump3Callback(void (*callback)(int)) { RB_TP_Pump3.setCallback(callback); }
1100-
1101-
int getRB_TP_Pump4() { return RB_TP_Pump4.getValue(); }
1102-
void setRB_TP_Pump4Callback(void (*callback)(int)) { RB_TP_Pump4.setCallback(callback); }
1103-
1104-
int getRB_TP_Pump5() { return RB_TP_Pump5.getValue(); }
1105-
void setRB_TP_Pump5Callback(void (*callback)(int)) { RB_TP_Pump5.setCallback(callback); }
11061067
const std::array<String, 2> autoPumpOptions = {"Manual", "Auto"};
11071068

11081069
int getRB_TP_Blower() { return RB_TP_Blower.getValue(); }

lib/SpaUtils/SpaUtils.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ bool getPumpModesJson(SpaInterface &si, int pumpNumber, JsonObject pumps) {
7878
}
7979
}
8080

81-
int pumpState = (si.*(pumpStateFunctions[pumpNumber - 1]))();
81+
int pumpState = (pumpNumber - 1 < SpaInterface::pumpStatusesCount)
82+
? (si.*(SpaInterface::pumpStatuses[pumpNumber - 1])).get() : 0;
8283
if (pumpInstallState.endsWith("4") && possibleStates.length() > 1) {
8384
if (pumpState == 4) pumps[pumpKey]["mode"] = "Auto";
8485
else pumps[pumpKey]["mode"] = "Manual";
@@ -204,14 +205,14 @@ bool generateStatusJson(SpaInterface &si, MQTTClientWrapper &mqttClient, String
204205
json["lights"]["brightness"] = si.LBRTValue.get();
205206

206207
// 0 = white, if white, then set the hue and saturation to white so the light displays correctly in HA.
207-
if (si.ColorMode.get() == 0) {
208-
json["lights"]["color"]["h"] = 0;
209-
json["lights"]["color"]["s"] = 0;
210-
} else {
211-
int hue = atoi(si.CurrClr.getLabel("0"));
212-
json["lights"]["color"]["h"] = hue;
213-
json["lights"]["color"]["s"] = 100;
214-
}
208+
if (si.ColorMode.get() == 0) {
209+
json["lights"]["color"]["h"] = 0;
210+
json["lights"]["color"]["s"] = 0;
211+
} else {
212+
int hue = atoi(si.CurrClr.getLabel("0"));
213+
json["lights"]["color"]["h"] = hue;
214+
json["lights"]["color"]["s"] = 100;
215+
}
215216
json["lights"]["color_mode"] = "hs";
216217

217218
int jsonSize;

0 commit comments

Comments
 (0)