Skip to content

Commit

Permalink
Added Device Energy Management server.cpp to all-clusters-app (#30957)
Browse files Browse the repository at this point in the history
* Fix #30665 (EVSE)
- Changed to use amperage_mA, energy_mWh
- removed max on epoch_s
- removed access for operate
- removed side for events

* Fix #30665 updates to try to get further with ZAP and autogen, but still fails with some parts of regen_all

* Added ember-compatibility-functions.cpp which was missing.

* Made all types all lowercase to resolve regen_all issues.

* Fixed lint issue (trailing whitespace).

* Added Device Energy Management server.cpp, added to all-clusters-app.zap and regen_all

* Restyled by whitespace

* Restyled by clang-format

* Fixes based on similar conversations on EVSE review. Made Forecast and PowerAdjustmentCapability Nullable attributes. Added feature support.

* Added delegate class to all-clusters-app

* Changed ChipLogProgress to Error. Better handling of EnumerateCommands

* Aligned EVSE XML to same state as PR#30857 (includes SessionID being Nullable etc and in Fault Event).

* Updated Device Energy Management XML to use power_mw, energy_mwh per spec definition.

* Updated controller-clusters.zap

* regen_all.py

* Restyled by whitespace

* Regen_all after merging in changes for XML

* Fixed types to be signed=true

* Fixed 31032 - revert removal of side="server".

* regen_all.py

* Added Device Energy Management cluster back into all-clusters.zap and regen_all after merging from master.

* Compiles but doesn't work. Needs stub to instantiate class

* Fixed EnumerateCommands to allow optional ModifyForecastRequest and RequestConstraintBasedForecast commands

* Fixed InvokeCommand issues to allow optional commands.

* Improved HandleModifyForecastRequest and HandleRequestConstraintBasedForecast in sdk

* Updates to add DeviceEnergyManagement to all-clusters.

* Compiles and links

* Sync file in energy-management-app

* Updated DEM to support SetPowerAdjustmentCapability and SetForecast methods.

* Updated based on review comments. Changed Epoch to be Matter 2000 based epochs.

* Turned on commands in DEM. Added DEM cluster server to energy-management-app.

* Added more comments to Delegate to describe expected behaviour.

* Updated BUILD.gn to remove duplicated files from all-clusters-common and energy-management-common

* Aim to fix compile issues on other platforms due to logging of %d

* Restyled by gn

* Updated build files to remove duplicate copies from all-clusters-common to energy-management-common

* Fixed ESP32 include path

* Added DEM into energy-management-app - refactored main.cpp.

* Added DEM into EVSEManufacturerImpl.h

* Fix - avoid using global namespace in header file

* Restyled by gn

* Updated CMakeLists.txt to remove duplicate energy-management files.

* Added device-energy-management-server to ESP32 all-clusters CMakeLists.txt

* Removed return at end of void function.

* Added include to all-clusters-minimal in ESP32

* Removed __FUNCTION__ from logs

* Removed stray %s

* Added FeatureMap handling in sdk (not in ember)

* Removed extra chip::

* Used CHIP_ERROR_FORMAT, err.Format() mechanism

* Refactored StartTimeAdjust based on review comments.

* Removed unnecessary Write Attributes function

* Beginnings of Session handling

* Added beginnings of EVConnected,EVNotDetected,EnergyTransferStarted,EnergyTransferStopped handling. State machine is not finished. Callback to read Energy Meter added

* Added framework for EVSE Test Event triggers

* Added EnergyEvseTestEventTrigger delegates

* Restyled by whitespace

* Restyled by gn

* Added :energy-evse-test-event-trigger to public_deps to see if it resolves build errors

* Restyled by gn

* Fixed Darwin compile error - do not use else after return

* Refactored code so that the EvseManufacturer instance could be retrieved for Test Event triggers

* Started adding TC_EEVSE_2_2.py

* Updated TC_EEVSE_2_2.py to support test events. Still needs to handle reading of Logged Events and verifying they are correct.

* Refactored Handling of TestEvents to allow clear, and better error handling.

* Refactored state handling by decomposing into state machine events where similar functions are performed based on state transition. Fixed TC chargingEnabledUntil cast to int. Note gets to step 6e

* Fixed step 6e caused by not setting the cable limit / maxHardwareCurrentLimit in test events

* Added comment to clarify purpose and definition of test eventtrigger field values.

* Fixed several bugs in test script

* Made SetChargingEnabledUntil take a nullable type.

* Removed Reference to step 5c, and moved reading of SessionID to step 4b.
More TC_EEVSE_2_2 bug fixes. Added event checking. Still fails at step 14.
Does not have enable timeout timer implemented

* Fixed issue with not detecting 2nd plug in event, and session ID not incrementing. Now test case passes all the way.

* Restyled by isort

* Made some attributes persisted per spec.

* Added attributes to zcl.json to mark them as implemented in attributeAccessInterfaceAttributes

* Ran regen_all.py after changing zcl.json

* Fixed incorrect type - not picked up by all compilers.

* Re-ran bootstrap, and then regen-all - to pick up more zap generated fixes

* Added provisional handling for Faults

* Added new test event triggers to help test Fault and Diagnostics

* Added TC_EEVSE_2_4

* Fix lint issue - unused datetime modules.

* Committed suggested change to comment

* Added TC_EEVSE_2_5.py to support DiagnosticsCommand testing. Also changed the SupplyState reverting to Disabled once diagnostics is complete to match the spec.

* Created a helper EEVSE base class to avoid repetition in the different test cases.

* Restyled by isort

* Fixed Lint issues

* Revamped TC_EEVSE_2_5 to match spec behaviour (cannot start diagnostics unless Disabled). Also removed hard-coded endpoint ids in Utils

* Implemented timer to disable the EVSE automatically.

* Added documentation to cover concern about long-lived bytespan in enableKey

* Fixed Lint and build issues on other platforms

* Restyled by isort

* Implemented some of the feedback on PR

* Refactored HwSetState to use nested switch statements to be clear that all enums are caught.

* Fixed error messages

* Test scripts: Removed hardcoded endpoint 1 (use --endpoint 1 in args), allowed the enableKey to be passed in using --hex-arg enableKey:000102030405060708090a0b0c0d0e0f

* Made enum class for callbacks and improved documentation comments based on feedback.

* Fixed another python lint issue.

* Updated README.md with help on how to build for test event triggers, using chip-repl and python testing.

* Tweaks to README.md to avoid Myst syntax highlighting issues.

* Improved error logging around GetEpochTS()

* Made main use std::unique_ptr instead of using new/delete per PR comments. Also moved GetEVSEManufacturer declaration to header file.

* Fixing MISSPELL issues in README.md

* Small change missed in main.cpp missed in unique_ptr change.

* Changed all-clusters app stubs to use unique_ptr style instead of new/delete.

* Removed unhelpful comment

* Restyled by whitespace

* Fixes #31061 Updated DEVICE_TYPE to 0x050C now this has been allocated

* Small correction to description in test case.

* Update examples/energy-management-app/energy-management-common/include/EnergyEvseDelegateImpl.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Touched file to retrigger restyled job

* Removed whitespace which was added to trigger restyled to rerun

* Removed potentially unsafe code before merging into PR #30957

* Renamed variable and replaced auto with type so it is clearer to reader.

---------

Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
3 people authored Jan 17, 2024
1 parent 09f014c commit f59323b
Show file tree
Hide file tree
Showing 37 changed files with 2,758 additions and 1,536 deletions.
233 changes: 220 additions & 13 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -3920,6 +3920,185 @@ provisional cluster ElectricalEnergyMeasurement = 145 {
readonly attribute int16u clusterRevision = 65533;
}

/** 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 2;

enum CauseEnum : enum8 {
kNormalCompletion = 0;
kOffline = 1;
kFault = 2;
kUserOptOut = 3;
}

enum CostTypeEnum : enum8 {
kFinancial = 0;
kGHGEmissions = 1;
kComfort = 2;
kTemperature = 3;
}

enum ESAStateEnum : enum8 {
kOffline = 0;
kOnline = 1;
kFault = 2;
kUserOptOut = 3;
kPowerAdjustActive = 4;
kPaused = 5;
}

enum ESATypeEnum : enum8 {
kEVSE = 0;
kSpaceHeating = 1;
kWaterHeating = 2;
kSpaceCooling = 3;
kSpaceHeatingCooling = 4;
kBatteryStorage = 5;
kSolarPV = 6;
kFridgeFreezer = 7;
kWashingMachine = 8;
kDishwasher = 9;
kCooking = 10;
kHomeWaterPump = 11;
kIrrigationWaterPump = 12;
kPoolPump = 13;
kOther = 255;
}

bitmap Feature : bitmap32 {
kPowerAdjustment = 0x1;
kPowerForecastReporting = 0x2;
kStateForecastReporting = 0x4;
kForecastAdjustment = 0x8;
}

struct CostStruct {
CostTypeEnum costType = 0;
int32s value = 1;
int8u decimalPoints = 2;
optional int16u currency = 3;
}

struct SlotStruct {
elapsed_s minDuration = 0;
elapsed_s maxDuration = 1;
elapsed_s defaultDuration = 2;
elapsed_s elapsedSlotTime = 3;
elapsed_s remainingSlotTime = 4;
boolean slotIsPauseable = 5;
elapsed_s minPauseDuration = 6;
elapsed_s maxPauseDuration = 7;
optional int16u manufacturerESAState = 8;
optional power_mw nominalPower = 9;
optional power_mw minPower = 10;
optional power_mw maxPower = 11;
optional energy_mwh nominalEnergy = 12;
optional CostStruct costs[] = 13;
optional power_mw minPowerAdjustment = 14;
optional power_mw maxPowerAdjustment = 15;
optional elapsed_s minDurationAdjustment = 16;
optional elapsed_s maxDurationAdjustment = 17;
}

struct ForecastStruct {
int16u 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;
SlotStruct slots[] = 7;
}

struct ConstraintsStruct {
epoch_s startTime = 0;
elapsed_s duration = 1;
optional power_mw nominalPower = 2;
optional energy_mwh maximumEnergy = 3;
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;
elapsed_s duration = 2;
}

info event PowerAdjustStart = 0 {
}

info event PowerAdjustEnd = 1 {
CauseEnum cause = 0;
elapsed_s duration = 1;
energy_mwh energyUse = 2;
}

info event Paused = 2 {
}

info event Resumed = 3 {
}

readonly attribute ESATypeEnum ESAType = 0;
readonly attribute boolean ESACanGenerate = 1;
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 ForecastStruct forecast = 6;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

request struct PowerAdjustRequestRequest {
power_mw power = 0;
elapsed_s duration = 1;
}

request struct StartTimeAdjustRequestRequest {
epoch_s requestedStartTime = 0;
}

request struct PauseRequestRequest {
elapsed_s duration = 0;
}

request struct ModifyForecastRequestRequest {
int32u forecastId = 0;
SlotAdjustmentStruct slotAdjustments[] = 1;
}

request struct RequestConstraintBasedForecastRequest {
ConstraintsStruct constraints[] = 0;
}

/** Allows a client to request an adjustment in the power consumption of an ESA for a specified duration. */
command PowerAdjustRequest(PowerAdjustRequestRequest): DefaultSuccess = 0;
/** Allows a client to cancel an ongoing PowerAdjustmentRequest operation. */
command CancelPowerAdjustRequest(): DefaultSuccess = 1;
/** Allows a client to adjust the start time of a Forecast sequence that has not yet started operation (i.e. where the current Forecast StartTime is in the future). */
command StartTimeAdjustRequest(StartTimeAdjustRequestRequest): DefaultSuccess = 2;
/** Allows a client to temporarily pause an operation and reduce the ESAs energy demand. */
command PauseRequest(PauseRequestRequest): DefaultSuccess = 3;
/** Allows a client to cancel the PauseRequest command and enable earlier resumption of operation. */
command ResumeRequest(): DefaultSuccess = 4;
/** Allows a client to modify a Forecast within the limits allowed by the ESA. */
command ModifyForecastRequest(ModifyForecastRequestRequest): DefaultSuccess = 5;
/** Allows a client to ask the ESA to recompute its Forecast based on power and time constraints. */
command RequestConstraintBasedForecast(RequestConstraintBasedForecastRequest): DefaultSuccess = 6;
}

/** Electric Vehicle Supply Equipment (EVSE) is equipment used to charge an Electric Vehicle (EV) or Plug-In Hybrid Electric Vehicle. This cluster provides an interface to the functionality of Electric Vehicle Supply Equipment (EVSE) management. */
provisional cluster EnergyEvse = 153 {
revision 2;
Expand Down Expand Up @@ -7737,25 +7916,53 @@ endpoint 1 {
ram attribute clusterRevision default = 1;
}

server cluster DeviceEnergyManagement {
emits event PowerAdjustStart;
emits event PowerAdjustEnd;
emits event Paused;
emits event Resumed;
callback attribute ESAType;
callback attribute ESACanGenerate;
callback attribute ESAState;
callback attribute absMinPower;
callback attribute absMaxPower;
callback attribute powerAdjustmentCapability;
callback attribute forecast;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
callback attribute featureMap;
ram attribute clusterRevision default = 2;

handle command PowerAdjustRequest;
handle command CancelPowerAdjustRequest;
handle command StartTimeAdjustRequest;
handle command PauseRequest;
handle command ResumeRequest;
handle command ModifyForecastRequest;
handle command RequestConstraintBasedForecast;
}

server cluster EnergyEvse {
callback attribute state default = 0;
callback attribute supplyState default = 0;
callback attribute faultState default = 0;
callback attribute chargingEnabledUntil default = 0;
callback attribute dischargingEnabledUntil default = 0;
callback attribute circuitCapacity default = 0;
callback attribute minimumChargeCurrent default = 6000;
callback attribute maximumChargeCurrent default = 0;
callback attribute maximumDischargeCurrent default = 0;
callback attribute userMaximumChargeCurrent default = 0;
callback attribute randomizationDelayWindow default = 600;
callback attribute state;
callback attribute supplyState;
callback attribute faultState;
callback attribute chargingEnabledUntil;
callback attribute dischargingEnabledUntil;
callback attribute circuitCapacity;
callback attribute minimumChargeCurrent;
callback attribute maximumChargeCurrent;
callback attribute maximumDischargeCurrent;
callback attribute userMaximumChargeCurrent;
callback attribute randomizationDelayWindow;
callback attribute numberOfWeeklyTargets default = 0;
callback attribute numberOfDailyTargets default = 1;
callback attribute nextChargeStartTime;
callback attribute nextChargeTargetTime;
callback attribute nextChargeRequiredEnergy;
callback attribute nextChargeTargetSoC;
callback attribute approximateEVEfficiency default = 0xFFFF;
callback attribute approximateEVEfficiency;
callback attribute stateOfCharge;
callback attribute batteryCapacity;
callback attribute vehicleID;
Expand All @@ -7767,7 +7974,7 @@ endpoint 1 {
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
ram attribute featureMap default = 0;
callback attribute featureMap;
ram attribute clusterRevision default = 2;

handle command GetTargetsResponse;
Expand Down
Loading

0 comments on commit f59323b

Please sign in to comment.