fans: Use attribute() instead of attributes()
It is needed to read only those fanX_input files, that are enabled via
fanX_enable. Reading from fanX_input while it's fanX_enable is disabled
returns an error.
Change-Id: Iaf8d43d11e01fc24a19791bdf86d427ec714e064
diff --git a/src/ietf-hardware/IETFHardware.cpp b/src/ietf-hardware/IETFHardware.cpp
index e138e51..b18a071 100644
--- a/src/ietf-hardware/IETFHardware.cpp
+++ b/src/ietf-hardware/IETFHardware.cpp
@@ -133,13 +133,11 @@
{
DataTree res(m_staticData);
- auto attrs = m_hwmon->attributes();
-
for (unsigned i = 1; i <= m_fanChannelsCount; i++) {
const auto sensorComponentName = m_componentName + ":fan" + std::to_string(i) + ":rpm";
const auto attribute = "fan"s + std::to_string(i) + "_input";
- addSensorValue(res, sensorComponentName, std::to_string(attrs.at(attribute)));
+ addSensorValue(res, sensorComponentName, std::to_string(m_hwmon->attribute(attribute)));
}
return res;
diff --git a/tests/hardware_ietf-hardware.cpp b/tests/hardware_ietf-hardware.cpp
index 17ecf48..db75eea 100644
--- a/tests/hardware_ietf-hardware.cpp
+++ b/tests/hardware_ietf-hardware.cpp
@@ -46,13 +46,10 @@
};
FAKE_EMMC(emmc, attributesEMMC);
- attributesHWMon = {
- {"fan1_input"s, 253},
- {"fan2_input"s, 0},
- {"fan3_input"s, 1280},
- {"fan4_input"s, 666},
- };
- FAKE_HWMON(fans, attributesHWMon);
+ REQUIRE_CALL(*fans, attribute("fan1_input"s)).RETURN( 253);
+ REQUIRE_CALL(*fans, attribute("fan2_input"s)).RETURN( 0);
+ REQUIRE_CALL(*fans, attribute("fan3_input"s)).RETURN( 1280);
+ REQUIRE_CALL(*fans, attribute("fan4_input"s)).RETURN( 666);
REQUIRE_CALL(*sysfsTempFront, attribute("temp1_input")).RETURN(30800);
REQUIRE_CALL(*sysfsTempCpu, attribute("temp1_input")).RETURN(41800);