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/include/ADCSensor.hpp b/include/ADCSensor.hpp
index d7eb933..2b5cdd4 100644
--- a/include/ADCSensor.hpp
+++ b/include/ADCSensor.hpp
@@ -4,6 +4,11 @@
 #include <sdbusplus/asio/object_server.hpp>
 #include <sensor.hpp>
 
+enum class PowerState : bool
+{
+    on,
+    always
+};
 class ADCSensor : public Sensor
 {
   public:
@@ -12,7 +17,8 @@
               std::shared_ptr<sdbusplus::asio::connection> &conn,
               boost::asio::io_service &io, const std::string &sensorName,
               std::vector<thresholds::Threshold> &&thresholds,
-              const double scaleFactor, const std::string &sensorConfiguration);
+              const double scaleFactor, PowerState readState,
+              const std::string &sensorConfiguration);
     ~ADCSensor();
 
   private:
@@ -22,6 +28,7 @@
     boost::asio::streambuf readBuf;
     int errCount;
     double scaleFactor;
+    PowerState readState;
     void setupRead(void);
     void handleResponse(const boost::system::error_code &err);
     void checkThresholds(void) override;
diff --git a/include/CPUSensor.hpp b/include/CPUSensor.hpp
index 4eb2ae0..10c1f4e 100644
--- a/include/CPUSensor.hpp
+++ b/include/CPUSensor.hpp
@@ -19,7 +19,6 @@
 
   private:
     sdbusplus::asio::object_server &objServer;
-    std::shared_ptr<sdbusplus::asio::connection> dbusConnection;
     boost::asio::posix::stream_descriptor inputDev;
     boost::asio::deadline_timer waitTimer;
     boost::asio::streambuf readBuf;
diff --git a/include/TachSensor.hpp b/include/TachSensor.hpp
index 174ce56..9fc50a6 100644
--- a/include/TachSensor.hpp
+++ b/include/TachSensor.hpp
@@ -59,7 +59,6 @@
   private:
     sdbusplus::asio::object_server &objServer;
     std::shared_ptr<RedundancySensor> redundancy;
-    std::shared_ptr<sdbusplus::asio::connection> dbusConnection;
     std::unique_ptr<PresenceSensor> presence;
     boost::asio::posix::stream_descriptor inputDev;
     boost::asio::deadline_timer waitTimer;
diff --git a/include/Utils.hpp b/include/Utils.hpp
index f5f9341..933d5f6 100644
--- a/include/Utils.hpp
+++ b/include/Utils.hpp
@@ -34,7 +34,8 @@
                const std::string& matchString,
                std::vector<std::experimental::filesystem::path>& foundPaths,
                unsigned int symlinkDepth = 1);
-bool isPowerOn(const std::shared_ptr<sdbusplus::asio::connection>& conn);
+bool isPowerOn(void);
+void setupPowerMatch(const std::shared_ptr<sdbusplus::asio::connection>& conn);
 bool getSensorConfiguration(
     const std::string& type,
     const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,