Skip to content

Commit

Permalink
Added AjustmentCause to delegate API for commands that should use it.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesharrow committed Jan 17, 2024
1 parent 00d0491 commit 06eda65
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Structs::SlotAdjustmentStruct::DecodableType> & slotAdjustments) override;
virtual Status RequestConstraintBasedForecast(
const DataModel::DecodableList<Structs::ConstraintsStruct::DecodableType> & constraints) override;
const DataModel::DecodableList<Structs::SlotAdjustmentStruct::DecodableType> & slotAdjustments,
AdjustmentCauseEnum cause) override;
virtual Status
RequestConstraintBasedForecast(const DataModel::DecodableList<Structs::ConstraintsStruct::DecodableType> & constraints,
AdjustmentCauseEnum cause) override;
virtual Status CancelRequest() override;

// ------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ using CostsList = DataModel::List<const Structs::CostStruct::Type>;
* 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;

Expand Down Expand Up @@ -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<Structs::ForecastStruct::Type> forecast = GetForecast();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Structs::SlotAdjustmentStruct::DecodableType> & slotAdjustments)
const uint32_t forecastId, const DataModel::DecodableList<Structs::SlotAdjustmentStruct::DecodableType> & slotAdjustments,
AdjustmentCauseEnum cause)
{
Status status = Status::UnsupportedCommand; // Status::Success;

Expand All @@ -202,7 +203,7 @@ Status DeviceEnergyManagementDelegate::ModifyForecastRequest(
* 3) notify the appliance to follow the revised schedule
*/
Status DeviceEnergyManagementDelegate::RequestConstraintBasedForecast(
const DataModel::DecodableList<Structs::ConstraintsStruct::DecodableType> & constraints)
const DataModel::DecodableList<Structs::ConstraintsStruct::DecodableType> & constraints, AdjustmentCauseEnum cause)
{
Status status = Status::UnsupportedCommand; // Status::Success;
// TODO: implement the behaviour above
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -476,7 +476,7 @@ void Instance::HandleStartTimeAdjustRequest(HandlerContext & ctx,
}

ChipLogProgress(Zcl, "DEM: Good requestedStartTimeEpoch %ld.", static_cast<long unsigned int>(requestedStartTimeEpoch));
status = mDelegate.StartTimeAdjustRequest(requestedStartTimeEpoch);
status = mDelegate.StartTimeAdjustRequest(requestedStartTimeEpoch, adjustmentCause);
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status);
if (status != Status::Success)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -642,7 +642,8 @@ void Instance::HandleRequestConstraintBasedForecast(HandlerContext & ctx,
{
Status status;

AdjustmentCauseEnum adjustmentCause = commandData.cause;
DataModel::DecodableList<Structs::ConstraintsStruct::DecodableType> constraints = commandData.constraints;
AdjustmentCauseEnum adjustmentCause = commandData.cause;

status = CheckOptOutAllowsRequest(adjustmentCause);
if (status != Status::Success)
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -119,7 +119,8 @@ class Delegate
* SHALL be rejected returning other IM_Status.
*/
virtual Status ModifyForecastRequest(const uint32_t forecastId,
const DataModel::DecodableList<Structs::SlotAdjustmentStruct::Type> & slotAdjustments) = 0;
const DataModel::DecodableList<Structs::SlotAdjustmentStruct::Type> & slotAdjustments,
AdjustmentCauseEnum cause) = 0;

/**
* @brief Delegate handler for RequestConstraintBasedForecast
Expand All @@ -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<Structs::ConstraintsStruct::Type> & constraints) = 0;
virtual Status RequestConstraintBasedForecast(const DataModel::DecodableList<Structs::ConstraintsStruct::Type> & constraints,
AdjustmentCauseEnum cause) = 0;

/**
* @brief Delegate handler for CancelRequest
Expand Down

0 comments on commit 06eda65

Please sign in to comment.