Add basic PowerControl and PowerLimit properties
Add code in the power-specific response handler to fetch the Power Limit
value for the chassis that implements the Chassis inventory item. Add a
special case to the generic sensor handling code to place the
total_power value into the PowerControl PowerConsumedWatts field.
curl -k https://${bmc}/redfish/v1/Chassis/chassis/Power
{
"@odata.context": "/redfish/v1/$metadata#Power.Power",
"@odata.id": "/redfish/v1/Chassis/chassis/Power",
"@odata.type": "#Power.v1_5_2.Power",
"Id": "Power",
"Name": "Power",
"PowerControl": [
{
"@odata.id": "/redfish/v1/Chassis/chassis/Power#/PowerControl/",
"MemberId": "total_power",
"Name": "total power",
"PowerConsumedWatts": 269.0,
"Status": {
"Health": "OK",
"State": "Enabled"
}
}
],
"PowerLimit": [
{
"LimitInWatts": null
}
],
Signed-off-by: Eddie James <eajames@linux.ibm.com>
Change-Id: I447de59fb44a4ecbe7b47610d915ac22aef90250
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index c44ff71..86e5a07 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -32,7 +32,7 @@
std::pair<std::string,
std::vector<std::pair<std::string, std::vector<std::string>>>>>;
-using SensorVariant = std::variant<int64_t, double>;
+using SensorVariant = std::variant<int64_t, double, uint32_t, bool>;
using ManagedObjectsVectorType = std::vector<std::pair<
sdbusplus::message::object_path,
@@ -484,7 +484,11 @@
std::string sensorNameLower =
boost::algorithm::to_lower_copy(sensorName);
- if (sensorNameLower.find("input") != std::string::npos)
+ if (!sensorName.compare("total_power"))
+ {
+ unit = "PowerConsumedWatts";
+ }
+ else if (sensorNameLower.find("input") != std::string::npos)
{
unit = "PowerInputWatts";
}
@@ -550,6 +554,7 @@
const int64_t* int64Value = std::get_if<int64_t>(&valueVariant);
const double* doubleValue = std::get_if<double>(&valueVariant);
+ const uint32_t* uValue = std::get_if<uint32_t>(&valueVariant);
double temp = 0.0;
if (int64Value != nullptr)
{
@@ -559,6 +564,10 @@
{
temp = *doubleValue;
}
+ else if (uValue != nullptr)
+ {
+ temp = *uValue;
+ }
else
{
BMCWEB_LOG_ERROR
@@ -920,7 +929,14 @@
}
else if (sensorType == "power")
{
- fieldName = "PowerSupplies";
+ if (!sensorName.compare("total_power"))
+ {
+ fieldName = "PowerControl";
+ }
+ else
+ {
+ fieldName = "PowerSupplies";
+ }
}
else
{