Use NaN for missing warning/crit threshold values

Handle loading the Warning and Critical threshold interfaces like the
hard/soft shutdown ones and use NaN if a low or high value is missing in
the JSON, assuming the other one is there.

Using NaN means the threshold alarm will never be tripped for that
property.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ib6b6d3a657df8e77ea4c7e5a491ea367693c5951
diff --git a/virtualSensor.cpp b/virtualSensor.cpp
index e7363cc..a731a15 100644
--- a/virtualSensor.cpp
+++ b/virtualSensor.cpp
@@ -13,8 +13,6 @@
 static constexpr bool DEBUG = false;
 static constexpr auto busName = "xyz.openbmc_project.VirtualSensor";
 static constexpr auto sensorDbusPath = "/xyz/openbmc_project/sensors/";
-static constexpr uint8_t defaultHighThreshold = 100;
-static constexpr uint8_t defaultLowThreshold = 0;
 
 using namespace phosphor::logging;
 
@@ -84,20 +82,33 @@
     auto threshold = sensorConfig.value("Threshold", empty);
     if (!threshold.empty())
     {
-        criticalIface = std::make_unique<CriticalObject>(bus, objPath.c_str());
-        criticalIface->criticalHigh(
-            threshold.value("CriticalHigh", defaultHighThreshold));
-        criticalIface->criticalLow(
-            threshold.value("CriticalLow", defaultLowThreshold));
-
-        warningIface = std::make_unique<WarningObject>(bus, objPath.c_str());
-        warningIface->warningHigh(
-            threshold.value("WarningHigh", defaultHighThreshold));
-        warningIface->warningLow(
-            threshold.value("WarningLow", defaultLowThreshold));
-
-        // Only create the high and low shutdown interfaces if
+        // Only create the threshold interfaces if
         // at least one of their values is present.
+
+        if (threshold.contains("CriticalHigh") ||
+            threshold.contains("CriticalLow"))
+        {
+            criticalIface =
+                std::make_unique<CriticalObject>(bus, objPath.c_str());
+
+            criticalIface->criticalHigh(threshold.value(
+                "CriticalHigh", std::numeric_limits<double>::quiet_NaN()));
+            criticalIface->criticalLow(threshold.value(
+                "CriticalLow", std::numeric_limits<double>::quiet_NaN()));
+        }
+
+        if (threshold.contains("WarningHigh") ||
+            threshold.contains("WarningLow"))
+        {
+            warningIface =
+                std::make_unique<WarningObject>(bus, objPath.c_str());
+
+            warningIface->warningHigh(threshold.value(
+                "WarningHigh", std::numeric_limits<double>::quiet_NaN()));
+            warningIface->warningLow(threshold.value(
+                "WarningLow", std::numeric_limits<double>::quiet_NaN()));
+        }
+
         if (threshold.contains("HardShutdownHigh") ||
             threshold.contains("HardShutdownLow"))
         {