Commit f901b29b authored by Arjen Hiemstra's avatar Arjen Hiemstra Committed by Nate Graham
Browse files

Only rate-limit sensors if we already have a valid value

If we don't yet have a valid value, we should make sure to always update
the value so we can show something valid. Most importantly, this
prevents the value from being empty when the first value update comes in
for a sensor that is static.

BUG: 446372
parent 685a43af
Pipeline #130044 passed with stage
in 1 minute and 27 seconds
......@@ -228,6 +228,7 @@ void Sensor::setUpdateRateLimit(int newUpdateRateLimit)
d->updateRateLimit = newUpdateRateLimit;
}
d->lastUpdate = chrono::steady_clock::now();
Q_EMIT updateRateLimitChanged();
}
......@@ -275,7 +276,7 @@ void Sensor::onValueChanged(const QString &sensorId, const QVariant &value)
return;
}
if (d->updateRateLimit) {
if (d->updateRateLimit && d->value.isValid()) {
auto updateRateLimit = chrono::steady_clock::duration(chrono::milliseconds(d->updateRateLimit.value()));
auto now = chrono::steady_clock::now();
if (now - d->lastUpdate < updateRateLimit) {
......
......@@ -478,7 +478,7 @@ void SensorDataModel::onValueChanged(const QString &sensorId, const QVariant &va
return;
}
if (d->updateRateLimit) {
if (d->updateRateLimit && d->sensorData[sensorId].isValid()) {
auto updateRateLimit = chrono::steady_clock::duration(chrono::milliseconds(d->updateRateLimit.value()));
auto now = chrono::steady_clock::now();
if (d->lastUpdateTimes.contains(column) && now - d->lastUpdateTimes.value(column) < updateRateLimit) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment