From 06eda65e3041f8d638b44b64e1a6c012d763b468 Mon Sep 17 00:00:00 2001 From: James Harrow Date: Wed, 17 Jan 2024 20:33:38 +0000 Subject: [PATCH] Added AjustmentCause to delegate API for commands that should use it. --- .../include/DeviceEnergyManagementDelegateImpl.h | 14 ++++++++------ .../src/DeviceEnergyManagementDelegateImpl.cpp | 11 ++++++----- .../device-energy-management-server.cpp | 13 +++++++------ .../device-energy-management-server.h | 13 +++++++------ 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h index 85554546b033e1..973e1e622576a4 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -36,16 +36,18 @@ namespace DeviceEnergyManagement { class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate { public: - virtual Status PowerAdjustRequest(const int64_t power, const uint32_t duration) override; + virtual Status PowerAdjustRequest(const int64_t power, const uint32_t duration, AdjustmentCauseEnum cause) override; virtual Status CancelPowerAdjustRequest() override; - virtual Status StartTimeAdjustRequest(const uint32_t requestedStartTime) override; - virtual Status PauseRequest(const uint32_t duration) override; + virtual Status StartTimeAdjustRequest(const uint32_t requestedStartTime, AdjustmentCauseEnum cause) override; + virtual Status PauseRequest(const uint32_t duration, AdjustmentCauseEnum cause) override; virtual Status ResumeRequest() override; virtual Status ModifyForecastRequest(const uint32_t forecastId, - const DataModel::DecodableList & slotAdjustments) override; - virtual Status RequestConstraintBasedForecast( - const DataModel::DecodableList & constraints) override; + const DataModel::DecodableList & slotAdjustments, + AdjustmentCauseEnum cause) override; + virtual Status + RequestConstraintBasedForecast(const DataModel::DecodableList & constraints, + AdjustmentCauseEnum cause) override; virtual Status CancelRequest() override; // ------------------------------------------------------------------ diff --git a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp index 1b3e030d21eec4..28c6b8942ff493 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -49,7 +49,7 @@ using CostsList = DataModel::List; * 6) generate a PowerAdjustEnd event with cause NormalCompletion * 7) if necessary, update the forecast with new expected end time */ -Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t power, const uint32_t duration) +Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t power, const uint32_t duration, AdjustmentCauseEnum cause) { Status status = Status::UnsupportedCommand; // Status::Success; @@ -98,7 +98,7 @@ Status DeviceEnergyManagementDelegate::CancelPowerAdjustRequest() * 1) update the forecast attribute with the revised start time * 2) send a callback notification to the appliance so it can refresh its internal schedule */ -Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t requestedStartTime) +Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t requestedStartTime, AdjustmentCauseEnum cause) { DataModel::Nullable forecast = GetForecast(); @@ -136,7 +136,7 @@ Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t req * 6) generate a Resumed event * 7) if necessary, update the forecast with new expected end time */ -Status DeviceEnergyManagementDelegate::PauseRequest(const uint32_t duration) +Status DeviceEnergyManagementDelegate::PauseRequest(const uint32_t duration, AdjustmentCauseEnum cause) { Status status = Status::UnsupportedCommand; // Status::Success; // TODO: implement the behaviour above @@ -181,7 +181,8 @@ Status DeviceEnergyManagementDelegate::ResumeRequest() * 3) notify the appliance to follow the revised schedule */ Status DeviceEnergyManagementDelegate::ModifyForecastRequest( - const uint32_t forecastId, const DataModel::DecodableList & slotAdjustments) + const uint32_t forecastId, const DataModel::DecodableList & slotAdjustments, + AdjustmentCauseEnum cause) { Status status = Status::UnsupportedCommand; // Status::Success; @@ -202,7 +203,7 @@ Status DeviceEnergyManagementDelegate::ModifyForecastRequest( * 3) notify the appliance to follow the revised schedule */ Status DeviceEnergyManagementDelegate::RequestConstraintBasedForecast( - const DataModel::DecodableList & constraints) + const DataModel::DecodableList & constraints, AdjustmentCauseEnum cause) { Status status = Status::UnsupportedCommand; // Status::Success; // TODO: implement the behaviour above diff --git a/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp b/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp index 1807fb7594ee8a..adbcad971a2077 100644 --- a/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp +++ b/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp @@ -346,7 +346,7 @@ void Instance::HandlePowerAdjustRequest(HandlerContext & ctx, const Commands::Po ChipLogProgress(Zcl, "DEM: Good PowerAdjustRequest() args."); - status = mDelegate.PowerAdjustRequest(power, durationSec); + status = mDelegate.PowerAdjustRequest(power, durationSec, adjustmentCause); ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); if (status != Status::Success) { @@ -476,7 +476,7 @@ void Instance::HandleStartTimeAdjustRequest(HandlerContext & ctx, } ChipLogProgress(Zcl, "DEM: Good requestedStartTimeEpoch %ld.", static_cast(requestedStartTimeEpoch)); - status = mDelegate.StartTimeAdjustRequest(requestedStartTimeEpoch); + status = mDelegate.StartTimeAdjustRequest(requestedStartTimeEpoch, adjustmentCause); ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); if (status != Status::Success) { @@ -574,7 +574,7 @@ void Instance::HandlePauseRequest(HandlerContext & ctx, const Commands::PauseReq return; } - status = mDelegate.PauseRequest(duration); + status = mDelegate.PauseRequest(duration, adjustmentCause); ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); if (status != Status::Success) { @@ -628,7 +628,7 @@ void Instance::HandleModifyForecastRequest(HandlerContext & ctx, const Commands: return; } - status = mDelegate.ModifyForecastRequest(forecastId, slotAdjustments); + status = mDelegate.ModifyForecastRequest(forecastId, slotAdjustments, adjustmentCause); ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); if (status != Status::Success) { @@ -642,7 +642,8 @@ void Instance::HandleRequestConstraintBasedForecast(HandlerContext & ctx, { Status status; - AdjustmentCauseEnum adjustmentCause = commandData.cause; + DataModel::DecodableList constraints = commandData.constraints; + AdjustmentCauseEnum adjustmentCause = commandData.cause; status = CheckOptOutAllowsRequest(adjustmentCause); if (status != Status::Success) @@ -652,7 +653,7 @@ void Instance::HandleRequestConstraintBasedForecast(HandlerContext & ctx, return; } - status = mDelegate.RequestConstraintBasedForecast(commandData.constraints); + status = mDelegate.RequestConstraintBasedForecast(constraints, adjustmentCause); ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); if (status != Status::Success) { diff --git a/src/app/clusters/device-energy-management-server/device-energy-management-server.h b/src/app/clusters/device-energy-management-server/device-energy-management-server.h index f5cf37cafa1034..3620379d4ed8e2 100644 --- a/src/app/clusters/device-energy-management-server/device-energy-management-server.h +++ b/src/app/clusters/device-energy-management-server/device-energy-management-server.h @@ -52,7 +52,7 @@ class Delegate * @param duration The duration that the ESA SHALL maintain the requested power for. * @return Success if the adjustment is accepted; otherwise the command SHALL be rejected with appropriate error. */ - virtual Status PowerAdjustRequest(const int64_t power, const uint32_t duration) = 0; + virtual Status PowerAdjustRequest(const int64_t power, const uint32_t duration, AdjustmentCauseEnum cause) = 0; /** * @brief Delegate SHALL make the ESA end the active power adjustment session & return to normal (or idle) power levels. @@ -76,7 +76,7 @@ class Delegate * @return Success if the StartTime in the Forecast is updated, otherwise the command SHALL be rejected with appropriate * IM_Status. */ - virtual Status StartTimeAdjustRequest(const uint32_t requestedStartTime) = 0; + virtual Status StartTimeAdjustRequest(const uint32_t requestedStartTime, AdjustmentCauseEnum cause) = 0; /** * @brief Delegate handler for PauseRequest command @@ -91,7 +91,7 @@ class Delegate * @param duration Duration that the ESA SHALL be paused for. * @return Success if the ESA is paused, otherwise returns other IM_Status. */ - virtual Status PauseRequest(const uint32_t duration) = 0; + virtual Status PauseRequest(const uint32_t duration, AdjustmentCauseEnum cause) = 0; /** * @brief Delegate handler for ResumeRequest command @@ -119,7 +119,8 @@ class Delegate * SHALL be rejected returning other IM_Status. */ virtual Status ModifyForecastRequest(const uint32_t forecastId, - const DataModel::DecodableList & slotAdjustments) = 0; + const DataModel::DecodableList & slotAdjustments, + AdjustmentCauseEnum cause) = 0; /** * @brief Delegate handler for RequestConstraintBasedForecast @@ -132,8 +133,8 @@ class Delegate * @param constraints Sequence of turn up/down power requests that the ESA is being asked to constrain its operation within. * @return Success if successful, otherwise the command SHALL be rejected returning other IM_Status. */ - virtual Status - RequestConstraintBasedForecast(const DataModel::DecodableList & constraints) = 0; + virtual Status RequestConstraintBasedForecast(const DataModel::DecodableList & constraints, + AdjustmentCauseEnum cause) = 0; /** * @brief Delegate handler for CancelRequest