Sync ReadingUnit with Redfish Sensor Schema
Actual attribute "ReadingUnits" does not match with Redfish Sensor
Schema. This change match "ReadingUnits" with Redfish Sensor Scheme
1.0.0 and add missing "ReadingType" attribute. This change affect all
users that depends on old units that does not match with Redfish
standard. Added toReadingType and toReadingUnit function that uses
values taken from Redfish Sensor Scheme 1.0.0. Latest version 1.2.0 of
Sensor scheme defines same units.
Changed value stored in ReadingUnits for Sensor resource:
- "Watts" -> "W"
- "Amperes" -> "A"
- "Percent" -> "%"
Tested:
- RedfishServiceValidator pass
- Verified that Sensors contain proper ReadingUnits
- Webui-Vue displays ReadingUnits properly in Health tab
Change-Id: I0c8820eba7271022c427cd25dec321db36aa0176
Signed-off-by: Wludzik, Jozef <jozef.wludzik@intel.com>
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 35114bf..9f06d2f 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -54,9 +54,10 @@
namespace dbus
{
+
static const boost::container::flat_map<std::string_view,
std::vector<const char*>>
- types = {{node::power,
+ paths = {{node::power,
{"/xyz/openbmc_project/sensors/voltage",
"/xyz/openbmc_project/sensors/power"}},
{node::sensors,
@@ -67,6 +68,88 @@
{"/xyz/openbmc_project/sensors/fan_tach",
"/xyz/openbmc_project/sensors/temperature",
"/xyz/openbmc_project/sensors/fan_pwm"}}};
+} // namespace dbus
+
+inline const char* toReadingType(const std::string& sensorType)
+{
+ if (sensorType == "voltage")
+ {
+ return "Voltage";
+ }
+ if (sensorType == "power")
+ {
+ return "Power";
+ }
+ if (sensorType == "current")
+ {
+ return "Current";
+ }
+ if (sensorType == "fan_tach")
+ {
+ return "Rotational";
+ }
+ if (sensorType == "temperature")
+ {
+ return "Temperature";
+ }
+ if (sensorType == "fan_pwm" || sensorType == "utilization")
+ {
+ return "Percent";
+ }
+ if (sensorType == "altitude")
+ {
+ return "Altitude";
+ }
+ if (sensorType == "airflow")
+ {
+ return "AirFlow";
+ }
+ if (sensorType == "energy")
+ {
+ return "EnergyJoules";
+ }
+ return "";
+}
+
+inline const char* toReadingUnits(const std::string& sensorType)
+{
+ if (sensorType == "voltage")
+ {
+ return "V";
+ }
+ if (sensorType == "power")
+ {
+ return "W";
+ }
+ if (sensorType == "current")
+ {
+ return "A";
+ }
+ if (sensorType == "fan_tach")
+ {
+ return "RPM";
+ }
+ if (sensorType == "temperature")
+ {
+ return "Cel";
+ }
+ if (sensorType == "fan_pwm" || sensorType == "utilization")
+ {
+ return "%";
+ }
+ if (sensorType == "altitude")
+ {
+ return "m";
+ }
+ if (sensorType == "airflow")
+ {
+ return "cft_i/min";
+ }
+ if (sensorType == "energy")
+ {
+ return "J";
+ }
+ return "";
}
} // namespace sensors
@@ -854,17 +937,27 @@
if (sensorsAsyncResp->chassisSubNode == sensors::node::sensors)
{
sensorJson["@odata.type"] = "#Sensor.v1_0_0.Sensor";
- if (sensorType == "power")
+
+ const std::string& readingType = sensors::toReadingType(sensorType);
+ if (readingType.empty())
{
- sensorJson["ReadingUnits"] = "Watts";
+ BMCWEB_LOG_ERROR << "Redfish cannot map reading type for "
+ << sensorType;
}
- else if (sensorType == "current")
+ else
{
- sensorJson["ReadingUnits"] = "Amperes";
+ sensorJson["ReadingType"] = readingType;
}
- else if (sensorType == "utilization")
+
+ const std::string& readingUnits = sensors::toReadingUnits(sensorType);
+ if (readingUnits.empty())
{
- sensorJson["ReadingUnits"] = "Percent";
+ BMCWEB_LOG_ERROR << "Redfish cannot map reading unit for "
+ << sensorType;
+ }
+ else
+ {
+ sensorJson["ReadingUnits"] = readingUnits;
}
}
else if (sensorType == "temperature")
@@ -2979,8 +3072,8 @@
const std::string& node,
SensorsAsyncResp::DataCompleteCb&& mapComplete)
{
- auto typesIt = sensors::dbus::types.find(node);
- if (typesIt == sensors::dbus::types.end())
+ auto pathIt = sensors::dbus::paths.find(node);
+ if (pathIt == sensors::dbus::paths.end())
{
BMCWEB_LOG_ERROR << "Wrong node provided : " << node;
mapComplete(boost::beast::http::status::bad_request, {});
@@ -2995,7 +3088,7 @@
uriToDbus) { mapCompleteCb(status, uriToDbus); };
auto resp = std::make_shared<SensorsAsyncResp>(
- *respBuffer, chassis, typesIt->second, node, std::move(callback));
+ *respBuffer, chassis, pathIt->second, node, std::move(callback));
getChassisData(resp);
}
@@ -3030,7 +3123,7 @@
const std::string& chassisId = params[0];
std::shared_ptr<SensorsAsyncResp> asyncResp =
std::make_shared<SensorsAsyncResp>(
- res, chassisId, sensors::dbus::types.at(sensors::node::sensors),
+ res, chassisId, sensors::dbus::paths.at(sensors::node::sensors),
sensors::node::sensors);
auto getChassisCb =