Add Unit property to dbus interfaces
Previously, the lack of the Unit property on the Value interfaces
provided by dbus-sensors meant that readings from its sensors weren't
displayed in phosphor-webui/webui-vue. Here it's added as an extra
parameter to setInitialProperties, allowing sensors that handle multiple
types of data (e.g. IpmbSensor, PSUSensor) to determine the appropriate
string to pass once they've had time to determine that.
Tested: PSUSensor, ADCSensor, CPUSensor, TachSensor, and HwmonTempSensor
all have an appropriate Unit property available on dbus, and are
displayed in webui-vue.
Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Change-Id: I5e6df74cc42d9fb84852c5bf3ea5d3b383a16cdc
diff --git a/include/IpmbSensor.hpp b/include/IpmbSensor.hpp
index ff15fa6..4effd18 100644
--- a/include/IpmbSensor.hpp
+++ b/include/IpmbSensor.hpp
@@ -87,6 +87,7 @@
void checkThresholds(void) override;
void read(void);
void init(void);
+ std::string getSubTypeUnits(void);
void loadDefaults(void);
void runInitCmd(void);
bool processReading(const std::vector<uint8_t>& data, double& resp);
diff --git a/include/PSUSensor.hpp b/include/PSUSensor.hpp
index fd69c5a..e309aeb 100644
--- a/include/PSUSensor.hpp
+++ b/include/PSUSensor.hpp
@@ -19,7 +19,7 @@
boost::asio::io_service& io, const std::string& sensorName,
std::vector<thresholds::Threshold>&& thresholds,
const std::string& sensorConfiguration,
- std::string& sensorTypeName, unsigned int factor, double max,
+ const std::string& sensorUnits, unsigned int factor, double max,
double min, const std::string& label, size_t tSize);
~PSUSensor() override;
void setupRead(void);
diff --git a/include/PwmSensor.hpp b/include/PwmSensor.hpp
index 1f8a467..d78b8e9 100644
--- a/include/PwmSensor.hpp
+++ b/include/PwmSensor.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <sdbusplus/asio/object_server.hpp>
+#include <sensor.hpp>
#include <memory>
#include <string>
diff --git a/include/SensorPaths.hpp b/include/SensorPaths.hpp
index e8ed8fa..023d615 100644
--- a/include/SensorPaths.hpp
+++ b/include/SensorPaths.hpp
@@ -11,6 +11,21 @@
// with
// phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Sensor/Value.interface.yaml#L35
+constexpr const char* unitDegreesC =
+ "xyz.openbmc_project.Sensor.Value.Unit.DegreesC";
+constexpr const char* unitRPMs = "xyz.openbmc_project.Sensor.Value.Unit.RPMS";
+constexpr const char* unitVolts = "xyz.openbmc_project.Sensor.Value.Unit.Volts";
+constexpr const char* unitMeters =
+ "xyz.openbmc_project.Sensor.Value.Unit.Meters";
+constexpr const char* unitAmperes =
+ "xyz.openbmc_project.Sensor.Value.Unit.Amperes";
+constexpr const char* unitWatts = "xyz.openbmc_project.Sensor.Value.Unit.Watts";
+constexpr const char* unitJoules =
+ "xyz.openbmc_project.Sensor.Value.Unit.Joules";
+constexpr const char* unitPercent =
+ "xyz.openbmc_project.Sensor.Value.Unit.Percent";
+constexpr const char* unitCFM = "xyz.openbmc_project.Sensor.Value.Unit.CFM";
+
std::string getPathForUnits(const std::string& units);
std::string escapePathForDbus(const std::string& name);
diff --git a/include/sensor.hpp b/include/sensor.hpp
index dc91fc1..d1fb22e 100644
--- a/include/sensor.hpp
+++ b/include/sensor.hpp
@@ -194,6 +194,7 @@
void
setInitialProperties(std::shared_ptr<sdbusplus::asio::connection>& conn,
+ const std::string& unit,
const std::string& label = std::string(),
size_t thresholdSize = 0)
{
@@ -204,6 +205,7 @@
createAssociation(association, configurationPath);
+ sensorInterface->register_property("Unit", unit);
sensorInterface->register_property("MaxValue", maxValue);
sensorInterface->register_property("MinValue", minValue);
sensorInterface->register_property(