HwmonTempSensor: Add PollRate attribute

Tested:
1. Add the following configuration for test case:
   {
      "Address": "0x5c",
      "Bus": "47",
      "Name": "inlet",
      "PollRate": 100.0,
      "Thresholds": [
         ...
      ],
      "Type": "MAX31725"
   },
   - update sensor once every 100 seconds and verify pass.
2. Add "PollRate" in configuration for positive and negative value and
   verify pass.

Signed-off-by: Jeff Lin <JeffLin2@quantatw.com>
Change-Id: Ieeee2dd7ab6b3b2d237496b356e29b856078eb06
diff --git a/src/HwmonTempMain.cpp b/src/HwmonTempMain.cpp
index b5cbf23..8a583b9 100644
--- a/src/HwmonTempMain.cpp
+++ b/src/HwmonTempMain.cpp
@@ -38,6 +38,7 @@
 #include <vector>
 
 static constexpr bool DEBUG = false;
+static constexpr float pollRateDefault = 0.5;
 
 namespace fs = std::filesystem;
 static constexpr std::array<const char*, 13> sensorTypes = {
@@ -207,6 +208,19 @@
                     std::cerr << "error populating thresholds for "
                               << sensorName << "\n";
                 }
+
+                auto findPollRate = baseConfiguration->second.find("PollRate");
+                float pollRate = pollRateDefault;
+                if (findPollRate != baseConfiguration->second.end())
+                {
+                    pollRate = std::visit(VariantToFloatVisitor(),
+                                          findPollRate->second);
+                    if (pollRate <= 0.0f)
+                    {
+                        pollRate = pollRateDefault; // polling time too short
+                    }
+                }
+
                 auto findPowerOn = baseConfiguration->second.find("PowerState");
                 PowerState readState = PowerState::always;
                 if (findPowerOn != baseConfiguration->second.end())
@@ -225,7 +239,7 @@
                 {
                     sensor = std::make_shared<HwmonTempSensor>(
                         *hwmonFile, sensorType, objectServer, dbusConnection,
-                        io, sensorName, std::move(sensorThresholds),
+                        io, sensorName, std::move(sensorThresholds), pollRate,
                         *interfacePath, readState);
                     sensor->setupRead();
                 }
@@ -253,7 +267,7 @@
                         sensor = std::make_shared<HwmonTempSensor>(
                             *hwmonFile, sensorType, objectServer,
                             dbusConnection, io, sensorName,
-                            std::vector<thresholds::Threshold>(),
+                            std::vector<thresholds::Threshold>(), pollRate,
                             *interfacePath, readState);
                         sensor->setupRead();
                     }