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/TachSensor.cpp b/src/TachSensor.cpp
index b42062c..132ca69 100644
--- a/src/TachSensor.cpp
+++ b/src/TachSensor.cpp
@@ -43,9 +43,9 @@
     Sensor(boost::replace_all_copy(fanName, " ", "_"), path,
            std::move(_thresholds), sensorConfiguration, objectType,
            limits.second, limits.first),
-    objServer(objectServer), dbusConnection(conn),
-    presence(std::move(presence)), redundancy(redundancy),
-    inputDev(io, open(path.c_str(), O_RDONLY)), waitTimer(io), errCount(0)
+    objServer(objectServer), presence(std::move(presence)),
+    redundancy(redundancy), inputDev(io, open(path.c_str(), O_RDONLY)),
+    waitTimer(io), errCount(0)
 {
     sensorInterface = objectServer.add_interface(
         "/xyz/openbmc_project/sensors/fan_tach/" + name,
@@ -64,7 +64,7 @@
             "xyz.openbmc_project.Sensor.Threshold.Critical");
     }
     setInitialProperties(conn);
-    isPowerOn(dbusConnection); // first call initializes
+    setupPowerMatch(conn); // first call initializes
     setupRead();
 }
 
@@ -131,28 +131,27 @@
         }
         else
         {
-            pollTime = sensorFailedPollTimeMs;
-            errCount++;
-        }
-        if (errCount >= warnAfterErrorCount)
-        {
-            // only an error if power is on
-            if (isPowerOn(dbusConnection))
+            if (!isPowerOn())
             {
-                // only print once
-                if (errCount == warnAfterErrorCount)
-                {
-                    std::cerr << "Failure to read sensor " << name << " at "
-                              << path << " ec:" << err << "\n";
-                }
-                updateValue(0);
+                errCount = 0;
+                updateValue(std::numeric_limits<double>::quiet_NaN());
             }
             else
             {
-                errCount = 0; // check power again in 10 cycles
-                updateValue(std::numeric_limits<double>::quiet_NaN());
+                pollTime = sensorFailedPollTimeMs;
+                errCount++;
             }
         }
+        if (errCount >= warnAfterErrorCount)
+        {
+            // only print once
+            if (errCount == warnAfterErrorCount)
+            {
+                std::cerr << "Failure to read sensor " << name << " at " << path
+                          << " ec:" << err << "\n";
+            }
+            updateValue(0);
+        }
     }
     responseStream.clear();
     inputDev.close();