Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions redfish-core/lib/power_supply.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,12 @@ inline void getValidPowerSupplyPath(

inline void getPowerSupplyState(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& service, const std::string& path)
const std::string& service, const std::string& path, bool available)
{
dbus::utility::getProperty<bool>(
service, path, "xyz.openbmc_project.Inventory.Item", "Present",
[asyncResp](const boost::system::error_code& ec, const bool value) {
[asyncResp,
available](const boost::system::error_code& ec, const bool value) {
if (ec)
{
if (ec.value() != EBADR)
Expand All @@ -229,17 +230,23 @@ inline void getPowerSupplyState(
asyncResp->res.jsonValue["Status"]["State"] =
resource::State::Absent;
}
else if (!available)
{
asyncResp->res.jsonValue["Status"]["State"] =
resource::State::UnavailableOffline;
}
});
}

inline void getPowerSupplyHealth(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& service, const std::string& path)
const std::string& service, const std::string& path, bool available)
{
dbus::utility::getProperty<bool>(
service, path, "xyz.openbmc_project.State.Decorator.OperationalStatus",
"Functional",
[asyncResp](const boost::system::error_code& ec, const bool value) {
[asyncResp,
available](const boost::system::error_code& ec, const bool value) {
if (ec)
{
if (ec.value() != EBADR)
Expand All @@ -251,14 +258,39 @@ inline void getPowerSupplyHealth(
return;
}

if (!value)
if (!value || !available)
{
asyncResp->res.jsonValue["Status"]["Health"] =
resource::Health::Critical;
}
});
}

inline void getPowerSupplyStateAndHealth(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& service, const std::string& path)
{
dbus::utility::getProperty<bool>(
service, path, "xyz.openbmc_project.State.Decorator.Availability",
"Available",
[asyncResp, service,
path](const boost::system::error_code& ec, const bool available) {
if (ec)
{
if (ec.value() != EBADR)
{
BMCWEB_LOG_ERROR("DBUS response error for Available {}",
ec.value());
messages::internalError(asyncResp->res);
}
return;
}

getPowerSupplyState(asyncResp, service, path, available);
getPowerSupplyHealth(asyncResp, service, path, available);
});
}

inline void getPowerSupplyAsset(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& service, const std::string& path)
Expand Down Expand Up @@ -478,8 +510,7 @@ inline void doPowerSupplyGet(
asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;

getPowerSupplyState(asyncResp, service, powerSupplyPath);
getPowerSupplyHealth(asyncResp, service, powerSupplyPath);
getPowerSupplyStateAndHealth(asyncResp, service, powerSupplyPath);
getPowerSupplyAsset(asyncResp, service, powerSupplyPath);
getPowerSupplyFirmwareVersion(asyncResp, service, powerSupplyPath);
getPowerSupplyLocation(asyncResp, service, powerSupplyPath);
Expand Down