psu-sensor: Add devmgmt and powercallback to PSU

Some PSU sensors are dependent on system power state.
Without change the device initialization would fail and
dbus-sensors and entity-manager wouldn't come back to
properly instantiate.

Same intention as this hwmontempsensor change: https://github.com/openbmc/dbus-sensors/commit/a1456c4abafc697e7caa6b8e95ac9ddb35c4e7d1

Tested: Same sensors are getting created.  Sensors are
getting created/destroyed on host power events based
on their PowerState.

Signed-off-by: Matt Simmering <matthew.simmering@intel.com>
Change-Id: I3ee719cf65df225f964148d3994eec4d758d72a1
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index 763a926..ecf546e 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -44,10 +44,11 @@
                      const PowerState& powerState,
                      const std::string& sensorUnits, unsigned int factor,
                      double max, double min, double offset,
-                     const std::string& label, size_t tSize, double pollRate) :
+                     const std::string& label, size_t tSize, double pollRate,
+                     const std::shared_ptr<I2CDevice>& i2cDevice) :
     Sensor(escapeName(sensorName), std::move(thresholdsIn), sensorConfiguration,
            objectType, false, false, max, min, conn, powerState),
-    objServer(objectServer),
+    i2cDevice(i2cDevice), objServer(objectServer),
     inputDev(io, path, boost::asio::random_access_file::read_only),
     waitTimer(io), path(path), sensorFactor(factor), sensorOffset(offset),
     thresholdTimer(io)
@@ -98,8 +99,8 @@
 
 PSUSensor::~PSUSensor()
 {
-    waitTimer.cancel();
-    inputDev.close();
+    deactivate();
+
     objServer.remove_interface(sensorInterface);
     for (const auto& iface : thresholdInterfaces)
     {
@@ -108,6 +109,31 @@
     objServer.remove_interface(association);
 }
 
+bool PSUSensor::isActive()
+{
+    return inputDev.is_open();
+}
+
+void PSUSensor::activate(const std::string& newPath,
+                         const std::shared_ptr<I2CDevice>& newI2CDevice)
+{
+    path = newPath;
+    i2cDevice = newI2CDevice;
+    inputDev.open(path, boost::asio::random_access_file::read_only);
+    markAvailable(true);
+    setupRead();
+}
+
+void PSUSensor::deactivate()
+{
+    markAvailable(false);
+    // close the input dev to cancel async operations
+    inputDev.close();
+    waitTimer.cancel();
+    i2cDevice = nullptr;
+    path = "";
+}
+
 void PSUSensor::setupRead(void)
 {
     if (!readingStateGood())