Fixed issue with displaying empty triggers

It was not possible to display empty triggers due to one of the property
handlers returning error. This fixes handlers and proper value is
returned instead.

Tested:
- All unit tests are passing.
- Can introspect empty triggers
- Empty triggers are correctly listed in redfish

Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Change-Id: I1ce9a9a43faac5446911f0e44c638b4ca91adb82
diff --git a/src/trigger.cpp b/src/trigger.cpp
index 6982267..485f2f9 100644
--- a/src/trigger.cpp
+++ b/src/trigger.cpp
@@ -81,10 +81,7 @@
                     return 1;
                 },
                 [this](const auto&) {
-                    return fromLabeledThresholdParam(
-                        utils::transform(thresholds, [](const auto& threshold) {
-                            return threshold->getThresholdParam();
-                        }));
+                    return fromLabeledThresholdParam(getLabeledThresholds());
                 });
 
             dbusIface.register_property_rw(
@@ -103,13 +100,11 @@
                 },
                 [this](const auto&) {
                     return utils::fromLabeledSensorsInfo(
-                        utils::transform(sensors, [](const auto& sensor) {
-                            return sensor->getLabeledSensorInfo();
-                        }));
+                        getLabeledSensorInfo());
                 });
 
             dbusIface.register_property_rw(
-                "ReportNames", std::vector<std::string>{},
+                "ReportNames", *reportIds,
                 sdbusplus::vtable::property_::emits_change,
                 [this](auto newVal, auto& oldVal) {
                     TriggerManager::verifyReportIds(newVal);
@@ -122,16 +117,11 @@
                 [this](const auto&) { return *reportIds; });
 
             dbusIface.register_property_r(
-                "Discrete", false, sdbusplus::vtable::property_::const_,
-                [this](const auto& x) {
-                    return !std::holds_alternative<
-                        numeric::LabeledThresholdParam>(
-                        thresholds.back()->getThresholdParam());
-                });
+                "Discrete", isDiscreate(), sdbusplus::vtable::property_::const_,
+                [this](const auto& x) { return isDiscreate(); });
 
             dbusIface.register_property_rw(
-                "Name", std::string(),
-                sdbusplus::vtable::property_::emits_change,
+                "Name", name, sdbusplus::vtable::property_::emits_change,
                 [this](auto newVal, auto& oldVal) {
                     name = oldVal = newVal;
                     return 1;
@@ -173,10 +163,7 @@
 
         auto labeledThresholdParams =
             std::visit(utils::ToLabeledThresholdParamConversion(),
-                       fromLabeledThresholdParam(utils::transform(
-                           thresholds, [](const auto& threshold) {
-                               return threshold->getThresholdParam();
-                           })));
+                       fromLabeledThresholdParam(getLabeledThresholds()));
 
         data["Version"] = triggerVersion;
         data["Id"] = id;
@@ -189,9 +176,7 @@
         data["ThresholdParams"] =
             utils::labeledThresholdParamsToJson(labeledThresholdParams);
         data["ReportIds"] = *reportIds;
-        data["Sensors"] = utils::transform(sensors, [](const auto& sensor) {
-            return sensor->getLabeledSensorInfo();
-        });
+        data["Sensors"] = getLabeledSensorInfo();
 
         triggerStorage.store(fileName, data);
     }
@@ -204,3 +189,26 @@
     }
     return true;
 }
+
+std::vector<LabeledSensorInfo> Trigger::getLabeledSensorInfo() const
+{
+    return utils::transform(sensors, [](const auto& sensor) {
+        return sensor->getLabeledSensorInfo();
+    });
+}
+
+std::vector<LabeledThresholdParam> Trigger::getLabeledThresholds() const
+{
+    return utils::transform(thresholds, [](const auto& threshold) {
+        return threshold->getThresholdParam();
+    });
+}
+
+bool Trigger::isDiscreate() const
+{
+    const auto labeledThresholds = getLabeledThresholds();
+
+    return utils::isFirstElementOfType<std::monostate>(labeledThresholds) ||
+           utils::isFirstElementOfType<discrete::LabeledThresholdParam>(
+               labeledThresholds);
+}