Add support for tracking system power state

Change-Id: Ie0f27f696082ff3ee60c955992f3c2e55f4b5e57
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/power-supply/main.cpp b/power-supply/main.cpp
index af6bb9a..33729d8 100644
--- a/power-supply/main.cpp
+++ b/power-supply/main.cpp
@@ -56,16 +56,6 @@
         return -4;
     }
 
-    auto bus = sdbusplus::bus::new_default();
-
-    auto objname = "power_supply" + instnum;
-    auto instance = std::stoul(instnum);
-    auto psuDevice = std::make_unique<psu::PowerSupply>(objname,
-                                                        std::move(instance),
-                                                        std::move(objpath),
-                                                        std::move(invpath),
-                                                        bus);
-
     sd_event* events = nullptr;
 
     auto r = sd_event_default(&events);
@@ -76,17 +66,24 @@
         return -5;
     }
 
+    auto bus = sdbusplus::bus::new_default();
     witherspoon::power::event::Event eventPtr{events};
 
     //Attach the event object to the bus object so we can
     //handle both sd_events (for the timers) and dbus signals.
     bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL);
 
-    //Attach the event object to the bus object so we can
-    //handle both sd_events (for the timers) and dbus signals.
-    bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL);
-
-    // TODO: Get power state on startup.
+    auto objname = "power_supply" + instnum;
+    auto instance = std::stoul(instnum);
+    // The Witherspoon power supply can delay DC_GOOD active for 1 second.
+    std::chrono::seconds powerOnDelay(1);
+    auto psuDevice = std::make_unique<psu::PowerSupply>(objname,
+                                                        std::move(instance),
+                                                        std::move(objpath),
+                                                        std::move(invpath),
+                                                        bus,
+                                                        eventPtr,
+                                                        powerOnDelay);
 
     auto pollInterval = std::chrono::milliseconds(1000);
     DeviceMonitor mainloop(std::move(psuDevice), eventPtr, pollInterval);