Add Hysteresis support

This adds a hysteresis to each sensor that is 1% of
the range of the sensor.

Change-Id: I0c8606e61d1aca3582d1f6882be5da1bf2884cd9
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/include/sensor.hpp b/include/sensor.hpp
index 29f674a..3ff37f7 100644
--- a/include/sensor.hpp
+++ b/include/sensor.hpp
@@ -14,7 +14,8 @@
            const double max, const double min) :
         name(name),
         configurationPath(configurationPath), objectType(objectType),
-        thresholds(std::move(thresholdData)), maxValue(max), minValue(min)
+        thresholds(std::move(thresholdData)), maxValue(max), minValue(min),
+        hysteresis((max - min) * 0.01)
     {
     }
     virtual ~Sensor() = default;
@@ -32,6 +33,7 @@
     double value = std::numeric_limits<double>::quiet_NaN();
     bool overriddenState = false;
     bool internalSet = false;
+    double hysteresis;
 
     int setSensorValue(const double& newValue, double& oldValue)
     {
@@ -144,8 +146,11 @@
             internalSet = true;
             sensorInterface->set_property("Value", newValue);
             internalSet = false;
-            value = newValue;
-            checkThresholds();
+            if (std::abs(value - newValue) > hysteresis)
+            {
+                value = newValue;
+                checkThresholds();
+            }
         }
     }
 };