control: Add fan objects to their zones
Load the fan configurations and add each fan to its configured zone.
Change-Id: Ib798db9f272484c60b6eadd58e6545bd704b9573
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index 804b15e..78aac29 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -15,6 +15,7 @@
*/
#include "manager.hpp"
+#include "fan.hpp"
#include "json_config.hpp"
#include "profile.hpp"
#include "zone.hpp"
@@ -23,6 +24,7 @@
#include <sdbusplus/bus.hpp>
#include <sdeventplus/event.hpp>
+#include <algorithm>
#include <filesystem>
#include <vector>
@@ -49,6 +51,21 @@
// Load the zone configurations
_zones = getConfig<Zone>(bus);
+
+ // Load the fan configurations and move each fan into its zone
+ auto fans = getConfig<Fan>(bus);
+ for (auto& fan : fans)
+ {
+ auto itZone =
+ std::find_if(_zones.begin(), _zones.end(),
+ [&fanZone = fan.second->getZone()](const auto& zone) {
+ return fanZone == zone.second->getName();
+ });
+ if (itZone != _zones.end())
+ {
+ itZone->second->addFan(std::move(fan.second));
+ }
+ }
}
const std::vector<std::string>& Manager::getActiveProfiles()