ensure power status is always correct

There's a slight bug here in that anytime determineStatusOfPower() is
called, the PowerStatus was set to Good for a period of time. This can
cause confusion on clients monitoring the property. Instead of
defaulting it to good, set it after the true status is known.

Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: If48eb5bd1c2bd94d51d12aff54a186aba295b179
diff --git a/chassis_state_manager.cpp b/chassis_state_manager.cpp
index d526358..3989bca 100644
--- a/chassis_state_manager.cpp
+++ b/chassis_state_manager.cpp
@@ -203,19 +203,21 @@
 
 void Chassis::determineStatusOfPower()
 {
-    // Default PowerStatus to good
-    server::Chassis::currentPowerStatus(PowerStatus::Good);
-
-    determineStatusOfUPSPower();
-    if (server::Chassis::currentPowerStatus() != PowerStatus::Good)
+    bool powerGood = determineStatusOfUPSPower();
+    if (!powerGood)
     {
         return;
     }
 
-    determineStatusOfPSUPower();
+    powerGood = determineStatusOfPSUPower();
+    if (powerGood)
+    {
+        // All checks passed, set power status to good
+        server::Chassis::currentPowerStatus(PowerStatus::Good);
+    }
 }
 
-void Chassis::determineStatusOfUPSPower()
+bool Chassis::determineStatusOfUPSPower()
 {
     // Find all implementations of the UPower interface
     auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
@@ -288,7 +290,7 @@
                          std::get<uint>(properties["State"]));
                     server::Chassis::currentPowerStatus(
                         PowerStatus::UninterruptiblePowerSupply);
-                    return;
+                    return false;
                 }
 
                 if (std::get<uint>(properties["BatteryLevel"]) ==
@@ -297,7 +299,7 @@
                     info("UPS Battery Level is Full");
                     // Only one UPS per system, we've found it and it's all
                     // good so exit function
-                    return;
+                    return true;
                 }
                 else
                 {
@@ -306,7 +308,7 @@
                          std::get<uint>(properties["BatteryLevel"]));
                     server::Chassis::currentPowerStatus(
                         PowerStatus::UninterruptiblePowerSupply);
-                    return;
+                    return false;
                 }
             }
             catch (const sdbusplus::exception::exception& e)
@@ -318,10 +320,10 @@
             }
         }
     }
-    return;
+    return true;
 }
 
-void Chassis::determineStatusOfPSUPower()
+bool Chassis::determineStatusOfPSUPower()
 {
     // Find all implementations of the PowerSystemInputs interface
     auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
@@ -372,7 +374,7 @@
                 {
                     info("Power System Inputs status is in Fault state");
                     server::Chassis::currentPowerStatus(PowerStatus::BrownOut);
-                    return;
+                    return false;
                 }
             }
             catch (const sdbusplus::exception::exception& e)
@@ -385,7 +387,7 @@
             }
         }
     }
-    return;
+    return true;
 }
 
 void Chassis::uPowerChangeEvent(sdbusplus::message::message& msg)