PEL: LightPath: Assert LED groups

Fill in the functions to get the LED group D-Bus paths corresponding to
the called out location codes, and then set the Asserted property on
that path to turn on the LEDs.

If there are any problems looking up any of the LED groups, then do not
turn on any LEDs at all, even if others were OK.  In this case, the
system attention indicator will be turned on instead.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I7e3ee6259d972dd2c6939c5a1004c6d25c40e38a
diff --git a/extensions/openpower-pels/data_interface.cpp b/extensions/openpower-pels/data_interface.cpp
index c57593d..4cad337 100644
--- a/extensions/openpower-pels/data_interface.cpp
+++ b/extensions/openpower-pels/data_interface.cpp
@@ -31,6 +31,7 @@
 {
 constexpr auto objectMapper = "xyz.openbmc_project.ObjectMapper";
 constexpr auto vpdManager = "com.ibm.VPD.Manager";
+constexpr auto ledGroupManager = "xyz.openbmc_project.LED.GroupManager";
 } // namespace service_name
 
 namespace object_path
@@ -66,6 +67,8 @@
 constexpr auto invCompatible =
     "xyz.openbmc_project.Inventory.Decorator.Compatible";
 constexpr auto vpdManager = "com.ibm.VPD.Manager";
+constexpr auto association = "xyz.openbmc_project.Association";
+constexpr auto ledGroup = "xyz.openbmc_project.Led.Group";
 } // namespace interface
 
 using namespace sdbusplus::xyz::openbmc_project::State::OperatingSystem::server;
@@ -412,5 +415,34 @@
     return shortest;
 }
 
+std::string
+    DataInterface::getFaultLEDGroup(const std::string& inventoryPath) const
+{
+    auto associationPath = inventoryPath + "/" + "fault_led_group";
+    auto service = getService(associationPath, interface::association);
+
+    DBusValue endpoints;
+    getProperty(service, associationPath, interface::association, "endpoints",
+                endpoints);
+    auto paths = std::get<std::vector<std::string>>(endpoints);
+    if (paths.empty())
+    {
+        throw std::runtime_error("Association endpoints property empty");
+    }
+
+    return paths[0];
+}
+
+void DataInterface::assertLEDGroup(const std::string& ledGroup,
+                                   bool value) const
+{
+    DBusValue variant = value;
+    auto method =
+        _bus.new_method_call(service_name::ledGroupManager, ledGroup.c_str(),
+                             interface::dbusProperty, "Set");
+    method.append(interface::ledGroup, "Asserted", variant);
+    _bus.call(method);
+}
+
 } // namespace pels
 } // namespace openpower