Skip to content

Commit 1103358

Browse files
jamesharrowrestyled-commitsPeterC1965
authored andcommitted
Add water heater to energy management app (#34886)
* Refactored file location for chip-energy-management-app. Updated esp32 and linux build files. * Updated some all-clusters-app build and CMakeLists (linux, esp32, psoc6) * Updated remaining build and CMakefiles with new folders. * Fixed unit tests BUILD.gn * Restyled by gn * Missed Ameba .cmake * Missed all-clusters-minimal-app/esp32/main/CMakeLists.txt * Added basic hooks to ESP32 to allow EVSE or Water Heater app * Added initial WaterHeaterMain.cpp - needs rework * Configure runner command to use --application <dem|eevse|whm> option * Unify the WHM and EEVSE/DEM apps * Restyled by whitespace * Restyled by clang-format * Restyled by gn * Rename application names * Get ESP32 energy management app building with water-heater. Move water heater files from all-clusters-app to examples/energy-management-app/energy-management-common/water-heater * Get WHM triggers working * Get energy tests passing * Add some more build infrastructure to set the DEM feature map * Address review comments from James and fix some CI tests * Restyled by clang-format * Restyled by gn * Undo changes to Objects.py * Address review from James and fix forecast subscription issues * Address review from James * Added ENERGY_REPORTING_TRIGGERS option to ESP32 and updated ESP32 README.md * Guard against a EVSE and WHM app being simultaneously defined * Updated Linux README.md to highlight --application and --featureSet args. * Fixed mis-spell * Removed duplicate WaterHeaterMode::Shutdown() * Fixed missing free of WaterHeaterMode and made a call to both EvseMain shutdown and WaterHeaterMain shutdown regardless of application mode. * Restyled by whitespace * Restyled by clang-format * Applied code review comments, attempt to fix clang build failure with type in loop. * Restyled by whitespace * Restyled by clang-format * Get DEM and EEM tests passing when running combined app in WHM mode * Restyled by clang-format * Ensure absMinPower and absMaxPower are set * Fix CI build error * Restyled by whitespace * Restyled by clang-format * Fix power levels so they fit within absMinPower and absMaxPower * Fix definition of CHIP_DEVICE_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER --------- Co-authored-by: Restyled.io <[email protected]> Co-authored-by: pcoleman <[email protected]> Co-authored-by: PeterC1965 <[email protected]>
1 parent 50bcfed commit 1103358

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1031
-144
lines changed

examples/all-clusters-app/esp32/main/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set(PRIV_INCLUDE_DIRS_LIST
2222
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/device-energy-management/include"
2323
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/energy-evse/include"
2424
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/energy-reporting/include"
25+
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/water-heater/include"
2526
"${CMAKE_CURRENT_LIST_DIR}/include"
2627
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers"
2728
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32"
@@ -36,6 +37,7 @@ set(SRC_DIRS_LIST
3637
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/device-energy-management/src"
3738
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/energy-evse/src"
3839
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/energy-reporting/src"
40+
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/water-heater/src"
3941
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers"
4042
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/ota"
4143
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/common"

examples/all-clusters-app/linux/BUILD.gn

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ if (chip_enable_pw_rpc) {
2929

3030
source_set("chip-all-clusters-common") {
3131
sources = [
32-
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/WhmDelegateImpl.cpp",
33-
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/WhmInstance.cpp",
34-
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/WhmMain.cpp",
35-
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/WhmManufacturer.cpp",
3632
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/air-quality-instance.cpp",
3733
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/binding-handler.cpp",
3834
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/boolcfg-stub.cpp",
@@ -62,7 +58,6 @@ source_set("chip-all-clusters-common") {
6258
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp",
6359
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp",
6460
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp",
65-
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/water-heater-mode.cpp",
6661
"${chip_root}/examples/all-clusters-app/linux/diagnostic-logs-provider-delegate-impl.cpp",
6762
"${chip_root}/examples/energy-management-app/energy-management-common/common/src/EnergyTimeUtils.cpp",
6863
"${chip_root}/examples/energy-management-app/energy-management-common/device-energy-management/src/DeviceEnergyManagementDelegateImpl.cpp",
@@ -75,6 +70,11 @@ source_set("chip-all-clusters-common") {
7570
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/src/EnergyEvseTargetsStore.cpp",
7671
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/src/energy-evse-mode.cpp",
7772
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/src/ElectricalPowerMeasurementDelegate.cpp",
73+
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmDelegateImpl.cpp",
74+
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmInstance.cpp",
75+
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmMain.cpp",
76+
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmManufacturer.cpp",
77+
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/water-heater-mode.cpp",
7878
"${chip_root}/examples/thermostat/thermostat-common/src/thermostat-delegate-impl.cpp",
7979
"AllClustersCommandDelegate.cpp",
8080
"AllClustersCommandDelegate.h",
@@ -102,6 +102,7 @@ source_set("chip-all-clusters-common") {
102102
"${chip_root}/examples/energy-management-app/energy-management-common/device-energy-management/include",
103103
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/include",
104104
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/include",
105+
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/include",
105106
"${chip_root}/examples/thermostat/thermostat-common/include",
106107
]
107108

examples/all-clusters-app/linux/main-common.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ void ApplicationShutdown()
285285
Clusters::WaterHeaterMode::Shutdown();
286286

287287
Clusters::WaterHeaterManagement::WhmApplicationShutdown();
288-
Clusters::WaterHeaterMode::Shutdown();
289288

290289
if (sChipNamedPipeCommands.Stop() != CHIP_NO_ERROR)
291290
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <DeviceEnergyManagementDelegateImpl.h>
22+
23+
chip::app::Clusters::DeviceEnergyManagement::DeviceEnergyManagementDelegate * GetDEMDelegate();

examples/energy-management-app/energy-management-common/device-energy-management/src/DEMTestEventTriggers.cpp

+8-20
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19+
#include <DEMDelegate.h>
1920
#include <DeviceEnergyManagementDelegateImpl.h>
2021
#include <EVSEManufacturerImpl.h>
2122
#include <app/clusters/device-energy-management-server/DeviceEnergyManagementTestEventTriggerHandler.h>
@@ -41,16 +42,6 @@ static chip::app::Clusters::DeviceEnergyManagement::Structs::PowerAdjustCapabili
4142
static chip::app::DataModel::Nullable<chip::app::Clusters::DeviceEnergyManagement::Structs::PowerAdjustCapabilityStruct::Type>
4243
sPowerAdjustmentCapability;
4344

44-
DeviceEnergyManagementDelegate * GetDEMDelegate()
45-
{
46-
EVSEManufacturer * mn = GetEvseManufacturer();
47-
VerifyOrDieWithMsg(mn != nullptr, AppServer, "EVSEManufacturer is null");
48-
DeviceEnergyManagementDelegate * dg = mn->GetDEMDelegate();
49-
VerifyOrDieWithMsg(dg != nullptr, AppServer, "DEM Delegate is null");
50-
51-
return dg;
52-
}
53-
5445
CHIP_ERROR ConfigureForecast(uint16_t numSlots)
5546
{
5647
uint32_t chipEpoch = 0;
@@ -92,9 +83,9 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots)
9283

9384
if (GetDEMDelegate()->HasFeature(DeviceEnergyManagement::Feature::kPowerForecastReporting))
9485
{
95-
sSlots[0].nominalPower.SetValue(1500);
96-
sSlots[0].minPower.SetValue(1000);
97-
sSlots[0].maxPower.SetValue(2000);
86+
sSlots[0].nominalPower.SetValue(2500000);
87+
sSlots[0].minPower.SetValue(1200000);
88+
sSlots[0].maxPower.SetValue(7600000);
9889
}
9990

10091
sSlots[0].nominalEnergy.SetValue(2000);
@@ -119,9 +110,9 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots)
119110

120111
if (GetDEMDelegate()->HasFeature(DeviceEnergyManagement::Feature::kPowerForecastReporting))
121112
{
122-
sSlots[slotNo].nominalPower.SetValue(2 * sSlots[slotNo - 1].nominalPower.Value());
123-
sSlots[slotNo].minPower.SetValue(2 * sSlots[slotNo - 1].minPower.Value());
124-
sSlots[slotNo].maxPower.SetValue(2 * sSlots[slotNo - 1].maxPower.Value());
113+
sSlots[slotNo].nominalPower.SetValue(sSlots[slotNo - 1].nominalPower.Value());
114+
sSlots[slotNo].minPower.SetValue(sSlots[slotNo - 1].minPower.Value());
115+
sSlots[slotNo].maxPower.SetValue(sSlots[slotNo - 1].maxPower.Value());
125116

126117
sSlots[slotNo].nominalEnergy.SetValue(2 * sSlots[slotNo - 1].nominalEnergy.Value());
127118
}
@@ -134,10 +125,7 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots)
134125

135126
sForecastStruct.slots = DataModel::List<const DeviceEnergyManagement::Structs::SlotStruct::Type>(sSlots, numSlots);
136127

137-
EVSEManufacturer * mn = GetEvseManufacturer();
138-
mn->GetDEMDelegate()->SetForecast(DataModel::MakeNullable(sForecastStruct));
139-
mn->GetDEMDelegate()->SetAbsMinPower(1000);
140-
mn->GetDEMDelegate()->SetAbsMaxPower(256 * 2000 * 1000);
128+
GetDEMDelegate()->SetForecast(DataModel::MakeNullable(sForecastStruct));
141129

142130
return CHIP_NO_ERROR;
143131
}

examples/energy-management-app/energy-management-common/device-energy-management/src/DeviceEnergyManagementDelegateImpl.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,14 @@ Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t req
377377
mForecast.Value().startTime = savedStartTime;
378378
mForecast.Value().endTime = savedEndTime;
379379

380+
MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
381+
380382
return Status::Failure;
381383
}
382384
}
383385

386+
MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
387+
384388
return Status::Success;
385389
}
386390

@@ -457,10 +461,14 @@ Status DeviceEnergyManagementDelegate::PauseRequest(const uint32_t durationS, Ad
457461
if (cause == AdjustmentCauseEnum::kLocalOptimization)
458462
{
459463
mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kLocalOptimization;
464+
465+
MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
460466
}
461467
else if (cause == AdjustmentCauseEnum::kGridOptimization)
462468
{
463469
mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kGridOptimization;
470+
471+
MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
464472
}
465473

466474
return Status::Success;
@@ -606,6 +614,8 @@ Status DeviceEnergyManagementDelegate::ResumeRequest()
606614
// The PauseRequest has effectively been cancelled so as a result the device should
607615
// go back to InternalOptimisation
608616
mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization;
617+
618+
MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
609619
}
610620

611621
CHIP_ERROR err = CancelPauseRequestAndGenerateEvent(CauseEnum::kCancelled);
@@ -672,6 +682,8 @@ Status DeviceEnergyManagementDelegate::ModifyForecastRequest(
672682
}
673683

674684
mForecast.Value().forecastID++;
685+
686+
MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
675687
}
676688

677689
return status;
@@ -725,6 +737,8 @@ Status DeviceEnergyManagementDelegate::RequestConstraintBasedForecast(
725737

726738
mForecast.Value().forecastID++;
727739

740+
MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
741+
728742
status = Status::Success;
729743
}
730744

@@ -748,6 +762,8 @@ Status DeviceEnergyManagementDelegate::CancelRequest()
748762

749763
mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization;
750764

765+
MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
766+
751767
/* It is expected the mpDEMManufacturerDelegate will cancel the effects of any previous adjustment
752768
* request commands, and re-evaluate its forecast for intended operation ignoring those previous
753769
* requests.
@@ -980,6 +996,8 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal
980996
if ((mOptOutState == OptOutStateEnum::kOptOut) || (mOptOutState == OptOutStateEnum::kLocalOptOut))
981997
{
982998
mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization;
999+
1000+
MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
9831001
// Generate a new forecast with Internal Optimization
9841002
// TODO
9851003
}
@@ -988,6 +1006,8 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal
9881006
if ((mOptOutState == OptOutStateEnum::kOptOut) || (mOptOutState == OptOutStateEnum::kGridOptOut))
9891007
{
9901008
mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization;
1009+
1010+
MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
9911011
// Generate a new forecast with Internal Optimization
9921012
// TODO
9931013
}

examples/energy-management-app/energy-management-common/energy-evse/include/EnergyEvseMain.h

+11
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,16 @@
1818

1919
#pragma once
2020

21+
#include <lib/core/CHIPError.h>
22+
2123
void EvseApplicationInit();
2224
void EvseApplicationShutdown();
25+
26+
CHIP_ERROR DeviceEnergyManagementInit();
27+
CHIP_ERROR DeviceEnergyManagementShutdown();
28+
29+
CHIP_ERROR EnergyMeterInit();
30+
CHIP_ERROR EnergyMeterShutdown();
31+
32+
CHIP_ERROR PowerTopologyInit();
33+
CHIP_ERROR PowerTopologyShutdown();

examples/energy-management-app/energy-management-common/energy-evse/src/EVSEManufacturerImpl.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ CHIP_ERROR EVSEManufacturer::Init()
7070
/* For Device Energy Management we need the ESA to be Online and ready to accept commands */
7171
dem->SetESAState(ESAStateEnum::kOnline);
7272

73+
// Set the abs min and max power
74+
dem->SetAbsMinPower(1200000); // 1.2KW
75+
dem->SetAbsMaxPower(7600000); // 7.6KW
76+
7377
/*
7478
* This is an example implementation for manufacturers to consider
7579
*

examples/energy-management-app/energy-management-common/energy-evse/src/EnergyEvseMain.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ EVSEManufacturer * EnergyEvse::GetEvseManufacturer()
6767
return gEvseManufacturer.get();
6868
}
6969

70+
DeviceEnergyManagement::DeviceEnergyManagementDelegate * GetDEMDelegate()
71+
{
72+
VerifyOrDieWithMsg(gDEMDelegate.get() != nullptr, AppServer, "DEM Delegate is null");
73+
74+
return gDEMDelegate.get();
75+
}
76+
7077
/*
7178
* @brief Creates a Delegate and Instance for DEM
7279
*
@@ -472,7 +479,7 @@ void EvseApplicationInit()
472479

473480
void EvseApplicationShutdown()
474481
{
475-
ChipLogDetail(AppServer, "Energy Management App: ApplicationShutdown()");
482+
ChipLogDetail(AppServer, "Energy Management App (EVSE): ApplicationShutdown()");
476483

477484
/* Shutdown in reverse order that they were created */
478485
EVSEManufacturerShutdown(); /* Free the EVSEManufacturer */

0 commit comments

Comments
 (0)