hwmontemp: add labels attribute support
Adds Labels support to Hwmontemp. The behavior is meant to be identical
to the behavior of Labels from PSUSensors.
Labels has the following behavior:
When discovering Name, Name1...NameX attributes from the configuration
and an associated temp is found
If tempX_label exists and its contents is in the Labels attribute then
create the sensor
If tempX_label does not exist but tempX is in the Labels attribute then
create the sensor
If Labels attribute is not present or is an empty list then create the
sensor
Tested:
Had a simple , publically available MAX6581 sensor that has
temp1, temp2, temp3, temp4, temp5
and tested with
Labels = ["temp1", "temp2", "temp3", "temp4", "temp5"]
├─/xyz/openbmc_project/sensors/temperature/max6581_1
├─/xyz/openbmc_project/sensors/temperature/max6581_2
├─/xyz/openbmc_project/sensors/temperature/max6581_3
├─/xyz/openbmc_project/sensors/temperature/max6581_4
├─/xyz/openbmc_project/sensors/temperature/max6581_5
Labels omitted
├─/xyz/openbmc_project/sensors/temperature/max6581_1
├─/xyz/openbmc_project/sensors/temperature/max6581_2
├─/xyz/openbmc_project/sensors/temperature/max6581_3
├─/xyz/openbmc_project/sensors/temperature/max6581_4
├─/xyz/openbmc_project/sensors/temperature/max6581_5
Labels containing temp2,temp5
Results:
├─/xyz/openbmc_project/sensors/temperature/max6581_2
├─/xyz/openbmc_project/sensors/temperature/max6581_5
And a similar test with a device that has temperature labels
"Labels": [
"device_label_A",
"device_label_B",
"device_label_C"
],
├─/xyz/openbmc_project/sensors/temperature/device1_label_A
├─/xyz/openbmc_project/sensors/temperature/device1_label_B
├─/xyz/openbmc_project/sensors/temperature/device1_label_C
Signed-off-by: Jason Ling <jasonling@google.com>
Change-Id: I6cb9edb0c7ae68fe01663d4ee1be0070715e9f82
diff --git a/include/Utils.hpp b/include/Utils.hpp
index 7f529e1..c164187 100644
--- a/include/Utils.hpp
+++ b/include/Utils.hpp
@@ -42,6 +42,12 @@
std::vector<std::pair<std::string, std::vector<std::string>>>>>;
using Association = std::tuple<std::string, std::string, std::string>;
+std::optional<std::string> openAndRead(const std::string& hwmonFile);
+std::optional<std::string>
+ getFullHwmonFilePath(const std::string& directory,
+ const std::string& hwmonBaseName,
+ const std::set<std::string>& permitSet);
+std::set<std::string> getPermitSet(const SensorBaseConfigMap& config);
bool findFiles(const std::filesystem::path dirPath,
const std::string& matchString,
std::vector<std::filesystem::path>& foundPaths,