sensordatahandler: Throw on sensor's OperationalStatus

Add UPDATE_FUNCTIONAL_ON_FAIL and only when defined, read sensor's
OperationalStatus interface for the functional property and throw if the
sensor is not funcitonal.

Bug: openbmc/phosphor-hwmon#10
Signed-off-by: Brandon Kim <brandonkim@google.com>
Change-Id: I1144a6d3f8145bda73f3363664ca48b848a295db
diff --git a/sensordatahandler.hpp b/sensordatahandler.hpp
index 73f0dbf..129cbb4 100644
--- a/sensordatahandler.hpp
+++ b/sensordatahandler.hpp
@@ -1,5 +1,7 @@
 #pragma once
 
+#include "config.h"
+
 #include "sensorhandler.hpp"
 
 #include <cmath>
@@ -190,6 +192,32 @@
     auto service = ipmi::getService(bus, sensorInfo.sensorInterface,
                                     sensorInfo.sensorPath);
 
+#ifdef UPDATE_FUNCTIONAL_ON_FAIL
+    // Check the OperationalStatus interface for functional property
+    if (sensorInfo.propertyInterfaces.begin()->first ==
+        "xyz.openbmc_project.Sensor.Value")
+    {
+        bool functional = true;
+        try
+        {
+            auto funcValue = ipmi::getDbusProperty(
+                bus, service, sensorInfo.sensorPath,
+                "xyz.openbmc_project.State.Decorator.OperationalStatus",
+                "Functional");
+            functional = std::get<bool>(funcValue);
+        }
+        catch (...)
+        {
+            // No-op if Functional property could not be found since this
+            // check is only valid for Sensor.Value read for hwmonio
+        }
+        if (!functional)
+        {
+            throw SensorFunctionalError();
+        }
+    }
+#endif
+
     auto propValue = ipmi::getDbusProperty(
         bus, service, sensorInfo.sensorPath,
         sensorInfo.propertyInterfaces.begin()->first,