-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[WIP] ValveConfigurationAndControl code driven cluster migration #42134
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR migrates the ValveConfigurationAndControl cluster from an Ember-based implementation to a Code-Driven approach. The migration involves removing generated attribute accessors and command callbacks, implementing a new cluster class that manages attributes internally, and updating configuration files to mark the cluster as code-driven.
Key changes include:
- New
ValveConfigurationAndControlClusterclass for managing cluster state and behavior - Removal of auto-generated attribute accessors from zap-generated files
- Introduction of
TimeSyncTrackerinterface for TimeSync cluster dependency - Updated integration layer with CodegenIntegration files
Reviewed changes
Copilot reviewed 28 out of 29 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| valve-configuration-and-control-cluster.h | Defines new cluster class with internal attribute storage |
| valve-configuration-and-control-cluster.cpp | Implements cluster logic, command handlers, and attribute management |
| CodegenIntegration.cpp | Provides integration layer for codegen data model provider |
| TimeSyncTracker.h | Interface for abstracting TimeSync cluster dependency |
| config-data.yaml | Marks cluster as CommandHandlerInterfaceOnly and CodeDriven |
| zcl.json | Configures attributes as code-driven (external storage) |
| Test files | Unit tests for basic cluster functionality |
.../clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster.cpp
Outdated
Show resolved
Hide resolved
.../clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster.cpp
Outdated
Show resolved
Hide resolved
.../clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster.cpp
Outdated
Show resolved
Hide resolved
...pp/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster.h
Outdated
Show resolved
Hide resolved
...pp/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster.h
Outdated
Show resolved
Hide resolved
src/app/clusters/valve-configuration-and-control-server/BUILD.gn
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 28 out of 28 changed files in this pull request and generated 8 comments.
.../clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster.cpp
Outdated
Show resolved
Hide resolved
.../clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster.cpp
Outdated
Show resolved
Hide resolved
src/app/clusters/valve-configuration-and-control-server/BUILD.gn
Outdated
Show resolved
Hide resolved
.../clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster.cpp
Outdated
Show resolved
Hide resolved
.../clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster.cpp
Show resolved
Hide resolved
.../clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster.cpp
Outdated
Show resolved
Hide resolved
.../clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster.cpp
Outdated
Show resolved
Hide resolved
.../clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster.cpp
Outdated
Show resolved
Hide resolved
|
PR #42134: Size comparison from d83c06e to b203f51 Full report (35 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, nxp, psoc6, qpg, realtek, stm32, telink)
|
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 28 out of 28 changed files in this pull request and generated 4 comments.
src/app/clusters/valve-configuration-and-control-server/CodegenIntegration.cpp
Outdated
Show resolved
Hide resolved
scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/endpoint_config.h
Show resolved
Hide resolved
.../clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster.cpp
Outdated
Show resolved
Hide resolved
.../clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster.cpp
Outdated
Show resolved
Hide resolved
|
PR #42134: Size comparison from d83c06e to ddd5939 Full report (35 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, nxp, psoc6, qpg, realtek, stm32, telink)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 29 out of 29 changed files in this pull request and generated 3 comments.
src/app/clusters/valve-configuration-and-control-server/TimeSyncTracker.h
Outdated
Show resolved
Hide resolved
src/app/clusters/valve-configuration-and-control-server/app_config_dependent_sources.cmake
Outdated
Show resolved
Hide resolved
src/app/clusters/valve-configuration-and-control-server/CodegenIntegration.h
Outdated
Show resolved
Hide resolved
|
PR #42134: Size comparison from 147004c to 2855e3e Full report (5 builds for cc32xx, realtek, stm32)
|
|
PR #42134: Size comparison from 147004c to f4e0c3f Full report (33 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, nxp, psoc6, qpg, realtek, stm32, telink)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 29 out of 29 changed files in this pull request and generated 4 comments.
| bool ValveConfigurationAndControlCluster::ValueCompliesWithLevelStep(const uint8_t value) const | ||
| { | ||
| if (mOptionalAttributeSet.IsSet(Attributes::LevelStep::Id)) | ||
| { | ||
| commandObj->AddStatus(commandPath, Status::Success); | ||
| if ((value != 100u) && ((value % mLevelStep) != 0)) | ||
| { | ||
| return false; | ||
| } |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition on line 458 uses (value % mLevelStep) != 0 which will fail when mLevelStep is 0, causing a division by zero. Although the default is 1, the attribute could potentially be set to 0 through external means. Add a check to ensure mLevelStep is not 0 before performing the modulo operation.
| void ValveConfigurationAndControlCluster::emitValveLevelEvent(chip::Percent currentLevel) | ||
| { | ||
| ValveConfigurationAndControl::Events::ValveStateChanged::Type event; | ||
| event.valveLevel = MakeOptional<Percent>(currentLevel); | ||
| mContext->interactionContext.eventsGenerator.GenerateEvent(event, mPath.mEndpointId); | ||
| } | ||
|
|
||
| void MatterValveConfigurationAndControlPluginServerInitCallback() | ||
| void ValveConfigurationAndControlCluster::emitValveChangeEvent(ValveConfigurationAndControl::ValveStateEnum currentState) | ||
| { | ||
| AttributeAccessInterfaceRegistry::Instance().Register(&gAttrAccess); | ||
| ValveConfigurationAndControl::Events::ValveStateChanged::Type event; | ||
| event.valveState = currentState; | ||
| mContext->interactionContext.eventsGenerator.GenerateEvent(event, mPath.mEndpointId); | ||
| } |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The event emission methods emitValveLevelEvent and emitValveChangeEvent should follow the codebase naming convention. Method names in this codebase typically use PascalCase for public methods (e.g., EmitValveFault), but these two methods use camelCase with a lowercase first letter. Rename to EmitValveLevelEvent and EmitValveChangeEvent for consistency.
| CHIP_ERROR ValveConfigurationAndControlCluster::CloseValve() | ||
| { | ||
| RemainingDurationTable * item = reinterpret_cast<RemainingDurationTable *>(data); | ||
| VerifyOrReturn(item != nullptr, ChipLogError(Zcl, "Error retrieving RemainingDuration item")); | ||
| CHIP_ERROR err = CHIP_NO_ERROR; | ||
|
|
||
| DataModel::Nullable<uint32_t> rDuration = item->remainingDuration; | ||
| VerifyOrReturn(!rDuration.IsNull()); | ||
| // OpenDuration and RemainingDuration should be set to Null | ||
| SaveAndReportIfChanged(mOpenDuration, DataModel::NullNullable, Attributes::OpenDuration::Id); | ||
| SetRemainingDuration(DataModel::NullNullable); | ||
|
|
||
| EndpointId ep = item->endpoint; | ||
| // TargetState should be set to Closed and CurrentState to Transitioning | ||
| SaveAndReportIfChanged(mTargetState, DataModel::Nullable<ValveStateEnum>(ValveStateEnum::kClosed), Attributes::TargetState::Id); | ||
| SaveAndReportIfChanged(mCurrentState, DataModel::Nullable<ValveStateEnum>(ValveStateEnum::kTransitioning), | ||
| Attributes::CurrentState::Id); | ||
|
|
||
| if (rDuration.Value() > 0) | ||
| // If TimeSync is enabled, AutoCloseTime should be set to Null | ||
| if (mFeatures.Has(Feature::kTimeSync)) | ||
| { | ||
| SetRemainingDuration(ep, DataModel::MakeNullable<uint32_t>(--rDuration.Value())); | ||
| startRemainingDurationTick(ep); | ||
| SaveAndReportIfChanged(mAutoCloseTime, DataModel::NullNullable, Attributes::AutoCloseTime::Id); | ||
| } | ||
| else | ||
|
|
||
| // Set the TargetLevel to 0 | ||
| if (mFeatures.Has(Feature::kLevel)) | ||
| { | ||
| SetRemainingDurationNull(ep); | ||
| SaveAndReportIfChanged(mTargetLevel, Percent(0), Attributes::TargetLevel::Id); | ||
| } | ||
| } | ||
|
|
||
| void startRemainingDurationTick(EndpointId ep) | ||
| { | ||
| RemainingDurationTable * item = GetRemainingDurationItem(ep); | ||
| VerifyOrReturn(item != nullptr, ChipLogError(Zcl, "Error retrieving RemainingDuration item")); | ||
|
|
||
| DataModel::Nullable<uint32_t> rDuration = item->remainingDuration; | ||
| VerifyOrReturn(!rDuration.IsNull()); | ||
| Delegate * delegate = GetDelegate(item->endpoint); | ||
| VerifyOrReturn(!isDelegateNull(delegate)); | ||
|
|
||
| delegate->HandleRemainingDurationTick(rDuration.Value()); | ||
| if (rDuration.Value() > 0) | ||
| if (mDelegate != nullptr) | ||
| { | ||
| (void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onValveConfigurationAndControlTick, item); | ||
| err = mDelegate->HandleCloseValve(); | ||
| } | ||
| else | ||
|
|
||
| // If there was an error, we know nothing about the current state | ||
| if (err != CHIP_NO_ERROR) | ||
| { | ||
| TEMPORARY_RETURN_IGNORED ValveConfigurationAndControl::CloseValve(ep); | ||
| (void) DeviceLayer::SystemLayer().CancelTimer(onValveConfigurationAndControlTick, item); | ||
| SaveAndReportIfChanged(mCurrentLevel, DataModel::NullNullable, Attributes::CurrentLevel::Id); | ||
| SaveAndReportIfChanged(mCurrentState, DataModel::NullNullable, Attributes::CurrentState::Id); | ||
| } | ||
| } | ||
|
|
||
| namespace chip { | ||
| namespace app { | ||
| namespace Clusters { | ||
| namespace ValveConfigurationAndControl { | ||
| // Emit the Transition state. | ||
| emitValveChangeEvent(ValveStateEnum::kTransitioning); | ||
|
|
||
| void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) | ||
| { | ||
| uint16_t ep = emberAfGetClusterServerEndpointIndex(endpoint, ValveConfigurationAndControl::Id, | ||
| MATTER_DM_VALVE_CONFIGURATION_AND_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT); | ||
| // if endpoint is found | ||
| if (ep < kValveConfigurationAndControlDelegateTableSize) | ||
| { | ||
| gDelegateTable[ep] = delegate; | ||
| } | ||
| return err; |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling doesn't set appropriate status codes when the delegate fails. If mDelegate->HandleCloseValve() returns an error, the function still returns that error (line 264), but attributes have already been modified. This could leave the cluster in an inconsistent state. Consider returning a proper status code or rolling back attribute changes on failure.
| ValveConfigurationAndControl::Events::ValveFault::Type event; | ||
| event.valveFault = fault; | ||
| mContext->interactionContext.eventsGenerator.GenerateEvent(event, mPath.mEndpointId); | ||
| mValveFault = fault; |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EmitValveFault method updates mValveFault (line 517) but doesn't report the attribute change. The ValveFault attribute should be marked dirty and reported when it changes. Add NotifyAttributeChanged(Attributes::ValveFault::Id) after setting the value.
| mValveFault = fault; | |
| mValveFault = fault; | |
| NotifyAttributeChanged(Attributes::ValveFault::Id); |
|
PR #42134: Size comparison from 48df2e2 to 26861db Full report (33 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, nxp, psoc6, qpg, realtek, stm32, telink)
|
|
PR #42134: Size comparison from efdf99d to dc48c58 Full report (33 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, nxp, psoc6, qpg, realtek, stm32, telink)
|
|
PR #42134: Size comparison from efdf99d to f12f7a4 Full report (33 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, nxp, psoc6, qpg, realtek, stm32, telink)
|
|
PR #42134: Size comparison from efdf99d to c4e373c Full report (33 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, nxp, psoc6, qpg, realtek, stm32, telink)
|
|
PR #42134: Size comparison from efdf99d to 6854105 Increases above 0.2%:
Full report (35 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, nxp, psoc6, qpg, realtek, stm32, telink)
|
|
The PR history for this change is a little messy for all the Copilot repeated comments added after each commit. Closing this one and creating a new clean one since there are no many comments yet from non-AI participants. Will request review from Copilot and Gemini in the new PR. |
|
|
Summary
This is a migration from the ember based implementation of the ValveConfigurationAndControl to a CodeDriven approach.
Still some work missing and potential improvements so still a WIP.
Related issues
Fixes #41581
Testing
Added unit tests for basic functionality and ran Integration tests locally, they should be executed by the CI too.