thresholds: support hysteresis field if supplied

At the moment dbus-sensors that use thresholds use a default hysteresis
of (max - min) * 0.01. If a hysteresis field is specified for a
threshold that is not NaN, use that instead.

Tested by giving a sensor multiple thresholds, with and without
hysteresis, changing the value of the sensor and observing that the
threshold alarms are asserted and deasserted as expected.

Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com>
Change-Id: I9c6c2ef3bb034157b0a6b3bd5c359dae7592d85b
diff --git a/src/Thresholds.cpp b/src/Thresholds.cpp
index c52eee6..0581f21 100644
--- a/src/Thresholds.cpp
+++ b/src/Thresholds.cpp
@@ -100,6 +100,14 @@
             }
         }
 
+        double hysteresis = std::numeric_limits<double>::quiet_NaN();
+        auto hysteresisFind = item.second.find("Hysteresis");
+        if (hysteresisFind != item.second.end())
+        {
+            hysteresis =
+                std::visit(VariantToDoubleVisitor(), hysteresisFind->second);
+        }
+
         auto directionFind = item.second.find("Direction");
         auto severityFind = item.second.find("Severity");
         auto valueFind = item.second.find("Value");
@@ -133,7 +141,7 @@
         }
         double val = std::visit(VariantToDoubleVisitor(), valueFind->second);
 
-        thresholdVector.emplace_back(level, direction, val);
+        thresholdVector.emplace_back(level, direction, val, hysteresis);
     }
     return true;
 }
@@ -305,7 +313,7 @@
                               << " raw data " << sensor->rawValue << "\n";
                 }
             }
-            else if (value < (threshold.value - sensor->hysteresisTrigger))
+            else if (value < (threshold.value - threshold.hysteresis))
             {
                 thresholdChanges.emplace_back(threshold, false, value);
                 ++cHiFalse;
@@ -328,7 +336,7 @@
                               << sensor->rawValue << "\n";
                 }
             }
-            else if (value > (threshold.value + sensor->hysteresisTrigger))
+            else if (value > (threshold.value + threshold.hysteresis))
             {
                 thresholdChanges.emplace_back(threshold, false, value);
                 ++cLoFalse;