diff --git a/redfish-core/lib/power_supply.hpp b/redfish-core/lib/power_supply.hpp index 2d3942b3a..208c7dfad 100644 --- a/redfish-core/lib/power_supply.hpp +++ b/redfish-core/lib/power_supply.hpp @@ -208,11 +208,12 @@ inline void getValidPowerSupplyPath( inline void getPowerSupplyState( const std::shared_ptr& asyncResp, - const std::string& service, const std::string& path) + const std::string& service, const std::string& path, bool available) { dbus::utility::getProperty( 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) @@ -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& asyncResp, - const std::string& service, const std::string& path) + const std::string& service, const std::string& path, bool available) { dbus::utility::getProperty( 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) @@ -251,7 +258,7 @@ inline void getPowerSupplyHealth( return; } - if (!value) + if (!value || !available) { asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::Critical; @@ -259,6 +266,31 @@ inline void getPowerSupplyHealth( }); } +inline void getPowerSupplyStateAndHealth( + const std::shared_ptr& asyncResp, + const std::string& service, const std::string& path) +{ + dbus::utility::getProperty( + 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& asyncResp, const std::string& service, const std::string& path) @@ -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);