Clean up power/thermal to use readJsonObject
Change-Id: I69ed29472b209e8782be63c3f0f2e8ca63dc14a4
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/redfish-core/lib/power.hpp b/redfish-core/lib/power.hpp
index 2a0f300..80276d2 100644
--- a/redfish-core/lib/power.hpp
+++ b/redfish-core/lib/power.hpp
@@ -26,7 +26,9 @@
#include <sdbusplus/asio/property.hpp>
#include <array>
+#include <string>
#include <string_view>
+#include <vector>
namespace redfish
{
@@ -69,7 +71,7 @@
inline void afterGetChassisPath(
const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
- std::vector<nlohmann::json>& powerControlCollections,
+ std::vector<nlohmann::json::object_t>& powerControlCollections,
const std::optional<std::string>& chassisPath)
{
if (!chassisPath)
@@ -90,19 +92,9 @@
auto& item = powerControlCollections[0];
- std::optional<nlohmann::json> powerLimit;
- if (!json_util::readJson(item, sensorsAsyncResp->asyncResp->res,
- "PowerLimit", powerLimit))
- {
- return;
- }
- if (!powerLimit)
- {
- return;
- }
std::optional<uint32_t> value;
- if (!json_util::readJson(*powerLimit, sensorsAsyncResp->asyncResp->res,
- "LimitInWatts", value))
+ if (!json_util::readJsonObject(item, sensorsAsyncResp->asyncResp->res,
+ "PowerLimit/LimitInWatts", value))
{
return;
}
@@ -313,8 +305,8 @@
asyncResp, chassisName, sensors::dbus::powerPaths,
sensors::node::power);
- std::optional<std::vector<nlohmann::json>> voltageCollections;
- std::optional<std::vector<nlohmann::json>> powerCtlCollections;
+ std::optional<std::vector<nlohmann::json::object_t>> voltageCollections;
+ std::optional<std::vector<nlohmann::json::object_t>> powerCtlCollections;
if (!json_util::readJsonPatch(req, sensorAsyncResp->asyncResp->res,
"PowerControl", powerCtlCollections,
@@ -332,9 +324,9 @@
}
if (voltageCollections)
{
- std::unordered_map<std::string, std::vector<nlohmann::json>>
+ std::unordered_map<std::string, std::vector<nlohmann::json::object_t>>
allCollections;
- allCollections.emplace("Voltages", *std::move(voltageCollections));
+ allCollections.emplace("Voltages", std::move(*voltageCollections));
setSensorsOverride(sensorAsyncResp, allCollections);
}
}
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 4f44b5a..e6de44d 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -2631,7 +2631,7 @@
*/
inline void setSensorsOverride(
const std::shared_ptr<SensorsAsyncResp>& sensorAsyncResp,
- std::unordered_map<std::string, std::vector<nlohmann::json>>&
+ std::unordered_map<std::string, std::vector<nlohmann::json::object_t>>&
allCollections)
{
BMCWEB_LOG_INFO("setSensorsOverride for subNode{}",
@@ -2657,9 +2657,9 @@
}
for (auto& item : collectionItems.second)
{
- if (!json_util::readJson(item, sensorAsyncResp->asyncResp->res,
- "MemberId", memberId, propertyValueName,
- value))
+ if (!json_util::readJsonObject(
+ item, sensorAsyncResp->asyncResp->res, "MemberId", memberId,
+ propertyValueName, value))
{
return;
}
diff --git a/redfish-core/lib/thermal.hpp b/redfish-core/lib/thermal.hpp
index 9d057f2..7e840d2 100644
--- a/redfish-core/lib/thermal.hpp
+++ b/redfish-core/lib/thermal.hpp
@@ -55,9 +55,10 @@
return;
}
- std::optional<std::vector<nlohmann::json>> temperatureCollections;
- std::optional<std::vector<nlohmann::json>> fanCollections;
- std::unordered_map<std::string, std::vector<nlohmann::json>>
+ std::optional<std::vector<nlohmann::json::object_t>>
+ temperatureCollections;
+ std::optional<std::vector<nlohmann::json::object_t>> fanCollections;
+ std::unordered_map<std::string, std::vector<nlohmann::json::object_t>>
allCollections;
auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(