sensor-cache: Implement inventory::get::assertion()

Implement inventory::get::assertion() similar to get::assertion().
Not tested as we do not use this function.

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: Iaee109cee4cb947878733a617a466f499fab3e7c
diff --git a/sensordatahandler.cpp b/sensordatahandler.cpp
index ef18a8f..d502268 100644
--- a/sensordatahandler.cpp
+++ b/sensordatahandler.cpp
@@ -459,6 +459,8 @@
 namespace get
 {
 
+#ifndef FEATURE_SENSORS_CACHE
+
 GetSensorResponse assertion(const Info& sensorInfo)
 {
     namespace fs = std::filesystem;
@@ -471,6 +473,45 @@
         sensorInfo.propertyInterfaces.begin()->first);
 }
 
+#else
+
+std::optional<GetSensorResponse> assertion(uint8_t id, const Info& sensorInfo,
+                                           sdbusplus::message::message& msg)
+{
+    auto type = msg.get_type();
+    if (type == msgTypeSignal)
+    {
+        // This is signal callback
+        std::string interfaceName;
+        msg.read(interfaceName);
+        if (interfaceName != sensorInfo.sensorInterface)
+        {
+            // Not the interface we need
+            return {};
+        }
+    }
+
+    // The assertion may contain multiple properties
+    // So we have to get the properties from DBus anyway
+    namespace fs = std::filesystem;
+
+    fs::path path{ipmi::sensor::inventoryRoot};
+    path += sensorInfo.sensorPath;
+
+    auto response = ipmi::sensor::get::mapDbusToAssertion(
+        sensorInfo, path.string(),
+        sensorInfo.propertyInterfaces.begin()->first);
+
+    if (!sensorCacheMap[id].has_value())
+    {
+        sensorCacheMap[id] = SensorData{};
+    }
+    sensorCacheMap[id]->response = response;
+    return response;
+}
+
+#endif
+
 } // namespace get
 
 } // namespace inventory
diff --git a/sensordatahandler.hpp b/sensordatahandler.hpp
index 9084b7a..6768634 100644
--- a/sensordatahandler.hpp
+++ b/sensordatahandler.hpp
@@ -699,6 +699,8 @@
 namespace get
 {
 
+#ifndef FEATURE_SENSORS_CACHE
+
 /**
  *  @brief Map the Dbus info to sensor's assertion status in the Get sensor
  *         reading command response.
@@ -709,6 +711,23 @@
  */
 GetSensorResponse assertion(const Info& sensorInfo);
 
+#else
+
+/**
+ *  @brief Map the Dbus info to sensor's assertion status in the Get sensor
+ *         reading command response.
+ *
+ *  @param[in] id - The sensor id
+ *  @param[in] sensorInfo - Dbus info related to sensor.
+ *  @param[in] msg - Dbus message from match callback.
+ *
+ *  @return Response for get sensor reading command.
+ */
+std::optional<GetSensorResponse> assertion(uint8_t id, const Info& sensorInfo,
+                                           sdbusplus::message::message& msg);
+
+#endif
+
 } // namespace get
 
 } // namespace inventory