Initialize the wctemp/modelNumber of struct NVMeData

Avoid to set unexpected value for wctemp/modelNumber
and also set thresholds when they're different from the
previous one

Signed-off-by: George Hung <george.hung@quantatw.com>
Signed-off-by: Brandon Kim <brandonkim@google.com>
Change-Id: Ib5247dcc0b20c017cefba5eac61a92638310d0b5
diff --git a/nvme_manager.cpp b/nvme_manager.cpp
index 02bc819..9ceed7c 100644
--- a/nvme_manager.cpp
+++ b/nvme_manager.cpp
@@ -214,10 +214,12 @@
     nvmeData.present = true;
     nvmeData.vendor = "";
     nvmeData.serialNumber = "";
+    nvmeData.modelNumber = "";
     nvmeData.smartWarnings = "";
     nvmeData.statusFlags = "";
     nvmeData.driveLifeUsed = "";
     nvmeData.sensorValue = (int8_t)TEMPERATURE_SENSOR_FAILURE;
+    nvmeData.wcTemp = 0;
 
     phosphor::smbus::Smbus smbus;
 
@@ -503,7 +505,7 @@
     std::string inventoryPath;
     std::map<sdbusplus::message::object_path, Interfaces> obj;
 
-    for (const auto config : configs)
+    for (const auto& config : configs)
     {
         inventoryPath = "/system/chassis/motherboard/nvme" + config.index;
 
@@ -547,8 +549,8 @@
             config.criticalHigh = nvmeData.wcTemp;
             config.warningHigh = nvmeData.wcTemp;
         }
+        nvmeSSD->setSensorMaxMin(config.maxValue, config.minValue);
         nvmeSSD->setSensorThreshold(config.criticalHigh, config.criticalLow,
-                                    config.maxValue, config.minValue,
                                     config.warningHigh, config.warningLow);
 
         nvmeSSD->checkSensorThreshold();
@@ -558,6 +560,12 @@
     {
         setNvmeInventoryProperties(true, nvmeData, inventoryPath);
         iter->second->setSensorValueToDbus(nvmeData.sensorValue);
+        if (nvmeData.wcTemp != 0)
+        {
+            iter->second->setSensorThreshold(
+                config.criticalHigh, config.criticalLow, config.warningHigh,
+                config.warningLow);
+        }
         iter->second->checkSensorThreshold();
         setLEDsStatus(config, success, nvmeData);
     }
diff --git a/nvmes.cpp b/nvmes.cpp
index 01222d0..972d406 100644
--- a/nvmes.cpp
+++ b/nvmes.cpp
@@ -23,16 +23,17 @@
 }
 
 void NvmeSSD::setSensorThreshold(int8_t criticalHigh, int8_t criticalLow,
-                                 int8_t maxValue, int8_t minValue,
                                  int8_t warningHigh, int8_t warningLow)
 {
-
     CriticalInterface::criticalHigh(criticalHigh);
     CriticalInterface::criticalLow(criticalLow);
 
     WarningInterface::warningHigh(warningHigh);
     WarningInterface::warningLow(warningLow);
+}
 
+void NvmeSSD::setSensorMaxMin(int8_t maxValue, int8_t minValue)
+{
     ValueIface::maxValue(maxValue);
     ValueIface::minValue(minValue);
 }
@@ -43,4 +44,4 @@
 }
 
 } // namespace nvme
-} // namespace phosphor
\ No newline at end of file
+} // namespace phosphor
diff --git a/nvmes.hpp b/nvmes.hpp
index c9a133e..64d279e 100644
--- a/nvmes.hpp
+++ b/nvmes.hpp
@@ -54,8 +54,9 @@
     void checkSensorThreshold();
     /** @brief Set Sensor Threshold to D-bus at beginning */
     void setSensorThreshold(int8_t criticalHigh, int8_t criticalLow,
-                            int8_t maxValue, int8_t minValue,
                             int8_t warningHigh, int8_t warningLow);
+    /** @brief Set Sensor Max/Min value to D-bus at beginning */
+    void setSensorMaxMin(int8_t maxValue, int8_t minValue);
 
   private:
     sdbusplus::bus::bus& bus;