Add Item Iface to Track Fan Presence

Item iface has a present bit that phosphor-fan-presence
uses to track presence. Algin to this so we can add it
to redfish.

Tested: Pulled fan and correct bit changed to false

Change-Id: I5bfb5d97b8ad7a4d582b3e41b0f14007cdd88b51
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/include/TachSensor.hpp b/include/TachSensor.hpp
index 2ef1298..c6f255f 100644
--- a/include/TachSensor.hpp
+++ b/include/TachSensor.hpp
@@ -62,6 +62,7 @@
     sdbusplus::asio::object_server& objServer;
     std::shared_ptr<RedundancySensor> redundancy;
     std::unique_ptr<PresenceSensor> presence;
+    std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface;
     boost::asio::posix::stream_descriptor inputDev;
     boost::asio::deadline_timer waitTimer;
     boost::asio::streambuf readBuf;
diff --git a/src/TachSensor.cpp b/src/TachSensor.cpp
index ae27a04..36b5ecf 100644
--- a/src/TachSensor.cpp
+++ b/src/TachSensor.cpp
@@ -34,7 +34,7 @@
 TachSensor::TachSensor(const std::string& path, const std::string& objectType,
                        sdbusplus::asio::object_server& objectServer,
                        std::shared_ptr<sdbusplus::asio::connection>& conn,
-                       std::unique_ptr<PresenceSensor>&& presence,
+                       std::unique_ptr<PresenceSensor>&& presenceSensor,
                        const std::shared_ptr<RedundancySensor>& redundancy,
                        boost::asio::io_service& io, const std::string& fanName,
                        std::vector<thresholds::Threshold>&& _thresholds,
@@ -43,7 +43,7 @@
     Sensor(boost::replace_all_copy(fanName, " ", "_"), path,
            std::move(_thresholds), sensorConfiguration, objectType,
            limits.second, limits.first),
-    objServer(objectServer), presence(std::move(presence)),
+    objServer(objectServer), presence(std::move(presenceSensor)),
     redundancy(redundancy), inputDev(io, open(path.c_str(), O_RDONLY)),
     waitTimer(io), errCount(0)
 {
@@ -66,6 +66,17 @@
     association = objectServer.add_interface(
         "/xyz/openbmc_project/sensors/fan_tach/" + name,
         "org.openbmc.Associations");
+
+    if (presence)
+    {
+        itemIface =
+            objectServer.add_interface("/xyz/openbmc_project/Inventory/" + name,
+                                       "xyz.openbmc_project.Inventory.Item");
+        itemIface->register_property("PrettyName",
+                                     std::string()); // unused property
+        itemIface->register_property("Present", true);
+        itemIface->initialize();
+    }
     setInitialProperties(conn);
     setupPowerMatch(conn);
     setupRead();
@@ -80,6 +91,7 @@
     objServer.remove_interface(thresholdInterfaceCritical);
     objServer.remove_interface(sensorInterface);
     objServer.remove_interface(association);
+    objServer.remove_interface(itemIface);
 }
 
 void TachSensor::setupRead(void)
@@ -106,6 +118,7 @@
             missing = true;
             pollTime = sensorFailedPollTimeMs;
         }
+        itemIface->set_property("Present", !missing);
     }
     std::istream responseStream(&readBuf);
     if (!missing)