FIX: added missing sensor->loopBeforeValues()

This commit is contained in:
Patrick Haßel 2025-01-16 16:18:55 +01:00
parent 7cac90875f
commit ad4e425895
2 changed files with 14 additions and 8 deletions

View File

@ -50,6 +50,12 @@ private:
auto sensorIndex = 0; auto sensorIndex = 0;
Sensor *sensor; Sensor *sensor;
while ((sensor = getSensor(sensorIndex++)) != nullptr) { while ((sensor = getSensor(sensorIndex++)) != nullptr) {
sensor->loopBeforeValues();
loopValues(timestamp, cacheIndex, sensor);
}
}
void loopValues(const time_t timestamp, int& cacheIndex, Sensor *sensor) {
auto valueIndex = 0; auto valueIndex = 0;
Value *value; Value *value;
while ((value = sensor->getValue(valueIndex++)) != nullptr) { while ((value = sensor->getValue(valueIndex++)) != nullptr) {
@ -58,7 +64,6 @@ private:
} }
} }
} }
}
void cacheSend() { void cacheSend() {
const auto entry = cache.read(); const auto entry = cache.read();

View File

@ -52,15 +52,16 @@ public:
update(NAN); update(NAN);
} }
const auto now = time(nullptr);
const auto dueToNAN = isnan(currentValue) != isnan(sentValue); const auto dueToNAN = isnan(currentValue) != isnan(sentValue);
const auto dueToThreshold = abs(sentValue - currentValue) >= threshold; const auto dueToThreshold = abs(sentValue - currentValue) >= threshold;
const auto dueToTime = sentInterval != 0 && sentInterval != time(nullptr) / overdueSeconds; const auto dueToTime = sentInterval != 0 && sentInterval != now / overdueSeconds;
const auto changed = dueToNAN || dueToThreshold || dueToTime; const auto changed = dueToNAN || dueToThreshold || dueToTime;
if (changed) { if (changed) {
mqttPublish(name + "/retain", String(currentValue), RETAIN); mqttPublish(name + "/retain", String(currentValue), RETAIN);
websocketSendAll(toJson(false)); websocketSendAll(toJson(false));
sentValue = currentValue; sentValue = currentValue;
sentInterval = time(nullptr) / overdueSeconds; sentInterval = now / overdueSeconds;
} }
return changed; return changed;
} }