healthMonitor: wait until enough sensor reading in queue

Usually the BMC is very busy during startup and it is risky to fill up
the entire queue with only one initial value.

In this patch, we wait until the queue is filled with enough sensor
values before doing any checks.

Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Change-Id: I38de9351e88fb666051008170bdeae635fbcd103
diff --git a/healthMonitor.cpp b/healthMonitor.cpp
index 05f9cbc..3c5cd89 100644
--- a/healthMonitor.cpp
+++ b/healthMonitor.cpp
@@ -256,50 +256,12 @@
 
 void HealthSensor::initHealthSensor(const std::vector<std::string>& chassisIds)
 {
-    info("{SENSOR} Health Sensor initialized", "SENSOR", sensorConfig.name);
-
-    /* Look for sensor read functions and Read Sensor values */
-    double value;
-    std::map<std::string,
-             std::function<double(std::string path)>>::const_iterator it;
-    it = readSensors.find(sensorConfig.name);
-
-    if (sensorConfig.name.rfind(storage, 0) == 0)
-    {
-        it = readSensors.find(storage);
-    }
-    else if (sensorConfig.name.rfind(inode, 0) == 0)
-    {
-        it = readSensors.find(inode);
-    }
-    else if (it == readSensors.end())
-    {
-        error("Sensor read function not available");
-        return;
-    }
-
-    value = it->second(sensorConfig.path);
-
-    if (value < 0)
-    {
-        error("Reading Sensor Utilization failed: {SENSOR}", "SENSOR",
-              sensorConfig.name);
-        return;
-    }
-
-    /* Initialize value queue with initial sensor reading */
-    for (int i = 0; i < sensorConfig.windowSize; i++)
-    {
-        valQueue.push_back(value);
-    }
-
     /* Initialize unit value (Percent) for utilization sensor */
     ValueIface::unit(ValueIface::Unit::Percent);
 
     ValueIface::maxValue(100);
     ValueIface::minValue(0);
-
-    setSensorValueToDbus(value);
+    ValueIface::value(std::numeric_limits<double>::quiet_NaN());
 
     // Associate the sensor to chassis
     std::vector<AssociationTuple> associationTuples;
@@ -394,9 +356,17 @@
     }
 
     /* Remove first item from the queue */
-    valQueue.pop_front();
+    if (valQueue.size() >= sensorConfig.windowSize)
+    {
+        valQueue.pop_front();
+    }
     /* Add new item at the back */
     valQueue.push_back(value);
+    /* Wait until the queue is filled with enough reference*/
+    if (valQueue.size() < sensorConfig.windowSize)
+    {
+        return;
+    }
 
     /* Calculate average values for the given window size */
     double avgValue = 0;