control: Update zone target on startup
To handle restarting of the fan control service, set the zone's target
to what's initialized on one of the fan's target that's included in the
zone.
Change-Id: I88c598e817c1dbbd42d82265b8378dc78d3946d2
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/fan.cpp b/control/json/fan.cpp
index 9fbd03c..edd8514 100644
--- a/control/json/fan.cpp
+++ b/control/json/fan.cpp
@@ -89,6 +89,11 @@
void Fan::setTarget(uint64_t target)
{
+ if (_target == target)
+ {
+ return;
+ }
+
for (const auto& sensor : _sensors)
{
auto value = target;
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index 94a39a8..bd5261c 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -80,6 +80,12 @@
});
if (itZone != _zones.end())
{
+ if (itZone->second->getTarget() != fan.second->getTarget() &&
+ fan.second->getTarget() != 0)
+ {
+ // Update zone target to current target of the fan in the zone
+ itZone->second->setTarget(fan.second->getTarget());
+ }
itZone->second->addFan(std::move(fan.second));
}
}
diff --git a/control/json/zone.cpp b/control/json/zone.cpp
index 90aeb66..4d353d5 100644
--- a/control/json/zone.cpp
+++ b/control/json/zone.cpp
@@ -91,7 +91,7 @@
void Zone::setTarget(uint64_t target)
{
- if (_isActive)
+ if (_isActive && _target != target)
{
_target = target;
for (auto& fan : _fans)
diff --git a/control/json/zone.hpp b/control/json/zone.hpp
index e46522a..d9d6815 100644
--- a/control/json/zone.hpp
+++ b/control/json/zone.hpp
@@ -147,6 +147,16 @@
}
/**
+ * @brief Get the current target of the zone
+ *
+ * @return - The current target of the zone
+ */
+ inline const auto& getTarget() const
+ {
+ return _target;
+ }
+
+ /**
* @brief Get the target increase delta
*
* @return - The current target increase delta