Fixes around persisting values in entity-manager

This fixes three problems that were causing "Faild to set dbus
property." error traces to show up.

1. In VirtualSensor::createThresholds() the setEntityPath() and
   setEntityInterfaceHigh/Low() calls have to be made on the threshold
   objects before the critical/warning/High/Low() functions are called
   so that the path and interface is known for the property set call.
   Reorder the code so this is the case.

2. Saving the value in entity-manager only works when the virtual sensor
   config was obtained from entity-manager D-Bus objects, and not when
   it was obtained from virtual_sensor_config.json.  In the latter case,
   the 'entityPath' variable won't have a value, so check for that
   before trying to set a property on entity-manager.

3. If either a 'high' or 'low' threshold property isn't set, then the
   'entityInterfaceHigh/Low' variable will be empty.  Also skip the
   property write in that case.

Tested:  No more error traces, and verified that changing a threshold
value on a virtual sensor is still reflected in entity-manager when its
config was from EM in the first place.

Change-Id: I67dc35fb4b8f4c1367231e22ddde91fbd1bb354d
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/virtualSensor.cpp b/virtualSensor.cpp
index d130200..e2e0399 100644
--- a/virtualSensor.cpp
+++ b/virtualSensor.cpp
@@ -596,15 +596,6 @@
         criticalIface =
             std::make_unique<Threshold<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()));
-        criticalIface->setHighHysteresis(
-            threshold.value("CriticalHighHysteresis", defaultHysteresis));
-        criticalIface->setLowHysteresis(
-            threshold.value("CriticalLowHysteresis", defaultHysteresis));
-
         if (threshold.contains("CriticalHigh"))
         {
             criticalIface->setEntityInterfaceHigh(
@@ -632,6 +623,15 @@
             debug("Sensor Threshold:{NAME} = path:{PATH}", "NAME", objPath,
                   "PATH", entityPath);
         }
+
+        criticalIface->criticalHigh(threshold.value(
+            "CriticalHigh", std::numeric_limits<double>::quiet_NaN()));
+        criticalIface->criticalLow(threshold.value(
+            "CriticalLow", std::numeric_limits<double>::quiet_NaN()));
+        criticalIface->setHighHysteresis(
+            threshold.value("CriticalHighHysteresis", defaultHysteresis));
+        criticalIface->setLowHysteresis(
+            threshold.value("CriticalLowHysteresis", defaultHysteresis));
     }
 
     if (threshold.contains("WarningHigh") || threshold.contains("WarningLow"))
@@ -639,15 +639,6 @@
         warningIface =
             std::make_unique<Threshold<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()));
-        warningIface->setHighHysteresis(
-            threshold.value("WarningHighHysteresis", defaultHysteresis));
-        warningIface->setLowHysteresis(
-            threshold.value("WarningLowHysteresis", defaultHysteresis));
-
         if (threshold.contains("WarningHigh"))
         {
             warningIface->setEntityInterfaceHigh(
@@ -675,6 +666,15 @@
             debug("Sensor Threshold:{NAME} = path:{PATH}", "NAME", objPath,
                   "PATH", entityPath);
         }
+
+        warningIface->warningHigh(threshold.value(
+            "WarningHigh", std::numeric_limits<double>::quiet_NaN()));
+        warningIface->warningLow(threshold.value(
+            "WarningLow", std::numeric_limits<double>::quiet_NaN()));
+        warningIface->setHighHysteresis(
+            threshold.value("WarningHighHysteresis", defaultHysteresis));
+        warningIface->setLowHysteresis(
+            threshold.value("WarningLowHysteresis", defaultHysteresis));
     }
 
     if (threshold.contains("HardShutdownHigh") ||