regulators: Implements support for presence_detection

Enhance the configuration file parser to support the
presence_detection element.

Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I40ed2e849b6baaebdfd1899000fc389429d46543
diff --git a/phosphor-regulators/src/config_file_parser.cpp b/phosphor-regulators/src/config_file_parser.cpp
index 9615d31..14bf942 100644
--- a/phosphor-regulators/src/config_file_parser.cpp
+++ b/phosphor-regulators/src/config_file_parser.cpp
@@ -299,14 +299,13 @@
     ++propertyCount;
 
     // Optional presence_detection property
-    // TODO: Not implemented yet
     std::unique_ptr<PresenceDetection> presenceDetection{};
-    // auto presenceDetectionIt = element.find("presence_detection");
-    // if (presenceDetectionIt != element.end())
-    // {
-    //     presenceDetection = parsePresenceDetection(*presenceDetectionIt);
-    //     ++propertyCount;
-    // }
+    auto presenceDetectionIt = element.find("presence_detection");
+    if (presenceDetectionIt != element.end())
+    {
+        presenceDetection = parsePresenceDetection(*presenceDetectionIt);
+        ++propertyCount;
+    }
 
     // Optional configuration property
     std::unique_ptr<Configuration> configuration{};
@@ -679,6 +678,28 @@
                                                          exponent, isVerified);
 }
 
+std::unique_ptr<PresenceDetection> parsePresenceDetection(const json& element)
+{
+    verifyIsObject(element);
+    unsigned int propertyCount{0};
+
+    // Optional comments property; value not stored
+    if (element.contains("comments"))
+    {
+        ++propertyCount;
+    }
+
+    // Required rule_id or actions property
+    std::vector<std::unique_ptr<Action>> actions{};
+    actions = parseRuleIDOrActionsProperty(element);
+    ++propertyCount;
+
+    // Verify no invalid properties exist
+    verifyPropertyCount(element, propertyCount);
+
+    return std::make_unique<PresenceDetection>(std::move(actions));
+}
+
 std::unique_ptr<Rail> parseRail(const json& element)
 {
     verifyIsObject(element);