sensorhandler: allow preconfigured unit and scale
Allow specifying the scale and unit for a sensor in the
YAML configuration. This can save clock time by no longer
requiring the daemon to reach out to the sensor owner for
the information.
Change-Id: I5f63286fc32fb9d64ebab7d86d1dbb7ff40591f4
Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index 582f16b..3358b83 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -697,20 +697,27 @@
"xyz.openbmc_project.Sensor.Value")
{
std::string result {};
- char *raw_cstr = NULL;
- if (0 > sd_bus_get_property_string(bus, iface.bus, iface.path,
- iface.interface, "Unit", NULL,
- &raw_cstr))
+ if (info->unit.empty())
{
- log<level::WARNING>("Unit interface missing.",
- entry("BUS=%s", iface.bus),
- entry("PATH=%s", iface.path));
+ char *raw_cstr = NULL;
+ if (0 > sd_bus_get_property_string(bus, iface.bus, iface.path,
+ iface.interface, "Unit", NULL,
+ &raw_cstr))
+ {
+ log<level::WARNING>("Unit interface missing.",
+ entry("BUS=%s", iface.bus),
+ entry("PATH=%s", iface.path));
+ }
+ else
+ {
+ result = raw_cstr;
+ }
+ free(raw_cstr);
}
else
{
- result = raw_cstr;
+ result = info->unit;
}
- free(raw_cstr);
namespace server = sdbusplus::xyz::openbmc_project::Sensor::server;
try {
@@ -758,17 +765,24 @@
if (info->propertyInterfaces.begin()->first ==
"xyz.openbmc_project.Sensor.Value")
{
- if (0 > sd_bus_get_property_trivial(bus,
- iface.bus,
- iface.path,
- iface.interface,
- "Scale",
- NULL,
- 'x',
- &result)) {
- log<level::WARNING>("Scale interface missing.",
- entry("BUS=%s", iface.bus),
- entry("PATH=%s", iface.path));
+ if (info->hasScale)
+ {
+ result = info->scale;
+ }
+ else
+ {
+ if (0 > sd_bus_get_property_trivial(bus,
+ iface.bus,
+ iface.path,
+ iface.interface,
+ "Scale",
+ NULL,
+ 'x',
+ &result)) {
+ log<level::WARNING>("Scale interface missing.",
+ entry("BUS=%s", iface.bus),
+ entry("PATH=%s", iface.path));
+ }
}
}