Using sdbusplus::asio::getProperty

It simplifies a lot of code and after changing sdbusplus implementation
slightly reduces binary size if used together with:

https://gerrit.openbmc-project.xyz/c/openbmc/sdbusplus/+/49467

* Uncompressed size:    3033148 -> 3012164, -20984 B
* gzip compressed size: 1220586 -> 1214625, -5961 B

Tested:
- Redfish validator output is the same before and after the change

Change-Id: Ibe3227d3f4230de2363ba3d9396e51130c8240a5
Signed-off-by: Jonathan Doman <jonathan.doman@intel.com>
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
diff --git a/redfish-core/lib/power.hpp b/redfish-core/lib/power.hpp
index dea6be3..ad3ca8e 100644
--- a/redfish-core/lib/power.hpp
+++ b/redfish-core/lib/power.hpp
@@ -69,58 +69,47 @@
         {
             return;
         }
-        auto valueHandler = [value, sensorsAsyncResp](
-                                const boost::system::error_code ec,
-                                const dbus::utility::DbusVariantType&
-                                    powerCapEnable) {
-            if (ec)
-            {
-                messages::internalError(sensorsAsyncResp->asyncResp->res);
-                BMCWEB_LOG_ERROR << "powerCapEnable Get handler: Dbus error "
-                                 << ec;
-                return;
-            }
-            // Check PowerCapEnable
-            const bool* b = std::get_if<bool>(&powerCapEnable);
-            if (b == nullptr)
-            {
-                messages::internalError(sensorsAsyncResp->asyncResp->res);
-                BMCWEB_LOG_ERROR << "Fail to get PowerCapEnable status ";
-                return;
-            }
-            if (!(*b))
-            {
-                messages::actionNotSupported(
-                    sensorsAsyncResp->asyncResp->res,
-                    "Setting LimitInWatts when PowerLimit feature is disabled");
-                BMCWEB_LOG_ERROR << "PowerLimit feature is disabled ";
-                return;
-            }
-
-            crow::connections::systemBus->async_method_call(
-                [sensorsAsyncResp](const boost::system::error_code ec2) {
-                    if (ec2)
-                    {
-                        BMCWEB_LOG_DEBUG << "Power Limit Set: Dbus error: "
-                                         << ec2;
-                        messages::internalError(
-                            sensorsAsyncResp->asyncResp->res);
-                        return;
-                    }
-                    sensorsAsyncResp->asyncResp->res.result(
-                        boost::beast::http::status::no_content);
-                },
-                "xyz.openbmc_project.Settings",
-                "/xyz/openbmc_project/control/host0/power_cap",
-                "org.freedesktop.DBus.Properties", "Set",
-                "xyz.openbmc_project.Control.Power.Cap", "PowerCap",
-                dbus::utility::DbusVariantType(*value));
-        };
-        crow::connections::systemBus->async_method_call(
-            std::move(valueHandler), "xyz.openbmc_project.Settings",
+        sdbusplus::asio::getProperty<bool>(
+            *crow::connections::systemBus, "xyz.openbmc_project.Settings",
             "/xyz/openbmc_project/control/host0/power_cap",
-            "org.freedesktop.DBus.Properties", "Get",
-            "xyz.openbmc_project.Control.Power.Cap", "PowerCapEnable");
+            "xyz.openbmc_project.Control.Power.Cap", "PowerCapEnable",
+            [value, sensorsAsyncResp](const boost::system::error_code ec,
+                                      bool powerCapEnable) {
+                if (ec)
+                {
+                    messages::internalError(sensorsAsyncResp->asyncResp->res);
+                    BMCWEB_LOG_ERROR
+                        << "powerCapEnable Get handler: Dbus error " << ec;
+                    return;
+                }
+                if (!powerCapEnable)
+                {
+                    messages::actionNotSupported(
+                        sensorsAsyncResp->asyncResp->res,
+                        "Setting LimitInWatts when PowerLimit feature is disabled");
+                    BMCWEB_LOG_ERROR << "PowerLimit feature is disabled ";
+                    return;
+                }
+
+                crow::connections::systemBus->async_method_call(
+                    [sensorsAsyncResp](const boost::system::error_code ec2) {
+                        if (ec2)
+                        {
+                            BMCWEB_LOG_DEBUG << "Power Limit Set: Dbus error: "
+                                             << ec2;
+                            messages::internalError(
+                                sensorsAsyncResp->asyncResp->res);
+                            return;
+                        }
+                        sensorsAsyncResp->asyncResp->res.result(
+                            boost::beast::http::status::no_content);
+                    },
+                    "xyz.openbmc_project.Settings",
+                    "/xyz/openbmc_project/control/host0/power_cap",
+                    "org.freedesktop.DBus.Properties", "Set",
+                    "xyz.openbmc_project.Control.Power.Cap", "PowerCap",
+                    std::variant<uint32_t>(*value));
+            });
     };
     getValidChassisPath(sensorsAsyncResp, std::move(getChassisPath));
 }