Preserve original discrete trigger value

Currently, there are no 'real' discrete sensors, so discrete trigger is
working with numeric ones. Dbus api is using string as thresholdValue,
but internally service is converting it to double. This resulted in
side-effect of malformed value of Thresholds property, e.g., 90.0 being
represented as 90.000000. This change stores original value in order to
not confuse potential users.

Additionally, check was added to validate whole string of thesholdValue.
Now, it must consist only of numeric characters, values like '12.3FOO'
will be rejected on AddTrigger call.

Testing done:
- UTs added and are passing,
- dbus get-property on Thresholds confirms unchanged initial value.

Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: Iec3514ac1479587e610f8da31ecf9ba6fc0bdb62
diff --git a/src/discrete_threshold.cpp b/src/discrete_threshold.cpp
index d7640f6..1bb250f 100644
--- a/src/discrete_threshold.cpp
+++ b/src/discrete_threshold.cpp
@@ -1,15 +1,19 @@
 #include "discrete_threshold.hpp"
 
+#include "utils/conversion_trigger.hpp"
+
 #include <phosphor-logging/log.hpp>
 
 DiscreteThreshold::DiscreteThreshold(
     boost::asio::io_context& ioc, Sensors sensorsIn,
     std::vector<std::unique_ptr<interfaces::TriggerAction>> actionsIn,
-    Milliseconds dwellTimeIn, double thresholdValueIn,
+    Milliseconds dwellTimeIn, const std::string& thresholdValueIn,
     const std::string& nameIn, const discrete::Severity severityIn) :
     ioc(ioc),
     actions(std::move(actionsIn)), dwellTime(dwellTimeIn),
-    thresholdValue(thresholdValueIn), name(nameIn), severity(severityIn)
+    thresholdValue(thresholdValueIn),
+    numericThresholdValue(utils::stodStrict(thresholdValue)), name(nameIn),
+    severity(severityIn)
 {
     for (const auto& sensor : sensorsIn)
     {
@@ -45,17 +49,14 @@
     auto& details = getDetails(sensor);
     auto& [sensorName, dwell, timer] = details;
 
-    if (thresholdValue)
+    if (dwell && value != numericThresholdValue)
     {
-        if (dwell && value != thresholdValue)
-        {
-            timer.cancel();
-            dwell = false;
-        }
-        else if (value == thresholdValue)
-        {
-            startTimer(details, timestamp, value);
-        }
+        timer.cancel();
+        dwell = false;
+    }
+    else if (value == numericThresholdValue)
+    {
+        startTimer(details, timestamp, value);
     }
 }
 
@@ -100,5 +101,5 @@
 LabeledThresholdParam DiscreteThreshold::getThresholdParam() const
 {
     return discrete::LabeledThresholdParam(name, severity, dwellTime.count(),
-                                           std::to_string(thresholdValue));
+                                           thresholdValue);
 }