sensors: buildjson: only load min/max if type fan
The min/max value in the json configuration only provide meaning in the
context of a fan sensor. This patch only loads the configuration
options in that case, and reports a warning if otherwise detected.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I20898ab3c87f4e9c6005683420a30c6685944c96
diff --git a/sensors/buildjson.cpp b/sensors/buildjson.cpp
index f5449eb..2dc5a37 100644
--- a/sensors/buildjson.cpp
+++ b/sensors/buildjson.cpp
@@ -19,6 +19,7 @@
#include "conf.hpp"
#include "sensors/sensor.hpp"
+#include <cstdio>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
@@ -48,14 +49,28 @@
auto min = j.find("min");
if (min != j.end())
{
- j.at("min").get_to(s.min);
+ if (s.type == "fan")
+ {
+ j.at("min").get_to(s.min);
+ }
+ else
+ {
+ std::fprintf(stderr, "Non-fan types ignore min value specified\n");
+ }
}
/* The max field is optional in a configuration. */
auto max = j.find("max");
if (max != j.end())
{
- j.at("max").get_to(s.max);
+ if (s.type == "fan")
+ {
+ j.at("max").get_to(s.max);
+ }
+ else
+ {
+ std::fprintf(stderr, "Non-fan types ignore max value specified\n");
+ }
}
/* The timeout field is optional in a configuration. */