mirror of
https://github.com/Laxilef/OTGateway.git
synced 2026-11-30 10:13:04 +05:00
fix: normalize floating-point settings before validation
This commit is contained in:
1 parent
ff07bdcdca
commit
7c6e85b3f6
2 files changed
+37
-32
No files matched your search
+34
-29
@@ -1351,20 +1351,23 @@ static SettingResult setEmergencyTarget(EmergencySettings& dst, float value) {
|
||||
? settings.heating.maxTemp
|
||||
: THERMOSTAT_INDOOR_MAX_TEMP;
|
||||
|
||||
bool valid = isValidTemp(
|
||||
bool valid = std::isfinite(value);
|
||||
if (valid) {
|
||||
value = roundf(value, 2);
|
||||
valid = isValidTemp(
|
||||
value,
|
||||
UnitSystem::METRIC,
|
||||
minTemp,
|
||||
maxTemp,
|
||||
UnitSystem::METRIC
|
||||
);
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
value = noRegulators ? DEFAULT_HEATING_TARGET_TEMP : THERMOSTAT_INDOOR_DEFAULT_TEMP;
|
||||
}
|
||||
|
||||
value = roundf(constrain(value, minTemp, maxTemp), 2);
|
||||
|
||||
value = constrain(value, minTemp, maxTemp);
|
||||
if (isFloatDifferent(dst.target, value, 0.0001f)) {
|
||||
dst.target = value;
|
||||
changed = true;
|
||||
@@ -1462,20 +1465,23 @@ static SettingResult setHeatingTarget(HeatingSettings& dst, float value) {
|
||||
? THERMOSTAT_INDOOR_MAX_TEMP
|
||||
: dst.maxTemp;
|
||||
|
||||
bool valid = isValidTemp(
|
||||
bool valid = std::isfinite(value);
|
||||
if (valid) {
|
||||
value = roundf(value, 2);
|
||||
valid = isValidTemp(
|
||||
value,
|
||||
UnitSystem::METRIC,
|
||||
minTemp,
|
||||
maxTemp,
|
||||
UnitSystem::METRIC
|
||||
);
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
value = smartControl ? THERMOSTAT_INDOOR_DEFAULT_TEMP : DEFAULT_HEATING_TARGET_TEMP;
|
||||
}
|
||||
|
||||
value = roundf(constrain(value, minTemp, maxTemp), 2);
|
||||
|
||||
value = constrain(value, minTemp, maxTemp);
|
||||
if (isFloatDifferent(dst.target, value, 0.0001f)) {
|
||||
dst.target = value;
|
||||
changed = true;
|
||||
@@ -1531,11 +1537,11 @@ static SettingResult applySetting(HeatingSettings& dst, std::string_view path, f
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 2);
|
||||
if (value < 0.05f || value > 15.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 2);
|
||||
if (isFloatDifferent(value, dst.hysteresis.value, 0.0001f)) {
|
||||
dst.hysteresis.value = value;
|
||||
changed = true;
|
||||
@@ -1551,11 +1557,11 @@ static SettingResult applySetting(HeatingSettings& dst, std::string_view path, f
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 3);
|
||||
if (value < 1.5f || value > 10.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 3);
|
||||
if (isFloatDifferent(value, dst.turboFactor, 0.0001f)) {
|
||||
dst.turboFactor = value;
|
||||
changed = true;
|
||||
@@ -1948,7 +1954,7 @@ static bool normalizeDhwOverheatBounds(DhwSettings& dst) {
|
||||
static SettingResult setDhwTarget(DhwSettings& dst, float value) {
|
||||
bool changed = false;
|
||||
|
||||
bool valid = isValidTemp(
|
||||
bool valid = std::isfinite(value) && isValidTemp(
|
||||
value,
|
||||
UnitSystem::METRIC,
|
||||
dst.minTemp,
|
||||
@@ -1961,7 +1967,6 @@ static SettingResult setDhwTarget(DhwSettings& dst, float value) {
|
||||
}
|
||||
|
||||
value = constrain(value, dst.minTemp, dst.maxTemp);
|
||||
|
||||
if (isFloatDifferent(dst.target, value, 0.0001f)) {
|
||||
dst.target = value;
|
||||
changed = true;
|
||||
@@ -2239,11 +2244,11 @@ static SettingResult applySetting(PidSettings& dst, std::string_view path, float
|
||||
return {};
|
||||
}
|
||||
|
||||
if (value <= 0 || value > 1000) {
|
||||
value = roundf(value, 3);
|
||||
if (value < 0.0f || value > 1000.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 3);
|
||||
if (isFloatDifferent(value, dst.p_factor, 0.0001f)) {
|
||||
dst.p_factor = value;
|
||||
changed = true;
|
||||
@@ -2259,12 +2264,12 @@ static SettingResult applySetting(PidSettings& dst, std::string_view path, float
|
||||
return {};
|
||||
}
|
||||
|
||||
if (value < 0 || value > 100) {
|
||||
value = roundf(value, 4);
|
||||
if (value < 0.0f || value > 100.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 4);
|
||||
if (isFloatDifferent(value, dst.i_factor, 0.0001f)) {
|
||||
if (isFloatDifferent(value, dst.i_factor, 0.00005f)) {
|
||||
dst.i_factor = value;
|
||||
changed = true;
|
||||
}
|
||||
@@ -2279,11 +2284,11 @@ static SettingResult applySetting(PidSettings& dst, std::string_view path, float
|
||||
return {};
|
||||
}
|
||||
|
||||
if (value < 0 || value > 100000) {
|
||||
value = roundf(value, 1);
|
||||
if (value < 0.0f || value > 100000.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 1);
|
||||
if (isFloatDifferent(value, dst.d_factor, 0.0001f)) {
|
||||
dst.d_factor = value;
|
||||
changed = true;
|
||||
@@ -2374,11 +2379,11 @@ static SettingResult applySetting(PidSettings& dst, std::string_view path, float
|
||||
return {};
|
||||
}
|
||||
|
||||
if (value < 0 || value > 1) {
|
||||
value = roundf(value, 3);
|
||||
if (value < 0.0f || value > 1.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 3);
|
||||
if (isFloatDifferent(value, dst.deadband.p_multiplier, 0.0001f)) {
|
||||
dst.deadband.p_multiplier = value;
|
||||
changed = true;
|
||||
@@ -2394,11 +2399,11 @@ static SettingResult applySetting(PidSettings& dst, std::string_view path, float
|
||||
return {};
|
||||
}
|
||||
|
||||
if (value < 0 || value > 1) {
|
||||
value = roundf(value, 3);
|
||||
if (value < 0.0f || value > 1.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 3);
|
||||
if (isFloatDifferent(value, dst.deadband.i_multiplier, 0.0001f)) {
|
||||
dst.deadband.i_multiplier = value;
|
||||
changed = true;
|
||||
@@ -2414,11 +2419,11 @@ static SettingResult applySetting(PidSettings& dst, std::string_view path, float
|
||||
return {};
|
||||
}
|
||||
|
||||
if (value < 0 || value > 1) {
|
||||
value = roundf(value, 3);
|
||||
if (value < 0.0f || value > 1.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 3);
|
||||
if (isFloatDifferent(value, dst.deadband.d_multiplier, 0.0001f)) {
|
||||
dst.deadband.d_multiplier = value;
|
||||
changed = true;
|
||||
@@ -2434,11 +2439,11 @@ static SettingResult applySetting(PidSettings& dst, std::string_view path, float
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 2);
|
||||
if (value < 0.0f || value > 5.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 2);
|
||||
if (isFloatDifferent(value, dst.deadband.thresholdHigh, 0.0001f)) {
|
||||
dst.deadband.thresholdHigh = value;
|
||||
changed = true;
|
||||
@@ -2454,11 +2459,11 @@ static SettingResult applySetting(PidSettings& dst, std::string_view path, float
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 2);
|
||||
if (value < 0.0f || value > 5.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 2);
|
||||
if (isFloatDifferent(value, dst.deadband.thresholdLow, 0.0001f)) {
|
||||
dst.deadband.thresholdLow = value;
|
||||
changed = true;
|
||||
@@ -2635,11 +2640,11 @@ static SettingResult applySetting(EquithermSettings& dst, std::string_view path,
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 3);
|
||||
if (value < 0.001f || value > 10.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 3);
|
||||
if (isFloatDifferent(value, dst.slope, 0.0001f)) {
|
||||
dst.slope = value;
|
||||
changed = true;
|
||||
@@ -2655,11 +2660,11 @@ static SettingResult applySetting(EquithermSettings& dst, std::string_view path,
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 3);
|
||||
if (value < 0.2f || value > 2.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 3);
|
||||
if (isFloatDifferent(value, dst.exponent, 0.0001f)) {
|
||||
dst.exponent = value;
|
||||
changed = true;
|
||||
@@ -2675,11 +2680,11 @@ static SettingResult applySetting(EquithermSettings& dst, std::string_view path,
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 2);
|
||||
if (value < -15.0f || value > 15.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 2);
|
||||
if (isFloatDifferent(value, dst.shift, 0.0001f)) {
|
||||
dst.shift = value;
|
||||
changed = true;
|
||||
@@ -2695,11 +2700,11 @@ static SettingResult applySetting(EquithermSettings& dst, std::string_view path,
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 3);
|
||||
if (value < 0.0f || value > 10.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
value = roundf(value, 3);
|
||||
if (isFloatDifferent(value, dst.targetDiffFactor, 0.0001f)) {
|
||||
dst.targetDiffFactor = value;
|
||||
changed = true;
|
||||
|
||||
+3
-3
@@ -173,11 +173,11 @@ static void collectMqttChanges() {
|
||||
template <typename Structure, typename Field, typename Publish>
|
||||
static bool publishField(
|
||||
StructSnapshot<Structure>& snapshot, const Field* field,
|
||||
unsigned long intervalMs, Publish publish
|
||||
unsigned long intervalMs, Publish publish, float tolerance = 0.0001f
|
||||
) {
|
||||
const unsigned long now = millis();
|
||||
unsigned long& lastPublishAt = mqttPublishTimes.get(field);
|
||||
if (lastPublishAt != 0 && now - lastPublishAt < intervalMs && snapshot.equals(field)) {
|
||||
if (lastPublishAt != 0 && now - lastPublishAt < intervalMs && snapshot.equals(field, tolerance)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -460,7 +460,7 @@ static bool publishPidSettings(unsigned long intervalMs) {
|
||||
published = publishField(
|
||||
settingsSnapshot, &settings.pid.i_factor, intervalMs, [](float value) {
|
||||
return publishValue(mqttTopic("settings/pid/i_factor"), value, 4);
|
||||
}
|
||||
}, 0.00005f
|
||||
);
|
||||
if (published) {
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user