Add getPollRate helper function

This open-coded pattern had been duplicated in a few places; deduplicate
and increase readability by adding a dedicated function.  While we're at
it, also ensure the configured value isn't inf or NaN.

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Change-Id: I5f8fe788eb342ca3bf8b52bd6a2e7cc3364f45e1
diff --git a/include/Utils.hpp b/include/Utils.hpp
index b39492e..790bbf8 100644
--- a/include/Utils.hpp
+++ b/include/Utils.hpp
@@ -194,6 +194,21 @@
     return state;
 }
 
+inline float getPollRate(const SensorBaseConfigMap& cfg, float dflt)
+{
+    float pollRate = dflt;
+    auto findPollRate = cfg.find("PollRate");
+    if (findPollRate != cfg.end())
+    {
+        pollRate = std::visit(VariantToFloatVisitor(), findPollRate->second);
+        if (!std::isfinite(pollRate) || pollRate <= 0.0F)
+        {
+            pollRate = dflt; // poll time invalid, fall back to default
+        }
+    }
+    return pollRate;
+}
+
 inline void setLed(const std::shared_ptr<sdbusplus::asio::connection>& conn,
                    const std::string& name, bool on)
 {