Clean up power state handling and fix voltage events

Seperate isPowerOn into two functions, one to set up the
match and one to poll the boolean. This way a dbus connection
object isn't needed in the sensor. Use this new function to
allow the ADCSensor to only signal threshold crosses if the
sensor is in the correct state.

Tested-by: Verified no SEL events for ADC sensors were created
during power cycling.

Change-Id: Ida800ab478b85ac2cb5976fa3471411c5d4bdc88
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/src/ADCSensorMain.cpp b/src/ADCSensorMain.cpp
index 4fff81a..8bd28b9 100644
--- a/src/ADCSensorMain.cpp
+++ b/src/ADCSensorMain.cpp
@@ -183,9 +183,23 @@
             scaleFactor = variant_ns::visit(VariantToFloatVisitor(),
                                             findScaleFactor->second);
         }
+
+        auto findPowerOn = baseConfiguration->second.find("PowerState");
+        PowerState readState = PowerState::always;
+        if (findPowerOn != baseConfiguration->second.end())
+        {
+            std::string powerState = variant_ns::visit(VariantToStringVisitor(),
+                                                       findPowerOn->second);
+            if (powerState == "On")
+            {
+                readState = PowerState::on;
+            };
+        }
+
         sensors[sensorName] = std::make_unique<ADCSensor>(
             path.string(), objectServer, dbusConnection, io, sensorName,
-            std::move(sensorThresholds), scaleFactor, *interfacePath);
+            std::move(sensorThresholds), scaleFactor, readState,
+            *interfacePath);
     }
 }