config: allow led priority to be Off

This makes the configuration more flexible and eliminates the edge case.

I don't see why this should not be possible.

Change-Id: I28e33535539b3214e18d7816314656df5d3c370e
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/README.md b/README.md
index 7e88e39..68b2270 100644
--- a/README.md
+++ b/README.md
@@ -12,8 +12,8 @@
 
 ### Configuration: LED Priority
 
-Each LED can have "Priority" as "Blink" or "On". If this property is defined, it
-should be defined on each instance of the LED in the config.
+Each LED can have "Priority" as "Blink", "Off" or "On". If this property is
+defined, it should be defined on each instance of the LED in the config.
 
 When multiple LED groups are asserted and contain the same LED, "Priority"
 determines the state of the LED.
diff --git a/manager/json-parser.hpp b/manager/json-parser.hpp
index e17568b..8f2832b 100644
--- a/manager/json-parser.hpp
+++ b/manager/json-parser.hpp
@@ -18,7 +18,6 @@
 using Json = nlohmann::json;
 
 // Priority for a particular LED needs to stay SAME across all groups
-// phosphor::led::Layout::Action can only be one of `Blink` and `On`
 using PriorityMap =
     std::unordered_map<std::string,
                        std::optional<phosphor::led::Layout::Action>>;
@@ -56,14 +55,25 @@
  *
  *  @param[in] action - action string
  *
- *  @return Action - action enum (On/Blink)
+ *  @return Action - action enum (On/Off/Blink)
  */
 phosphor::led::Layout::Action getAction(const std::string& action)
 {
-    assert(action == "On" || action == "Blink");
+    if (action == "On")
+    {
+        return phosphor::led::Layout::Action::On;
+    }
+    if (action == "Off")
+    {
+        return phosphor::led::Layout::Action::Off;
+    }
+    if (action == "Blink")
+    {
+        return phosphor::led::Layout::Action::Blink;
+    }
 
-    return action == "Blink" ? phosphor::led::Layout::Action::Blink
-                             : phosphor::led::Layout::Action::On;
+    assert(false);
+    return phosphor::led::Layout::Action::Blink;
 }
 
 static std::string priorityToString(
diff --git a/test/config/led-group-config.json b/test/config/led-group-config.json
index dcdd93f..0a4ccb9 100644
--- a/test/config/led-group-config.json
+++ b/test/config/led-group-config.json
@@ -20,6 +20,16 @@
             ]
         },
         {
+            "group": "power_off",
+            "members": [
+                {
+                    "Name": "power_off_led",
+                    "Action": "Off",
+                    "Priority": "Off"
+                }
+            ]
+        },
+        {
             "group": "enclosure_identify",
             "members": [
                 {
diff --git a/test/utest-led-json.cpp b/test/utest-led-json.cpp
index afd4505..fa9161b 100644
--- a/test/utest-led-json.cpp
+++ b/test/utest-led-json.cpp
@@ -10,14 +10,17 @@
     std::string objPath = "/xyz/openbmc_project/led/groups";
     std::string bmcBooted = objPath + "/bmc_booted";
     std::string powerOn = objPath + "/power_on";
+    std::string powerOff = objPath + "/power_off";
     std::string enclosureIdentify = objPath + "/enclosure_identify";
 
     ASSERT_EQ(ledMap.contains(bmcBooted), true);
     ASSERT_EQ(ledMap.contains(powerOn), true);
+    ASSERT_EQ(ledMap.contains(powerOff), true);
     ASSERT_EQ(ledMap.contains(enclosureIdentify), true);
 
     auto& bmcBootedActions = ledMap.at(bmcBooted).actionSet;
     auto& powerOnActions = ledMap.at(powerOn).actionSet;
+    auto& powerOffActions = ledMap.at(powerOff).actionSet;
     auto& enclosureIdentifyActions = ledMap.at(enclosureIdentify).actionSet;
 
     for (const auto& group : bmcBootedActions)
@@ -37,6 +40,12 @@
         ASSERT_EQ(group.period, 0);
         ASSERT_EQ(group.priority, phosphor::led::Layout::Action::On);
     }
+    for (const auto& group : powerOffActions)
+    {
+        ASSERT_EQ(group.name, "power_off_led");
+        ASSERT_EQ(group.action, phosphor::led::Layout::Action::Off);
+        ASSERT_EQ(group.priority, phosphor::led::Layout::Action::Off);
+    }
 
     for (const auto& group : enclosureIdentifyActions)
     {