sensor: Implement sensor "ACCURACY"

Support the accuracy attribute of the sensor. Since the latest
Redfish spec needs to support the accuracy attribute of the sensor,
extend the configuration file syntax to support the accuracy value,
read the value and publish it to the new D-Bus Accuracy interface.

Also, This function will be synchronized to the dbus sensors repo in
the future.

Tested: Build phosphor-hwmon successfully
eg: The configuration accuracy in power supply is 1
~# busctl get-property xyz.openbmc_project.Hwmon-xxx.Hwmon1
/xyz/openbmc_project/sensors/power/ps0_input_power
xyz.openbmc_project.Sensor.Accuracy Accuracy
d 1

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Idd0159b75a7506001cf886f4ae8a22dbd38b1135
diff --git a/mainloop.cpp b/mainloop.cpp
index 85770a2..f205003 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -174,14 +174,17 @@
 {
     std::string id = getID(sensor);
     std::string label;
+    std::string accuracy;
 
     if (!id.empty())
     {
         // Ignore inputs without a label.
         label = env::getEnv("LABEL", sensor.first.first, id);
+        accuracy = env::getEnv("ACCURACY", sensor.first.first, id);
     }
 
-    return std::make_tuple(std::move(id), std::move(label));
+    return std::make_tuple(std::move(id), std::move(label),
+                           std::move(accuracy));
 }
 
 /**
@@ -237,6 +240,20 @@
     auto valueInterface = static_cast<std::shared_ptr<ValueObject>>(nullptr);
     try
     {
+        // Add accuracy interface
+        auto accuracyStr = std::get<sensorAccuracy>(properties);
+        try
+        {
+            if (!accuracyStr.empty())
+            {
+                auto accuracy = stod(accuracyStr);
+                sensorObj->addAccuracy(info, accuracy);
+            }
+        }
+        catch (const std::invalid_argument&)
+        {
+        }
+
         // Add status interface based on _fault file being present
         sensorObj->addStatus(info);
         valueInterface = sensorObj->addValue(retryIO, info, _timedoutMap);