Factor out getPowerState() helper function

This same pattern had been open-coded in many of the sensor daemons;
let's reduce the duplication a bit.

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Change-Id: I8556af30fdcd53cdf06e5a4911f9152d3265c7af
diff --git a/include/Utils.hpp b/include/Utils.hpp
index 92a8b6f..b823e5b 100644
--- a/include/Utils.hpp
+++ b/include/Utils.hpp
@@ -170,6 +170,19 @@
     }
 }
 
+inline PowerState getPowerState(const SensorBaseConfigMap& cfg)
+{
+    PowerState state = PowerState::always;
+    auto findPowerState = cfg.find("PowerState");
+    if (findPowerState != cfg.end())
+    {
+        std::string powerState =
+            std::visit(VariantToStringVisitor(), findPowerState->second);
+        setReadState(powerState, state);
+    }
+    return state;
+}
+
 inline void setLed(const std::shared_ptr<sdbusplus::asio::connection>& conn,
                    const std::string& name, bool on)
 {