Skip to content

Commit 9bddbfe

Browse files
committed
Get DEM and EEM tests passing when running combined app in WHM mode
1 parent ce3a90f commit 9bddbfe

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

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

+4-14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <DeviceEnergyManagementDelegateImpl.h>
2020
#include <EVSEManufacturerImpl.h>
21+
#include <DEMDelegate.h>
2122
#include <app/clusters/device-energy-management-server/DeviceEnergyManagementTestEventTriggerHandler.h>
2223

2324
#include <EnergyTimeUtils.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;
@@ -134,10 +125,9 @@ 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));
129+
GetDEMDelegate()->SetAbsMinPower(1000);
130+
GetDEMDelegate()->SetAbsMaxPower(256 * 2000 * 1000);
141131

142132
return CHIP_NO_ERROR;
143133
}

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

+7
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
*

examples/energy-management-app/energy-management-common/water-heater/include/WhmManufacturer.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <WhmDelegate.h>
2222
#include <WhmInstance.h>
23+
#include <DEMManufacturerDelegate.h>
2324

2425
namespace chip {
2526
namespace app {
@@ -32,7 +33,7 @@ namespace WaterHeaterManagement {
3233
* Helps with handling the test triggers.
3334
*/
3435

35-
class WhmManufacturer
36+
class WhmManufacturer: public DeviceEnergyManagement::DEMManufacturerDelegate
3637
{
3738
public:
3839
WhmManufacturer(WaterHeaterManagementInstance * whmInstance) { mWhmInstance = whmInstance; }
@@ -139,6 +140,13 @@ class WhmManufacturer
139140
*/
140141
void BoostCommandFinished();
141142

143+
/* Implement the DEMManufacturerDelegate interface */
144+
145+
/**
146+
* @brief The PowerAdjustEnd event needs to report the approximate energy used by the ESA during the session.
147+
*/
148+
int64_t GetApproxEnergyDuringSession() override;
149+
142150
private:
143151
WaterHeaterManagementInstance * mWhmInstance;
144152
};

examples/energy-management-app/energy-management-common/water-heater/src/WaterHeaterMain.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
#include "EnergyManagementAppCmdLineOptions.h"
2020

2121
#include <DeviceEnergyManagementManager.h>
22+
#include <DeviceEnergyManagementDelegateImpl.h>
2223
#include <ElectricalPowerMeasurementDelegate.h>
2324
#include <PowerTopologyDelegate.h>
2425
#include <device-energy-management-modes.h>
2526
#include <water-heater-mode.h>
27+
#include <WhmManufacturer.h>
2628

2729
#include <app-common/zap-generated/ids/Attributes.h>
2830
#include <app-common/zap-generated/ids/Clusters.h>
@@ -36,6 +38,7 @@
3638

3739
#include <EnergyEvseMain.h>
3840
#include <WhmMain.h>
41+
#include <DEMDelegate.h>
3942

4043
namespace chip {
4144
namespace app {
@@ -66,6 +69,11 @@ void FullWhmApplicationInit()
6669
WhmApplicationShutdown();
6770
return;
6871
}
72+
73+
/* For Device Energy Management we need the ESA to be Online and ready to accept commands */
74+
75+
GetDEMDelegate()->SetESAState(ESAStateEnum::kOnline);
76+
GetDEMDelegate()->SetDEMManufacturerDelegate(*GetWhmManufacturer());
6977
}
7078

7179
void FullWhmApplicationShutdown()

examples/energy-management-app/energy-management-common/water-heater/src/WhmManufacturer.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ WaterHeaterManagementDelegate * GetWhmDelegate()
160160
return wg;
161161
}
162162

163+
// The PowerAdjustEnd event needs to report the approximate energy used by the ESA during the session.
164+
int64_t WhmManufacturer::GetApproxEnergyDuringSession()
165+
{
166+
return 300;
167+
}
168+
163169
void SetTestEventTrigger_BasicInstallationTestEvent()
164170
{
165171
WaterHeaterManagementDelegate * dg = GetWhmDelegate();

0 commit comments

Comments
 (0)