Add chassis association for total_power sensor
Currently all power and temperatures sensors have an all_sensors chassis
association.
The total system power sensor is used in bmcweb, but had the sensor path
hardcoded. To prevent users from having to hardcode the sensor path this
commit will add a total_power association to the chassis.
Tested on Rainier:
'''
a{sv} 1 "Associations" a(sss) 2 "chassis" "all_sensors" "/xyz/openbmc_project/inventory/system/chassis" "chassis" "total_power" "/xyz/openbmc_project/inventory/system/chassis"
as 1 "/xyz/openbmc_project/sensors/power/total_power"
d 366
'''
Change-Id: I11b82e439de6b9d7a9e9e46eee26bb5e22502283
Signed-off-by: Chris Cain <cjcain@us.ibm.com>
diff --git a/occ_dbus.cpp b/occ_dbus.cpp
index 62ae23f..96d4554 100644
--- a/occ_dbus.cpp
+++ b/occ_dbus.cpp
@@ -172,7 +172,8 @@
throw std::invalid_argument("Failed to get OperationalStatus property.");
}
-void OccDBusSensors::setChassisAssociation(const std::string& path)
+void OccDBusSensors::setChassisAssociation(
+ const std::string& path, const std::vector<std::string>& fTypes)
{
using AssociationsEntry = std::tuple<std::string, std::string, std::string>;
using AssociationsProperty = std::vector<AssociationsEntry>;
@@ -184,8 +185,11 @@
chassisPath = getChassisPath();
}
- AssociationsProperty associations{
- AssociationsEntry{"chassis", "all_sensors", chassisPath}};
+ AssociationsProperty associations;
+ for (const auto& fType : fTypes)
+ {
+ associations.emplace_back("chassis", fType, chassisPath);
+ }
PropVariant value{std::move(associations)};
std::map<std::string, PropVariant> properties;
diff --git a/occ_dbus.hpp b/occ_dbus.hpp
index f20ffc3..595cf5f 100644
--- a/occ_dbus.hpp
+++ b/occ_dbus.hpp
@@ -139,9 +139,11 @@
/** @brief Set the association to the chassis
*
- * @param[in] path - The object path
+ * @param[in] path - The object path
+ * @param[in] fType - vector of forward types
*/
- void setChassisAssociation(const std::string& path);
+ void setChassisAssociation(const std::string& path,
+ const std::vector<std::string>& fTypes);
/** @brief Set the value of the DVFS temp sensor
*
diff --git a/occ_manager.cpp b/occ_manager.cpp
index 308c67e..7823111 100644
--- a/occ_manager.cpp
+++ b/occ_manager.cpp
@@ -1186,7 +1186,7 @@
if (existingSensors.find(objectPath) == existingSensors.end())
{
dbus::OccDBusSensors::getOccDBus().setChassisAssociation(
- objectPath);
+ objectPath, {"all_sensors"});
}
existingSensors[objectPath] = occInstance;
@@ -1290,8 +1290,15 @@
if (existingSensors.find(sensorPath) == existingSensors.end())
{
+ std::vector<int> occs;
+ std::vector<std::string> fTypeList = {"all_sensors"};
+ if (iter->second == "total_power")
+ {
+ // Total system power has its own chassis association
+ fTypeList.push_back("total_power");
+ }
dbus::OccDBusSensors::getOccDBus().setChassisAssociation(
- sensorPath);
+ sensorPath, fTypeList);
}
existingSensors[sensorPath] = id;