Parse I2C bus and address out of JSON config file

The I2C bus and address need to be passed down to the PowerSupply
constructor, so get those out of the JSON configuration file now.

Change I2C address format in JSON to be a string, without the
hexadecimal format since it needs to be appended to a string, allowing
to skip conversion from string to number and then from number back to
string.

Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
Change-Id: I2707799bb60d1f4a9783a0403bc3e4920461b7a1
diff --git a/phosphor-power-supply/configurations/witherspoon/psu_config.json b/phosphor-power-supply/configurations/witherspoon/psu_config.json
index 6724ab0..eaa57aa 100644
--- a/phosphor-power-supply/configurations/witherspoon/psu_config.json
+++ b/phosphor-power-supply/configurations/witherspoon/psu_config.json
@@ -8,12 +8,12 @@
         {
             "Inventory" : "/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply0",
             "Bus" : 3,
-            "Address" : "0x68"
+            "Address" : "0068"
         },
         {
             "Inventory" : "/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply1",
             "Bus" : 3,
-            "Address" : "0x69"
+            "Address" : "0069"
         }
     ]
 }
diff --git a/phosphor-power-supply/power_supply.hpp b/phosphor-power-supply/power_supply.hpp
index e5c1e76..419e1a7 100644
--- a/phosphor-power-supply/power_supply.hpp
+++ b/phosphor-power-supply/power_supply.hpp
@@ -21,10 +21,14 @@
     ~PowerSupply() = default;
 
     /**
-     * @param[in] invpath - string for inventory path to use
+     * @param[in] invpath - String for inventory path to use
+     * @param[in] i2cbus - The bus number this power supply is on
+     * @param[in] i2caddr - The 16-bit I2C address of the power supply
      */
-    PowerSupply(sdbusplus::bus::bus& bus, const std::string& invpath) :
-        bus(bus), inventoryPath(invpath)
+    PowerSupply(sdbusplus::bus::bus& bus, const std::string& invpath,
+                std::uint8_t i2cbus, const std::string& i2caddr) :
+        bus(bus),
+        inventoryPath(invpath), i2cbus(i2cbus), i2caddr(i2caddr)
     {
         // Setup the functions to call when the D-Bus inventory path for the
         // Present property changes.
@@ -104,6 +108,19 @@
      **/
     std::string inventoryPath;
 
+    /**
+     * @brief I2C bus that this power supply is on.
+     */
+    std::uint8_t i2cbus;
+
+    /**
+     * @brief I2C address of this power supply.
+     *
+     * The PMBus device driver will put this in a path with 16-bit address,
+     * represented as a file path string.
+     */
+    std::string i2caddr;
+
     /** @brief True if the power supply is present. */
     bool present = false;
 
diff --git a/phosphor-power-supply/psu_manager.cpp b/phosphor-power-supply/psu_manager.cpp
index 922d555..9880b08 100644
--- a/phosphor-power-supply/psu_manager.cpp
+++ b/phosphor-power-supply/psu_manager.cpp
@@ -88,12 +88,20 @@
 
     for (auto psuJSON : configFileJSON["PowerSupplies"])
     {
-        if (psuJSON.contains("Inventory"))
+        if (psuJSON.contains("Inventory") && psuJSON.contains("Bus") &&
+            psuJSON.contains("Address"))
         {
             std::string invpath = psuJSON["Inventory"];
-            auto psu = std::make_unique<PowerSupply>(bus, invpath);
+            std::uint8_t i2cbus = psuJSON["Bus"];
+            std::string i2caddr = psuJSON["Address"];
+            auto psu =
+                std::make_unique<PowerSupply>(bus, invpath, i2cbus, i2caddr);
             psus.emplace_back(std::move(psu));
         }
+        else
+        {
+            log<level::ERR>("Insufficient PowerSupply properties");
+        }
     }
 
     if (psus.empty())