Skip to content

Commit 52449a3

Browse files
committed
add feature map and cluster revision
1 parent 100a967 commit 52449a3

4 files changed

+58
-1
lines changed

src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ CHIP_ERROR ClusterLogic::GetLevelStep(uint8_t & levelStep)
276276
levelStep = mState.GetState().levelStep;
277277
return CHIP_NO_ERROR;
278278
}
279+
CHIP_ERROR ClusterLogic::GetFeatureMap(Attributes::FeatureMap::TypeInfo::Type & featureMap)
280+
{
281+
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
282+
featureMap = mConformance.featureMap;
283+
return CHIP_NO_ERROR;
284+
}
285+
CHIP_ERROR ClusterLogic::GetClusterRevision(Attributes::ClusterRevision::TypeInfo::Type & clusterRevision)
286+
{
287+
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
288+
clusterRevision = kClusterRevision;
289+
return CHIP_NO_ERROR;
290+
}
279291

280292
CHIP_ERROR ClusterLogic::SetDefaultOpenDuration(const DataModel::Nullable<ElapsedS> & defaultOpenDuration)
281293
{

src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "valve-configuration-and-control-delegate.h"
2424
#include "valve-configuration-and-control-matter-context.h"
25+
#include <app-common/zap-generated/cluster-objects.h>
2526
#include <app/cluster-building-blocks/QuieterReporting.h>
2627
#include <app/data-model/Nullable.h>
2728
#include <lib/core/CHIPError.h>
@@ -84,7 +85,7 @@ struct ClusterState
8485
class ClusterStateAttributes
8586
{
8687
public:
87-
explicit ClusterStateAttributes(MatterContext & matterContext) : mMatterContext(matterContext){};
88+
explicit ClusterStateAttributes(MatterContext & matterContext) : mMatterContext(matterContext) {};
8889
void Init(ClusterInitParameters initialState);
8990
const ClusterState & GetState() { return mState; }
9091

@@ -143,6 +144,8 @@ class ClusterLogic
143144
CHIP_ERROR GetDefaultOpenLevel(Percent & defaultOpenLevel);
144145
CHIP_ERROR GetValveFault(BitMask<ValveFaultBitmap> & valveFault);
145146
CHIP_ERROR GetLevelStep(uint8_t & levelStep);
147+
CHIP_ERROR GetFeatureMap(Attributes::FeatureMap::TypeInfo::Type & featureMap);
148+
CHIP_ERROR GetClusterRevision(Attributes::ClusterRevision::TypeInfo::Type & clusterRevision);
146149

147150
// All Set functions
148151
// Return CHIP_ERROR_INCORRECT_STATE if the class has not been initialized.
@@ -181,6 +184,10 @@ class ClusterLogic
181184
CHIP_ERROR HandleCloseCommand();
182185

183186
private:
187+
// This cluster implements version 1 of the valve cluster. Do not change this revision without updating
188+
// the cluster to implement the newest features.
189+
// TODO: consider implementing the server such that multiple revisions can be supported
190+
static constexpr Attributes::ClusterRevision::TypeInfo::Type kClusterRevision = 1u;
184191
// Determines if the level value is allowed per the level step.
185192
bool ValueCompliesWithLevelStep(const uint8_t value);
186193
// Returns the target level to send to the delegate based on the targetLevel command field, the device conformance and the

src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-server-disco.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ CHIP_ERROR Interface::Read(const ConcreteReadAttributePath & aPath, AttributeVal
115115
typedef LevelStep::TypeInfo::Type T;
116116
return EncodeRead<T>(aEncoder, [&logic = mClusterLogic](T & ret) -> CHIP_ERROR { return logic.GetLevelStep(ret); });
117117
}
118+
case FeatureMap::Id: {
119+
typedef FeatureMap::TypeInfo::Type T;
120+
return EncodeRead<T>(aEncoder, [&logic = mClusterLogic](T & ret) -> CHIP_ERROR { return logic.GetFeatureMap(ret); });
121+
}
122+
case ClusterRevision::Id: {
123+
typedef ClusterRevision::TypeInfo::Type T;
124+
return EncodeRead<T>(aEncoder, [&logic = mClusterLogic](T & ret) -> CHIP_ERROR { return logic.GetClusterRevision(ret); });
125+
}
118126
default:
119127
return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute);
120128
}

src/app/tests/TestValveConfigurationAndControl.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ namespace {
105105
// These are globals because SetUpTestSuite is static and I'm not shaving that yak today.
106106
System::TimerAndMockClock gSystemLayerAndClock = System::TimerAndMockClock();
107107
System::Clock::ClockBase * gSavedClock = nullptr;
108+
109+
constexpr uint16_t kExpectedClusterRevision = 1u;
108110
} // namespace
109111

110112
class TestValveConfigurationAndControlClusterLogic : public ::testing::Test
@@ -406,6 +408,8 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesAllFeature
406408
Percent valPercent;
407409
uint8_t val8;
408410
BitMask<ValveFaultBitmap> valBitmap;
411+
Attributes::FeatureMap::TypeInfo::Type featureMap;
412+
Attributes::ClusterRevision::TypeInfo::Type clusterRevision;
409413

410414
EXPECT_EQ(logic.GetOpenDuration(valElapsedSNullable), CHIP_NO_ERROR);
411415
EXPECT_EQ(valElapsedSNullable, DataModel::NullNullable);
@@ -439,6 +443,12 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesAllFeature
439443

440444
EXPECT_EQ(logic.GetLevelStep(val8), CHIP_NO_ERROR);
441445
EXPECT_EQ(val8, 1);
446+
447+
EXPECT_EQ(logic.GetFeatureMap(featureMap), CHIP_NO_ERROR);
448+
EXPECT_EQ(featureMap, conformance.featureMap);
449+
450+
EXPECT_EQ(logic.GetClusterRevision(clusterRevision), CHIP_NO_ERROR);
451+
EXPECT_EQ(clusterRevision, kExpectedClusterRevision);
442452
}
443453

444454
// This test ensures that attributes that are not supported by the conformance properly return errors
@@ -463,6 +473,8 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesNoFeatures
463473
Percent valPercent;
464474
uint8_t val8;
465475
BitMask<ValveFaultBitmap> valBitmap;
476+
Attributes::FeatureMap::TypeInfo::Type featureMap;
477+
Attributes::ClusterRevision::TypeInfo::Type clusterRevision;
466478

467479
EXPECT_EQ(logic.GetOpenDuration(valElapsedSNullable), CHIP_NO_ERROR);
468480
EXPECT_EQ(valElapsedSNullable, DataModel::NullNullable);
@@ -490,6 +502,12 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesNoFeatures
490502
EXPECT_EQ(logic.GetValveFault(valBitmap), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
491503

492504
EXPECT_EQ(logic.GetLevelStep(val8), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
505+
506+
EXPECT_EQ(logic.GetFeatureMap(featureMap), CHIP_NO_ERROR);
507+
EXPECT_EQ(featureMap, conformance.featureMap);
508+
509+
EXPECT_EQ(logic.GetClusterRevision(clusterRevision), CHIP_NO_ERROR);
510+
EXPECT_EQ(clusterRevision, kExpectedClusterRevision);
493511
}
494512

495513
// This test ensures that all attribute getters return the given starting state values before changes.
@@ -526,6 +544,8 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesStartingSt
526544
Percent valPercent;
527545
uint8_t val8;
528546
BitMask<ValveFaultBitmap> valBitmap;
547+
Attributes::FeatureMap::TypeInfo::Type featureMap;
548+
Attributes::ClusterRevision::TypeInfo::Type clusterRevision;
529549

530550
EXPECT_EQ(logic.GetOpenDuration(valElapsedSNullable), CHIP_NO_ERROR);
531551
EXPECT_EQ(valElapsedSNullable, state.openDuration);
@@ -559,6 +579,12 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesStartingSt
559579

560580
EXPECT_EQ(logic.GetLevelStep(val8), CHIP_NO_ERROR);
561581
EXPECT_EQ(val8, state.levelStep);
582+
583+
EXPECT_EQ(logic.GetFeatureMap(featureMap), CHIP_NO_ERROR);
584+
EXPECT_EQ(featureMap, conformance.featureMap);
585+
586+
EXPECT_EQ(logic.GetClusterRevision(clusterRevision), CHIP_NO_ERROR);
587+
EXPECT_EQ(clusterRevision, kExpectedClusterRevision);
562588
}
563589

564590
// This test ensures that all attribute getter functions properly error on an uninitialized cluster.
@@ -576,6 +602,8 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesUninitiali
576602
Percent valPercent;
577603
uint8_t val8;
578604
BitMask<ValveFaultBitmap> valBitmap;
605+
Attributes::FeatureMap::TypeInfo::Type featureMap;
606+
Attributes::ClusterRevision::TypeInfo::Type clusterRevision;
579607

580608
EXPECT_EQ(logic.GetOpenDuration(valElapsedSNullable), CHIP_ERROR_INCORRECT_STATE);
581609
EXPECT_EQ(logic.GetDefaultOpenDuration(valElapsedSNullable), CHIP_ERROR_INCORRECT_STATE);
@@ -588,6 +616,8 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesUninitiali
588616
EXPECT_EQ(logic.GetDefaultOpenLevel(valPercent), CHIP_ERROR_INCORRECT_STATE);
589617
EXPECT_EQ(logic.GetValveFault(valBitmap), CHIP_ERROR_INCORRECT_STATE);
590618
EXPECT_EQ(logic.GetLevelStep(val8), CHIP_ERROR_INCORRECT_STATE);
619+
EXPECT_EQ(logic.GetFeatureMap(featureMap), CHIP_ERROR_INCORRECT_STATE);
620+
EXPECT_EQ(logic.GetClusterRevision(clusterRevision), CHIP_ERROR_INCORRECT_STATE);
591621
}
592622

593623
//=========================================================================================

0 commit comments

Comments
 (0)