Fix PSU threshold mismatch issue

When trying to change thresholds on PSU sensors, PSU service will crash.
Some PSU in entity-manager will have threshold0 to threshodl5 which
contains all labels in one D-Bus path. But in current dbus sensors,
the presist threshold function do not support labels, it only check
severity. So when change a threshold in PSU sensor, it will change some
incorrect threshold in entity-manger. This patch adds label support to
presist threshold function, so that correct theshold in entity-manager
can be changed.

Tested:
After changed PSU1 Temp1 threshold by ipmitool, check the threshold again,
the value should be changed to the value we set. Check entity-manager,
the threshold in entity-manager should also change to the value we set.

Signed-off-by: Cheng C Yang <cheng.c.yang@linux.intel.com>
Change-Id: Ib1c8bb454cd42dff170ae33c4aa768c4b515bb44
diff --git a/include/PSUSensor.hpp b/include/PSUSensor.hpp
index 14b6d96..98ec3d7 100644
--- a/include/PSUSensor.hpp
+++ b/include/PSUSensor.hpp
@@ -18,7 +18,7 @@
               std::vector<thresholds::Threshold>&& thresholds,
               const std::string& sensorConfiguration,
               std::string& sensorTypeName, unsigned int factor, double max,
-              double min);
+              double min, const std::string& label, size_t tSize);
     ~PSUSensor();
 
   private:
diff --git a/include/Thresholds.hpp b/include/Thresholds.hpp
index 00df68c..20ce69e 100644
--- a/include/Thresholds.hpp
+++ b/include/Thresholds.hpp
@@ -118,10 +118,11 @@
 void persistThreshold(const std::string& baseInterface, const std::string& path,
                       const thresholds::Threshold& threshold,
                       std::shared_ptr<sdbusplus::asio::connection>& conn,
-                      size_t thresholdCount);
+                      size_t thresholdCount, const std::string& label);
 
 void updateThresholds(Sensor* sensor);
 // returns false if a critical threshold has been crossed, true otherwise
 bool checkThresholds(Sensor* sensor);
 void checkThresholdsPowerDelay(Sensor* sensor, ThresholdTimer& thresholdTimer);
+
 } // namespace thresholds
diff --git a/include/sensor.hpp b/include/sensor.hpp
index e298677..3c4706f 100644
--- a/include/sensor.hpp
+++ b/include/sensor.hpp
@@ -60,7 +60,9 @@
     }
 
     void
-        setInitialProperties(std::shared_ptr<sdbusplus::asio::connection>& conn)
+        setInitialProperties(std::shared_ptr<sdbusplus::asio::connection>& conn,
+                             const std::string label = std::string(),
+                             size_t thresholdSize = 0)
     {
         createAssociation(association, configurationPath);
 
@@ -114,14 +116,17 @@
                 std::cout << "trying to set uninitialized interface\n";
                 continue;
             }
+
+            size_t thresSize =
+                label.empty() ? thresholds.size() : thresholdSize;
             iface->register_property(
                 level, threshold.value,
-                [&](const double& request, double& oldValue) {
+                [&, label, thresSize](const double& request, double& oldValue) {
                     oldValue = request; // todo, just let the config do this?
                     threshold.value = request;
                     thresholds::persistThreshold(configurationPath, objectType,
-                                                 threshold, conn,
-                                                 thresholds.size());
+                                                 threshold, conn, thresSize,
+                                                 label);
                     // Invalidate previously remembered value,
                     // so new thresholds will be checked during next update,
                     // even if sensor reading remains unchanged.