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/CPUSensor.cpp b/src/CPUSensor.cpp
index afc4706..bf2b6aa 100644
--- a/src/CPUSensor.cpp
+++ b/src/CPUSensor.cpp
@@ -43,11 +43,11 @@
                      bool show, double dtsOffset) :
     Sensor(boost::replace_all_copy(sensorName, " ", "_"),
            std::move(_thresholds), sensorConfiguration, objectType, maxReading,
-           minReading),
+           minReading, PowerState::on),
     objServer(objectServer), inputDev(io, open(path.c_str(), O_RDONLY)),
     waitTimer(io), path(path),
     privTcontrol(std::numeric_limits<double>::quiet_NaN()),
-    dtsOffset(dtsOffset), show(show), errCount(0)
+    dtsOffset(dtsOffset), show(show)
 {
     nameTcontrol = labelTcontrol;
     nameTcontrol += " CPU" + std::to_string(cpuId);
@@ -87,6 +87,8 @@
             setInitialProperties(conn);
         }
     }
+
+    // call setup always as not all sensors call setInitialProperties
     setupPowerMatch(conn);
     setupRead();
 }
@@ -223,52 +225,16 @@
                     }
                 }
             }
-            errCount = 0;
         }
         catch (const std::invalid_argument&)
         {
-            errCount++;
+            incrementError();
         }
     }
     else
     {
         pollTime = sensorFailedPollTimeMs;
-        errCount++;
-    }
-
-    if (errCount >= warnAfterErrorCount)
-    {
-        // only an error if power is on
-        if (isPowerOn())
-        {
-            // only print once
-            if (errCount == warnAfterErrorCount)
-            {
-                std::cerr << "Failure to read sensor " << name << " at " << path
-                          << "\n";
-            }
-            if (show)
-            {
-                updateValue(0);
-            }
-            else
-            {
-                value = 0;
-            }
-            errCount++;
-        }
-        else
-        {
-            errCount = 0; // check power again in 10 cycles
-            if (show)
-            {
-                updateValue(std::numeric_limits<double>::quiet_NaN());
-            }
-            else
-            {
-                value = std::numeric_limits<double>::quiet_NaN();
-            }
-        }
+        incrementError();
     }
 
     responseStream.clear();