Add power state check for HwmonTempSensor
We have some sensors that are on DC power, add the
check so this is configurable.
Tested: DC cycled, saw no logs
Change-Id: I0f2fc5c96c46d8c782f4bc364f649a9f2f699c3a
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/include/HwmonTempSensor.hpp b/include/HwmonTempSensor.hpp
index 677cab8..e041085 100644
--- a/include/HwmonTempSensor.hpp
+++ b/include/HwmonTempSensor.hpp
@@ -15,7 +15,8 @@
std::shared_ptr<sdbusplus::asio::connection>& conn,
boost::asio::io_service& io, const std::string& fanName,
std::vector<thresholds::Threshold>&& thresholds,
- const std::string& sensorConfiguration);
+ const std::string& sensorConfiguration,
+ const PowerState powerState);
~HwmonTempSensor();
private:
@@ -24,6 +25,7 @@
boost::asio::deadline_timer waitTimer;
boost::asio::streambuf readBuf;
std::string path;
+ PowerState readState;
size_t errCount;
void setupRead(void);
void handleResponse(const boost::system::error_code& err);
diff --git a/src/HwmonTempMain.cpp b/src/HwmonTempMain.cpp
index d26b2d6..55d4508 100644
--- a/src/HwmonTempMain.cpp
+++ b/src/HwmonTempMain.cpp
@@ -201,12 +201,20 @@
std::cerr << "error populating thresholds for "
<< sensorName << "\n";
}
+ auto findPowerOn = baseConfiguration->second.find("PowerState");
+ PowerState readState = PowerState::always;
+ if (findPowerOn != baseConfiguration->second.end())
+ {
+ std::string powerState = std::visit(
+ VariantToStringVisitor(), findPowerOn->second);
+ setReadState(powerState, readState);
+ }
auto& sensor = sensors[sensorName];
sensor = nullptr;
sensor = std::make_unique<HwmonTempSensor>(
directory.string() + "/temp1_input", sensorType,
objectServer, dbusConnection, io, sensorName,
- std::move(sensorThresholds), *interfacePath);
+ std::move(sensorThresholds), *interfacePath, readState);
// Looking for keys like "Name1" for temp2_input,
// "Name2" for temp3_input, etc.
@@ -230,7 +238,7 @@
"_input",
sensorType, objectServer, dbusConnection, io,
sensorName, std::vector<thresholds::Threshold>(),
- *interfacePath);
+ *interfacePath, readState);
}
}
}));
diff --git a/src/HwmonTempSensor.cpp b/src/HwmonTempSensor.cpp
index 15d4d38..5222b04 100644
--- a/src/HwmonTempSensor.cpp
+++ b/src/HwmonTempSensor.cpp
@@ -43,12 +43,12 @@
std::shared_ptr<sdbusplus::asio::connection>& conn,
boost::asio::io_service& io, const std::string& sensorName,
std::vector<thresholds::Threshold>&& _thresholds,
- const std::string& sensorConfiguration) :
+ const std::string& sensorConfiguration, const PowerState powerState) :
Sensor(boost::replace_all_copy(sensorName, " ", "_"),
std::move(_thresholds), sensorConfiguration, objectType, maxReading,
minReading),
objServer(objectServer), inputDev(io, open(path.c_str(), O_RDONLY)),
- waitTimer(io), path(path), errCount(0)
+ waitTimer(io), path(path), errCount(0), readState(powerState)
{
sensorInterface = objectServer.add_interface(
"/xyz/openbmc_project/sensors/temperature/" + name,
@@ -70,6 +70,7 @@
"/xyz/openbmc_project/sensors/temperature/" + name,
association::interface);
setInitialProperties(conn);
+ setupPowerMatch(conn);
setupRead();
}
@@ -154,5 +155,9 @@
void HwmonTempSensor::checkThresholds(void)
{
+ if (readState == PowerState::on && !isPowerOn())
+ {
+ return;
+ }
thresholds::checkThresholds(this);
}