Implement de-glitch for temperature fault or warn

If three consecutive reads in a row, one second apart, show the fault
on, create an log an error.

Change-Id: I9fb1285a01e269beffd2201f5082545748f5bee3
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/power-supply/power_supply.cpp b/power-supply/power_supply.cpp
index f0c3089..eb93b91 100644
--- a/power-supply/power_supply.cpp
+++ b/power-supply/power_supply.cpp
@@ -480,34 +480,47 @@
     // logging the over-temperature condition.
     std::uint8_t statusTemperature = 0;
     statusTemperature = pmbusIntf.read(STATUS_TEMPERATURE, Type::Debug);
-    if (((statusWord & status_word::TEMPERATURE_FAULT_WARN) ||
-         (statusTemperature & status_temperature::OT_FAULT)) &&
-        !temperatureFault)
+    if (temperatureFault < FAULT_COUNT)
     {
-        // The power supply has had an over-temperature condition.
-        // This may not result in a shutdown if experienced for a short
-        // duration.
-        // This should not occur under normal conditions.
-        // The power supply may be faulty, or the paired supply may be putting
-        // out less current.
-        // Capture command responses with potentially relevant information,
-        // and call out the power supply reporting the condition.
-        util::NamesValues nv;
-        nv.add("STATUS_WORD", statusWord);
-        captureCmd(nv, STATUS_MFR, Type::Debug);
-        captureCmd(nv, STATUS_IOUT, Type::Debug);
-        nv.add("STATUS_TEMPERATURE", statusTemperature);
-        captureCmd(nv, STATUS_FANS_1_2, Type::Debug);
+        if ((statusWord & status_word::TEMPERATURE_FAULT_WARN) ||
+            (statusTemperature & status_temperature::OT_FAULT))
+        {
+            temperatureFault++;
+        }
+        else
+        {
+            if (temperatureFault > 0)
+            {
+                temperatureFault = 0;
+            }
+        }
 
-        using metadata = org::open_power::Witherspoon::Fault::
-                PowerSupplyTemperatureFault;
+        if (temperatureFault >= FAULT_COUNT)
+        {
+            // The power supply has had an over-temperature condition.
+            // This may not result in a shutdown if experienced for a short
+            // duration.
+            // This should not occur under normal conditions.
+            // The power supply may be faulty, or the paired supply may be
+            // putting out less current.
+            // Capture command responses with potentially relevant information,
+            // and call out the power supply reporting the condition.
+            util::NamesValues nv;
+            nv.add("STATUS_WORD", statusWord);
+            captureCmd(nv, STATUS_MFR, Type::Debug);
+            captureCmd(nv, STATUS_IOUT, Type::Debug);
+            nv.add("STATUS_TEMPERATURE", statusTemperature);
+            captureCmd(nv, STATUS_FANS_1_2, Type::Debug);
 
-        report<PowerSupplyTemperatureFault>(
-                metadata::RAW_STATUS(nv.get().c_str()),
-                metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
+            using metadata = org::open_power::Witherspoon::Fault::
+                    PowerSupplyTemperatureFault;
 
-        faultFound = true;
-        temperatureFault = true;
+            report<PowerSupplyTemperatureFault>(
+                    metadata::RAW_STATUS(nv.get().c_str()),
+                    metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
+
+            faultFound = true;
+        }
     }
 }
 
@@ -519,7 +532,7 @@
     outputOCFault = 0;
     outputOVFault = 0;
     fanFault = 0;
-    temperatureFault = false;
+    temperatureFault = 0;
     faultFound = false;
 
     return;
diff --git a/power-supply/power_supply.hpp b/power-supply/power_supply.hpp
index b6fcc3a..2723bfe 100644
--- a/power-supply/power_supply.hpp
+++ b/power-supply/power_supply.hpp
@@ -190,9 +190,15 @@
         size_t fanFault = 0;
 
         /**
-         * @brief Set to true during a temperature fault or warn condition.
+         * @brief Indicates a temperature fault or warn condition was detected
+         *        if equal to FAULT_COUNT.
+         *
+         * @details This is incremented when the 'TEMPERATURE_FAULT_WARN' bit
+         *          in the STATUS_WORD command response is on, or if the
+         *          'OT_FAULT' bit in the STATUS_TEMPERATURE command response
+         *          is on.
          */
-        bool temperatureFault = false;
+        size_t temperatureFault = 0;
 
         /**
          * @brief Callback for inventory property changes