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/DeviceMgmt.hpp b/src/DeviceMgmt.hpp
index 170cd37..5e469de 100644
--- a/src/DeviceMgmt.hpp
+++ b/src/DeviceMgmt.hpp
@@ -63,6 +63,16 @@
sdbusplus::asio::connection& bus, const I2CDeviceTypeMap& typeMap,
const std::function<void(sdbusplus::message_t&)>& handler);
+// Helper find function because some sensors use underscores in their names
+// while others use spaces. Ignore this discrepancy by changing all spaces to
+// underscores.
+inline size_t sensorNameFind(const std::string& fullName,
+ const std::string& partialName)
+{
+ return boost::replace_all_copy(fullName, " ", "_")
+ .find(boost::replace_all_copy(partialName, " ", "_"));
+}
+
// returns a {path: <I2CDevice, is_new>} map. is_new indicates if the I2CDevice
// is newly instantiated by this call (true) or was already there (false).
template <class T>
@@ -92,16 +102,31 @@
{
continue;
}
- std::string sensorName =
- std::get<std::string>(findSensorName->second);
- auto findSensor = sensors.find(sensorName);
- if (findSensor != sensors.end() && findSensor->second != nullptr &&
- findSensor->second->isActive())
+ const auto* sensorName =
+ std::get_if<std::string>(&findSensorName->second);
+ if (sensorName == nullptr)
+ {
+ std::cerr << "Unable to find sensor name " << name
+ << " on path " << path.str << "\n";
+ continue;
+ }
+
+ std::shared_ptr<T> findSensor(nullptr);
+ for (const auto& sensor : sensors)
+ {
+ if (sensorNameFind(sensor.first, *sensorName) !=
+ std::string::npos)
+ {
+ findSensor = sensor.second;
+ break;
+ }
+ }
+ if (findSensor != nullptr && findSensor->isActive())
{
devices.emplace(
path.str,
- std::make_pair(findSensor->second->getI2CDevice(), false));
+ std::make_pair(findSensor->getI2CDevice(), false));
continue;
}