psu-ng: Updates to allow PSU missing on startup

If the power supply is missing when the application starts up, the
created PMBus interface will log an INFO message about being unable to
read any of the sysfs files. Allow that informational message to occur,
but in the inventoryChange() interface, when the power supply goes
present, be sure to call the findHwmonDir() function to update the
directory/file changes that may occur when the device driver binds.

Tested:
    Use simulator to verify no changes when both present and chassison.
    Use simulator to mark 2nd PSU missing, restart application, mark 2nd
    PSU as present and verify no PSU communication problems.
    Use simulator to mark 1st PSU missing, restart application, mark 1st
    PSU present and verify no PSU communication problems.
    Use simulator to chassison with PSU missing, then change PSU
    present, verify no errors.
    Use simulator to chassison with PSUs present, mark PSU missing, then
    PSU present, verify no errors.

Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
Change-Id: Iba1c8296167519e7285eb680ab067bfb6046b4c7
diff --git a/phosphor-power-supply/power_supply.cpp b/phosphor-power-supply/power_supply.cpp
index 0d63ca2..82bd9aa 100644
--- a/phosphor-power-supply/power_supply.cpp
+++ b/phosphor-power-supply/power_supply.cpp
@@ -128,13 +128,6 @@
 
 void PowerSupply::clearFaults()
 {
-    faultFound = false;
-    inputFault = false;
-    mfrFault = false;
-    vinUVFault = false;
-    readFail = 0;
-    faultLogged = false;
-
     // The PMBus device driver does not allow for writing CLEAR_FAULTS
     // directly. However, the pmbus hwmon device driver code will send a
     // CLEAR_FAULTS after reading from any of the hwmon "files" in sysfs, so
@@ -143,6 +136,13 @@
     // I do not care what the return value is.
     if (present)
     {
+        faultFound = false;
+        inputFault = false;
+        mfrFault = false;
+        vinUVFault = false;
+        readFail = 0;
+        faultLogged = false;
+
         try
         {
             static_cast<void>(
@@ -175,6 +175,7 @@
             // or write failures.
             using namespace std::chrono_literals;
             std::this_thread::sleep_for(20ms);
+            pmbusIntf->findHwmonDir();
             onOffConfig(phosphor::pmbus::ON_OFF_CONFIG_CONTROL_PIN_ONLY);
             clearFaults();
             updateInventory();
diff --git a/phosphor-power-supply/power_supply.hpp b/phosphor-power-supply/power_supply.hpp
index 757171d..a73e14e 100644
--- a/phosphor-power-supply/power_supply.hpp
+++ b/phosphor-power-supply/power_supply.hpp
@@ -236,7 +236,7 @@
     /** @brief systemd bus member */
     sdbusplus::bus::bus& bus;
 
-    /** @brief Will be updated to the latest/lastvalue read from STATUS_WORD. */
+    /** @brief Will be updated to the latest/lastvalue read from STATUS_WORD.*/
     uint64_t statusWord = 0;
 
     /** @brief True if a fault has already been found and not cleared */
@@ -280,7 +280,7 @@
      *
      * Used to read or write to/from PMBus power supply devices.
      */
-    std::unique_ptr<phosphor::pmbus::PMBusBase> pmbusIntf;
+    std::unique_ptr<phosphor::pmbus::PMBusBase> pmbusIntf = nullptr;
 
     /** @brief Stored copy of the firmware version/revision string */
     std::string fwVersion;
diff --git a/phosphor-power-supply/test/mock.hpp b/phosphor-power-supply/test/mock.hpp
index 02e3947..f99b33f 100644
--- a/phosphor-power-supply/test/mock.hpp
+++ b/phosphor-power-supply/test/mock.hpp
@@ -22,6 +22,7 @@
     MOCK_METHOD(void, writeBinary,
                 (const std::string& name, std::vector<uint8_t> data, Type type),
                 (override));
+    MOCK_METHOD(void, findHwmonDir, (), (override));
     MOCK_METHOD(const fs::path&, path, (), (const, override));
 };
 } // namespace pmbus
diff --git a/pmbus.hpp b/pmbus.hpp
index 6f5b91f..ea2b297 100644
--- a/pmbus.hpp
+++ b/pmbus.hpp
@@ -145,6 +145,7 @@
     virtual std::string readString(const std::string& name, Type type) = 0;
     virtual void writeBinary(const std::string& name, std::vector<uint8_t> data,
                              Type type) = 0;
+    virtual void findHwmonDir() = 0;
     virtual const fs::path& path() const = 0;
 };
 
@@ -334,7 +335,7 @@
      * Finds the path relative to basePath to the hwmon directory
      * for the device and stores it in hwmonRelPath.
      */
-    void findHwmonDir();
+    void findHwmonDir() override;
 
     /**
      * Returns the path to use for the passed in type.