Skip to content

Commit a1a3929

Browse files
committed
Fix ecosystem information cluster when reading cluster revision
1 parent d31f7be commit a1a3929

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp

+32-16
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ namespace Clusters {
2626
namespace EcosystemInformation {
2727
namespace {
2828

29+
#define ZCL_ECOSYSTEM_INFORMATION_CLUSTER_REVISION (1u)
30+
#define ZCL_ECOSYSTEM_INFORMATION_FEATURE_MAP (0u)
31+
2932
constexpr size_t kDeviceNameMaxSize = 64;
3033
constexpr size_t kUniqueLocationIdMaxSize = 64;
3134
constexpr size_t kUniqueLocationIdsListMaxSize = 64;
@@ -46,18 +49,7 @@ class AttrAccess : public AttributeAccessInterface
4649
CHIP_ERROR AttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
4750
{
4851
VerifyOrDie(aPath.mClusterId == Clusters::EcosystemInformation::Id);
49-
switch (aPath.mAttributeId)
50-
{
51-
case Attributes::RemovedOn::Id:
52-
return EcosystemInformationServer::Instance().EncodeRemovedOnAttribute(aPath.mEndpointId, aEncoder);
53-
case Attributes::DeviceDirectory ::Id:
54-
return EcosystemInformationServer::Instance().EncodeDeviceDirectoryAttribute(aPath.mEndpointId, aEncoder);
55-
case Attributes::LocationDirectory ::Id:
56-
return EcosystemInformationServer::Instance().EncodeLocationStructAttribute(aPath.mEndpointId, aEncoder);
57-
default:
58-
break;
59-
}
60-
return CHIP_NO_ERROR;
52+
return EcosystemInformationServer::Instance().ReadAttribute(aPath, aEncoder);
6153
}
6254

6355
// WARNING: caller is expected to use the returned LocationDescriptorStruct::Type immediately. Caller must
@@ -66,8 +58,7 @@ CHIP_ERROR AttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeVa
6658
// TODO(#33223) To improve safety we could make GetEncodableLocationDescriptorStruct a private
6759
// memeber method where we explicitly delete member method for the parameter that matches
6860
// (LocationDescriptorStruct && aLocationDescriptor).
69-
Globals::Structs::LocationDescriptorStruct::Type
70-
GetEncodableLocationDescriptorStruct(const LocationDescriptorStruct & aLocationDescriptor)
61+
Globals::Structs::LocationDescriptorStruct::Type GetEncodableLocationDescriptorStruct(const LocationDescriptorStruct & aLocationDescriptor)
7162
{
7263
Globals::Structs::LocationDescriptorStruct::Type locationDescriptor;
7364
// This would imply data is either not properly validated before being
@@ -200,8 +191,7 @@ EcosystemLocationStruct::Builder & EcosystemLocationStruct::Builder::SetFloorNum
200191
return *this;
201192
}
202193

203-
EcosystemLocationStruct::Builder &
204-
EcosystemLocationStruct::Builder::SetAreaTypeTag(std::optional<Globals::AreaTypeTag> aAreaTypeTag)
194+
EcosystemLocationStruct::Builder & EcosystemLocationStruct::Builder::SetAreaTypeTag(std::optional<Globals::AreaTypeTag> aAreaTypeTag)
205195
{
206196
VerifyOrDie(!mIsAlreadyBuilt);
207197
mLocationDescriptor.mAreaType = aAreaTypeTag;
@@ -285,6 +275,32 @@ CHIP_ERROR EcosystemInformationServer::RemoveDevice(EndpointId aEndpoint, uint64
285275
return CHIP_NO_ERROR;
286276
}
287277

278+
CHIP_ERROR EcosystemInformationServer::ReadAttribute(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
279+
{
280+
switch (aPath.mAttributeId)
281+
{
282+
case Attributes::RemovedOn::Id:
283+
return EcosystemInformationServer::Instance().EncodeRemovedOnAttribute(aPath.mEndpointId, aEncoder);
284+
case Attributes::DeviceDirectory::Id:
285+
return EcosystemInformationServer::Instance().EncodeDeviceDirectoryAttribute(aPath.mEndpointId, aEncoder);
286+
case Attributes::LocationDirectory::Id:
287+
return EcosystemInformationServer::Instance().EncodeLocationStructAttribute(aPath.mEndpointId, aEncoder);
288+
case Attributes::ClusterRevision::Id:
289+
{
290+
uint16_t rev = ZCL_ECOSYSTEM_INFORMATION_CLUSTER_REVISION;
291+
return aEncoder.Encode(rev);
292+
}
293+
case Attributes::FeatureMap::Id:
294+
{
295+
uint32_t featureMap = ZCL_ECOSYSTEM_INFORMATION_FEATURE_MAP;
296+
return aEncoder.Encode(featureMap);
297+
}
298+
default:
299+
break;
300+
}
301+
return CHIP_NO_ERROR;
302+
}
303+
288304
CHIP_ERROR EcosystemInformationServer::EncodeRemovedOnAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder)
289305
{
290306
auto it = mDevicesMap.find(aEndpoint);

src/app/clusters/ecosystem-information-server/ecosystem-information-server.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,7 @@ class EcosystemInformationServer
182182
CHIP_ERROR RemoveDevice(EndpointId aEndpoint, uint64_t aEpochUs);
183183
// TODO(#33223) Add removal and update counterparts to AddDeviceInfo and AddLocationInfo.
184184

185-
CHIP_ERROR EncodeRemovedOnAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);
186-
CHIP_ERROR EncodeDeviceDirectoryAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);
187-
CHIP_ERROR EncodeLocationStructAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);
185+
CHIP_ERROR ReadAttribute(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder);
188186

189187
private:
190188
struct DeviceInfo
@@ -194,6 +192,11 @@ class EcosystemInformationServer
194192
// Map key is using the UniqueLocationId
195193
std::map<std::string, std::unique_ptr<EcosystemLocationStruct>> mLocationDirectory;
196194
};
195+
196+
CHIP_ERROR EncodeRemovedOnAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);
197+
CHIP_ERROR EncodeDeviceDirectoryAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);
198+
CHIP_ERROR EncodeLocationStructAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);
199+
197200
std::map<EndpointId, DeviceInfo> mDevicesMap;
198201

199202
static EcosystemInformationServer mInstance;

0 commit comments

Comments
 (0)