Standardize read errors

Each sensor handled read errors their own way,
making it inconsistant. This helps to align them all
in the base class, so that error handling happens the
same for each sensor. It also aligns the power state
change handling.

Tested: Tested DC Cycling and Enabling/Disabling ME to
make sure functional change correctly

Change-Id: I1a191d27629602e1ca3871d933af07b15bf9f331
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/src/TachSensor.cpp b/src/TachSensor.cpp
index c45fcb0..953f26c 100644
--- a/src/TachSensor.cpp
+++ b/src/TachSensor.cpp
@@ -51,11 +51,11 @@
                        const std::string& sensorConfiguration,
                        const std::pair<size_t, size_t>& limits) :
     Sensor(boost::replace_all_copy(fanName, " ", "_"), std::move(_thresholds),
-           sensorConfiguration, objectType, limits.second, limits.first),
+           sensorConfiguration, objectType, limits.second, limits.first,
+           PowerState::on),
     objServer(objectServer), redundancy(redundancy),
     presence(std::move(presenceSensor)),
-    inputDev(io, open(path.c_str(), O_RDONLY)), waitTimer(io), path(path),
-    errCount(0)
+    inputDev(io, open(path.c_str(), O_RDONLY)), waitTimer(io), path(path)
 {
     sensorInterface = objectServer.add_interface(
         "/xyz/openbmc_project/sensors/fan_tach/" + name,
@@ -96,7 +96,6 @@
         itemAssoc->initialize();
     }
     setInitialProperties(conn);
-    setupPowerMatch(conn);
     setupRead();
 }
 
@@ -133,7 +132,7 @@
     {
         if (!presence->getValue())
         {
-            updateValue(std::numeric_limits<double>::quiet_NaN());
+            markAvailable(false);
             missing = true;
             pollTime = sensorFailedPollTimeMs;
         }
@@ -151,35 +150,17 @@
                 double nvalue = std::stod(response);
                 responseStream.clear();
                 updateValue(nvalue);
-                errCount = 0;
             }
             catch (const std::invalid_argument&)
             {
-                errCount++;
+                incrementError();
+                pollTime = sensorFailedPollTimeMs;
             }
         }
         else
         {
-            if (!isPowerOn())
-            {
-                errCount = 0;
-                updateValue(std::numeric_limits<double>::quiet_NaN());
-            }
-            else
-            {
-                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);
+            incrementError();
+            pollTime = sensorFailedPollTimeMs;
         }
     }
     responseStream.clear();
@@ -202,11 +183,6 @@
 
 void TachSensor::checkThresholds(void)
 {
-    if (!isPowerOn())
-    {
-        return;
-    }
-
     bool status = thresholds::checkThresholds(this);
 
     if (redundancy && *redundancy)