Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

energy-management-app: refactor WH and EVSE into separate endpoints and fix conformance issues #36201

Merged
merged 28 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7e192ae
Add missing Water Heater device to matter-devices.xml
soares-sergio Oct 17, 2024
e43ff67
zap regen
soares-sergio Oct 17, 2024
ea06d89
energy-management-app: Split WH and EVSE into 2 endpoints
soares-sergio Oct 22, 2024
ac11559
Use anon namespace instead of static.
soares-sergio Oct 22, 2024
f05afff
disable enpoint on esp32 and silabs
soares-sergio Oct 22, 2024
f827e4a
address Tennessee's PR feedback
soares-sergio Oct 24, 2024
6f3f6dc
Review suggestion: move GetMainAppEndpointId to another file
soares-sergio Oct 24, 2024
8d9d66f
Merge branch 'master' into fix-energy-man-app-comp
soares-sergio Oct 24, 2024
9dee3de
zap regen
soares-sergio Oct 24, 2024
e2f7990
fix matter-devices white space diffs
soares-sergio Oct 28, 2024
1371752
App now builds on all-clusters app
soares-sergio Oct 29, 2024
4143090
Fix typo on init
soares-sergio Oct 29, 2024
b63a9d0
fix all-clusters breakage on esp32
soares-sergio Oct 30, 2024
50fb815
fix misuse of namespace in header
soares-sergio Oct 30, 2024
2f140ea
Fix breakage for silabs water heater
soares-sergio Oct 31, 2024
18fd4df
Merge branch 'master' into fix-energy-man-app-comp
soares-sergio Nov 4, 2024
97ced72
Update WaterHeater endpoint for CI tests
soares-sergio Nov 4, 2024
a4936c2
Update WaterHeater tests to endpoint 2
soares-sergio Nov 5, 2024
d52ca43
Bumped ClusterRevisions
soares-sergio Nov 5, 2024
09476fd
Update AccessControl featureMap to enable Extension attribute
soares-sergio Nov 5, 2024
d8e2764
Remove AccessControl extension attribute
soares-sergio Nov 6, 2024
24f6e7d
Remove kStateForecastReporting from the default feature map
soares-sergio Nov 6, 2024
ffab349
Update TC_WHM_1_2 endpoint to 2
soares-sergio Nov 7, 2024
b9d229f
Merge branch 'master' into fix-energy-man-app-comp
soares-sergio Nov 20, 2024
1164357
Fix various conformance issues
soares-sergio Nov 20, 2024
c0d14a2
Merge branch 'master' into fix-energy-man-app-comp
soares-sergio Nov 20, 2024
2d92654
TC_WHM_1_2: Use endpoint id passed as argument instead of hardcoded
soares-sergio Nov 21, 2024
d2f26a1
Merge branch 'master' into fix-energy-man-app-comp
soares-sergio Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ namespace chip {
namespace app {
namespace Clusters {
namespace DeviceEnergyManagement {
constexpr EndpointId kEvseEndpoint = 1;
constexpr EndpointId kWaterHeaterEndpoint = 2;

EndpointId GetMainAppEndpointId();
soares-sergio marked this conversation as resolved.
Show resolved Hide resolved
chip::BitMask<Feature> GetFeatureMapFromCmdLine();

} // namespace DeviceEnergyManagement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@
#pragma once

#include <DeviceEnergyManagementDelegateImpl.h>
#include <DeviceEnergyManagementManager.h>
#include <lib/core/CHIPError.h>

CHIP_ERROR DeviceEnergyManagementInit(chip::EndpointId endpointId);
CHIP_ERROR DeviceEnergyManagementShutdown();

chip::app::Clusters::DeviceEnergyManagement::DeviceEnergyManagementDelegate * GetDEMDelegate();
chip::app::Clusters::DeviceEnergyManagementManager * GetDEMInstance();
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
*
* 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 "EnergyManagementAppCmdLineOptions.h"

#include <DeviceEnergyManagementManager.h>
#include <EVSEManufacturerImpl.h>
#include <ElectricalPowerMeasurementDelegate.h>
#include <ElectricalSensorInit.h>
#include <EnergyEvseManager.h>
#include <PowerTopologyDelegate.h>
#include <device-energy-management-modes.h>
#include <energy-evse-modes.h>

#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/ConcreteAttributePath.h>
#include <app/clusters/electrical-energy-measurement-server/electrical-energy-measurement-server.h>
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/server/Server.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/Linux/NetworkCommissioningDriver.h>

using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::DeviceEnergyManagement;

static std::unique_ptr<DeviceEnergyManagementDelegate> gDEMDelegate;
soares-sergio marked this conversation as resolved.
Show resolved Hide resolved
static std::unique_ptr<DeviceEnergyManagementManager> gDEMInstance;

DeviceEnergyManagement::DeviceEnergyManagementDelegate * GetDEMDelegate()
{
VerifyOrDieWithMsg(gDEMDelegate.get() != nullptr, AppServer, "DEM Delegate is null");

return gDEMDelegate.get();
}

DeviceEnergyManagementManager * GetDEMInstance()
{
VerifyOrDieWithMsg(gDEMInstance.get() != nullptr, AppServer, "DEM Instance is null");

return gDEMInstance.get();
}

/*
* @brief Creates a Delegate and Instance for DEM
*
* The Instance is a container around the Delegate, so
* create the Delegate first, then wrap it in the Instance
* Then call the Instance->Init() to register the attribute and command handlers
*/
CHIP_ERROR DeviceEnergyManagementInit(chip::EndpointId endpointId)
{
// TODO: support both EVSE and WaterHeater endpoints
if (gDEMDelegate || gDEMInstance)
{
ChipLogError(AppServer, "DEM Instance or Delegate already exist.");
return CHIP_ERROR_INCORRECT_STATE;
}

gDEMDelegate = std::make_unique<DeviceEnergyManagementDelegate>();
if (!gDEMDelegate)
{
ChipLogError(AppServer, "Failed to allocate memory for DeviceEnergyManagementDelegate");
return CHIP_ERROR_NO_MEMORY;
}

chip::BitMask<DeviceEnergyManagement::Feature> featureMap = GetFeatureMapFromCmdLine();

/* Manufacturer may optionally not support all features, commands & attributes */
gDEMInstance = std::make_unique<DeviceEnergyManagementManager>(EndpointId(endpointId), *gDEMDelegate, featureMap);

if (!gDEMInstance)
{
ChipLogError(AppServer, "Failed to allocate memory for DeviceEnergyManagementManager");
gDEMDelegate.reset();
return CHIP_ERROR_NO_MEMORY;
}

gDEMDelegate->SetDeviceEnergyManagementInstance(*gDEMInstance);

CHIP_ERROR err = gDEMInstance->Init(); /* Register Attribute & Command handlers */
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Init failed on gDEMInstance");
gDEMInstance.reset();
gDEMDelegate.reset();
return err;
}

return CHIP_NO_ERROR;
}

CHIP_ERROR DeviceEnergyManagementShutdown()
{
// TODO: support both EVSE and WaterHeater endpoints
/* Do this in the order Instance first, then delegate
* Ensure we call the Instance->Shutdown to free attribute & command handlers first
*/
if (gDEMInstance)
{
/* deregister attribute & command handlers */
gDEMInstance->Shutdown();
gDEMInstance.reset();
}
if (gDEMDelegate)
{
gDEMDelegate.reset();
}
return CHIP_NO_ERROR;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

#include <DEMDelegate.h>
#include <DEMInit.h>
#include <DeviceEnergyManagementDelegateImpl.h>
#include <app/clusters/device-energy-management-server/DeviceEnergyManagementTestEventTriggerHandler.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
* limitations under the License.
*/

#include <EnergyManagementAppCmdLineOptions.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <device-energy-management-modes.h>

using namespace chip::app::Clusters;
using namespace chip::app::Clusters::DeviceEnergyManagementMode;
using namespace chip::app::Clusters::DeviceEnergyManagement;

using chip::Protocols::InteractionModel::Status;
template <typename T>
using List = chip::app::DataModel::List<T>;
Expand Down Expand Up @@ -77,11 +80,6 @@ CHIP_ERROR DeviceEnergyManagementModeDelegate::GetModeTagsByIndex(uint8_t modeIn
return CHIP_NO_ERROR;
}

ModeBase::Instance * DeviceEnergyManagementMode::Instance()
{
return gDeviceEnergyManagementModeInstance.get();
}

void DeviceEnergyManagementMode::Shutdown()
{
gDeviceEnergyManagementModeInstance.reset();
Expand All @@ -90,6 +88,18 @@ void DeviceEnergyManagementMode::Shutdown()

void emberAfDeviceEnergyManagementModeClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == kEvseEndpoint || endpointId == kWaterHeaterEndpoint);

/* emberAfDeviceEnergyManagementModeClusterInitCallback() is called for all endpoints
that include this endpoint (even the one we disable dynamically). So here, we only
proceed when it's called for the right endpoint determined by GetMainAppEndpointId()
(a cmd line argument or #define).
*/
if (endpointId != GetMainAppEndpointId())
{
return;
}

VerifyOrDie(!gDeviceEnergyManagementModeDelegate && !gDeviceEnergyManagementModeInstance);
gDeviceEnergyManagementModeDelegate = std::make_unique<DeviceEnergyManagementMode::DeviceEnergyManagementModeDelegate>();
gDeviceEnergyManagementModeInstance = std::make_unique<ModeBase::Instance>(gDeviceEnergyManagementModeDelegate.get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,5 @@

#include <lib/core/CHIPError.h>

void EvseApplicationInit();
void EvseApplicationInit(chip::EndpointId endpointId);
void EvseApplicationShutdown();

CHIP_ERROR DeviceEnergyManagementInit();
CHIP_ERROR DeviceEnergyManagementShutdown();

CHIP_ERROR EnergyMeterInit();
CHIP_ERROR EnergyMeterShutdown();

CHIP_ERROR PowerTopologyInit();
CHIP_ERROR PowerTopologyShutdown();
Loading
Loading