NVMeBasicContext: Defer polling sensors that are in error

A sensor is only polled after N sampling periods if it is in error. This
necessitates the movement of some of the error handling so we can
increment the sensor's error counter as appropriate.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ie19f6ceb7ad8f9b2f1408a4ca8f12c0ca385ce8c
diff --git a/src/NVMeSensor.cpp b/src/NVMeSensor.cpp
index d293737..213e320 100644
--- a/src/NVMeSensor.cpp
+++ b/src/NVMeSensor.cpp
@@ -31,7 +31,7 @@
     Sensor(escapeName(sensorName), std::move(thresholdsIn), sensorConfiguration,
            NVMeSensor::configType, false, false, maxReading, minReading, conn,
            PowerState::on),
-    bus(busNumber), objServer(objectServer)
+    bus(busNumber), objServer(objectServer), scanDelay(0)
 {
     if (bus < 0)
     {
@@ -67,6 +67,21 @@
     objServer.remove_interface(association);
 }
 
+bool NVMeSensor::sample()
+{
+    if (inError())
+    {
+        if (scanDelay == 0)
+        {
+            scanDelay = scanDelayTicks;
+        }
+
+        scanDelay--;
+    }
+
+    return scanDelay == 0;
+}
+
 void NVMeSensor::checkThresholds(void)
 {
     thresholds::checkThresholds(this);