OnChange trigger should not handle first reading
When OnChange trigger register for updates, it gets current sensor value
as an update. This reading fires trigger actions and is undesirable.
This change skips handling of first reading update for OnChange trigger.
Testing done:
- UTs updated and are passing,
- OnChange trigger is not doing an action on first reading update.
Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: Ief2d1edd5923fd332f3ea3234a9988e1967d972f
diff --git a/src/on_change_threshold.cpp b/src/on_change_threshold.cpp
index 72aedc5..eea8978 100644
--- a/src/on_change_threshold.cpp
+++ b/src/on_change_threshold.cpp
@@ -53,6 +53,12 @@
void OnChangeThreshold::sensorUpdated(interfaces::Sensor& sensor,
Milliseconds timestamp, double value)
{
+ if (isFirstReading)
+ {
+ isFirstReading = false;
+ return;
+ }
+
commit(sensor.getName(), timestamp, value);
}
diff --git a/src/on_change_threshold.hpp b/src/on_change_threshold.hpp
index 80876a2..1d4a4d0 100644
--- a/src/on_change_threshold.hpp
+++ b/src/on_change_threshold.hpp
@@ -33,6 +33,7 @@
Sensors sensors;
const std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
bool initialized = false;
+ bool isFirstReading = true;
void commit(const std::string&, Milliseconds, double);
};