Skip to content

Commit

Permalink
add feature map and cluster revision
Browse files Browse the repository at this point in the history
  • Loading branch information
cecille committed Sep 26, 2024
1 parent 100a967 commit 52449a3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,18 @@ CHIP_ERROR ClusterLogic::GetLevelStep(uint8_t & levelStep)
levelStep = mState.GetState().levelStep;
return CHIP_NO_ERROR;
}
CHIP_ERROR ClusterLogic::GetFeatureMap(Attributes::FeatureMap::TypeInfo::Type & featureMap)
{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
featureMap = mConformance.featureMap;
return CHIP_NO_ERROR;
}
CHIP_ERROR ClusterLogic::GetClusterRevision(Attributes::ClusterRevision::TypeInfo::Type & clusterRevision)
{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
clusterRevision = kClusterRevision;
return CHIP_NO_ERROR;
}

CHIP_ERROR ClusterLogic::SetDefaultOpenDuration(const DataModel::Nullable<ElapsedS> & defaultOpenDuration)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "valve-configuration-and-control-delegate.h"
#include "valve-configuration-and-control-matter-context.h"
#include <app-common/zap-generated/cluster-objects.h>
#include <app/cluster-building-blocks/QuieterReporting.h>
#include <app/data-model/Nullable.h>
#include <lib/core/CHIPError.h>
Expand Down Expand Up @@ -84,7 +85,7 @@ struct ClusterState
class ClusterStateAttributes
{
public:
explicit ClusterStateAttributes(MatterContext & matterContext) : mMatterContext(matterContext){};
explicit ClusterStateAttributes(MatterContext & matterContext) : mMatterContext(matterContext) {};
void Init(ClusterInitParameters initialState);
const ClusterState & GetState() { return mState; }

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

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

private:
// This cluster implements version 1 of the valve cluster. Do not change this revision without updating
// the cluster to implement the newest features.
// TODO: consider implementing the server such that multiple revisions can be supported
static constexpr Attributes::ClusterRevision::TypeInfo::Type kClusterRevision = 1u;
// Determines if the level value is allowed per the level step.
bool ValueCompliesWithLevelStep(const uint8_t value);
// Returns the target level to send to the delegate based on the targetLevel command field, the device conformance and the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ CHIP_ERROR Interface::Read(const ConcreteReadAttributePath & aPath, AttributeVal
typedef LevelStep::TypeInfo::Type T;
return EncodeRead<T>(aEncoder, [&logic = mClusterLogic](T & ret) -> CHIP_ERROR { return logic.GetLevelStep(ret); });
}
case FeatureMap::Id: {
typedef FeatureMap::TypeInfo::Type T;
return EncodeRead<T>(aEncoder, [&logic = mClusterLogic](T & ret) -> CHIP_ERROR { return logic.GetFeatureMap(ret); });
}
case ClusterRevision::Id: {
typedef ClusterRevision::TypeInfo::Type T;
return EncodeRead<T>(aEncoder, [&logic = mClusterLogic](T & ret) -> CHIP_ERROR { return logic.GetClusterRevision(ret); });
}
default:
return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute);
}
Expand Down
30 changes: 30 additions & 0 deletions src/app/tests/TestValveConfigurationAndControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ namespace {
// These are globals because SetUpTestSuite is static and I'm not shaving that yak today.
System::TimerAndMockClock gSystemLayerAndClock = System::TimerAndMockClock();
System::Clock::ClockBase * gSavedClock = nullptr;

constexpr uint16_t kExpectedClusterRevision = 1u;
} // namespace

class TestValveConfigurationAndControlClusterLogic : public ::testing::Test
Expand Down Expand Up @@ -406,6 +408,8 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesAllFeature
Percent valPercent;
uint8_t val8;
BitMask<ValveFaultBitmap> valBitmap;
Attributes::FeatureMap::TypeInfo::Type featureMap;
Attributes::ClusterRevision::TypeInfo::Type clusterRevision;

EXPECT_EQ(logic.GetOpenDuration(valElapsedSNullable), CHIP_NO_ERROR);
EXPECT_EQ(valElapsedSNullable, DataModel::NullNullable);
Expand Down Expand Up @@ -439,6 +443,12 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesAllFeature

EXPECT_EQ(logic.GetLevelStep(val8), CHIP_NO_ERROR);
EXPECT_EQ(val8, 1);

EXPECT_EQ(logic.GetFeatureMap(featureMap), CHIP_NO_ERROR);
EXPECT_EQ(featureMap, conformance.featureMap);

EXPECT_EQ(logic.GetClusterRevision(clusterRevision), CHIP_NO_ERROR);
EXPECT_EQ(clusterRevision, kExpectedClusterRevision);
}

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

EXPECT_EQ(logic.GetOpenDuration(valElapsedSNullable), CHIP_NO_ERROR);
EXPECT_EQ(valElapsedSNullable, DataModel::NullNullable);
Expand Down Expand Up @@ -490,6 +502,12 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesNoFeatures
EXPECT_EQ(logic.GetValveFault(valBitmap), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);

EXPECT_EQ(logic.GetLevelStep(val8), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);

EXPECT_EQ(logic.GetFeatureMap(featureMap), CHIP_NO_ERROR);
EXPECT_EQ(featureMap, conformance.featureMap);

EXPECT_EQ(logic.GetClusterRevision(clusterRevision), CHIP_NO_ERROR);
EXPECT_EQ(clusterRevision, kExpectedClusterRevision);
}

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

EXPECT_EQ(logic.GetOpenDuration(valElapsedSNullable), CHIP_NO_ERROR);
EXPECT_EQ(valElapsedSNullable, state.openDuration);
Expand Down Expand Up @@ -559,6 +579,12 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesStartingSt

EXPECT_EQ(logic.GetLevelStep(val8), CHIP_NO_ERROR);
EXPECT_EQ(val8, state.levelStep);

EXPECT_EQ(logic.GetFeatureMap(featureMap), CHIP_NO_ERROR);
EXPECT_EQ(featureMap, conformance.featureMap);

EXPECT_EQ(logic.GetClusterRevision(clusterRevision), CHIP_NO_ERROR);
EXPECT_EQ(clusterRevision, kExpectedClusterRevision);
}

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

EXPECT_EQ(logic.GetOpenDuration(valElapsedSNullable), CHIP_ERROR_INCORRECT_STATE);
EXPECT_EQ(logic.GetDefaultOpenDuration(valElapsedSNullable), CHIP_ERROR_INCORRECT_STATE);
Expand All @@ -588,6 +616,8 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesUninitiali
EXPECT_EQ(logic.GetDefaultOpenLevel(valPercent), CHIP_ERROR_INCORRECT_STATE);
EXPECT_EQ(logic.GetValveFault(valBitmap), CHIP_ERROR_INCORRECT_STATE);
EXPECT_EQ(logic.GetLevelStep(val8), CHIP_ERROR_INCORRECT_STATE);
EXPECT_EQ(logic.GetFeatureMap(featureMap), CHIP_ERROR_INCORRECT_STATE);
EXPECT_EQ(logic.GetClusterRevision(clusterRevision), CHIP_ERROR_INCORRECT_STATE);
}

//=========================================================================================
Expand Down

0 comments on commit 52449a3

Please sign in to comment.