Fix: Move overriding logic to base sensor class
Instead of having the overridden value check inside each
sensor type, move the same to sensor base class, so that
any future addition of new sensor model, will be able to
inherit this feature automatically
Tested:
1. Verified the behaviour of overriden value by setting
the Value property.
2. restarting the sensor initializes the value back correctly
Change-Id: Iddf280cafcf6d9299e1edc13b942683bf60ea89b
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
diff --git a/include/ChassisIntrusionSensor.hpp b/include/ChassisIntrusionSensor.hpp
index fe04fc9..4bc421a 100644
--- a/include/ChassisIntrusionSensor.hpp
+++ b/include/ChassisIntrusionSensor.hpp
@@ -42,7 +42,6 @@
int mFd;
// common members
- std::string mOverriddenValue = "unknown";
bool mOverridenState = false;
bool mInternalSet = false;
diff --git a/include/sensor.hpp b/include/sensor.hpp
index 607eb3d..2a414da 100644
--- a/include/sensor.hpp
+++ b/include/sensor.hpp
@@ -30,20 +30,20 @@
std::shared_ptr<sdbusplus::asio::dbus_interface> thresholdInterfaceCritical;
std::shared_ptr<sdbusplus::asio::dbus_interface> association;
double value = std::numeric_limits<double>::quiet_NaN();
- double overriddenValue = std::numeric_limits<double>::quiet_NaN();
bool overridenState = false;
bool internalSet = false;
int setSensorValue(const double& newValue, double& oldValue)
{
- if (internalSet)
+ if (!internalSet)
{
- internalSet = false;
oldValue = newValue;
- return 1;
+ overridenState = true;
}
- overriddenValue = newValue;
- overridenState = true;
+ else if (!overridenState)
+ {
+ oldValue = newValue;
+ }
return 1;
}
diff --git a/src/ADCSensor.cpp b/src/ADCSensor.cpp
index 1db036e..505bbfa 100644
--- a/src/ADCSensor.cpp
+++ b/src/ADCSensor.cpp
@@ -115,11 +115,6 @@
nvalue = (nvalue / sensorScaleFactor) / scaleFactor;
nvalue = std::round(nvalue * roundFactor) / roundFactor;
- if (overridenState)
- {
- nvalue = overriddenValue;
- }
-
if (nvalue != value)
{
updateValue(nvalue);
diff --git a/src/CPUSensor.cpp b/src/CPUSensor.cpp
index 955bab4..4c5eb8b 100644
--- a/src/CPUSensor.cpp
+++ b/src/CPUSensor.cpp
@@ -110,10 +110,6 @@
double nvalue = std::stof(response);
responseStream.clear();
nvalue /= CPUSensor::sensorScaleFactor;
- if (overridenState)
- {
- nvalue = overriddenValue;
- }
if (nvalue != value)
{
if (show)
diff --git a/src/ChassisIntrusionSensor.cpp b/src/ChassisIntrusionSensor.cpp
index 22c03ab..4bf7fdc 100644
--- a/src/ChassisIntrusionSensor.cpp
+++ b/src/ChassisIntrusionSensor.cpp
@@ -54,6 +54,7 @@
// indicate that it is internal set call
mInternalSet = true;
mIface->set_property("Status", newValue);
+ mInternalSet = false;
mValue = newValue;
@@ -147,12 +148,6 @@
int statusValue = i2cReadFromPch(mBusId, mSlaveAddr);
std::string newValue = statusValue ? "HardwareIntrusion" : "Normal";
- // save value
- if (mOverridenState)
- {
- newValue = mOverriddenValue;
- }
-
if (newValue != "unknown" && mValue != newValue)
{
std::cout << "update value from " << mValue << " to "
@@ -200,12 +195,6 @@
std::cout << "Intrusion sensor value is " << newValue << "\n";
}
- // save value
- if (mOverridenState)
- {
- newValue = mOverriddenValue;
- }
-
if (newValue != "unknown" && mValue != newValue)
{
std::cout << "update value from " << mValue << " to " << newValue
@@ -251,16 +240,15 @@
int ChassisIntrusionSensor::setSensorValue(const std::string& req,
std::string& propertyValue)
{
- if (mInternalSet)
+ if (!mInternalSet)
{
- mInternalSet = false;
propertyValue = req;
- }
- else
- {
- mOverriddenValue = req;
mOverridenState = true;
}
+ else if (!mOverridenState)
+ {
+ propertyValue = req;
+ }
return 1;
}
diff --git a/src/HwmonTempSensor.cpp b/src/HwmonTempSensor.cpp
index 8325d3d..8472012 100644
--- a/src/HwmonTempSensor.cpp
+++ b/src/HwmonTempSensor.cpp
@@ -103,10 +103,6 @@
{
float nvalue = std::stof(response);
nvalue /= sensorScaleFactor;
- if (overridenState)
- {
- nvalue = overriddenValue;
- }
if (nvalue != value)
{
updateValue(nvalue);
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index c71b84d..5410b08 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -92,10 +92,6 @@
float nvalue = std::stof(response);
responseStream.clear();
nvalue /= sensorFactor;
- if (overridenState)
- {
- nvalue = overriddenValue;
- }
if (nvalue != value)
{
updateValue(nvalue);
diff --git a/src/TachSensor.cpp b/src/TachSensor.cpp
index 36b5ecf..03ff4a5 100644
--- a/src/TachSensor.cpp
+++ b/src/TachSensor.cpp
@@ -131,10 +131,6 @@
std::getline(responseStream, response);
float nvalue = std::stof(response);
responseStream.clear();
- if (overridenState)
- {
- nvalue = overriddenValue;
- }
if (nvalue != value)
{
updateValue(nvalue);