Fix duplicated/missed PSU logs in redfish

When perform disconnect/reconnect PSU actions,
some logs are missing and some are duplicated in redfish,
this change fixes this issue.

Tested:
With two PSUs, perform these actions, then check the redfish event logs:

# remove one AC cable
PowerSupplyPowerLost
PowerSupplyFailed
PowerSupplyFailurePredicted

#One PSU is removed
PowerSupplyConfigurationError
PowerSupplyFanFailed

#Connected the PSU
PowerSupplyConfigurationErrorRecovered
PowerSupplyFanRecovered

#Connected the AC cable
PowerSupplyRecovered
PowerSupplyPredictedFailureRecovered
PowerSupplyPowerRestored

Signed-off-by: Yong Li <yong.b.li@linux.intel.com>
Change-Id: I5cef5f728e99e785113294c931cae6219346653f
diff --git a/src/PSUEvent.cpp b/src/PSUEvent.cpp
index b75a494..8980d53 100644
--- a/src/PSUEvent.cpp
+++ b/src/PSUEvent.cpp
@@ -52,12 +52,13 @@
         std::make_shared<std::set<std::string>>();
     for (const auto& pathList : eventPathList)
     {
+        std::shared_ptr<std::set<std::string>> assert =
+            std::make_shared<std::set<std::string>>();
+
         const std::string& eventName = pathList.first;
         std::string eventPSUName = eventName + psuName;
         for (const auto& path : pathList.second)
         {
-            std::shared_ptr<std::set<std::string>> assert =
-                std::make_shared<std::set<std::string>>();
             std::shared_ptr<bool> state = std::make_shared<bool>(false);
             events[eventPSUName].emplace_back(std::make_unique<PSUSubEvent>(
                 eventInterface, path, io, eventName, assert, combineEvent,
@@ -207,15 +208,16 @@
 {
     if (newValue == 0)
     {
-        auto found = (*asserts).find(path);
-        if (found == (*asserts).end())
-        {
-            return;
-        }
-        (*asserts).erase(path);
-
+        // log deassert only after all asserts are gone
         if (!(*asserts).empty())
         {
+            auto found = (*asserts).find(path);
+            if (found == (*asserts).end())
+            {
+                return;
+            }
+            (*asserts).erase(path);
+
             return;
         }
         if (*assertState == true)
@@ -224,7 +226,6 @@
             auto foundCombine = (*combineEvent).find(eventName);
             if (foundCombine == (*combineEvent).end())
             {
-                value = newValue;
                 return;
             }
             (*combineEvent).erase(eventName);
@@ -236,7 +237,7 @@
                 {
                     sd_journal_send(
                         "MESSAGE=%s", sendMessage.c_str(), "PRIORITY=%i",
-                        LOG_ERR, "REDFISH_MESSAGE_ID=%s",
+                        LOG_INFO, "REDFISH_MESSAGE_ID=%s",
                         deassertMessage.c_str(), "REDFISH_MESSAGE_ARGS=%s,%s",
                         psuName.c_str(), fanName.c_str(), NULL);
                 }
@@ -244,7 +245,7 @@
                 {
                     sd_journal_send(
                         "MESSAGE=%s", sendMessage.c_str(), "PRIORITY=%i",
-                        LOG_ERR, "REDFISH_MESSAGE_ID=%s",
+                        LOG_INFO, "REDFISH_MESSAGE_ID=%s",
                         deassertMessage.c_str(), "REDFISH_MESSAGE_ARGS=%s",
                         psuName.c_str(), NULL);
                 }
@@ -258,16 +259,9 @@
     }
     else
     {
-        (*asserts).emplace(path);
-        if (*assertState == false)
+        if ((*assertState == false) && ((*asserts).empty()))
         {
             *assertState = true;
-            auto foundCombine = (*combineEvent).find(eventName);
-            if (foundCombine != (*combineEvent).end())
-            {
-                value = newValue;
-                return;
-            }
             if (!assertMessage.empty())
             {
                 // Fan Failed has two args
@@ -276,16 +270,17 @@
                 {
                     sd_journal_send(
                         "MESSAGE=%s", sendMessage.c_str(), "PRIORITY=%i",
-                        LOG_ERR, "REDFISH_MESSAGE_ID=%s", assertMessage.c_str(),
-                        "REDFISH_MESSAGE_ARGS=%s,%s", psuName.c_str(),
-                        fanName.c_str(), NULL);
+                        LOG_WARNING, "REDFISH_MESSAGE_ID=%s",
+                        assertMessage.c_str(), "REDFISH_MESSAGE_ARGS=%s,%s",
+                        psuName.c_str(), fanName.c_str(), NULL);
                 }
                 else
                 {
                     sd_journal_send(
                         "MESSAGE=%s", sendMessage.c_str(), "PRIORITY=%i",
-                        LOG_ERR, "REDFISH_MESSAGE_ID=%s", assertMessage.c_str(),
-                        "REDFISH_MESSAGE_ARGS=%s", psuName.c_str(), NULL);
+                        LOG_WARNING, "REDFISH_MESSAGE_ID=%s",
+                        assertMessage.c_str(), "REDFISH_MESSAGE_ARGS=%s",
+                        psuName.c_str(), NULL);
                 }
             }
             if ((*combineEvent).empty())
@@ -294,6 +289,7 @@
             }
             (*combineEvent).emplace(eventName);
         }
+        (*asserts).emplace(path);
     }
     value = newValue;
 }