Cleaned up usage of updateValue() callers
Removed needless float, simply using double
Corrected string parsing function called for each type
Callers no longer need to check for equality first
Equality test now added to int and string override methods
This ensures all have same semantics
Removed extraordinarily spammy debug in updateValue(double)
Signed-off-by: Josh Lehan <krellan@google.com>
Change-Id: If8422d6516e083041685ddb6ef8cd469299cbad3
diff --git a/src/ADCSensor.cpp b/src/ADCSensor.cpp
index 5e01503..2ab1a4f 100644
--- a/src/ADCSensor.cpp
+++ b/src/ADCSensor.cpp
@@ -141,15 +141,12 @@
// todo read scaling factors from configuration
try
{
- double nvalue = std::stof(response);
+ double nvalue = std::stod(response);
nvalue = (nvalue / sensorScaleFactor) / scaleFactor;
nvalue = std::round(nvalue * roundFactor) / roundFactor;
- if (nvalue != value)
- {
- updateValue(nvalue);
- }
+ updateValue(nvalue);
errCount = 0;
}
catch (std::invalid_argument&)
diff --git a/src/CPUSensor.cpp b/src/CPUSensor.cpp
index 27c9c38..d3789fd 100644
--- a/src/CPUSensor.cpp
+++ b/src/CPUSensor.cpp
@@ -114,20 +114,19 @@
try
{
std::getline(responseStream, response);
- double nvalue = std::stof(response);
+ double nvalue = std::stod(response);
responseStream.clear();
nvalue /= CPUSensor::sensorScaleFactor;
- if (nvalue != value)
+
+ if (show)
{
- if (show)
- {
- updateValue(nvalue);
- }
- else
- {
- value = nvalue;
- }
+ updateValue(nvalue);
}
+ else
+ {
+ value = nvalue;
+ }
+
double gTcontrol = gCpuSensors[nameTcontrol]
? gCpuSensors[nameTcontrol]->value
: std::numeric_limits<double>::quiet_NaN();
diff --git a/src/ChassisIntrusionSensor.cpp b/src/ChassisIntrusionSensor.cpp
index 4b2327e..15ed888 100644
--- a/src/ChassisIntrusionSensor.cpp
+++ b/src/ChassisIntrusionSensor.cpp
@@ -47,6 +47,13 @@
void ChassisIntrusionSensor::updateValue(const std::string newValue)
{
+ // Take no action if value already equal
+ // Same semantics as Sensor::updateValue(const double&)
+ if (newValue == mValue)
+ {
+ return;
+ }
+
// indicate that it is internal set call
mInternalSet = true;
mIface->set_property("Status", newValue);
diff --git a/src/HwmonTempSensor.cpp b/src/HwmonTempSensor.cpp
index cf8ee10..f110b37 100644
--- a/src/HwmonTempSensor.cpp
+++ b/src/HwmonTempSensor.cpp
@@ -106,12 +106,9 @@
std::getline(responseStream, response);
try
{
- float nvalue = std::stof(response);
+ double nvalue = std::stod(response);
nvalue /= sensorScaleFactor;
- if (static_cast<double>(nvalue) != value)
- {
- updateValue(nvalue);
- }
+ updateValue(nvalue);
errCount = 0;
}
catch (const std::invalid_argument&)
diff --git a/src/PSUEvent.cpp b/src/PSUEvent.cpp
index 4e5c5a7..0849500 100644
--- a/src/PSUEvent.cpp
+++ b/src/PSUEvent.cpp
@@ -198,12 +198,10 @@
try
{
std::getline(responseStream, response);
- int nvalue = std::stof(response);
+ int nvalue = std::stoi(response);
responseStream.clear();
- if (nvalue != value)
- {
- updateValue(nvalue);
- }
+
+ updateValue(nvalue);
errCount = 0;
}
catch (const std::invalid_argument&)
@@ -240,6 +238,13 @@
// deasserted.
void PSUSubEvent::updateValue(const int& newValue)
{
+ // Take no action if value already equal
+ // Same semantics as Sensor::updateValue(const double&)
+ if (newValue == value)
+ {
+ return;
+ }
+
if (newValue == 0)
{
// log deassert only after all asserts are gone
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index e94d1c4..96b710c 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -125,24 +125,11 @@
try
{
std::getline(responseStream, response);
- float nvalue = std::stof(response);
+ double nvalue = std::stod(response);
responseStream.clear();
nvalue /= sensorFactor;
- if constexpr (DEBUG)
- {
- std::cerr << "Read " << path << " scale " << sensorFactor
- << " value " << nvalue << "\n";
- }
- if (static_cast<double>(nvalue) != value)
- {
- if constexpr (DEBUG)
- {
- std::cerr << "Update " << path << " from " << value
- << " to " << nvalue << "\n";
- }
- updateValue(nvalue);
- }
+ updateValue(nvalue);
errCount = 0;
}
catch (const std::invalid_argument&)
diff --git a/src/TachSensor.cpp b/src/TachSensor.cpp
index cc9d37d..bea79d8 100644
--- a/src/TachSensor.cpp
+++ b/src/TachSensor.cpp
@@ -147,12 +147,9 @@
try
{
std::getline(responseStream, response);
- float nvalue = std::stof(response);
+ double nvalue = std::stod(response);
responseStream.clear();
- if (static_cast<double>(nvalue) != value)
- {
- updateValue(nvalue);
- }
+ updateValue(nvalue);
errCount = 0;
}
catch (const std::invalid_argument&)