From 02415920530984928bc35ccc24f94c05430cb554 Mon Sep 17 00:00:00 2001 From: TD-er Date: Mon, 16 Sep 2024 00:49:01 +0200 Subject: [PATCH] Fix formatting nr. decimals with formula (#5123) --- src/src/DataStructs/UserVarStruct.cpp | 4 ++-- src/src/DataTypes/TaskValues_Data.cpp | 4 ++-- src/src/Globals/Plugins.cpp | 2 ++ src/src/WebServer/JSON.cpp | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/src/DataStructs/UserVarStruct.cpp b/src/src/DataStructs/UserVarStruct.cpp index 671dfd5181..1552a4c6ad 100644 --- a/src/src/DataStructs/UserVarStruct.cpp +++ b/src/src/DataStructs/UserVarStruct.cpp @@ -382,7 +382,7 @@ const TaskValues_Data_t * UserVarStruct::getRawOrComputed( // Should not apply set nr. of decimals when calculating a formula - const uint8_t nrDecimals = 255; + const uint8_t nrDecimals = 254; const String value = getAsString(taskIndex, varNr, sensorType, nrDecimals, true); constexpr bool applyNow = true; @@ -482,7 +482,7 @@ bool UserVarStruct::applyFormulaAndSet(taskIndex_t taskIndex tmp.set(varNr, value, sensorType); // Should not apply set nr. of decimals when calculating a formula - const uint8_t nrDecimals = 255; + const uint8_t nrDecimals = 254; const String value_str = tmp.getAsString(varNr, sensorType, nrDecimals); constexpr bool applyNow = false; diff --git a/src/src/DataTypes/TaskValues_Data.cpp b/src/src/DataTypes/TaskValues_Data.cpp index ae0a6c7b91..5b3017e994 100644 --- a/src/src/DataTypes/TaskValues_Data.cpp +++ b/src/src/DataTypes/TaskValues_Data.cpp @@ -254,7 +254,7 @@ String TaskValues_Data_t::getAsString(uint8_t varNr, Sensor_VType sensorType, u if (isFloatOutputDataType(sensorType)) { const float value = getFloat(varNr); - if (nrDecimals = 255) { + if (nrDecimals == 254) { // FIXME TD-er: Must use defines for these special situations nrDecimals = maxNrDecimals_fpType(value); } result = toString(value, nrDecimals); @@ -262,7 +262,7 @@ String TaskValues_Data_t::getAsString(uint8_t varNr, Sensor_VType sensorType, u #if FEATURE_USE_DOUBLE_AS_ESPEASY_RULES_FLOAT_TYPE } else if (isDoubleOutputDataType(sensorType)) { const double value = getDouble(varNr); - if (nrDecimals = 255) { + if (nrDecimals == 254) { // FIXME TD-er: Must use defines for these special situations nrDecimals = maxNrDecimals_fpType(value); } result = doubleToString(value, nrDecimals); diff --git a/src/src/Globals/Plugins.cpp b/src/src/Globals/Plugins.cpp index 956b38d56a..db208e272f 100644 --- a/src/src/Globals/Plugins.cpp +++ b/src/src/Globals/Plugins.cpp @@ -784,6 +784,7 @@ bool PluginCall(uint8_t Function, struct EventStruct *event, String& str) } if (Function == PLUGIN_INIT) { + clearTaskCache(event->TaskIndex); UserVar.clear_computed(event->TaskIndex); } } @@ -938,6 +939,7 @@ bool PluginCall(uint8_t Function, struct EventStruct *event, String& str) if (Function == PLUGIN_EXIT) { UserVar.clear_computed(event->TaskIndex); clearPluginTaskData(event->TaskIndex); + clearTaskCache(event->TaskIndex); // initSerial(); queueTaskEvent(F("TaskExit"), event->TaskIndex, retval); diff --git a/src/src/WebServer/JSON.cpp b/src/src/WebServer/JSON.cpp index e510094ef1..e1df8668b6 100644 --- a/src/src/WebServer/JSON.cpp +++ b/src/src/WebServer/JSON.cpp @@ -452,8 +452,8 @@ void handle_json() for (uint8_t x = 0; x < valueCount; x++) { addHtml('{'); - const String value = formatUserVarNoCheck(&TempEvent, x); uint8_t nrDecimals = Cache.getTaskDeviceValueDecimals(TaskIndex, x); + const String value = formatUserVarNoCheck(&TempEvent, x); if (mustConsiderAsJSONString(value)) { // Flag as not to treat as a float