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,12 +50,17 @@ private:
auto sensorIndex = 0;
Sensor *sensor;
while ((sensor = getSensor(sensorIndex++)) != nullptr) {
auto valueIndex = 0;
Value *value;
while ((value = sensor->getValue(valueIndex++)) != nullptr) {
if (value->loop()) {
cache.put(timestamp, cacheIndex++, value->getCurrentValue());
}
sensor->loopBeforeValues();
loopValues(timestamp, cacheIndex, sensor);
}
}
void loopValues(const time_t timestamp, int& cacheIndex, Sensor *sensor) {
auto valueIndex = 0;
Value *value;
while ((value = sensor->getValue(valueIndex++)) != nullptr) {
if (value->loop()) {
cache.put(timestamp, cacheIndex++, value->getCurrentValue());
}
}
}

View File

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