Skip to content

Commit

Permalink
Update device-energy-management-cluster.xml based on latest cluster s…
Browse files Browse the repository at this point in the history
…pec (#33771)

* Update device-energy-management-cluster.xml based on latest cluster spec and regenerate zap files

* Restyled by clang-format

* Address comments from Boris Zbarsky

* Address some further useful comments from Boris Zbarsky

* Restyled by clang-format

* Merge from master and regenerate zap files

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Dec 3, 2024
1 parent 4571df2 commit 6cd68bd
Show file tree
Hide file tree
Showing 46 changed files with 1,749 additions and 857 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4069,7 +4069,7 @@ cluster ElectricalEnergyMeasurement = 145 {

/** This cluster allows a client to manage the power draw of a device. An example of such a client could be an Energy Management System (EMS) which controls an Energy Smart Appliance (ESA). */
provisional cluster DeviceEnergyManagement = 152 {
revision 3;
revision 4;

enum AdjustmentCauseEnum : enum8 {
kLocalOptimization = 0;
Expand Down Expand Up @@ -4130,6 +4130,12 @@ provisional cluster DeviceEnergyManagement = 152 {
kOptOut = 3;
}

enum PowerAdjustReasonEnum : enum8 {
kNoAdjustment = 0;
kLocalOptimizationAdjustment = 1;
kGridOptimizationAdjustment = 2;
}

bitmap Feature : bitmap32 {
kPowerAdjustment = 0x1;
kPowerForecastReporting = 0x2;
Expand All @@ -4147,13 +4153,25 @@ provisional cluster DeviceEnergyManagement = 152 {
optional int16u currency = 3;
}

struct PowerAdjustStruct {
power_mw minPower = 0;
power_mw maxPower = 1;
elapsed_s minDuration = 2;
elapsed_s maxDuration = 3;
}

struct PowerAdjustCapabilityStruct {
nullable PowerAdjustStruct powerAdjustCapability[] = 0;
PowerAdjustReasonEnum cause = 1;
}

struct SlotStruct {
elapsed_s minDuration = 0;
elapsed_s maxDuration = 1;
elapsed_s defaultDuration = 2;
elapsed_s elapsedSlotTime = 3;
elapsed_s remainingSlotTime = 4;
optional boolean slotIsPauseable = 5;
optional boolean slotIsPausable = 5;
optional elapsed_s minPauseDuration = 6;
optional elapsed_s maxPauseDuration = 7;
optional int16u manufacturerESAState = 8;
Expand All @@ -4169,13 +4187,13 @@ provisional cluster DeviceEnergyManagement = 152 {
}

struct ForecastStruct {
int16u forecastId = 0;
int32u forecastID = 0;
nullable int16u activeSlotNumber = 1;
epoch_s startTime = 2;
epoch_s endTime = 3;
optional nullable epoch_s earliestStartTime = 4;
optional epoch_s latestEndTime = 5;
boolean isPauseable = 6;
boolean isPausable = 6;
SlotStruct slots[] = 7;
ForecastUpdateReasonEnum forecastUpdateReason = 8;
}
Expand All @@ -4188,16 +4206,9 @@ provisional cluster DeviceEnergyManagement = 152 {
optional int8s loadControl = 4;
}

struct PowerAdjustStruct {
power_mw minPower = 0;
power_mw maxPower = 1;
elapsed_s minDuration = 2;
elapsed_s maxDuration = 3;
}

struct SlotAdjustmentStruct {
int8u slotIndex = 0;
power_mw nominalPower = 1;
optional power_mw nominalPower = 1;
elapsed_s duration = 2;
}

Expand All @@ -4222,7 +4233,7 @@ provisional cluster DeviceEnergyManagement = 152 {
readonly attribute ESAStateEnum ESAState = 2;
readonly attribute power_mw absMinPower = 3;
readonly attribute power_mw absMaxPower = 4;
readonly attribute optional nullable PowerAdjustStruct powerAdjustmentCapability[] = 5;
readonly attribute optional nullable PowerAdjustCapabilityStruct powerAdjustmentCapability = 5;
readonly attribute optional nullable ForecastStruct forecast = 6;
readonly attribute optional OptOutStateEnum optOutState = 7;
readonly attribute command_id generatedCommandList[] = 65528;
Expand All @@ -4249,7 +4260,7 @@ provisional cluster DeviceEnergyManagement = 152 {
}

request struct ModifyForecastRequestRequest {
int32u forecastId = 0;
int32u forecastID = 0;
SlotAdjustmentStruct slotAdjustments[] = 1;
AdjustmentCauseEnum cause = 2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ cluster ElectricalEnergyMeasurement = 145 {

/** This cluster allows a client to manage the power draw of a device. An example of such a client could be an Energy Management System (EMS) which controls an Energy Smart Appliance (ESA). */
provisional cluster DeviceEnergyManagement = 152 {
revision 3;
revision 4;

enum AdjustmentCauseEnum : enum8 {
kLocalOptimization = 0;
Expand Down Expand Up @@ -1491,6 +1491,12 @@ provisional cluster DeviceEnergyManagement = 152 {
kOptOut = 3;
}

enum PowerAdjustReasonEnum : enum8 {
kNoAdjustment = 0;
kLocalOptimizationAdjustment = 1;
kGridOptimizationAdjustment = 2;
}

bitmap Feature : bitmap32 {
kPowerAdjustment = 0x1;
kPowerForecastReporting = 0x2;
Expand All @@ -1508,13 +1514,25 @@ provisional cluster DeviceEnergyManagement = 152 {
optional int16u currency = 3;
}

struct PowerAdjustStruct {
power_mw minPower = 0;
power_mw maxPower = 1;
elapsed_s minDuration = 2;
elapsed_s maxDuration = 3;
}

struct PowerAdjustCapabilityStruct {
nullable PowerAdjustStruct powerAdjustCapability[] = 0;
PowerAdjustReasonEnum cause = 1;
}

struct SlotStruct {
elapsed_s minDuration = 0;
elapsed_s maxDuration = 1;
elapsed_s defaultDuration = 2;
elapsed_s elapsedSlotTime = 3;
elapsed_s remainingSlotTime = 4;
optional boolean slotIsPauseable = 5;
optional boolean slotIsPausable = 5;
optional elapsed_s minPauseDuration = 6;
optional elapsed_s maxPauseDuration = 7;
optional int16u manufacturerESAState = 8;
Expand All @@ -1530,13 +1548,13 @@ provisional cluster DeviceEnergyManagement = 152 {
}

struct ForecastStruct {
int16u forecastId = 0;
int32u forecastID = 0;
nullable int16u activeSlotNumber = 1;
epoch_s startTime = 2;
epoch_s endTime = 3;
optional nullable epoch_s earliestStartTime = 4;
optional epoch_s latestEndTime = 5;
boolean isPauseable = 6;
boolean isPausable = 6;
SlotStruct slots[] = 7;
ForecastUpdateReasonEnum forecastUpdateReason = 8;
}
Expand All @@ -1549,16 +1567,9 @@ provisional cluster DeviceEnergyManagement = 152 {
optional int8s loadControl = 4;
}

struct PowerAdjustStruct {
power_mw minPower = 0;
power_mw maxPower = 1;
elapsed_s minDuration = 2;
elapsed_s maxDuration = 3;
}

struct SlotAdjustmentStruct {
int8u slotIndex = 0;
power_mw nominalPower = 1;
optional power_mw nominalPower = 1;
elapsed_s duration = 2;
}

Expand All @@ -1583,7 +1594,7 @@ provisional cluster DeviceEnergyManagement = 152 {
readonly attribute ESAStateEnum ESAState = 2;
readonly attribute power_mw absMinPower = 3;
readonly attribute power_mw absMaxPower = 4;
readonly attribute optional nullable PowerAdjustStruct powerAdjustmentCapability[] = 5;
readonly attribute optional nullable PowerAdjustCapabilityStruct powerAdjustmentCapability = 5;
readonly attribute optional nullable ForecastStruct forecast = 6;
readonly attribute optional OptOutStateEnum optOutState = 7;
readonly attribute command_id generatedCommandList[] = 65528;
Expand All @@ -1610,7 +1621,7 @@ provisional cluster DeviceEnergyManagement = 152 {
}

request struct ModifyForecastRequestRequest {
int32u forecastId = 0;
int32u forecastID = 0;
SlotAdjustmentStruct slotAdjustments[] = 1;
AdjustmentCauseEnum cause = 2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate
virtual CHIP_ERROR SetAbsMaxPower(int64_t) override;
virtual CHIP_ERROR SetPowerAdjustmentCapability(Attributes::PowerAdjustmentCapability::TypeInfo::Type) override;
virtual CHIP_ERROR SetForecast(DataModel::Nullable<Structs::ForecastStruct::Type>) override;
virtual CHIP_ERROR SetOptOutState(OptOutStateEnum) override;

private:
ESATypeEnum mEsaType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,8 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetForecast(DataModel::Nullable<Struc

return CHIP_NO_ERROR;
}

CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newValue)
{
return CHIP_NO_ERROR;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@
{ ZAP_EMPTY_DEFAULT(), 0x00000002, 1, ZAP_TYPE(ENUM8), ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) }, /* ESAState */ \
{ ZAP_EMPTY_DEFAULT(), 0x00000003, 8, ZAP_TYPE(POWER_MW), ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) }, /* AbsMinPower */ \
{ ZAP_EMPTY_DEFAULT(), 0x00000004, 8, ZAP_TYPE(POWER_MW), ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) }, /* AbsMaxPower */ \
{ ZAP_EMPTY_DEFAULT(), 0x00000005, 0, ZAP_TYPE(ARRAY), \
{ ZAP_EMPTY_DEFAULT(), 0x00000005, 0, ZAP_TYPE(STRUCT), \
ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) | ZAP_ATTRIBUTE_MASK(NULLABLE) }, /* PowerAdjustmentCapability */ \
{ ZAP_EMPTY_DEFAULT(), 0x00000006, 0, ZAP_TYPE(STRUCT), \
ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) | ZAP_ATTRIBUTE_MASK(NULLABLE) }, /* Forecast */ \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <app-common/zap-generated/cluster-objects.h>
#include <app/TestEventTriggerDelegate.h>

/**
* @brief User handler for handling the test event trigger
*
* @note If TestEventTrigger is enabled, it needs to be implemented in the app
*
* @param eventTrigger Event trigger to handle
*
* @retval true on success
* @retval false if error happened
*/
bool HandleDeviceEnergyManagementTestEventTrigger(uint64_t eventTrigger);

namespace chip {

/*
* These Test EventTrigger values can be used to produce artificial DEM forecasts
*
* They are sent along with the enableKey (manufacturer defined secret)
* in the General Diagnostic cluster TestEventTrigger command
*/
enum class DeviceEnergyManagementTrigger : uint64_t
{
// Simulate a fixed forecast power usage including one or more PowerAdjustmentStructs
kPowerAdjustment = 0x0098'0000'0000'0000,
// Clear the PowerAdjustment structs
kPowerAdjustmentClear = 0x0098'0000'0000'0001,
// Simulate user opt-out of Local Optimization
kUserOptOutLocalOptimization = 0x0098'0000'0000'0002,
// Simulate user opt-out of Grid Optimization
kUserOptOutGridOptimization = 0x0098'0000'0000'0003,
// Remove all user opt-out opting out
kUserOptOutClearAll = 0x0098'0000'0000'0004,
// Simulate a fixed forecast with EarliestStartTime earlier than startTime, and LatestEndTime greater than EndTime
kStartTimeAdjustment = 0x0098'0000'0000'0005,
// Clear the StartTimeAdjustment simulated forecast
kStartTimeAdjustmentClear = 0x0098'0000'0000'0006,
// Simulate a fixed forecast with one pausable slo with MinPauseDuration >1, MaxPauseDuration>1 and one non pausable slot
kPausable = 0x0098'0000'0000'0007,
// Simulate a moving time to the next forecast slot
kPausableNextSlot = 0x0098'0000'0000'0008,
// Clear the Pausable simulated forecast
kPausableClear = 0x0098'0000'0000'0009,
// Simulate a forecast power usage with at least 2 and at most 4 slots
kForecastAdjustment = 0x0098'0000'0000'000A,
// Simulate moving time to the next forecast slot
kForecastAdjustmentNextSlot = 0x0098'0000'0000'000B,
// Clear the forecast adjustment
kForecastAdjustmentClear = 0x0098'0000'0000'000C,
// Simulate a forecast power usage with at least 2 and at most 4 slots
kConstraintBasedAdjustment = 0x0098'0000'0000'000D,
// Clear the constraint based adjustment
kConstraintBasedAdjustmentClear = 0x0098'0000'0000'000E,
// Simulate a forecast with at least 1 slot
kForecast = 0x0098'0000'0000'000F,
// Clear the forecast
kForecastClear = 0x0098'0000'0000'0010,
};

class DeviceEnergyManagementTestEventTriggerHandler : public TestEventTriggerHandler
{
public:
DeviceEnergyManagementTestEventTriggerHandler() {}

CHIP_ERROR HandleEventTrigger(uint64_t eventTrigger) override
{
if (HandleDeviceEnergyManagementTestEventTrigger(eventTrigger))
{
return CHIP_NO_ERROR;
}
return CHIP_ERROR_INVALID_ARGUMENT;
}
};

} // namespace chip
Loading

0 comments on commit 6cd68bd

Please sign in to comment.