sensor: Bypass updating Nan to value when it's already Nan
Bypass updating sensor value when both old and new value of the sensor
are Nan. This avoids continuous value update to some sensor types
(nvmesensor, adcsensor) when the power state is off, and affecting
speed of applications that listen to their propertiesChanged signals.
Signed-off-by: chaul.ampere <chaul@amperecomputing.com>
Change-Id: I20044ecdb2f420928a83bed7e37eef6750ce9e5f
diff --git a/include/sensor.hpp b/include/sensor.hpp
index abc6d82..2bc55f5 100644
--- a/include/sensor.hpp
+++ b/include/sensor.hpp
@@ -535,12 +535,13 @@
bool requiresUpdate(const double& lVal, const double& rVal) const
{
- if (std::isnan(lVal) || std::isnan(rVal))
+ const auto lNan = std::isnan(lVal);
+ const auto rNan = std::isnan(rVal);
+ if (lNan || rNan)
{
- return true;
+ return (lNan != rNan);
}
- double diff = std::abs(lVal - rVal);
- return diff > hysteresisPublish;
+ return std::abs(lVal - rVal) > hysteresisPublish;
}
private: