Fix default ValidInput values for DBus configuration
{Min,Max}ValidInput are optional properties defined in entity-manager
schema, currently they are initialized to NaN by default, causing
failure when comparing MinValidInput <= InputValue <= MaxValidInput in
sensorInRange(). This patch fixes it by setting the default value to
+/-NaN.
Tested:
Verified sensorInRange() no longer returns false when valid reading
value is given and virtual sensor reading is successfully updated.
Change-Id: If48a07eea95c8c971565e6e5ed429a1272ad824f
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
diff --git a/virtualSensor.cpp b/virtualSensor.cpp
index 304e874..4a60f4d 100644
--- a/virtualSensor.cpp
+++ b/virtualSensor.cpp
@@ -108,7 +108,8 @@
template <typename U>
U getNumberFromConfig(const PropertyMap& map, const std::string& name,
- bool required)
+ bool required,
+ U defaultValue = std::numeric_limits<U>::quiet_NaN())
{
if (auto itr = map.find(name); itr != map.end())
{
@@ -119,7 +120,7 @@
error("Required field {NAME} missing in config", "NAME", name);
throw std::invalid_argument("Required field missing in config");
}
- return std::numeric_limits<U>::quiet_NaN();
+ return defaultValue;
}
bool isCalculationType(const std::string& interface)
@@ -246,9 +247,11 @@
ValueIface::minValue(
getNumberFromConfig<double>(propertyMap, "MinValue", false));
maxValidInput =
- getNumberFromConfig<double>(propertyMap, "MaxValidInput", false);
+ getNumberFromConfig<double>(propertyMap, "MaxValidInput", false,
+ std::numeric_limits<double>::infinity());
minValidInput =
- getNumberFromConfig<double>(propertyMap, "MinValidInput", false);
+ getNumberFromConfig<double>(propertyMap, "MinValidInput", false,
+ -std::numeric_limits<double>::infinity());
}
void VirtualSensor::initVirtualSensor(const Json& sensorConfig,