From 90ac94bf61adf5fabb5874d2aed44e6707dc9731 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 13 Jun 2024 20:20:30 +0100 Subject: [PATCH 01/74] Get the EVSE app building and test TC_DEM_2_2 passing --- .../all-clusters-app/ameba/chip_main.cmake | 2 + examples/all-clusters-app/asr/BUILD.gn | 2 + .../all-clusters-app/cc13x4_26x4/BUILD.gn | 2 + .../all-clusters-app/infineon/psoc6/BUILD.gn | 2 + examples/all-clusters-app/linux/BUILD.gn | 2 + examples/all-clusters-app/mbed/CMakeLists.txt | 3 +- .../nrfconnect/CMakeLists.txt | 2 + examples/all-clusters-app/nxp/mw320/BUILD.gn | 2 + .../openiotsdk/CMakeLists.txt | 4 +- .../all-clusters-app/telink/CMakeLists.txt | 4 +- examples/all-clusters-app/tizen/BUILD.gn | 2 + .../include/DEMManufacturerDelegate.h | 104 +++ .../include/DEMUtils.h | 56 ++ .../DeviceEnergyManagementDelegateImpl.h | 199 ++++- .../include/DeviceEnergyManagementManager.h | 11 +- .../include/EVSEManufacturerImpl.h | 53 +- .../EnergyManagementAppCmdLineOptions.h | 25 + .../include/FakeReadings.h | 120 +++ .../src/DEMTestEventTriggers.cpp | 392 ++++++++++ .../energy-management-common/src/DEMUtils.cpp | 116 +++ .../DeviceEnergyManagementDelegateImpl.cpp | 719 ++++++++++++++++-- .../src/DeviceEnergyManagementManager.cpp | 15 + .../src/EVSEManufacturerImpl.cpp | 369 +-------- .../src/EnergyEvseEventTriggers.cpp | 184 +++++ .../src/EnergyEvseMain.cpp | 19 +- .../src/EnergyReportingEventTriggers.cpp | 85 +++ .../src/FakeReadings.cpp | 185 +++++ .../esp32/main/CMakeLists.txt | 1 + .../energy-management-app/esp32/main/main.cpp | 14 + examples/energy-management-app/linux/BUILD.gn | 15 +- .../energy-management-app/linux/README.md | 32 + examples/energy-management-app/linux/args.gni | 1 + examples/energy-management-app/linux/main.cpp | 83 +- examples/platform/linux/AppMain.cpp | 7 + examples/platform/linux/BUILD.gn | 7 + examples/shell/shell_common/BUILD.gn | 5 +- src/app/chip_data_model.gni | 6 + .../device-energy-management-server.h | 8 +- src/python_testing/TC_DEM_2_2.py | 312 ++++++++ src/python_testing/TC_DEM_Utils.py | 223 ++++++ src/python_testing/matter_testing_support.py | 9 + 41 files changed, 2984 insertions(+), 418 deletions(-) create mode 100644 examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h create mode 100644 examples/energy-management-app/energy-management-common/include/DEMUtils.h create mode 100644 examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h create mode 100644 examples/energy-management-app/energy-management-common/include/FakeReadings.h create mode 100644 examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp create mode 100644 examples/energy-management-app/energy-management-common/src/DEMUtils.cpp create mode 100644 examples/energy-management-app/energy-management-common/src/EnergyEvseEventTriggers.cpp create mode 100644 examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp create mode 100644 examples/energy-management-app/energy-management-common/src/FakeReadings.cpp create mode 100644 src/python_testing/TC_DEM_2_2.py create mode 100644 src/python_testing/TC_DEM_Utils.py diff --git a/examples/all-clusters-app/ameba/chip_main.cmake b/examples/all-clusters-app/ameba/chip_main.cmake index 2afdd4e8d70942..e9c55f3de32120 100755 --- a/examples/all-clusters-app/ameba/chip_main.cmake +++ b/examples/all-clusters-app/ameba/chip_main.cmake @@ -189,9 +189,11 @@ list( ${chip_dir}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp + ${chip_dir}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp + ${chip_dir}/examples/energy-management-app/energy-management-common/src/utils.cpp ${chip_dir}/examples/platform/ameba/route_hook/ameba_route_hook.c ${chip_dir}/examples/platform/ameba/route_hook/ameba_route_table.c diff --git a/examples/all-clusters-app/asr/BUILD.gn b/examples/all-clusters-app/asr/BUILD.gn index 6f70452fa71bbe..a1fd16aec7e988 100755 --- a/examples/all-clusters-app/asr/BUILD.gn +++ b/examples/all-clusters-app/asr/BUILD.gn @@ -84,9 +84,11 @@ asr_executable("clusters_app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/utils.cpp", "${examples_plat_dir}/ButtonHandler.cpp", "${examples_plat_dir}/CHIPDeviceManager.cpp", "${examples_plat_dir}/LEDWidget.cpp", diff --git a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn index 4a60c7992b197e..cf749b38f612ec 100644 --- a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn +++ b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn @@ -77,6 +77,8 @@ ti_simplelink_executable("all-clusters-app") { "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/utils.cpp", "${chip_root}/examples/providers/DeviceInfoProviderImpl.cpp", "${project_dir}/main/AppTask.cpp", "${project_dir}/main/ClusterManager.cpp", diff --git a/examples/all-clusters-app/infineon/psoc6/BUILD.gn b/examples/all-clusters-app/infineon/psoc6/BUILD.gn index 9a0fbe3b3b37ac..68e33a28506aed 100644 --- a/examples/all-clusters-app/infineon/psoc6/BUILD.gn +++ b/examples/all-clusters-app/infineon/psoc6/BUILD.gn @@ -120,9 +120,11 @@ psoc6_executable("clusters_app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/utils.cpp", "${examples_plat_dir}/LEDWidget.cpp", "${examples_plat_dir}/init_psoc6Platform.cpp", "src/AppTask.cpp", diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index 3d52ef748de90d..fa11cfad1b16e7 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -60,11 +60,13 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/all-clusters-app/linux/diagnostic-logs-provider-delegate-impl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/device-energy-management-mode.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/energy-evse-mode.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/utils.cpp", "AllClustersCommandDelegate.cpp", "AppOptions.cpp", "ValveControlDelegate.cpp", diff --git a/examples/all-clusters-app/mbed/CMakeLists.txt b/examples/all-clusters-app/mbed/CMakeLists.txt index 3d1a179a93bbb2..a80d159e1a5e63 100644 --- a/examples/all-clusters-app/mbed/CMakeLists.txt +++ b/examples/all-clusters-app/mbed/CMakeLists.txt @@ -77,7 +77,8 @@ target_sources(${APP_TARGET} PRIVATE ${ENERGY_MANAGEMENT_COMMON}/src/EnergyEvseManager.cpp ${ENERGY_MANAGEMENT_COMMON}/src/DeviceEnergyManagementDelegateImpl.cpp ${ENERGY_MANAGEMENT_COMMON}/src/DeviceEnergyManagementManager.cpp - + ${ENERGY_MANAGEMENT_COMMON}/src/EVSEManufacturerImpl.cpp + ${ENERGY_MANAGEMENT_COMMON}/src/utils.cpp ) chip_configure_data_model(${APP_TARGET} diff --git a/examples/all-clusters-app/nrfconnect/CMakeLists.txt b/examples/all-clusters-app/nrfconnect/CMakeLists.txt index 563295e059b46c..7301361b97ed6f 100644 --- a/examples/all-clusters-app/nrfconnect/CMakeLists.txt +++ b/examples/all-clusters-app/nrfconnect/CMakeLists.txt @@ -72,6 +72,8 @@ target_sources(app PRIVATE ${ALL_CLUSTERS_COMMON_DIR}/src/resource-monitoring-delegates.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DeviceEnergyManagementDelegateImpl.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DeviceEnergyManagementManager.cpp + ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EVSEManufacturerImpl.cpp + ${ENERGY_MANAGEMENT_COMMON_DIR}/src/utils.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/ElectricalPowerMeasurementDelegate.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EnergyEvseDelegateImpl.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EnergyEvseManager.cpp diff --git a/examples/all-clusters-app/nxp/mw320/BUILD.gn b/examples/all-clusters-app/nxp/mw320/BUILD.gn index 65d2df0401dd62..51c30eb190a9fb 100644 --- a/examples/all-clusters-app/nxp/mw320/BUILD.gn +++ b/examples/all-clusters-app/nxp/mw320/BUILD.gn @@ -88,9 +88,11 @@ mw320_executable("shell_mw320") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/utils.cpp", "${chip_root}/src/lib/shell/streamer_mw320.cpp", "binding-handler.cpp", "include/CHIPProjectConfig.h", diff --git a/examples/all-clusters-app/openiotsdk/CMakeLists.txt b/examples/all-clusters-app/openiotsdk/CMakeLists.txt index 6d2fb76c0db919..f3d98c4b64dd34 100644 --- a/examples/all-clusters-app/openiotsdk/CMakeLists.txt +++ b/examples/all-clusters-app/openiotsdk/CMakeLists.txt @@ -69,7 +69,9 @@ target_sources(${APP_TARGET} ${ENERGY_MANAGEMENT_COMMON}/src/EnergyEvseDelegateImpl.cpp ${ENERGY_MANAGEMENT_COMMON}/src/EnergyEvseManager.cpp ${ENERGY_MANAGEMENT_COMMON}/src/DeviceEnergyManagementDelegateImpl.cpp - ${ENERGY_MANAGEMENT_COMMON}/src/DeviceEnergyManagementManager.cpp + ${ENERGY_MANAGEMENT_COMMON}/src/DeviceEnergyManagementManager.cpp + ${ENERGY_MANAGEMENT_COMMON}/src/EVSEManufacturerImpl.cpp + ${ENERGY_MANAGEMENT_COMMON}/src/utils.cpp ) target_link_libraries(${APP_TARGET} diff --git a/examples/all-clusters-app/telink/CMakeLists.txt b/examples/all-clusters-app/telink/CMakeLists.txt index d5f2132c9d2747..58a6bb82963314 100644 --- a/examples/all-clusters-app/telink/CMakeLists.txt +++ b/examples/all-clusters-app/telink/CMakeLists.txt @@ -55,7 +55,9 @@ target_sources(app PRIVATE ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EnergyEvseDelegateImpl.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EnergyEvseManager.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DeviceEnergyManagementDelegateImpl.cpp - ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DeviceEnergyManagementManager.cpp + ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DeviceEnergyManagementManager.cpp + ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EVSEManufacturerImpl.cpp + ${ENERGY_MANAGEMENT_COMMON_DIR}/src/utils.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp ${TELINK_COMMON}/util/src/LEDManager.cpp diff --git a/examples/all-clusters-app/tizen/BUILD.gn b/examples/all-clusters-app/tizen/BUILD.gn index 364e9ce857d5da..7a3ae2a0546a39 100644 --- a/examples/all-clusters-app/tizen/BUILD.gn +++ b/examples/all-clusters-app/tizen/BUILD.gn @@ -40,9 +40,11 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/utils.cpp", ] deps = [ diff --git a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h new file mode 100644 index 00000000000000..4aa0d5f322c253 --- /dev/null +++ b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h @@ -0,0 +1,104 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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 + +using chip::Protocols::InteractionModel::Status; + +namespace chip { +namespace app { +namespace Clusters { +namespace DeviceEnergyManagement { + +class DeviceEnergyManagementDelegate; + +/** + * Class to abstract manufacturer specific functionality + */ +class DEMManufacturerDelegate +{ +public: + DEMManufacturerDelegate() + { + } + + virtual ~DEMManufacturerDelegate() + { + } + + virtual int64_t GetEnergyUse() = 0; + + virtual CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t power, const uint32_t duration, AdjustmentCauseEnum cause) + { + return CHIP_NO_ERROR; + } + + virtual CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustCompletion() + { + return CHIP_NO_ERROR; + } + + virtual CHIP_ERROR HandleDeviceEnergyManagementCancelPowerAdjustRequest(CauseEnum cause) + { + return CHIP_NO_ERROR; + } + + virtual CHIP_ERROR HandleDeviceEnergyManagementStartTimeAdjustRequest(const uint32_t requestedStartTime, AdjustmentCauseEnum cause) + { + return CHIP_NO_ERROR; + } + + virtual CHIP_ERROR HandleDeviceEnergyManagementPauseRequest(const uint32_t duration, AdjustmentCauseEnum cause) + { + return CHIP_NO_ERROR; + } + + virtual CHIP_ERROR HandleDeviceEnergyManagementPauseCompletion() + { + return CHIP_NO_ERROR; + } + + virtual CHIP_ERROR HandleDeviceEnergyManagementCancelPauseRequest(CauseEnum cause) + { + return CHIP_NO_ERROR; + } + + virtual CHIP_ERROR HandleDeviceEnergyManagementCancelRequest() + { + return CHIP_NO_ERROR; + } + + virtual CHIP_ERROR HandleModifyRequest(const uint32_t forecastID, + const DataModel::DecodableList & slotAdjustments, + AdjustmentCauseEnum cause) + { + return CHIP_NO_ERROR; + } + + virtual CHIP_ERROR RequestConstraintBasedForecast(const DataModel::DecodableList & constraints, + AdjustmentCauseEnum cause) + { + return CHIP_NO_ERROR; + } +}; + +} // namespace DeviceEnergyManagement +} // namespace Clusters +} // namespace app +} // namespace chip + diff --git a/examples/energy-management-app/energy-management-common/include/DEMUtils.h b/examples/energy-management-app/energy-management-common/include/DEMUtils.h new file mode 100644 index 00000000000000..66bc155a679c9f --- /dev/null +++ b/examples/energy-management-app/energy-management-common/include/DEMUtils.h @@ -0,0 +1,56 @@ +/* + * + * Copyright (c) 2024 Project CHIP Authors + * All rights reserved. + * + * 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 +#include +#include +#include + +using chip::Protocols::InteractionModel::Status; + +/** + * @brief Helper function to get current timestamp in Epoch format + * + * @param chipEpoch reference to hold return timestamp + */ +CHIP_ERROR UtilsGetEpochTS(uint32_t & chipEpoch); + +/** + * @brief Helper function to get current timestamp and work out the day of week + * + * NOTE that the time_t is converted using localtime to provide the timestamp + * in local time. If this is not supported on some platforms an alternative + * implementation may be required. + * + * @param unixEpoch (as time_t) + * + * @return bitmap value for day of week + * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) + */ +uint8_t UtilsGetDayOfWeekUnixEpoch(time_t unixEpoch); + +/** + * @brief Helper function to get current timestamp and work out the day of week based on localtime + * + * @param reference to hold the day of week as a bitmap + * + * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) + */ +CHIP_ERROR UtilsGetDayOfWeekNow(uint8_t & dayOfWeekMap); 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 1248fc405a3c8a..f993a2efca3d6a 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -18,10 +18,9 @@ #pragma once -#include "app/clusters/device-energy-management-server/device-energy-management-server.h" - #include -#include +#include + using chip::Protocols::InteractionModel::Status; namespace chip { @@ -29,58 +28,232 @@ namespace app { namespace Clusters { namespace DeviceEnergyManagement { +class DEMManufacturerDelegate; + /** * The application delegate. */ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate { public: + DeviceEnergyManagementDelegate(); + + void SetDeviceEnergyManagementInstance(DeviceEnergyManagement::Instance & instance); + + void SetDemManufacturerDelegate(DEMManufacturerDelegate & deviceEnergyManagementManufacturerDelegate); + + /** + * + * Implement the DeviceEnergyManagement::Delegate interface + * + */ + + /** + * @brief Implements a handler to begin to adjust client power + * consumption/generation to the level requested. + * + * @param power Milli-Watts the ESA SHALL use during the adjustment period. + * @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, AdjustmentCauseEnum cause) override; + + /** + * @brief Make the ESA end the active power adjustment session & return to normal (or idle) power levels. + * The ESA SHALL also generate an PowerAdjustEnd Event and the ESAState SHALL be restored to Online. + * + * @return It should report SUCCESS if successful and FAILURE otherwise. + */ virtual Status CancelPowerAdjustRequest() override; + + /** + * @brief The ESA SHALL update its Forecast attribute with the RequestedStartTime including a new ForecastID. + * + * If the ESA supports ForecastAdjustment, and the ESAState is not UserOptOut and the RequestedStartTime is after + * the EarliestStartTime and the resulting EndTime is before the LatestEndTime, then ESA SHALL accept the request + * to modify the Start Time. + * A client can estimate the entire Forecast sequence duration by computing the EndTime - StartTime fields from the + * Forecast attribute, and therefore avoid scheduling the start time too late. + * + * @param requestedStartTime The requested start time in UTC that the client would like the appliance to shift its power + * forecast to. + * @param cause Who (Grid/local) is triggering this change. + * + * @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, AdjustmentCauseEnum cause) override; + + /** + * @brief Handler for PauseRequest command + * + * If the ESA supports FA and the SlotIsPauseable field is true in the ActiveSlotNumber + * index in the Slots list, and the ESAState is not UserOptOut then the ESA SHALL allow its current + * operation to be Paused. + * + * During this state the ESA SHALL not consume or produce significant power (other than required to keep its + * basic control system operational). + * + * @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, AdjustmentCauseEnum cause) override; + + /** + * @brief Handler for ResumeRequest command + * + * If the ESA supports FA and it is currently Paused then the ESA SHALL resume its operation. + * The ESA SHALL also generate a Resumed Event and the ESAState SHALL be updated accordingly to + * reflect its current state. + * + * @return Success if the ESA is resumed, otherwise returns other IM_Status. + */ virtual Status ResumeRequest() override; + + /** + * @brief Handler for ModifyForecastRequest + * + * If the ESA supports FA, and the ESAState is not UserOptOut it SHALL attempt to adjust its power forecast. + * This allows a one or more modifications in a single command by sending a list of modifications (one for each 'slot'). + * Attempts to modify slots which have already past, SHALL result in the entire command being rejected. + * If the ESA accepts the requested Forecast then it SHALL update its Forecast attribute (incrementing its ForecastID) + * and run the revised Forecast as its new intended operation. + * + * @param forecastID Indicates the ESA ForecastID that is to be modified. + * @param slotAdjustments List of adjustments to be applied to the ESA, corresponding to the expected ESA forecastID. + * @return Success if the entire list of SlotAdjustmentStruct are accepted, otherwise the command + * SHALL be rejected returning other IM_Status. + */ virtual Status - ModifyForecastRequest(const uint32_t forecastId, + ModifyForecastRequest(const uint32_t forecastID, const DataModel::DecodableList & slotAdjustments, AdjustmentCauseEnum cause) override; + + /** + * @brief Handler for RequestConstraintBasedForecast + * + * The ESA SHALL inspect the requested power limits to ensure that there are no overlapping elements. The ESA + * manufacturer may also reject the request if it could cause the user’s preferences to be breached (e.g. may + * cause the home to be too hot or too cold, or a battery to be insufficiently charged). + * If the ESA can meet the requested power limits, it SHALL regenerate a new Power Forecast with a new ForecastID. + * + * @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, AdjustmentCauseEnum cause) override; + + /** + * @brief Handler for CancelRequest + * + * The ESA SHALL attempt to cancel the effects of any previous adjustment request commands, and re-evaluate its + * forecast for intended operation ignoring those previous requests. + * + * If the ESA ForecastStruct ForecastUpdateReason was already `Internal Optimization`, then the command SHALL + * be rejected with FAILURE. + * + * If the command is accepted, the ESA SHALL update its ESAState if required, and the command status returned + * SHALL be SUCCESS. + * + * The ESA SHALL update its Forecast attribute to match its new intended operation, and update the + * ForecastStruct.ForecastUpdateReason to `Internal Optimization` + * + * @return Success if successful, otherwise the command SHALL be rejected returning other IM_Status. + */ virtual Status CancelRequest() override; // ------------------------------------------------------------------ - // Get attribute methods + // Overridden DeviceEnergyManagement::Delegate Get attribute methods virtual ESATypeEnum GetESAType() override; virtual bool GetESACanGenerate() override; virtual ESAStateEnum GetESAState() override; virtual int64_t GetAbsMinPower() override; virtual int64_t GetAbsMaxPower() override; - virtual Attributes::PowerAdjustmentCapability::TypeInfo::Type GetPowerAdjustmentCapability() override; - virtual DataModel::Nullable GetForecast() override; + virtual DataModel::Nullable & GetPowerAdjustmentCapability() override; + virtual DataModel::Nullable & GetForecast() override; virtual OptOutStateEnum GetOptOutState() override; // ------------------------------------------------------------------ - // Set attribute methods + // Overridden DeviceEnergyManagement::Delegate Set attribute methods virtual CHIP_ERROR SetESAType(ESATypeEnum) override; virtual CHIP_ERROR SetESACanGenerate(bool) override; virtual CHIP_ERROR SetESAState(ESAStateEnum) override; virtual CHIP_ERROR SetAbsMinPower(int64_t) override; virtual CHIP_ERROR SetAbsMaxPower(int64_t) override; - virtual CHIP_ERROR SetPowerAdjustmentCapability(Attributes::PowerAdjustmentCapability::TypeInfo::Type) override; - virtual CHIP_ERROR SetForecast(DataModel::Nullable) override; + virtual CHIP_ERROR SetPowerAdjustmentCapability(DataModel::Nullable &) override; + virtual CHIP_ERROR SetForecast(DataModel::Nullable &) override; virtual CHIP_ERROR SetOptOutState(OptOutStateEnum) override; + // Returns whether the DeviceEnergyManagement is supported + uint32_t HasFeature(Feature feature) const; + +private: + /** + * @brief Handle a PowerAdjustRequest failing + * + * Cleans up the PowerAdjust state should the request fail + */ + void HandlePowerAdjustRequestFailure(); + + // Methods to handle when a PowerAdjustment completes + static void PowerAdjustTimerExpiry(System::Layer * systemLayer, void * delegate); + void HandlePowerAdjustTimerExpiry(); + + // Method to cancel a PowerAdjustment + CHIP_ERROR CancelPowerAdjustRequestAndSendEvent(CauseEnum cause); + + // Method to send a PowerAdjustEnd event + CHIP_ERROR SendPowerAdjustEndEvent(CauseEnum cause); + + /** + * @brief Handle a PauseRequest failing + * + * Cleans up the state should the PauseRequest fail + */ + void HandlePauseRequestFailure(); + + // Methods to handle when a PauseRequest completes + static void PauseRequestTimerExpiry(System::Layer * systemLayer, void * delegate); + void HandlePauseRequestTimerExpiry(); + + // Method to cancel a PauseRequest + CHIP_ERROR CancelPauseRequestAndSendEvent(CauseEnum cause); + + // Method to send a Paused event + CHIP_ERROR SendResumedEvent(CauseEnum cause); + private: + // Have a pointer to partner instance object + DeviceEnergyManagement::Instance *mpDEMInstance; + + // The DEMManufacturerDelegate object knows how to handle + // manufacturer/product specific operations + DEMManufacturerDelegate *mpDEMManufacturerDelegate; + + // Various attributes ESATypeEnum mEsaType; bool mEsaCanGenerate; ESAStateEnum mEsaState; int64_t mAbsMinPower; int64_t mAbsMaxPower; - Attributes::PowerAdjustmentCapability::TypeInfo::Type mPowerAdjustmentCapability; + OptOutStateEnum mOptOutState; + + DataModel::Nullable mPowerAdjustCapabilityStruct; + DataModel::Nullable mForecast; - // Default to NoOptOut - OptOutStateEnum mOptOutState = OptOutStateEnum::kNoOptOut; + + // Keep track whether a PowerAdjustment is in progress + bool mPowerAdjustmentInProgress; + + // Keep track of when that PowerAdjustment started + uint32_t mPowerAdjustmentStartTime; + + // Keep track whether a PauseRequest is in progress + bool mPauseRequestInProgress; + + // Keep track of when that PauseRequest started + uint32_t mPauseRequestStartTime; }; } // namespace DeviceEnergyManagement diff --git a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h index aec875ff0d1f99..5098f665c500e1 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h @@ -18,24 +18,21 @@ #pragma once -#include -#include #include #include +#include namespace chip { namespace app { namespace Clusters { + using namespace chip::app::Clusters::DeviceEnergyManagement; + class DeviceEnergyManagementManager : public Instance { public: - DeviceEnergyManagementManager(EndpointId aEndpointId, DeviceEnergyManagementDelegate & aDelegate, Feature aFeature) : - DeviceEnergyManagement::Instance(aEndpointId, aDelegate, aFeature) - { - mDelegate = &aDelegate; - } + DeviceEnergyManagementManager(EndpointId aEndpointId, DeviceEnergyManagementDelegate & aDelegate, Feature aFeature); // Delete copy constructor and assignment operator. DeviceEnergyManagementManager(const DeviceEnergyManagementManager &) = delete; diff --git a/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h b/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h index 23994e7f5d9454..179b4a0efee35a 100644 --- a/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h +++ b/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h @@ -19,6 +19,7 @@ #pragma once #include +#include #include #include #include @@ -33,20 +34,32 @@ namespace EnergyEvse { * The EVSEManufacturer example class */ -class EVSEManufacturer +class EVSEManufacturer: public DEMManufacturerDelegate { public: EVSEManufacturer(EnergyEvseManager * aEvseInstance, ElectricalPowerMeasurement::ElectricalPowerMeasurementInstance * aEPMInstance, - PowerTopology::PowerTopologyInstance * aPTInstance) + PowerTopology::PowerTopologyInstance * aPTInstance, DeviceEnergyManagementManager * aDEMInstance) { mEvseInstance = aEvseInstance; mEPMInstance = aEPMInstance; mPTInstance = aPTInstance; + mDEMInstance = aDEMInstance; + } + + virtual ~EVSEManufacturer() + { + } + + EnergyEvseManager * GetEvseInstance() + { + return mEvseInstance; + } + + ElectricalPowerMeasurement::ElectricalPowerMeasurementInstance * GetEPMInstance() + { + return mEPMInstance; } - EnergyEvseManager * GetEvseInstance() { return mEvseInstance; } - ElectricalPowerMeasurement::ElectricalPowerMeasurementInstance * GetEPMInstance() { return mEPMInstance; } - PowerTopology::PowerTopologyInstance * GetPTInstance() { return mPTInstance; } EnergyEvseDelegate * GetEvseDelegate() { @@ -75,6 +88,35 @@ class EVSEManufacturer return nullptr; } + DeviceEnergyManagementDelegate * GetDEMDelegate() + { + if (mDEMInstance) + { + return mDEMInstance->GetDelegate(); + } + return nullptr; + } + + /** + * + * Implement the DEMManufacturerDelegate interface + * + */ + int64_t GetEnergyUse() override; + CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t power, const uint32_t duration, AdjustmentCauseEnum cause) override; + CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustCompletion() override; + CHIP_ERROR HandleDeviceEnergyManagementCancelPowerAdjustRequest(CauseEnum cause) override; + CHIP_ERROR HandleDeviceEnergyManagementStartTimeAdjustRequest(const uint32_t requestedStartTime, AdjustmentCauseEnum cause) override; + CHIP_ERROR HandleDeviceEnergyManagementPauseRequest(const uint32_t duration, AdjustmentCauseEnum cause) override; + CHIP_ERROR HandleDeviceEnergyManagementPauseCompletion() override; + CHIP_ERROR HandleDeviceEnergyManagementCancelPauseRequest(CauseEnum cause) override; + CHIP_ERROR HandleDeviceEnergyManagementCancelRequest() override; + CHIP_ERROR HandleModifyRequest(const uint32_t forecastID, + const DataModel::DecodableList & slotAdjustments, + AdjustmentCauseEnum cause) override; + CHIP_ERROR RequestConstraintBasedForecast(const DataModel::DecodableList & constraints, + AdjustmentCauseEnum cause) override; + /** * @brief Called at start up to apply hardware settings */ @@ -172,6 +214,7 @@ class EVSEManufacturer EnergyEvseManager * mEvseInstance; ElectricalPowerMeasurement::ElectricalPowerMeasurementInstance * mEPMInstance; PowerTopology::PowerTopologyInstance * mPTInstance; + DeviceEnergyManagementManager * mDEMInstance; int64_t mLastChargingEnergyMeter = 0; int64_t mLastDischargingEnergyMeter = 0; diff --git a/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h b/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h new file mode 100644 index 00000000000000..fc64112e34e961 --- /dev/null +++ b/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h @@ -0,0 +1,25 @@ +/* + * + * Copyright (c) 2024 Project CHIP Authors + * All rights reserved. + * + * 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 +#include + +chip::BitMask GetFeatureMap(); + diff --git a/examples/energy-management-app/energy-management-common/include/FakeReadings.h b/examples/energy-management-app/energy-management-common/include/FakeReadings.h new file mode 100644 index 00000000000000..4d17b5b3b37594 --- /dev/null +++ b/examples/energy-management-app/energy-management-common/include/FakeReadings.h @@ -0,0 +1,120 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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 +#include +#include + +#define MAX_SLOTS 10 + + +class FakeReadings +{ +public: + static FakeReadings & GetInstance(); + + /** + * @brief Starts a fake load/generator to periodically callback the power and energy + * clusters. + * @param[in] aEndpointId - which endpoint is the meter to be updated on + * @param[in] aPower_mW - the mean power of the load + * Positive power indicates Imported energy (e.g. a load) + * Negative power indicated Exported energy (e.g. a generator) + * @param[in] aPowerRandomness_mW This is used to define the max randomness of the + * random power values around the mean power of the load + * @param[in] aVoltage_mV - the nominal voltage measurement + * @param[in] aVoltageRandomness_mV This is used to define the max randomness of the + * random voltage values + * @param[in] aCurrent_mA - the nominal current measurement + * @param[in] aCurrentRandomness_mA This is used to define the max randomness of the + * random current values + * @param[in] aInterval_s - the callback interval in seconds + * @param[in] bReset - boolean: true will reset the energy values to 0 + */ + void StartFakeReadings(chip::EndpointId aEndpointId, int64_t aPower_mW, uint32_t aPowerRandomness_mW, + int64_t aVoltage_mV, uint32_t aVoltageRandomness_mV, int64_t aCurrent_mA, + uint32_t aCurrentRandomness_mA, uint8_t aInterval_s, bool bReset); + + /** + * @brief Stops any active updates to the fake load data callbacks + */ + void StopFakeReadings(); + + /** + * @brief Sends fake meter data into the cluster and restarts the timer + */ + void FakeReadingsUpdate(); + + /** + * @brief Timer expiry callback to handle fake load + */ + static void FakeReadingsTimerExpiry(chip::System::Layer * systemLayer, void * manufacturer); + + CHIP_ERROR ConfigureForecast(uint16_t numSlots); + +private: + FakeReadings(); + ~FakeReadings(); + +private: + /* If enabled then the timer callback will re-trigger */ + bool bEnabled; + + /* Which endpoint the meter is on */ + chip::EndpointId mEndpointId; + + /* Interval in seconds to callback */ + uint8_t mInterval_s; + + /* Active Power on the load in mW (signed value) +ve = imported */ + int64_t mPower_mW; + + /* The amount to randomize the Power on the load in mW */ + uint32_t mPowerRandomness_mW; + + /* Voltage reading in mV (signed value) */ + int64_t mVoltage_mV; + + /* The amount to randomize the Voltage in mV */ + uint32_t mVoltageRandomness_mV; + + /* ActiveCurrent reading in mA (signed value) */ + int64_t mCurrent_mA; + + /* The amount to randomize the ActiveCurrent in mA */ + uint32_t mCurrentRandomness_mA; + + /* These energy values can only be positive values. However the underlying + * energy type (power_mWh) is signed, so keeping with that convention. + */ + + /* Cumulative Energy Imported which is updated if mPower > 0 */ + int64_t mTotalEnergyImported = 0; + + /* Cumulative Energy Imported which is updated if mPower < 0 */ + int64_t mTotalEnergyExported = 0; + + /* Periodic Energy Imported which is updated if mPower > 0 */ + int64_t mPeriodicEnergyImported = 0; + + /* Periodic Energy Imported which is updated if mPower < 0 */ + int64_t mPeriodicEnergyExported = 0; +}; + diff --git a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp new file mode 100644 index 00000000000000..72cf4f2e6a1b7f --- /dev/null +++ b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp @@ -0,0 +1,392 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +#include +#include +#include + +#include + +#include "FakeReadings.h" + +using namespace chip; +using namespace chip::app; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::DeviceEnergyManagement; + +#define MAX_SLOTS 10 +static chip::app::Clusters::DeviceEnergyManagement::Structs::SlotStruct::Type sSlots[MAX_SLOTS]; +static chip::app::Clusters::DeviceEnergyManagement::Structs::ForecastStruct::Type sForecastStruct; +static chip::app::DataModel::Nullable sForecast; + +#define MAX_POWER_ADJUSTMENTS 5 +static chip::app::Clusters::DeviceEnergyManagement::Structs::PowerAdjustStruct::Type sPowerAdjustments[MAX_POWER_ADJUSTMENTS]; +static chip::app::Clusters::DeviceEnergyManagement::Structs::PowerAdjustCapabilityStruct::Type sPowerAdjustCapabilityStruct; +static chip::app::DataModel::Nullable sPowerAdjustmentCapability; + +DeviceEnergyManagementDelegate * GetDEMDelegate() +{ + EVSEManufacturer * mn = GetEvseManufacturer(); + VerifyOrDieWithMsg(mn != nullptr, AppServer, "EVSEManufacturer is null"); + DeviceEnergyManagementDelegate * dg = mn->GetDEMDelegate(); + VerifyOrDieWithMsg(dg != nullptr, AppServer, "DEM Delegate is null"); + + return dg; +} + +CHIP_ERROR ConfigureForecast(uint16_t numSlots) +{ + uint32_t chipEpoch = 0; + + CHIP_ERROR err = UtilsGetEpochTS(chipEpoch); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Support, "ConfigureForecast could not get time"); + return err; + } + + // planned start time, in UTC, for the entire Forecast. + sForecastStruct.startTime = static_cast(chipEpoch); + + // earliest start time, in UTC, that the entire Forecast can be shifted to. null value indicates that it can be started + // immediately. + sForecastStruct.earliestStartTime = Optional>{ DataModel::Nullable{ chipEpoch } }; + + // planned end time, in UTC, for the entire Forecast. + sForecastStruct.endTime = static_cast(chipEpoch * 3); + + // latest end time, in UTC, for the entire Forecast + sForecastStruct.latestEndTime = Optional(static_cast(chipEpoch * 3)); + + sForecastStruct.isPausable = true; + + sForecastStruct.activeSlotNumber.SetNonNull(0); + + sSlots[0].minDuration = 10; + sSlots[0].maxDuration = 20; + sSlots[0].defaultDuration = 15; + sSlots[0].elapsedSlotTime = 0; + sSlots[0].remainingSlotTime = 0; + + sSlots[0].slotIsPausable.SetValue(true); + sSlots[0].minPauseDuration.SetValue(10); + sSlots[0].maxPauseDuration.SetValue(60); + + if (GetDEMDelegate()->HasFeature(DeviceEnergyManagement::Feature::kPowerForecastReporting)) + { + sSlots[0].nominalPower.SetValue(1500); + sSlots[0].minPower.SetValue(1000); + sSlots[0].maxPower.SetValue(2000); + } + + sSlots[0].nominalEnergy.SetValue(2000); + + if (GetDEMDelegate()->HasFeature(DeviceEnergyManagement::Feature::kStateForecastReporting)) + { + sSlots[0].manufacturerESAState.SetValue(23); + } + + for (uint16_t slotNo = 1; slotNo < numSlots; slotNo++) + { + sSlots[slotNo].minDuration = 2 * sSlots[slotNo - 1].minDuration; + sSlots[slotNo].maxDuration = 2 * sSlots[slotNo - 1].maxDuration; + sSlots[slotNo].defaultDuration = 2 * sSlots[slotNo - 1].defaultDuration; + sSlots[slotNo].elapsedSlotTime = 2 * sSlots[slotNo - 1].elapsedSlotTime; + sSlots[slotNo].remainingSlotTime = 2 * sSlots[slotNo - 1].remainingSlotTime; + + // Need slotNo == 1 not to be pausible for test DEM 2.4 step 3b + sSlots[slotNo].slotIsPausable.SetValue((slotNo & 1) == 0 ? true : false); + sSlots[slotNo].minPauseDuration.SetValue(2 * sSlots[slotNo - 1].slotIsPausable.Value()); + sSlots[slotNo].maxPauseDuration.SetValue(2 * sSlots[slotNo - 1].maxPauseDuration.Value()); + + if (GetDEMDelegate()->HasFeature(DeviceEnergyManagement::Feature::kPowerForecastReporting)) + { + sSlots[slotNo].nominalPower.SetValue(2 * sSlots[slotNo - 1].nominalPower.Value()); + sSlots[slotNo].minPower.SetValue(2 * sSlots[slotNo - 1].minPower.Value()); + sSlots[slotNo].maxPower.SetValue(2 * sSlots[slotNo - 1].maxPower.Value()); + + sSlots[slotNo].nominalEnergy.SetValue(2 * sSlots[slotNo - 1].nominalEnergy.Value()); + } + + if (GetDEMDelegate()->HasFeature(DeviceEnergyManagement::Feature::kStateForecastReporting)) + { + sSlots[slotNo].manufacturerESAState.SetValue(sSlots[slotNo - 1].manufacturerESAState.Value() + 1); + } + } + + sForecastStruct.slots = DataModel::List(sSlots, numSlots); + + DataModel::Nullable forecast(sForecastStruct); + + EVSEManufacturer * mn = GetEvseManufacturer(); + mn->GetDEMDelegate()->SetForecast(forecast); + + mn->GetDEMDelegate()->SetAbsMinPower(1000); + mn->GetDEMDelegate()->SetAbsMaxPower(256 * 2000 * 1000); + + return CHIP_NO_ERROR; +} + + + +void SetTestEventTrigger_PowerAdjustment() +{ + sPowerAdjustments[0].minPower = 5000 * 1000; // 5kW + sPowerAdjustments[0].maxPower = 30000 * 1000; // 30kW + sPowerAdjustments[0].minDuration = 10; // 30s + sPowerAdjustments[0].maxDuration = 60; // 60s + + DataModel::List powerAdjustmentList(sPowerAdjustments, 1); + + sPowerAdjustCapabilityStruct.cause = PowerAdjustReasonEnum::kNoAdjustment; + sPowerAdjustCapabilityStruct.powerAdjustCapability.SetNonNull(powerAdjustmentList); + + DataModel::Nullable powerAdjustmentCapability(sPowerAdjustCapabilityStruct); + sPowerAdjustmentCapability.SetNonNull(sPowerAdjustCapabilityStruct); + + CHIP_ERROR err = GetDEMDelegate()->SetPowerAdjustmentCapability(sPowerAdjustmentCapability); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Support, "SetTestEventTrigger_PowerAdjustment failed %s", chip::ErrorStr(err)); + } +} + +void SetTestEventTrigger_ClearForecast() +{ + sPowerAdjustments[0].minPower = 0; + sPowerAdjustments[0].maxPower = 0; + sPowerAdjustments[0].minDuration = 0; + sPowerAdjustments[0].maxDuration = 0; + + DataModel::List powerAdjustmentList(sPowerAdjustments, 1); + + sPowerAdjustCapabilityStruct.powerAdjustCapability.SetNonNull(powerAdjustmentList); + sPowerAdjustCapabilityStruct.cause = PowerAdjustReasonEnum::kNoAdjustment; + + DataModel::Nullable powerAdjustmentCapabilityStruct(sPowerAdjustCapabilityStruct); + + CHIP_ERROR err = GetDEMDelegate()->SetPowerAdjustmentCapability(powerAdjustmentCapabilityStruct); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Support, "SetTestEventTrigger_PowerAdjustment failed %s", chip::ErrorStr(err)); + } +} + +void SetTestEventTrigger_StartTimeAdjustment() +{ + ConfigureForecast(2); + + // Get the current forecast ad update the earliestStartTime and latestEndTime + sForecastStruct = GetDEMDelegate()->GetForecast().Value(); + + uint32_t chipEpoch = 0; + + CHIP_ERROR err = UtilsGetEpochTS(chipEpoch); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Support, "ConfigureForecast_EarliestStartLatestEndTimes could not get time"); + } + + // planned start time, in UTC, for the entire Forecast. + sForecastStruct.startTime = static_cast(chipEpoch); + + // Set the earliest start time, in UTC, to that before the startTime + sForecastStruct.earliestStartTime = Optional>{ DataModel::Nullable{ chipEpoch - 60 } }; + + // Planned end time, in UTC, for the entire Forecast. + sForecastStruct.endTime = static_cast(chipEpoch * 3); + + // Latest end time, in UTC, for the entire Forecast which is > sForecastStruct.endTime + sForecastStruct.latestEndTime = Optional(static_cast(chipEpoch * 3 + 60)); + + DataModel::Nullable forecast(sForecastStruct); + + GetDEMDelegate()->SetForecast(forecast); +} + +void SetTestEventTrigger_StartTimeAdjustmentClear() +{ + // Get the current forecast ad update the earliestStartTime and latestEndTime + sForecastStruct = GetDEMDelegate()->GetForecast().Value(); + + sForecastStruct.startTime = static_cast(0); + sForecastStruct.endTime = static_cast(0); + + sForecastStruct.earliestStartTime = Optional>(); + sForecastStruct.latestEndTime = Optional(); + + DataModel::Nullable forecast(sForecastStruct); + + GetDEMDelegate()->SetForecast(forecast); +} + +void SetTestEventTrigger_UserOptOutOptimization(OptOutStateEnum optOutState) +{ + GetDEMDelegate()->SetOptOutState(optOutState); +} + +void SetTestEventTrigger_Pausable() +{ + ConfigureForecast(2); +} + +void SetTestEventTrigger_PausableNextSlot() +{ + // Get the current forecast ad update the active slot number + sForecastStruct = GetDEMDelegate()->GetForecast().Value(); + sForecastStruct.activeSlotNumber.SetNonNull(1); + + DataModel::Nullable forecast(sForecastStruct); + + GetDEMDelegate()->SetForecast(forecast); +} + +void SetTestEventTrigger_Forecast() +{ + ConfigureForecast(2); +} + +void SetTestEventTrigger_ForecastClear() +{ + sForecastStruct.startTime = 0; + sForecastStruct.endTime = 0; + sForecastStruct.earliestStartTime.ClearValue(); + sForecastStruct.latestEndTime.ClearValue(); + sForecastStruct.isPausable = false; + sForecastStruct.activeSlotNumber.SetNull(); + sForecastStruct.slots = DataModel::List(); + + DataModel::Nullable forecast(sForecastStruct); + + GetDEMDelegate()->SetForecast(forecast); +} + +void SetTestEventTrigger_ForecastAdjustment() +{ + ConfigureForecast(2); + + // The following values need to match the equivalent values in src/python_testing/TC_DEM_2_5.py + sForecastStruct = GetDEMDelegate()->GetForecast().Value(); + sSlots[0].minPowerAdjustment.SetValue(20); + sSlots[0].maxPowerAdjustment.SetValue(2000); + sSlots[0].minDurationAdjustment.SetValue(120); + sSlots[0].maxDurationAdjustment.SetValue(240); + + sForecastStruct.slots = DataModel::List(sSlots, 2); + + DataModel::Nullable forecast(sForecastStruct); + + GetDEMDelegate()->SetForecast(forecast); +} + +void SetTestEventTrigger_ForecastAdjustmentNextSlot() +{ + sForecastStruct = GetDEMDelegate()->GetForecast().Value(); + sForecastStruct.activeSlotNumber.SetNonNull(sForecastStruct.activeSlotNumber.Value() + 1); + DataModel::Nullable forecast(sForecastStruct); + + GetDEMDelegate()->SetForecast(forecast); +} + +void SetTestEventTrigger_ConstraintBasedAdjustment() +{ + ConfigureForecast(4); +} + +bool HandleDeviceEnergyManagementTestEventTrigger(uint64_t eventTrigger) +{ + ChipLogError(Zcl,"HandleDeviceEnergyManagementTestEventTrigger"); + DeviceEnergyManagementTrigger trigger = static_cast(eventTrigger); + + switch (trigger) + { + case DeviceEnergyManagementTrigger::kPowerAdjustment: + ChipLogProgress(Support, "[PowerAdjustment-Test-Event] => Simulate a fixed forecast power usage including one or more PowerAdjustmentStructs"); + SetTestEventTrigger_PowerAdjustment(); + break; + case DeviceEnergyManagementTrigger::kPowerAdjustmentClear: + ChipLogProgress(Support, "[PowerAdjustmentClear-Test-Event] => Clear the PowerAdjustment structs"); + SetTestEventTrigger_ClearForecast(); + break; + case DeviceEnergyManagementTrigger::kUserOptOutLocalOptimization: + ChipLogProgress(Support, "[UserOptOutLocalOptimization-Test-Event] => Simulate user opt-out of Local Optimization"); + SetTestEventTrigger_UserOptOutOptimization(OptOutStateEnum::kLocalOptOut); + break; + case DeviceEnergyManagementTrigger::kUserOptOutGridOptimization: + ChipLogProgress(Support, "[UserOptOutGrisOptimization-Test-Event] => Simulate user opt-out of Grid Optimization"); + SetTestEventTrigger_UserOptOutOptimization(OptOutStateEnum::kGridOptOut); + break; + case DeviceEnergyManagementTrigger::kUserOptOutClearAll: + ChipLogProgress(Support, "[UserOptOutClearAll-Test-Event] => Remove all user opt-out opting out"); + SetTestEventTrigger_UserOptOutOptimization(OptOutStateEnum::kNoOptOut); + break; + case DeviceEnergyManagementTrigger::kStartTimeAdjustment: + ChipLogProgress(Support, "[StartTimeAdjustment-Test-Event] => Simulate a fixed forecast with EarliestStartTime earlier than startTime, and LatestEndTime greater than EndTime"); + SetTestEventTrigger_StartTimeAdjustment(); + break; + case DeviceEnergyManagementTrigger::kStartTimeAdjustmentClear: + ChipLogProgress(Support, "[StartTimeAdjustmentClear-Test-Event] => Clear the StartTimeAdjustment simulated forecast"); + SetTestEventTrigger_StartTimeAdjustmentClear(); + break; + case DeviceEnergyManagementTrigger::kPausable: + ChipLogProgress(Support, "[Pausable-Test-Event] => Simulate a fixed forecast with one pausable slot with MinPauseDuration >1, MaxPauseDuration>1 and one non pausable slot"); + SetTestEventTrigger_Pausable(); + break; + case DeviceEnergyManagementTrigger::kPausableNextSlot: + ChipLogProgress(Support, "[PausableNextSlot-Test-Event] => Simulate a moving time to the next forecast slot"); + SetTestEventTrigger_PausableNextSlot(); + break; + case DeviceEnergyManagementTrigger::kPausableClear: + ChipLogProgress(Support, "[PausableClear-Test-Event] => Clear the Pausable simulated forecast"); + SetTestEventTrigger_ClearForecast(); + break; + case DeviceEnergyManagementTrigger::kForecastAdjustment: + ChipLogProgress(Support, "[ForecastAdjustment-Test-Event] => Simulate a forecast power usage with at least 2 and at most 4 slots"); + SetTestEventTrigger_ForecastAdjustment(); + break; + case DeviceEnergyManagementTrigger::kForecastAdjustmentNextSlot: + ChipLogProgress(Support, "[ForecastAdjustmentNextSlot-Test-Event] => Simulate moving time to the next forecast slot"); + SetTestEventTrigger_ForecastAdjustmentNextSlot(); + break; + case DeviceEnergyManagementTrigger::kForecastAdjustmentClear: + ChipLogProgress(Support, "[ForecastAdjustmentClear-Test-Event] => Clear the forecast adjustment"); + SetTestEventTrigger_ClearForecast(); + break; + case DeviceEnergyManagementTrigger::kConstraintBasedAdjustment: + ChipLogProgress(Support, "[ConstraintBasedAdjustment-Test-Event] => Simulate a forecast power usage with at least 2 and at most 4 slots"); + SetTestEventTrigger_ConstraintBasedAdjustment(); + break; + case DeviceEnergyManagementTrigger::kConstraintBasedAdjustmentClear: + ChipLogProgress(Support, "[ConstraintBasedAdjustmentClear-Test-Event] => Clear the constraint based adjustment"); + SetTestEventTrigger_ClearForecast(); + break; + case DeviceEnergyManagementTrigger::kForecast: + ChipLogProgress(Support, "[Forecast-Test-Event] => Create a forecast with at least 1 slot"); + SetTestEventTrigger_Forecast(); + break; + case DeviceEnergyManagementTrigger::kForecastClear: + ChipLogProgress(Support, "[ForecastClear-Test-Event] => Clear the forecast"); + SetTestEventTrigger_ForecastClear(); + break; + + default: + return false; + } + + return true; +} diff --git a/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp b/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp new file mode 100644 index 00000000000000..165486c41a4573 --- /dev/null +++ b/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp @@ -0,0 +1,116 @@ +/* + * + * Copyright (c) 2024 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +#include +#include +#include +#include + +using namespace chip; +using namespace chip::app; +using namespace chip::app::DataModel; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::EnergyEvse; +using namespace chip::app::Clusters::EnergyEvse::Attributes; + +using chip::app::LogEvent; +using chip::Protocols::InteractionModel::Status; + +/** + * @brief Helper function to get current timestamp in Epoch format + * + * @param chipEpoch reference to hold return timestamp + */ +CHIP_ERROR UtilsGetEpochTS(uint32_t & chipEpoch) +{ + chipEpoch = 0; + + System::Clock::Milliseconds64 cTMs; + CHIP_ERROR err = System::SystemClock().GetClock_RealTimeMS(cTMs); + + /* If the GetClock_RealTimeMS returns CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE, then + * This platform cannot ever report real time ! + * This should not be certifiable since getting time is a Mandatory + * feature of EVSE Cluster + */ + VerifyOrDie(err != CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); + + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "EVSE: Unable to get current time - err:%" CHIP_ERROR_FORMAT, err.Format()); + return err; + } + + auto unixEpoch = std::chrono::duration_cast(cTMs).count(); + if (!UnixEpochToChipEpochTime(unixEpoch, chipEpoch)) + { + ChipLogError(Zcl, "EVSE: unable to convert Unix Epoch time to Matter Epoch Time"); + return err; + } + + return CHIP_NO_ERROR; +} + +/** + * @brief Helper function to get current timestamp and work out the day of week + * + * NOTE that the time_t is converted using localtime to provide the timestamp + * in local time. If this is not supported on some platforms an alternative + * implementation may be required. + * + * @param unixEpoch (as time_t) + * + * @return bitmap value for day of week + * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) + */ +uint8_t UtilsGetDayOfWeekUnixEpoch(time_t unixEpoch) +{ + // Define a timezone structure and initialize it to the local timezone + // This will capture any daylight saving time changes + struct tm local_time; + localtime_r(&unixEpoch, &local_time); + + // Get the day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday) + uint8_t dayOfWeek = static_cast(local_time.tm_wday); + + // Calculate the bitmap value based on the day of the week + uint8_t bitmap = static_cast(1 << dayOfWeek); + + return bitmap; +} +/** + * @brief Helper function to get current timestamp and work out the day of week based on localtime + * + * @param reference to hold the day of week as a bitmap + * + * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) + */ +CHIP_ERROR UtilsGetDayOfWeekNow(uint8_t & dayOfWeekMap) +{ + chip::System::Clock::Milliseconds64 cTMs; + CHIP_ERROR err = chip::System::SystemClock().GetClock_RealTimeMS(cTMs); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "EVSE: unable to get current time to check user schedules error=%" CHIP_ERROR_FORMAT, err.Format()); + return err; + } + time_t unixEpoch = std::chrono::duration_cast(cTMs).count(); + dayOfWeekMap = UtilsGetDayOfWeekUnixEpoch(unixEpoch); + + return CHIP_NO_ERROR; +} 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 8f122bdac2b046..6c49f008cc535d 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -17,7 +17,8 @@ */ #include "DeviceEnergyManagementDelegateImpl.h" - +#include "DEMManufacturerDelegate.h" +#include "DEMUtils.h" #include using namespace chip; @@ -27,9 +28,45 @@ using namespace chip::app::Clusters::DeviceEnergyManagement; using namespace chip::app::Clusters::DeviceEnergyManagement::Attributes; using chip::Optional; -using namespace chip::app; using CostsList = DataModel::List; +DeviceEnergyManagementDelegate::DeviceEnergyManagementDelegate(): + mpDEMManufacturerDelegate(nullptr), + mEsaType(ESATypeEnum::kEvse), + mEsaCanGenerate(false), + mEsaState(ESAStateEnum::kOffline), + mAbsMinPower(0), + mAbsMaxPower(0), + mOptOutState(OptOutStateEnum::kNoOptOut), + mPowerAdjustmentInProgress(false), + mPowerAdjustmentStartTime(0), + mPauseRequestInProgress(false), + mPauseRequestStartTime(0) +{ +} + +void DeviceEnergyManagementDelegate::SetDeviceEnergyManagementInstance(DeviceEnergyManagement::Instance & instance) +{ + mpDEMInstance = &instance; +} + +uint32_t DeviceEnergyManagementDelegate::HasFeature(Feature feature) const +{ + bool hasFeature = false; + + if (mpDEMInstance != nullptr) + { + hasFeature = mpDEMInstance->HasFeature(feature); + } + + return hasFeature; +} + +void DeviceEnergyManagementDelegate::SetDemManufacturerDelegate(DEMManufacturerDelegate & deviceEnergyManagementManufacturerDelegate) +{ + mpDEMManufacturerDelegate = &deviceEnergyManagementManufacturerDelegate; +} + /** * @brief Delegate handler for PowerAdjustRequest * @@ -49,25 +86,151 @@ using CostsList = DataModel::List; */ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t power, const uint32_t duration, AdjustmentCauseEnum cause) { - Status status = Status::UnsupportedCommand; // Status::Success; + bool sendEvent = false; - // TODO: implement - mEsaState = ESAStateEnum::kPowerAdjustActive; + // If a timer is running, cancel it so we can start it with the new duration + if (mPowerAdjustmentInProgress) + { + DeviceLayer::SystemLayer().CancelTimer(PowerAdjustTimerExpiry, this); + } + else + { + // Going to start a new power adjustment so will need to send an event + sendEvent = true; + + // Record when this PowerAdjustment starts. Note if we do not set this value if a PowerAdjustment is in progress + CHIP_ERROR err = UtilsGetEpochTS(mPowerAdjustmentStartTime); + if (err != CHIP_NO_ERROR) + { + ChipLogError(AppServer, "Unable to get time: %" CHIP_ERROR_FORMAT, err.Format()); + return Status::Failure; + } + } - // TODO: Generate a PowerAdjustStart Event, then begins to adjust its power - // When done, raise PowerAdjustEnd & ESAState set to kOnline. + // Update the forecast with the new expected end time + if (mpDEMManufacturerDelegate != nullptr) + { + CHIP_ERROR err = mpDEMManufacturerDelegate->HandleDeviceEnergyManagementPowerAdjustRequest(power, duration, cause); + if (err != CHIP_NO_ERROR) + { + return Status::Failure; + } + } - MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, ESAState::Id); + SetESAState(ESAStateEnum::kPowerAdjustActive); - return status; + switch (cause) + { + case AdjustmentCauseEnum::kLocalOptimization: + mPowerAdjustCapabilityStruct.Value().cause = PowerAdjustReasonEnum::kLocalOptimizationAdjustment; + break; + + case AdjustmentCauseEnum::kGridOptimization: + mPowerAdjustCapabilityStruct.Value().cause = PowerAdjustReasonEnum::kGridOptimizationAdjustment; + break; + + default: + HandlePowerAdjustRequestFailure(); + return Status::Failure; + } + + // Remember we have a timer running so we don't send a PowerAdjustStart event should another request come + // in before this timer expires + mPowerAdjustmentInProgress = true; + + CHIP_ERROR err = DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(duration), PowerAdjustTimerExpiry, this); + if (err != CHIP_NO_ERROR) + { + // TODO: Note: should the PowerAdjust just initiated be cancelled because an Event could not be logged? + ChipLogError(AppServer, "Unable to start a PowerAdjustStart timer: %" CHIP_ERROR_FORMAT, err.Format()); + HandlePowerAdjustRequestFailure(); + return Status::Failure; + } + + if (sendEvent) + { + Events::PowerAdjustStart::Type event; + EventNumber eventNumber; + err = LogEvent(event, mEndpointId, eventNumber); + if (CHIP_NO_ERROR != err) + { + // TODO: Note: should the PowerAdjust just initiated be cancelled because an Event could not be logged? + ChipLogError(AppServer, "Unable to send notify PowerAdjustStart event: %" CHIP_ERROR_FORMAT, err.Format()); + HandlePowerAdjustRequestFailure(); + return Status::Failure; + } + } + + return Status::Success; +} + +/** + * @brief Handle a PowerAdjustRequest failing + * + * Cleans up the PowerAdjust state should the request fail + */ +void DeviceEnergyManagementDelegate::HandlePowerAdjustRequestFailure() +{ + DeviceLayer::SystemLayer().CancelTimer(PowerAdjustTimerExpiry, this); + + SetESAState(ESAStateEnum::kOnline); + + mPowerAdjustmentInProgress = false; + + mPowerAdjustCapabilityStruct.Value().cause = PowerAdjustReasonEnum::kNoAdjustment; + + // TODO + // Should we inform the mpDEMManufacturerDelegate that PowerAdjustRequest has failed? +} + +/** + * @brief Timer for handling the PowerAdjustRequest + * + * This static function calls the non-static HandlePowerAdjustTimerExpiry method. + */ +void DeviceEnergyManagementDelegate::PowerAdjustTimerExpiry(System::Layer * systemLayer, void * delegate) +{ + DeviceEnergyManagementDelegate * dg = reinterpret_cast(delegate); + + dg->HandlePowerAdjustTimerExpiry(); +} + +/** + * @brief Timer for handling the completion of a PowerAdjustRequest + * + * When the timer expires: + * 1) notify the appliance's that it can resume its intended power setting (or go idle) + * 2) generate a PowerAdjustEnd event with cause NormalCompletion + * 3) if necessary, update the forecast with new expected end time + */ +void DeviceEnergyManagementDelegate::HandlePowerAdjustTimerExpiry() +{ + ChipLogError(AppServer, "DeviceEnergyManagementDelegate::HandlePowerAdjustTimerExpiry"); + + // The PowerAdjustment is no longer in progress + mPowerAdjustmentInProgress = false; + + SetESAState(ESAStateEnum::kOnline); + + mPowerAdjustCapabilityStruct.Value().cause = PowerAdjustReasonEnum::kNoAdjustment; + + // Send a PowerAdjustEnd event + SendPowerAdjustEndEvent(CauseEnum::kNormalCompletion); + + // Update the forecast with new expected end time + if (mpDEMManufacturerDelegate != nullptr) + { + mpDEMManufacturerDelegate->HandleDeviceEnergyManagementPowerAdjustCompletion(); + } } + /** * @brief Delegate handler for CancelPowerAdjustRequest * * Note: checking of the validity of the CancelPowerAdjustRequest has been done by the lower layer * * This function needs to notify the appliance that it should resume its intended power setting (or go idle). - + * * It should: * 1) notify the appliance's that it can resume its intended power setting (or go idle) * 2) generate a PowerAdjustEnd event with cause code Cancelled @@ -75,16 +238,91 @@ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t power, c */ Status DeviceEnergyManagementDelegate::CancelPowerAdjustRequest() { - Status status = Status::UnsupportedCommand; // Status::Success; + Status status = Status::Success; - // TODO: implement - /* TODO: If the command is accepted, the ESA SHALL generate an PowerAdjustEnd Event. */ - mEsaState = ESAStateEnum::kOnline; - MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, ESAState::Id); + CHIP_ERROR err = CancelPowerAdjustRequestAndSendEvent(DeviceEnergyManagement::CauseEnum::kCancelled); + if (CHIP_NO_ERROR != err) + { + status = Status::Failure; + } return status; } +/** + * @brief Handles the cancelation of a PowerAdjust operation + * + * This function needs to notify the appliance that it should resume its intended power setting (or go idle). + * + * It should: + * 1) notify the appliance's that it can resume its intended power setting (or go idle) + * 2) generate a PowerAdjustEnd event with cause code Cancelled + * 3) if necessary, update the forecast with new expected end time + */ +CHIP_ERROR DeviceEnergyManagementDelegate::CancelPowerAdjustRequestAndSendEvent(CauseEnum cause) +{ + DeviceLayer::SystemLayer().CancelTimer(PowerAdjustTimerExpiry, this); + + SetESAState(ESAStateEnum::kOnline); + + mPowerAdjustmentInProgress = false; + + mPowerAdjustCapabilityStruct.Value().cause = PowerAdjustReasonEnum::kNoAdjustment; + + CHIP_ERROR err = SendPowerAdjustEndEvent(cause); + + // Notify the appliance's that it can resume its intended power setting (or go idle) + if (mpDEMManufacturerDelegate != nullptr) + { + // It is expected the mpDEMManufacturerDelegate will update the forecast with new expected end time + // as a consequence of the cancel request. + err = mpDEMManufacturerDelegate->HandleDeviceEnergyManagementCancelPowerAdjustRequest(cause); + } + + return err; +} + +/** + * @brief Send a PowerAdjustEvent + * + */ +CHIP_ERROR DeviceEnergyManagementDelegate::SendPowerAdjustEndEvent(CauseEnum cause) +{ + Events::PowerAdjustEnd::Type event; + EventNumber eventNumber; + event.cause = cause; + + uint32_t timeNow; + CHIP_ERROR err = UtilsGetEpochTS(timeNow); + if (err == CHIP_NO_ERROR) + { + event.duration = timeNow - mPowerAdjustmentStartTime; + } + else + { + ChipLogError(AppServer, "Unable to get time: %" CHIP_ERROR_FORMAT, err.Format()); + return err; + } + + if (mpDEMManufacturerDelegate != nullptr) + { + event.energyUse = mpDEMManufacturerDelegate->GetEnergyUse(); + } + else + { + event.energyUse = 0; + } + + err = LogEvent(event, mEndpointId, eventNumber); + if (CHIP_NO_ERROR != err) + { + ChipLogError(AppServer, "Unable to send notify PowerAdjustEnd event: %" CHIP_ERROR_FORMAT, err.Format()); + return err; + } + + return err; +} + /** * @brief Delegate handler for StartTimeAdjustRequest * @@ -98,25 +336,55 @@ Status DeviceEnergyManagementDelegate::CancelPowerAdjustRequest() */ Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t requestedStartTime, AdjustmentCauseEnum cause) { - DataModel::Nullable forecast = GetForecast(); + if (mForecast.IsNull()) + { + return Status::Failure; + } - if (forecast.IsNull()) + switch (cause) { + case AdjustmentCauseEnum::kLocalOptimization: + mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kLocalOptimization; + break; + case AdjustmentCauseEnum::kGridOptimization: + mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kGridOptimization; + break; + default: + ChipLogDetail(AppServer, "Bad cause %d", static_cast(cause)); return Status::Failure; + break; } - uint32_t duration = forecast.Value().endTime - forecast.Value().startTime; // the current entire forecast duration + mForecast.Value().forecastID++; - /* Modify start time and end time */ - forecast.Value().startTime = requestedStartTime; - forecast.Value().endTime = requestedStartTime + duration; + uint32_t duration = mForecast.Value().endTime - mForecast.Value().startTime; // the current entire forecast duration - SetForecast(forecast); // This will increment forecast ID + // Save the start and end time in case there is an issue with the mpDEMManufacturerDelegate handling this + // startTimeAdjustment request + uint32_t savedStartTime = mForecast.Value().startTime; + uint32_t savedEndTime = mForecast.Value().endTime; - // TODO: callback to the appliance to notify it of a new start time + /* Modify start time and end time */ + mForecast.Value().startTime = requestedStartTime; + mForecast.Value().endTime = requestedStartTime + duration; + + if (mpDEMManufacturerDelegate != nullptr) + { + CHIP_ERROR err = mpDEMManufacturerDelegate->HandleDeviceEnergyManagementStartTimeAdjustRequest(requestedStartTime, cause); + if (err != CHIP_NO_ERROR) + { + // Reset state + mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization; + mForecast.Value().startTime = savedStartTime; + mForecast.Value().endTime = savedEndTime; + + return Status::Failure; + } + } return Status::Success; } + /** * @brief Delegate handler for Pause Request * @@ -136,9 +404,191 @@ Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t req */ Status DeviceEnergyManagementDelegate::PauseRequest(const uint32_t duration, AdjustmentCauseEnum cause) { - Status status = Status::UnsupportedCommand; // Status::Success; - // TODO: implement the behaviour above - return status; + bool sendEvent = false; + + // Record when this PauseRequest starts + CHIP_ERROR err = UtilsGetEpochTS(mPauseRequestStartTime); + if (err != CHIP_NO_ERROR) + { + ChipLogError(AppServer, "Unable to get time: %" CHIP_ERROR_FORMAT, err.Format()); + return Status::Failure; + } + + // If a timer is running, cancel it so we can start it with the new duration + if (mPauseRequestInProgress) + { + DeviceLayer::SystemLayer().CancelTimer(PauseRequestTimerExpiry, this); + } + else + { + sendEvent = true; + + // Remember we have a timer running so we don't send a Paused event should another request come + // in before this timer expires + mPauseRequestInProgress = true; + } + + err = DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(duration), PauseRequestTimerExpiry, this); + if (err != CHIP_NO_ERROR) + { + HandlePauseRequestFailure(); + return Status::Failure; + } + + // Pause the appliance + if (mpDEMManufacturerDelegate != nullptr) + { + // It is expected that the mpDEMManufacturerDelegate will update the forecast with the new expected end time + err = mpDEMManufacturerDelegate->HandleDeviceEnergyManagementPauseRequest(duration, cause); + if (err != CHIP_NO_ERROR) + { + HandlePauseRequestFailure(); + return Status::Failure; + } + } + + if (sendEvent) + { + Events::Paused::Type event; + EventNumber eventNumber; + err = LogEvent(event, mEndpointId, eventNumber); + if (CHIP_NO_ERROR != err) + { + ChipLogError(AppServer, "Unable to send notify Paused event: %" CHIP_ERROR_FORMAT, err.Format()); + HandlePauseRequestFailure(); + return Status::Failure; + } + } + + SetESAState(ESAStateEnum::kPaused); + + // Update the forecaseUpdateReason based on the AdjustmentCause + if (cause == AdjustmentCauseEnum::kLocalOptimization) + { + mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kLocalOptimization; + } + else if (cause == AdjustmentCauseEnum::kGridOptimization) + { + mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kGridOptimization; + } + + return Status::Success; +} + +/** + * @brief Handle a PauseRequest failing + * + * Cleans up the state should the PauseRequest fail + */ +void DeviceEnergyManagementDelegate::HandlePauseRequestFailure() +{ + DeviceLayer::SystemLayer().CancelTimer(PowerAdjustTimerExpiry, this); + + SetESAState(ESAStateEnum::kOnline); + + mPauseRequestInProgress = false; + + // TODO + // Should we inform the mpDEMManufacturerDelegate that PauseRequest has failed? +} + +/** + * @brief Timer for handling the PauseRequest + * + * This static function calls the non-static HandlePauseRequestTimerExpiry method. + */ +void DeviceEnergyManagementDelegate::PauseRequestTimerExpiry(System::Layer * systemLayer, void * delegate) +{ + DeviceEnergyManagementDelegate * dg = reinterpret_cast(delegate); + + dg->HandlePauseRequestTimerExpiry(); +} + +/** + * @brief Timer for handling the completion of a PauseRequest + * + * When the timer expires: + * 1) restore the appliance's operational state + * 2) generate a Resumed event + * 3) if necessary, update the forecast with new expected end time + */ +void DeviceEnergyManagementDelegate::HandlePauseRequestTimerExpiry() +{ + // The PauseRequestment is no longer in progress + mPauseRequestInProgress = false; + + SetESAState(ESAStateEnum::kOnline); + + // Send a Resumed event + SendResumedEvent(CauseEnum::kNormalCompletion); + + // It is expected the mpDEMManufacturerDelegate will update the forecast with new expected end time + if (mpDEMManufacturerDelegate != nullptr) + { + mpDEMManufacturerDelegate->HandleDeviceEnergyManagementPauseCompletion(); + } +} + + +/** + * @brief Handles the cancelation of a pause operation + * + * This function needs to notify the appliance that it should resume its intended power setting (or go idle). + * + * It should: + * 1) notify the appliance's that it can resume its intended power setting (or go idle) + * 2) generate a PowerAdjustEnd event with cause code Cancelled + * 3) if necessary, update the forecast with new expected end time + */ +CHIP_ERROR DeviceEnergyManagementDelegate::CancelPauseRequestAndSendEvent(CauseEnum cause) +{ + mPauseRequestInProgress = false; + + SetESAState(ESAStateEnum::kOnline); + + DeviceLayer::SystemLayer().CancelTimer(PauseRequestTimerExpiry, this); + + CHIP_ERROR err = SendResumedEvent(cause); + CHIP_ERROR err2 = CHIP_NO_ERROR; + + // Notify the appliance's that it can resume its intended power setting (or go idle) + if (mpDEMManufacturerDelegate != nullptr) + { + // It is expected that the mpDEMManufacturerDelegate will update the forecast with new expected end time + err2 = mpDEMManufacturerDelegate->HandleDeviceEnergyManagementCancelPauseRequest(cause); + } + + // Need to pick one of the error codes two return... + if (err == CHIP_NO_ERROR && err2 == CHIP_NO_ERROR) + { + return CHIP_NO_ERROR; + } + + if (err2 != CHIP_NO_ERROR) + { + return err2; + } + + return err; +} + +/** + * @brief Send a Resumed event + * + */ +CHIP_ERROR DeviceEnergyManagementDelegate::SendResumedEvent(CauseEnum cause) +{ + Events::Resumed::Type event; + EventNumber eventNumber; + event.cause = cause; + + CHIP_ERROR err = LogEvent(event, mEndpointId, eventNumber); + if (CHIP_NO_ERROR != err) + { + ChipLogError(AppServer, "Unable to send notify Resumed event: %" CHIP_ERROR_FORMAT, err.Format()); + } + + return err; } /** @@ -156,10 +606,16 @@ Status DeviceEnergyManagementDelegate::PauseRequest(const uint32_t duration, Adj */ Status DeviceEnergyManagementDelegate::ResumeRequest() { - Status status = Status::UnsupportedCommand; // Status::Success; + Status status = Status::Failure; - // TODO: implement the behaviour above - SetESAState(ESAStateEnum::kOnline); + if (mPauseRequestInProgress) + { + CHIP_ERROR err = CancelPauseRequestAndSendEvent(CauseEnum::kCancelled); + if (err == CHIP_NO_ERROR) + { + status = Status::Success; + } + } return status; } @@ -179,12 +635,47 @@ 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; + Status status = Status::Success; + + if (mForecast.IsNull()) + { + status = Status::Failure; + } + else if (mForecast.Value().forecastID != forecastID) + { + status = Status::ConstraintError; + } + else if (mpDEMManufacturerDelegate != nullptr) + { + // Determine if the new forecast adjustments are acceptable to the appliance + CHIP_ERROR err = mpDEMManufacturerDelegate->HandleModifyRequest(forecastID, slotAdjustments, cause); + if (err != CHIP_NO_ERROR) + { + status = Status::Failure; + } + } + + if (status == Status::Success) + { + switch (cause) + { + case AdjustmentCauseEnum::kLocalOptimization: + mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kLocalOptimization; + break; + case AdjustmentCauseEnum::kGridOptimization: + mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kGridOptimization; + break; + default: + // Already checked in chip::app::Clusters::DeviceEnergyManagement::Instance::HandleModifyForecastRequest + break; + } + + mForecast.Value().forecastID++; + } - // TODO: implement the behaviour above return status; } @@ -203,8 +694,42 @@ Status DeviceEnergyManagementDelegate::ModifyForecastRequest( Status DeviceEnergyManagementDelegate::RequestConstraintBasedForecast( const DataModel::DecodableList & constraints, AdjustmentCauseEnum cause) { - Status status = Status::UnsupportedCommand; // Status::Success; - // TODO: implement the behaviour above + Status status = Status::Success; + + if (mForecast.IsNull()) + { + status = Status::Failure; + } + else if (mpDEMManufacturerDelegate != nullptr) + { + // Determine if the new forecast adjustments are acceptable to the appliance + CHIP_ERROR err = mpDEMManufacturerDelegate->RequestConstraintBasedForecast(constraints, cause); + if (err != CHIP_NO_ERROR) + { + status = Status::Failure; + } + } + + if (status == Status::Success) + { + switch (cause) + { + case AdjustmentCauseEnum::kLocalOptimization: + mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kLocalOptimization; + break; + case AdjustmentCauseEnum::kGridOptimization: + mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kGridOptimization; + break; + default: + // Already checked in chip::app::Clusters::DeviceEnergyManagement::Instance::HandleModifyForecastRequest + break; + } + + mForecast.Value().forecastID++; + + status = Status::Success; + } + return status; } @@ -221,8 +746,23 @@ Status DeviceEnergyManagementDelegate::RequestConstraintBasedForecast( */ Status DeviceEnergyManagementDelegate::CancelRequest() { - Status status = Status::UnsupportedCommand; // Status::Success; - // TODO: implement the behaviour above + Status status = Status::Success; + + mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization; + + /* It is expected the mpDEMManufacturerDelegate will cancel the effects of any previous adjustment + * request commands, and re-evaluate its forecast for intended operation ignoring those previous + * requests. + */ + if (mpDEMManufacturerDelegate != nullptr) + { + CHIP_ERROR error = mpDEMManufacturerDelegate->HandleDeviceEnergyManagementCancelRequest(); + if (error != CHIP_NO_ERROR) + { + status = Status::Failure; + } + } + return status; } @@ -253,18 +793,21 @@ int64_t DeviceEnergyManagementDelegate::GetAbsMaxPower() return mAbsMaxPower; } -PowerAdjustmentCapability::TypeInfo::Type DeviceEnergyManagementDelegate::GetPowerAdjustmentCapability() +DataModel::Nullable & DeviceEnergyManagementDelegate::GetPowerAdjustmentCapability() { - return mPowerAdjustmentCapability; + return mPowerAdjustCapabilityStruct; } -DataModel::Nullable DeviceEnergyManagementDelegate::GetForecast() +DataModel::Nullable & DeviceEnergyManagementDelegate::GetForecast() { + ChipLogDetail(Zcl, "DeviceEnergyManagementDelegate::GetForecast"); + return mForecast; } OptOutStateEnum DeviceEnergyManagementDelegate::GetOptOutState() { + ChipLogDetail(AppServer, "mOptOutState %d", static_cast(mOptOutState)); return mOptOutState; } @@ -352,20 +895,110 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetAbsMaxPower(int64_t newValue) } CHIP_ERROR -DeviceEnergyManagementDelegate::SetPowerAdjustmentCapability(PowerAdjustmentCapability::TypeInfo::Type powerAdjustmentCapability) +DeviceEnergyManagementDelegate::SetPowerAdjustmentCapability(DataModel::Nullable & powerAdjustCapabilityStruct) { - // TODO see Issue #31147 + if (powerAdjustCapabilityStruct.IsNull()) + { + mPowerAdjustCapabilityStruct.SetNull(); + } + else + { + mPowerAdjustCapabilityStruct = powerAdjustCapabilityStruct; + } + return CHIP_NO_ERROR; } -CHIP_ERROR DeviceEnergyManagementDelegate::SetForecast(DataModel::Nullable forecast) +CHIP_ERROR DeviceEnergyManagementDelegate::SetForecast(DataModel::Nullable & forecast) { // TODO see Issue #31147 + if (forecast.IsNull()) + { + mForecast.SetNull(); + } + else + { + mForecast = forecast; + } return CHIP_NO_ERROR; } CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newValue) { - return CHIP_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; + + OptOutStateEnum oldValue = mOptOutState; + + // The OptOutState is cumulative + if ((oldValue == OptOutStateEnum::kGridOptOut && newValue == OptOutStateEnum::kLocalOptOut) || + (oldValue == OptOutStateEnum::kLocalOptOut && newValue == OptOutStateEnum::kGridOptOut)) + { + mOptOutState = OptOutStateEnum::kOptOut; + } + else + { + mOptOutState = newValue; + } + + if (oldValue != newValue) + { + ChipLogDetail(AppServer, "mOptOutState updated to %d mPowerAdjustmentInProgress %d", static_cast(mOptOutState), mPowerAdjustmentInProgress); + MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, OptOutState::Id); + } + + // Cancel any outstanding PowerAdjustment if necessary + if (mPowerAdjustmentInProgress) + { + if ((newValue == OptOutStateEnum::kLocalOptOut && mPowerAdjustCapabilityStruct.Value().cause == PowerAdjustReasonEnum::kLocalOptimizationAdjustment) || + (newValue == OptOutStateEnum::kGridOptOut && mPowerAdjustCapabilityStruct.Value().cause == PowerAdjustReasonEnum::kGridOptimizationAdjustment) || + newValue == OptOutStateEnum::kOptOut) + { + err = CancelPowerAdjustRequestAndSendEvent(DeviceEnergyManagement::CauseEnum::kUserOptOut); + } + } + + // Cancel any outstanding PauseRequest if necessary + if (mPauseRequestInProgress) + { + // Cancel any outstanding PauseRequest + if ((newValue == OptOutStateEnum::kLocalOptOut && mForecast.Value().forecastUpdateReason == ForecastUpdateReasonEnum::kLocalOptimization) || + (newValue == OptOutStateEnum::kGridOptOut && mForecast.Value().forecastUpdateReason == ForecastUpdateReasonEnum::kGridOptimization) || + newValue == OptOutStateEnum::kOptOut) + { + err = CancelPauseRequestAndSendEvent(DeviceEnergyManagement::CauseEnum::kUserOptOut); + } + } + + if (!mForecast.IsNull()) + { + switch (mForecast.Value().forecastUpdateReason) + { + case ForecastUpdateReasonEnum::kInternalOptimization: + // We don't need to redo a forecast since its internal already + break; + case ForecastUpdateReasonEnum::kLocalOptimization: + if ((mOptOutState == OptOutStateEnum::kOptOut) || (mOptOutState == OptOutStateEnum::kLocalOptOut)) + { + mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization; + // Generate a new forecast with Internal Optimization + // TODO + } + break; + case ForecastUpdateReasonEnum::kGridOptimization: + if ((mOptOutState == OptOutStateEnum::kOptOut) || (mOptOutState == OptOutStateEnum::kGridOptOut)) + { + mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization; + // Generate a new forecast with Internal Optimization + // TODO + } + break; + default: + ChipLogDetail(AppServer, "Bad ForecastUpdateReasonEnum value of %d", static_cast(mForecast.Value().forecastUpdateReason)); + return CHIP_ERROR_BAD_REQUEST; + break; + } + } + + return err; } diff --git a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp index c31e0624e4c743..2854ecb91eb030 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp @@ -22,6 +22,17 @@ using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::DeviceEnergyManagement; +namespace chip { +namespace app { +namespace Clusters { + +DeviceEnergyManagementManager::DeviceEnergyManagementManager(EndpointId aEndpointId, DeviceEnergyManagementDelegate & aDelegate, + Feature aFeature) : + DeviceEnergyManagement::Instance(aEndpointId, aDelegate, aFeature), + mDelegate(&aDelegate) +{ +} + CHIP_ERROR DeviceEnergyManagementManager::Init() { return Instance::Init(); @@ -31,3 +42,7 @@ void DeviceEnergyManagementManager::Shutdown() { Instance::Shutdown(); } + +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp b/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp index d9848bcbc53515..0318334b3a6eda 100644 --- a/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp @@ -16,14 +16,18 @@ * limitations under the License. */ +#include #include +#include #include +#include #include #include #include #include #include +#include #include #include @@ -58,6 +62,13 @@ CHIP_ERROR EVSEManufacturer::Init() ReturnErrorOnFailure(InitializePowerMeasurementCluster()); ReturnErrorOnFailure(InitializePowerSourceCluster()); + + DeviceEnergyManagementDelegate * dem = GetEvseManufacturer()->GetDEMDelegate(); + VerifyOrReturnLogError(dem != nullptr, CHIP_ERROR_UNINITIALIZED); + + /* For Device Energy Management we need the ESA to be Online and ready to accept commands */ + dem->SetESAState(ESAStateEnum::kOnline); + /* * This is an example implementation for manufacturers to consider * @@ -322,147 +333,6 @@ CHIP_ERROR EVSEManufacturer::SendPeriodicEnergyReading(EndpointId aEndpointId, i return CHIP_NO_ERROR; } -struct FakeReadingsData -{ - bool bEnabled; /* If enabled then the timer callback will re-trigger */ - EndpointId mEndpointId; /* Which endpoint the meter is on */ - uint8_t mInterval_s; /* Interval in seconds to callback */ - int64_t mPower_mW; /* Active Power on the load in mW (signed value) +ve = imported */ - uint32_t mPowerRandomness_mW; /* The amount to randomize the Power on the load in mW */ - int64_t mVoltage_mV; /* Voltage reading in mV (signed value) */ - uint32_t mVoltageRandomness_mV; /* The amount to randomize the Voltage in mV */ - int64_t mCurrent_mA; /* ActiveCurrent reading in mA (signed value) */ - uint32_t mCurrentRandomness_mA; /* The amount to randomize the ActiveCurrent in mA */ - - /* These energy values can only be positive values. - * however the underlying energy type (power_mWh) is signed, so keeping with that convention */ - int64_t mTotalEnergyImported = 0; /* Cumulative Energy Imported which is updated if mPower > 0 */ - int64_t mTotalEnergyExported = 0; /* Cumulative Energy Imported which is updated if mPower < 0 */ - int64_t mPeriodicEnergyImported = 0; /* Periodic Energy Imported which is updated if mPower > 0 */ - int64_t mPeriodicEnergyExported = 0; /* Periodic Energy Imported which is updated if mPower < 0 */ -}; - -static FakeReadingsData gFakeReadingsData; - -/* This helper routine starts and handles a callback */ -/** - * @brief Starts a fake load/generator to periodically callback the power and energy - * clusters. - * @param[in] aEndpointId - which endpoint is the meter to be updated on - * @param[in] aPower_mW - the mean power of the load - * Positive power indicates Imported energy (e.g. a load) - * Negative power indicated Exported energy (e.g. a generator) - * @param[in] aPowerRandomness_mW This is used to define the max randomness of the - * random power values around the mean power of the load - * @param[in] aVoltage_mV - the nominal voltage measurement - * @param[in] aVoltageRandomness_mV This is used to define the max randomness of the - * random voltage values - * @param[in] aCurrent_mA - the nominal current measurement - * @param[in] aCurrentRandomness_mA This is used to define the max randomness of the - * random current values - * @param[in] aInterval_s - the callback interval in seconds - * @param[in] bReset - boolean: true will reset the energy values to 0 - */ -void EVSEManufacturer::StartFakeReadings(EndpointId aEndpointId, int64_t aPower_mW, uint32_t aPowerRandomness_mW, - int64_t aVoltage_mV, uint32_t aVoltageRandomness_mV, int64_t aCurrent_mA, - uint32_t aCurrentRandomness_mA, uint8_t aInterval_s, bool bReset) -{ - gFakeReadingsData.bEnabled = true; - gFakeReadingsData.mEndpointId = aEndpointId; - gFakeReadingsData.mPower_mW = aPower_mW; - gFakeReadingsData.mPowerRandomness_mW = aPowerRandomness_mW; - gFakeReadingsData.mVoltage_mV = aVoltage_mV; - gFakeReadingsData.mVoltageRandomness_mV = aVoltageRandomness_mV; - gFakeReadingsData.mCurrent_mA = aCurrent_mA; - gFakeReadingsData.mCurrentRandomness_mA = aCurrentRandomness_mA; - gFakeReadingsData.mInterval_s = aInterval_s; - - if (bReset) - { - gFakeReadingsData.mTotalEnergyImported = 0; - gFakeReadingsData.mTotalEnergyExported = 0; - } - - // Call update function to kick off regular readings - FakeReadingsUpdate(); -} -/** - * @brief Stops any active updates to the fake load data callbacks - */ -void EVSEManufacturer::StopFakeReadings() -{ - gFakeReadingsData.bEnabled = false; -} -/** - * @brief Sends fake meter data into the cluster and restarts the timer - */ -void EVSEManufacturer::FakeReadingsUpdate() -{ - /* Check to see if the fake Load is still running - don't send updates if the timer was already cancelled */ - if (!gFakeReadingsData.bEnabled) - { - return; - } - - // Update readings - // Avoid using floats - so we will do a basic rand() call which will generate a integer value between 0 and RAND_MAX - // first compute power as a mean + some random value in range +/- mPowerRandomness_mW - int64_t power = - (static_cast(rand()) % (2 * gFakeReadingsData.mPowerRandomness_mW)) - gFakeReadingsData.mPowerRandomness_mW; - power += gFakeReadingsData.mPower_mW; // add in the base power - - int64_t voltage = - (static_cast(rand()) % (2 * gFakeReadingsData.mVoltageRandomness_mV)) - gFakeReadingsData.mVoltageRandomness_mV; - voltage += gFakeReadingsData.mVoltage_mV; // add in the base voltage - - /* Note: whilst we could compute a current from the power and voltage, - * there will always be some random error from the sensor - * that measures it. To keep this simple and to avoid doing divides in integer - * format etc use the same approach here too. - * This is meant more as an example to show how to use the APIs, not - * to be a real representation of laws of physics. - */ - int64_t current = - (static_cast(rand()) % (2 * gFakeReadingsData.mCurrentRandomness_mA)) - gFakeReadingsData.mCurrentRandomness_mA; - current += gFakeReadingsData.mCurrent_mA; // add in the base current - - SendPowerReading(gFakeReadingsData.mEndpointId, power, voltage, current); - - // update the energy meter - we'll assume that the power has been constant during the previous interval - if (gFakeReadingsData.mPower_mW > 0) - { - // Positive power - means power is imported - gFakeReadingsData.mPeriodicEnergyImported = ((power * gFakeReadingsData.mInterval_s) / 3600); - gFakeReadingsData.mPeriodicEnergyExported = 0; - gFakeReadingsData.mTotalEnergyImported += gFakeReadingsData.mPeriodicEnergyImported; - } - else - { - // Negative power - means power is exported, but the exported energy is reported positive - gFakeReadingsData.mPeriodicEnergyImported = 0; - gFakeReadingsData.mPeriodicEnergyExported = ((-power * gFakeReadingsData.mInterval_s) / 3600); - gFakeReadingsData.mTotalEnergyExported += gFakeReadingsData.mPeriodicEnergyExported; - } - - SendPeriodicEnergyReading(gFakeReadingsData.mEndpointId, gFakeReadingsData.mPeriodicEnergyImported, - gFakeReadingsData.mPeriodicEnergyExported); - - SendCumulativeEnergyReading(gFakeReadingsData.mEndpointId, gFakeReadingsData.mTotalEnergyImported, - gFakeReadingsData.mTotalEnergyExported); - - // start/restart the timer - DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(gFakeReadingsData.mInterval_s), FakeReadingsTimerExpiry, this); -} -/** - * @brief Timer expiry callback to handle fake load - */ -void EVSEManufacturer::FakeReadingsTimerExpiry(System::Layer * systemLayer, void * manufacturer) -{ - EVSEManufacturer * mn = reinterpret_cast(manufacturer); - - mn->FakeReadingsUpdate(); -} - /** * @brief Main Callback handler - to be implemented by Manufacturer * @@ -501,227 +371,60 @@ void EVSEManufacturer::ApplicationCallbackHandler(const EVSECbInfo * cb, intptr_ } } -struct EVSETestEventSaveData +int64_t EVSEManufacturer::GetEnergyUse() { - int64_t mOldMaxHardwareCurrentLimit; - int64_t mOldCircuitCapacity; - int64_t mOldUserMaximumChargeCurrent; - int64_t mOldCableAssemblyLimit; - StateEnum mOldHwStateBasic; /* For storing hwState before Basic Func event */ - StateEnum mOldHwStatePluggedIn; /* For storing hwState before PluggedIn event */ - StateEnum mOldHwStatePluggedInDemand; /* For storing hwState before PluggedInDemand event */ -}; - -static EVSETestEventSaveData sEVSETestEventSaveData; - -EnergyEvseDelegate * GetEvseDelegate() -{ - EVSEManufacturer * mn = GetEvseManufacturer(); - VerifyOrDieWithMsg(mn != nullptr, AppServer, "EVSEManufacturer is null"); - EnergyEvseDelegate * dg = mn->GetEvseDelegate(); - VerifyOrDieWithMsg(dg != nullptr, AppServer, "EVSE Delegate is null"); - - return dg; -} - -void SetTestEventTrigger_BasicFunctionality() -{ - EnergyEvseDelegate * dg = GetEvseDelegate(); - - sEVSETestEventSaveData.mOldMaxHardwareCurrentLimit = dg->HwGetMaxHardwareCurrentLimit(); - sEVSETestEventSaveData.mOldCircuitCapacity = dg->GetCircuitCapacity(); - sEVSETestEventSaveData.mOldUserMaximumChargeCurrent = dg->GetUserMaximumChargeCurrent(); - sEVSETestEventSaveData.mOldHwStateBasic = dg->HwGetState(); - - dg->HwSetMaxHardwareCurrentLimit(32000); - dg->HwSetCircuitCapacity(32000); - dg->SetUserMaximumChargeCurrent(32000); - dg->HwSetState(StateEnum::kNotPluggedIn); + return 300; } -void SetTestEventTrigger_BasicFunctionalityClear() -{ - EnergyEvseDelegate * dg = GetEvseDelegate(); - dg->HwSetMaxHardwareCurrentLimit(sEVSETestEventSaveData.mOldMaxHardwareCurrentLimit); - dg->HwSetCircuitCapacity(sEVSETestEventSaveData.mOldCircuitCapacity); - dg->SetUserMaximumChargeCurrent(sEVSETestEventSaveData.mOldUserMaximumChargeCurrent); - dg->HwSetState(sEVSETestEventSaveData.mOldHwStateBasic); -} -void SetTestEventTrigger_EVPluggedIn() +CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t power, const uint32_t duration, AdjustmentCauseEnum cause) { - EnergyEvseDelegate * dg = GetEvseDelegate(); - - sEVSETestEventSaveData.mOldCableAssemblyLimit = dg->HwGetCableAssemblyLimit(); - sEVSETestEventSaveData.mOldHwStatePluggedIn = dg->HwGetState(); - - dg->HwSetCableAssemblyLimit(63000); - dg->HwSetState(StateEnum::kPluggedInNoDemand); -} -void SetTestEventTrigger_EVPluggedInClear() -{ - EnergyEvseDelegate * dg = GetEvseDelegate(); - dg->HwSetCableAssemblyLimit(sEVSETestEventSaveData.mOldCableAssemblyLimit); - dg->HwSetState(sEVSETestEventSaveData.mOldHwStatePluggedIn); + return CHIP_NO_ERROR; } -void SetTestEventTrigger_EVChargeDemand() +CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementPowerAdjustCompletion() { - EnergyEvseDelegate * dg = GetEvseDelegate(); - - sEVSETestEventSaveData.mOldHwStatePluggedInDemand = dg->HwGetState(); - dg->HwSetState(StateEnum::kPluggedInDemand); -} -void SetTestEventTrigger_EVChargeDemandClear() -{ - EnergyEvseDelegate * dg = GetEvseDelegate(); - - dg->HwSetState(sEVSETestEventSaveData.mOldHwStatePluggedInDemand); -} -void SetTestEventTrigger_EVSEGroundFault() -{ - EnergyEvseDelegate * dg = GetEvseDelegate(); - - dg->HwSetFault(FaultStateEnum::kGroundFault); + return CHIP_NO_ERROR; } -void SetTestEventTrigger_EVSEOverTemperatureFault() +CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementCancelPowerAdjustRequest(CauseEnum cause) { - EnergyEvseDelegate * dg = GetEvseDelegate(); - - dg->HwSetFault(FaultStateEnum::kOverTemperature); + return CHIP_NO_ERROR; } -void SetTestEventTrigger_EVSEFaultClear() +CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementStartTimeAdjustRequest(const uint32_t requestedStartTime, AdjustmentCauseEnum cause) { - EnergyEvseDelegate * dg = GetEvseDelegate(); - - dg->HwSetFault(FaultStateEnum::kNoError); + return CHIP_NO_ERROR; } -void SetTestEventTrigger_EVSEDiagnosticsComplete() +CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementPauseRequest(const uint32_t duration, AdjustmentCauseEnum cause) { - EnergyEvseDelegate * dg = GetEvseDelegate(); - - dg->HwDiagnosticsComplete(); + return CHIP_NO_ERROR; } -void SetTestEventTrigger_FakeReadingsLoadStart() +CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementCancelPauseRequest(CauseEnum cause) { - EVSEManufacturer * mn = GetEvseManufacturer(); - VerifyOrDieWithMsg(mn != nullptr, AppServer, "EVSEManufacturer is null"); - - int64_t aPower_mW = 1'000'000; // Fake load 1000 W - uint32_t aPowerRandomness_mW = 20'000; // randomness 20W - int64_t aVoltage_mV = 230'000; // Fake Voltage 230V - uint32_t aVoltageRandomness_mV = 1'000; // randomness 1V - int64_t aCurrent_mA = 4'348; // Fake Current (at 1kW@230V = 4.3478 Amps) - uint32_t aCurrentRandomness_mA = 500; // randomness 500mA - uint8_t aInterval_s = 2; // 2s updates - bool bReset = true; - mn->StartFakeReadings(EndpointId(1), aPower_mW, aPowerRandomness_mW, aVoltage_mV, aVoltageRandomness_mV, aCurrent_mA, - aCurrentRandomness_mA, aInterval_s, bReset); + return CHIP_NO_ERROR; } -void SetTestEventTrigger_FakeReadingsGeneratorStart() +CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementPauseCompletion() { - EVSEManufacturer * mn = GetEvseManufacturer(); - VerifyOrDieWithMsg(mn != nullptr, AppServer, "EVSEManufacturer is null"); - - int64_t aPower_mW = -3'000'000; // Fake Generator -3000 W - uint32_t aPowerRandomness_mW = 20'000; // randomness 20W - int64_t aVoltage_mV = 230'000; // Fake Voltage 230V - uint32_t aVoltageRandomness_mV = 1'000; // randomness 1V - int64_t aCurrent_mA = -13'043; // Fake Current (at -3kW@230V = -13.0434 Amps) - uint32_t aCurrentRandomness_mA = 500; // randomness 500mA - uint8_t aInterval_s = 5; // 5s updates - bool bReset = true; - mn->StartFakeReadings(EndpointId(1), aPower_mW, aPowerRandomness_mW, aVoltage_mV, aVoltageRandomness_mV, aCurrent_mA, - aCurrentRandomness_mA, aInterval_s, bReset); + return CHIP_NO_ERROR; } -void SetTestEventTrigger_FakeReadingsStop() +CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementCancelRequest() { - EVSEManufacturer * mn = GetEvseManufacturer(); - VerifyOrDieWithMsg(mn != nullptr, AppServer, "EVSEManufacturer is null"); - mn->StopFakeReadings(); + return CHIP_NO_ERROR; } -bool HandleEnergyEvseTestEventTrigger(uint64_t eventTrigger) +CHIP_ERROR EVSEManufacturer::HandleModifyRequest(const uint32_t forecastID, + const DataModel::DecodableList & slotAdjustments, + AdjustmentCauseEnum cause) { - EnergyEvseTrigger trigger = static_cast(eventTrigger); - - switch (trigger) - { - case EnergyEvseTrigger::kBasicFunctionality: - ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => Basic Functionality install"); - SetTestEventTrigger_BasicFunctionality(); - break; - case EnergyEvseTrigger::kBasicFunctionalityClear: - ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => Basic Functionality clear"); - SetTestEventTrigger_BasicFunctionalityClear(); - break; - case EnergyEvseTrigger::kEVPluggedIn: - ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EV plugged in"); - SetTestEventTrigger_EVPluggedIn(); - break; - case EnergyEvseTrigger::kEVPluggedInClear: - ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EV unplugged"); - SetTestEventTrigger_EVPluggedInClear(); - break; - case EnergyEvseTrigger::kEVChargeDemand: - ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EV Charge Demand"); - SetTestEventTrigger_EVChargeDemand(); - break; - case EnergyEvseTrigger::kEVChargeDemandClear: - ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EV Charge NoDemand"); - SetTestEventTrigger_EVChargeDemandClear(); - break; - case EnergyEvseTrigger::kEVSEGroundFault: - ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EVSE has a GroundFault fault"); - SetTestEventTrigger_EVSEGroundFault(); - break; - case EnergyEvseTrigger::kEVSEOverTemperatureFault: - ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EVSE has a OverTemperature fault"); - SetTestEventTrigger_EVSEOverTemperatureFault(); - break; - case EnergyEvseTrigger::kEVSEFaultClear: - ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EVSE faults have cleared"); - SetTestEventTrigger_EVSEFaultClear(); - break; - case EnergyEvseTrigger::kEVSEDiagnosticsComplete: - ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EVSE Diagnostics Completed"); - SetTestEventTrigger_EVSEDiagnosticsComplete(); - break; - - default: - return false; - } - - return true; + return CHIP_NO_ERROR; } -bool HandleEnergyReportingTestEventTrigger(uint64_t eventTrigger) +CHIP_ERROR EVSEManufacturer::RequestConstraintBasedForecast(const DataModel::DecodableList & constraints, + AdjustmentCauseEnum cause) { - EnergyReportingTrigger trigger = static_cast(eventTrigger); - - switch (trigger) - { - case EnergyReportingTrigger::kFakeReadingsStop: - ChipLogProgress(Support, "[EnergyReporting-Test-Event] => Stop Fake load"); - SetTestEventTrigger_FakeReadingsStop(); - break; - case EnergyReportingTrigger::kFakeReadingsLoadStart_1kW_2s: - ChipLogProgress(Support, "[EnergyReporting-Test-Event] => Start Fake load 1kW @2s Import"); - SetTestEventTrigger_FakeReadingsLoadStart(); - break; - case EnergyReportingTrigger::kFakeReadingsGenStart_3kW_5s: - ChipLogProgress(Support, "[EnergyReporting-Test-Event] => Start Fake generator 3kW @5s Export"); - SetTestEventTrigger_FakeReadingsGeneratorStart(); - break; - - default: - return false; - } - - return true; + return CHIP_NO_ERROR; } diff --git a/examples/energy-management-app/energy-management-common/src/EnergyEvseEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/EnergyEvseEventTriggers.cpp new file mode 100644 index 00000000000000..25452c8a91c423 --- /dev/null +++ b/examples/energy-management-app/energy-management-common/src/EnergyEvseEventTriggers.cpp @@ -0,0 +1,184 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +#include + +#include + +using namespace chip; +using namespace chip::app; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::EnergyEvse; + +struct EVSETestEventSaveData +{ + int64_t mOldMaxHardwareCurrentLimit; + int64_t mOldCircuitCapacity; + int64_t mOldUserMaximumChargeCurrent; + int64_t mOldCableAssemblyLimit; + StateEnum mOldHwStateBasic; /* For storing hwState before Basic Func event */ + StateEnum mOldHwStatePluggedIn; /* For storing hwState before PluggedIn event */ + StateEnum mOldHwStatePluggedInDemand; /* For storing hwState before PluggedInDemand event */ +}; + +static EVSETestEventSaveData sEVSETestEventSaveData; + +EnergyEvseDelegate * GetEvseDelegate() +{ + EVSEManufacturer * mn = GetEvseManufacturer(); + VerifyOrDieWithMsg(mn != nullptr, AppServer, "EVSEManufacturer is null"); + EnergyEvseDelegate * dg = mn->GetEvseDelegate(); + VerifyOrDieWithMsg(dg != nullptr, AppServer, "EVSE Delegate is null"); + + return dg; +} + +void SetTestEventTrigger_BasicFunctionality() +{ + EnergyEvseDelegate * dg = GetEvseDelegate(); + + sEVSETestEventSaveData.mOldMaxHardwareCurrentLimit = dg->HwGetMaxHardwareCurrentLimit(); + sEVSETestEventSaveData.mOldCircuitCapacity = dg->GetCircuitCapacity(); + sEVSETestEventSaveData.mOldUserMaximumChargeCurrent = dg->GetUserMaximumChargeCurrent(); + sEVSETestEventSaveData.mOldHwStateBasic = dg->HwGetState(); + + dg->HwSetMaxHardwareCurrentLimit(32000); + dg->HwSetCircuitCapacity(32000); + dg->SetUserMaximumChargeCurrent(32000); + dg->HwSetState(StateEnum::kNotPluggedIn); +} +void SetTestEventTrigger_BasicFunctionalityClear() +{ + EnergyEvseDelegate * dg = GetEvseDelegate(); + + dg->HwSetMaxHardwareCurrentLimit(sEVSETestEventSaveData.mOldMaxHardwareCurrentLimit); + dg->HwSetCircuitCapacity(sEVSETestEventSaveData.mOldCircuitCapacity); + dg->SetUserMaximumChargeCurrent(sEVSETestEventSaveData.mOldUserMaximumChargeCurrent); + dg->HwSetState(sEVSETestEventSaveData.mOldHwStateBasic); +} +void SetTestEventTrigger_EVPluggedIn() +{ + EnergyEvseDelegate * dg = GetEvseDelegate(); + + sEVSETestEventSaveData.mOldCableAssemblyLimit = dg->HwGetCableAssemblyLimit(); + sEVSETestEventSaveData.mOldHwStatePluggedIn = dg->HwGetState(); + + dg->HwSetCableAssemblyLimit(63000); + dg->HwSetState(StateEnum::kPluggedInNoDemand); +} +void SetTestEventTrigger_EVPluggedInClear() +{ + EnergyEvseDelegate * dg = GetEvseDelegate(); + dg->HwSetCableAssemblyLimit(sEVSETestEventSaveData.mOldCableAssemblyLimit); + dg->HwSetState(sEVSETestEventSaveData.mOldHwStatePluggedIn); +} + +void SetTestEventTrigger_EVChargeDemand() +{ + EnergyEvseDelegate * dg = GetEvseDelegate(); + + sEVSETestEventSaveData.mOldHwStatePluggedInDemand = dg->HwGetState(); + dg->HwSetState(StateEnum::kPluggedInDemand); +} +void SetTestEventTrigger_EVChargeDemandClear() +{ + EnergyEvseDelegate * dg = GetEvseDelegate(); + + dg->HwSetState(sEVSETestEventSaveData.mOldHwStatePluggedInDemand); +} +void SetTestEventTrigger_EVSEGroundFault() +{ + EnergyEvseDelegate * dg = GetEvseDelegate(); + + dg->HwSetFault(FaultStateEnum::kGroundFault); +} + +void SetTestEventTrigger_EVSEOverTemperatureFault() +{ + EnergyEvseDelegate * dg = GetEvseDelegate(); + + dg->HwSetFault(FaultStateEnum::kOverTemperature); +} + +void SetTestEventTrigger_EVSEFaultClear() +{ + EnergyEvseDelegate * dg = GetEvseDelegate(); + + dg->HwSetFault(FaultStateEnum::kNoError); +} + +void SetTestEventTrigger_EVSEDiagnosticsComplete() +{ + EnergyEvseDelegate * dg = GetEvseDelegate(); + + dg->HwDiagnosticsComplete(); +} + +bool HandleEnergyEvseTestEventTrigger(uint64_t eventTrigger) +{ + EnergyEvseTrigger trigger = static_cast(eventTrigger); + + switch (trigger) + { + case EnergyEvseTrigger::kBasicFunctionality: + ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => Basic Functionality install"); + SetTestEventTrigger_BasicFunctionality(); + break; + case EnergyEvseTrigger::kBasicFunctionalityClear: + ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => Basic Functionality clear"); + SetTestEventTrigger_BasicFunctionalityClear(); + break; + case EnergyEvseTrigger::kEVPluggedIn: + ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EV plugged in"); + SetTestEventTrigger_EVPluggedIn(); + break; + case EnergyEvseTrigger::kEVPluggedInClear: + ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EV unplugged"); + SetTestEventTrigger_EVPluggedInClear(); + break; + case EnergyEvseTrigger::kEVChargeDemand: + ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EV Charge Demand"); + SetTestEventTrigger_EVChargeDemand(); + break; + case EnergyEvseTrigger::kEVChargeDemandClear: + ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EV Charge NoDemand"); + SetTestEventTrigger_EVChargeDemandClear(); + break; + case EnergyEvseTrigger::kEVSEGroundFault: + ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EVSE has a GroundFault fault"); + SetTestEventTrigger_EVSEGroundFault(); + break; + case EnergyEvseTrigger::kEVSEOverTemperatureFault: + ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EVSE has a OverTemperature fault"); + SetTestEventTrigger_EVSEOverTemperatureFault(); + break; + case EnergyEvseTrigger::kEVSEFaultClear: + ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EVSE faults have cleared"); + SetTestEventTrigger_EVSEFaultClear(); + break; + case EnergyEvseTrigger::kEVSEDiagnosticsComplete: + ChipLogProgress(Support, "[EnergyEVSE-Test-Event] => EVSE Diagnostics Completed"); + SetTestEventTrigger_EVSEDiagnosticsComplete(); + break; + + default: + return false; + } + + return true; +} diff --git a/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp b/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp index 6eeaaf8369c38c..bc16e5f91d59d9 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp @@ -16,6 +16,8 @@ * limitations under the License. */ +#include "EnergyManagementAppCmdLineOptions.h" + #include #include #include @@ -59,6 +61,8 @@ static std::unique_ptr gEEMAttrAccess; static std::unique_ptr gPTDelegate; static std::unique_ptr gPTInstance; +extern chip::BitMask GetFeatureMap(); + EVSEManufacturer * EnergyEvse::GetEvseManufacturer() { return gEvseManufacturer.get(); @@ -86,13 +90,11 @@ CHIP_ERROR DeviceEnergyManagementInit() return CHIP_ERROR_NO_MEMORY; } + BitMask featureMap = GetFeatureMap(); + /* Manufacturer may optionally not support all features, commands & attributes */ gDEMInstance = std::make_unique( - EndpointId(ENERGY_EVSE_ENDPOINT), *gDEMDelegate, - BitMask( - DeviceEnergyManagement::Feature::kPowerAdjustment, DeviceEnergyManagement::Feature::kPowerForecastReporting, - DeviceEnergyManagement::Feature::kStateForecastReporting, DeviceEnergyManagement::Feature::kStartTimeAdjustment, - DeviceEnergyManagement::Feature::kPausable)); + EndpointId(ENERGY_EVSE_ENDPOINT), *gDEMDelegate, featureMap); if (!gDEMInstance) { @@ -101,6 +103,8 @@ CHIP_ERROR DeviceEnergyManagementInit() return CHIP_ERROR_NO_MEMORY; } + gDEMDelegate->SetDeviceEnergyManagementInstance(*gDEMInstance); + CHIP_ERROR err = gDEMInstance->Init(); /* Register Attribute & Command handlers */ if (err != CHIP_NO_ERROR) { @@ -375,13 +379,16 @@ CHIP_ERROR EVSEManufacturerInit() } /* Now create EVSEManufacturer */ - gEvseManufacturer = std::make_unique(gEvseInstance.get(), gEPMInstance.get(), gPTInstance.get()); + gEvseManufacturer = + std::make_unique(gEvseInstance.get(), gEPMInstance.get(), gPTInstance.get(), gDEMInstance.get()); if (!gEvseManufacturer) { ChipLogError(AppServer, "Failed to allocate memory for EvseManufacturer"); return CHIP_ERROR_NO_MEMORY; } + gDEMDelegate.get()->SetDemManufacturerDelegate(*gEvseManufacturer.get()); + /* Call Manufacturer specific init */ err = gEvseManufacturer->Init(); if (err != CHIP_NO_ERROR) diff --git a/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp new file mode 100644 index 00000000000000..9aecd8d577a7fa --- /dev/null +++ b/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp @@ -0,0 +1,85 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +#include "FakeReadings.h" + +#include + +using namespace chip; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::ElectricalEnergyMeasurement; +using namespace chip::app::Clusters::ElectricalEnergyMeasurement::Structs; + +void SetTestEventTrigger_FakeReadingsLoadStart() +{ + int64_t aPower_mW = 1'000'000; // Fake load 1000 W + uint32_t aPowerRandomness_mW = 20'000; // randomness 20W + int64_t aVoltage_mV = 230'000; // Fake Voltage 230V + uint32_t aVoltageRandomness_mV = 1'000; // randomness 1V + int64_t aCurrent_mA = 4'348; // Fake Current (at 1kW@230V = 4.3478 Amps) + uint32_t aCurrentRandomness_mA = 500; // randomness 500mA + uint8_t aInterval_s = 2; // 2s updates + bool bReset = true; + FakeReadings::GetInstance().StartFakeReadings(EndpointId(1), aPower_mW, aPowerRandomness_mW, aVoltage_mV, aVoltageRandomness_mV, aCurrent_mA, + aCurrentRandomness_mA, aInterval_s, bReset); +} + +void SetTestEventTrigger_FakeReadingsGeneratorStart() +{ + int64_t aPower_mW = -3'000'000; // Fake Generator -3000 W + uint32_t aPowerRandomness_mW = 20'000; // randomness 20W + int64_t aVoltage_mV = 230'000; // Fake Voltage 230V + uint32_t aVoltageRandomness_mV = 1'000; // randomness 1V + int64_t aCurrent_mA = -13'043; // Fake Current (at -3kW@230V = -13.0434 Amps) + uint32_t aCurrentRandomness_mA = 500; // randomness 500mA + uint8_t aInterval_s = 5; // 5s updates + bool bReset = true; + FakeReadings::GetInstance().StartFakeReadings(EndpointId(1), aPower_mW, aPowerRandomness_mW, aVoltage_mV, aVoltageRandomness_mV, aCurrent_mA, + aCurrentRandomness_mA, aInterval_s, bReset); +} + +void SetTestEventTrigger_FakeReadingsStop() +{ + FakeReadings::GetInstance().StopFakeReadings(); +} + +bool HandleEnergyReportingTestEventTrigger(uint64_t eventTrigger) +{ + EnergyReportingTrigger trigger = static_cast(eventTrigger); + + switch (trigger) + { + case EnergyReportingTrigger::kFakeReadingsStop: + ChipLogProgress(Support, "[EnergyReporting-Test-Event] => Stop Fake load"); + SetTestEventTrigger_FakeReadingsStop(); + break; + case EnergyReportingTrigger::kFakeReadingsLoadStart_1kW_2s: + ChipLogProgress(Support, "[EnergyReporting-Test-Event] => Start Fake load 1kW @2s Import"); + SetTestEventTrigger_FakeReadingsLoadStart(); + break; + case EnergyReportingTrigger::kFakeReadingsGenStart_3kW_5s: + ChipLogProgress(Support, "[EnergyReporting-Test-Event] => Start Fake generator 3kW @5s Export"); + SetTestEventTrigger_FakeReadingsGeneratorStart(); + break; + + default: + return false; + } + + return true; +} diff --git a/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp b/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp new file mode 100644 index 00000000000000..0ff7f7b3044b44 --- /dev/null +++ b/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp @@ -0,0 +1,185 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "FakeReadings.h" + +using namespace chip; +using namespace chip::app; +using namespace chip::app::DataModel; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::EnergyEvse; +using namespace chip::app::Clusters::ElectricalPowerMeasurement; +using namespace chip::app::Clusters::ElectricalEnergyMeasurement; +using namespace chip::app::Clusters::ElectricalEnergyMeasurement::Structs; +using namespace chip::app::Clusters::PowerSource; +using namespace chip::app::Clusters::PowerSource::Attributes; + +using Protocols::InteractionModel::Status; + +FakeReadings::FakeReadings() +{ +} + +FakeReadings::~FakeReadings() +{ +} + +/* static */ +FakeReadings & FakeReadings::GetInstance() +{ + static FakeReadings sInstance; + + return sInstance; +} + +/** + * @brief Starts a fake load/generator to periodically callback the power and energy + * clusters. + * @param[in] aEndpointId - which endpoint is the meter to be updated on + * @param[in] aPower_mW - the mean power of the load + * Positive power indicates Imported energy (e.g. a load) + * Negative power indicated Exported energy (e.g. a generator) + * @param[in] aPowerRandomness_mW This is used to define the max randomness of the + * random power values around the mean power of the load + * @param[in] aVoltage_mV - the nominal voltage measurement + * @param[in] aVoltageRandomness_mV This is used to define the max randomness of the + * random voltage values + * @param[in] aCurrent_mA - the nominal current measurement + * @param[in] aCurrentRandomness_mA This is used to define the max randomness of the + * random current values + * @param[in] aInterval_s - the callback interval in seconds + * @param[in] bReset - boolean: true will reset the energy values to 0 + */ +void FakeReadings::StartFakeReadings(EndpointId aEndpointId, int64_t aPower_mW, uint32_t aPowerRandomness_mW, + int64_t aVoltage_mV, uint32_t aVoltageRandomness_mV, int64_t aCurrent_mA, + uint32_t aCurrentRandomness_mA, uint8_t aInterval_s, bool bReset) +{ + bEnabled = true; + mEndpointId = aEndpointId; + mPower_mW = aPower_mW; + mPowerRandomness_mW = aPowerRandomness_mW; + mVoltage_mV = aVoltage_mV; + mVoltageRandomness_mV = aVoltageRandomness_mV; + mCurrent_mA = aCurrent_mA; + mCurrentRandomness_mA = aCurrentRandomness_mA; + mInterval_s = aInterval_s; + + if (bReset) + { + mTotalEnergyImported = 0; + mTotalEnergyExported = 0; + } + + // Call update function to kick off regular readings + FakeReadingsUpdate(); +} + +/** + * @brief Stops any active updates to the fake load data callbacks + */ +void FakeReadings::StopFakeReadings() +{ + bEnabled = false; +} + +/** + * @brief Sends fake meter data into the cluster and restarts the timer + */ +void FakeReadings::FakeReadingsUpdate() +{ + /* Check to see if the fake Load is still running - don't send updates if the timer was already cancelled */ + if (!bEnabled) + { + return; + } + + // Update readings + // Avoid using floats - so we will do a basic rand() call which will generate a integer value between 0 and RAND_MAX + // first compute power as a mean + some random value in range +/- mPowerRandomness_mW + int64_t power = + (static_cast(rand()) % (2 * mPowerRandomness_mW)) - mPowerRandomness_mW; + power += mPower_mW; // add in the base power + + int64_t voltage = + (static_cast(rand()) % (2 * mVoltageRandomness_mV)) - mVoltageRandomness_mV; + voltage += mVoltage_mV; // add in the base voltage + + /* Note: whilst we could compute a current from the power and voltage, + * there will always be some random error from the sensor + * that measures it. To keep this simple and to avoid doing divides in integer + * format etc use the same approach here too. + * This is meant more as an example to show how to use the APIs, not + * to be a real representation of laws of physics. + */ + int64_t current = + (static_cast(rand()) % (2 * mCurrentRandomness_mA)) - mCurrentRandomness_mA; + current += mCurrent_mA; // add in the base current + + GetEvseManufacturer()->SendPowerReading(mEndpointId, power, voltage, current); + + // update the energy meter - we'll assume that the power has been constant during the previous interval + if (mPower_mW > 0) + { + // Positive power - means power is imported + mPeriodicEnergyImported = ((power * mInterval_s) / 3600); + mPeriodicEnergyExported = 0; + mTotalEnergyImported += mPeriodicEnergyImported; + } + else + { + // Negative power - means power is exported, but the exported energy is reported positive + mPeriodicEnergyImported = 0; + mPeriodicEnergyExported = ((-power * mInterval_s) / 3600); + mTotalEnergyExported += mPeriodicEnergyExported; + } + + GetEvseManufacturer()->SendPeriodicEnergyReading(mEndpointId, mPeriodicEnergyImported, + mPeriodicEnergyExported); + + GetEvseManufacturer()->SendCumulativeEnergyReading(mEndpointId, mTotalEnergyImported, + mTotalEnergyExported); + + // start/restart the timer + DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(mInterval_s), FakeReadingsTimerExpiry, this); +} + +/** + * @brief Timer expiry callback to handle fake load + */ +void FakeReadings::FakeReadingsTimerExpiry(System::Layer * systemLayer, void * manufacturer) +{ + FakeReadings * mn = reinterpret_cast(manufacturer); + + mn->FakeReadingsUpdate(); +} diff --git a/examples/energy-management-app/esp32/main/CMakeLists.txt b/examples/energy-management-app/esp32/main/CMakeLists.txt index a9a8c4100ae2de..15c1f99a6982aa 100644 --- a/examples/energy-management-app/esp32/main/CMakeLists.txt +++ b/examples/energy-management-app/esp32/main/CMakeLists.txt @@ -20,6 +20,7 @@ set(PRIV_INCLUDE_DIRS_LIST "${APP_GEN_DIR}" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/include" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/esp32/main/include" "${CMAKE_CURRENT_LIST_DIR}/include" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32" ) diff --git a/examples/energy-management-app/esp32/main/main.cpp b/examples/energy-management-app/esp32/main/main.cpp index e61e6cb00cca9b..769597357aca85 100644 --- a/examples/energy-management-app/esp32/main/main.cpp +++ b/examples/energy-management-app/esp32/main/main.cpp @@ -98,6 +98,15 @@ DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; DeviceLayer::ESP32SecureCertDACProvider gSecureCertDACProvider; #endif // CONFIG_SEC_CERT_DAC_PROVIDER +// Keep track of the parsed featureMap option +static chip::BitMask sFeatureMap(DeviceEnergyManagement::Feature::kPowerAdjustment, + DeviceEnergyManagement::Feature::kPowerForecastReporting, + DeviceEnergyManagement::Feature::kStateForecastReporting, + DeviceEnergyManagement::Feature::kStartTimeAdjustment, + DeviceEnergyManagement::Feature::kPausable, + DeviceEnergyManagement::Feature::kForecastAdjustment, + DeviceEnergyManagement::Feature::kConstraintBasedAdjustment); + chip::Credentials::DeviceAttestationCredentialsProvider * get_dac_provider(void) { #if CONFIG_SEC_CERT_DAC_PROVIDER @@ -123,6 +132,11 @@ void ApplicationShutdown() EvseApplicationShutdown(); } +chip::BitMask GetFeatureMap() +{ + return sFeatureMap; +} + static void InitServer(intptr_t context) { // Print QR Code URL diff --git a/examples/energy-management-app/linux/BUILD.gn b/examples/energy-management-app/linux/BUILD.gn index 4730c2c8ea82f3..27eddb8f0c67ca 100644 --- a/examples/energy-management-app/linux/BUILD.gn +++ b/examples/energy-management-app/linux/BUILD.gn @@ -36,16 +36,27 @@ config("includes") { executable("chip-energy-management-app") { sources = [ + "${chip_root}/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseEventTriggers.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/PowerTopologyDelegate.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/device-energy-management-mode.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/energy-evse-mode.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", + + "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp", "include/CHIPProjectAppConfig.h", "main.cpp", ] diff --git a/examples/energy-management-app/linux/README.md b/examples/energy-management-app/linux/README.md index f91d341915ccd8..146efefd238182 100644 --- a/examples/energy-management-app/linux/README.md +++ b/examples/energy-management-app/linux/README.md @@ -163,6 +163,10 @@ There are several test scripts provided for EVSE (in - `TC_EEVSE_2_3`: This validates Get/Set/Clear target commands - `TC_EEVSE_2_4`: This validates Faults - `TC_EEVSE_2_5`: This validates EVSE diagnostic command (optional) +- `TC_EEVSE_2_6`: This validates EVSE Forecast Adjustment with State Forecast Reporting feature functionality +- `TC_EEVSE_2_7`: This validates EVSE Constraints-based Adjustment with Power Forecast Reporting feature functionality +- `TC_EEVSE_2_8`: This validates EVSE Constraints-based Adjustment with State Forecast Reporting feature functionality +- `TC_EEVSE_2_9`: This validates EVSE Power or State Forecast Reporting feature functionality These scripts require the use of Test Event Triggers via the GeneralDiagnostics cluster on Endpoint 0. This requires an `enableKey` (16 bytes) and a set of @@ -183,6 +187,32 @@ chosen enable key is using the `--enable-key` command line option. From the top-level of the connectedhomeip repo type: +Start the chip-energy-management-app: +```bash +rm -f evse.bin; out/debug/chip-energy-management-app --enable-key 000102030405060708090a0b0c0d0e0f --KVS evse.bin --featureSet $featureSet +``` +where the $featureSet depends on the test being run: +``` +TC_DEM_2_2.py: 0x01 // PA +TC_DEM_2_3.py: 0x3b // STA, PAU, FA, CON + (PFR | SFR) +TC_DEM_2_4.py: 0x3b // STA, PAU, FA, CON + (PFR | SFR) +TC_DEM_2_5.py: 0x3b // STA, PAU, FA, CON + PFR +TC_DEM_2_6.py: 0x3d // STA, PAU, FA, CON + SFR +TC_DEM_2_7.py: 0x3b // STA, PAU, FA, CON + PFR +TC_DEM_2_8.py: 0x3d // STA, PAU, FA, CON + SFR +TC_DEM_2_9.py: 0x3f // STA, PAU, FA, CON + PFR + SFR +``` +where +``` +PA - DEM.S.F00(PowerAdjustment) +PFR - DEM.S.F01(PowerForecastReporting) +SFR - DEM.S.F02(StateForecastReporting) +STA - DEM.S.F03(StartTimeAdjustment) +PAU - DEM.S.F04(Pausable) +FA - DEM.S.F05(ForecastAdjustment) +CON -DEM.S.F06(ConstraintBasedAdjustment) +``` +Then run the test: ```bash $ python src/python_testing/TC_EEVSE_2_2.py --endpoint 1 -m on-network -n 1234 -p 20202021 -d 3840 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f ``` @@ -191,6 +221,8 @@ From the top-level of the connectedhomeip repo type: cluster is on endpoint 1. The `--hex-arg enableKey:` value must match the `--enable-key ` used on chip-energy-management-app args. +The chip-energy-management-app will need to be stopped before running each test script as each test commissions the chip-energy-management-app in the first step. That is also why the evse.bin is deleted before running chip-energy-management-app as this is where the app stores the matter persistent data (e.g. fabric info). + ## CHIP-REPL Interaction - See chip-repl documentation in diff --git a/examples/energy-management-app/linux/args.gni b/examples/energy-management-app/linux/args.gni index e1000e6cb3fa27..21db8cfc9277e6 100644 --- a/examples/energy-management-app/linux/args.gni +++ b/examples/energy-management-app/linux/args.gni @@ -31,3 +31,4 @@ matter_enable_tracing_support = true chip_enable_read_client = false chip_enable_energy_evse_trigger = true chip_enable_energy_reporting_trigger = true +chip_enable_device_energy_management_trigger = true diff --git a/examples/energy-management-app/linux/main.cpp b/examples/energy-management-app/linux/main.cpp index 7973c16025d640..d0963f580acc09 100644 --- a/examples/energy-management-app/linux/main.cpp +++ b/examples/energy-management-app/linux/main.cpp @@ -18,6 +18,47 @@ #include #include +#include +#include + +using namespace chip; +using namespace chip::app; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::DeviceEnergyManagement; +using namespace chip::app::Clusters::DeviceEnergyManagement::Attributes; + +// Parse a hex (prefixed by 0x) or decimal (no-prefix) string +static uint32_t ParseNumber(const char *pString); + +// Parses the --featureMap option +static bool FeatureMapOptionHandler(const char * aProgram, chip::ArgParser::OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue); + +constexpr uint16_t kOptionFeatureMap = 'f'; + +// Define the chip::ArgParser command line structures for extending the command line to support the +// -f/--featureMap option +static chip::ArgParser::OptionDef sFeatureMapOptionDefs[] = +{ + { "featureSet", chip::ArgParser::kArgumentRequired, kOptionFeatureMap}, + { NULL } +}; + +static chip::ArgParser::OptionSet sCmdLineOptions = +{ + FeatureMapOptionHandler, // handler function + sFeatureMapOptionDefs, // array of option definitions + "GENERAL OPTIONS", // help group + "-f, --featureSet " // option help text +}; + +// Keep track of the parsed featureMap option +static chip::BitMask sFeatureMap(DeviceEnergyManagement::Feature::kPowerAdjustment, + DeviceEnergyManagement::Feature::kPowerForecastReporting, + DeviceEnergyManagement::Feature::kStateForecastReporting, + DeviceEnergyManagement::Feature::kStartTimeAdjustment, + DeviceEnergyManagement::Feature::kPausable, + DeviceEnergyManagement::Feature::kForecastAdjustment, + DeviceEnergyManagement::Feature::kConstraintBasedAdjustment); void ApplicationInit() { @@ -31,9 +72,49 @@ void ApplicationShutdown() EvseApplicationShutdown(); } +chip::BitMask GetFeatureMap() +{ + return sFeatureMap; +} + +static uint32_t ParseNumber(const char *pString) +{ + uint32_t num = 0; + if (strlen(pString) > 2 && pString[0] == '0' && pString[1] == 'x') + { + num = (uint32_t) strtoul(&pString[2], NULL, 16); + } + else + { + num = (uint32_t) strtoul(pString, NULL, 10); + } + + return num; +} + +static bool FeatureMapOptionHandler(const char * aProgram, chip::ArgParser::OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue) +{ + bool retval = true; + + switch (aIdentifier) + { + case kOptionFeatureMap: + sFeatureMap = BitMask(ParseNumber(aValue)); + ChipLogDetail(Support, "Using FeatureMap 0x%04x", sFeatureMap.Raw()); + break; + default: + ChipLogError(Support, "%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName); + retval = false; + break; + } + + return (retval); +} + + int main(int argc, char * argv[]) { - if (ChipLinuxAppInit(argc, argv) != 0) + if (ChipLinuxAppInit(argc, argv, &sCmdLineOptions) != 0) { return -1; } diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index b92d76e613e618..37bf2495f08736 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -90,6 +90,9 @@ #if CHIP_DEVICE_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER #include #endif +#if CHIP_DEVICE_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER +#include +#endif #include #include @@ -553,6 +556,10 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl) static EnergyReportingTestEventTriggerHandler sEnergyReportingTestEventTriggerHandler; sTestEventTriggerDelegate.AddHandler(&sEnergyReportingTestEventTriggerHandler); #endif +#if CHIP_DEVICE_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER + static DeviceEnergyManagementTestEventTriggerHandler sDeviceEnergyManagementTestEventTriggerHandler; + sTestEventTriggerDelegate.AddHandler(&sDeviceEnergyManagementTestEventTriggerHandler); +#endif initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; diff --git a/examples/platform/linux/BUILD.gn b/examples/platform/linux/BUILD.gn index 8cf00c5be5e62c..a8b02cbed22763 100644 --- a/examples/platform/linux/BUILD.gn +++ b/examples/platform/linux/BUILD.gn @@ -24,6 +24,7 @@ declare_args() { chip_enable_boolean_state_configuration_trigger = false chip_enable_energy_evse_trigger = false chip_enable_energy_reporting_trigger = false + chip_enable_device_energy_management_trigger = false } config("app-main-config") { @@ -52,6 +53,10 @@ source_set("energy-reporting-test-event-trigger") { sources = [ "${chip_root}/src/app/clusters/electrical-energy-measurement-server/EnergyReportingTestEventTriggerHandler.h" ] } +source_set("device-energy-management-test-event-trigger") { + sources = [ "${chip_root}/src/app/clusters/device-energy-management-server/DeviceEnergyManagementTestEventTriggerHandler.h" ] +} + source_set("app-main") { defines = [ "ENABLE_TRACING=${matter_enable_tracing_support}" ] sources = [ @@ -75,6 +80,7 @@ source_set("app-main") { public_deps = [ ":boolean-state-configuration-test-event-trigger", + ":device-energy-management-test-event-trigger", ":energy-evse-test-event-trigger", ":energy-reporting-test-event-trigger", ":smco-test-event-trigger", @@ -117,6 +123,7 @@ source_set("app-main") { "CHIP_DEVICE_CONFIG_ENABLE_BOOLEAN_STATE_CONFIGURATION_TRIGGER=${chip_enable_boolean_state_configuration_trigger}", "CHIP_DEVICE_CONFIG_ENABLE_ENERGY_EVSE_TRIGGER=${chip_enable_energy_evse_trigger}", "CHIP_DEVICE_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER=${chip_enable_energy_reporting_trigger}", + "CHIP_DEVICE_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER=${chip_enable_device_energy_management_trigger}", ] public_configs = [ ":app-main-config" ] diff --git a/examples/shell/shell_common/BUILD.gn b/examples/shell/shell_common/BUILD.gn index cb098a64598a1b..4f9d75dc2401be 100644 --- a/examples/shell/shell_common/BUILD.gn +++ b/examples/shell/shell_common/BUILD.gn @@ -72,14 +72,17 @@ static_library("shell_common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", - ] + "${chip_root}/examples/energy-management-app/energy-management-common/src/utils.cpp", + ] include_dirs = [ "${chip_root}/examples/all-clusters-app/all-clusters-common/include", "${chip_root}/examples/energy-management-app/energy-management-common/include", + "${chip_root}/src/app/clusters/device-energy-management-server" ] public_deps += diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index a68d193d241541..16c500cc354cac 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -384,6 +384,12 @@ template("chip_data_model") { "${_app_root}/clusters/${cluster}/${cluster}.h", "${_app_root}/clusters/${cluster}/EnergyReportingTestEventTriggerHandler.h", ] + } else if (cluster == "device-energy-management-server") { + sources += [ + "${_app_root}/clusters/${cluster}/${cluster}.cpp", + "${_app_root}/clusters/${cluster}/${cluster}.h", + "${_app_root}/clusters/${cluster}/DeviceEnergyManagementTestEventTriggerHandler.h", + ] } else if (cluster == "thread-network-diagnostics-server") { sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp", 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 b0d27b0b99edd7..43fbbb03b159b7 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 @@ -165,8 +165,8 @@ class Delegate virtual ESAStateEnum GetESAState() = 0; virtual int64_t GetAbsMinPower() = 0; virtual int64_t GetAbsMaxPower() = 0; - virtual DataModel::Nullable GetPowerAdjustmentCapability() = 0; - virtual DataModel::Nullable GetForecast() = 0; + virtual DataModel::Nullable & GetPowerAdjustmentCapability() = 0; + virtual DataModel::Nullable & GetForecast() = 0; virtual OptOutStateEnum GetOptOutState() = 0; // ------------------------------------------------------------------ @@ -176,8 +176,8 @@ class Delegate virtual CHIP_ERROR SetESAState(ESAStateEnum) = 0; virtual CHIP_ERROR SetAbsMinPower(int64_t) = 0; virtual CHIP_ERROR SetAbsMaxPower(int64_t) = 0; - virtual CHIP_ERROR SetPowerAdjustmentCapability(DataModel::Nullable) = 0; - virtual CHIP_ERROR SetForecast(DataModel::Nullable) = 0; + virtual CHIP_ERROR SetPowerAdjustmentCapability(DataModel::Nullable &) = 0; + virtual CHIP_ERROR SetForecast(DataModel::Nullable &) = 0; virtual CHIP_ERROR SetOptOutState(OptOutStateEnum) = 0; protected: diff --git a/src/python_testing/TC_DEM_2_2.py b/src/python_testing/TC_DEM_2_2.py new file mode 100644 index 00000000000000..49288a7d05a414 --- /dev/null +++ b/src/python_testing/TC_DEM_2_2.py @@ -0,0 +1,312 @@ +# +# Copyright (c) 2024 Project CHIP Authors +# All rights reserved. +# +# 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. +# pylint: disable=invalid-name +"""Define Matter test case TC_DEM_2_2.""" + + +import sys +import logging +import datetime +import time + +import chip.clusters as Clusters +from chip.interaction_model import Status +from matter_testing_support import EventChangeCallback, MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from mobly import asserts +from TC_DEM_Utils import DEMBaseTestHelper + +logger = logging.getLogger(__name__) + + +class TC_DEM_2_2(MatterBaseTest, DEMBaseTestHelper): + """Implementation of test case TC_DEM_2_2.""" + + def desc_TC_DEM_2_2(self) -> str: + """Return a description of this test.""" + return "4.1.3. [TC-DEM-2.2] Power Adjustment feature functionality with DUT as Server" + + def pics_TC_DEM_2_2(self): + """Return the PICS definitions associated with this test.""" + pics = [ + "DEM.S.F00", # Depends on Feature 00 (PowerAdjustment) + ] + return pics + + def steps_TC_DEM_2_2(self) -> list[TestStep]: + """Execute the test steps.""" + steps = [ + TestStep("1", "Commissioning, already done", is_commissioning=True), + TestStep("2", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster. Verify that TestEventTriggersEnabled attribute has a value of 1 (True)"), + TestStep("3", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Power Adjustment Test Event"), + TestStep("3a", "TH reads ESAState attribute. Verify value is 0x01 (Online)"), + TestStep("3b", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=NoAdjustment. Note value for later. Determine the OverallMaxPower and OverallMaxDuration as the largest MaxPower and MaxDuration of the PowerAdjustStructs returned, and similarly the OverallMinPower and OverallMinDuration as the smallest of the MinPower and MinDuration values."), + TestStep("3c", "TH reads OptOutState attribute. Verify value is 0x00 (NoOptOut)"), + TestStep("4", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is Success and Event DEM.S.E00(PowerAdjustStart) sent"), + TestStep("4a", "TH reads ESAState attribute. Verify value is 0x04 (PowerAdjustActive)"), + TestStep("4b", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=LocalOptimizationAdjustment."), + TestStep("5", "TH sends CancelPowerAdjustRequest. Verify Command response is Success and Event DEM.S.E01(PowerAdjustEnd) sent with Cause=Cancelled"), + TestStep("5a", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=NoAdjustment."), + TestStep("5b", "TH reads ESAState attribute. Verify value is 0x01 (Online)"), + TestStep("6", "TH sends CancelPowerAdjustRequest. Verify Command response is InvalidInStateError"), + TestStep("7", "TH sends PowerAdjustRequest with Power=OverallMaxPower+1 Duration=OverallMinDuration Cause=LocalOptimization. Verify Command response is ConstraintError"), + TestStep("8", "TH sends PowerAdjustRequest with Power=OverallMinPower Duration=OverallMaxDuration+1 Cause=LocalOptimization. Verify Command response is ConstraintError"), + TestStep("9", "TH sends PowerAdjustRequest with Power=OverallMinPower-1 Duration=OverallMaxDuration Cause=LocalOptimization. Verify Command response is ConstraintError"), + TestStep("10", "TH sends PowerAdjustRequest with Power=OverallMaxPower Duration=OverallMinDuration-1 Cause=LocalOptimization. Verify Command response is ConstraintError"), + TestStep("11", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is Success and event DEM.S.E00(PowerAdjustStart) sent"), + TestStep("11a", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=LocalOptimizationAdjustment."), + TestStep("12", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=GridOptimization. Verify Command response is Success and no event sent"), + TestStep("12a", "TH reads ESAState attribute. Verify value is 0x04 (PowerAdjustActive)"), + TestStep("12b", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=GridOptimizationAdjustment."), + TestStep("13", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event. No event sent"), + TestStep("13a", "TH reads ESAState attribute. Verify value is 0x04 (PowerAdjustActive)"), + TestStep("13b", "TH reads OptOutState attribute. Verify value is 0x02 (LocalOptOut)"), + TestStep("14", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is ConstraintError"), + TestStep("15", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event. Event DEM.S.E01(PowerAdjustEnd) sent with Cause=UserOptOut, Duration= approx time from step 11 to step 15, EnergyUse= a valid value"), + TestStep("15a", "TH reads ESAState attribute. Verify value is 0x01 (Online)"), + TestStep("15b", "TH reads OptOutState attribute. Verify value is 0x03 (OptOut)"), + TestStep("15c", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=NoAdjustment."), + TestStep("16", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear"), + TestStep("16a", "TH reads ESAState attribute. Verify value is 0x01 (Online)"), + TestStep("16b", "TH reads OptOutState attribute. Verify value is 0x00 (NoOptOut)"), + TestStep("17", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is Success and event DEM.S.E00(PowerAdjustStart) sent"), + TestStep("17a", "TH reads ESAState attribute. Verify value is 0x04 (PowerAdjustActive)"), + TestStep("17b", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=LocalOptimizationAdjustment."), + TestStep("18", "Wait 10 seconds. Event DEM.S.E01(PowerAdjustEnd) sent with Cause=NormalCompletion, Duration=10s, EnergyUse= a valid value"), + TestStep("18a", "TH reads ESAState attribute. Verify value is 0x01 (Online)"), + TestStep("18b", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=NoAdjustment."), + TestStep("19", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Power Adjustment Test Event Clear"), + ] + + return steps + + @async_test_body + async def test_TC_DEM_2_2(self): + # pylint: disable=too-many-locals, too-many-statements + """Run the test steps.""" + # These values have to correlate with the values configured in + # DeviceEnergyManagementManufacturerImpl::SetTestEventTrigger_PowerAdjustment() + min_power = 5 * 1000 * 1000 + max_power = 30 * 1000 * 1000 + + min_duration = 10 + max_duration = 60 + + self.step("1") + # Commission DUT - already done + + # Subscribe to Events and when they are sent push them to a queue for checking later + events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement) + await events_callback.start(self.default_controller, + self.dut_node_id, + self.matter_test_config.endpoint) + + self.step("2") + await self.check_test_event_triggers_enabled() + + self.step("3") + await self.send_test_event_trigger_power_adjustment() + + self.step("3a") + await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) + + self.step("3b") + powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") + asserts.assert_greater_equal(len(powerAdjustCapabilityStruct.powerAdjustCapability), 1) + logging.info(powerAdjustCapabilityStruct) + asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) + + # we should expect powerAdjustCapabilityStruct to have multiple entries with different max powers, min powers, max and min durations + found_min_power = sys.maxsize + found_max_power = 0 + found_min_duration = sys.maxsize + found_max_duration = 0 + + for entry in powerAdjustCapabilityStruct.powerAdjustCapability: + found_min_power = min(found_min_power, entry.minPower) + found_max_power = max(found_max_power, entry.maxPower) + found_min_duration = min(found_min_duration, entry.minDuration) + found_max_duration = max(found_max_duration, entry.maxDuration) + + result = f"found_min_power {found_min_power} found_max_power {found_max_power} found_min_duration {found_min_duration} found_max_duration {found_max_duration}" + logging.info(result) + + asserts.assert_equal(found_min_power, min_power) + asserts.assert_equal(found_max_power, max_power) + asserts.assert_equal(found_min_duration, min_duration) + asserts.assert_equal(found_max_duration, max_duration) + + self.step("3c") + await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) + + self.step("4") + await self.send_power_adjustment_command(power=max_power, + duration=powerAdjustCapabilityStruct.powerAdjustCapability[0].minDuration, + cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization) + + event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.PowerAdjustStart) + + self.step("4a") + await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kPowerAdjustActive) + + self.step("4b") + powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") + asserts.assert_greater_equal(len(powerAdjustCapabilityStruct.powerAdjustCapability), 1) + asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kLocalOptimizationAdjustment) + + self.step("5") + await self.send_cancel_power_adjustment_command() + event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.PowerAdjustEnd) + asserts.assert_equal(event_data.cause, Clusters.DeviceEnergyManagement.Enums.CauseEnum.kCancelled) + + self.step("5a") + powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") + asserts.assert_greater_equal(len(powerAdjustCapabilityStruct.powerAdjustCapability), 1) + asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) + + self.step("5b") + await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) + + self.step("6") + await self.send_cancel_power_adjustment_command(expected_status=Status.InvalidInState) + + self.step("7") + await self.send_power_adjustment_command(power=max_power + 1, + duration=min_duration, + cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, + expected_status=Status.ConstraintError) + + self.step("8") + await self.send_power_adjustment_command(power=min_power, + duration=max_duration + 1, + cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, + expected_status=Status.ConstraintError) + + self.step("9") + await self.send_power_adjustment_command(power=min_power - 1, + duration=max_duration, + cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, + expected_status=Status.ConstraintError) + + self.step("10") + await self.send_power_adjustment_command(power=max_power, + duration=min_duration - 1, + cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, + expected_status=Status.ConstraintError) + + self.step("11") + start = datetime.datetime.now() + await self.send_power_adjustment_command(power=max_power, + duration=min_duration, + cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization) + + event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.PowerAdjustStart) + + self.step("11a") + powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") + asserts.assert_greater_equal(len(powerAdjustCapabilityStruct.powerAdjustCapability), 1) + asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kLocalOptimizationAdjustment) + + self.step("12") + await self.send_power_adjustment_command(power=max_power, + duration=min_duration, + cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization) + + # Wait 5 seconds for an event not to be reported + events_callback.wait_for_no_event_report(5) + + self.step("12a") + await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kPowerAdjustActive) + + self.step("12b") + powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") + asserts.assert_greater_equal(len(powerAdjustCapabilityStruct.powerAdjustCapability), 1) + asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kGridOptimizationAdjustment) + + self.step("13") + await self.send_test_event_trigger_user_opt_out_local() + + self.step("13a") + await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kPowerAdjustActive) + + self.step("13b") + await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kLocalOptOut) + + self.step("14") + await self.send_power_adjustment_command(power=max_power, + duration=max_duration, + cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, + expected_status=Status.ConstraintError) + + self.step("15") + await self.send_test_event_trigger_user_opt_out_grid() + event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.PowerAdjustEnd) + asserts.assert_equal(event_data.cause, Clusters.DeviceEnergyManagement.Enums.CauseEnum.kUserOptOut) + + elapsed = datetime.datetime.now() - start + asserts.assert_less_equal(abs(elapsed.seconds - event_data.duration), 1) + + # TODO: Do a better check on valid energyUse value. + # Value returned here is defined in DeviceEnergyManagementManufacturerImpl::GetEnergyUse() + asserts.assert_greater_equal(event_data.energyUse, 300) + + self.step("15a") + await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) + + self.step("15b") + await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kOptOut) + + self.step("15c") + powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") + asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) + + self.step("16") + await self.send_test_event_trigger_user_opt_out_clear_all() + + self.step("16a") + await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) + + self.step("16b") + await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) + + self.step("17") + await self.send_power_adjustment_command(power=max_power, + duration=min_duration, + cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, + expected_status=Status.Success) + + self.step("17a") + await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kPowerAdjustActive) + + self.step("17b") + powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") + asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kLocalOptimizationAdjustment) + + self.step("18") + time.sleep(10) + + self.step("18a") + await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) + + self.step("18b") + powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") + asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) + + self.step("19") + await self.send_test_event_trigger_power_adjustment_clear() + + +if __name__ == "__main__": + default_matter_test_main() diff --git a/src/python_testing/TC_DEM_Utils.py b/src/python_testing/TC_DEM_Utils.py new file mode 100644 index 00000000000000..a99f0c81a3d889 --- /dev/null +++ b/src/python_testing/TC_DEM_Utils.py @@ -0,0 +1,223 @@ +# +# Copyright (c) 2023 Project CHIP Authors +# All rights reserved. +# +# 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. + + +import logging + +import chip.clusters as Clusters +from chip.interaction_model import InteractionModelError, Status +from mobly import asserts + +logger = logging.getLogger(__name__) + + +class DEMBaseTestHelper: + + async def read_dem_attribute_expect_success(self, endpoint: int = None, attribute: str = ""): + cluster = Clusters.Objects.DeviceEnergyManagement + full_attr = getattr(cluster.Attributes, attribute) + logging.info(f"endpoint {endpoint} full_attr {full_attr}") + return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=full_attr) + + async def check_dem_attribute(self, attribute, expected_value, endpoint: int = None): + value = await self.read_dem_attribute_expect_success(endpoint=endpoint, attribute=attribute) + asserts.assert_equal(value, expected_value, + f"Unexpected '{attribute}' value - expected {expected_value}, was {value}") + + async def send_power_adjustment_command(self, power: int, duration: int, + cause: Clusters.Objects.DeviceEnergyManagement.Enums.CauseEnum, + endpoint: int = None, timedRequestTimeoutMs: int = 3000, + expected_status: Status = Status.Success): + try: + await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.PowerAdjustRequest( + power=power, + duration=duration, + cause=cause), + endpoint=endpoint, + timedRequestTimeoutMs=timedRequestTimeoutMs) + + asserts.assert_equal(expected_status, Status.Success) + + except InteractionModelError as e: + asserts.assert_equal(e.status, expected_status, "Unexpected error returned") + + async def send_cancel_power_adjustment_command(self, endpoint: int = None, timedRequestTimeoutMs: int = 3000, + expected_status: Status = Status.Success): + try: + await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.CancelPowerAdjustRequest(), + endpoint=endpoint, + timedRequestTimeoutMs=timedRequestTimeoutMs) + + asserts.assert_equal(expected_status, Status.Success) + + except InteractionModelError as e: + asserts.assert_equal(e.status, expected_status, "Unexpected error returned") + + async def send_start_time_adjust_request_command(self, requestedStartTime: int, + cause: Clusters.Objects.DeviceEnergyManagement.Enums.CauseEnum, + endpoint: int = None, timedRequestTimeoutMs: int = 3000, + expected_status: Status = Status.Success): + try: + await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.StartTimeAdjustRequest( + requestedStartTime=requestedStartTime, + cause=cause), + endpoint=endpoint, + timedRequestTimeoutMs=timedRequestTimeoutMs) + + asserts.assert_equal(expected_status, Status.Success) + + except InteractionModelError as e: + asserts.assert_equal(e.status, expected_status, "Unexpected error returned") + + async def send_start_time_adjust_clear_command(self, + endpoint: int = None, timedRequestTimeoutMs: int = 3000, + expected_status: Status = Status.Success): + try: + await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.StartTimeAdjustClear(), # StartTimeAdjustmentClear(), + endpoint=endpoint, + timedRequestTimeoutMs=timedRequestTimeoutMs) + + asserts.assert_equal(expected_status, Status.Success) + + except InteractionModelError as e: + asserts.assert_equal(e.status, expected_status, "Unexpected error returned") + + async def send_cancel_request_command(self, + endpoint: int = None, timedRequestTimeoutMs: int = 3000, + expected_status: Status = Status.Success): + try: + await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.CancelRequest(), + endpoint=endpoint, + timedRequestTimeoutMs=timedRequestTimeoutMs) + + asserts.assert_equal(expected_status, Status.Success) + + except InteractionModelError as e: + asserts.assert_equal(e.status, expected_status, "Unexpected error returned") + + async def send_pause_request_command(self, duration: int, cause: + Clusters.Objects.DeviceEnergyManagement.Enums.AdjustmentCauseEnum, + endpoint: int = None, timedRequestTimeoutMs: int = 3000, + expected_status: Status = Status.Success): + try: + await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.PauseRequest( + duration=duration, + cause=cause), + endpoint=endpoint, + timedRequestTimeoutMs=timedRequestTimeoutMs) + + asserts.assert_equal(expected_status, Status.Success) + + except InteractionModelError as e: + asserts.assert_equal(e.status, expected_status, "Unexpected error returned") + + async def send_resume_request_command(self, endpoint: int = None, timedRequestTimeoutMs: int = 3000, + expected_status: Status = Status.Success): + try: + await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.ResumeRequest(), + endpoint=endpoint, + timedRequestTimeoutMs=timedRequestTimeoutMs) + + asserts.assert_equal(expected_status, Status.Success) + + except InteractionModelError as e: + asserts.assert_equal(e.status, expected_status, "Unexpected error returned") + + async def send_modify_forecast_request_command(self, forecastID: int, + slotAdjustments: list[Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct], + cause: Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum, + endpoint: int = None, timedRequestTimeoutMs: int = 3000, + expected_status: Status = Status.Success): + try: + await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.ModifyForecastRequest(forecastID=forecastID, + slotAdjustments=slotAdjustments, + cause=cause), + endpoint=endpoint, + timedRequestTimeoutMs=timedRequestTimeoutMs) + + asserts.assert_equal(expected_status, Status.Success) + + except InteractionModelError as e: + asserts.assert_equal(e.status, expected_status, "Unexpected error returned") + + async def send_request_constraint_based_forecast(self, constraintList: list[Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct], + cause: Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum, + endpoint: int = None, timedRequestTimeoutMs: int = 3000, + expected_status: Status = Status.Success): + try: + await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.RequestConstraintBasedForecast(constraints=constraintList, + cause=cause), + endpoint=endpoint, + timedRequestTimeoutMs=timedRequestTimeoutMs) + + asserts.assert_equal(expected_status, Status.Success) + + except InteractionModelError as e: + asserts.assert_equal(e.status, expected_status, "Unexpected error returned") + + async def send_test_event_trigger_power_adjustment(self): + await self.send_test_event_triggers(eventTrigger=0x0098000000000000) + + async def send_test_event_trigger_power_adjustment_clear(self): + await self.send_test_event_triggers(eventTrigger=0x0098000000000001) + + async def send_test_event_trigger_user_opt_out_local(self): + await self.send_test_event_triggers(eventTrigger=0x0098000000000002) + + async def send_test_event_trigger_user_opt_out_grid(self): + await self.send_test_event_triggers(eventTrigger=0x0098000000000003) + + async def send_test_event_trigger_user_opt_out_clear_all(self): + await self.send_test_event_triggers(eventTrigger=0x0098000000000004) + + async def send_test_event_trigger_start_time_adjustment(self): + await self.send_test_event_triggers(eventTrigger=0x0098000000000005) + + async def send_test_event_trigger_start_time_adjustment_clear(self): + await self.send_test_event_triggers(eventTrigger=0x0098000000000006) + + async def send_test_event_trigger_pausable(self): + await self.send_test_event_triggers(eventTrigger=0x0098000000000007) + + async def send_test_event_trigger_pausable_next_slot(self): + await self.send_test_event_triggers(eventTrigger=0x0098000000000008) + + async def send_test_event_trigger_pausable_clear(self): + await self.send_test_event_triggers(eventTrigger=0x0098000000000009) + + async def send_test_event_trigger_forecast_adjustment(self): + await self.send_test_event_triggers(eventTrigger=0x009800000000000A) + + async def send_test_event_trigger_forecast_adjustment_next_slot(self): + await self.send_test_event_triggers(eventTrigger=0x009800000000000B) + + async def send_test_event_trigger_forecast_adjustment_clear(self): + await self.send_test_event_triggers(eventTrigger=0x009800000000000C) + + async def send_test_event_trigger_constraint_based_adjustment(self): + await self.send_test_event_triggers(eventTrigger=0x009800000000000D) + + async def send_test_event_trigger_constraint_based_adjustment_clear(self): + await self.send_test_event_triggers(eventTrigger=0x009800000000000E) + + async def send_test_event_trigger_forecast(self): + await self.send_test_event_triggers(eventTrigger=0x009800000000000F) + + async def send_test_event_trigger_forecast_clear(self): + await self.send_test_event_triggers(eventTrigger=0x0098000000000010) + + + diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py index c342d87ef2cf46..3c90bfdab1518b 100644 --- a/src/python_testing/matter_testing_support.py +++ b/src/python_testing/matter_testing_support.py @@ -265,6 +265,15 @@ def wait_for_event_report(self, expected_event: ClusterObjects.ClusterEvent, tim asserts.assert_equal(res.Header.EventId, expected_event.event_id, "Expected event ID not found in event report") return res.Data + def wait_for_no_event_report(self, timeout: int = 10): + """This function allows a test script to block waiting for the specific event to arrive with a timeout. + It returns the event data so that the values can be checked.""" + try: + res = self._q.get(block=True, timeout=timeout) + except queue.Empty: + return + + asserts.assert_equal(False, f"Event reported when not expected {res}") class InternalTestRunnerHooks(TestRunnerHooks): From c683503fdf2d7e90935f8b97f558b0107e17ad3b Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 13 Jun 2024 21:03:05 +0100 Subject: [PATCH 02/74] Get all targets building --- examples/all-clusters-app/ameba/chip_main.cmake | 2 +- examples/all-clusters-app/asr/BUILD.gn | 2 +- examples/all-clusters-app/cc13x4_26x4/BUILD.gn | 2 +- examples/all-clusters-app/infineon/psoc6/BUILD.gn | 2 +- examples/all-clusters-app/linux/BUILD.gn | 2 +- examples/all-clusters-app/nxp/mw320/BUILD.gn | 2 +- examples/all-clusters-app/tizen/BUILD.gn | 2 +- examples/shell/shell_common/BUILD.gn | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) mode change 100755 => 100644 examples/all-clusters-app/ameba/chip_main.cmake mode change 100755 => 100644 examples/all-clusters-app/asr/BUILD.gn diff --git a/examples/all-clusters-app/ameba/chip_main.cmake b/examples/all-clusters-app/ameba/chip_main.cmake old mode 100755 new mode 100644 index e9c55f3de32120..f5f8ed6efd7964 --- a/examples/all-clusters-app/ameba/chip_main.cmake +++ b/examples/all-clusters-app/ameba/chip_main.cmake @@ -193,7 +193,7 @@ list( ${chip_dir}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp - ${chip_dir}/examples/energy-management-app/energy-management-common/src/utils.cpp + ${chip_dir}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp ${chip_dir}/examples/platform/ameba/route_hook/ameba_route_hook.c ${chip_dir}/examples/platform/ameba/route_hook/ameba_route_table.c diff --git a/examples/all-clusters-app/asr/BUILD.gn b/examples/all-clusters-app/asr/BUILD.gn old mode 100755 new mode 100644 index a1fd16aec7e988..c8a73ee116c5c8 --- a/examples/all-clusters-app/asr/BUILD.gn +++ b/examples/all-clusters-app/asr/BUILD.gn @@ -88,7 +88,7 @@ asr_executable("clusters_app") { "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/utils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${examples_plat_dir}/ButtonHandler.cpp", "${examples_plat_dir}/CHIPDeviceManager.cpp", "${examples_plat_dir}/LEDWidget.cpp", diff --git a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn index cf749b38f612ec..d3f2ea753d98ef 100644 --- a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn +++ b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn @@ -78,7 +78,7 @@ ti_simplelink_executable("all-clusters-app") { "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/utils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${chip_root}/examples/providers/DeviceInfoProviderImpl.cpp", "${project_dir}/main/AppTask.cpp", "${project_dir}/main/ClusterManager.cpp", diff --git a/examples/all-clusters-app/infineon/psoc6/BUILD.gn b/examples/all-clusters-app/infineon/psoc6/BUILD.gn index 68e33a28506aed..4e38566ee9e24c 100644 --- a/examples/all-clusters-app/infineon/psoc6/BUILD.gn +++ b/examples/all-clusters-app/infineon/psoc6/BUILD.gn @@ -124,7 +124,7 @@ psoc6_executable("clusters_app") { "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/utils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${examples_plat_dir}/LEDWidget.cpp", "${examples_plat_dir}/init_psoc6Platform.cpp", "src/AppTask.cpp", diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index fa11cfad1b16e7..241f586d40a333 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -66,7 +66,7 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/device-energy-management-mode.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/energy-evse-mode.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/utils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "AllClustersCommandDelegate.cpp", "AppOptions.cpp", "ValveControlDelegate.cpp", diff --git a/examples/all-clusters-app/nxp/mw320/BUILD.gn b/examples/all-clusters-app/nxp/mw320/BUILD.gn index 51c30eb190a9fb..3415f277404f6f 100644 --- a/examples/all-clusters-app/nxp/mw320/BUILD.gn +++ b/examples/all-clusters-app/nxp/mw320/BUILD.gn @@ -92,7 +92,7 @@ mw320_executable("shell_mw320") { "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/utils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${chip_root}/src/lib/shell/streamer_mw320.cpp", "binding-handler.cpp", "include/CHIPProjectConfig.h", diff --git a/examples/all-clusters-app/tizen/BUILD.gn b/examples/all-clusters-app/tizen/BUILD.gn index 7a3ae2a0546a39..7efedb18fda536 100644 --- a/examples/all-clusters-app/tizen/BUILD.gn +++ b/examples/all-clusters-app/tizen/BUILD.gn @@ -44,7 +44,7 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/utils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", ] deps = [ diff --git a/examples/shell/shell_common/BUILD.gn b/examples/shell/shell_common/BUILD.gn index 4f9d75dc2401be..a11f7314e09188 100644 --- a/examples/shell/shell_common/BUILD.gn +++ b/examples/shell/shell_common/BUILD.gn @@ -76,7 +76,7 @@ static_library("shell_common") { "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/utils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", ] include_dirs = [ From 0ac11b7da1eff75acc03cf0d1bf2139975b671a1 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Sat, 15 Jun 2024 07:19:49 +0100 Subject: [PATCH 03/74] Address JamesH review comments --- examples/all-clusters-app/ameba/chip_main.cmake | 2 +- examples/all-clusters-app/cc13x4_26x4/BUILD.gn | 4 ++-- examples/all-clusters-app/linux/BUILD.gn | 2 +- examples/all-clusters-app/mbed/CMakeLists.txt | 8 ++++---- examples/all-clusters-app/nrfconnect/CMakeLists.txt | 6 +++--- examples/all-clusters-app/tizen/BUILD.gn | 2 +- .../include/DEMManufacturerDelegate.h | 2 +- .../energy-management-common/include/DEMUtils.h | 4 ++-- .../src/DEMTestEventTriggers.cpp | 1 - .../energy-management-common/src/DEMUtils.cpp | 12 ++++++------ examples/shell/shell_common/BUILD.gn | 2 +- src/python_testing/matter_testing_support.py | 4 ++-- 12 files changed, 24 insertions(+), 25 deletions(-) diff --git a/examples/all-clusters-app/ameba/chip_main.cmake b/examples/all-clusters-app/ameba/chip_main.cmake index f5f8ed6efd7964..36e0f4829917d7 100644 --- a/examples/all-clusters-app/ameba/chip_main.cmake +++ b/examples/all-clusters-app/ameba/chip_main.cmake @@ -187,13 +187,13 @@ list( ${chip_dir}/examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-device.cpp + ${chip_dir}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp - ${chip_dir}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp ${chip_dir}/examples/platform/ameba/route_hook/ameba_route_hook.c ${chip_dir}/examples/platform/ameba/route_hook/ameba_route_table.c diff --git a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn index d3f2ea753d98ef..45735da251279f 100644 --- a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn +++ b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn @@ -72,13 +72,13 @@ ti_simplelink_executable("all-clusters-app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${chip_root}/examples/providers/DeviceInfoProviderImpl.cpp", "${project_dir}/main/AppTask.cpp", "${project_dir}/main/ClusterManager.cpp", diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index 241f586d40a333..b7b9e2073a6c0f 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -58,6 +58,7 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp", "${chip_root}/examples/all-clusters-app/linux/diagnostic-logs-provider-delegate-impl.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", @@ -66,7 +67,6 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/device-energy-management-mode.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/energy-evse-mode.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "AllClustersCommandDelegate.cpp", "AppOptions.cpp", "ValveControlDelegate.cpp", diff --git a/examples/all-clusters-app/mbed/CMakeLists.txt b/examples/all-clusters-app/mbed/CMakeLists.txt index a80d159e1a5e63..c0da3c948091cf 100644 --- a/examples/all-clusters-app/mbed/CMakeLists.txt +++ b/examples/all-clusters-app/mbed/CMakeLists.txt @@ -72,13 +72,13 @@ target_sources(${APP_TARGET} PRIVATE ${ALL_CLUSTERS_COMMON}/src/smco-stub.cpp ${ALL_CLUSTERS_COMMON}/src/static-supported-modes-manager.cpp ${ALL_CLUSTERS_COMMON}/src/static-supported-temperature-levels.cpp - ${ENERGY_MANAGEMENT_COMMON}/src/ElectricalPowerMeasurementDelegate.cpp - ${ENERGY_MANAGEMENT_COMMON}/src/EnergyEvseDelegateImpl.cpp - ${ENERGY_MANAGEMENT_COMMON}/src/EnergyEvseManager.cpp + ${ENERGY_MANAGEMENT_COMMON}/src/DEMUtils.cpp ${ENERGY_MANAGEMENT_COMMON}/src/DeviceEnergyManagementDelegateImpl.cpp ${ENERGY_MANAGEMENT_COMMON}/src/DeviceEnergyManagementManager.cpp ${ENERGY_MANAGEMENT_COMMON}/src/EVSEManufacturerImpl.cpp - ${ENERGY_MANAGEMENT_COMMON}/src/utils.cpp + ${ENERGY_MANAGEMENT_COMMON}/src/ElectricalPowerMeasurementDelegate.cpp + ${ENERGY_MANAGEMENT_COMMON}/src/EnergyEvseDelegateImpl.cpp + ${ENERGY_MANAGEMENT_COMMON}/src/EnergyEvseManager.cpp ) chip_configure_data_model(${APP_TARGET} diff --git a/examples/all-clusters-app/nrfconnect/CMakeLists.txt b/examples/all-clusters-app/nrfconnect/CMakeLists.txt index 7301361b97ed6f..d2a0a48e31f523 100644 --- a/examples/all-clusters-app/nrfconnect/CMakeLists.txt +++ b/examples/all-clusters-app/nrfconnect/CMakeLists.txt @@ -50,7 +50,7 @@ include(${CHIP_ROOT}/src/app/chip_data_model.cmake) target_include_directories(app PRIVATE main/include ${ALL_CLUSTERS_COMMON_DIR}/include - ${ENERGY_MANAGEMENT_COMMON_DIR}/include + ${ENERGY_MANAGEMENT_COMMON_DIR}/include ${GEN_DIR}/app-common ${GEN_DIR}/all-clusters-app ${NRFCONNECT_COMMON}/util/include) @@ -65,15 +65,15 @@ target_sources(app PRIVATE ${ALL_CLUSTERS_COMMON_DIR}/src/fan-stub.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/oven-modes.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/energy-evse-stub.cpp - ${ALL_CLUSTERS_COMMON_DIR}/src/device-energy-management-stub.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/device-energy-management-stub.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/binding-handler.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/air-quality-instance.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/concentration-measurement-instances.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/resource-monitoring-delegates.cpp + ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DEMUtils.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DeviceEnergyManagementDelegateImpl.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DeviceEnergyManagementManager.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EVSEManufacturerImpl.cpp - ${ENERGY_MANAGEMENT_COMMON_DIR}/src/utils.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/ElectricalPowerMeasurementDelegate.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EnergyEvseDelegateImpl.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EnergyEvseManager.cpp diff --git a/examples/all-clusters-app/tizen/BUILD.gn b/examples/all-clusters-app/tizen/BUILD.gn index 7efedb18fda536..451f9a91b0448a 100644 --- a/examples/all-clusters-app/tizen/BUILD.gn +++ b/examples/all-clusters-app/tizen/BUILD.gn @@ -38,13 +38,13 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", ] deps = [ diff --git a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h index 4aa0d5f322c253..feaff160629d0f 100644 --- a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h +++ b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/energy-management-common/include/DEMUtils.h b/examples/energy-management-app/energy-management-common/include/DEMUtils.h index 66bc155a679c9f..11261ce7104931 100644 --- a/examples/energy-management-app/energy-management-common/include/DEMUtils.h +++ b/examples/energy-management-app/energy-management-common/include/DEMUtils.h @@ -44,7 +44,7 @@ CHIP_ERROR UtilsGetEpochTS(uint32_t & chipEpoch); * @return bitmap value for day of week * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) */ -uint8_t UtilsGetDayOfWeekUnixEpoch(time_t unixEpoch); +uint8_t UtilsGetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch); /** * @brief Helper function to get current timestamp and work out the day of week based on localtime @@ -53,4 +53,4 @@ uint8_t UtilsGetDayOfWeekUnixEpoch(time_t unixEpoch); * * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) */ -CHIP_ERROR UtilsGetDayOfWeekNow(uint8_t & dayOfWeekMap); +CHIP_ERROR UtilsGetLocalDayOfWeekNow(uint8_t & dayOfWeekMap); diff --git a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp index 72cf4f2e6a1b7f..8de283e048584f 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp @@ -310,7 +310,6 @@ void SetTestEventTrigger_ConstraintBasedAdjustment() bool HandleDeviceEnergyManagementTestEventTrigger(uint64_t eventTrigger) { - ChipLogError(Zcl,"HandleDeviceEnergyManagementTestEventTrigger"); DeviceEnergyManagementTrigger trigger = static_cast(eventTrigger); switch (trigger) diff --git a/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp b/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp index 165486c41a4573..eff5d19bf3f5d6 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp @@ -34,7 +34,7 @@ using chip::Protocols::InteractionModel::Status; /** * @brief Helper function to get current timestamp in Epoch format * - * @param chipEpoch reference to hold return timestamp + * @param[out] chipEpoch reference to hold return timestamp. Set to 0 if an error occurs. */ CHIP_ERROR UtilsGetEpochTS(uint32_t & chipEpoch) { @@ -59,7 +59,7 @@ CHIP_ERROR UtilsGetEpochTS(uint32_t & chipEpoch) auto unixEpoch = std::chrono::duration_cast(cTMs).count(); if (!UnixEpochToChipEpochTime(unixEpoch, chipEpoch)) { - ChipLogError(Zcl, "EVSE: unable to convert Unix Epoch time to Matter Epoch Time"); + ChipLogError(Zcl, "Unable to convert Unix Epoch time to Matter Epoch Time"); return err; } @@ -78,7 +78,7 @@ CHIP_ERROR UtilsGetEpochTS(uint32_t & chipEpoch) * @return bitmap value for day of week * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) */ -uint8_t UtilsGetDayOfWeekUnixEpoch(time_t unixEpoch) +uint8_t UtilsGetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch) { // Define a timezone structure and initialize it to the local timezone // This will capture any daylight saving time changes @@ -100,17 +100,17 @@ uint8_t UtilsGetDayOfWeekUnixEpoch(time_t unixEpoch) * * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) */ -CHIP_ERROR UtilsGetDayOfWeekNow(uint8_t & dayOfWeekMap) +CHIP_ERROR UtilsGetLocalDayOfWeekNow(uint8_t & dayOfWeekMap) { chip::System::Clock::Milliseconds64 cTMs; CHIP_ERROR err = chip::System::SystemClock().GetClock_RealTimeMS(cTMs); if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "EVSE: unable to get current time to check user schedules error=%" CHIP_ERROR_FORMAT, err.Format()); + ChipLogError(Zcl, "Uable to get current time. error=%" CHIP_ERROR_FORMAT, err.Format()); return err; } time_t unixEpoch = std::chrono::duration_cast(cTMs).count(); - dayOfWeekMap = UtilsGetDayOfWeekUnixEpoch(unixEpoch); + dayOfWeekMap = UtilsGetLocalDayOfWeekFromUnixEpoch(unixEpoch); return CHIP_NO_ERROR; } diff --git a/examples/shell/shell_common/BUILD.gn b/examples/shell/shell_common/BUILD.gn index a11f7314e09188..44242a0f2918c7 100644 --- a/examples/shell/shell_common/BUILD.gn +++ b/examples/shell/shell_common/BUILD.gn @@ -70,13 +70,13 @@ static_library("shell_common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", ] include_dirs = [ diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py index 3c90bfdab1518b..547c72e1461ea6 100644 --- a/src/python_testing/matter_testing_support.py +++ b/src/python_testing/matter_testing_support.py @@ -266,8 +266,8 @@ def wait_for_event_report(self, expected_event: ClusterObjects.ClusterEvent, tim return res.Data def wait_for_no_event_report(self, timeout: int = 10): - """This function allows a test script to block waiting for the specific event to arrive with a timeout. - It returns the event data so that the values can be checked.""" + """This function succceeds/returns if an event does not arrive within the timeout. + If an event does arrive, an assert is called.""" try: res = self._q.get(block=True, timeout=timeout) except queue.Empty: From 3cb089fc45f0e0017c85a2c4f8eee3ed531a6a07 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Sat, 15 Jun 2024 07:26:19 +0100 Subject: [PATCH 04/74] Rename utils.cpp to DEMUtils.cpp --- examples/all-clusters-app/openiotsdk/CMakeLists.txt | 12 ++++++------ examples/all-clusters-app/telink/CMakeLists.txt | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/all-clusters-app/openiotsdk/CMakeLists.txt b/examples/all-clusters-app/openiotsdk/CMakeLists.txt index f3d98c4b64dd34..4787bf9f79904b 100644 --- a/examples/all-clusters-app/openiotsdk/CMakeLists.txt +++ b/examples/all-clusters-app/openiotsdk/CMakeLists.txt @@ -48,7 +48,7 @@ target_include_directories(${APP_TARGET} PRIVATE main/include ${ALL_CLUSTERS_COMMON}/include - ${ENERGY_MANAGEMENT_COMMON}/include + ${ENERGY_MANAGEMENT_COMMON}/include ) target_sources(${APP_TARGET} @@ -60,18 +60,18 @@ target_sources(${APP_TARGET} ${ALL_CLUSTERS_COMMON}/src/concentration-measurement-instances.cpp ${ALL_CLUSTERS_COMMON}/src/fan-stub.cpp ${ALL_CLUSTERS_COMMON}/src/oven-modes.cpp - ${ALL_CLUSTERS_COMMON}/src/device-energy-management-stub.cpp + ${ALL_CLUSTERS_COMMON}/src/device-energy-management-stub.cpp ${ALL_CLUSTERS_COMMON}/src/energy-evse-stub.cpp ${ALL_CLUSTERS_COMMON}/src/resource-monitoring-delegates.cpp ${ALL_CLUSTERS_COMMON}/src/static-supported-modes-manager.cpp ${ALL_CLUSTERS_COMMON}/src/binding-handler.cpp - ${ENERGY_MANAGEMENT_COMMON}/src/ElectricalPowerMeasurementDelegate.cpp - ${ENERGY_MANAGEMENT_COMMON}/src/EnergyEvseDelegateImpl.cpp - ${ENERGY_MANAGEMENT_COMMON}/src/EnergyEvseManager.cpp + ${ENERGY_MANAGEMENT_COMMON}/src/DEMUtils.cpp ${ENERGY_MANAGEMENT_COMMON}/src/DeviceEnergyManagementDelegateImpl.cpp ${ENERGY_MANAGEMENT_COMMON}/src/DeviceEnergyManagementManager.cpp ${ENERGY_MANAGEMENT_COMMON}/src/EVSEManufacturerImpl.cpp - ${ENERGY_MANAGEMENT_COMMON}/src/utils.cpp + ${ENERGY_MANAGEMENT_COMMON}/src/ElectricalPowerMeasurementDelegate.cpp + ${ENERGY_MANAGEMENT_COMMON}/src/EnergyEvseDelegateImpl.cpp + ${ENERGY_MANAGEMENT_COMMON}/src/EnergyEvseManager.cpp ) target_link_libraries(${APP_TARGET} diff --git a/examples/all-clusters-app/telink/CMakeLists.txt b/examples/all-clusters-app/telink/CMakeLists.txt index 58a6bb82963314..223a8e1f29b06f 100644 --- a/examples/all-clusters-app/telink/CMakeLists.txt +++ b/examples/all-clusters-app/telink/CMakeLists.txt @@ -31,7 +31,7 @@ project(chip-telink-all-clusters-app-example) target_include_directories(app PRIVATE include ${ALL_CLUSTERS_COMMON_DIR}/include - ${ENERGY_MANAGEMENT_COMMON_DIR}/include + ${ENERGY_MANAGEMENT_COMMON_DIR}/include ${GEN_DIR}/app-common ${GEN_DIR}/all-clusters-app ${TELINK_COMMON}/common/include @@ -48,16 +48,16 @@ target_sources(app PRIVATE ${ALL_CLUSTERS_COMMON_DIR}/src/air-quality-instance.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/concentration-measurement-instances.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/fan-stub.cpp - ${ALL_CLUSTERS_COMMON_DIR}/src/device-energy-management-stub.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/device-energy-management-stub.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/energy-evse-stub.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/resource-monitoring-delegates.cpp - ${ENERGY_MANAGEMENT_COMMON_DIR}/src/ElectricalPowerMeasurementDelegate.cpp - ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EnergyEvseDelegateImpl.cpp - ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EnergyEvseManager.cpp + ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DEMUtils.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DeviceEnergyManagementDelegateImpl.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DeviceEnergyManagementManager.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EVSEManufacturerImpl.cpp - ${ENERGY_MANAGEMENT_COMMON_DIR}/src/utils.cpp + ${ENERGY_MANAGEMENT_COMMON_DIR}/src/ElectricalPowerMeasurementDelegate.cpp + ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EnergyEvseDelegateImpl.cpp + ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EnergyEvseManager.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp ${TELINK_COMMON}/util/src/LEDManager.cpp From 6688c42bf2f143c003432a234e63cb931a51ede0 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Sat, 15 Jun 2024 07:52:07 +0100 Subject: [PATCH 05/74] Address JamesH review comments --- examples/all-clusters-app/asr/BUILD.gn | 2 +- examples/all-clusters-app/infineon/psoc6/BUILD.gn | 2 +- examples/all-clusters-app/nxp/mw320/BUILD.gn | 2 +- .../include/DeviceEnergyManagementDelegateImpl.h | 2 +- .../src/DeviceEnergyManagementDelegateImpl.cpp | 2 +- .../energy-management-common/src/EnergyEvseMain.cpp | 2 +- src/python_testing/TC_DEM_2_2.py | 2 +- src/python_testing/matter_testing_support.py | 4 ++-- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/all-clusters-app/asr/BUILD.gn b/examples/all-clusters-app/asr/BUILD.gn index c8a73ee116c5c8..94bbbf0e0f83b5 100644 --- a/examples/all-clusters-app/asr/BUILD.gn +++ b/examples/all-clusters-app/asr/BUILD.gn @@ -82,13 +82,13 @@ asr_executable("clusters_app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${examples_plat_dir}/ButtonHandler.cpp", "${examples_plat_dir}/CHIPDeviceManager.cpp", "${examples_plat_dir}/LEDWidget.cpp", diff --git a/examples/all-clusters-app/infineon/psoc6/BUILD.gn b/examples/all-clusters-app/infineon/psoc6/BUILD.gn index 4e38566ee9e24c..151e12926e8b81 100644 --- a/examples/all-clusters-app/infineon/psoc6/BUILD.gn +++ b/examples/all-clusters-app/infineon/psoc6/BUILD.gn @@ -118,13 +118,13 @@ psoc6_executable("clusters_app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${examples_plat_dir}/LEDWidget.cpp", "${examples_plat_dir}/init_psoc6Platform.cpp", "src/AppTask.cpp", diff --git a/examples/all-clusters-app/nxp/mw320/BUILD.gn b/examples/all-clusters-app/nxp/mw320/BUILD.gn index 3415f277404f6f..26725fc2b1da41 100644 --- a/examples/all-clusters-app/nxp/mw320/BUILD.gn +++ b/examples/all-clusters-app/nxp/mw320/BUILD.gn @@ -86,13 +86,13 @@ mw320_executable("shell_mw320") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${chip_root}/src/lib/shell/streamer_mw320.cpp", "binding-handler.cpp", "include/CHIPProjectConfig.h", 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 f993a2efca3d6a..e16ecb65b023d3 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -40,7 +40,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate void SetDeviceEnergyManagementInstance(DeviceEnergyManagement::Instance & instance); - void SetDemManufacturerDelegate(DEMManufacturerDelegate & deviceEnergyManagementManufacturerDelegate); + void SetDEMManufacturerDelegate(DEMManufacturerDelegate & deviceEnergyManagementManufacturerDelegate); /** * 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 6c49f008cc535d..00e74ff54f36a4 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -62,7 +62,7 @@ uint32_t DeviceEnergyManagementDelegate::HasFeature(Feature feature) const return hasFeature; } -void DeviceEnergyManagementDelegate::SetDemManufacturerDelegate(DEMManufacturerDelegate & deviceEnergyManagementManufacturerDelegate) +void DeviceEnergyManagementDelegate::SetDEMManufacturerDelegate(DEMManufacturerDelegate & deviceEnergyManagementManufacturerDelegate) { mpDEMManufacturerDelegate = &deviceEnergyManagementManufacturerDelegate; } diff --git a/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp b/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp index bc16e5f91d59d9..83a75892166553 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp @@ -387,7 +387,7 @@ CHIP_ERROR EVSEManufacturerInit() return CHIP_ERROR_NO_MEMORY; } - gDEMDelegate.get()->SetDemManufacturerDelegate(*gEvseManufacturer.get()); + gDEMDelegate.get()->SetDEMManufacturerDelegate(*gEvseManufacturer.get()); /* Call Manufacturer specific init */ err = gEvseManufacturer->Init(); diff --git a/src/python_testing/TC_DEM_2_2.py b/src/python_testing/TC_DEM_2_2.py index 49288a7d05a414..03e63c80c4e84f 100644 --- a/src/python_testing/TC_DEM_2_2.py +++ b/src/python_testing/TC_DEM_2_2.py @@ -225,7 +225,7 @@ async def test_TC_DEM_2_2(self): cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization) # Wait 5 seconds for an event not to be reported - events_callback.wait_for_no_event_report(5) + events_callback.wait_for_event_expect_no_report(5) self.step("12a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kPowerAdjustActive) diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py index 547c72e1461ea6..9eb3a0e391d29e 100644 --- a/src/python_testing/matter_testing_support.py +++ b/src/python_testing/matter_testing_support.py @@ -265,7 +265,7 @@ def wait_for_event_report(self, expected_event: ClusterObjects.ClusterEvent, tim asserts.assert_equal(res.Header.EventId, expected_event.event_id, "Expected event ID not found in event report") return res.Data - def wait_for_no_event_report(self, timeout: int = 10): + def wait_for_event_expect_no_report(self, timeout: int = 10): """This function succceeds/returns if an event does not arrive within the timeout. If an event does arrive, an assert is called.""" try: @@ -273,7 +273,7 @@ def wait_for_no_event_report(self, timeout: int = 10): except queue.Empty: return - asserts.assert_equal(False, f"Event reported when not expected {res}") + asserts.fail(f"Event reported when not expected {res}") class InternalTestRunnerHooks(TestRunnerHooks): From f0858e126fd358a09237f4a3797fd9b23366b796 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sat, 15 Jun 2024 06:52:47 +0000 Subject: [PATCH 06/74] Restyled by whitespace --- .../energy-management-common/include/DEMManufacturerDelegate.h | 1 - .../include/EnergyManagementAppCmdLineOptions.h | 1 - .../energy-management-common/include/FakeReadings.h | 1 - 3 files changed, 3 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h index feaff160629d0f..0f502d22d5515e 100644 --- a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h +++ b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h @@ -101,4 +101,3 @@ class DEMManufacturerDelegate } // namespace Clusters } // namespace app } // namespace chip - diff --git a/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h b/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h index fc64112e34e961..9bcb3dfedbf9da 100644 --- a/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h +++ b/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h @@ -22,4 +22,3 @@ #include chip::BitMask GetFeatureMap(); - diff --git a/examples/energy-management-app/energy-management-common/include/FakeReadings.h b/examples/energy-management-app/energy-management-common/include/FakeReadings.h index 4d17b5b3b37594..a8b953f26c77de 100644 --- a/examples/energy-management-app/energy-management-common/include/FakeReadings.h +++ b/examples/energy-management-app/energy-management-common/include/FakeReadings.h @@ -117,4 +117,3 @@ class FakeReadings /* Periodic Energy Imported which is updated if mPower < 0 */ int64_t mPeriodicEnergyExported = 0; }; - From 757bc1cfd218d00b4a641e3b613b38f7e23b7474 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sat, 15 Jun 2024 06:52:49 +0000 Subject: [PATCH 07/74] Restyled by clang-format --- .../include/DEMManufacturerDelegate.h | 51 +++++--------- .../include/DEMUtils.h | 4 +- .../DeviceEnergyManagementDelegateImpl.h | 7 +- .../include/DeviceEnergyManagementManager.h | 3 +- .../include/EVSEManufacturerImpl.h | 36 +++++----- .../include/FakeReadings.h | 15 ++--- .../src/DEMTestEventTriggers.cpp | 66 +++++++++++-------- .../energy-management-common/src/DEMUtils.cpp | 2 +- .../DeviceEnergyManagementDelegateImpl.cpp | 62 +++++++++-------- .../src/DeviceEnergyManagementManager.cpp | 3 +- .../src/EVSEManufacturerImpl.cpp | 22 ++++--- .../src/EnergyEvseMain.cpp | 3 +- .../src/EnergyReportingEventTriggers.cpp | 8 +-- .../src/FakeReadings.cpp | 33 ++++------ .../energy-management-app/esp32/main/main.cpp | 12 ++-- examples/energy-management-app/linux/main.cpp | 32 ++++----- .../device-energy-management-server.h | 24 +++---- 17 files changed, 178 insertions(+), 205 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h index 0f502d22d5515e..e74ecbae98ad67 100644 --- a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h +++ b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h @@ -33,32 +33,24 @@ class DeviceEnergyManagementDelegate; class DEMManufacturerDelegate { public: - DEMManufacturerDelegate() - { - } + DEMManufacturerDelegate() {} - virtual ~DEMManufacturerDelegate() - { - } + virtual ~DEMManufacturerDelegate() {} virtual int64_t GetEnergyUse() = 0; - virtual CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t power, const uint32_t duration, AdjustmentCauseEnum cause) + virtual CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t power, const uint32_t duration, + AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; } - virtual CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustCompletion() - { - return CHIP_NO_ERROR; - } + virtual CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustCompletion() { return CHIP_NO_ERROR; } - virtual CHIP_ERROR HandleDeviceEnergyManagementCancelPowerAdjustRequest(CauseEnum cause) - { - return CHIP_NO_ERROR; - } + virtual CHIP_ERROR HandleDeviceEnergyManagementCancelPowerAdjustRequest(CauseEnum cause) { return CHIP_NO_ERROR; } - virtual CHIP_ERROR HandleDeviceEnergyManagementStartTimeAdjustRequest(const uint32_t requestedStartTime, AdjustmentCauseEnum cause) + virtual CHIP_ERROR HandleDeviceEnergyManagementStartTimeAdjustRequest(const uint32_t requestedStartTime, + AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; } @@ -68,30 +60,23 @@ class DEMManufacturerDelegate return CHIP_NO_ERROR; } - virtual CHIP_ERROR HandleDeviceEnergyManagementPauseCompletion() - { - return CHIP_NO_ERROR; - } + virtual CHIP_ERROR HandleDeviceEnergyManagementPauseCompletion() { return CHIP_NO_ERROR; } - virtual CHIP_ERROR HandleDeviceEnergyManagementCancelPauseRequest(CauseEnum cause) - { - return CHIP_NO_ERROR; - } + virtual CHIP_ERROR HandleDeviceEnergyManagementCancelPauseRequest(CauseEnum cause) { return CHIP_NO_ERROR; } - virtual CHIP_ERROR HandleDeviceEnergyManagementCancelRequest() - { - return CHIP_NO_ERROR; - } + virtual CHIP_ERROR HandleDeviceEnergyManagementCancelRequest() { return CHIP_NO_ERROR; } - virtual CHIP_ERROR HandleModifyRequest(const uint32_t forecastID, - const DataModel::DecodableList & slotAdjustments, - AdjustmentCauseEnum cause) + virtual CHIP_ERROR + HandleModifyRequest(const uint32_t forecastID, + const DataModel::DecodableList & slotAdjustments, + AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; } - virtual CHIP_ERROR RequestConstraintBasedForecast(const DataModel::DecodableList & constraints, - AdjustmentCauseEnum cause) + virtual CHIP_ERROR RequestConstraintBasedForecast( + const DataModel::DecodableList & constraints, + AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; } diff --git a/examples/energy-management-app/energy-management-common/include/DEMUtils.h b/examples/energy-management-app/energy-management-common/include/DEMUtils.h index 11261ce7104931..d4a0785808e6a5 100644 --- a/examples/energy-management-app/energy-management-common/include/DEMUtils.h +++ b/examples/energy-management-app/energy-management-common/include/DEMUtils.h @@ -18,10 +18,10 @@ #pragma once -#include -#include #include #include +#include +#include using chip::Protocols::InteractionModel::Status; 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 e16ecb65b023d3..4871dbaf342c86 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -18,9 +18,8 @@ #pragma once -#include #include - +#include using chip::Protocols::InteractionModel::Status; namespace chip { @@ -225,11 +224,11 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate private: // Have a pointer to partner instance object - DeviceEnergyManagement::Instance *mpDEMInstance; + DeviceEnergyManagement::Instance * mpDEMInstance; // The DEMManufacturerDelegate object knows how to handle // manufacturer/product specific operations - DEMManufacturerDelegate *mpDEMManufacturerDelegate; + DEMManufacturerDelegate * mpDEMManufacturerDelegate; // Various attributes ESATypeEnum mEsaType; diff --git a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h index 5098f665c500e1..79e061421c5cf4 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h @@ -18,15 +18,14 @@ #pragma once +#include #include #include -#include namespace chip { namespace app { namespace Clusters { - using namespace chip::app::Clusters::DeviceEnergyManagement; class DeviceEnergyManagementManager : public Instance diff --git a/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h b/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h index 179b4a0efee35a..24e5728a326f08 100644 --- a/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h +++ b/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h @@ -18,8 +18,8 @@ #pragma once -#include #include +#include #include #include #include @@ -34,7 +34,7 @@ namespace EnergyEvse { * The EVSEManufacturer example class */ -class EVSEManufacturer: public DEMManufacturerDelegate +class EVSEManufacturer : public DEMManufacturerDelegate { public: EVSEManufacturer(EnergyEvseManager * aEvseInstance, @@ -47,19 +47,11 @@ class EVSEManufacturer: public DEMManufacturerDelegate mDEMInstance = aDEMInstance; } - virtual ~EVSEManufacturer() - { - } + virtual ~EVSEManufacturer() {} - EnergyEvseManager * GetEvseInstance() - { - return mEvseInstance; - } + EnergyEvseManager * GetEvseInstance() { return mEvseInstance; } - ElectricalPowerMeasurement::ElectricalPowerMeasurementInstance * GetEPMInstance() - { - return mEPMInstance; - } + ElectricalPowerMeasurement::ElectricalPowerMeasurementInstance * GetEPMInstance() { return mEPMInstance; } EnergyEvseDelegate * GetEvseDelegate() { @@ -103,19 +95,23 @@ class EVSEManufacturer: public DEMManufacturerDelegate * */ int64_t GetEnergyUse() override; - CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t power, const uint32_t duration, AdjustmentCauseEnum cause) override; + CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t power, const uint32_t duration, + AdjustmentCauseEnum cause) override; CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustCompletion() override; CHIP_ERROR HandleDeviceEnergyManagementCancelPowerAdjustRequest(CauseEnum cause) override; - CHIP_ERROR HandleDeviceEnergyManagementStartTimeAdjustRequest(const uint32_t requestedStartTime, AdjustmentCauseEnum cause) override; + CHIP_ERROR HandleDeviceEnergyManagementStartTimeAdjustRequest(const uint32_t requestedStartTime, + AdjustmentCauseEnum cause) override; CHIP_ERROR HandleDeviceEnergyManagementPauseRequest(const uint32_t duration, AdjustmentCauseEnum cause) override; CHIP_ERROR HandleDeviceEnergyManagementPauseCompletion() override; CHIP_ERROR HandleDeviceEnergyManagementCancelPauseRequest(CauseEnum cause) override; CHIP_ERROR HandleDeviceEnergyManagementCancelRequest() override; - CHIP_ERROR HandleModifyRequest(const uint32_t forecastID, - const DataModel::DecodableList & slotAdjustments, - AdjustmentCauseEnum cause) override; - CHIP_ERROR RequestConstraintBasedForecast(const DataModel::DecodableList & constraints, - AdjustmentCauseEnum cause) override; + CHIP_ERROR HandleModifyRequest( + const uint32_t forecastID, + const DataModel::DecodableList & slotAdjustments, + AdjustmentCauseEnum cause) override; + CHIP_ERROR RequestConstraintBasedForecast( + const DataModel::DecodableList & constraints, + AdjustmentCauseEnum cause) override; /** * @brief Called at start up to apply hardware settings diff --git a/examples/energy-management-app/energy-management-common/include/FakeReadings.h b/examples/energy-management-app/energy-management-common/include/FakeReadings.h index a8b953f26c77de..7667a4b5779712 100644 --- a/examples/energy-management-app/energy-management-common/include/FakeReadings.h +++ b/examples/energy-management-app/energy-management-common/include/FakeReadings.h @@ -18,13 +18,12 @@ #pragma once -#include -#include #include +#include +#include #define MAX_SLOTS 10 - class FakeReadings { public: @@ -48,9 +47,9 @@ class FakeReadings * @param[in] aInterval_s - the callback interval in seconds * @param[in] bReset - boolean: true will reset the energy values to 0 */ - void StartFakeReadings(chip::EndpointId aEndpointId, int64_t aPower_mW, uint32_t aPowerRandomness_mW, - int64_t aVoltage_mV, uint32_t aVoltageRandomness_mV, int64_t aCurrent_mA, - uint32_t aCurrentRandomness_mA, uint8_t aInterval_s, bool bReset); + void StartFakeReadings(chip::EndpointId aEndpointId, int64_t aPower_mW, uint32_t aPowerRandomness_mW, int64_t aVoltage_mV, + uint32_t aVoltageRandomness_mV, int64_t aCurrent_mA, uint32_t aCurrentRandomness_mA, uint8_t aInterval_s, + bool bReset); /** * @brief Stops any active updates to the fake load data callbacks @@ -106,10 +105,10 @@ class FakeReadings */ /* Cumulative Energy Imported which is updated if mPower > 0 */ - int64_t mTotalEnergyImported = 0; + int64_t mTotalEnergyImported = 0; /* Cumulative Energy Imported which is updated if mPower < 0 */ - int64_t mTotalEnergyExported = 0; + int64_t mTotalEnergyExported = 0; /* Periodic Energy Imported which is updated if mPower > 0 */ int64_t mPeriodicEnergyImported = 0; diff --git a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp index 8de283e048584f..eea6e0073c1481 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp @@ -16,8 +16,8 @@ * limitations under the License. */ -#include #include +#include #include #include @@ -37,7 +37,8 @@ static chip::app::DataModel::Nullable sPowerAdjustmentCapability; +static chip::app::DataModel::Nullable + sPowerAdjustmentCapability; DeviceEnergyManagementDelegate * GetDEMDelegate() { @@ -77,10 +78,10 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots) sForecastStruct.activeSlotNumber.SetNonNull(0); - sSlots[0].minDuration = 10; - sSlots[0].maxDuration = 20; - sSlots[0].defaultDuration = 15; - sSlots[0].elapsedSlotTime = 0; + sSlots[0].minDuration = 10; + sSlots[0].maxDuration = 20; + sSlots[0].defaultDuration = 15; + sSlots[0].elapsedSlotTime = 0; sSlots[0].remainingSlotTime = 0; sSlots[0].slotIsPausable.SetValue(true); @@ -103,10 +104,10 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots) for (uint16_t slotNo = 1; slotNo < numSlots; slotNo++) { - sSlots[slotNo].minDuration = 2 * sSlots[slotNo - 1].minDuration; - sSlots[slotNo].maxDuration = 2 * sSlots[slotNo - 1].maxDuration; - sSlots[slotNo].defaultDuration = 2 * sSlots[slotNo - 1].defaultDuration; - sSlots[slotNo].elapsedSlotTime = 2 * sSlots[slotNo - 1].elapsedSlotTime; + sSlots[slotNo].minDuration = 2 * sSlots[slotNo - 1].minDuration; + sSlots[slotNo].maxDuration = 2 * sSlots[slotNo - 1].maxDuration; + sSlots[slotNo].defaultDuration = 2 * sSlots[slotNo - 1].defaultDuration; + sSlots[slotNo].elapsedSlotTime = 2 * sSlots[slotNo - 1].elapsedSlotTime; sSlots[slotNo].remainingSlotTime = 2 * sSlots[slotNo - 1].remainingSlotTime; // Need slotNo == 1 not to be pausible for test DEM 2.4 step 3b @@ -142,21 +143,20 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots) return CHIP_NO_ERROR; } - - void SetTestEventTrigger_PowerAdjustment() { - sPowerAdjustments[0].minPower = 5000 * 1000; // 5kW - sPowerAdjustments[0].maxPower = 30000 * 1000; // 30kW - sPowerAdjustments[0].minDuration = 10; // 30s - sPowerAdjustments[0].maxDuration = 60; // 60s + sPowerAdjustments[0].minPower = 5000 * 1000; // 5kW + sPowerAdjustments[0].maxPower = 30000 * 1000; // 30kW + sPowerAdjustments[0].minDuration = 10; // 30s + sPowerAdjustments[0].maxDuration = 60; // 60s DataModel::List powerAdjustmentList(sPowerAdjustments, 1); sPowerAdjustCapabilityStruct.cause = PowerAdjustReasonEnum::kNoAdjustment; sPowerAdjustCapabilityStruct.powerAdjustCapability.SetNonNull(powerAdjustmentList); - DataModel::Nullable powerAdjustmentCapability(sPowerAdjustCapabilityStruct); + DataModel::Nullable powerAdjustmentCapability( + sPowerAdjustCapabilityStruct); sPowerAdjustmentCapability.SetNonNull(sPowerAdjustCapabilityStruct); CHIP_ERROR err = GetDEMDelegate()->SetPowerAdjustmentCapability(sPowerAdjustmentCapability); @@ -168,8 +168,8 @@ void SetTestEventTrigger_PowerAdjustment() void SetTestEventTrigger_ClearForecast() { - sPowerAdjustments[0].minPower = 0; - sPowerAdjustments[0].maxPower = 0; + sPowerAdjustments[0].minPower = 0; + sPowerAdjustments[0].maxPower = 0; sPowerAdjustments[0].minDuration = 0; sPowerAdjustments[0].maxDuration = 0; @@ -178,7 +178,8 @@ void SetTestEventTrigger_ClearForecast() sPowerAdjustCapabilityStruct.powerAdjustCapability.SetNonNull(powerAdjustmentList); sPowerAdjustCapabilityStruct.cause = PowerAdjustReasonEnum::kNoAdjustment; - DataModel::Nullable powerAdjustmentCapabilityStruct(sPowerAdjustCapabilityStruct); + DataModel::Nullable powerAdjustmentCapabilityStruct( + sPowerAdjustCapabilityStruct); CHIP_ERROR err = GetDEMDelegate()->SetPowerAdjustmentCapability(powerAdjustmentCapabilityStruct); if (err != CHIP_NO_ERROR) @@ -225,10 +226,10 @@ void SetTestEventTrigger_StartTimeAdjustmentClear() sForecastStruct = GetDEMDelegate()->GetForecast().Value(); sForecastStruct.startTime = static_cast(0); - sForecastStruct.endTime = static_cast(0); + sForecastStruct.endTime = static_cast(0); sForecastStruct.earliestStartTime = Optional>(); - sForecastStruct.latestEndTime = Optional(); + sForecastStruct.latestEndTime = Optional(); DataModel::Nullable forecast(sForecastStruct); @@ -264,7 +265,7 @@ void SetTestEventTrigger_Forecast() void SetTestEventTrigger_ForecastClear() { sForecastStruct.startTime = 0; - sForecastStruct.endTime = 0; + sForecastStruct.endTime = 0; sForecastStruct.earliestStartTime.ClearValue(); sForecastStruct.latestEndTime.ClearValue(); sForecastStruct.isPausable = false; @@ -315,7 +316,9 @@ bool HandleDeviceEnergyManagementTestEventTrigger(uint64_t eventTrigger) switch (trigger) { case DeviceEnergyManagementTrigger::kPowerAdjustment: - ChipLogProgress(Support, "[PowerAdjustment-Test-Event] => Simulate a fixed forecast power usage including one or more PowerAdjustmentStructs"); + ChipLogProgress( + Support, + "[PowerAdjustment-Test-Event] => Simulate a fixed forecast power usage including one or more PowerAdjustmentStructs"); SetTestEventTrigger_PowerAdjustment(); break; case DeviceEnergyManagementTrigger::kPowerAdjustmentClear: @@ -335,7 +338,9 @@ bool HandleDeviceEnergyManagementTestEventTrigger(uint64_t eventTrigger) SetTestEventTrigger_UserOptOutOptimization(OptOutStateEnum::kNoOptOut); break; case DeviceEnergyManagementTrigger::kStartTimeAdjustment: - ChipLogProgress(Support, "[StartTimeAdjustment-Test-Event] => Simulate a fixed forecast with EarliestStartTime earlier than startTime, and LatestEndTime greater than EndTime"); + ChipLogProgress(Support, + "[StartTimeAdjustment-Test-Event] => Simulate a fixed forecast with EarliestStartTime earlier than " + "startTime, and LatestEndTime greater than EndTime"); SetTestEventTrigger_StartTimeAdjustment(); break; case DeviceEnergyManagementTrigger::kStartTimeAdjustmentClear: @@ -343,7 +348,9 @@ bool HandleDeviceEnergyManagementTestEventTrigger(uint64_t eventTrigger) SetTestEventTrigger_StartTimeAdjustmentClear(); break; case DeviceEnergyManagementTrigger::kPausable: - ChipLogProgress(Support, "[Pausable-Test-Event] => Simulate a fixed forecast with one pausable slot with MinPauseDuration >1, MaxPauseDuration>1 and one non pausable slot"); + ChipLogProgress(Support, + "[Pausable-Test-Event] => Simulate a fixed forecast with one pausable slot with MinPauseDuration >1, " + "MaxPauseDuration>1 and one non pausable slot"); SetTestEventTrigger_Pausable(); break; case DeviceEnergyManagementTrigger::kPausableNextSlot: @@ -355,7 +362,8 @@ bool HandleDeviceEnergyManagementTestEventTrigger(uint64_t eventTrigger) SetTestEventTrigger_ClearForecast(); break; case DeviceEnergyManagementTrigger::kForecastAdjustment: - ChipLogProgress(Support, "[ForecastAdjustment-Test-Event] => Simulate a forecast power usage with at least 2 and at most 4 slots"); + ChipLogProgress(Support, + "[ForecastAdjustment-Test-Event] => Simulate a forecast power usage with at least 2 and at most 4 slots"); SetTestEventTrigger_ForecastAdjustment(); break; case DeviceEnergyManagementTrigger::kForecastAdjustmentNextSlot: @@ -367,7 +375,9 @@ bool HandleDeviceEnergyManagementTestEventTrigger(uint64_t eventTrigger) SetTestEventTrigger_ClearForecast(); break; case DeviceEnergyManagementTrigger::kConstraintBasedAdjustment: - ChipLogProgress(Support, "[ConstraintBasedAdjustment-Test-Event] => Simulate a forecast power usage with at least 2 and at most 4 slots"); + ChipLogProgress( + Support, + "[ConstraintBasedAdjustment-Test-Event] => Simulate a forecast power usage with at least 2 and at most 4 slots"); SetTestEventTrigger_ConstraintBasedAdjustment(); break; case DeviceEnergyManagementTrigger::kConstraintBasedAdjustmentClear: diff --git a/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp b/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp index eff5d19bf3f5d6..4b9308fcf6accf 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp @@ -16,10 +16,10 @@ * limitations under the License. */ +#include #include #include #include -#include using namespace chip; using namespace chip::app; 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 00e74ff54f36a4..aab56f4111e3a7 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -30,20 +30,11 @@ using namespace chip::app::Clusters::DeviceEnergyManagement::Attributes; using chip::Optional; using CostsList = DataModel::List; -DeviceEnergyManagementDelegate::DeviceEnergyManagementDelegate(): - mpDEMManufacturerDelegate(nullptr), - mEsaType(ESATypeEnum::kEvse), - mEsaCanGenerate(false), - mEsaState(ESAStateEnum::kOffline), - mAbsMinPower(0), - mAbsMaxPower(0), - mOptOutState(OptOutStateEnum::kNoOptOut), - mPowerAdjustmentInProgress(false), - mPowerAdjustmentStartTime(0), - mPauseRequestInProgress(false), - mPauseRequestStartTime(0) -{ -} +DeviceEnergyManagementDelegate::DeviceEnergyManagementDelegate() : + mpDEMManufacturerDelegate(nullptr), mEsaType(ESATypeEnum::kEvse), mEsaCanGenerate(false), mEsaState(ESAStateEnum::kOffline), + mAbsMinPower(0), mAbsMaxPower(0), mOptOutState(OptOutStateEnum::kNoOptOut), mPowerAdjustmentInProgress(false), + mPowerAdjustmentStartTime(0), mPauseRequestInProgress(false), mPauseRequestStartTime(0) +{} void DeviceEnergyManagementDelegate::SetDeviceEnergyManagementInstance(DeviceEnergyManagement::Instance & instance) { @@ -62,7 +53,8 @@ uint32_t DeviceEnergyManagementDelegate::HasFeature(Feature feature) const return hasFeature; } -void DeviceEnergyManagementDelegate::SetDEMManufacturerDelegate(DEMManufacturerDelegate & deviceEnergyManagementManufacturerDelegate) +void DeviceEnergyManagementDelegate::SetDEMManufacturerDelegate( + DEMManufacturerDelegate & deviceEnergyManagementManufacturerDelegate) { mpDEMManufacturerDelegate = &deviceEnergyManagementManufacturerDelegate; } @@ -140,12 +132,12 @@ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t power, c CHIP_ERROR err = DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(duration), PowerAdjustTimerExpiry, this); if (err != CHIP_NO_ERROR) - { - // TODO: Note: should the PowerAdjust just initiated be cancelled because an Event could not be logged? - ChipLogError(AppServer, "Unable to start a PowerAdjustStart timer: %" CHIP_ERROR_FORMAT, err.Format()); - HandlePowerAdjustRequestFailure(); - return Status::Failure; - } + { + // TODO: Note: should the PowerAdjust just initiated be cancelled because an Event could not be logged? + ChipLogError(AppServer, "Unable to start a PowerAdjustStart timer: %" CHIP_ERROR_FORMAT, err.Format()); + HandlePowerAdjustRequestFailure(); + return Status::Failure; + } if (sendEvent) { @@ -375,8 +367,8 @@ Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t req { // Reset state mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization; - mForecast.Value().startTime = savedStartTime; - mForecast.Value().endTime = savedEndTime; + mForecast.Value().startTime = savedStartTime; + mForecast.Value().endTime = savedEndTime; return Status::Failure; } @@ -529,7 +521,6 @@ void DeviceEnergyManagementDelegate::HandlePauseRequestTimerExpiry() } } - /** * @brief Handles the cancelation of a pause operation * @@ -548,7 +539,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::CancelPauseRequestAndSendEvent(CauseE DeviceLayer::SystemLayer().CancelTimer(PauseRequestTimerExpiry, this); - CHIP_ERROR err = SendResumedEvent(cause); + CHIP_ERROR err = SendResumedEvent(cause); CHIP_ERROR err2 = CHIP_NO_ERROR; // Notify the appliance's that it can resume its intended power setting (or go idle) @@ -895,7 +886,8 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetAbsMaxPower(int64_t newValue) } CHIP_ERROR -DeviceEnergyManagementDelegate::SetPowerAdjustmentCapability(DataModel::Nullable & powerAdjustCapabilityStruct) +DeviceEnergyManagementDelegate::SetPowerAdjustmentCapability( + DataModel::Nullable & powerAdjustCapabilityStruct) { if (powerAdjustCapabilityStruct.IsNull()) { @@ -943,15 +935,18 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal if (oldValue != newValue) { - ChipLogDetail(AppServer, "mOptOutState updated to %d mPowerAdjustmentInProgress %d", static_cast(mOptOutState), mPowerAdjustmentInProgress); + ChipLogDetail(AppServer, "mOptOutState updated to %d mPowerAdjustmentInProgress %d", static_cast(mOptOutState), + mPowerAdjustmentInProgress); MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, OptOutState::Id); } // Cancel any outstanding PowerAdjustment if necessary if (mPowerAdjustmentInProgress) { - if ((newValue == OptOutStateEnum::kLocalOptOut && mPowerAdjustCapabilityStruct.Value().cause == PowerAdjustReasonEnum::kLocalOptimizationAdjustment) || - (newValue == OptOutStateEnum::kGridOptOut && mPowerAdjustCapabilityStruct.Value().cause == PowerAdjustReasonEnum::kGridOptimizationAdjustment) || + if ((newValue == OptOutStateEnum::kLocalOptOut && + mPowerAdjustCapabilityStruct.Value().cause == PowerAdjustReasonEnum::kLocalOptimizationAdjustment) || + (newValue == OptOutStateEnum::kGridOptOut && + mPowerAdjustCapabilityStruct.Value().cause == PowerAdjustReasonEnum::kGridOptimizationAdjustment) || newValue == OptOutStateEnum::kOptOut) { err = CancelPowerAdjustRequestAndSendEvent(DeviceEnergyManagement::CauseEnum::kUserOptOut); @@ -962,8 +957,10 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal if (mPauseRequestInProgress) { // Cancel any outstanding PauseRequest - if ((newValue == OptOutStateEnum::kLocalOptOut && mForecast.Value().forecastUpdateReason == ForecastUpdateReasonEnum::kLocalOptimization) || - (newValue == OptOutStateEnum::kGridOptOut && mForecast.Value().forecastUpdateReason == ForecastUpdateReasonEnum::kGridOptimization) || + if ((newValue == OptOutStateEnum::kLocalOptOut && + mForecast.Value().forecastUpdateReason == ForecastUpdateReasonEnum::kLocalOptimization) || + (newValue == OptOutStateEnum::kGridOptOut && + mForecast.Value().forecastUpdateReason == ForecastUpdateReasonEnum::kGridOptimization) || newValue == OptOutStateEnum::kOptOut) { err = CancelPauseRequestAndSendEvent(DeviceEnergyManagement::CauseEnum::kUserOptOut); @@ -994,7 +991,8 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal } break; default: - ChipLogDetail(AppServer, "Bad ForecastUpdateReasonEnum value of %d", static_cast(mForecast.Value().forecastUpdateReason)); + ChipLogDetail(AppServer, "Bad ForecastUpdateReasonEnum value of %d", + static_cast(mForecast.Value().forecastUpdateReason)); return CHIP_ERROR_BAD_REQUEST; break; } diff --git a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp index 2854ecb91eb030..5ed0445a8e0606 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp @@ -30,8 +30,7 @@ DeviceEnergyManagementManager::DeviceEnergyManagementManager(EndpointId aEndpoin Feature aFeature) : DeviceEnergyManagement::Instance(aEndpointId, aDelegate, aFeature), mDelegate(&aDelegate) -{ -} +{} CHIP_ERROR DeviceEnergyManagementManager::Init() { diff --git a/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp b/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp index 0318334b3a6eda..8a042d9d84a205 100644 --- a/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp @@ -16,18 +16,18 @@ * limitations under the License. */ +#include #include #include -#include #include +#include #include #include #include #include #include #include -#include #include #include @@ -376,7 +376,8 @@ int64_t EVSEManufacturer::GetEnergyUse() return 300; } -CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t power, const uint32_t duration, AdjustmentCauseEnum cause) +CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t power, const uint32_t duration, + AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; } @@ -391,7 +392,8 @@ CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementCancelPowerAdjustReques return CHIP_NO_ERROR; } -CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementStartTimeAdjustRequest(const uint32_t requestedStartTime, AdjustmentCauseEnum cause) +CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementStartTimeAdjustRequest(const uint32_t requestedStartTime, + AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; } @@ -416,15 +418,17 @@ CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementCancelRequest() return CHIP_NO_ERROR; } -CHIP_ERROR EVSEManufacturer::HandleModifyRequest(const uint32_t forecastID, - const DataModel::DecodableList & slotAdjustments, - AdjustmentCauseEnum cause) +CHIP_ERROR EVSEManufacturer::HandleModifyRequest( + const uint32_t forecastID, + const DataModel::DecodableList & slotAdjustments, + AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; } -CHIP_ERROR EVSEManufacturer::RequestConstraintBasedForecast(const DataModel::DecodableList & constraints, - AdjustmentCauseEnum cause) +CHIP_ERROR EVSEManufacturer::RequestConstraintBasedForecast( + const DataModel::DecodableList & constraints, + AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; } diff --git a/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp b/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp index 83a75892166553..2459b9ddbcffe8 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp @@ -93,8 +93,7 @@ CHIP_ERROR DeviceEnergyManagementInit() BitMask featureMap = GetFeatureMap(); /* Manufacturer may optionally not support all features, commands & attributes */ - gDEMInstance = std::make_unique( - EndpointId(ENERGY_EVSE_ENDPOINT), *gDEMDelegate, featureMap); + gDEMInstance = std::make_unique(EndpointId(ENERGY_EVSE_ENDPOINT), *gDEMDelegate, featureMap); if (!gDEMInstance) { diff --git a/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp index 9aecd8d577a7fa..62e9c876ad24de 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp @@ -35,8 +35,8 @@ void SetTestEventTrigger_FakeReadingsLoadStart() uint32_t aCurrentRandomness_mA = 500; // randomness 500mA uint8_t aInterval_s = 2; // 2s updates bool bReset = true; - FakeReadings::GetInstance().StartFakeReadings(EndpointId(1), aPower_mW, aPowerRandomness_mW, aVoltage_mV, aVoltageRandomness_mV, aCurrent_mA, - aCurrentRandomness_mA, aInterval_s, bReset); + FakeReadings::GetInstance().StartFakeReadings(EndpointId(1), aPower_mW, aPowerRandomness_mW, aVoltage_mV, aVoltageRandomness_mV, + aCurrent_mA, aCurrentRandomness_mA, aInterval_s, bReset); } void SetTestEventTrigger_FakeReadingsGeneratorStart() @@ -49,8 +49,8 @@ void SetTestEventTrigger_FakeReadingsGeneratorStart() uint32_t aCurrentRandomness_mA = 500; // randomness 500mA uint8_t aInterval_s = 5; // 5s updates bool bReset = true; - FakeReadings::GetInstance().StartFakeReadings(EndpointId(1), aPower_mW, aPowerRandomness_mW, aVoltage_mV, aVoltageRandomness_mV, aCurrent_mA, - aCurrentRandomness_mA, aInterval_s, bReset); + FakeReadings::GetInstance().StartFakeReadings(EndpointId(1), aPower_mW, aPowerRandomness_mW, aVoltage_mV, aVoltageRandomness_mV, + aCurrent_mA, aCurrentRandomness_mA, aInterval_s, bReset); } void SetTestEventTrigger_FakeReadingsStop() diff --git a/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp b/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp index 0ff7f7b3044b44..61937b91d282c9 100644 --- a/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp +++ b/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp @@ -16,18 +16,18 @@ * limitations under the License. */ +#include #include #include -#include #include +#include #include #include #include #include #include #include -#include #include #include @@ -47,13 +47,9 @@ using namespace chip::app::Clusters::PowerSource::Attributes; using Protocols::InteractionModel::Status; -FakeReadings::FakeReadings() -{ -} +FakeReadings::FakeReadings() {} -FakeReadings::~FakeReadings() -{ -} +FakeReadings::~FakeReadings() {} /* static */ FakeReadings & FakeReadings::GetInstance() @@ -81,9 +77,9 @@ FakeReadings & FakeReadings::GetInstance() * @param[in] aInterval_s - the callback interval in seconds * @param[in] bReset - boolean: true will reset the energy values to 0 */ -void FakeReadings::StartFakeReadings(EndpointId aEndpointId, int64_t aPower_mW, uint32_t aPowerRandomness_mW, - int64_t aVoltage_mV, uint32_t aVoltageRandomness_mV, int64_t aCurrent_mA, - uint32_t aCurrentRandomness_mA, uint8_t aInterval_s, bool bReset) +void FakeReadings::StartFakeReadings(EndpointId aEndpointId, int64_t aPower_mW, uint32_t aPowerRandomness_mW, int64_t aVoltage_mV, + uint32_t aVoltageRandomness_mV, int64_t aCurrent_mA, uint32_t aCurrentRandomness_mA, + uint8_t aInterval_s, bool bReset) { bEnabled = true; mEndpointId = aEndpointId; @@ -127,12 +123,10 @@ void FakeReadings::FakeReadingsUpdate() // Update readings // Avoid using floats - so we will do a basic rand() call which will generate a integer value between 0 and RAND_MAX // first compute power as a mean + some random value in range +/- mPowerRandomness_mW - int64_t power = - (static_cast(rand()) % (2 * mPowerRandomness_mW)) - mPowerRandomness_mW; + int64_t power = (static_cast(rand()) % (2 * mPowerRandomness_mW)) - mPowerRandomness_mW; power += mPower_mW; // add in the base power - int64_t voltage = - (static_cast(rand()) % (2 * mVoltageRandomness_mV)) - mVoltageRandomness_mV; + int64_t voltage = (static_cast(rand()) % (2 * mVoltageRandomness_mV)) - mVoltageRandomness_mV; voltage += mVoltage_mV; // add in the base voltage /* Note: whilst we could compute a current from the power and voltage, @@ -142,8 +136,7 @@ void FakeReadings::FakeReadingsUpdate() * This is meant more as an example to show how to use the APIs, not * to be a real representation of laws of physics. */ - int64_t current = - (static_cast(rand()) % (2 * mCurrentRandomness_mA)) - mCurrentRandomness_mA; + int64_t current = (static_cast(rand()) % (2 * mCurrentRandomness_mA)) - mCurrentRandomness_mA; current += mCurrent_mA; // add in the base current GetEvseManufacturer()->SendPowerReading(mEndpointId, power, voltage, current); @@ -164,11 +157,9 @@ void FakeReadings::FakeReadingsUpdate() mTotalEnergyExported += mPeriodicEnergyExported; } - GetEvseManufacturer()->SendPeriodicEnergyReading(mEndpointId, mPeriodicEnergyImported, - mPeriodicEnergyExported); + GetEvseManufacturer()->SendPeriodicEnergyReading(mEndpointId, mPeriodicEnergyImported, mPeriodicEnergyExported); - GetEvseManufacturer()->SendCumulativeEnergyReading(mEndpointId, mTotalEnergyImported, - mTotalEnergyExported); + GetEvseManufacturer()->SendCumulativeEnergyReading(mEndpointId, mTotalEnergyImported, mTotalEnergyExported); // start/restart the timer DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(mInterval_s), FakeReadingsTimerExpiry, this); diff --git a/examples/energy-management-app/esp32/main/main.cpp b/examples/energy-management-app/esp32/main/main.cpp index 769597357aca85..c52f781454cc75 100644 --- a/examples/energy-management-app/esp32/main/main.cpp +++ b/examples/energy-management-app/esp32/main/main.cpp @@ -99,13 +99,11 @@ DeviceLayer::ESP32SecureCertDACProvider gSecureCertDACProvider; #endif // CONFIG_SEC_CERT_DAC_PROVIDER // Keep track of the parsed featureMap option -static chip::BitMask sFeatureMap(DeviceEnergyManagement::Feature::kPowerAdjustment, - DeviceEnergyManagement::Feature::kPowerForecastReporting, - DeviceEnergyManagement::Feature::kStateForecastReporting, - DeviceEnergyManagement::Feature::kStartTimeAdjustment, - DeviceEnergyManagement::Feature::kPausable, - DeviceEnergyManagement::Feature::kForecastAdjustment, - DeviceEnergyManagement::Feature::kConstraintBasedAdjustment); +static chip::BitMask + sFeatureMap(DeviceEnergyManagement::Feature::kPowerAdjustment, DeviceEnergyManagement::Feature::kPowerForecastReporting, + DeviceEnergyManagement::Feature::kStateForecastReporting, DeviceEnergyManagement::Feature::kStartTimeAdjustment, + DeviceEnergyManagement::Feature::kPausable, DeviceEnergyManagement::Feature::kForecastAdjustment, + DeviceEnergyManagement::Feature::kConstraintBasedAdjustment); chip::Credentials::DeviceAttestationCredentialsProvider * get_dac_provider(void) { diff --git a/examples/energy-management-app/linux/main.cpp b/examples/energy-management-app/linux/main.cpp index d0963f580acc09..84ef54b2fc9674 100644 --- a/examples/energy-management-app/linux/main.cpp +++ b/examples/energy-management-app/linux/main.cpp @@ -28,23 +28,21 @@ using namespace chip::app::Clusters::DeviceEnergyManagement; using namespace chip::app::Clusters::DeviceEnergyManagement::Attributes; // Parse a hex (prefixed by 0x) or decimal (no-prefix) string -static uint32_t ParseNumber(const char *pString); +static uint32_t ParseNumber(const char * pString); // Parses the --featureMap option -static bool FeatureMapOptionHandler(const char * aProgram, chip::ArgParser::OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue); +static bool FeatureMapOptionHandler(const char * aProgram, chip::ArgParser::OptionSet * aOptions, int aIdentifier, + const char * aName, const char * aValue); constexpr uint16_t kOptionFeatureMap = 'f'; // Define the chip::ArgParser command line structures for extending the command line to support the // -f/--featureMap option -static chip::ArgParser::OptionDef sFeatureMapOptionDefs[] = -{ - { "featureSet", chip::ArgParser::kArgumentRequired, kOptionFeatureMap}, - { NULL } +static chip::ArgParser::OptionDef sFeatureMapOptionDefs[] = { + { "featureSet", chip::ArgParser::kArgumentRequired, kOptionFeatureMap }, { NULL } }; -static chip::ArgParser::OptionSet sCmdLineOptions = -{ +static chip::ArgParser::OptionSet sCmdLineOptions = { FeatureMapOptionHandler, // handler function sFeatureMapOptionDefs, // array of option definitions "GENERAL OPTIONS", // help group @@ -52,13 +50,11 @@ static chip::ArgParser::OptionSet sCmdLineOptions = }; // Keep track of the parsed featureMap option -static chip::BitMask sFeatureMap(DeviceEnergyManagement::Feature::kPowerAdjustment, - DeviceEnergyManagement::Feature::kPowerForecastReporting, - DeviceEnergyManagement::Feature::kStateForecastReporting, - DeviceEnergyManagement::Feature::kStartTimeAdjustment, - DeviceEnergyManagement::Feature::kPausable, - DeviceEnergyManagement::Feature::kForecastAdjustment, - DeviceEnergyManagement::Feature::kConstraintBasedAdjustment); +static chip::BitMask + sFeatureMap(DeviceEnergyManagement::Feature::kPowerAdjustment, DeviceEnergyManagement::Feature::kPowerForecastReporting, + DeviceEnergyManagement::Feature::kStateForecastReporting, DeviceEnergyManagement::Feature::kStartTimeAdjustment, + DeviceEnergyManagement::Feature::kPausable, DeviceEnergyManagement::Feature::kForecastAdjustment, + DeviceEnergyManagement::Feature::kConstraintBasedAdjustment); void ApplicationInit() { @@ -77,7 +73,7 @@ chip::BitMask GetFeatureMap() return sFeatureMap; } -static uint32_t ParseNumber(const char *pString) +static uint32_t ParseNumber(const char * pString) { uint32_t num = 0; if (strlen(pString) > 2 && pString[0] == '0' && pString[1] == 'x') @@ -92,7 +88,8 @@ static uint32_t ParseNumber(const char *pString) return num; } -static bool FeatureMapOptionHandler(const char * aProgram, chip::ArgParser::OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue) +static bool FeatureMapOptionHandler(const char * aProgram, chip::ArgParser::OptionSet * aOptions, int aIdentifier, + const char * aName, const char * aValue) { bool retval = true; @@ -111,7 +108,6 @@ static bool FeatureMapOptionHandler(const char * aProgram, chip::ArgParser::Opti return (retval); } - int main(int argc, char * argv[]) { if (ChipLinuxAppInit(argc, argv, &sCmdLineOptions) != 0) 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 43fbbb03b159b7..72b3c672c2c8e8 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 @@ -160,25 +160,25 @@ class Delegate // ------------------------------------------------------------------ // Get attribute methods - virtual ESATypeEnum GetESAType() = 0; - virtual bool GetESACanGenerate() = 0; - virtual ESAStateEnum GetESAState() = 0; - virtual int64_t GetAbsMinPower() = 0; - virtual int64_t GetAbsMaxPower() = 0; + virtual ESATypeEnum GetESAType() = 0; + virtual bool GetESACanGenerate() = 0; + virtual ESAStateEnum GetESAState() = 0; + virtual int64_t GetAbsMinPower() = 0; + virtual int64_t GetAbsMaxPower() = 0; virtual DataModel::Nullable & GetPowerAdjustmentCapability() = 0; virtual DataModel::Nullable & GetForecast() = 0; - virtual OptOutStateEnum GetOptOutState() = 0; + virtual OptOutStateEnum GetOptOutState() = 0; // ------------------------------------------------------------------ // Set attribute methods - virtual CHIP_ERROR SetESAType(ESATypeEnum) = 0; - virtual CHIP_ERROR SetESACanGenerate(bool) = 0; - virtual CHIP_ERROR SetESAState(ESAStateEnum) = 0; - virtual CHIP_ERROR SetAbsMinPower(int64_t) = 0; - virtual CHIP_ERROR SetAbsMaxPower(int64_t) = 0; + virtual CHIP_ERROR SetESAType(ESATypeEnum) = 0; + virtual CHIP_ERROR SetESACanGenerate(bool) = 0; + virtual CHIP_ERROR SetESAState(ESAStateEnum) = 0; + virtual CHIP_ERROR SetAbsMinPower(int64_t) = 0; + virtual CHIP_ERROR SetAbsMaxPower(int64_t) = 0; virtual CHIP_ERROR SetPowerAdjustmentCapability(DataModel::Nullable &) = 0; virtual CHIP_ERROR SetForecast(DataModel::Nullable &) = 0; - virtual CHIP_ERROR SetOptOutState(OptOutStateEnum) = 0; + virtual CHIP_ERROR SetOptOutState(OptOutStateEnum) = 0; protected: EndpointId mEndpointId = 0; From eccee3129a38fd98bda15534e654d68bea0b0ebd Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sat, 15 Jun 2024 06:52:49 +0000 Subject: [PATCH 08/74] Restyled by gn --- examples/energy-management-app/linux/BUILD.gn | 18 ++++++------------ examples/shell/shell_common/BUILD.gn | 4 ++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/examples/energy-management-app/linux/BUILD.gn b/examples/energy-management-app/linux/BUILD.gn index 27eddb8f0c67ca..a70f94788b79ad 100644 --- a/examples/energy-management-app/linux/BUILD.gn +++ b/examples/energy-management-app/linux/BUILD.gn @@ -36,27 +36,21 @@ config("includes") { executable("chip-energy-management-app") { sources = [ - "${chip_root}/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseEventTriggers.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp", - + "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", - + "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseEventTriggers.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", - + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/PowerTopologyDelegate.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/device-energy-management-mode.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/energy-evse-mode.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", - - "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp", "include/CHIPProjectAppConfig.h", "main.cpp", ] diff --git a/examples/shell/shell_common/BUILD.gn b/examples/shell/shell_common/BUILD.gn index 44242a0f2918c7..572c519ce6544f 100644 --- a/examples/shell/shell_common/BUILD.gn +++ b/examples/shell/shell_common/BUILD.gn @@ -77,12 +77,12 @@ static_library("shell_common") { "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", - ] + ] include_dirs = [ "${chip_root}/examples/all-clusters-app/all-clusters-common/include", "${chip_root}/examples/energy-management-app/energy-management-common/include", - "${chip_root}/src/app/clusters/device-energy-management-server" + "${chip_root}/src/app/clusters/device-energy-management-server", ] public_deps += From d1761364e0918b040c059a2efa061a0b82241816 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sat, 15 Jun 2024 06:52:51 +0000 Subject: [PATCH 09/74] Restyled by prettier-markdown --- .../energy-management-app/linux/README.md | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/examples/energy-management-app/linux/README.md b/examples/energy-management-app/linux/README.md index 146efefd238182..ab35600709de47 100644 --- a/examples/energy-management-app/linux/README.md +++ b/examples/energy-management-app/linux/README.md @@ -163,10 +163,14 @@ There are several test scripts provided for EVSE (in - `TC_EEVSE_2_3`: This validates Get/Set/Clear target commands - `TC_EEVSE_2_4`: This validates Faults - `TC_EEVSE_2_5`: This validates EVSE diagnostic command (optional) -- `TC_EEVSE_2_6`: This validates EVSE Forecast Adjustment with State Forecast Reporting feature functionality -- `TC_EEVSE_2_7`: This validates EVSE Constraints-based Adjustment with Power Forecast Reporting feature functionality -- `TC_EEVSE_2_8`: This validates EVSE Constraints-based Adjustment with State Forecast Reporting feature functionality -- `TC_EEVSE_2_9`: This validates EVSE Power or State Forecast Reporting feature functionality +- `TC_EEVSE_2_6`: This validates EVSE Forecast Adjustment with State Forecast + Reporting feature functionality +- `TC_EEVSE_2_7`: This validates EVSE Constraints-based Adjustment with Power + Forecast Reporting feature functionality +- `TC_EEVSE_2_8`: This validates EVSE Constraints-based Adjustment with State + Forecast Reporting feature functionality +- `TC_EEVSE_2_9`: This validates EVSE Power or State Forecast Reporting + feature functionality These scripts require the use of Test Event Triggers via the GeneralDiagnostics cluster on Endpoint 0. This requires an `enableKey` (16 bytes) and a set of @@ -188,10 +192,13 @@ chosen enable key is using the `--enable-key` command line option. From the top-level of the connectedhomeip repo type: Start the chip-energy-management-app: + ```bash rm -f evse.bin; out/debug/chip-energy-management-app --enable-key 000102030405060708090a0b0c0d0e0f --KVS evse.bin --featureSet $featureSet ``` -where the $featureSet depends on the test being run: + +where the \$featureSet depends on the test being run: + ``` TC_DEM_2_2.py: 0x01 // PA TC_DEM_2_3.py: 0x3b // STA, PAU, FA, CON + (PFR | SFR) @@ -202,7 +209,9 @@ TC_DEM_2_7.py: 0x3b // STA, PAU, FA, CON + PFR TC_DEM_2_8.py: 0x3d // STA, PAU, FA, CON + SFR TC_DEM_2_9.py: 0x3f // STA, PAU, FA, CON + PFR + SFR ``` + where + ``` PA - DEM.S.F00(PowerAdjustment) PFR - DEM.S.F01(PowerForecastReporting) @@ -212,7 +221,9 @@ PAU - DEM.S.F04(Pausable) FA - DEM.S.F05(ForecastAdjustment) CON -DEM.S.F06(ConstraintBasedAdjustment) ``` + Then run the test: + ```bash $ python src/python_testing/TC_EEVSE_2_2.py --endpoint 1 -m on-network -n 1234 -p 20202021 -d 3840 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f ``` @@ -221,7 +232,11 @@ Then run the test: cluster is on endpoint 1. The `--hex-arg enableKey:` value must match the `--enable-key ` used on chip-energy-management-app args. -The chip-energy-management-app will need to be stopped before running each test script as each test commissions the chip-energy-management-app in the first step. That is also why the evse.bin is deleted before running chip-energy-management-app as this is where the app stores the matter persistent data (e.g. fabric info). +The chip-energy-management-app will need to be stopped before running each test +script as each test commissions the chip-energy-management-app in the first +step. That is also why the evse.bin is deleted before running +chip-energy-management-app as this is where the app stores the matter persistent +data (e.g. fabric info). ## CHIP-REPL Interaction From 86d7929fc713070bc018a99d68f31caa109f312f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sat, 15 Jun 2024 06:52:53 +0000 Subject: [PATCH 10/74] Restyled by autopep8 --- src/python_testing/TC_DEM_2_2.py | 39 +++++++++++++------- src/python_testing/TC_DEM_Utils.py | 7 +--- src/python_testing/matter_testing_support.py | 1 + 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/python_testing/TC_DEM_2_2.py b/src/python_testing/TC_DEM_2_2.py index 03e63c80c4e84f..e8767587a96e8e 100644 --- a/src/python_testing/TC_DEM_2_2.py +++ b/src/python_testing/TC_DEM_2_2.py @@ -54,7 +54,8 @@ def steps_TC_DEM_2_2(self) -> list[TestStep]: TestStep("3a", "TH reads ESAState attribute. Verify value is 0x01 (Online)"), TestStep("3b", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=NoAdjustment. Note value for later. Determine the OverallMaxPower and OverallMaxDuration as the largest MaxPower and MaxDuration of the PowerAdjustStructs returned, and similarly the OverallMinPower and OverallMinDuration as the smallest of the MinPower and MinDuration values."), TestStep("3c", "TH reads OptOutState attribute. Verify value is 0x00 (NoOptOut)"), - TestStep("4", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is Success and Event DEM.S.E00(PowerAdjustStart) sent"), + TestStep( + "4", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is Success and Event DEM.S.E00(PowerAdjustStart) sent"), TestStep("4a", "TH reads ESAState attribute. Verify value is 0x04 (PowerAdjustActive)"), TestStep("4b", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=LocalOptimizationAdjustment."), TestStep("5", "TH sends CancelPowerAdjustRequest. Verify Command response is Success and Event DEM.S.E01(PowerAdjustEnd) sent with Cause=Cancelled"), @@ -65,15 +66,18 @@ def steps_TC_DEM_2_2(self) -> list[TestStep]: TestStep("8", "TH sends PowerAdjustRequest with Power=OverallMinPower Duration=OverallMaxDuration+1 Cause=LocalOptimization. Verify Command response is ConstraintError"), TestStep("9", "TH sends PowerAdjustRequest with Power=OverallMinPower-1 Duration=OverallMaxDuration Cause=LocalOptimization. Verify Command response is ConstraintError"), TestStep("10", "TH sends PowerAdjustRequest with Power=OverallMaxPower Duration=OverallMinDuration-1 Cause=LocalOptimization. Verify Command response is ConstraintError"), - TestStep("11", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is Success and event DEM.S.E00(PowerAdjustStart) sent"), + TestStep( + "11", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is Success and event DEM.S.E00(PowerAdjustStart) sent"), TestStep("11a", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=LocalOptimizationAdjustment."), - TestStep("12", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=GridOptimization. Verify Command response is Success and no event sent"), + TestStep( + "12", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=GridOptimization. Verify Command response is Success and no event sent"), TestStep("12a", "TH reads ESAState attribute. Verify value is 0x04 (PowerAdjustActive)"), TestStep("12b", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=GridOptimizationAdjustment."), TestStep("13", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event. No event sent"), TestStep("13a", "TH reads ESAState attribute. Verify value is 0x04 (PowerAdjustActive)"), TestStep("13b", "TH reads OptOutState attribute. Verify value is 0x02 (LocalOptOut)"), - TestStep("14", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is ConstraintError"), + TestStep( + "14", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is ConstraintError"), TestStep("15", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event. Event DEM.S.E01(PowerAdjustEnd) sent with Cause=UserOptOut, Duration= approx time from step 11 to step 15, EnergyUse= a valid value"), TestStep("15a", "TH reads ESAState attribute. Verify value is 0x01 (Online)"), TestStep("15b", "TH reads OptOutState attribute. Verify value is 0x03 (OptOut)"), @@ -81,7 +85,8 @@ def steps_TC_DEM_2_2(self) -> list[TestStep]: TestStep("16", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear"), TestStep("16a", "TH reads ESAState attribute. Verify value is 0x01 (Online)"), TestStep("16b", "TH reads OptOutState attribute. Verify value is 0x00 (NoOptOut)"), - TestStep("17", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is Success and event DEM.S.E00(PowerAdjustStart) sent"), + TestStep( + "17", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is Success and event DEM.S.E00(PowerAdjustStart) sent"), TestStep("17a", "TH reads ESAState attribute. Verify value is 0x04 (PowerAdjustActive)"), TestStep("17b", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=LocalOptimizationAdjustment."), TestStep("18", "Wait 10 seconds. Event DEM.S.E01(PowerAdjustEnd) sent with Cause=NormalCompletion, Duration=10s, EnergyUse= a valid value"), @@ -126,7 +131,8 @@ async def test_TC_DEM_2_2(self): powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") asserts.assert_greater_equal(len(powerAdjustCapabilityStruct.powerAdjustCapability), 1) logging.info(powerAdjustCapabilityStruct) - asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) + asserts.assert_equal(powerAdjustCapabilityStruct.cause, + Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) # we should expect powerAdjustCapabilityStruct to have multiple entries with different max powers, min powers, max and min durations found_min_power = sys.maxsize @@ -164,7 +170,8 @@ async def test_TC_DEM_2_2(self): self.step("4b") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") asserts.assert_greater_equal(len(powerAdjustCapabilityStruct.powerAdjustCapability), 1) - asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kLocalOptimizationAdjustment) + asserts.assert_equal(powerAdjustCapabilityStruct.cause, + Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kLocalOptimizationAdjustment) self.step("5") await self.send_cancel_power_adjustment_command() @@ -174,7 +181,8 @@ async def test_TC_DEM_2_2(self): self.step("5a") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") asserts.assert_greater_equal(len(powerAdjustCapabilityStruct.powerAdjustCapability), 1) - asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) + asserts.assert_equal(powerAdjustCapabilityStruct.cause, + Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) self.step("5b") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) @@ -217,7 +225,8 @@ async def test_TC_DEM_2_2(self): self.step("11a") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") asserts.assert_greater_equal(len(powerAdjustCapabilityStruct.powerAdjustCapability), 1) - asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kLocalOptimizationAdjustment) + asserts.assert_equal(powerAdjustCapabilityStruct.cause, + Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kLocalOptimizationAdjustment) self.step("12") await self.send_power_adjustment_command(power=max_power, @@ -233,7 +242,8 @@ async def test_TC_DEM_2_2(self): self.step("12b") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") asserts.assert_greater_equal(len(powerAdjustCapabilityStruct.powerAdjustCapability), 1) - asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kGridOptimizationAdjustment) + asserts.assert_equal(powerAdjustCapabilityStruct.cause, + Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kGridOptimizationAdjustment) self.step("13") await self.send_test_event_trigger_user_opt_out_local() @@ -270,7 +280,8 @@ async def test_TC_DEM_2_2(self): self.step("15c") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") - asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) + asserts.assert_equal(powerAdjustCapabilityStruct.cause, + Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) self.step("16") await self.send_test_event_trigger_user_opt_out_clear_all() @@ -292,7 +303,8 @@ async def test_TC_DEM_2_2(self): self.step("17b") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") - asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kLocalOptimizationAdjustment) + asserts.assert_equal(powerAdjustCapabilityStruct.cause, + Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kLocalOptimizationAdjustment) self.step("18") time.sleep(10) @@ -302,7 +314,8 @@ async def test_TC_DEM_2_2(self): self.step("18b") powerAdjustCapabilityStruct = await self.read_dem_attribute_expect_success(attribute="PowerAdjustmentCapability") - asserts.assert_equal(powerAdjustCapabilityStruct.cause, Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) + asserts.assert_equal(powerAdjustCapabilityStruct.cause, + Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) self.step("19") await self.send_test_event_trigger_power_adjustment_clear() diff --git a/src/python_testing/TC_DEM_Utils.py b/src/python_testing/TC_DEM_Utils.py index a99f0c81a3d889..f58b8e5d509989 100644 --- a/src/python_testing/TC_DEM_Utils.py +++ b/src/python_testing/TC_DEM_Utils.py @@ -58,8 +58,8 @@ async def send_cancel_power_adjustment_command(self, endpoint: int = None, timed expected_status: Status = Status.Success): try: await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.CancelPowerAdjustRequest(), - endpoint=endpoint, - timedRequestTimeoutMs=timedRequestTimeoutMs) + endpoint=endpoint, + timedRequestTimeoutMs=timedRequestTimeoutMs) asserts.assert_equal(expected_status, Status.Success) @@ -218,6 +218,3 @@ async def send_test_event_trigger_forecast(self): async def send_test_event_trigger_forecast_clear(self): await self.send_test_event_triggers(eventTrigger=0x0098000000000010) - - - diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py index 9eb3a0e391d29e..8276163fe8cd03 100644 --- a/src/python_testing/matter_testing_support.py +++ b/src/python_testing/matter_testing_support.py @@ -275,6 +275,7 @@ def wait_for_event_expect_no_report(self, timeout: int = 10): asserts.fail(f"Event reported when not expected {res}") + class InternalTestRunnerHooks(TestRunnerHooks): def start(self, count: int): From e9c2f5f2f0eba3d8c9be9c9f7e56c886ebfdea11 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sat, 15 Jun 2024 06:52:54 +0000 Subject: [PATCH 11/74] Restyled by isort --- src/python_testing/TC_DEM_2_2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/TC_DEM_2_2.py b/src/python_testing/TC_DEM_2_2.py index e8767587a96e8e..dcb513e49c0922 100644 --- a/src/python_testing/TC_DEM_2_2.py +++ b/src/python_testing/TC_DEM_2_2.py @@ -17,9 +17,9 @@ """Define Matter test case TC_DEM_2_2.""" -import sys -import logging import datetime +import logging +import sys import time import chip.clusters as Clusters From a45e6ddca72c2dee238c6a4d470740b774f2c4cc Mon Sep 17 00:00:00 2001 From: pcoleman Date: Sat, 15 Jun 2024 18:54:25 +0100 Subject: [PATCH 12/74] Fix compilation problem by including lib/core/DataModelTypes.h --- .../energy-management-common/include/DEMManufacturerDelegate.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h index e74ecbae98ad67..c22a792f3abd45 100644 --- a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h +++ b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h @@ -18,6 +18,8 @@ #pragma once +#include + using chip::Protocols::InteractionModel::Status; namespace chip { From fe103a92bda093ef11a8df363986b2255130acc5 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Sat, 15 Jun 2024 20:00:39 +0100 Subject: [PATCH 13/74] Fix compilation problem by including --- .../energy-management-common/include/DEMManufacturerDelegate.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h index c22a792f3abd45..ed6cdcd6f253e7 100644 --- a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h +++ b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h @@ -19,6 +19,8 @@ #pragma once #include +#include +#include using chip::Protocols::InteractionModel::Status; From a6f0b6dce6ca7f751e8c3f06ef922d0f074170d3 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Sat, 15 Jun 2024 20:57:20 +0100 Subject: [PATCH 14/74] Save examples/all-clusters-app/all-clusters-common/all-clusters-app.zap to update it --- .../all-clusters-common/all-clusters-app.zap | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap index 8660f24af8b504..f0afbd78296bd2 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap @@ -1,6 +1,6 @@ { "fileFormat": 2, - "featureLevel": 102, + "featureLevel": 103, "creator": "zap", "keyValuePairs": [ { @@ -29,6 +29,7 @@ "pathRelativity": "relativeToZap", "path": "../../../src/app/zap-templates/app-templates.json", "type": "gen-templates-json", + "category": "matter", "version": "chip-v1" } ], @@ -8226,7 +8227,6 @@ "define": "OPERATIONAL_STATE_OVEN_CLUSTER", "side": "server", "enabled": 1, - "apiMaturity": "provisional", "commands": [ { "name": "Pause", @@ -8487,7 +8487,6 @@ "define": "OVEN_MODE_CLUSTER", "side": "server", "enabled": 1, - "apiMaturity": "provisional", "commands": [ { "name": "ChangeToMode", @@ -8644,7 +8643,6 @@ "define": "LAUNDRY_DRYER_CONTROLS_CLUSTER", "side": "server", "enabled": 1, - "apiMaturity": "provisional", "attributes": [ { "name": "SupportedDrynessLevels", @@ -10898,7 +10896,6 @@ "define": "MICROWAVE_OVEN_MODE_CLUSTER", "side": "server", "enabled": 1, - "apiMaturity": "provisional", "attributes": [ { "name": "SupportedModes", @@ -12202,7 +12199,6 @@ "define": "BOOLEAN_STATE_CONFIGURATION_CLUSTER", "side": "server", "enabled": 1, - "apiMaturity": "provisional", "commands": [ { "name": "SuppressAlarm", @@ -12471,7 +12467,6 @@ "define": "VALVE_CONFIGURATION_AND_CONTROL_CLUSTER", "side": "server", "enabled": 1, - "apiMaturity": "provisional", "commands": [ { "name": "Open", @@ -12788,7 +12783,6 @@ "define": "ELECTRICAL_POWER_MEASUREMENT_CLUSTER", "side": "server", "enabled": 1, - "apiMaturity": "provisional", "attributes": [ { "name": "PowerMode", @@ -13208,7 +13202,6 @@ "define": "ELECTRICAL_ENERGY_MEASUREMENT_CLUSTER", "side": "server", "enabled": 1, - "apiMaturity": "provisional", "attributes": [ { "name": "Accuracy", @@ -13580,7 +13573,7 @@ "code": 5, "mfgCode": null, "side": "server", - "type": "array", + "type": "PowerAdjustCapabilityStruct", "included": 1, "storageOption": "External", "singleton": 0, @@ -13758,7 +13751,6 @@ "define": "ENERGY_EVSE_CLUSTER", "side": "server", "enabled": 1, - "apiMaturity": "provisional", "commands": [ { "name": "GetTargetsResponse", @@ -14434,7 +14426,6 @@ "define": "POWER_TOPOLOGY_CLUSTER", "side": "server", "enabled": 1, - "apiMaturity": "provisional", "attributes": [ { "name": "AvailableEndpoints", @@ -14573,7 +14564,6 @@ "define": "ENERGY_EVSE_MODE_CLUSTER", "side": "server", "enabled": 1, - "apiMaturity": "provisional", "commands": [ { "name": "ChangeToMode", From 9cef02365d97314a74f03f22b94339b59e162d14 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sat, 15 Jun 2024 19:01:19 +0000 Subject: [PATCH 15/74] Restyled by clang-format --- .../energy-management-common/include/DEMManufacturerDelegate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h index ed6cdcd6f253e7..a504f55abde4bc 100644 --- a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h +++ b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h @@ -18,9 +18,9 @@ #pragma once +#include #include #include -#include using chip::Protocols::InteractionModel::Status; From 2cbe9c6ada8b4eb5d011c5fd2107a74b0ddb4a85 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Wed, 19 Jun 2024 18:42:58 +0100 Subject: [PATCH 16/74] Apply further code review changes --- .../all-clusters-app/ameba/chip_main.cmake | 2 +- examples/all-clusters-app/asr/BUILD.gn | 2 +- .../all-clusters-app/cc13x4_26x4/BUILD.gn | 2 +- .../all-clusters-app/infineon/psoc6/BUILD.gn | 2 +- examples/all-clusters-app/linux/BUILD.gn | 2 +- examples/all-clusters-app/mbed/CMakeLists.txt | 2 +- .../nrfconnect/CMakeLists.txt | 2 +- examples/all-clusters-app/nxp/mw320/BUILD.gn | 2 +- .../openiotsdk/CMakeLists.txt | 2 +- .../all-clusters-app/telink/CMakeLists.txt | 2 +- examples/all-clusters-app/tizen/BUILD.gn | 2 +- .../include/DEMManufacturerDelegate.h | 5 +-- .../DeviceEnergyManagementDelegateImpl.h | 34 +++++++++++++++++++ .../include/EVSEManufacturerImpl.h | 5 +-- .../include/{DEMUtils.h => EnergyTimeUtils.h} | 0 .../src/DEMTestEventTriggers.cpp | 2 +- .../DeviceEnergyManagementDelegateImpl.cpp | 6 ++-- .../src/EVSEManufacturerImpl.cpp | 7 ++-- .../src/{DEMUtils.cpp => EnergyTimeUtils.cpp} | 4 +-- .../src/FakeReadings.cpp | 2 +- examples/energy-management-app/linux/BUILD.gn | 2 +- examples/shell/shell_common/BUILD.gn | 2 +- 22 files changed, 64 insertions(+), 27 deletions(-) rename examples/energy-management-app/energy-management-common/include/{DEMUtils.h => EnergyTimeUtils.h} (100%) rename examples/energy-management-app/energy-management-common/src/{DEMUtils.cpp => EnergyTimeUtils.cpp} (96%) diff --git a/examples/all-clusters-app/ameba/chip_main.cmake b/examples/all-clusters-app/ameba/chip_main.cmake index 36e0f4829917d7..6b63a8abcf15d0 100644 --- a/examples/all-clusters-app/ameba/chip_main.cmake +++ b/examples/all-clusters-app/ameba/chip_main.cmake @@ -187,7 +187,7 @@ list( ${chip_dir}/examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-device.cpp - ${chip_dir}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp + ${chip_dir}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp ${chip_dir}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp diff --git a/examples/all-clusters-app/asr/BUILD.gn b/examples/all-clusters-app/asr/BUILD.gn index 94bbbf0e0f83b5..17b377e58e0061 100644 --- a/examples/all-clusters-app/asr/BUILD.gn +++ b/examples/all-clusters-app/asr/BUILD.gn @@ -82,7 +82,7 @@ asr_executable("clusters_app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", diff --git a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn index 45735da251279f..6debd3fe41ae30 100644 --- a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn +++ b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn @@ -72,7 +72,7 @@ ti_simplelink_executable("all-clusters-app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", diff --git a/examples/all-clusters-app/infineon/psoc6/BUILD.gn b/examples/all-clusters-app/infineon/psoc6/BUILD.gn index 151e12926e8b81..0d970c81c7d90c 100644 --- a/examples/all-clusters-app/infineon/psoc6/BUILD.gn +++ b/examples/all-clusters-app/infineon/psoc6/BUILD.gn @@ -118,7 +118,7 @@ psoc6_executable("clusters_app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index b7b9e2073a6c0f..132f67b40e6a88 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -58,7 +58,7 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp", "${chip_root}/examples/all-clusters-app/linux/diagnostic-logs-provider-delegate-impl.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", diff --git a/examples/all-clusters-app/mbed/CMakeLists.txt b/examples/all-clusters-app/mbed/CMakeLists.txt index c0da3c948091cf..9b490ff687d1e3 100644 --- a/examples/all-clusters-app/mbed/CMakeLists.txt +++ b/examples/all-clusters-app/mbed/CMakeLists.txt @@ -72,7 +72,7 @@ target_sources(${APP_TARGET} PRIVATE ${ALL_CLUSTERS_COMMON}/src/smco-stub.cpp ${ALL_CLUSTERS_COMMON}/src/static-supported-modes-manager.cpp ${ALL_CLUSTERS_COMMON}/src/static-supported-temperature-levels.cpp - ${ENERGY_MANAGEMENT_COMMON}/src/DEMUtils.cpp + ${ENERGY_MANAGEMENT_COMMON}/src/EnergyTimeUtils.cpp ${ENERGY_MANAGEMENT_COMMON}/src/DeviceEnergyManagementDelegateImpl.cpp ${ENERGY_MANAGEMENT_COMMON}/src/DeviceEnergyManagementManager.cpp ${ENERGY_MANAGEMENT_COMMON}/src/EVSEManufacturerImpl.cpp diff --git a/examples/all-clusters-app/nrfconnect/CMakeLists.txt b/examples/all-clusters-app/nrfconnect/CMakeLists.txt index d2a0a48e31f523..a21bcdde4b19eb 100644 --- a/examples/all-clusters-app/nrfconnect/CMakeLists.txt +++ b/examples/all-clusters-app/nrfconnect/CMakeLists.txt @@ -70,7 +70,7 @@ target_sources(app PRIVATE ${ALL_CLUSTERS_COMMON_DIR}/src/air-quality-instance.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/concentration-measurement-instances.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/resource-monitoring-delegates.cpp - ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DEMUtils.cpp + ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EnergyTimeUtils.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DeviceEnergyManagementDelegateImpl.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DeviceEnergyManagementManager.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EVSEManufacturerImpl.cpp diff --git a/examples/all-clusters-app/nxp/mw320/BUILD.gn b/examples/all-clusters-app/nxp/mw320/BUILD.gn index 26725fc2b1da41..2fb7f7a6f65055 100644 --- a/examples/all-clusters-app/nxp/mw320/BUILD.gn +++ b/examples/all-clusters-app/nxp/mw320/BUILD.gn @@ -86,7 +86,7 @@ mw320_executable("shell_mw320") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", diff --git a/examples/all-clusters-app/openiotsdk/CMakeLists.txt b/examples/all-clusters-app/openiotsdk/CMakeLists.txt index 4787bf9f79904b..1395cf170a8b79 100644 --- a/examples/all-clusters-app/openiotsdk/CMakeLists.txt +++ b/examples/all-clusters-app/openiotsdk/CMakeLists.txt @@ -65,7 +65,7 @@ target_sources(${APP_TARGET} ${ALL_CLUSTERS_COMMON}/src/resource-monitoring-delegates.cpp ${ALL_CLUSTERS_COMMON}/src/static-supported-modes-manager.cpp ${ALL_CLUSTERS_COMMON}/src/binding-handler.cpp - ${ENERGY_MANAGEMENT_COMMON}/src/DEMUtils.cpp + ${ENERGY_MANAGEMENT_COMMON}/src/EnergyTimeUtils.cpp ${ENERGY_MANAGEMENT_COMMON}/src/DeviceEnergyManagementDelegateImpl.cpp ${ENERGY_MANAGEMENT_COMMON}/src/DeviceEnergyManagementManager.cpp ${ENERGY_MANAGEMENT_COMMON}/src/EVSEManufacturerImpl.cpp diff --git a/examples/all-clusters-app/telink/CMakeLists.txt b/examples/all-clusters-app/telink/CMakeLists.txt index 223a8e1f29b06f..149b38e3528cce 100644 --- a/examples/all-clusters-app/telink/CMakeLists.txt +++ b/examples/all-clusters-app/telink/CMakeLists.txt @@ -51,7 +51,7 @@ target_sources(app PRIVATE ${ALL_CLUSTERS_COMMON_DIR}/src/device-energy-management-stub.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/energy-evse-stub.cpp ${ALL_CLUSTERS_COMMON_DIR}/src/resource-monitoring-delegates.cpp - ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DEMUtils.cpp + ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EnergyTimeUtils.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DeviceEnergyManagementDelegateImpl.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DeviceEnergyManagementManager.cpp ${ENERGY_MANAGEMENT_COMMON_DIR}/src/EVSEManufacturerImpl.cpp diff --git a/examples/all-clusters-app/tizen/BUILD.gn b/examples/all-clusters-app/tizen/BUILD.gn index 451f9a91b0448a..f5db501f9319f4 100644 --- a/examples/all-clusters-app/tizen/BUILD.gn +++ b/examples/all-clusters-app/tizen/BUILD.gn @@ -38,7 +38,7 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", diff --git a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h index a504f55abde4bc..98f83f1ac41196 100644 --- a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h +++ b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h @@ -41,7 +41,8 @@ class DEMManufacturerDelegate virtual ~DEMManufacturerDelegate() {} - virtual int64_t GetEnergyUse() = 0; + // The PowerAdjustEnd event needs to report the approximate energy used by the ESA during the session. + virtual int64_t GetApproxEnergyDuringSession() = 0; virtual CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t power, const uint32_t duration, AdjustmentCauseEnum cause) @@ -71,7 +72,7 @@ class DEMManufacturerDelegate virtual CHIP_ERROR HandleDeviceEnergyManagementCancelRequest() { return CHIP_NO_ERROR; } virtual CHIP_ERROR - HandleModifyRequest(const uint32_t forecastID, + HandleModifyForecastRequest(const uint32_t forecastID, const DataModel::DecodableList & slotAdjustments, AdjustmentCauseEnum cause) { 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 4871dbaf342c86..e28637f5629bec 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -118,6 +118,8 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate * If the ESA accepts the requested Forecast then it SHALL update its Forecast attribute (incrementing its ForecastID) * and run the revised Forecast as its new intended operation. * + * *** NOTE *** for the memory management of the forecast object, see the comment before the mForecast delaration below. + * * @param forecastID Indicates the ESA ForecastID that is to be modified. * @param slotAdjustments List of adjustments to be applied to the ESA, corresponding to the expected ESA forecastID. * @return Success if the entire list of SlotAdjustmentStruct are accepted, otherwise the command @@ -240,6 +242,38 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate DataModel::Nullable mPowerAdjustCapabilityStruct; + // The DeviceEnergyManagementDelegate owns the master copy of the ForecastStruct object which is accessed via GetForecast and SetForecast. + // The slots field of forecast is owned and managed by the object that implements the DEMManufacturerDelegate interface. + // + // The rationale for this is as follows: + // It is envisioned there will be one master forecast object declared in DeviceEnergyManagementDelegate. When + // constructed, the field DataModel::List slots will be empty. + // + // The EVSEManufacturerImpl class (examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h) is + // an example implementation that a specific vendor can use as a template. It understands how the underlying energy appliance + // functions. EVSEManufacturerImpl inherits from DEMManufacturerDelegate + // (examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h) which is a generic interface + // and how the DeviceEnergyManagementDelegate class + // (examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp) communicates from the + // generic cluster world to the specific appliance implementation (EVSEManufacturerImpl). + // + // EVSEManufacturerImpl understands the slot structures of the appliance and configures the slot structures as follows: + // + // Call DeviceEnergyManagementDelegate::GetForecast() to get the current forecast + // Modify the slot structure - the slots memory is owned by EVSEManufacturerImpl + // Call DeviceEnergyManagementDelegate::GetForecast() to set the current forecast + // + // + // The cluster object DeviceEnergyManagement::Instance + // (src/app/clusters/device-energy-management-server/device-energy-management-server.cpp) only reads the slots field of + // forecast when checking commands (indeed it does not modify any forecast fields itself). The DeviceEnergyManagementDelegate + // object does modify some of forecast's fields but does NOT modify the slots field. The only command that can modify the + // slots field is HandleModifyForecastRequest. Whilst DeviceEnergyManagementDelegate::ModifyForecastRequest does some state + // checking, the slots field is only modified by the EVSEManufacturerImpl object via the call + // DEMManufacturerDelegate::HandleModifyForecastRequest. DEMManufacturerDelegate::HandleModifyForecastRequest may + // delete/allocate the slots memory but this will be done atomically in the call to + // DEMManufacturerDelegate::HandleModifyForecastRequest so the underlying memory is coherent => the call to + // DEMManufacturerDelegate::HandleModifyForecastRequest cannot be interrupted by any other CHIP task activity. DataModel::Nullable mForecast; // Keep track whether a PowerAdjustment is in progress diff --git a/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h b/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h index 24e5728a326f08..2b37debdd2756c 100644 --- a/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h +++ b/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h @@ -94,7 +94,8 @@ class EVSEManufacturer : public DEMManufacturerDelegate * Implement the DEMManufacturerDelegate interface * */ - int64_t GetEnergyUse() override; + // The PowerAdjustEnd event needs to report the approximate energy used by the ESA during the session. + int64_t GetApproxEnergyDuringSession() override; CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t power, const uint32_t duration, AdjustmentCauseEnum cause) override; CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustCompletion() override; @@ -105,7 +106,7 @@ class EVSEManufacturer : public DEMManufacturerDelegate CHIP_ERROR HandleDeviceEnergyManagementPauseCompletion() override; CHIP_ERROR HandleDeviceEnergyManagementCancelPauseRequest(CauseEnum cause) override; CHIP_ERROR HandleDeviceEnergyManagementCancelRequest() override; - CHIP_ERROR HandleModifyRequest( + CHIP_ERROR HandleModifyForecastRequest( const uint32_t forecastID, const DataModel::DecodableList & slotAdjustments, AdjustmentCauseEnum cause) override; diff --git a/examples/energy-management-app/energy-management-common/include/DEMUtils.h b/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h similarity index 100% rename from examples/energy-management-app/energy-management-common/include/DEMUtils.h rename to examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h diff --git a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp index eea6e0073c1481..9f02d2fb3dbdd2 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include "FakeReadings.h" 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 aab56f4111e3a7..04ed3618c9158e 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -18,7 +18,7 @@ #include "DeviceEnergyManagementDelegateImpl.h" #include "DEMManufacturerDelegate.h" -#include "DEMUtils.h" +#include "EnergyTimeUtils.h" #include using namespace chip; @@ -298,7 +298,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SendPowerAdjustEndEvent(CauseEnum cau if (mpDEMManufacturerDelegate != nullptr) { - event.energyUse = mpDEMManufacturerDelegate->GetEnergyUse(); + event.energyUse = mpDEMManufacturerDelegate->GetApproxEnergyDuringSession(); } else { @@ -642,7 +642,7 @@ Status DeviceEnergyManagementDelegate::ModifyForecastRequest( else if (mpDEMManufacturerDelegate != nullptr) { // Determine if the new forecast adjustments are acceptable to the appliance - CHIP_ERROR err = mpDEMManufacturerDelegate->HandleModifyRequest(forecastID, slotAdjustments, cause); + CHIP_ERROR err = mpDEMManufacturerDelegate->HandleModifyForecastRequest(forecastID, slotAdjustments, cause); if (err != CHIP_NO_ERROR) { status = Status::Failure; diff --git a/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp b/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp index 8a042d9d84a205..97d995c589c6c2 100644 --- a/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include @@ -371,7 +371,8 @@ void EVSEManufacturer::ApplicationCallbackHandler(const EVSECbInfo * cb, intptr_ } } -int64_t EVSEManufacturer::GetEnergyUse() +// The PowerAdjustEnd event needs to report the approximate energy used by the ESA during the session. +int64_t EVSEManufacturer::GetApproxEnergyDuringSession() { return 300; } @@ -418,7 +419,7 @@ CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementCancelRequest() return CHIP_NO_ERROR; } -CHIP_ERROR EVSEManufacturer::HandleModifyRequest( +CHIP_ERROR EVSEManufacturer::HandleModifyForecastRequest( const uint32_t forecastID, const DataModel::DecodableList & slotAdjustments, AdjustmentCauseEnum cause) diff --git a/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp b/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp similarity index 96% rename from examples/energy-management-app/energy-management-common/src/DEMUtils.cpp rename to examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp index 4b9308fcf6accf..27037900aad459 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp @@ -16,7 +16,7 @@ * limitations under the License. */ -#include +#include #include #include #include @@ -52,7 +52,7 @@ CHIP_ERROR UtilsGetEpochTS(uint32_t & chipEpoch) if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "EVSE: Unable to get current time - err:%" CHIP_ERROR_FORMAT, err.Format()); + ChipLogError(Zcl, "Unable to get current time - err:%" CHIP_ERROR_FORMAT, err.Format()); return err; } diff --git a/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp b/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp index 61937b91d282c9..ed18aa087d83b4 100644 --- a/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp +++ b/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include diff --git a/examples/energy-management-app/linux/BUILD.gn b/examples/energy-management-app/linux/BUILD.gn index a70f94788b79ad..f92dde7022da9a 100644 --- a/examples/energy-management-app/linux/BUILD.gn +++ b/examples/energy-management-app/linux/BUILD.gn @@ -37,7 +37,7 @@ config("includes") { executable("chip-energy-management-app") { sources = [ "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", diff --git a/examples/shell/shell_common/BUILD.gn b/examples/shell/shell_common/BUILD.gn index 572c519ce6544f..4295ed370d2e66 100644 --- a/examples/shell/shell_common/BUILD.gn +++ b/examples/shell/shell_common/BUILD.gn @@ -70,7 +70,7 @@ static_library("shell_common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMUtils.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", From 46e8f0c38fe5ca1fecd37f525733b4380068e9c9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 19 Jun 2024 17:43:45 +0000 Subject: [PATCH 17/74] Restyled by clang-format --- .../include/DEMManufacturerDelegate.h | 4 ++-- .../include/DeviceEnergyManagementDelegateImpl.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h index 98f83f1ac41196..2e1e060f1bc987 100644 --- a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h +++ b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h @@ -73,8 +73,8 @@ class DEMManufacturerDelegate virtual CHIP_ERROR HandleModifyForecastRequest(const uint32_t forecastID, - const DataModel::DecodableList & slotAdjustments, - AdjustmentCauseEnum cause) + const DataModel::DecodableList & slotAdjustments, + AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; } 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 e28637f5629bec..916e596e036b97 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -242,8 +242,9 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate DataModel::Nullable mPowerAdjustCapabilityStruct; - // The DeviceEnergyManagementDelegate owns the master copy of the ForecastStruct object which is accessed via GetForecast and SetForecast. - // The slots field of forecast is owned and managed by the object that implements the DEMManufacturerDelegate interface. + // The DeviceEnergyManagementDelegate owns the master copy of the ForecastStruct object which is accessed via GetForecast and + // SetForecast. The slots field of forecast is owned and managed by the object that implements the DEMManufacturerDelegate + // interface. // // The rationale for this is as follows: // It is envisioned there will be one master forecast object declared in DeviceEnergyManagementDelegate. When From 78e695113768c6bd905e3c356a2e61148521cdcf Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 19 Jun 2024 17:43:45 +0000 Subject: [PATCH 18/74] Restyled by gn --- examples/all-clusters-app/asr/BUILD.gn | 2 +- examples/all-clusters-app/cc13x4_26x4/BUILD.gn | 2 +- examples/all-clusters-app/infineon/psoc6/BUILD.gn | 2 +- examples/all-clusters-app/linux/BUILD.gn | 2 +- examples/all-clusters-app/nxp/mw320/BUILD.gn | 2 +- examples/all-clusters-app/tizen/BUILD.gn | 2 +- examples/energy-management-app/linux/BUILD.gn | 2 +- examples/shell/shell_common/BUILD.gn | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/all-clusters-app/asr/BUILD.gn b/examples/all-clusters-app/asr/BUILD.gn index 17b377e58e0061..6ef5791c13be07 100644 --- a/examples/all-clusters-app/asr/BUILD.gn +++ b/examples/all-clusters-app/asr/BUILD.gn @@ -82,13 +82,13 @@ asr_executable("clusters_app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${examples_plat_dir}/ButtonHandler.cpp", "${examples_plat_dir}/CHIPDeviceManager.cpp", "${examples_plat_dir}/LEDWidget.cpp", diff --git a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn index 6debd3fe41ae30..6f3c009a8d6ad8 100644 --- a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn +++ b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn @@ -72,13 +72,13 @@ ti_simplelink_executable("all-clusters-app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/providers/DeviceInfoProviderImpl.cpp", "${project_dir}/main/AppTask.cpp", "${project_dir}/main/ClusterManager.cpp", diff --git a/examples/all-clusters-app/infineon/psoc6/BUILD.gn b/examples/all-clusters-app/infineon/psoc6/BUILD.gn index 0d970c81c7d90c..7127907790f6bd 100644 --- a/examples/all-clusters-app/infineon/psoc6/BUILD.gn +++ b/examples/all-clusters-app/infineon/psoc6/BUILD.gn @@ -118,13 +118,13 @@ psoc6_executable("clusters_app") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${examples_plat_dir}/LEDWidget.cpp", "${examples_plat_dir}/init_psoc6Platform.cpp", "src/AppTask.cpp", diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index 132f67b40e6a88..dc9366bce37cc8 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -58,13 +58,13 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp", "${chip_root}/examples/all-clusters-app/linux/diagnostic-logs-provider-delegate-impl.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/device-energy-management-mode.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/energy-evse-mode.cpp", "AllClustersCommandDelegate.cpp", diff --git a/examples/all-clusters-app/nxp/mw320/BUILD.gn b/examples/all-clusters-app/nxp/mw320/BUILD.gn index 2fb7f7a6f65055..bf9c3dd6b79718 100644 --- a/examples/all-clusters-app/nxp/mw320/BUILD.gn +++ b/examples/all-clusters-app/nxp/mw320/BUILD.gn @@ -86,13 +86,13 @@ mw320_executable("shell_mw320") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/src/lib/shell/streamer_mw320.cpp", "binding-handler.cpp", "include/CHIPProjectConfig.h", diff --git a/examples/all-clusters-app/tizen/BUILD.gn b/examples/all-clusters-app/tizen/BUILD.gn index f5db501f9319f4..9aff82b57b2876 100644 --- a/examples/all-clusters-app/tizen/BUILD.gn +++ b/examples/all-clusters-app/tizen/BUILD.gn @@ -38,13 +38,13 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", ] deps = [ diff --git a/examples/energy-management-app/linux/BUILD.gn b/examples/energy-management-app/linux/BUILD.gn index f92dde7022da9a..9d6b2e1f8dfd8e 100644 --- a/examples/energy-management-app/linux/BUILD.gn +++ b/examples/energy-management-app/linux/BUILD.gn @@ -37,7 +37,6 @@ config("includes") { executable("chip-energy-management-app") { sources = [ "${chip_root}/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", @@ -47,6 +46,7 @@ executable("chip-energy-management-app") { "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/PowerTopologyDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/device-energy-management-mode.cpp", diff --git a/examples/shell/shell_common/BUILD.gn b/examples/shell/shell_common/BUILD.gn index 4295ed370d2e66..0e318ccb31a5ca 100644 --- a/examples/shell/shell_common/BUILD.gn +++ b/examples/shell/shell_common/BUILD.gn @@ -70,13 +70,13 @@ static_library("shell_common") { "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp", - "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/ElectricalPowerMeasurementDelegate.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp", "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp", + "${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp", ] include_dirs = [ From 73a6430f173ab35ae95bb0b8650323b52742287e Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 20 Jun 2024 10:19:41 +0100 Subject: [PATCH 19/74] Address code review comments from AndreiL --- .../energy-management-common/BUILD.gn | 2 +- .../include/DEMManufacturerDelegate.h | 6 +- .../DeviceEnergyManagementDelegateImpl.h | 17 ++--- .../include/DeviceEnergyManagementManager.h | 2 +- .../include/EVSECallbacks.h | 2 +- .../include/EVSEManufacturerImpl.h | 6 +- .../include/EnergyEvseDelegateImpl.h | 2 +- .../include/EnergyEvseManager.h | 2 +- .../EnergyManagementAppCmdLineOptions.h | 13 +++- .../include/FakeReadings.h | 5 +- .../src/DEMTestEventTriggers.cpp | 7 +- .../DeviceEnergyManagementDelegateImpl.cpp | 68 ++++++++----------- .../src/DeviceEnergyManagementManager.cpp | 2 +- .../src/EVSEManufacturerImpl.cpp | 8 +-- .../src/EnergyEvseDelegateImpl.cpp | 2 +- .../src/EnergyEvseEventTriggers.cpp | 2 +- .../src/EnergyEvseMain.cpp | 4 +- .../src/EnergyEvseManager.cpp | 2 +- .../src/EnergyReportingEventTriggers.cpp | 2 +- .../src/FakeReadings.cpp | 2 +- .../esp32/main/include/CHIPProjectConfig.h | 2 +- .../esp32/sdkconfig.optimize.defaults | 2 +- examples/energy-management-app/linux/BUILD.gn | 2 +- examples/energy-management-app/linux/args.gni | 2 +- examples/energy-management-app/linux/main.cpp | 48 +++++++------ src/python_testing/matter_testing_support.py | 8 +-- 26 files changed, 113 insertions(+), 107 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/BUILD.gn b/examples/energy-management-app/energy-management-common/BUILD.gn index 937aca9f1746d0..a1dc2c320f9d79 100644 --- a/examples/energy-management-app/energy-management-common/BUILD.gn +++ b/examples/energy-management-app/energy-management-common/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Project CHIP Authors +# 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. diff --git a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h index 2e1e060f1bc987..68c30dc2cd6686 100644 --- a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h +++ b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h @@ -44,7 +44,7 @@ class DEMManufacturerDelegate // The PowerAdjustEnd event needs to report the approximate energy used by the ESA during the session. virtual int64_t GetApproxEnergyDuringSession() = 0; - virtual CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t power, const uint32_t duration, + virtual CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t powerMw, const uint32_t durationS, AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; @@ -54,13 +54,13 @@ class DEMManufacturerDelegate virtual CHIP_ERROR HandleDeviceEnergyManagementCancelPowerAdjustRequest(CauseEnum cause) { return CHIP_NO_ERROR; } - virtual CHIP_ERROR HandleDeviceEnergyManagementStartTimeAdjustRequest(const uint32_t requestedStartTime, + virtual CHIP_ERROR HandleDeviceEnergyManagementStartTimeAdjustRequest(const uint32_t requestedStartTimeUtc, AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; } - virtual CHIP_ERROR HandleDeviceEnergyManagementPauseRequest(const uint32_t duration, AdjustmentCauseEnum cause) + virtual CHIP_ERROR HandleDeviceEnergyManagementPauseRequest(const uint32_t durationS, AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; } 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 916e596e036b97..33eb3e1d57efd5 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -55,7 +55,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::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, AdjustmentCauseEnum cause) override; + virtual Status PowerAdjustRequest(const int64_t powerMw, const uint32_t durationS, AdjustmentCauseEnum cause) override; /** * @brief Make the ESA end the active power adjustment session & return to normal (or idle) power levels. @@ -81,7 +81,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::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, AdjustmentCauseEnum cause) override; + virtual Status StartTimeAdjustRequest(const uint32_t requestedStartTimeUtc, AdjustmentCauseEnum cause) override; /** * @brief Handler for PauseRequest command @@ -96,7 +96,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::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, AdjustmentCauseEnum cause) override; + virtual Status PauseRequest(const uint32_t durationS, AdjustmentCauseEnum cause) override; /** * @brief Handler for ResumeRequest command @@ -236,8 +236,8 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate ESATypeEnum mEsaType; bool mEsaCanGenerate; ESAStateEnum mEsaState; - int64_t mAbsMinPower; - int64_t mAbsMaxPower; + int64_t mAbsMinPowerMw; + int64_t mAbsMaxPowerMw; OptOutStateEnum mOptOutState; DataModel::Nullable mPowerAdjustCapabilityStruct; @@ -281,13 +281,10 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate bool mPowerAdjustmentInProgress; // Keep track of when that PowerAdjustment started - uint32_t mPowerAdjustmentStartTime; + uint32_t mPowerAdjustmentStartTimeUtc; // Keep track whether a PauseRequest is in progress bool mPauseRequestInProgress; - - // Keep track of when that PauseRequest started - uint32_t mPauseRequestStartTime; }; } // namespace DeviceEnergyManagement diff --git a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h index 79e061421c5cf4..cbb44f99bf845a 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/energy-management-common/include/EVSECallbacks.h b/examples/energy-management-app/energy-management-common/include/EVSECallbacks.h index 7d288809952ee3..d5681d7b60321f 100644 --- a/examples/energy-management-app/energy-management-common/include/EVSECallbacks.h +++ b/examples/energy-management-app/energy-management-common/include/EVSECallbacks.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h b/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h index 2b37debdd2756c..8e8253e293c869 100644 --- a/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h +++ b/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -96,13 +96,13 @@ class EVSEManufacturer : public DEMManufacturerDelegate */ // The PowerAdjustEnd event needs to report the approximate energy used by the ESA during the session. int64_t GetApproxEnergyDuringSession() override; - CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t power, const uint32_t duration, + CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t powerMw, const uint32_t durationS, AdjustmentCauseEnum cause) override; CHIP_ERROR HandleDeviceEnergyManagementPowerAdjustCompletion() override; CHIP_ERROR HandleDeviceEnergyManagementCancelPowerAdjustRequest(CauseEnum cause) override; CHIP_ERROR HandleDeviceEnergyManagementStartTimeAdjustRequest(const uint32_t requestedStartTime, AdjustmentCauseEnum cause) override; - CHIP_ERROR HandleDeviceEnergyManagementPauseRequest(const uint32_t duration, AdjustmentCauseEnum cause) override; + CHIP_ERROR HandleDeviceEnergyManagementPauseRequest(const uint32_t durationS, AdjustmentCauseEnum cause) override; CHIP_ERROR HandleDeviceEnergyManagementPauseCompletion() override; CHIP_ERROR HandleDeviceEnergyManagementCancelPauseRequest(CauseEnum cause) override; CHIP_ERROR HandleDeviceEnergyManagementCancelRequest() override; diff --git a/examples/energy-management-app/energy-management-common/include/EnergyEvseDelegateImpl.h b/examples/energy-management-app/energy-management-common/include/EnergyEvseDelegateImpl.h index df0d08b76f7e4e..6a58136ff39eb6 100644 --- a/examples/energy-management-app/energy-management-common/include/EnergyEvseDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/EnergyEvseDelegateImpl.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/energy-management-common/include/EnergyEvseManager.h b/examples/energy-management-app/energy-management-common/include/EnergyEvseManager.h index fc0d41b9259643..fc3562d3865ad7 100644 --- a/examples/energy-management-app/energy-management-common/include/EnergyEvseManager.h +++ b/examples/energy-management-app/energy-management-common/include/EnergyEvseManager.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h b/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h index 9bcb3dfedbf9da..291ffeb979415b 100644 --- a/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h +++ b/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h @@ -21,4 +21,15 @@ #include #include -chip::BitMask GetFeatureMap(); +namespace chip { +namespace app { +namespace Clusters { +namespace DeviceEnergyManagement { + +chip::BitMask GetFeatureMapFromCmdLine(); + +} // namespace DeviceEnergyManagement +} // namespace Clusters +} // namespace app +} // namespace chip + diff --git a/examples/energy-management-app/energy-management-common/include/FakeReadings.h b/examples/energy-management-app/energy-management-common/include/FakeReadings.h index 7667a4b5779712..cee09c8dc4d3d8 100644 --- a/examples/energy-management-app/energy-management-common/include/FakeReadings.h +++ b/examples/energy-management-app/energy-management-common/include/FakeReadings.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,12 +18,9 @@ #pragma once -#include #include #include -#define MAX_SLOTS 10 - class FakeReadings { public: diff --git a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp index 9f02d2fb3dbdd2..bf7ce83f9988dc 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,12 +29,13 @@ using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::DeviceEnergyManagement; -#define MAX_SLOTS 10 +static constexpr uint16_t MAX_SLOTS = 10; +static constexpr uint16_t MAX_POWER_ADJUSTMENTS = 5; + static chip::app::Clusters::DeviceEnergyManagement::Structs::SlotStruct::Type sSlots[MAX_SLOTS]; static chip::app::Clusters::DeviceEnergyManagement::Structs::ForecastStruct::Type sForecastStruct; static chip::app::DataModel::Nullable sForecast; -#define MAX_POWER_ADJUSTMENTS 5 static chip::app::Clusters::DeviceEnergyManagement::Structs::PowerAdjustStruct::Type sPowerAdjustments[MAX_POWER_ADJUSTMENTS]; static chip::app::Clusters::DeviceEnergyManagement::Structs::PowerAdjustCapabilityStruct::Type sPowerAdjustCapabilityStruct; static chip::app::DataModel::Nullable 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 04ed3618c9158e..91e8f9b75a8129 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,8 +32,8 @@ using CostsList = DataModel::List; DeviceEnergyManagementDelegate::DeviceEnergyManagementDelegate() : mpDEMManufacturerDelegate(nullptr), mEsaType(ESATypeEnum::kEvse), mEsaCanGenerate(false), mEsaState(ESAStateEnum::kOffline), - mAbsMinPower(0), mAbsMaxPower(0), mOptOutState(OptOutStateEnum::kNoOptOut), mPowerAdjustmentInProgress(false), - mPowerAdjustmentStartTime(0), mPauseRequestInProgress(false), mPauseRequestStartTime(0) + mAbsMinPowerMw(0), mAbsMaxPowerMw(0), mOptOutState(OptOutStateEnum::kNoOptOut), mPowerAdjustmentInProgress(false), + mPowerAdjustmentStartTimeUtc(0), mPauseRequestInProgress(false) {} void DeviceEnergyManagementDelegate::SetDeviceEnergyManagementInstance(DeviceEnergyManagement::Instance & instance) @@ -76,7 +76,7 @@ void DeviceEnergyManagementDelegate::SetDEMManufacturerDelegate( * 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, AdjustmentCauseEnum cause) +Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t powerMw, const uint32_t durationS, AdjustmentCauseEnum cause) { bool sendEvent = false; @@ -91,7 +91,7 @@ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t power, c sendEvent = true; // Record when this PowerAdjustment starts. Note if we do not set this value if a PowerAdjustment is in progress - CHIP_ERROR err = UtilsGetEpochTS(mPowerAdjustmentStartTime); + CHIP_ERROR err = UtilsGetEpochTS(mPowerAdjustmentStartTimeUtc); if (err != CHIP_NO_ERROR) { ChipLogError(AppServer, "Unable to get time: %" CHIP_ERROR_FORMAT, err.Format()); @@ -102,7 +102,7 @@ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t power, c // Update the forecast with the new expected end time if (mpDEMManufacturerDelegate != nullptr) { - CHIP_ERROR err = mpDEMManufacturerDelegate->HandleDeviceEnergyManagementPowerAdjustRequest(power, duration, cause); + CHIP_ERROR err = mpDEMManufacturerDelegate->HandleDeviceEnergyManagementPowerAdjustRequest(powerMw, durationS, cause); if (err != CHIP_NO_ERROR) { return Status::Failure; @@ -130,7 +130,7 @@ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t power, c // in before this timer expires mPowerAdjustmentInProgress = true; - CHIP_ERROR err = DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(duration), PowerAdjustTimerExpiry, this); + CHIP_ERROR err = DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(durationS), PowerAdjustTimerExpiry, this); if (err != CHIP_NO_ERROR) { // TODO: Note: should the PowerAdjust just initiated be cancelled because an Event could not be logged? @@ -284,11 +284,11 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SendPowerAdjustEndEvent(CauseEnum cau EventNumber eventNumber; event.cause = cause; - uint32_t timeNow; - CHIP_ERROR err = UtilsGetEpochTS(timeNow); + uint32_t timeNowUtc; + CHIP_ERROR err = UtilsGetEpochTS(timeNowUtc); if (err == CHIP_NO_ERROR) { - event.duration = timeNow - mPowerAdjustmentStartTime; + event.duration = timeNowUtc - mPowerAdjustmentStartTimeUtc; } else { @@ -326,7 +326,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SendPowerAdjustEndEvent(CauseEnum cau * 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, AdjustmentCauseEnum cause) +Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t requestedStartTimeUtc, AdjustmentCauseEnum cause) { if (mForecast.IsNull()) { @@ -349,7 +349,7 @@ Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t req mForecast.Value().forecastID++; - uint32_t duration = mForecast.Value().endTime - mForecast.Value().startTime; // the current entire forecast duration + uint32_t durationS = mForecast.Value().endTime - mForecast.Value().startTime; // the current entire forecast duration // Save the start and end time in case there is an issue with the mpDEMManufacturerDelegate handling this // startTimeAdjustment request @@ -357,12 +357,12 @@ Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t req uint32_t savedEndTime = mForecast.Value().endTime; /* Modify start time and end time */ - mForecast.Value().startTime = requestedStartTime; - mForecast.Value().endTime = requestedStartTime + duration; + mForecast.Value().startTime = requestedStartTimeUtc; + mForecast.Value().endTime = requestedStartTimeUtc + durationS; if (mpDEMManufacturerDelegate != nullptr) { - CHIP_ERROR err = mpDEMManufacturerDelegate->HandleDeviceEnergyManagementStartTimeAdjustRequest(requestedStartTime, cause); + CHIP_ERROR err = mpDEMManufacturerDelegate->HandleDeviceEnergyManagementStartTimeAdjustRequest(requestedStartTimeUtc, cause); if (err != CHIP_NO_ERROR) { // Reset state @@ -394,18 +394,10 @@ 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, AdjustmentCauseEnum cause) +Status DeviceEnergyManagementDelegate::PauseRequest(const uint32_t durationS, AdjustmentCauseEnum cause) { bool sendEvent = false; - // Record when this PauseRequest starts - CHIP_ERROR err = UtilsGetEpochTS(mPauseRequestStartTime); - if (err != CHIP_NO_ERROR) - { - ChipLogError(AppServer, "Unable to get time: %" CHIP_ERROR_FORMAT, err.Format()); - return Status::Failure; - } - // If a timer is running, cancel it so we can start it with the new duration if (mPauseRequestInProgress) { @@ -420,7 +412,7 @@ Status DeviceEnergyManagementDelegate::PauseRequest(const uint32_t duration, Adj mPauseRequestInProgress = true; } - err = DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(duration), PauseRequestTimerExpiry, this); + CHIP_ERROR err = DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(durationS), PauseRequestTimerExpiry, this); if (err != CHIP_NO_ERROR) { HandlePauseRequestFailure(); @@ -431,7 +423,7 @@ Status DeviceEnergyManagementDelegate::PauseRequest(const uint32_t duration, Adj if (mpDEMManufacturerDelegate != nullptr) { // It is expected that the mpDEMManufacturerDelegate will update the forecast with the new expected end time - err = mpDEMManufacturerDelegate->HandleDeviceEnergyManagementPauseRequest(duration, cause); + err = mpDEMManufacturerDelegate->HandleDeviceEnergyManagementPauseRequest(durationS, cause); if (err != CHIP_NO_ERROR) { HandlePauseRequestFailure(); @@ -776,12 +768,12 @@ ESAStateEnum DeviceEnergyManagementDelegate::GetESAState() int64_t DeviceEnergyManagementDelegate::GetAbsMinPower() { - return mAbsMinPower; + return mAbsMinPowerMw; } int64_t DeviceEnergyManagementDelegate::GetAbsMaxPower() { - return mAbsMaxPower; + return mAbsMaxPowerMw; } DataModel::Nullable & DeviceEnergyManagementDelegate::GetPowerAdjustmentCapability() @@ -857,28 +849,28 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetESAState(ESAStateEnum newValue) return CHIP_NO_ERROR; } -CHIP_ERROR DeviceEnergyManagementDelegate::SetAbsMinPower(int64_t newValue) +CHIP_ERROR DeviceEnergyManagementDelegate::SetAbsMinPower(int64_t newValueMw) { - int64_t oldValue = mAbsMinPower; + int64_t oldValueMw = mAbsMinPowerMw; - mAbsMinPower = newValue; - if (oldValue != newValue) + mAbsMinPowerMw = newValueMw; + if (oldValueMw != newValueMw) { - ChipLogDetail(AppServer, "mAbsMinPower updated to %d", static_cast(mAbsMinPower)); + ChipLogDetail(AppServer, "mAbsMinPower updated to %d", static_cast(mAbsMinPowerMw)); MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, AbsMinPower::Id); } return CHIP_NO_ERROR; } -CHIP_ERROR DeviceEnergyManagementDelegate::SetAbsMaxPower(int64_t newValue) +CHIP_ERROR DeviceEnergyManagementDelegate::SetAbsMaxPower(int64_t newValueMw) { - int64_t oldValue = mAbsMaxPower; + int64_t oldValueMw = mAbsMaxPowerMw; - mAbsMaxPower = newValue; - if (oldValue != newValue) + mAbsMaxPowerMw = newValueMw; + if (oldValueMw != newValueMw) { - ChipLogDetail(AppServer, "mAbsMaxPower updated to %d", static_cast(mAbsMaxPower)); + ChipLogDetail(AppServer, "mAbsMaxPower updated to %d", static_cast(mAbsMaxPowerMw)); MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, AbsMaxPower::Id); } diff --git a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp index 5ed0445a8e0606..49c1086fdeae8e 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp b/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp index 97d995c589c6c2..2dc42860115726 100644 --- a/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -377,7 +377,7 @@ int64_t EVSEManufacturer::GetApproxEnergyDuringSession() return 300; } -CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t power, const uint32_t duration, +CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementPowerAdjustRequest(const int64_t powerMw, const uint32_t durationS, AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; @@ -393,13 +393,13 @@ CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementCancelPowerAdjustReques return CHIP_NO_ERROR; } -CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementStartTimeAdjustRequest(const uint32_t requestedStartTime, +CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementStartTimeAdjustRequest(const uint32_t requestedStartTimeUtc, AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; } -CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementPauseRequest(const uint32_t duration, AdjustmentCauseEnum cause) +CHIP_ERROR EVSEManufacturer::HandleDeviceEnergyManagementPauseRequest(const uint32_t durationS, AdjustmentCauseEnum cause) { return CHIP_NO_ERROR; } diff --git a/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp b/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp index 99619fc95b5fb0..3d46b67863cf6a 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/energy-management-common/src/EnergyEvseEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/EnergyEvseEventTriggers.cpp index 25452c8a91c423..62329068610f47 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyEvseEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyEvseEventTriggers.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp b/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp index 2459b9ddbcffe8..0a4bc0456e2254 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyEvseMain.cpp @@ -61,8 +61,6 @@ static std::unique_ptr gEEMAttrAccess; static std::unique_ptr gPTDelegate; static std::unique_ptr gPTInstance; -extern chip::BitMask GetFeatureMap(); - EVSEManufacturer * EnergyEvse::GetEvseManufacturer() { return gEvseManufacturer.get(); @@ -90,7 +88,7 @@ CHIP_ERROR DeviceEnergyManagementInit() return CHIP_ERROR_NO_MEMORY; } - BitMask featureMap = GetFeatureMap(); + BitMask featureMap = GetFeatureMapFromCmdLine(); /* Manufacturer may optionally not support all features, commands & attributes */ gDEMInstance = std::make_unique(EndpointId(ENERGY_EVSE_ENDPOINT), *gDEMDelegate, featureMap); diff --git a/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp b/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp index f4b3941e8c1ca7..493a0720d5860b 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp index 62e9c876ad24de..e01612a5f408d3 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyReportingEventTriggers.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp b/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp index ed18aa087d83b4..151e82be8436e9 100644 --- a/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp +++ b/examples/energy-management-app/energy-management-common/src/FakeReadings.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/esp32/main/include/CHIPProjectConfig.h b/examples/energy-management-app/esp32/main/include/CHIPProjectConfig.h index 559895608a08d0..a68e0cfcd5cdb4 100644 --- a/examples/energy-management-app/esp32/main/include/CHIPProjectConfig.h +++ b/examples/energy-management-app/esp32/main/include/CHIPProjectConfig.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/esp32/sdkconfig.optimize.defaults b/examples/energy-management-app/esp32/sdkconfig.optimize.defaults index 87248eebfcdfa7..cd2995a7c62ae2 100644 --- a/examples/energy-management-app/esp32/sdkconfig.optimize.defaults +++ b/examples/energy-management-app/esp32/sdkconfig.optimize.defaults @@ -1,5 +1,5 @@ # -# Copyright (c) 2023 Project CHIP Authors +# Copyright (c) 2024 Project CHIP Authors # All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/linux/BUILD.gn b/examples/energy-management-app/linux/BUILD.gn index 9d6b2e1f8dfd8e..0c5aa1c3adaced 100644 --- a/examples/energy-management-app/linux/BUILD.gn +++ b/examples/energy-management-app/linux/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Project CHIP Authors +# 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. diff --git a/examples/energy-management-app/linux/args.gni b/examples/energy-management-app/linux/args.gni index 21db8cfc9277e6..14e8335505cb8e 100644 --- a/examples/energy-management-app/linux/args.gni +++ b/examples/energy-management-app/linux/args.gni @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Project CHIP Authors +# 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. diff --git a/examples/energy-management-app/linux/main.cpp b/examples/energy-management-app/linux/main.cpp index 84ef54b2fc9674..9951c5243592c0 100644 --- a/examples/energy-management-app/linux/main.cpp +++ b/examples/energy-management-app/linux/main.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -49,30 +49,28 @@ static chip::ArgParser::OptionSet sCmdLineOptions = { "-f, --featureSet " // option help text }; -// Keep track of the parsed featureMap option -static chip::BitMask - sFeatureMap(DeviceEnergyManagement::Feature::kPowerAdjustment, DeviceEnergyManagement::Feature::kPowerForecastReporting, - DeviceEnergyManagement::Feature::kStateForecastReporting, DeviceEnergyManagement::Feature::kStartTimeAdjustment, - DeviceEnergyManagement::Feature::kPausable, DeviceEnergyManagement::Feature::kForecastAdjustment, - DeviceEnergyManagement::Feature::kConstraintBasedAdjustment); - -void ApplicationInit() -{ - ChipLogDetail(AppServer, "Energy Management App: ApplicationInit()"); - EvseApplicationInit(); -} +namespace chip { +namespace app { +namespace Clusters { +namespace DeviceEnergyManagement { -void ApplicationShutdown() -{ - ChipLogDetail(AppServer, "Energy Management App: ApplicationShutdown()"); - EvseApplicationShutdown(); -} +// Keep track of the parsed featureMap option +static chip::BitMask + sFeatureMap(Feature::kPowerAdjustment, Feature::kPowerForecastReporting, + Feature::kStateForecastReporting, Feature::kStartTimeAdjustment, + Feature::kPausable, Feature::kForecastAdjustment, + Feature::kConstraintBasedAdjustment); -chip::BitMask GetFeatureMap() +chip::BitMask GetFeatureMapFromCmdLine() { return sFeatureMap; } +} // namespace DeviceEnergyManagement +} // namespace Clusters +} // namespace app +} // namespace chip + static uint32_t ParseNumber(const char * pString) { uint32_t num = 0; @@ -88,6 +86,18 @@ static uint32_t ParseNumber(const char * pString) return num; } +void ApplicationInit() +{ + ChipLogDetail(AppServer, "Energy Management App: ApplicationInit()"); + EvseApplicationInit(); +} + +void ApplicationShutdown() +{ + ChipLogDetail(AppServer, "Energy Management App: ApplicationShutdown()"); + EvseApplicationShutdown(); +} + static bool FeatureMapOptionHandler(const char * aProgram, chip::ArgParser::OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue) { diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py index 00de078532b17d..29f887280957b4 100644 --- a/src/python_testing/matter_testing_support.py +++ b/src/python_testing/matter_testing_support.py @@ -253,11 +253,11 @@ def __call__(self, res: EventReadResult, transaction: SubscriptionTransaction): f'Got subscription report for event on cluster {self._expected_cluster}: {res.Data}') self._q.put(res) - def wait_for_event_report(self, expected_event: ClusterObjects.ClusterEvent, timeout: int = 10): - """This function allows a test script to block waiting for the specific event to arrive with a timeout. - It returns the event data so that the values can be checked.""" + def wait_for_event_report(self, expected_event: ClusterObjects.ClusterEvent, timeoutS: int = 10): + """This function allows a test script to block waiting for the specific event to arrive with a timeout + (specified in seconds). It returns the event data so that the values can be checked.""" try: - res = self._q.get(block=True, timeout=timeout) + res = self._q.get(block=True, timeout=timeoutS) except queue.Empty: asserts.fail("Failed to receive a report for the event {}".format(expected_event)) From cfc815eae8d2113e08af3ea10fa43afcde8c7c17 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 20 Jun 2024 09:20:19 +0000 Subject: [PATCH 20/74] Restyled by whitespace --- .../include/EnergyManagementAppCmdLineOptions.h | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h b/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h index 291ffeb979415b..a44140b94c762b 100644 --- a/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h +++ b/examples/energy-management-app/energy-management-common/include/EnergyManagementAppCmdLineOptions.h @@ -32,4 +32,3 @@ chip::BitMask GetFeatureMapFromCmdLine(); } // namespace Clusters } // namespace app } // namespace chip - From b2c1616cd811949b63c2f7ab4d5e441a252f5f5f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 20 Jun 2024 09:20:21 +0000 Subject: [PATCH 21/74] Restyled by clang-format --- .../energy-management-common/src/DEMTestEventTriggers.cpp | 2 +- .../src/DeviceEnergyManagementDelegateImpl.cpp | 6 ++++-- examples/energy-management-app/linux/main.cpp | 8 +++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp index bf7ce83f9988dc..fc3053289653a3 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp @@ -29,7 +29,7 @@ using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::DeviceEnergyManagement; -static constexpr uint16_t MAX_SLOTS = 10; +static constexpr uint16_t MAX_SLOTS = 10; static constexpr uint16_t MAX_POWER_ADJUSTMENTS = 5; static chip::app::Clusters::DeviceEnergyManagement::Structs::SlotStruct::Type sSlots[MAX_SLOTS]; 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 91e8f9b75a8129..69d6b888f21740 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -76,7 +76,8 @@ void DeviceEnergyManagementDelegate::SetDEMManufacturerDelegate( * 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 powerMw, const uint32_t durationS, AdjustmentCauseEnum cause) +Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t powerMw, const uint32_t durationS, + AdjustmentCauseEnum cause) { bool sendEvent = false; @@ -362,7 +363,8 @@ Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t req if (mpDEMManufacturerDelegate != nullptr) { - CHIP_ERROR err = mpDEMManufacturerDelegate->HandleDeviceEnergyManagementStartTimeAdjustRequest(requestedStartTimeUtc, cause); + CHIP_ERROR err = + mpDEMManufacturerDelegate->HandleDeviceEnergyManagementStartTimeAdjustRequest(requestedStartTimeUtc, cause); if (err != CHIP_NO_ERROR) { // Reset state diff --git a/examples/energy-management-app/linux/main.cpp b/examples/energy-management-app/linux/main.cpp index 9951c5243592c0..add57c0b02746a 100644 --- a/examples/energy-management-app/linux/main.cpp +++ b/examples/energy-management-app/linux/main.cpp @@ -55,11 +55,9 @@ namespace Clusters { namespace DeviceEnergyManagement { // Keep track of the parsed featureMap option -static chip::BitMask - sFeatureMap(Feature::kPowerAdjustment, Feature::kPowerForecastReporting, - Feature::kStateForecastReporting, Feature::kStartTimeAdjustment, - Feature::kPausable, Feature::kForecastAdjustment, - Feature::kConstraintBasedAdjustment); +static chip::BitMask sFeatureMap(Feature::kPowerAdjustment, Feature::kPowerForecastReporting, + Feature::kStateForecastReporting, Feature::kStartTimeAdjustment, Feature::kPausable, + Feature::kForecastAdjustment, Feature::kConstraintBasedAdjustment); chip::BitMask GetFeatureMapFromCmdLine() { From 61cca47912ed0a0eaa94d41a2c8095890dac6059 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 20 Jun 2024 11:28:22 +0100 Subject: [PATCH 22/74] Fix ESP build --- .../energy-management-app/esp32/main/main.cpp | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/examples/energy-management-app/esp32/main/main.cpp b/examples/energy-management-app/esp32/main/main.cpp index c52f781454cc75..eba6de0cd1a5c9 100644 --- a/examples/energy-management-app/esp32/main/main.cpp +++ b/examples/energy-management-app/esp32/main/main.cpp @@ -98,12 +98,27 @@ DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; DeviceLayer::ESP32SecureCertDACProvider gSecureCertDACProvider; #endif // CONFIG_SEC_CERT_DAC_PROVIDER +namespace chip { +namespace app { +namespace Clusters { +namespace DeviceEnergyManagement { + // Keep track of the parsed featureMap option -static chip::BitMask - sFeatureMap(DeviceEnergyManagement::Feature::kPowerAdjustment, DeviceEnergyManagement::Feature::kPowerForecastReporting, - DeviceEnergyManagement::Feature::kStateForecastReporting, DeviceEnergyManagement::Feature::kStartTimeAdjustment, - DeviceEnergyManagement::Feature::kPausable, DeviceEnergyManagement::Feature::kForecastAdjustment, - DeviceEnergyManagement::Feature::kConstraintBasedAdjustment); +static chip::BitMask + sFeatureMap(Feature::kPowerAdjustment, Feature::kPowerForecastReporting, + Feature::kStateForecastReporting, Feature::kStartTimeAdjustment, + Feature::kPausable, Feature::kForecastAdjustment, + Feature::kConstraintBasedAdjustment); + +chip::BitMask GetFeatureMapFromCmdLine() +{ + return sFeatureMap; +} + +} // namespace DeviceEnergyManagement +} // namespace Clusters +} // namespace app +} // namespace chip chip::Credentials::DeviceAttestationCredentialsProvider * get_dac_provider(void) { @@ -130,11 +145,6 @@ void ApplicationShutdown() EvseApplicationShutdown(); } -chip::BitMask GetFeatureMap() -{ - return sFeatureMap; -} - static void InitServer(intptr_t context) { // Print QR Code URL From 55d778e9d18e3cc7b7f3462133bb47479e844289 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 20 Jun 2024 22:56:14 +0100 Subject: [PATCH 23/74] Fix ESP build --- .../energy-management-app/esp32/main/main.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/energy-management-app/esp32/main/main.cpp b/examples/energy-management-app/esp32/main/main.cpp index eba6de0cd1a5c9..5d7fbb5bc494cc 100644 --- a/examples/energy-management-app/esp32/main/main.cpp +++ b/examples/energy-management-app/esp32/main/main.cpp @@ -98,6 +98,19 @@ DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; DeviceLayer::ESP32SecureCertDACProvider gSecureCertDACProvider; #endif // CONFIG_SEC_CERT_DAC_PROVIDER +chip::Credentials::DeviceAttestationCredentialsProvider * get_dac_provider(void) +{ +#if CONFIG_SEC_CERT_DAC_PROVIDER + return &gSecureCertDACProvider; +#elif CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER + return &sFactoryDataProvider; +#else // EXAMPLE_DAC_PROVIDER + return chip::Credentials::Examples::GetExampleDACProvider(); +#endif +} + +} // namespace + namespace chip { namespace app { namespace Clusters { @@ -120,19 +133,6 @@ chip::BitMask GetFeatureMapFromCmdLine() } // namespace app } // namespace chip -chip::Credentials::DeviceAttestationCredentialsProvider * get_dac_provider(void) -{ -#if CONFIG_SEC_CERT_DAC_PROVIDER - return &gSecureCertDACProvider; -#elif CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER - return &sFactoryDataProvider; -#else // EXAMPLE_DAC_PROVIDER - return chip::Credentials::Examples::GetExampleDACProvider(); -#endif -} - -} // namespace - void ApplicationInit() { ESP_LOGD(TAG, "Energy Management App: ApplicationInit()"); From 6c65ac41473265edb68f904bb38a26acd68ad2f2 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 20 Jun 2024 21:56:54 +0000 Subject: [PATCH 24/74] Restyled by clang-format --- examples/energy-management-app/esp32/main/main.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/energy-management-app/esp32/main/main.cpp b/examples/energy-management-app/esp32/main/main.cpp index 5d7fbb5bc494cc..136817a7744095 100644 --- a/examples/energy-management-app/esp32/main/main.cpp +++ b/examples/energy-management-app/esp32/main/main.cpp @@ -117,11 +117,9 @@ namespace Clusters { namespace DeviceEnergyManagement { // Keep track of the parsed featureMap option -static chip::BitMask - sFeatureMap(Feature::kPowerAdjustment, Feature::kPowerForecastReporting, - Feature::kStateForecastReporting, Feature::kStartTimeAdjustment, - Feature::kPausable, Feature::kForecastAdjustment, - Feature::kConstraintBasedAdjustment); +static chip::BitMask sFeatureMap(Feature::kPowerAdjustment, Feature::kPowerForecastReporting, + Feature::kStateForecastReporting, Feature::kStartTimeAdjustment, Feature::kPausable, + Feature::kForecastAdjustment, Feature::kConstraintBasedAdjustment); chip::BitMask GetFeatureMapFromCmdLine() { From c55ca01b55f400d1b7d1547f14e2ebf1ebc4e650 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Tue, 25 Jun 2024 07:33:47 +0100 Subject: [PATCH 25/74] Rename src/python_testing/TC_DEM_Utils.py src/python_testing/DEMTestBase.py --- src/python_testing/{TC_DEM_Utils.py => DEMTestBase.py} | 2 +- src/python_testing/TC_DEM_2_2.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/python_testing/{TC_DEM_Utils.py => DEMTestBase.py} (99%) diff --git a/src/python_testing/TC_DEM_Utils.py b/src/python_testing/DEMTestBase.py similarity index 99% rename from src/python_testing/TC_DEM_Utils.py rename to src/python_testing/DEMTestBase.py index f58b8e5d509989..59477d94e9befd 100644 --- a/src/python_testing/TC_DEM_Utils.py +++ b/src/python_testing/DEMTestBase.py @@ -24,7 +24,7 @@ logger = logging.getLogger(__name__) -class DEMBaseTestHelper: +class DEMTestBase: async def read_dem_attribute_expect_success(self, endpoint: int = None, attribute: str = ""): cluster = Clusters.Objects.DeviceEnergyManagement diff --git a/src/python_testing/TC_DEM_2_2.py b/src/python_testing/TC_DEM_2_2.py index dcb513e49c0922..0daa97fa2b93fa 100644 --- a/src/python_testing/TC_DEM_2_2.py +++ b/src/python_testing/TC_DEM_2_2.py @@ -26,12 +26,12 @@ from chip.interaction_model import Status from matter_testing_support import EventChangeCallback, MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts -from TC_DEM_Utils import DEMBaseTestHelper +from DEMTestBase import DEMTestBase logger = logging.getLogger(__name__) -class TC_DEM_2_2(MatterBaseTest, DEMBaseTestHelper): +class TC_DEM_2_2(MatterBaseTest, DEMTestBase): """Implementation of test case TC_DEM_2_2.""" def desc_TC_DEM_2_2(self) -> str: From d469ba0c8e050322967f6f8a878ab58eed375564 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Tue, 25 Jun 2024 08:07:08 +0100 Subject: [PATCH 26/74] Put time util funtions into namespace + drop the Utils prefix --- .../include/EnergyEvseDelegateImpl.h | 7 ------- .../include/EnergyTimeUtils.h | 17 ++++++++++++++--- .../src/DEMTestEventTriggers.cpp | 4 ++-- .../src/DeviceEnergyManagementDelegateImpl.cpp | 4 ++-- .../src/EnergyTimeUtils.cpp | 18 ++++++++++++++---- src/python_testing/matter_testing_support.py | 6 +++--- 6 files changed, 35 insertions(+), 21 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/include/EnergyEvseDelegateImpl.h b/examples/energy-management-app/energy-management-common/include/EnergyEvseDelegateImpl.h index 6a58136ff39eb6..39cbc8d385e08f 100644 --- a/examples/energy-management-app/energy-management-common/include/EnergyEvseDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/EnergyEvseDelegateImpl.h @@ -26,13 +26,6 @@ using chip::Protocols::InteractionModel::Status; -/** - * @brief Helper function to get current timestamp in Epoch format - * - * @param chipEpoch reference to hold return timestamp - */ -CHIP_ERROR GetEpochTS(uint32_t & chipEpoch); - namespace chip { namespace app { namespace Clusters { diff --git a/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h b/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h index d4a0785808e6a5..f16ddd6d53ddab 100644 --- a/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h +++ b/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h @@ -25,12 +25,17 @@ using chip::Protocols::InteractionModel::Status; +namespace chip { +namespace app { +namespace Clusters { +namespace DeviceEnergyManagement { + /** * @brief Helper function to get current timestamp in Epoch format * * @param chipEpoch reference to hold return timestamp */ -CHIP_ERROR UtilsGetEpochTS(uint32_t & chipEpoch); +CHIP_ERROR GetEpochTS(uint32_t & chipEpoch); /** * @brief Helper function to get current timestamp and work out the day of week @@ -44,7 +49,7 @@ CHIP_ERROR UtilsGetEpochTS(uint32_t & chipEpoch); * @return bitmap value for day of week * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) */ -uint8_t UtilsGetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch); +uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch); /** * @brief Helper function to get current timestamp and work out the day of week based on localtime @@ -53,4 +58,10 @@ uint8_t UtilsGetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch); * * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) */ -CHIP_ERROR UtilsGetLocalDayOfWeekNow(uint8_t & dayOfWeekMap); +CHIP_ERROR GetLocalDayOfWeekNow(uint8_t & dayOfWeekMap); + +} // namespace DeviceEnergyManagement +} // namespace Clusters +} // namespace app +} // namespace chip + diff --git a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp index fc3053289653a3..6571b07d1ee9a3 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp @@ -55,7 +55,7 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots) { uint32_t chipEpoch = 0; - CHIP_ERROR err = UtilsGetEpochTS(chipEpoch); + CHIP_ERROR err = GetEpochTS(chipEpoch); if (err != CHIP_NO_ERROR) { ChipLogError(Support, "ConfigureForecast could not get time"); @@ -198,7 +198,7 @@ void SetTestEventTrigger_StartTimeAdjustment() uint32_t chipEpoch = 0; - CHIP_ERROR err = UtilsGetEpochTS(chipEpoch); + CHIP_ERROR err = GetEpochTS(chipEpoch); if (err != CHIP_NO_ERROR) { ChipLogError(Support, "ConfigureForecast_EarliestStartLatestEndTimes could not get time"); 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 69d6b888f21740..c4fe74e8c13179 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -92,7 +92,7 @@ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t powerMw, sendEvent = true; // Record when this PowerAdjustment starts. Note if we do not set this value if a PowerAdjustment is in progress - CHIP_ERROR err = UtilsGetEpochTS(mPowerAdjustmentStartTimeUtc); + CHIP_ERROR err = GetEpochTS(mPowerAdjustmentStartTimeUtc); if (err != CHIP_NO_ERROR) { ChipLogError(AppServer, "Unable to get time: %" CHIP_ERROR_FORMAT, err.Format()); @@ -286,7 +286,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SendPowerAdjustEndEvent(CauseEnum cau event.cause = cause; uint32_t timeNowUtc; - CHIP_ERROR err = UtilsGetEpochTS(timeNowUtc); + CHIP_ERROR err = GetEpochTS(timeNowUtc); if (err == CHIP_NO_ERROR) { event.duration = timeNowUtc - mPowerAdjustmentStartTimeUtc; diff --git a/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp b/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp index 27037900aad459..476764f3f72a7a 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp @@ -31,12 +31,17 @@ using namespace chip::app::Clusters::EnergyEvse::Attributes; using chip::app::LogEvent; using chip::Protocols::InteractionModel::Status; +namespace chip { +namespace app { +namespace Clusters { +namespace DeviceEnergyManagement { + /** * @brief Helper function to get current timestamp in Epoch format * * @param[out] chipEpoch reference to hold return timestamp. Set to 0 if an error occurs. */ -CHIP_ERROR UtilsGetEpochTS(uint32_t & chipEpoch) +CHIP_ERROR GetEpochTS(uint32_t & chipEpoch) { chipEpoch = 0; @@ -78,7 +83,7 @@ CHIP_ERROR UtilsGetEpochTS(uint32_t & chipEpoch) * @return bitmap value for day of week * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) */ -uint8_t UtilsGetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch) +uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch) { // Define a timezone structure and initialize it to the local timezone // This will capture any daylight saving time changes @@ -100,7 +105,7 @@ uint8_t UtilsGetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch) * * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) */ -CHIP_ERROR UtilsGetLocalDayOfWeekNow(uint8_t & dayOfWeekMap) +CHIP_ERROR GetLocalDayOfWeekNow(uint8_t & dayOfWeekMap) { chip::System::Clock::Milliseconds64 cTMs; CHIP_ERROR err = chip::System::SystemClock().GetClock_RealTimeMS(cTMs); @@ -110,7 +115,12 @@ CHIP_ERROR UtilsGetLocalDayOfWeekNow(uint8_t & dayOfWeekMap) return err; } time_t unixEpoch = std::chrono::duration_cast(cTMs).count(); - dayOfWeekMap = UtilsGetLocalDayOfWeekFromUnixEpoch(unixEpoch); + dayOfWeekMap = GetLocalDayOfWeekFromUnixEpoch(unixEpoch); return CHIP_NO_ERROR; } + +} // namespace DeviceEnergyManagement +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py index 29f887280957b4..6b5135872cabec 100644 --- a/src/python_testing/matter_testing_support.py +++ b/src/python_testing/matter_testing_support.py @@ -265,11 +265,11 @@ def wait_for_event_report(self, expected_event: ClusterObjects.ClusterEvent, tim asserts.assert_equal(res.Header.EventId, expected_event.event_id, "Expected event ID not found in event report") return res.Data - def wait_for_event_expect_no_report(self, timeout: int = 10): - """This function succceeds/returns if an event does not arrive within the timeout. + def wait_for_event_expect_no_report(self, timeoutS: int = 10): + """This function succceeds/returns if an event does not arrive within the timeout specified in seconds. If an event does arrive, an assert is called.""" try: - res = self._q.get(block=True, timeout=timeout) + res = self._q.get(block=True, timeout=timeoutS) except queue.Empty: return From a89767f9dfece478738d0d31f0d883115a7f1602 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 25 Jun 2024 07:07:43 +0000 Subject: [PATCH 27/74] Restyled by whitespace --- .../energy-management-common/include/EnergyTimeUtils.h | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h b/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h index f16ddd6d53ddab..1ce662bd2635b0 100644 --- a/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h +++ b/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h @@ -64,4 +64,3 @@ CHIP_ERROR GetLocalDayOfWeekNow(uint8_t & dayOfWeekMap); } // namespace Clusters } // namespace app } // namespace chip - From 203802373ed78afcf65b8f36a4ce7f5620990d6d Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 25 Jun 2024 07:07:49 +0000 Subject: [PATCH 28/74] Restyled by isort --- src/python_testing/TC_DEM_2_2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_DEM_2_2.py b/src/python_testing/TC_DEM_2_2.py index 0daa97fa2b93fa..a9cafb85c22677 100644 --- a/src/python_testing/TC_DEM_2_2.py +++ b/src/python_testing/TC_DEM_2_2.py @@ -24,9 +24,9 @@ import chip.clusters as Clusters from chip.interaction_model import Status +from DEMTestBase import DEMTestBase from matter_testing_support import EventChangeCallback, MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts -from DEMTestBase import DEMTestBase logger = logging.getLogger(__name__) From 6a76ba9c9da20de3e8d622ce09b9ac4548202fc9 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Wed, 3 Jul 2024 11:36:25 +0100 Subject: [PATCH 29/74] Try to address setForecast comments from Boris --- .../DeviceEnergyManagementDelegateImpl.h | 72 ++++++++++--------- .../DeviceEnergyManagementDelegateImpl.cpp | 4 +- .../device-energy-management-server.h | 38 +++++++++- 3 files changed, 75 insertions(+), 39 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 33eb3e1d57efd5..5bf0ec33797fb9 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -182,8 +182,43 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate virtual CHIP_ERROR SetESAState(ESAStateEnum) override; virtual CHIP_ERROR SetAbsMinPower(int64_t) override; virtual CHIP_ERROR SetAbsMaxPower(int64_t) override; - virtual CHIP_ERROR SetPowerAdjustmentCapability(DataModel::Nullable &) override; - virtual CHIP_ERROR SetForecast(DataModel::Nullable &) override; + virtual CHIP_ERROR SetPowerAdjustmentCapability(const DataModel::Nullable &) override; + + // The DeviceEnergyManagementDelegate owns the master copy of the ForecastStruct object which is accessed via GetForecast and + // SetForecast. The slots field of forecast is owned and managed by the object that implements the DEMManufacturerDelegate + // interface. The slots memory MUST exist for the lifetime of the forecast object from where it is referenced. + // + // The rationale for this is as follows: + // It is envisioned there will be one master forecast object declared in DeviceEnergyManagementDelegate. When + // constructed, the field DataModel::List slots will be empty. + // + // The EVSEManufacturerImpl class (examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h) is + // an example implementation that a specific vendor can use as a template. It understands how the underlying energy appliance + // functions. EVSEManufacturerImpl inherits from DEMManufacturerDelegate + // (examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h) which is a generic interface + // and how the DeviceEnergyManagementDelegate class + // (examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp) communicates from the + // generic cluster world to the specific appliance implementation (EVSEManufacturerImpl). + // + // EVSEManufacturerImpl understands the slot structures of the appliance and configures the slot structures as follows: + // + // Call DeviceEnergyManagementDelegate::GetForecast() to get the current forecast + // Modify the slot structure - the slots memory is owned by EVSEManufacturerImpl + // Call DeviceEnergyManagementDelegate::GetForecast() to set the current forecast + // + // + // The cluster object DeviceEnergyManagement::Instance + // (src/app/clusters/device-energy-management-server/device-energy-management-server.cpp) only reads the slots field of + // forecast when checking commands (indeed it does not modify any forecast fields itself). The DeviceEnergyManagementDelegate + // object does modify some of forecast's fields but does NOT modify the slots field. The only command that can modify the + // slots field is HandleModifyForecastRequest. Whilst DeviceEnergyManagementDelegate::ModifyForecastRequest does some state + // checking, the slots field is only modified by the EVSEManufacturerImpl object via the call + // DEMManufacturerDelegate::HandleModifyForecastRequest. DEMManufacturerDelegate::HandleModifyForecastRequest may + // delete/allocate the slots memory but this will be done atomically in the call to + // DEMManufacturerDelegate::HandleModifyForecastRequest so the underlying memory is coherent => the call to + // DEMManufacturerDelegate::HandleModifyForecastRequest cannot be interrupted by any other CHIP task activity. + virtual CHIP_ERROR SetForecast(const DataModel::Nullable &) override; + virtual CHIP_ERROR SetOptOutState(OptOutStateEnum) override; // Returns whether the DeviceEnergyManagement is supported @@ -242,39 +277,6 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate DataModel::Nullable mPowerAdjustCapabilityStruct; - // The DeviceEnergyManagementDelegate owns the master copy of the ForecastStruct object which is accessed via GetForecast and - // SetForecast. The slots field of forecast is owned and managed by the object that implements the DEMManufacturerDelegate - // interface. - // - // The rationale for this is as follows: - // It is envisioned there will be one master forecast object declared in DeviceEnergyManagementDelegate. When - // constructed, the field DataModel::List slots will be empty. - // - // The EVSEManufacturerImpl class (examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h) is - // an example implementation that a specific vendor can use as a template. It understands how the underlying energy appliance - // functions. EVSEManufacturerImpl inherits from DEMManufacturerDelegate - // (examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h) which is a generic interface - // and how the DeviceEnergyManagementDelegate class - // (examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp) communicates from the - // generic cluster world to the specific appliance implementation (EVSEManufacturerImpl). - // - // EVSEManufacturerImpl understands the slot structures of the appliance and configures the slot structures as follows: - // - // Call DeviceEnergyManagementDelegate::GetForecast() to get the current forecast - // Modify the slot structure - the slots memory is owned by EVSEManufacturerImpl - // Call DeviceEnergyManagementDelegate::GetForecast() to set the current forecast - // - // - // The cluster object DeviceEnergyManagement::Instance - // (src/app/clusters/device-energy-management-server/device-energy-management-server.cpp) only reads the slots field of - // forecast when checking commands (indeed it does not modify any forecast fields itself). The DeviceEnergyManagementDelegate - // object does modify some of forecast's fields but does NOT modify the slots field. The only command that can modify the - // slots field is HandleModifyForecastRequest. Whilst DeviceEnergyManagementDelegate::ModifyForecastRequest does some state - // checking, the slots field is only modified by the EVSEManufacturerImpl object via the call - // DEMManufacturerDelegate::HandleModifyForecastRequest. DEMManufacturerDelegate::HandleModifyForecastRequest may - // delete/allocate the slots memory but this will be done atomically in the call to - // DEMManufacturerDelegate::HandleModifyForecastRequest so the underlying memory is coherent => the call to - // DEMManufacturerDelegate::HandleModifyForecastRequest cannot be interrupted by any other CHIP task activity. DataModel::Nullable mForecast; // Keep track whether a PowerAdjustment is in progress 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 c4fe74e8c13179..1034bcb868da01 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -881,7 +881,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetAbsMaxPower(int64_t newValueMw) CHIP_ERROR DeviceEnergyManagementDelegate::SetPowerAdjustmentCapability( - DataModel::Nullable & powerAdjustCapabilityStruct) + const DataModel::Nullable & powerAdjustCapabilityStruct) { if (powerAdjustCapabilityStruct.IsNull()) { @@ -895,7 +895,7 @@ DeviceEnergyManagementDelegate::SetPowerAdjustmentCapability( return CHIP_NO_ERROR; } -CHIP_ERROR DeviceEnergyManagementDelegate::SetForecast(DataModel::Nullable & forecast) +CHIP_ERROR DeviceEnergyManagementDelegate::SetForecast(const DataModel::Nullable & forecast) { // TODO see Issue #31147 if (forecast.IsNull()) 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 72b3c672c2c8e8..ce330df1edf01c 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 @@ -176,8 +176,42 @@ class Delegate virtual CHIP_ERROR SetESAState(ESAStateEnum) = 0; virtual CHIP_ERROR SetAbsMinPower(int64_t) = 0; virtual CHIP_ERROR SetAbsMaxPower(int64_t) = 0; - virtual CHIP_ERROR SetPowerAdjustmentCapability(DataModel::Nullable &) = 0; - virtual CHIP_ERROR SetForecast(DataModel::Nullable &) = 0; + virtual CHIP_ERROR SetPowerAdjustmentCapability(const DataModel::Nullable &) = 0; + + // The DeviceEnergyManagementDelegate owns the master copy of the ForecastStruct object which is accessed via GetForecast and + // SetForecast. The slots field of forecast is owned and managed by the object that implements the DEMManufacturerDelegate + // interface. The slots memory MUST exist for the lifetime of the forecast object from where it is referenced. + // + // The rationale for this is as follows: + // It is envisioned there will be one master forecast object declared in DeviceEnergyManagementDelegate. When + // constructed, the field DataModel::List slots will be empty. + // + // The EVSEManufacturerImpl class (examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h) is + // an example implementation that a specific vendor can use as a template. It understands how the underlying energy appliance + // functions. EVSEManufacturerImpl inherits from DEMManufacturerDelegate + // (examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h) which is a generic interface + // and how the DeviceEnergyManagementDelegate class + // (examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp) communicates from the + // generic cluster world to the specific appliance implementation (EVSEManufacturerImpl). + // + // EVSEManufacturerImpl understands the slot structures of the appliance and configures the slot structures as follows: + // + // Call DeviceEnergyManagementDelegate::GetForecast() to get the current forecast + // Modify the slot structure - the slots memory is owned by EVSEManufacturerImpl + // Call DeviceEnergyManagementDelegate::GetForecast() to set the current forecast + // + // + // The cluster object DeviceEnergyManagement::Instance + // (src/app/clusters/device-energy-management-server/device-energy-management-server.cpp) only reads the slots field of + // forecast when checking commands (indeed it does not modify any forecast fields itself). The DeviceEnergyManagementDelegate + // object does modify some of forecast's fields but does NOT modify the slots field. The only command that can modify the + // slots field is HandleModifyForecastRequest. Whilst DeviceEnergyManagementDelegate::ModifyForecastRequest does some state + // checking, the slots field is only modified by the EVSEManufacturerImpl object via the call + // DEMManufacturerDelegate::HandleModifyForecastRequest. DEMManufacturerDelegate::HandleModifyForecastRequest may + // delete/allocate the slots memory but this will be done atomically in the call to + // DEMManufacturerDelegate::HandleModifyForecastRequest so the underlying memory is coherent => the call to + // DEMManufacturerDelegate::HandleModifyForecastRequest cannot be interrupted by any other CHIP task activity. + virtual CHIP_ERROR SetForecast(const DataModel::Nullable &) = 0; virtual CHIP_ERROR SetOptOutState(OptOutStateEnum) = 0; protected: From 5ebaf2241a30b0d2792707794cf435f47e578665 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Wed, 3 Jul 2024 19:00:36 +0100 Subject: [PATCH 30/74] Remove unnecessary SetXXX methods from the device energy management cluster interface --- .../DeviceEnergyManagementDelegateImpl.h | 17 ++++---- .../device-energy-management-server.h | 41 ------------------- 2 files changed, 10 insertions(+), 48 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 5bf0ec33797fb9..8c0e75cb244687 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -177,12 +177,14 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate // ------------------------------------------------------------------ // Overridden DeviceEnergyManagement::Delegate Set attribute methods - virtual CHIP_ERROR SetESAType(ESATypeEnum) override; - virtual CHIP_ERROR SetESACanGenerate(bool) override; virtual CHIP_ERROR SetESAState(ESAStateEnum) override; - virtual CHIP_ERROR SetAbsMinPower(int64_t) override; - virtual CHIP_ERROR SetAbsMaxPower(int64_t) override; - virtual CHIP_ERROR SetPowerAdjustmentCapability(const DataModel::Nullable &) override; + + // Local Set methods + CHIP_ERROR SetESAType(ESATypeEnum); + CHIP_ERROR SetESACanGenerate(bool); + CHIP_ERROR SetAbsMinPower(int64_t); + CHIP_ERROR SetAbsMaxPower(int64_t); + CHIP_ERROR SetPowerAdjustmentCapability(const DataModel::Nullable &); // The DeviceEnergyManagementDelegate owns the master copy of the ForecastStruct object which is accessed via GetForecast and // SetForecast. The slots field of forecast is owned and managed by the object that implements the DEMManufacturerDelegate @@ -217,9 +219,9 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate // delete/allocate the slots memory but this will be done atomically in the call to // DEMManufacturerDelegate::HandleModifyForecastRequest so the underlying memory is coherent => the call to // DEMManufacturerDelegate::HandleModifyForecastRequest cannot be interrupted by any other CHIP task activity. - virtual CHIP_ERROR SetForecast(const DataModel::Nullable &) override; + CHIP_ERROR SetForecast(const DataModel::Nullable &); - virtual CHIP_ERROR SetOptOutState(OptOutStateEnum) override; + CHIP_ERROR SetOptOutState(OptOutStateEnum); // Returns whether the DeviceEnergyManagement is supported uint32_t HasFeature(Feature feature) const; @@ -277,6 +279,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate DataModel::Nullable mPowerAdjustCapabilityStruct; + // See note above on SetForecast() about mForecast memory management DataModel::Nullable mForecast; // Keep track whether a PowerAdjustment is in progress 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 ce330df1edf01c..812072b46a59a6 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 @@ -171,48 +171,7 @@ class Delegate // ------------------------------------------------------------------ // Set attribute methods - virtual CHIP_ERROR SetESAType(ESATypeEnum) = 0; - virtual CHIP_ERROR SetESACanGenerate(bool) = 0; virtual CHIP_ERROR SetESAState(ESAStateEnum) = 0; - virtual CHIP_ERROR SetAbsMinPower(int64_t) = 0; - virtual CHIP_ERROR SetAbsMaxPower(int64_t) = 0; - virtual CHIP_ERROR SetPowerAdjustmentCapability(const DataModel::Nullable &) = 0; - - // The DeviceEnergyManagementDelegate owns the master copy of the ForecastStruct object which is accessed via GetForecast and - // SetForecast. The slots field of forecast is owned and managed by the object that implements the DEMManufacturerDelegate - // interface. The slots memory MUST exist for the lifetime of the forecast object from where it is referenced. - // - // The rationale for this is as follows: - // It is envisioned there will be one master forecast object declared in DeviceEnergyManagementDelegate. When - // constructed, the field DataModel::List slots will be empty. - // - // The EVSEManufacturerImpl class (examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h) is - // an example implementation that a specific vendor can use as a template. It understands how the underlying energy appliance - // functions. EVSEManufacturerImpl inherits from DEMManufacturerDelegate - // (examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h) which is a generic interface - // and how the DeviceEnergyManagementDelegate class - // (examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp) communicates from the - // generic cluster world to the specific appliance implementation (EVSEManufacturerImpl). - // - // EVSEManufacturerImpl understands the slot structures of the appliance and configures the slot structures as follows: - // - // Call DeviceEnergyManagementDelegate::GetForecast() to get the current forecast - // Modify the slot structure - the slots memory is owned by EVSEManufacturerImpl - // Call DeviceEnergyManagementDelegate::GetForecast() to set the current forecast - // - // - // The cluster object DeviceEnergyManagement::Instance - // (src/app/clusters/device-energy-management-server/device-energy-management-server.cpp) only reads the slots field of - // forecast when checking commands (indeed it does not modify any forecast fields itself). The DeviceEnergyManagementDelegate - // object does modify some of forecast's fields but does NOT modify the slots field. The only command that can modify the - // slots field is HandleModifyForecastRequest. Whilst DeviceEnergyManagementDelegate::ModifyForecastRequest does some state - // checking, the slots field is only modified by the EVSEManufacturerImpl object via the call - // DEMManufacturerDelegate::HandleModifyForecastRequest. DEMManufacturerDelegate::HandleModifyForecastRequest may - // delete/allocate the slots memory but this will be done atomically in the call to - // DEMManufacturerDelegate::HandleModifyForecastRequest so the underlying memory is coherent => the call to - // DEMManufacturerDelegate::HandleModifyForecastRequest cannot be interrupted by any other CHIP task activity. - virtual CHIP_ERROR SetForecast(const DataModel::Nullable &) = 0; - virtual CHIP_ERROR SetOptOutState(OptOutStateEnum) = 0; protected: EndpointId mEndpointId = 0; From afcc61fe729de8be3b0b8cffa0b94614bfa0d171 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 3 Jul 2024 18:05:35 +0000 Subject: [PATCH 31/74] Restyled by clang-format --- .../device-energy-management-server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 812072b46a59a6..aa666fe36a8af3 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 @@ -171,7 +171,7 @@ class Delegate // ------------------------------------------------------------------ // Set attribute methods - virtual CHIP_ERROR SetESAState(ESAStateEnum) = 0; + virtual CHIP_ERROR SetESAState(ESAStateEnum) = 0; protected: EndpointId mEndpointId = 0; From 78633e09ff133802366e81b9e31d4809fde516b1 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Sat, 13 Jul 2024 08:29:20 +0100 Subject: [PATCH 32/74] Apply code review changes suggested by Louis-Philip Beliveau --- .../include/DEMManufacturerDelegate.h | 5 ----- .../DeviceEnergyManagementDelegateImpl.h | 17 ++++++++--------- .../include/EnergyTimeUtils.h | 5 ++--- .../src/DeviceEnergyManagementDelegateImpl.cpp | 4 ++++ 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h index 68c30dc2cd6686..65d214d31904ab 100644 --- a/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h +++ b/examples/energy-management-app/energy-management-common/include/DEMManufacturerDelegate.h @@ -20,17 +20,12 @@ #include #include -#include - -using chip::Protocols::InteractionModel::Status; namespace chip { namespace app { namespace Clusters { namespace DeviceEnergyManagement { -class DeviceEnergyManagementDelegate; - /** * Class to abstract manufacturer specific functionality */ 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 8c0e75cb244687..64c512dcb95612 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -21,7 +21,6 @@ #include #include -using chip::Protocols::InteractionModel::Status; namespace chip { namespace app { namespace Clusters { @@ -55,7 +54,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::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 powerMw, const uint32_t durationS, AdjustmentCauseEnum cause) override; + virtual chip::Protocols::InteractionModel::Status PowerAdjustRequest(const int64_t powerMw, const uint32_t durationS, AdjustmentCauseEnum cause) override; /** * @brief Make the ESA end the active power adjustment session & return to normal (or idle) power levels. @@ -63,7 +62,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate * * @return It should report SUCCESS if successful and FAILURE otherwise. */ - virtual Status CancelPowerAdjustRequest() override; + virtual chip::Protocols::InteractionModel::Status CancelPowerAdjustRequest() override; /** * @brief The ESA SHALL update its Forecast attribute with the RequestedStartTime including a new ForecastID. @@ -81,7 +80,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::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 requestedStartTimeUtc, AdjustmentCauseEnum cause) override; + virtual chip::Protocols::InteractionModel::Status StartTimeAdjustRequest(const uint32_t requestedStartTimeUtc, AdjustmentCauseEnum cause) override; /** * @brief Handler for PauseRequest command @@ -96,7 +95,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::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 durationS, AdjustmentCauseEnum cause) override; + virtual chip::Protocols::InteractionModel::Status PauseRequest(const uint32_t durationS, AdjustmentCauseEnum cause) override; /** * @brief Handler for ResumeRequest command @@ -107,7 +106,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate * * @return Success if the ESA is resumed, otherwise returns other IM_Status. */ - virtual Status ResumeRequest() override; + virtual chip::Protocols::InteractionModel::Status ResumeRequest() override; /** * @brief Handler for ModifyForecastRequest @@ -125,7 +124,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate * @return Success if the entire list of SlotAdjustmentStruct are accepted, otherwise the command * SHALL be rejected returning other IM_Status. */ - virtual Status + virtual chip::Protocols::InteractionModel::Status ModifyForecastRequest(const uint32_t forecastID, const DataModel::DecodableList & slotAdjustments, AdjustmentCauseEnum cause) override; @@ -141,7 +140,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::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 + virtual chip::Protocols::InteractionModel::Status RequestConstraintBasedForecast(const DataModel::DecodableList & constraints, AdjustmentCauseEnum cause) override; @@ -162,7 +161,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate * * @return Success if successful, otherwise the command SHALL be rejected returning other IM_Status. */ - virtual Status CancelRequest() override; + virtual chip::Protocols::InteractionModel::Status CancelRequest() override; // ------------------------------------------------------------------ // Overridden DeviceEnergyManagement::Delegate Get attribute methods diff --git a/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h b/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h index 1ce662bd2635b0..9c4ea1ec06b5f9 100644 --- a/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h +++ b/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h @@ -20,10 +20,9 @@ #include #include +#include #include -#include - -using chip::Protocols::InteractionModel::Status; +#include namespace chip { namespace app { 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 1034bcb868da01..e89f0426e5e6cc 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -20,6 +20,7 @@ #include "DEMManufacturerDelegate.h" #include "EnergyTimeUtils.h" #include +#include using namespace chip; using namespace chip::app; @@ -27,6 +28,9 @@ using namespace chip::app::Clusters; using namespace chip::app::Clusters::DeviceEnergyManagement; using namespace chip::app::Clusters::DeviceEnergyManagement::Attributes; +using chip::Protocols::InteractionModel::Status; + + using chip::Optional; using CostsList = DataModel::List; From 85bae274b76ab47b750c65e00d84eb8fe34e7dd1 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Mon, 15 Jul 2024 09:26:25 +0100 Subject: [PATCH 33/74] Document the API for GetForecast and GetPowerAdjustmentCapability --- .../device-energy-management-server.h | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) 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 aa666fe36a8af3..95b2976e9dc5fb 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 @@ -165,10 +165,32 @@ class Delegate virtual ESAStateEnum GetESAState() = 0; virtual int64_t GetAbsMinPower() = 0; virtual int64_t GetAbsMaxPower() = 0; - virtual DataModel::Nullable & GetPowerAdjustmentCapability() = 0; - virtual DataModel::Nullable & GetForecast() = 0; virtual OptOutStateEnum GetOptOutState() = 0; + /** + * @brief Returns the current PowerAdjustCapability object + * + * The caller of GetPowerAdjustmentCapability() must not store a pointer/reference to the + * DataModel::Nullable return value. Structs::PowerAdjustCapabilityStruct + * contains a list of powerAdjustCapabilities (of type PowerAdjustStruct). The memory allocated for these + * is managed by the application and could change once the caller of GetPowerAdjustmentCapability has finished its + * processing. + * + * @return The current PowerAdjustCapability object + */ + virtual DataModel::Nullable & GetPowerAdjustmentCapability() = 0; + + /** + * @brief Returns the current Forecast object + * + * The caller of GetForecast() must not store a pointer/reference to the Structs::ForecastStruct return value. + * Structs::ForecastStruct contains a list of slots (of type SlotStruct). The memory allocated for the slots + * is managed by the application and could change once the caller of GetForecast has finished its processing. + * + * @return The current Forecast object + */ + virtual DataModel::Nullable & GetForecast() = 0; + // ------------------------------------------------------------------ // Set attribute methods virtual CHIP_ERROR SetESAState(ESAStateEnum) = 0; From 3ed6f14100523f88006763f97f44e37ebc755bcd Mon Sep 17 00:00:00 2001 From: pcoleman Date: Mon, 15 Jul 2024 13:11:37 +0100 Subject: [PATCH 34/74] Document the GetForecast and GetPowerAdjustmentCapability APIs --- .../device-energy-management-server.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 95b2976e9dc5fb..2f45ea3c38481a 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 @@ -170,11 +170,10 @@ class Delegate /** * @brief Returns the current PowerAdjustCapability object * - * The caller of GetPowerAdjustmentCapability() must not store a pointer/reference to the - * DataModel::Nullable return value. Structs::PowerAdjustCapabilityStruct - * contains a list of powerAdjustCapabilities (of type PowerAdjustStruct). The memory allocated for these - * is managed by the application and could change once the caller of GetPowerAdjustmentCapability has finished its - * processing. + * The delegate MUST implement an API to provide a temporary reference to the Structs::PowerAdjustCapabilityStruct. + * The SDK (and other users) MUST not use the return value from GetPowerAdjustmentCapability() after they + * have used it in the scope of the calling function. The memory associated with the PowerAdjustCapabilityStruct + * is likely to change or be re-allocated, so would become invalid outside the scope of this calling function. * * @return The current PowerAdjustCapability object */ @@ -183,9 +182,10 @@ class Delegate /** * @brief Returns the current Forecast object * - * The caller of GetForecast() must not store a pointer/reference to the Structs::ForecastStruct return value. - * Structs::ForecastStruct contains a list of slots (of type SlotStruct). The memory allocated for the slots - * is managed by the application and could change once the caller of GetForecast has finished its processing. + * The delegate MUST implement an API to provide a temporary reference to the Structs::ForecastStruct. The SDK + * (and other users) MUST not use the return value from GetForecast() after they have used it in the scope of + * the calling function. The memory associated with the ForecastStruct is likely to change or be re-allocated, + * so would become invalid outside the scope of this calling function. * * @return The current Forecast object */ From 5fee7b92e18730cd99e9fa138f4c80dffbcdd321 Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 07:57:26 +0100 Subject: [PATCH 35/74] Update src/app/clusters/device-energy-management-server/device-energy-management-server.h Co-authored-by: Boris Zbarsky --- .../device-energy-management-server.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 2f45ea3c38481a..464a8cd28bb120 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 @@ -170,10 +170,11 @@ class Delegate /** * @brief Returns the current PowerAdjustCapability object * - * The delegate MUST implement an API to provide a temporary reference to the Structs::PowerAdjustCapabilityStruct. - * The SDK (and other users) MUST not use the return value from GetPowerAdjustmentCapability() after they - * have used it in the scope of the calling function. The memory associated with the PowerAdjustCapabilityStruct - * is likely to change or be re-allocated, so would become invalid outside the scope of this calling function. + * The reference returned from GetPowerAdjustmentCapability() is only valid until the next Matter event + * is processed. Callers must not hold on to that reference for any asynchronous processing. + * + * Once another Matter event has had a chance to run, the memory associated with the + * PowerAdjustCapabilityStruct is likely to change or be re-allocated, so would become invalid. * * @return The current PowerAdjustCapability object */ From 7194f5ba1bf663ef63c9b2faae2e42d7e3305041 Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 07:58:47 +0100 Subject: [PATCH 36/74] Update src/app/clusters/device-energy-management-server/device-energy-management-server.h Co-authored-by: Boris Zbarsky --- .../device-energy-management-server.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 464a8cd28bb120..e8b2f411d68f59 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 @@ -183,10 +183,11 @@ class Delegate /** * @brief Returns the current Forecast object * - * The delegate MUST implement an API to provide a temporary reference to the Structs::ForecastStruct. The SDK - * (and other users) MUST not use the return value from GetForecast() after they have used it in the scope of - * the calling function. The memory associated with the ForecastStruct is likely to change or be re-allocated, - * so would become invalid outside the scope of this calling function. + * The reference returned from GetForecast() is only valid until the next Matter event + * is processed. Callers must not hold on to that reference for any asynchronous processing. + * + * Once another Matter event has had a chance to run, the memory associated with the + * ForecastStruct is likely to change or be re-allocated, so would become invalid. * * @return The current Forecast object */ From d93a68e3726c31ffd854f16e7a1f7128a303f871 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 18 Jul 2024 08:50:35 +0100 Subject: [PATCH 37/74] Address review comments from Boris --- .../energy-management-app/energy-management-common/BUILD.gn | 2 +- .../include/DeviceEnergyManagementDelegateImpl.h | 4 ++-- .../src/DeviceEnergyManagementDelegateImpl.cpp | 4 ++-- .../esp32/main/include/CHIPProjectConfig.h | 2 +- .../energy-management-app/esp32/sdkconfig.optimize.defaults | 2 +- examples/energy-management-app/linux/BUILD.gn | 2 +- examples/energy-management-app/linux/args.gni | 2 +- examples/energy-management-app/linux/main.cpp | 2 +- .../device-energy-management-server.cpp | 3 ++- .../device-energy-management-server.h | 4 ++-- 10 files changed, 14 insertions(+), 13 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/BUILD.gn b/examples/energy-management-app/energy-management-common/BUILD.gn index a1dc2c320f9d79..e6b67461f40a3b 100644 --- a/examples/energy-management-app/energy-management-common/BUILD.gn +++ b/examples/energy-management-app/energy-management-common/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Project CHIP Authors +# Copyright (c) 2023-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. 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 64c512dcb95612..26563a653f0cfc 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -170,8 +170,8 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate virtual ESAStateEnum GetESAState() override; virtual int64_t GetAbsMinPower() override; virtual int64_t GetAbsMaxPower() override; - virtual DataModel::Nullable & GetPowerAdjustmentCapability() override; - virtual DataModel::Nullable & GetForecast() override; + virtual const DataModel::Nullable & GetPowerAdjustmentCapability() override; + virtual const DataModel::Nullable & GetForecast() override; virtual OptOutStateEnum GetOptOutState() 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 e89f0426e5e6cc..a689f6a8651bbb 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -782,12 +782,12 @@ int64_t DeviceEnergyManagementDelegate::GetAbsMaxPower() return mAbsMaxPowerMw; } -DataModel::Nullable & DeviceEnergyManagementDelegate::GetPowerAdjustmentCapability() +const DataModel::Nullable & DeviceEnergyManagementDelegate::GetPowerAdjustmentCapability() { return mPowerAdjustCapabilityStruct; } -DataModel::Nullable & DeviceEnergyManagementDelegate::GetForecast() +const DataModel::Nullable & DeviceEnergyManagementDelegate::GetForecast() { ChipLogDetail(Zcl, "DeviceEnergyManagementDelegate::GetForecast"); diff --git a/examples/energy-management-app/esp32/main/include/CHIPProjectConfig.h b/examples/energy-management-app/esp32/main/include/CHIPProjectConfig.h index a68e0cfcd5cdb4..b70a285ccfda0b 100644 --- a/examples/energy-management-app/esp32/main/include/CHIPProjectConfig.h +++ b/examples/energy-management-app/esp32/main/include/CHIPProjectConfig.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2023-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/esp32/sdkconfig.optimize.defaults b/examples/energy-management-app/esp32/sdkconfig.optimize.defaults index cd2995a7c62ae2..85a5c0cbd4615c 100644 --- a/examples/energy-management-app/esp32/sdkconfig.optimize.defaults +++ b/examples/energy-management-app/esp32/sdkconfig.optimize.defaults @@ -1,5 +1,5 @@ # -# Copyright (c) 2024 Project CHIP Authors +# Copyright (c) 2023-2024 Project CHIP Authors # All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/linux/BUILD.gn b/examples/energy-management-app/linux/BUILD.gn index 0c5aa1c3adaced..c3564c345a1182 100644 --- a/examples/energy-management-app/linux/BUILD.gn +++ b/examples/energy-management-app/linux/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Project CHIP Authors +# Copyright (c) 2023-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. diff --git a/examples/energy-management-app/linux/args.gni b/examples/energy-management-app/linux/args.gni index 14e8335505cb8e..1f196e6122910c 100644 --- a/examples/energy-management-app/linux/args.gni +++ b/examples/energy-management-app/linux/args.gni @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Project CHIP Authors +# Copyright (c) 2023-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. diff --git a/examples/energy-management-app/linux/main.cpp b/examples/energy-management-app/linux/main.cpp index add57c0b02746a..2d056e56a9b149 100644 --- a/examples/energy-management-app/linux/main.cpp +++ b/examples/energy-management-app/linux/main.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2023-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); 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 035a3daef71b88..5e5c56e163504a 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 @@ -606,6 +606,7 @@ void Instance::HandlePauseRequest(HandlerContext & ctx, const Commands::PauseReq if (status != Status::Success) { ChipLogError(Zcl, "DEM: PauseRequest(%ld) FAILURE", static_cast(duration)); + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); return; } } @@ -622,7 +623,7 @@ void Instance::HandleResumeRequest(HandlerContext & ctx, const Commands::ResumeR if (ESAStateEnum::kPaused != mDelegate.GetESAState()) { ChipLogError(Zcl, "DEM: ESAState not Paused."); - ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::Failure); + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::InvalidInState); return; } 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 e8b2f411d68f59..bf01f28bd8b84d 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 @@ -178,7 +178,7 @@ class Delegate * * @return The current PowerAdjustCapability object */ - virtual DataModel::Nullable & GetPowerAdjustmentCapability() = 0; + virtual const DataModel::Nullable & GetPowerAdjustmentCapability() = 0; /** * @brief Returns the current Forecast object @@ -191,7 +191,7 @@ class Delegate * * @return The current Forecast object */ - virtual DataModel::Nullable & GetForecast() = 0; + virtual const DataModel::Nullable & GetForecast() = 0; // ------------------------------------------------------------------ // Set attribute methods From a1d146c0fa828f5968a4ef3e90482b34dd3bc440 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 18 Jul 2024 10:25:44 +0100 Subject: [PATCH 38/74] Sync up with code review comments from PR34234 --- src/python_testing/TC_DEM_2_2.py | 190 +++++++++++++++++++------------ 1 file changed, 116 insertions(+), 74 deletions(-) diff --git a/src/python_testing/TC_DEM_2_2.py b/src/python_testing/TC_DEM_2_2.py index a9cafb85c22677..050c9f900cafd2 100644 --- a/src/python_testing/TC_DEM_2_2.py +++ b/src/python_testing/TC_DEM_2_2.py @@ -14,6 +14,19 @@ # See the License for the specific language governing permissions and # limitations under the License. # pylint: disable=invalid-name + +# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments +# for details about the block below. +# +# === BEGIN CI TEST ARGUMENTS === +# test-runner-runs: run1 +# test-runner-run/run1/app: ${ENERGY_MANAGEMENT_APP} +# test-runner-run/run1/factoryreset: True +# test-runner-run/run1/quiet: True +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f +# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto +# === END CI TEST ARGUMENTS === + """Define Matter test case TC_DEM_2_2.""" @@ -24,9 +37,9 @@ import chip.clusters as Clusters from chip.interaction_model import Status -from DEMTestBase import DEMTestBase from matter_testing_support import EventChangeCallback, MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts +from TC_DEMTestBase import DEMTestBase logger = logging.getLogger(__name__) @@ -48,51 +61,86 @@ def pics_TC_DEM_2_2(self): def steps_TC_DEM_2_2(self) -> list[TestStep]: """Execute the test steps.""" steps = [ - TestStep("1", "Commissioning, already done", is_commissioning=True), - TestStep("2", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster. Verify that TestEventTriggersEnabled attribute has a value of 1 (True)"), - TestStep("3", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Power Adjustment Test Event"), - TestStep("3a", "TH reads ESAState attribute. Verify value is 0x01 (Online)"), - TestStep("3b", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=NoAdjustment. Note value for later. Determine the OverallMaxPower and OverallMaxDuration as the largest MaxPower and MaxDuration of the PowerAdjustStructs returned, and similarly the OverallMinPower and OverallMinDuration as the smallest of the MinPower and MinDuration values."), - TestStep("3c", "TH reads OptOutState attribute. Verify value is 0x00 (NoOptOut)"), - TestStep( - "4", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is Success and Event DEM.S.E00(PowerAdjustStart) sent"), - TestStep("4a", "TH reads ESAState attribute. Verify value is 0x04 (PowerAdjustActive)"), - TestStep("4b", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=LocalOptimizationAdjustment."), - TestStep("5", "TH sends CancelPowerAdjustRequest. Verify Command response is Success and Event DEM.S.E01(PowerAdjustEnd) sent with Cause=Cancelled"), - TestStep("5a", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=NoAdjustment."), - TestStep("5b", "TH reads ESAState attribute. Verify value is 0x01 (Online)"), - TestStep("6", "TH sends CancelPowerAdjustRequest. Verify Command response is InvalidInStateError"), - TestStep("7", "TH sends PowerAdjustRequest with Power=OverallMaxPower+1 Duration=OverallMinDuration Cause=LocalOptimization. Verify Command response is ConstraintError"), - TestStep("8", "TH sends PowerAdjustRequest with Power=OverallMinPower Duration=OverallMaxDuration+1 Cause=LocalOptimization. Verify Command response is ConstraintError"), - TestStep("9", "TH sends PowerAdjustRequest with Power=OverallMinPower-1 Duration=OverallMaxDuration Cause=LocalOptimization. Verify Command response is ConstraintError"), - TestStep("10", "TH sends PowerAdjustRequest with Power=OverallMaxPower Duration=OverallMinDuration-1 Cause=LocalOptimization. Verify Command response is ConstraintError"), - TestStep( - "11", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is Success and event DEM.S.E00(PowerAdjustStart) sent"), - TestStep("11a", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=LocalOptimizationAdjustment."), - TestStep( - "12", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=GridOptimization. Verify Command response is Success and no event sent"), - TestStep("12a", "TH reads ESAState attribute. Verify value is 0x04 (PowerAdjustActive)"), - TestStep("12b", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=GridOptimizationAdjustment."), - TestStep("13", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event. No event sent"), - TestStep("13a", "TH reads ESAState attribute. Verify value is 0x04 (PowerAdjustActive)"), - TestStep("13b", "TH reads OptOutState attribute. Verify value is 0x02 (LocalOptOut)"), - TestStep( - "14", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is ConstraintError"), - TestStep("15", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event. Event DEM.S.E01(PowerAdjustEnd) sent with Cause=UserOptOut, Duration= approx time from step 11 to step 15, EnergyUse= a valid value"), - TestStep("15a", "TH reads ESAState attribute. Verify value is 0x01 (Online)"), - TestStep("15b", "TH reads OptOutState attribute. Verify value is 0x03 (OptOut)"), - TestStep("15c", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=NoAdjustment."), - TestStep("16", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear"), - TestStep("16a", "TH reads ESAState attribute. Verify value is 0x01 (Online)"), - TestStep("16b", "TH reads OptOutState attribute. Verify value is 0x00 (NoOptOut)"), - TestStep( - "17", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization. Verify Command response is Success and event DEM.S.E00(PowerAdjustStart) sent"), - TestStep("17a", "TH reads ESAState attribute. Verify value is 0x04 (PowerAdjustActive)"), - TestStep("17b", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=LocalOptimizationAdjustment."), - TestStep("18", "Wait 10 seconds. Event DEM.S.E01(PowerAdjustEnd) sent with Cause=NormalCompletion, Duration=10s, EnergyUse= a valid value"), - TestStep("18a", "TH reads ESAState attribute. Verify value is 0x01 (Online)"), - TestStep("18b", "TH reads PowerAdjustmentCapability attribute. Value has to include Cause=NoAdjustment."), - TestStep("19", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Power Adjustment Test Event Clear"), + TestStep("1", "Commissioning, already done", + is_commissioning=True), + TestStep("2", "TH reads TestEventTriggersEnabled attribute from General Diagnostics Cluster.", + "Verify that TestEventTriggersEnabled attribute has a value of 1 (True)"), + TestStep("3", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Power Adjustment Test Event", + "Verify DUT responds with status SUCCESS(0x00)"), + TestStep("3a", "TH reads ESAState attribute.", + "Verify value is 0x01 (Online)"), + TestStep("3b", "TH reads PowerAdjustmentCapability attribute.", + "Value has to include Cause=NoAdjustment. Note value for later. Determine the OverallMaxPower and OverallMaxDuration as the largest MaxPower and MaxDuration of the PowerAdjustStructs returned, and similarly the OverallMinPower and OverallMinDuration as the smallest of the MinPower and MinDuration values."), + TestStep("3c", "TH reads OptOutState attribute.", + "Verify value is 0x00 (NoOptOut)"), + TestStep("4", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization.", + "Verify DUT responds with status SUCCESS(0x00) and Event DEM.S.E00(PowerAdjustStart) sent"), + TestStep("4a", "TH reads ESAState attribute.", + "Verify value is 0x04 (PowerAdjustActive)"), + TestStep("4b", "TH reads PowerAdjustmentCapability attribute.", + "Value has to include Cause=LocalOptimizationAdjustment."), + TestStep("5", "TH sends CancelPowerAdjustRequest.", + "Verify DUT responds with status SUCCESS(0x00) and Event DEM.S.E01(PowerAdjustEnd) sent with Cause=Cancelled"), + TestStep("5a", "TH reads PowerAdjustmentCapability attribute.", + "Value has to include Cause=NoAdjustment."), + TestStep("5b", "TH reads ESAState attribute.", + "Verify value is 0x01 (Online)"), + TestStep("6", "TH sends CancelPowerAdjustRequest.", + "Verify DUT responds with status INVALID_IN_STATE(0xcb)"), + TestStep("7", "TH sends PowerAdjustRequest with Power=OverallMaxPower+1 Duration=OverallMinDuration Cause=LocalOptimization.", + "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), + TestStep("8", "TH sends PowerAdjustRequest with Power=OverallMinPower Duration=OverallMaxDuration+1 Cause=LocalOptimization.", + "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), + TestStep("9", "TH sends PowerAdjustRequest with Power=OverallMinPower-1 Duration=OverallMaxDuration Cause=LocalOptimization.", + "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), + TestStep("10", "TH sends PowerAdjustRequest with Power=OverallMaxPower Duration=OverallMinDuration-1 Cause=LocalOptimization.", + "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), + TestStep("11", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization.", + "Verify DUT responds with status SUCCESS(0x00) and event DEM.S.E00(PowerAdjustStart) sent"), + TestStep("11a", "TH reads PowerAdjustmentCapability attribute.", + "Value has to include Cause=LocalOptimizationAdjustment."), + TestStep("12", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=GridOptimization.", + "Verify DUT responds with status SUCCESS(0x00) and no event sent"), + TestStep("12a", "TH reads ESAState attribute.", + "Verify value is 0x04 (PowerAdjustActive)"), + TestStep("12b", "TH reads PowerAdjustmentCapability attribute.", + "Value has to include Cause=GridOptimizationAdjustment."), + TestStep("13", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Local Optimization Test Event.", + "Verify DUT responds with status SUCCESS(0x00) and no event sent"), + TestStep("13a", "TH reads ESAState attribute.", + "Verify value is 0x04 (PowerAdjustActive)"), + TestStep("13b", "TH reads OptOutState attribute.", + "Verify value is 0x02 (LocalOptOut)"), + TestStep("14", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization.", + "Verify DUT responds with status CONSTRAINT_ERROR(0x87)"), + TestStep("15", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Grid Optimization Test Event.", + "Verify DUT responds with status SUCCESS(0x00) and event DEM.S.E01(PowerAdjustEnd) sent with Cause=UserOptOut, Duration= approx time from step 11 to step 15, EnergyUse= a valid value"), + TestStep("15a", "TH reads ESAState attribute.", + "Verify value is 0x01 (Online)"), + TestStep("15b", "TH reads OptOutState attribute.", + "Verify value is 0x03 (OptOut)"), + TestStep("15c", "TH reads PowerAdjustmentCapability attribute.", + "Value has to include Cause=NoAdjustment."), + TestStep("16", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for User Opt-out Test Event Clear", + "Verify DUT responds with status SUCCESS(0x00)"), + TestStep("16a", "TH reads ESAState attribute.", + "Verify value is 0x01 (Online)"), + TestStep("16b", "TH reads OptOutState attribute.", + "Verify value is 0x00 (NoOptOut)"), + TestStep("17", "TH sends PowerAdjustRequest with Power=PowerAdjustmentCapability[0].MaxPower, Duration=PowerAdjustmentCapability[0].MinDuration, Cause=LocalOptimization.", + "Verify DUT responds with status SUCCESS(0x00) and event DEM.S.E00(PowerAdjustStart) sent"), + TestStep("17a", "TH reads ESAState attribute.", + "Verify value is 0x04 (PowerAdjustActive)"), + TestStep("17b", "TH reads PowerAdjustmentCapability attribute.", + "Value has to include Cause=LocalOptimizationAdjustment."), + TestStep("18", "Wait 10 seconds.", + "Event DEM.S.E01(PowerAdjustEnd) sent with Cause=NormalCompletion, Duration=10s, EnergyUse= a valid value"), + TestStep("18a", "TH reads ESAState attribute.", + "Verify value is 0x01 (Online)"), + TestStep("18b", "TH reads PowerAdjustmentCapability attribute.", + "Value has to include Cause=NoAdjustment."), + TestStep("19", "TH sends TestEventTrigger command to General Diagnostics Cluster on Endpoint 0 with EnableKey field set to PIXIT.DEM.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to PIXIT.DEM.TEST_EVENT_TRIGGER for Power Adjustment Test Event Clear", + "Verify DUT responds with status SUCCESS(0x00)"), ] return steps @@ -101,11 +149,6 @@ def steps_TC_DEM_2_2(self) -> list[TestStep]: async def test_TC_DEM_2_2(self): # pylint: disable=too-many-locals, too-many-statements """Run the test steps.""" - # These values have to correlate with the values configured in - # DeviceEnergyManagementManufacturerImpl::SetTestEventTrigger_PowerAdjustment() - min_power = 5 * 1000 * 1000 - max_power = 30 * 1000 * 1000 - min_duration = 10 max_duration = 60 @@ -135,25 +178,20 @@ async def test_TC_DEM_2_2(self): Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kNoAdjustment) # we should expect powerAdjustCapabilityStruct to have multiple entries with different max powers, min powers, max and min durations - found_min_power = sys.maxsize - found_max_power = 0 - found_min_duration = sys.maxsize - found_max_duration = 0 + min_power = sys.maxsize + max_power = 0 + min_duration = sys.maxsize + max_duration = 0 for entry in powerAdjustCapabilityStruct.powerAdjustCapability: - found_min_power = min(found_min_power, entry.minPower) - found_max_power = max(found_max_power, entry.maxPower) - found_min_duration = min(found_min_duration, entry.minDuration) - found_max_duration = max(found_max_duration, entry.maxDuration) + min_power = min(min_power, entry.minPower) + max_power = max(max_power, entry.maxPower) + min_duration = min(min_duration, entry.minDuration) + max_duration = max(max_duration, entry.maxDuration) - result = f"found_min_power {found_min_power} found_max_power {found_max_power} found_min_duration {found_min_duration} found_max_duration {found_max_duration}" + result = f"min_power {min_power} max_power {max_power} min_duration {min_duration} max_duration {max_duration}" logging.info(result) - asserts.assert_equal(found_min_power, min_power) - asserts.assert_equal(found_max_power, max_power) - asserts.assert_equal(found_min_duration, min_duration) - asserts.assert_equal(found_max_duration, max_duration) - self.step("3c") await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) @@ -216,7 +254,7 @@ async def test_TC_DEM_2_2(self): self.step("11") start = datetime.datetime.now() - await self.send_power_adjustment_command(power=max_power, + await self.send_power_adjustment_command(power=powerAdjustCapabilityStruct.powerAdjustCapability[0].maxPower, duration=min_duration, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization) @@ -229,7 +267,7 @@ async def test_TC_DEM_2_2(self): Clusters.DeviceEnergyManagement.Enums.PowerAdjustReasonEnum.kLocalOptimizationAdjustment) self.step("12") - await self.send_power_adjustment_command(power=max_power, + await self.send_power_adjustment_command(power=powerAdjustCapabilityStruct.powerAdjustCapability[0].maxPower, duration=min_duration, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kGridOptimization) @@ -265,12 +303,10 @@ async def test_TC_DEM_2_2(self): event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.PowerAdjustEnd) asserts.assert_equal(event_data.cause, Clusters.DeviceEnergyManagement.Enums.CauseEnum.kUserOptOut) + # Allow 3s error margin as the CI build system can run out of CPU time elapsed = datetime.datetime.now() - start - asserts.assert_less_equal(abs(elapsed.seconds - event_data.duration), 1) - - # TODO: Do a better check on valid energyUse value. - # Value returned here is defined in DeviceEnergyManagementManufacturerImpl::GetEnergyUse() - asserts.assert_greater_equal(event_data.energyUse, 300) + asserts.assert_less_equal(abs(elapsed.seconds - event_data.duration), 3) + asserts.assert_greater_equal(event_data.energyUse, 0) self.step("15a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) @@ -293,10 +329,11 @@ async def test_TC_DEM_2_2(self): await self.check_dem_attribute("OptOutState", Clusters.DeviceEnergyManagement.Enums.OptOutStateEnum.kNoOptOut) self.step("17") - await self.send_power_adjustment_command(power=max_power, - duration=min_duration, + await self.send_power_adjustment_command(power=powerAdjustCapabilityStruct.powerAdjustCapability[0].maxPower, + duration=powerAdjustCapabilityStruct.powerAdjustCapability[0].minDuration, cause=Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum.kLocalOptimization, expected_status=Status.Success) + event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.PowerAdjustStart) self.step("17a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kPowerAdjustActive) @@ -309,6 +346,11 @@ async def test_TC_DEM_2_2(self): self.step("18") time.sleep(10) + event_data = events_callback.wait_for_event_report(Clusters.DeviceEnergyManagement.Events.PowerAdjustEnd) + asserts.assert_equal(event_data.duration, 10) + asserts.assert_equal(event_data.cause, Clusters.DeviceEnergyManagement.Enums.CauseEnum.kNormalCompletion) + asserts.assert_greater(event_data.energyUse, 0) + self.step("18a") await self.check_dem_attribute("ESAState", Clusters.DeviceEnergyManagement.Enums.ESAStateEnum.kOnline) From 441d5869d2a6354201808b8961fa674ec95b7bf3 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 18 Jul 2024 10:26:41 +0100 Subject: [PATCH 39/74] Sync up with code review comments from PR34234 that caused some return codes to change --- .../src/DeviceEnergyManagementDelegateImpl.cpp | 2 +- .../device-energy-management-server.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) 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 a689f6a8651bbb..60fece3941c8f9 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -635,7 +635,7 @@ Status DeviceEnergyManagementDelegate::ModifyForecastRequest( } else if (mForecast.Value().forecastID != forecastID) { - status = Status::ConstraintError; + status = Status::Failure; } else if (mpDEMManufacturerDelegate != nullptr) { 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 5e5c56e163504a..b24c360525b1af 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 @@ -581,7 +581,7 @@ void Instance::HandlePauseRequest(HandlerContext & ctx, const Commands::PauseReq if (!forecast.Value().slots[activeSlotNumber].slotIsPausable.Value()) { ChipLogError(Zcl, "DEM: activeSlotNumber %d is NOT pausable.", activeSlotNumber); - ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::ConstraintError); + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::Failure); return; } @@ -726,6 +726,7 @@ void Instance::HandleModifyForecastRequest(HandlerContext & ctx, const Commands: if (status != Status::Success) { ChipLogError(Zcl, "DEM: ModifyForecastRequest FAILURE"); + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::Failure); return; } } From c984a59e3d79ea5bba21e1b5cbe594e7f6a77d9c Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 18 Jul 2024 14:09:30 +0000 Subject: [PATCH 40/74] Restyled by clang-format --- .../include/DeviceEnergyManagementDelegateImpl.h | 6 ++++-- .../src/DeviceEnergyManagementDelegateImpl.cpp | 4 ++-- .../device-energy-management-server.h | 12 ++++++------ 3 files changed, 12 insertions(+), 10 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 26563a653f0cfc..1478286e47c71d 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -54,7 +54,8 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::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 chip::Protocols::InteractionModel::Status PowerAdjustRequest(const int64_t powerMw, const uint32_t durationS, AdjustmentCauseEnum cause) override; + virtual chip::Protocols::InteractionModel::Status PowerAdjustRequest(const int64_t powerMw, const uint32_t durationS, + AdjustmentCauseEnum cause) override; /** * @brief Make the ESA end the active power adjustment session & return to normal (or idle) power levels. @@ -80,7 +81,8 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate * @return Success if the StartTime in the Forecast is updated, otherwise the command SHALL be rejected with appropriate * IM_Status. */ - virtual chip::Protocols::InteractionModel::Status StartTimeAdjustRequest(const uint32_t requestedStartTimeUtc, AdjustmentCauseEnum cause) override; + virtual chip::Protocols::InteractionModel::Status StartTimeAdjustRequest(const uint32_t requestedStartTimeUtc, + AdjustmentCauseEnum cause) override; /** * @brief Handler for PauseRequest command 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 60fece3941c8f9..a1ee51f8131e8a 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -30,7 +30,6 @@ using namespace chip::app::Clusters::DeviceEnergyManagement::Attributes; using chip::Protocols::InteractionModel::Status; - using chip::Optional; using CostsList = DataModel::List; @@ -782,7 +781,8 @@ int64_t DeviceEnergyManagementDelegate::GetAbsMaxPower() return mAbsMaxPowerMw; } -const DataModel::Nullable & DeviceEnergyManagementDelegate::GetPowerAdjustmentCapability() +const DataModel::Nullable & +DeviceEnergyManagementDelegate::GetPowerAdjustmentCapability() { return mPowerAdjustCapabilityStruct; } 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 bf01f28bd8b84d..dee7ba144d5bd3 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 @@ -160,12 +160,12 @@ class Delegate // ------------------------------------------------------------------ // Get attribute methods - virtual ESATypeEnum GetESAType() = 0; - virtual bool GetESACanGenerate() = 0; - virtual ESAStateEnum GetESAState() = 0; - virtual int64_t GetAbsMinPower() = 0; - virtual int64_t GetAbsMaxPower() = 0; - virtual OptOutStateEnum GetOptOutState() = 0; + virtual ESATypeEnum GetESAType() = 0; + virtual bool GetESACanGenerate() = 0; + virtual ESAStateEnum GetESAState() = 0; + virtual int64_t GetAbsMinPower() = 0; + virtual int64_t GetAbsMaxPower() = 0; + virtual OptOutStateEnum GetOptOutState() = 0; /** * @brief Returns the current PowerAdjustCapability object From b52bc59e48aa1d736046c2aea8b1fc23ad9fa752 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 18 Jul 2024 16:47:04 +0100 Subject: [PATCH 41/74] modifyForecastRequest: Failure should be returned if a slot number > num slots in a forecast --- .../device-energy-management-server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b24c360525b1af..07dff8b7ffb67c 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 @@ -678,7 +678,7 @@ void Instance::HandleModifyForecastRequest(HandlerContext & ctx, const Commands: if (slotAdjustment.slotIndex > forecast.Value().slots.size()) { ChipLogError(Zcl, "DEM: Bad slot index %d", slotAdjustment.slotIndex); - ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::ConstraintError); + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::Failure); return; } From 0c482488c01c69188a1d6270ffe3fcdf4c4acc33 Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:24:35 +0100 Subject: [PATCH 42/74] Update examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h Co-authored-by: Boris Zbarsky --- .../include/DeviceEnergyManagementDelegateImpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1478286e47c71d..f847e2b3f38780 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2023-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); From 5f9896e0c2273acd70a84444b727c35b8f19d42e Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:26:39 +0100 Subject: [PATCH 43/74] Update examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h Co-authored-by: Boris Zbarsky --- .../include/DeviceEnergyManagementManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h index cbb44f99bf845a..b7ae4565656ff3 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementManager.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2023-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); From 178b5a643273060fe2f02832f02ce0b7b465dc7f Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:27:11 +0100 Subject: [PATCH 44/74] Update examples/energy-management-app/energy-management-common/include/EVSECallbacks.h Co-authored-by: Boris Zbarsky --- .../energy-management-common/include/EVSECallbacks.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/energy-management-app/energy-management-common/include/EVSECallbacks.h b/examples/energy-management-app/energy-management-common/include/EVSECallbacks.h index d5681d7b60321f..4cbee2a6b7ca9f 100644 --- a/examples/energy-management-app/energy-management-common/include/EVSECallbacks.h +++ b/examples/energy-management-app/energy-management-common/include/EVSECallbacks.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2023-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); From d2369feaa0f36bf42e1544e38c2c7b3dda24bbe3 Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:27:32 +0100 Subject: [PATCH 45/74] Update examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h Co-authored-by: Boris Zbarsky --- .../energy-management-common/include/EVSEManufacturerImpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h b/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h index 8e8253e293c869..2faf81046cfdf2 100644 --- a/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h +++ b/examples/energy-management-app/energy-management-common/include/EVSEManufacturerImpl.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2023-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); From 27fef246c9ff5b2925d9a70b7847b43cf5a30372 Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:27:54 +0100 Subject: [PATCH 46/74] Update examples/energy-management-app/energy-management-common/include/EnergyEvseDelegateImpl.h Co-authored-by: Boris Zbarsky --- .../energy-management-common/include/EnergyEvseDelegateImpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/energy-management-app/energy-management-common/include/EnergyEvseDelegateImpl.h b/examples/energy-management-app/energy-management-common/include/EnergyEvseDelegateImpl.h index 39cbc8d385e08f..aed42fa857968a 100644 --- a/examples/energy-management-app/energy-management-common/include/EnergyEvseDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/EnergyEvseDelegateImpl.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2023-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); From 2ed990b7e80173166f36e3a0ac71f61a8fd1c2ad Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:32:13 +0100 Subject: [PATCH 47/74] Update examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp Co-authored-by: Boris Zbarsky --- .../energy-management-common/src/DEMTestEventTriggers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp index 6571b07d1ee9a3..a2f9253d48fd91 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp @@ -77,7 +77,7 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots) sForecastStruct.isPausable = true; - sForecastStruct.activeSlotNumber.SetNonNull(0); + sForecastStruct.activeSlotNumber.SetNonNull(0); sSlots[0].minDuration = 10; sSlots[0].maxDuration = 20; From 412b2e4deb778b2a8e15c3b9ec414e71ebbb2d59 Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:32:44 +0100 Subject: [PATCH 48/74] Update examples/energy-management-app/energy-management-common/include/EnergyEvseManager.h Co-authored-by: Boris Zbarsky --- .../energy-management-common/include/EnergyEvseManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/energy-management-app/energy-management-common/include/EnergyEvseManager.h b/examples/energy-management-app/energy-management-common/include/EnergyEvseManager.h index fc3562d3865ad7..f39b0c0c5dd34a 100644 --- a/examples/energy-management-app/energy-management-common/include/EnergyEvseManager.h +++ b/examples/energy-management-app/energy-management-common/include/EnergyEvseManager.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2023-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); From cb04ca14dc55f61436ef58e36a3dbcc78d24be14 Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:33:14 +0100 Subject: [PATCH 49/74] Update examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp Co-authored-by: Boris Zbarsky --- .../energy-management-common/src/DEMTestEventTriggers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp index a2f9253d48fd91..18b70f86f901f6 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp @@ -67,7 +67,7 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots) // earliest start time, in UTC, that the entire Forecast can be shifted to. null value indicates that it can be started // immediately. - sForecastStruct.earliestStartTime = Optional>{ DataModel::Nullable{ chipEpoch } }; + sForecastStruct.earliestStartTime = MakeOptional(DataModel::MakeNullable(chipEpoch)); // planned end time, in UTC, for the entire Forecast. sForecastStruct.endTime = static_cast(chipEpoch * 3); From 1db507af3ce2181e0495cdf8d7b1bc20eec9420b Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:33:47 +0100 Subject: [PATCH 50/74] Update examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp Co-authored-by: Boris Zbarsky --- .../energy-management-common/src/DEMTestEventTriggers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp index 18b70f86f901f6..91488c9ac662d4 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp @@ -73,7 +73,7 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots) sForecastStruct.endTime = static_cast(chipEpoch * 3); // latest end time, in UTC, for the entire Forecast - sForecastStruct.latestEndTime = Optional(static_cast(chipEpoch * 3)); + sForecastStruct.latestEndTime = MakeOptional(chipEpoch * 3); sForecastStruct.isPausable = true; From 083f324966344a3f7d6e479ad484218f58954fde Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 18 Jul 2024 17:55:39 +0100 Subject: [PATCH 51/74] Address review comments from Boris --- .../DeviceEnergyManagementDelegateImpl.h | 39 ++++++++++--------- .../include/EnergyTimeUtils.h | 4 +- .../include/FakeReadings.h | 4 +- .../src/DEMTestEventTriggers.cpp | 32 +++++---------- 4 files changed, 33 insertions(+), 46 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 f847e2b3f38780..0cd943df73bdf9 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -54,8 +54,8 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::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 chip::Protocols::InteractionModel::Status PowerAdjustRequest(const int64_t powerMw, const uint32_t durationS, - AdjustmentCauseEnum cause) override; + chip::Protocols::InteractionModel::Status PowerAdjustRequest(const int64_t powerMw, const uint32_t durationS, + AdjustmentCauseEnum cause) override; /** * @brief Make the ESA end the active power adjustment session & return to normal (or idle) power levels. @@ -63,7 +63,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate * * @return It should report SUCCESS if successful and FAILURE otherwise. */ - virtual chip::Protocols::InteractionModel::Status CancelPowerAdjustRequest() override; + chip::Protocols::InteractionModel::Status CancelPowerAdjustRequest() override; /** * @brief The ESA SHALL update its Forecast attribute with the RequestedStartTime including a new ForecastID. @@ -81,8 +81,8 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate * @return Success if the StartTime in the Forecast is updated, otherwise the command SHALL be rejected with appropriate * IM_Status. */ - virtual chip::Protocols::InteractionModel::Status StartTimeAdjustRequest(const uint32_t requestedStartTimeUtc, - AdjustmentCauseEnum cause) override; + chip::Protocols::InteractionModel::Status StartTimeAdjustRequest(const uint32_t requestedStartTimeUtc, + AdjustmentCauseEnum cause) override; /** * @brief Handler for PauseRequest command @@ -97,7 +97,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate * @param duration Duration that the ESA SHALL be paused for. * @return Success if the ESA is paused, otherwise returns other IM_Status. */ - virtual chip::Protocols::InteractionModel::Status PauseRequest(const uint32_t durationS, AdjustmentCauseEnum cause) override; + chip::Protocols::InteractionModel::Status PauseRequest(const uint32_t durationS, AdjustmentCauseEnum cause) override; /** * @brief Handler for ResumeRequest command @@ -108,7 +108,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate * * @return Success if the ESA is resumed, otherwise returns other IM_Status. */ - virtual chip::Protocols::InteractionModel::Status ResumeRequest() override; + chip::Protocols::InteractionModel::Status ResumeRequest() override; /** * @brief Handler for ModifyForecastRequest @@ -126,7 +126,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate * @return Success if the entire list of SlotAdjustmentStruct are accepted, otherwise the command * SHALL be rejected returning other IM_Status. */ - virtual chip::Protocols::InteractionModel::Status + chip::Protocols::InteractionModel::Status ModifyForecastRequest(const uint32_t forecastID, const DataModel::DecodableList & slotAdjustments, AdjustmentCauseEnum cause) override; @@ -142,7 +142,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::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 chip::Protocols::InteractionModel::Status + chip::Protocols::InteractionModel::Status RequestConstraintBasedForecast(const DataModel::DecodableList & constraints, AdjustmentCauseEnum cause) override; @@ -163,22 +163,23 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate * * @return Success if successful, otherwise the command SHALL be rejected returning other IM_Status. */ - virtual chip::Protocols::InteractionModel::Status CancelRequest() override; + chip::Protocols::InteractionModel::Status CancelRequest() override; // ------------------------------------------------------------------ // Overridden DeviceEnergyManagement::Delegate Get attribute methods - virtual ESATypeEnum GetESAType() override; - virtual bool GetESACanGenerate() override; - virtual ESAStateEnum GetESAState() override; - virtual int64_t GetAbsMinPower() override; - virtual int64_t GetAbsMaxPower() override; - virtual const DataModel::Nullable & GetPowerAdjustmentCapability() override; - virtual const DataModel::Nullable & GetForecast() override; - virtual OptOutStateEnum GetOptOutState() override; + + ESATypeEnum GetESAType() override; + bool GetESACanGenerate() override; + ESAStateEnum GetESAState() override; + int64_t GetAbsMinPower() override; + int64_t GetAbsMaxPower() override; + const DataModel::Nullable & GetPowerAdjustmentCapability() override; + const DataModel::Nullable & GetForecast() override; + OptOutStateEnum GetOptOutState() override; // ------------------------------------------------------------------ // Overridden DeviceEnergyManagement::Delegate Set attribute methods - virtual CHIP_ERROR SetESAState(ESAStateEnum) override; + CHIP_ERROR SetESAState(ESAStateEnum) override; // Local Set methods CHIP_ERROR SetESAType(ESATypeEnum); diff --git a/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h b/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h index 9c4ea1ec06b5f9..e15db6fc71f1e8 100644 --- a/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h +++ b/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h @@ -46,7 +46,7 @@ CHIP_ERROR GetEpochTS(uint32_t & chipEpoch); * @param unixEpoch (as time_t) * * @return bitmap value for day of week - * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) + * Sunday = 0x00, Monday = 0x01 ... Saturday = 0x40 (1<<6) */ uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch); @@ -55,7 +55,7 @@ uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch); * * @param reference to hold the day of week as a bitmap * - * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) + * Sunday = 0x00, Monday = 0x01 ... Saturday = 0x40 (1<<6) */ CHIP_ERROR GetLocalDayOfWeekNow(uint8_t & dayOfWeekMap); diff --git a/examples/energy-management-app/energy-management-common/include/FakeReadings.h b/examples/energy-management-app/energy-management-common/include/FakeReadings.h index cee09c8dc4d3d8..f8334ba2708b7e 100644 --- a/examples/energy-management-app/energy-management-common/include/FakeReadings.h +++ b/examples/energy-management-app/energy-management-common/include/FakeReadings.h @@ -42,11 +42,11 @@ class FakeReadings * @param[in] aCurrentRandomness_mA This is used to define the max randomness of the * random current values * @param[in] aInterval_s - the callback interval in seconds - * @param[in] bReset - boolean: true will reset the energy values to 0 + * @param[in] aReset - boolean: true will reset the energy values to 0 */ void StartFakeReadings(chip::EndpointId aEndpointId, int64_t aPower_mW, uint32_t aPowerRandomness_mW, int64_t aVoltage_mV, uint32_t aVoltageRandomness_mV, int64_t aCurrent_mA, uint32_t aCurrentRandomness_mA, uint8_t aInterval_s, - bool bReset); + bool aReset); /** * @brief Stops any active updates to the fake load data callbacks diff --git a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp index 91488c9ac662d4..abb72b2d05898b 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp @@ -63,14 +63,14 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots) } // planned start time, in UTC, for the entire Forecast. - sForecastStruct.startTime = static_cast(chipEpoch); + sForecastStruct.startTime = chipEpoch; // earliest start time, in UTC, that the entire Forecast can be shifted to. null value indicates that it can be started // immediately. sForecastStruct.earliestStartTime = MakeOptional(DataModel::MakeNullable(chipEpoch)); // planned end time, in UTC, for the entire Forecast. - sForecastStruct.endTime = static_cast(chipEpoch * 3); + sForecastStruct.endTime = chipEpoch * 3; // latest end time, in UTC, for the entire Forecast sForecastStruct.latestEndTime = MakeOptional(chipEpoch * 3); @@ -133,11 +133,8 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots) sForecastStruct.slots = DataModel::List(sSlots, numSlots); - DataModel::Nullable forecast(sForecastStruct); - EVSEManufacturer * mn = GetEvseManufacturer(); - mn->GetDEMDelegate()->SetForecast(forecast); - + mn->GetDEMDelegate()->SetForecast(DataModel::MakeNullable(sForecastStruct)); mn->GetDEMDelegate()->SetAbsMinPower(1000); mn->GetDEMDelegate()->SetAbsMaxPower(256 * 2000 * 1000); @@ -216,9 +213,7 @@ void SetTestEventTrigger_StartTimeAdjustment() // Latest end time, in UTC, for the entire Forecast which is > sForecastStruct.endTime sForecastStruct.latestEndTime = Optional(static_cast(chipEpoch * 3 + 60)); - DataModel::Nullable forecast(sForecastStruct); - - GetDEMDelegate()->SetForecast(forecast); + GetDEMDelegate()->SetForecast(DataModel::MakeNullable(sForecastStruct)); } void SetTestEventTrigger_StartTimeAdjustmentClear() @@ -232,9 +227,7 @@ void SetTestEventTrigger_StartTimeAdjustmentClear() sForecastStruct.earliestStartTime = Optional>(); sForecastStruct.latestEndTime = Optional(); - DataModel::Nullable forecast(sForecastStruct); - - GetDEMDelegate()->SetForecast(forecast); + GetDEMDelegate()->SetForecast(DataModel::MakeNullable(sForecastStruct)); } void SetTestEventTrigger_UserOptOutOptimization(OptOutStateEnum optOutState) @@ -253,9 +246,7 @@ void SetTestEventTrigger_PausableNextSlot() sForecastStruct = GetDEMDelegate()->GetForecast().Value(); sForecastStruct.activeSlotNumber.SetNonNull(1); - DataModel::Nullable forecast(sForecastStruct); - - GetDEMDelegate()->SetForecast(forecast); + GetDEMDelegate()->SetForecast(DataModel::MakeNullable(sForecastStruct)); } void SetTestEventTrigger_Forecast() @@ -273,9 +264,7 @@ void SetTestEventTrigger_ForecastClear() sForecastStruct.activeSlotNumber.SetNull(); sForecastStruct.slots = DataModel::List(); - DataModel::Nullable forecast(sForecastStruct); - - GetDEMDelegate()->SetForecast(forecast); + GetDEMDelegate()->SetForecast(DataModel::MakeNullable(sForecastStruct)); } void SetTestEventTrigger_ForecastAdjustment() @@ -291,18 +280,15 @@ void SetTestEventTrigger_ForecastAdjustment() sForecastStruct.slots = DataModel::List(sSlots, 2); - DataModel::Nullable forecast(sForecastStruct); - - GetDEMDelegate()->SetForecast(forecast); + GetDEMDelegate()->SetForecast(DataModel::MakeNullable(sForecastStruct)); } void SetTestEventTrigger_ForecastAdjustmentNextSlot() { sForecastStruct = GetDEMDelegate()->GetForecast().Value(); sForecastStruct.activeSlotNumber.SetNonNull(sForecastStruct.activeSlotNumber.Value() + 1); - DataModel::Nullable forecast(sForecastStruct); - GetDEMDelegate()->SetForecast(forecast); + GetDEMDelegate()->SetForecast(DataModel::MakeNullable(sForecastStruct)); } void SetTestEventTrigger_ConstraintBasedAdjustment() From 979353fcb354bb8acea3855878b4c680fc5e2031 Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 18:04:05 +0100 Subject: [PATCH 52/74] Update examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp Co-authored-by: Boris Zbarsky --- .../src/DeviceEnergyManagementDelegateImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a1ee51f8131e8a..f1839bd80cb24a 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2023-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); From 3e56098b67f109ccfd89af1cb5513e7b89573d97 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 18 Jul 2024 18:05:46 +0100 Subject: [PATCH 53/74] Address further review comments from Boris --- .../src/DEMTestEventTriggers.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp index abb72b2d05898b..1bcf11209436f6 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp @@ -152,9 +152,6 @@ void SetTestEventTrigger_PowerAdjustment() sPowerAdjustCapabilityStruct.cause = PowerAdjustReasonEnum::kNoAdjustment; sPowerAdjustCapabilityStruct.powerAdjustCapability.SetNonNull(powerAdjustmentList); - - DataModel::Nullable powerAdjustmentCapability( - sPowerAdjustCapabilityStruct); sPowerAdjustmentCapability.SetNonNull(sPowerAdjustCapabilityStruct); CHIP_ERROR err = GetDEMDelegate()->SetPowerAdjustmentCapability(sPowerAdjustmentCapability); @@ -202,16 +199,16 @@ void SetTestEventTrigger_StartTimeAdjustment() } // planned start time, in UTC, for the entire Forecast. - sForecastStruct.startTime = static_cast(chipEpoch); + sForecastStruct.startTime = chipEpoch; // Set the earliest start time, in UTC, to that before the startTime sForecastStruct.earliestStartTime = Optional>{ DataModel::Nullable{ chipEpoch - 60 } }; // Planned end time, in UTC, for the entire Forecast. - sForecastStruct.endTime = static_cast(chipEpoch * 3); + sForecastStruct.endTime = chipEpoch * 3; // Latest end time, in UTC, for the entire Forecast which is > sForecastStruct.endTime - sForecastStruct.latestEndTime = Optional(static_cast(chipEpoch * 3 + 60)); + sForecastStruct.latestEndTime = Optional(chipEpoch * 3 + 60); GetDEMDelegate()->SetForecast(DataModel::MakeNullable(sForecastStruct)); } From df78a953b57740cbb29b3380e3a6218f2cd02b2b Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 18 Jul 2024 18:14:31 +0100 Subject: [PATCH 54/74] Address further review comments from Boris --- .../DeviceEnergyManagementDelegateImpl.h | 4 +-- .../DeviceEnergyManagementDelegateImpl.cpp | 32 +++++++++---------- 2 files changed, 18 insertions(+), 18 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 0cd943df73bdf9..345e9b2172485d 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -241,7 +241,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate void HandlePowerAdjustTimerExpiry(); // Method to cancel a PowerAdjustment - CHIP_ERROR CancelPowerAdjustRequestAndSendEvent(CauseEnum cause); + CHIP_ERROR CancelPowerAdjustRequestAndGenerateEvent(CauseEnum cause); // Method to send a PowerAdjustEnd event CHIP_ERROR SendPowerAdjustEndEvent(CauseEnum cause); @@ -258,7 +258,7 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate void HandlePauseRequestTimerExpiry(); // Method to cancel a PauseRequest - CHIP_ERROR CancelPauseRequestAndSendEvent(CauseEnum cause); + CHIP_ERROR CancelPauseRequestAndGenerateEvent(CauseEnum cause); // Method to send a Paused event CHIP_ERROR SendResumedEvent(CauseEnum cause); 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 f1839bd80cb24a..28abf6eb7c7011 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -82,7 +82,7 @@ void DeviceEnergyManagementDelegate::SetDEMManufacturerDelegate( Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t powerMw, const uint32_t durationS, AdjustmentCauseEnum cause) { - bool sendEvent = false; + bool generateEvent = false; // If a timer is running, cancel it so we can start it with the new duration if (mPowerAdjustmentInProgress) @@ -92,7 +92,7 @@ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t powerMw, else { // Going to start a new power adjustment so will need to send an event - sendEvent = true; + generateEvent = true; // Record when this PowerAdjustment starts. Note if we do not set this value if a PowerAdjustment is in progress CHIP_ERROR err = GetEpochTS(mPowerAdjustmentStartTimeUtc); @@ -143,7 +143,7 @@ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t powerMw, return Status::Failure; } - if (sendEvent) + if (generateEvent) { Events::PowerAdjustStart::Type event; EventNumber eventNumber; @@ -151,7 +151,7 @@ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t powerMw, if (CHIP_NO_ERROR != err) { // TODO: Note: should the PowerAdjust just initiated be cancelled because an Event could not be logged? - ChipLogError(AppServer, "Unable to send notify PowerAdjustStart event: %" CHIP_ERROR_FORMAT, err.Format()); + ChipLogError(AppServer, "Unable to generate PowerAdjustStart event: %" CHIP_ERROR_FORMAT, err.Format()); HandlePowerAdjustRequestFailure(); return Status::Failure; } @@ -236,7 +236,7 @@ Status DeviceEnergyManagementDelegate::CancelPowerAdjustRequest() { Status status = Status::Success; - CHIP_ERROR err = CancelPowerAdjustRequestAndSendEvent(DeviceEnergyManagement::CauseEnum::kCancelled); + CHIP_ERROR err = CancelPowerAdjustRequestAndGenerateEvent(DeviceEnergyManagement::CauseEnum::kCancelled); if (CHIP_NO_ERROR != err) { status = Status::Failure; @@ -255,7 +255,7 @@ Status DeviceEnergyManagementDelegate::CancelPowerAdjustRequest() * 2) generate a PowerAdjustEnd event with cause code Cancelled * 3) if necessary, update the forecast with new expected end time */ -CHIP_ERROR DeviceEnergyManagementDelegate::CancelPowerAdjustRequestAndSendEvent(CauseEnum cause) +CHIP_ERROR DeviceEnergyManagementDelegate::CancelPowerAdjustRequestAndGenerateEvent(CauseEnum cause) { DeviceLayer::SystemLayer().CancelTimer(PowerAdjustTimerExpiry, this); @@ -312,7 +312,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SendPowerAdjustEndEvent(CauseEnum cau err = LogEvent(event, mEndpointId, eventNumber); if (CHIP_NO_ERROR != err) { - ChipLogError(AppServer, "Unable to send notify PowerAdjustEnd event: %" CHIP_ERROR_FORMAT, err.Format()); + ChipLogError(AppServer, "Unable to generate PowerAdjustEnd event: %" CHIP_ERROR_FORMAT, err.Format()); return err; } @@ -401,7 +401,7 @@ Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t req */ Status DeviceEnergyManagementDelegate::PauseRequest(const uint32_t durationS, AdjustmentCauseEnum cause) { - bool sendEvent = false; + bool generateEvent = false; // If a timer is running, cancel it so we can start it with the new duration if (mPauseRequestInProgress) @@ -410,7 +410,7 @@ Status DeviceEnergyManagementDelegate::PauseRequest(const uint32_t durationS, Ad } else { - sendEvent = true; + generateEvent = true; // Remember we have a timer running so we don't send a Paused event should another request come // in before this timer expires @@ -436,14 +436,14 @@ Status DeviceEnergyManagementDelegate::PauseRequest(const uint32_t durationS, Ad } } - if (sendEvent) + if (generateEvent) { Events::Paused::Type event; EventNumber eventNumber; err = LogEvent(event, mEndpointId, eventNumber); if (CHIP_NO_ERROR != err) { - ChipLogError(AppServer, "Unable to send notify Paused event: %" CHIP_ERROR_FORMAT, err.Format()); + ChipLogError(AppServer, "Unable to generate Paused event: %" CHIP_ERROR_FORMAT, err.Format()); HandlePauseRequestFailure(); return Status::Failure; } @@ -528,7 +528,7 @@ void DeviceEnergyManagementDelegate::HandlePauseRequestTimerExpiry() * 2) generate a PowerAdjustEnd event with cause code Cancelled * 3) if necessary, update the forecast with new expected end time */ -CHIP_ERROR DeviceEnergyManagementDelegate::CancelPauseRequestAndSendEvent(CauseEnum cause) +CHIP_ERROR DeviceEnergyManagementDelegate::CancelPauseRequestAndGenerateEvent(CauseEnum cause) { mPauseRequestInProgress = false; @@ -573,7 +573,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SendResumedEvent(CauseEnum cause) CHIP_ERROR err = LogEvent(event, mEndpointId, eventNumber); if (CHIP_NO_ERROR != err) { - ChipLogError(AppServer, "Unable to send notify Resumed event: %" CHIP_ERROR_FORMAT, err.Format()); + ChipLogError(AppServer, "Unable to generate Resumed event: %" CHIP_ERROR_FORMAT, err.Format()); } return err; @@ -598,7 +598,7 @@ Status DeviceEnergyManagementDelegate::ResumeRequest() if (mPauseRequestInProgress) { - CHIP_ERROR err = CancelPauseRequestAndSendEvent(CauseEnum::kCancelled); + CHIP_ERROR err = CancelPauseRequestAndGenerateEvent(CauseEnum::kCancelled); if (err == CHIP_NO_ERROR) { status = Status::Success; @@ -947,7 +947,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal mPowerAdjustCapabilityStruct.Value().cause == PowerAdjustReasonEnum::kGridOptimizationAdjustment) || newValue == OptOutStateEnum::kOptOut) { - err = CancelPowerAdjustRequestAndSendEvent(DeviceEnergyManagement::CauseEnum::kUserOptOut); + err = CancelPowerAdjustRequestAndGenerateEvent(DeviceEnergyManagement::CauseEnum::kUserOptOut); } } @@ -961,7 +961,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal mForecast.Value().forecastUpdateReason == ForecastUpdateReasonEnum::kGridOptimization) || newValue == OptOutStateEnum::kOptOut) { - err = CancelPauseRequestAndSendEvent(DeviceEnergyManagement::CauseEnum::kUserOptOut); + err = CancelPauseRequestAndGenerateEvent(DeviceEnergyManagement::CauseEnum::kUserOptOut); } } From be69ceba58e7e433de64b2f51db785204fb56cf3 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 18 Jul 2024 18:26:50 +0100 Subject: [PATCH 55/74] Address further review comments from Boris --- .../DeviceEnergyManagementDelegateImpl.h | 8 ++--- .../DeviceEnergyManagementDelegateImpl.cpp | 30 +++++++++++-------- 2 files changed, 21 insertions(+), 17 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 345e9b2172485d..9f9989d7b03c92 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -243,8 +243,8 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate // Method to cancel a PowerAdjustment CHIP_ERROR CancelPowerAdjustRequestAndGenerateEvent(CauseEnum cause); - // Method to send a PowerAdjustEnd event - CHIP_ERROR SendPowerAdjustEndEvent(CauseEnum cause); + // Method to generate a PowerAdjustEnd event + CHIP_ERROR GeneratePowerAdjustEndEvent(CauseEnum cause); /** * @brief Handle a PauseRequest failing @@ -260,8 +260,8 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate // Method to cancel a PauseRequest CHIP_ERROR CancelPauseRequestAndGenerateEvent(CauseEnum cause); - // Method to send a Paused event - CHIP_ERROR SendResumedEvent(CauseEnum cause); + // Method to generate a Paused event + CHIP_ERROR GenerateResumedEvent(CauseEnum cause); private: // Have a pointer to partner instance object 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 28abf6eb7c7011..bc21dbb87a52b8 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -91,7 +91,7 @@ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t powerMw, } else { - // Going to start a new power adjustment so will need to send an event + // Going to start a new power adjustment so will need to generate an event generateEvent = true; // Record when this PowerAdjustment starts. Note if we do not set this value if a PowerAdjustment is in progress @@ -130,7 +130,7 @@ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t powerMw, return Status::Failure; } - // Remember we have a timer running so we don't send a PowerAdjustStart event should another request come + // Remember we have a timer running so we don't generate a PowerAdjustStart event should another request come // in before this timer expires mPowerAdjustmentInProgress = true; @@ -210,8 +210,8 @@ void DeviceEnergyManagementDelegate::HandlePowerAdjustTimerExpiry() mPowerAdjustCapabilityStruct.Value().cause = PowerAdjustReasonEnum::kNoAdjustment; - // Send a PowerAdjustEnd event - SendPowerAdjustEndEvent(CauseEnum::kNormalCompletion); + // Generate a PowerAdjustEnd event + GeneratePowerAdjustEndEvent(CauseEnum::kNormalCompletion); // Update the forecast with new expected end time if (mpDEMManufacturerDelegate != nullptr) @@ -265,7 +265,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::CancelPowerAdjustRequestAndGenerateEv mPowerAdjustCapabilityStruct.Value().cause = PowerAdjustReasonEnum::kNoAdjustment; - CHIP_ERROR err = SendPowerAdjustEndEvent(cause); + CHIP_ERROR err = GeneratePowerAdjustEndEvent(cause); // Notify the appliance's that it can resume its intended power setting (or go idle) if (mpDEMManufacturerDelegate != nullptr) @@ -279,10 +279,10 @@ CHIP_ERROR DeviceEnergyManagementDelegate::CancelPowerAdjustRequestAndGenerateEv } /** - * @brief Send a PowerAdjustEvent + * @brief Generate a PowerAdjustEvent * */ -CHIP_ERROR DeviceEnergyManagementDelegate::SendPowerAdjustEndEvent(CauseEnum cause) +CHIP_ERROR DeviceEnergyManagementDelegate::GeneratePowerAdjustEndEvent(CauseEnum cause) { Events::PowerAdjustEnd::Type event; EventNumber eventNumber; @@ -412,7 +412,7 @@ Status DeviceEnergyManagementDelegate::PauseRequest(const uint32_t durationS, Ad { generateEvent = true; - // Remember we have a timer running so we don't send a Paused event should another request come + // Remember we have a timer running so we don't generate a Paused event should another request come // in before this timer expires mPauseRequestInProgress = true; } @@ -508,8 +508,8 @@ void DeviceEnergyManagementDelegate::HandlePauseRequestTimerExpiry() SetESAState(ESAStateEnum::kOnline); - // Send a Resumed event - SendResumedEvent(CauseEnum::kNormalCompletion); + // Generate a Resumed event + GenerateResumedEvent(CauseEnum::kNormalCompletion); // It is expected the mpDEMManufacturerDelegate will update the forecast with new expected end time if (mpDEMManufacturerDelegate != nullptr) @@ -536,7 +536,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::CancelPauseRequestAndGenerateEvent(Ca DeviceLayer::SystemLayer().CancelTimer(PauseRequestTimerExpiry, this); - CHIP_ERROR err = SendResumedEvent(cause); + CHIP_ERROR err = GenerateResumedEvent(cause); CHIP_ERROR err2 = CHIP_NO_ERROR; // Notify the appliance's that it can resume its intended power setting (or go idle) @@ -561,10 +561,10 @@ CHIP_ERROR DeviceEnergyManagementDelegate::CancelPauseRequestAndGenerateEvent(Ca } /** - * @brief Send a Resumed event + * @brief Generate a Resumed event * */ -CHIP_ERROR DeviceEnergyManagementDelegate::SendResumedEvent(CauseEnum cause) +CHIP_ERROR DeviceEnergyManagementDelegate::GenerateResumedEvent(CauseEnum cause) { Events::Resumed::Type event; EventNumber eventNumber; @@ -887,6 +887,8 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetPowerAdjustmentCapability( const DataModel::Nullable & powerAdjustCapabilityStruct) { + assertChipStackLockedByCurrentThread(); + if (powerAdjustCapabilityStruct.IsNull()) { mPowerAdjustCapabilityStruct.SetNull(); @@ -901,6 +903,8 @@ DeviceEnergyManagementDelegate::SetPowerAdjustmentCapability( CHIP_ERROR DeviceEnergyManagementDelegate::SetForecast(const DataModel::Nullable & forecast) { + assertChipStackLockedByCurrentThread(); + // TODO see Issue #31147 if (forecast.IsNull()) { From 3c577186b3c18f441e12bac967b6d56047944dc3 Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 18:36:04 +0100 Subject: [PATCH 56/74] Update examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp Co-authored-by: Boris Zbarsky --- .../src/DeviceEnergyManagementManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp index 49c1086fdeae8e..12f754a53ff804 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2023-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); From b8d55ce854f5187d950e08bce9e78365212dc14d Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 18 Jul 2024 18:36:37 +0100 Subject: [PATCH 57/74] Address further review comments from Boris --- .../DeviceEnergyManagementDelegateImpl.cpp | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) 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 bc21dbb87a52b8..aa1f1c1cf73bf9 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -889,14 +889,9 @@ DeviceEnergyManagementDelegate::SetPowerAdjustmentCapability( { assertChipStackLockedByCurrentThread(); - if (powerAdjustCapabilityStruct.IsNull()) - { - mPowerAdjustCapabilityStruct.SetNull(); - } - else - { - mPowerAdjustCapabilityStruct = powerAdjustCapabilityStruct; - } + mPowerAdjustCapabilityStruct = powerAdjustCapabilityStruct; + + MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, PowerAdjustmentCapability::Id); return CHIP_NO_ERROR; } @@ -906,14 +901,9 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetForecast(const DataModel::Nullable assertChipStackLockedByCurrentThread(); // TODO see Issue #31147 - if (forecast.IsNull()) - { - mForecast.SetNull(); - } - else - { - mForecast = forecast; - } + mForecast = forecast; + + MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id); return CHIP_NO_ERROR; } From 7a9ded1da1b586a6d5d4fb5a6fcc9e88ec7177fb Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 21:58:18 +0100 Subject: [PATCH 58/74] Update examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp Co-authored-by: Boris Zbarsky --- .../energy-management-common/src/DEMTestEventTriggers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp index 1bcf11209436f6..0dd035ec157a2e 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp @@ -221,8 +221,8 @@ void SetTestEventTrigger_StartTimeAdjustmentClear() sForecastStruct.startTime = static_cast(0); sForecastStruct.endTime = static_cast(0); - sForecastStruct.earliestStartTime = Optional>(); - sForecastStruct.latestEndTime = Optional(); + sForecastStruct.earliestStartTime = NullOptional; + sForecastStruct.latestEndTime = NullOptional; GetDEMDelegate()->SetForecast(DataModel::MakeNullable(sForecastStruct)); } From 2001980479b8fdcf65156cfc1bf73b719b257b78 Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 21:58:54 +0100 Subject: [PATCH 59/74] Update examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp Co-authored-by: Boris Zbarsky --- .../energy-management-common/src/EnergyTimeUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp b/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp index 476764f3f72a7a..acd47e6ea6cf79 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp @@ -107,7 +107,7 @@ uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch) */ CHIP_ERROR GetLocalDayOfWeekNow(uint8_t & dayOfWeekMap) { - chip::System::Clock::Milliseconds64 cTMs; + System::Clock::Milliseconds64 cTMs; CHIP_ERROR err = chip::System::SystemClock().GetClock_RealTimeMS(cTMs); if (err != CHIP_NO_ERROR) { From 940f102ae17d540c5dc226038a9435e8c63cf399 Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 22:03:12 +0100 Subject: [PATCH 60/74] Update examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp Co-authored-by: Boris Zbarsky --- .../src/DeviceEnergyManagementDelegateImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 aa1f1c1cf73bf9..cda30b497d7eff 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -346,7 +346,7 @@ Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t req mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kGridOptimization; break; default: - ChipLogDetail(AppServer, "Bad cause %d", static_cast(cause)); + ChipLogDetail(AppServer, "Bad cause %d", to_underlying(cause)); return Status::Failure; break; } From 2cdc8946f5810387bac26c3e843f0596fb9b002c Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Thu, 18 Jul 2024 22:03:47 +0100 Subject: [PATCH 61/74] Update examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp Co-authored-by: Boris Zbarsky --- .../src/DeviceEnergyManagementDelegateImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 cda30b497d7eff..ca06c1f0c85162 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -927,7 +927,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal if (oldValue != newValue) { - ChipLogDetail(AppServer, "mOptOutState updated to %d mPowerAdjustmentInProgress %d", static_cast(mOptOutState), + ChipLogDetail(AppServer, "mOptOutState updated to %d mPowerAdjustmentInProgress %d", to_underlying(mOptOutState), mPowerAdjustmentInProgress); MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, OptOutState::Id); } From 1c5e33d9655d608309de05735f53c993d807a593 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Sat, 20 Jul 2024 07:22:43 +0100 Subject: [PATCH 62/74] Apply further review comments from Boris --- .../include/EnergyTimeUtils.h | 7 ++----- .../src/EVSEManufacturerImpl.cpp | 2 +- .../src/EnergyEvseDelegateImpl.cpp | 2 +- .../src/EnergyEvseManager.cpp | 2 +- .../energy-management-common/src/EnergyTimeUtils.cpp | 12 +++++------- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h b/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h index e15db6fc71f1e8..1e01dd09858c31 100644 --- a/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h +++ b/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h @@ -45,17 +45,14 @@ CHIP_ERROR GetEpochTS(uint32_t & chipEpoch); * * @param unixEpoch (as time_t) * - * @return bitmap value for day of week - * Sunday = 0x00, Monday = 0x01 ... Saturday = 0x40 (1<<6) + * @return bitmap value for day of week as defined by EnergyEvse::TargetDayOfWeekBitmap */ uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch); /** * @brief Helper function to get current timestamp and work out the day of week based on localtime * - * @param reference to hold the day of week as a bitmap - * - * Sunday = 0x00, Monday = 0x01 ... Saturday = 0x40 (1<<6) + * @param reference to hold the day of week as a bitmap as defined by EnergyEvse::TargetDayOfWeekBitmap */ CHIP_ERROR GetLocalDayOfWeekNow(uint8_t & dayOfWeekMap); diff --git a/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp b/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp index 2dc42860115726..9006477b3662d5 100644 --- a/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/EVSEManufacturerImpl.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2023-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp b/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp index 3d46b67863cf6a..b0cfd6fc5ce0ef 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2023-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp b/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp index 493a0720d5860b..c8b43342f8bd1c 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2024 Project CHIP Authors + * Copyright (c) 2023-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp b/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp index acd47e6ea6cf79..3ef89a0576651d 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp @@ -65,7 +65,7 @@ CHIP_ERROR GetEpochTS(uint32_t & chipEpoch) if (!UnixEpochToChipEpochTime(unixEpoch, chipEpoch)) { ChipLogError(Zcl, "Unable to convert Unix Epoch time to Matter Epoch Time"); - return err; + return CHIP_ERROR_INCORRECT_STATE; } return CHIP_NO_ERROR; @@ -80,8 +80,7 @@ CHIP_ERROR GetEpochTS(uint32_t & chipEpoch) * * @param unixEpoch (as time_t) * - * @return bitmap value for day of week - * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) + * @return bitmap value for day of week as defined by EnergyEvse::TargetDayOfWeekBitmap */ uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch) { @@ -93,7 +92,8 @@ uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch) // Get the day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday) uint8_t dayOfWeek = static_cast(local_time.tm_wday); - // Calculate the bitmap value based on the day of the week + // Calculate the bitmap value based on the day of the week. Note that the value in bitmap + // maps directly to the definition in EnergyEvse::TargetDayOfWeekBitmap. uint8_t bitmap = static_cast(1 << dayOfWeek); return bitmap; @@ -101,9 +101,7 @@ uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch) /** * @brief Helper function to get current timestamp and work out the day of week based on localtime * - * @param reference to hold the day of week as a bitmap - * - * Sunday = 0x01, Monday = 0x01 ... Saturday = 0x40 (1<<6) + * @param reference to hold the day of week as a bitmap as defined by EnergyEvse::TargetDayOfWeekBitmap */ CHIP_ERROR GetLocalDayOfWeekNow(uint8_t & dayOfWeekMap) { From 14beb82845c3f4fb0b4935902ac3b353501bf3df Mon Sep 17 00:00:00 2001 From: pcoleman Date: Sat, 20 Jul 2024 19:52:50 +0100 Subject: [PATCH 63/74] Used a bitmap rather than uint8_t and sync EnergyTimeUtils files from the EVSE_Add_Get_Set_Clear_Targets_Support branch --- .../include/EnergyTimeUtils.h | 20 ++++++++-- .../src/EnergyTimeUtils.cpp | 37 +++++++++++++++++-- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h b/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h index 1e01dd09858c31..5e882063ad7540 100644 --- a/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h +++ b/examples/energy-management-app/energy-management-common/include/EnergyTimeUtils.h @@ -18,9 +18,11 @@ #pragma once +#include #include #include #include +#include #include #include @@ -45,16 +47,26 @@ CHIP_ERROR GetEpochTS(uint32_t & chipEpoch); * * @param unixEpoch (as time_t) * - * @return bitmap value for day of week as defined by EnergyEvse::TargetDayOfWeekBitmap + * @return bitmap value for day of week as defined by EnergyEvse::TargetDayOfWeekBitmap. Note + * only one bit will be set for the day of the week. */ -uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch); +BitMask GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch); /** * @brief Helper function to get current timestamp and work out the day of week based on localtime * - * @param reference to hold the day of week as a bitmap as defined by EnergyEvse::TargetDayOfWeekBitmap + * @param reference to hold the day of week as a bitmap as defined by EnergyEvse::TargetDayOfWeekBitmap. + * Note only one bit will be set for the current day. */ -CHIP_ERROR GetLocalDayOfWeekNow(uint8_t & dayOfWeekMap); +CHIP_ERROR GetLocalDayOfWeekNow(BitMask & dayOfWeekMap); + +/** + * @brief Helper function to get current timestamp and work out the current number of minutes + * past midnight based on localtime + * + * @param reference to hold the number of minutes past midnight + */ +CHIP_ERROR GetMinutesPastMidnight(uint16_t & minutesPastMidnight); } // namespace DeviceEnergyManagement } // namespace Clusters diff --git a/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp b/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp index 3ef89a0576651d..eac29920e173ae 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp @@ -80,9 +80,10 @@ CHIP_ERROR GetEpochTS(uint32_t & chipEpoch) * * @param unixEpoch (as time_t) * - * @return bitmap value for day of week as defined by EnergyEvse::TargetDayOfWeekBitmap + * @return bitmap value for day of week as defined by EnergyEvse::TargetDayOfWeekBitmap. Note + * only one bit will be set for the day of the week. */ -uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch) +BitMask GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch) { // Define a timezone structure and initialize it to the local timezone // This will capture any daylight saving time changes @@ -101,9 +102,10 @@ uint8_t GetLocalDayOfWeekFromUnixEpoch(time_t unixEpoch) /** * @brief Helper function to get current timestamp and work out the day of week based on localtime * - * @param reference to hold the day of week as a bitmap as defined by EnergyEvse::TargetDayOfWeekBitmap + * @return bitmap value for day of week as defined by EnergyEvse::TargetDayOfWeekBitmap. Note + * only one bit will be set for the current day. */ -CHIP_ERROR GetLocalDayOfWeekNow(uint8_t & dayOfWeekMap) +CHIP_ERROR GetLocalDayOfWeekNow(BitMask & dayOfWeekMap) { System::Clock::Milliseconds64 cTMs; CHIP_ERROR err = chip::System::SystemClock().GetClock_RealTimeMS(cTMs); @@ -118,6 +120,33 @@ CHIP_ERROR GetLocalDayOfWeekNow(uint8_t & dayOfWeekMap) return CHIP_NO_ERROR; } +/** + * @brief Helper function to get current timestamp and work out the current number of minutes + * past midnight based on localtime + * + * @param reference to hold the number of minutes past midnight + */ +CHIP_ERROR GetMinutesPastMidnight(uint16_t & minutesPastMidnight) +{ + chip::System::Clock::Milliseconds64 cTMs; + CHIP_ERROR err = chip::System::SystemClock().GetClock_RealTimeMS(cTMs); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "EVSE: unable to get current time to check user schedules error=%" CHIP_ERROR_FORMAT, err.Format()); + return err; + } + time_t unixEpoch = std::chrono::duration_cast(cTMs).count(); + + // Define a timezone structure and initialize it to the local timezone + // This will capture any daylight saving time changes + struct tm local_time; + localtime_r(&unixEpoch, &local_time); + + minutesPastMidnight = static_cast((local_time.tm_hour * 60) + local_time.tm_min); + + return err; +} + } // namespace DeviceEnergyManagement } // namespace Clusters } // namespace app From fa59eb6a727d7e2df1ed4b9a879eb966946e9f7b Mon Sep 17 00:00:00 2001 From: pcoleman Date: Sat, 20 Jul 2024 20:47:45 +0100 Subject: [PATCH 64/74] Update following review comments from Boris --- .../src/DeviceEnergyManagementDelegateImpl.cpp | 2 ++ 1 file changed, 2 insertions(+) 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 ca06c1f0c85162..3d11ab0e1d56b6 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -115,6 +115,8 @@ Status DeviceEnergyManagementDelegate::PowerAdjustRequest(const int64_t powerMw, SetESAState(ESAStateEnum::kPowerAdjustActive); + // mPowerAdjustCapabilityStruct is guaranteed to have a value as validated in Instance::HandlePowerAdjustRequest. + // If it did not have a value, this method would not have been called. switch (cause) { case AdjustmentCauseEnum::kLocalOptimization: From 48014ef12fd2927a000232e7cfc8081f8435b3b8 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Tue, 23 Jul 2024 09:12:56 +0100 Subject: [PATCH 65/74] Allow more time for forecast.startTime in test setup as tests can take variable lengths of time to run --- .../energy-management-common/src/DEMTestEventTriggers.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp index 0dd035ec157a2e..469b781a9b6211 100644 --- a/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp +++ b/examples/energy-management-app/energy-management-common/src/DEMTestEventTriggers.cpp @@ -62,8 +62,9 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots) return err; } - // planned start time, in UTC, for the entire Forecast. - sForecastStruct.startTime = chipEpoch; + // planned start time, in UTC, for the entire Forecast. Allow to be a little + // time in the future as forecastStruct.startTime is used in some tests. + sForecastStruct.startTime = chipEpoch + 60; // earliest start time, in UTC, that the entire Forecast can be shifted to. null value indicates that it can be started // immediately. From 6fcc1e7a7fa5b7e4d0bfb22328b4f62bcc323d74 Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Wed, 24 Jul 2024 06:55:15 +0100 Subject: [PATCH 66/74] Update examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp Co-authored-by: Boris Zbarsky --- .../src/DeviceEnergyManagementDelegateImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3d11ab0e1d56b6..47aadd51eafde5 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -798,7 +798,7 @@ const DataModel::Nullable & DeviceEnergyManagemen OptOutStateEnum DeviceEnergyManagementDelegate::GetOptOutState() { - ChipLogDetail(AppServer, "mOptOutState %d", static_cast(mOptOutState)); + ChipLogDetail(AppServer, "mOptOutState %d", to_underlying(mOptOutState)); return mOptOutState; } From 207f90762dbaf394c5974d8973349a1679ddb75b Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Wed, 24 Jul 2024 07:06:56 +0100 Subject: [PATCH 67/74] Update examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp Co-authored-by: Boris Zbarsky --- .../energy-management-common/src/EnergyTimeUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp b/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp index eac29920e173ae..60732c0f3b0497 100644 --- a/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp +++ b/examples/energy-management-app/energy-management-common/src/EnergyTimeUtils.cpp @@ -128,8 +128,8 @@ CHIP_ERROR GetLocalDayOfWeekNow(BitMask & day */ CHIP_ERROR GetMinutesPastMidnight(uint16_t & minutesPastMidnight) { - chip::System::Clock::Milliseconds64 cTMs; - CHIP_ERROR err = chip::System::SystemClock().GetClock_RealTimeMS(cTMs); + System::Clock::Milliseconds64 cTMs; + CHIP_ERROR err = System::SystemClock().GetClock_RealTimeMS(cTMs); if (err != CHIP_NO_ERROR) { ChipLogError(Zcl, "EVSE: unable to get current time to check user schedules error=%" CHIP_ERROR_FORMAT, err.Format()); From 0b1392f2c34b0773790bc996ab462f3df95049ab Mon Sep 17 00:00:00 2001 From: PeterC1965 <101805108+PeterC1965@users.noreply.github.com> Date: Wed, 24 Jul 2024 07:07:13 +0100 Subject: [PATCH 68/74] Update examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp Co-authored-by: Boris Zbarsky --- .../src/DeviceEnergyManagementDelegateImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 47aadd51eafde5..70b8b5dc5a5487 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -986,7 +986,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal break; default: ChipLogDetail(AppServer, "Bad ForecastUpdateReasonEnum value of %d", - static_cast(mForecast.Value().forecastUpdateReason)); + to_underlying(mForecast.Value().forecastUpdateReason)); return CHIP_ERROR_BAD_REQUEST; break; } From 9bbcc889a0e943b614a64f35b8d69c4c87e7aeda Mon Sep 17 00:00:00 2001 From: pcoleman Date: Wed, 24 Jul 2024 07:20:32 +0100 Subject: [PATCH 69/74] Addressing further review comments from Boris --- .../include/DeviceEnergyManagementDelegateImpl.h | 3 +++ .../src/DeviceEnergyManagementDelegateImpl.cpp | 4 ++-- .../device-energy-management-server.h | 3 +++ src/python_testing/TC_DEM_2_2.py | 2 +- 4 files changed, 9 insertions(+), 3 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 9f9989d7b03c92..daddbdf5419449 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -50,6 +50,9 @@ class DeviceEnergyManagementDelegate : public DeviceEnergyManagement::Delegate * @brief Implements a handler to begin to adjust client power * consumption/generation to the level requested. * + * Note callers must call GetPowerAdjustmentCapability and ensure the return value is not null + * before calling PowerAdjustRequest. + * * @param power Milli-Watts the ESA SHALL use during the adjustment period. * @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. 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 70b8b5dc5a5487..f7732f7bbcffc9 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -864,7 +864,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetAbsMinPower(int64_t newValueMw) mAbsMinPowerMw = newValueMw; if (oldValueMw != newValueMw) { - ChipLogDetail(AppServer, "mAbsMinPower updated to %d", static_cast(mAbsMinPowerMw)); + ChipLogDetail(AppServer, "mAbsMinPower updated to " ChipLogFormatX64, ChipLogValueX64(mAbsMinPowerMw)); MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, AbsMinPower::Id); } @@ -878,7 +878,7 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetAbsMaxPower(int64_t newValueMw) mAbsMaxPowerMw = newValueMw; if (oldValueMw != newValueMw) { - ChipLogDetail(AppServer, "mAbsMaxPower updated to %d", static_cast(mAbsMaxPowerMw)); + ChipLogDetail(AppServer, "mAbsMaxPower updated to " ChipLogFormatX64, ChipLogValueX64(mAbsMaxPowerMw)); MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, AbsMaxPower::Id); } 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 dee7ba144d5bd3..c58e5c5a73743a 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 @@ -45,6 +45,9 @@ class Delegate * @brief Delegate should implement a handler to begin to adjust client power * consumption/generation to the level requested. * + * Note callers must call GetPowerAdjustmentCapability and ensure the return value is not null + * before calling PowerAdjustRequest. + * * @param power Milli-Watts the ESA SHALL use during the adjustment period. * @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. diff --git a/src/python_testing/TC_DEM_2_2.py b/src/python_testing/TC_DEM_2_2.py index 050c9f900cafd2..dc81cbcc0aa9d2 100644 --- a/src/python_testing/TC_DEM_2_2.py +++ b/src/python_testing/TC_DEM_2_2.py @@ -23,7 +23,7 @@ # test-runner-run/run1/app: ${ENERGY_MANAGEMENT_APP} # test-runner-run/run1/factoryreset: True # test-runner-run/run1/quiet: True -# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x01 # test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # === END CI TEST ARGUMENTS === From 07a172fb4a13ba02044ceaea4d442ebe4db7de67 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Wed, 24 Jul 2024 08:45:07 +0100 Subject: [PATCH 70/74] Fix small issue found as a result of the DEM test script review --- .../src/DeviceEnergyManagementDelegateImpl.cpp | 4 ++++ 1 file changed, 4 insertions(+) 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 f7732f7bbcffc9..9f6328c8fbe2cf 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -600,6 +600,10 @@ Status DeviceEnergyManagementDelegate::ResumeRequest() if (mPauseRequestInProgress) { + // The PauseRequest has effectively been cancelled so as a result the device should + // go back to InternalOptimisation + mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization; + CHIP_ERROR err = CancelPauseRequestAndGenerateEvent(CauseEnum::kCancelled); if (err == CHIP_NO_ERROR) { From 242b27f729bfd67e63e9cd9752fcbdbc97cb7bb5 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Wed, 24 Jul 2024 11:42:38 +0100 Subject: [PATCH 71/74] Protect against forecast being null --- .../src/DeviceEnergyManagementDelegateImpl.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 9f6328c8fbe2cf..273bc9e0614333 100644 --- a/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp +++ b/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp @@ -600,9 +600,13 @@ Status DeviceEnergyManagementDelegate::ResumeRequest() if (mPauseRequestInProgress) { - // The PauseRequest has effectively been cancelled so as a result the device should - // go back to InternalOptimisation - mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization; + // Guard against mForecast being null + if (!mForecast.IsNull()) + { + // The PauseRequest has effectively been cancelled so as a result the device should + // go back to InternalOptimisation + mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization; + } CHIP_ERROR err = CancelPauseRequestAndGenerateEvent(CauseEnum::kCancelled); if (err == CHIP_NO_ERROR) From 5d4c2b1938539d47459e707b0d1c1fad8b38424f Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 25 Jul 2024 18:06:17 +0100 Subject: [PATCH 72/74] Remove src/python_testing/DEMTestBase.py as renamed in PR34234 --- src/python_testing/DEMTestBase.py | 220 ------------------------------ 1 file changed, 220 deletions(-) delete mode 100644 src/python_testing/DEMTestBase.py diff --git a/src/python_testing/DEMTestBase.py b/src/python_testing/DEMTestBase.py deleted file mode 100644 index 59477d94e9befd..00000000000000 --- a/src/python_testing/DEMTestBase.py +++ /dev/null @@ -1,220 +0,0 @@ -# -# Copyright (c) 2023 Project CHIP Authors -# All rights reserved. -# -# 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. - - -import logging - -import chip.clusters as Clusters -from chip.interaction_model import InteractionModelError, Status -from mobly import asserts - -logger = logging.getLogger(__name__) - - -class DEMTestBase: - - async def read_dem_attribute_expect_success(self, endpoint: int = None, attribute: str = ""): - cluster = Clusters.Objects.DeviceEnergyManagement - full_attr = getattr(cluster.Attributes, attribute) - logging.info(f"endpoint {endpoint} full_attr {full_attr}") - return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=full_attr) - - async def check_dem_attribute(self, attribute, expected_value, endpoint: int = None): - value = await self.read_dem_attribute_expect_success(endpoint=endpoint, attribute=attribute) - asserts.assert_equal(value, expected_value, - f"Unexpected '{attribute}' value - expected {expected_value}, was {value}") - - async def send_power_adjustment_command(self, power: int, duration: int, - cause: Clusters.Objects.DeviceEnergyManagement.Enums.CauseEnum, - endpoint: int = None, timedRequestTimeoutMs: int = 3000, - expected_status: Status = Status.Success): - try: - await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.PowerAdjustRequest( - power=power, - duration=duration, - cause=cause), - endpoint=endpoint, - timedRequestTimeoutMs=timedRequestTimeoutMs) - - asserts.assert_equal(expected_status, Status.Success) - - except InteractionModelError as e: - asserts.assert_equal(e.status, expected_status, "Unexpected error returned") - - async def send_cancel_power_adjustment_command(self, endpoint: int = None, timedRequestTimeoutMs: int = 3000, - expected_status: Status = Status.Success): - try: - await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.CancelPowerAdjustRequest(), - endpoint=endpoint, - timedRequestTimeoutMs=timedRequestTimeoutMs) - - asserts.assert_equal(expected_status, Status.Success) - - except InteractionModelError as e: - asserts.assert_equal(e.status, expected_status, "Unexpected error returned") - - async def send_start_time_adjust_request_command(self, requestedStartTime: int, - cause: Clusters.Objects.DeviceEnergyManagement.Enums.CauseEnum, - endpoint: int = None, timedRequestTimeoutMs: int = 3000, - expected_status: Status = Status.Success): - try: - await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.StartTimeAdjustRequest( - requestedStartTime=requestedStartTime, - cause=cause), - endpoint=endpoint, - timedRequestTimeoutMs=timedRequestTimeoutMs) - - asserts.assert_equal(expected_status, Status.Success) - - except InteractionModelError as e: - asserts.assert_equal(e.status, expected_status, "Unexpected error returned") - - async def send_start_time_adjust_clear_command(self, - endpoint: int = None, timedRequestTimeoutMs: int = 3000, - expected_status: Status = Status.Success): - try: - await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.StartTimeAdjustClear(), # StartTimeAdjustmentClear(), - endpoint=endpoint, - timedRequestTimeoutMs=timedRequestTimeoutMs) - - asserts.assert_equal(expected_status, Status.Success) - - except InteractionModelError as e: - asserts.assert_equal(e.status, expected_status, "Unexpected error returned") - - async def send_cancel_request_command(self, - endpoint: int = None, timedRequestTimeoutMs: int = 3000, - expected_status: Status = Status.Success): - try: - await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.CancelRequest(), - endpoint=endpoint, - timedRequestTimeoutMs=timedRequestTimeoutMs) - - asserts.assert_equal(expected_status, Status.Success) - - except InteractionModelError as e: - asserts.assert_equal(e.status, expected_status, "Unexpected error returned") - - async def send_pause_request_command(self, duration: int, cause: - Clusters.Objects.DeviceEnergyManagement.Enums.AdjustmentCauseEnum, - endpoint: int = None, timedRequestTimeoutMs: int = 3000, - expected_status: Status = Status.Success): - try: - await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.PauseRequest( - duration=duration, - cause=cause), - endpoint=endpoint, - timedRequestTimeoutMs=timedRequestTimeoutMs) - - asserts.assert_equal(expected_status, Status.Success) - - except InteractionModelError as e: - asserts.assert_equal(e.status, expected_status, "Unexpected error returned") - - async def send_resume_request_command(self, endpoint: int = None, timedRequestTimeoutMs: int = 3000, - expected_status: Status = Status.Success): - try: - await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.ResumeRequest(), - endpoint=endpoint, - timedRequestTimeoutMs=timedRequestTimeoutMs) - - asserts.assert_equal(expected_status, Status.Success) - - except InteractionModelError as e: - asserts.assert_equal(e.status, expected_status, "Unexpected error returned") - - async def send_modify_forecast_request_command(self, forecastID: int, - slotAdjustments: list[Clusters.DeviceEnergyManagement.Structs.SlotAdjustmentStruct], - cause: Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum, - endpoint: int = None, timedRequestTimeoutMs: int = 3000, - expected_status: Status = Status.Success): - try: - await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.ModifyForecastRequest(forecastID=forecastID, - slotAdjustments=slotAdjustments, - cause=cause), - endpoint=endpoint, - timedRequestTimeoutMs=timedRequestTimeoutMs) - - asserts.assert_equal(expected_status, Status.Success) - - except InteractionModelError as e: - asserts.assert_equal(e.status, expected_status, "Unexpected error returned") - - async def send_request_constraint_based_forecast(self, constraintList: list[Clusters.DeviceEnergyManagement.Structs.ConstraintsStruct], - cause: Clusters.DeviceEnergyManagement.Enums.AdjustmentCauseEnum, - endpoint: int = None, timedRequestTimeoutMs: int = 3000, - expected_status: Status = Status.Success): - try: - await self.send_single_cmd(cmd=Clusters.DeviceEnergyManagement.Commands.RequestConstraintBasedForecast(constraints=constraintList, - cause=cause), - endpoint=endpoint, - timedRequestTimeoutMs=timedRequestTimeoutMs) - - asserts.assert_equal(expected_status, Status.Success) - - except InteractionModelError as e: - asserts.assert_equal(e.status, expected_status, "Unexpected error returned") - - async def send_test_event_trigger_power_adjustment(self): - await self.send_test_event_triggers(eventTrigger=0x0098000000000000) - - async def send_test_event_trigger_power_adjustment_clear(self): - await self.send_test_event_triggers(eventTrigger=0x0098000000000001) - - async def send_test_event_trigger_user_opt_out_local(self): - await self.send_test_event_triggers(eventTrigger=0x0098000000000002) - - async def send_test_event_trigger_user_opt_out_grid(self): - await self.send_test_event_triggers(eventTrigger=0x0098000000000003) - - async def send_test_event_trigger_user_opt_out_clear_all(self): - await self.send_test_event_triggers(eventTrigger=0x0098000000000004) - - async def send_test_event_trigger_start_time_adjustment(self): - await self.send_test_event_triggers(eventTrigger=0x0098000000000005) - - async def send_test_event_trigger_start_time_adjustment_clear(self): - await self.send_test_event_triggers(eventTrigger=0x0098000000000006) - - async def send_test_event_trigger_pausable(self): - await self.send_test_event_triggers(eventTrigger=0x0098000000000007) - - async def send_test_event_trigger_pausable_next_slot(self): - await self.send_test_event_triggers(eventTrigger=0x0098000000000008) - - async def send_test_event_trigger_pausable_clear(self): - await self.send_test_event_triggers(eventTrigger=0x0098000000000009) - - async def send_test_event_trigger_forecast_adjustment(self): - await self.send_test_event_triggers(eventTrigger=0x009800000000000A) - - async def send_test_event_trigger_forecast_adjustment_next_slot(self): - await self.send_test_event_triggers(eventTrigger=0x009800000000000B) - - async def send_test_event_trigger_forecast_adjustment_clear(self): - await self.send_test_event_triggers(eventTrigger=0x009800000000000C) - - async def send_test_event_trigger_constraint_based_adjustment(self): - await self.send_test_event_triggers(eventTrigger=0x009800000000000D) - - async def send_test_event_trigger_constraint_based_adjustment_clear(self): - await self.send_test_event_triggers(eventTrigger=0x009800000000000E) - - async def send_test_event_trigger_forecast(self): - await self.send_test_event_triggers(eventTrigger=0x009800000000000F) - - async def send_test_event_trigger_forecast_clear(self): - await self.send_test_event_triggers(eventTrigger=0x0098000000000010) From d924fa90e7665d1e4e1a6a232e2805e743df7652 Mon Sep 17 00:00:00 2001 From: pcoleman Date: Thu, 25 Jul 2024 18:53:52 +0100 Subject: [PATCH 73/74] Update following review comment from Andrei --- .../include/DeviceEnergyManagementDelegateImpl.h | 3 +-- 1 file changed, 1 insertion(+), 2 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 daddbdf5419449..22d45239ecbe75 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -19,6 +19,7 @@ #pragma once #include +#include #include namespace chip { @@ -26,8 +27,6 @@ namespace app { namespace Clusters { namespace DeviceEnergyManagement { -class DEMManufacturerDelegate; - /** * The application delegate. */ From 07ed1fa98a884c35cb8a710e3280b33f90d2fe42 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 25 Jul 2024 17:54:41 +0000 Subject: [PATCH 74/74] Restyled by clang-format --- .../include/DeviceEnergyManagementDelegateImpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 22d45239ecbe75..e540d56e030058 100644 --- a/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +++ b/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h @@ -18,8 +18,8 @@ #pragma once -#include #include +#include #include namespace chip {