From 7dc8f6169e2356cb6cb50a13962f008ecb2af7f5 Mon Sep 17 00:00:00 2001 From: lucas_nz <606314+lucasnz@users.noreply.github.com> Date: Sat, 10 Jan 2026 21:52:13 +1300 Subject: [PATCH] Fix setMode --- lib/SpaInterface/SpaInterface.cpp | 6 +++--- lib/SpaInterface/SpaProperties.h | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/SpaInterface/SpaInterface.cpp b/lib/SpaInterface/SpaInterface.cpp index 31de4d8..0e0aecd 100644 --- a/lib/SpaInterface/SpaInterface.cpp +++ b/lib/SpaInterface/SpaInterface.cpp @@ -476,8 +476,8 @@ bool SpaInterface::setVARIValue(int mode){ bool SpaInterface::setMode(int mode){ debugD("setMode - %i", mode); - if (mode == getMode().toInt()) { //TODO - change getMode to return int??? why is it string??? - debugD("No Mode change detected - current %i, new %i", getMode(), mode); + if (mode == getModeIndex(getMode())) { + debugD("No Mode change detected - current %i, new %i", getModeIndex(getMode()), mode); return true; } @@ -712,7 +712,7 @@ void SpaInterface::loop(){ } if (_resultRegistersDirty) { - _nextUpdateDue = millis() + 200; // if we need to read the registers, pause a bit to see if there are more commands coming. + _nextUpdateDue = millis() + 500; // if we need to read the registers, pause a bit to see if there are more commands coming. _resultRegistersDirty = false; } diff --git a/lib/SpaInterface/SpaProperties.h b/lib/SpaInterface/SpaProperties.h index b719023..45487af 100644 --- a/lib/SpaInterface/SpaProperties.h +++ b/lib/SpaInterface/SpaProperties.h @@ -1034,6 +1034,14 @@ Property HV_2; void setHCONCallback(void (*callback)(int)) { HCON.setCallback(callback); } String getMode() { return Mode.getValue(); } + int getModeIndex(String mode) { + for (size_t i = 0; i < spaModeStrings.size(); i++) + { + if (spaModeStrings[i] == mode) + return i; + } + return -1; + } void setModeCallback(void (*callback)(String)) { Mode.setCallback(callback); } const std::array spaModeStrings = {"NORM","ECON", "AWAY","WEEK"};