Skip to content

Commit 18b2ec9

Browse files
[Closure] Adding matter closure specific attribute callback (#41592)
* Adding matter closure specific attribute callback when markdirty is called * Restyled by whitespace * Adding attribute update callback for closure dimension * Restyled by whitespace * add mock in unit tests * Restyled by clang-format --------- Co-authored-by: Restyled.io <[email protected]>
1 parent 8e5f3f8 commit 18b2ec9

File tree

7 files changed

+66
-6
lines changed

7 files changed

+66
-6
lines changed

examples/closure-app/linux/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ executable("closure-app") {
3535
"${chip_root}/examples/closure-app/closure-common/src/ClosureControlEndpoint.cpp",
3636
"${chip_root}/examples/closure-app/closure-common/src/ClosureDimensionEndpoint.cpp",
3737
"ClosureManager.cpp",
38+
"DataModelCallbacks.cpp",
3839
"include/CHIPProjectAppConfig.h",
3940
"main.cpp",
4041
]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
*
3+
* Copyright (c) 2025 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+
#include <app-common/zap-generated/callback.h>
20+
#include <app/ConcreteAttributePath.h>
21+
#include <lib/support/logging/CHIPLogging.h>
22+
23+
using namespace chip;
24+
using namespace chip::app;
25+
26+
/* Forwards all attributes changes */
27+
void MatterClosureControlClusterServerAttributeChangedCallback(const app::ConcreteAttributePath & attributePath)
28+
{
29+
ChipLogProgress(Zcl, "Closure Control cluster ID: " ChipLogFormatMEI, ChipLogValueMEI(attributePath.mAttributeId));
30+
}
31+
32+
void MatterClosureDimensionClusterServerAttributeChangedCallback(const app::ConcreteAttributePath & attributePath)
33+
{
34+
ChipLogProgress(Zcl, "Closure Dimension cluster ID: " ChipLogFormatMEI, ChipLogValueMEI(attributePath.mAttributeId));
35+
}

examples/closure-app/silabs/src/DataModelCallbacks.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,10 @@ void MatterPostAttributeChangeCallback(const app::ConcreteAttributePath & attrib
5252
/* Forwards all attributes changes */
5353
void MatterClosureControlClusterServerAttributeChangedCallback(const app::ConcreteAttributePath & attributePath)
5454
{
55-
ChipLogProgress(Zcl, "Closure cluster ID: " ChipLogFormatMEI, ChipLogValueMEI(attributePath.mAttributeId));
56-
// Attribute changes handling will be done in the next phase.
55+
ChipLogProgress(Zcl, "Closure Control cluster ID: " ChipLogFormatMEI, ChipLogValueMEI(attributePath.mAttributeId));
5756
}
5857

5958
void MatterClosureDimensionClusterServerAttributeChangedCallback(const app::ConcreteAttributePath & attributePath)
6059
{
61-
ChipLogProgress(Zcl, "Closure cluster ID: " ChipLogFormatMEI, ChipLogValueMEI(attributePath.mAttributeId));
62-
// Attribute changes handling will be done in the next phase.
60+
ChipLogProgress(Zcl, "Closure Dimension cluster ID: " ChipLogFormatMEI, ChipLogValueMEI(attributePath.mAttributeId));
6361
}

src/app/clusters/closure-control-server/closure-control-cluster-matter-context.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
#pragma once
2020

21+
#include <app-common/zap-generated/callback.h>
2122
#include <app-common/zap-generated/ids/Clusters.h>
23+
#include <app/ConcreteAttributePath.h>
2224
#include <app/EventLogging.h>
2325
#include <app/reporting/reporting.h>
2426
#include <lib/core/CHIPError.h>
@@ -38,7 +40,13 @@ class MatterContext
3840
MatterContext(EndpointId endpointId) : mEndpointId(endpointId) {}
3941
virtual ~MatterContext() = default;
4042

41-
virtual void MarkDirty(AttributeId attributeId) { MatterReportingAttributeChangeCallback(mEndpointId, Id, attributeId); }
43+
virtual void MarkDirty(AttributeId attributeId)
44+
{
45+
MatterReportingAttributeChangeCallback(mEndpointId, Id, attributeId);
46+
47+
ConcreteAttributePath attributePath(mEndpointId, Id, attributeId);
48+
MatterClosureControlClusterServerAttributeChangedCallback(attributePath);
49+
}
4250

4351
template <typename EventType>
4452
CHIP_ERROR GenerateEvent(EventType event)

src/app/clusters/closure-dimension-server/closure-dimension-matter-context.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
*/
1818

1919
#include "closure-dimension-matter-context.h"
20-
20+
#include <app-common/zap-generated/callback.h>
2121
#include <app-common/zap-generated/ids/Clusters.h>
22+
#include <app/ConcreteAttributePath.h>
2223
#include <app/reporting/reporting.h>
2324

2425
namespace chip {
@@ -29,6 +30,9 @@ namespace ClosureDimension {
2930
void MatterContext::MarkDirty(const AttributeId attributeId)
3031
{
3132
MatterReportingAttributeChangeCallback(mEndpoint, Id, attributeId);
33+
34+
ConcreteAttributePath attributePath(mEndpoint, Id, attributeId);
35+
MatterClosureDimensionClusterServerAttributeChangedCallback(attributePath);
3236
}
3337

3438
} // namespace ClosureDimension

src/app/tests/TestClosureControlClusterLogic.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ class TimerAndMockClock : public Clock::Internal::MockClock, public Layer
106106
} // namespace System
107107
} // namespace chip
108108

109+
// Mock callback functions
110+
__attribute__((unused)) void
111+
MatterClosureControlClusterServerAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath)
112+
{
113+
// Mock implementation - no-op for tests
114+
}
115+
109116
namespace {
110117

111118
// These are globals because SetUpTestSuite is static which requires static variables

src/app/tests/TestClosureDimensionCluster.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,3 +2427,10 @@ TEST_F(TestClosureDimensionClusterLogic, TestCurrentStateQuietReportingSpeedValu
24272427
} // namespace Clusters
24282428
} // namespace app
24292429
} // namespace chip
2430+
2431+
// Mock callback functions
2432+
__attribute__((unused)) void
2433+
MatterClosureDimensionClusterServerAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath)
2434+
{
2435+
// Mock implementation - no-op for tests
2436+
}

0 commit comments

Comments
 (0)