Skip to content

Commit

Permalink
Fix formatting nr. decimals with formula (letscontrolit#5123)
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-er committed Sep 15, 2024
1 parent cffe500 commit 0241592
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/src/DataStructs/UserVarStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/src/DataTypes/TaskValues_Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ 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);
#if FEATURE_EXTENDED_TASK_VALUE_TYPES
#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);
Expand Down
2 changes: 2 additions & 0 deletions src/src/Globals/Plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/src/WebServer/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0241592

Please sign in to comment.