Skip to content
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

Remove RemovedOn attribute from ECOINFO cluster #34988

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();

// Declare Ecosystem Information cluster attributes
DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(ecosystemInformationBasicAttrs)
DECLARE_DYNAMIC_ATTRIBUTE(EcosystemInformation::Attributes::RemovedOn::Id, EPOCH_US, kNodeLabelSize, ATTRIBUTE_MASK_NULLABLE),
DECLARE_DYNAMIC_ATTRIBUTE(EcosystemInformation::Attributes::DeviceDirectory::Id, ARRAY, kDescriptorAttributeArraySize, 0),
DECLARE_DYNAMIC_ATTRIBUTE(EcosystemInformation::Attributes::LocationDirectory::Id, ARRAY, kDescriptorAttributeArraySize, 0),
DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,21 +279,10 @@ CHIP_ERROR EcosystemInformationServer::AddLocationInfo(EndpointId aEndpoint, con
return CHIP_NO_ERROR;
}

CHIP_ERROR EcosystemInformationServer::RemoveDevice(EndpointId aEndpoint, uint64_t aEpochUs)
{
auto it = mDevicesMap.find(aEndpoint);
VerifyOrReturnError((it != mDevicesMap.end()), CHIP_ERROR_INVALID_ARGUMENT);
auto & deviceInfo = it->second;
deviceInfo.mRemovedOn.SetValue(aEpochUs);
return CHIP_NO_ERROR;
}

CHIP_ERROR EcosystemInformationServer::ReadAttribute(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
{
switch (aPath.mAttributeId)
{
case Attributes::RemovedOn::Id:
return EncodeRemovedOnAttribute(aPath.mEndpointId, aEncoder);
case Attributes::DeviceDirectory::Id:
return EncodeDeviceDirectoryAttribute(aPath.mEndpointId, aEncoder);
case Attributes::LocationDirectory::Id:
Expand All @@ -312,28 +301,6 @@ CHIP_ERROR EcosystemInformationServer::ReadAttribute(const ConcreteReadAttribute
return CHIP_NO_ERROR;
}

CHIP_ERROR EcosystemInformationServer::EncodeRemovedOnAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder)
{
auto it = mDevicesMap.find(aEndpoint);
if (it == mDevicesMap.end())
{
// We are always going to be given a valid endpoint. If the endpoint
// doesn't exist in our map that indicate that the cluster was not
// added on this endpoint, hence UnsupportedCluster.
return CHIP_IM_GLOBAL_STATUS(UnsupportedCluster);
}

auto & deviceInfo = it->second;
if (!deviceInfo.mRemovedOn.HasValue())
{
aEncoder.EncodeNull();
return CHIP_NO_ERROR;
}

aEncoder.Encode(deviceInfo.mRemovedOn.Value());
return CHIP_NO_ERROR;
}

CHIP_ERROR EcosystemInformationServer::EncodeDeviceDirectoryAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder)
{

Expand All @@ -347,7 +314,7 @@ CHIP_ERROR EcosystemInformationServer::EncodeDeviceDirectoryAttribute(EndpointId
}

auto & deviceInfo = it->second;
if (deviceInfo.mDeviceDirectory.empty() || deviceInfo.mRemovedOn.HasValue())
if (deviceInfo.mDeviceDirectory.empty())
{
return aEncoder.EncodeEmptyList();
}
Expand All @@ -374,7 +341,7 @@ CHIP_ERROR EcosystemInformationServer::EncodeLocationStructAttribute(EndpointId
}

auto & deviceInfo = it->second;
if (deviceInfo.mLocationDirectory.empty() || deviceInfo.mRemovedOn.HasValue())
if (deviceInfo.mLocationDirectory.empty())
{
return aEncoder.EncodeEmptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,30 +188,18 @@ class EcosystemInformationServer
*/
CHIP_ERROR AddLocationInfo(EndpointId aEndpoint, const std::string & aLocationId,
std::unique_ptr<EcosystemLocationStruct> aLocation);

/**
* @brief Removes device at the provided endpoint.
*
* @param aEndpoint Endpoint of the associated device that has been removed.
* @param aEpochUs Epoch time in micro seconds assoicated with when device was removed.
* @return #CHIP_NO_ERROR on success.
* @return Other CHIP_ERROR associated with issue.
*/
CHIP_ERROR RemoveDevice(EndpointId aEndpoint, uint64_t aEpochUs);
// TODO(#33223) Add removal and update counterparts to AddDeviceInfo and AddLocationInfo.

CHIP_ERROR ReadAttribute(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder);

private:
struct DeviceInfo
{
Optional<uint64_t> mRemovedOn = NullOptional;
std::vector<std::unique_ptr<EcosystemDeviceStruct>> mDeviceDirectory;
// Map key is using the UniqueLocationId
std::map<std::string, std::unique_ptr<EcosystemLocationStruct>> mLocationDirectory;
};

CHIP_ERROR EncodeRemovedOnAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);
CHIP_ERROR EncodeDeviceDirectoryAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);
CHIP_ERROR EncodeLocationStructAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ limitations under the License.
<server init="false" tick="false">true</server>
<!-- cluster revision -->
<globalAttribute code="0xFFFD" side="either" value="1"/>
<attribute code="0x0000" side="server" define="REMOVED_ON" type="epoch_us" isNullable="true" optional="true">
<description>RemovedOn</description>
<access op="read" privilege="manage"/>
</attribute>
<!-- RemovedOn with code 0x0000 is deprecated -->
<attribute code="0x0001" side="server" define="DEVICE_DIRECTORY" type="array" entryType="EcosystemDeviceStruct" length="256" minLength="1">
<description>DeviceDirectory</description>
<access op="read" privilege="manage"/>
Expand Down
1 change: 0 additions & 1 deletion src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -9395,7 +9395,6 @@ provisional cluster EcosystemInformation = 1872 {
fabric_idx fabricIndex = 254;
}

readonly attribute access(read: manage) optional nullable epoch_us removedOn = 0;
readonly attribute access(read: manage) EcosystemDeviceStruct deviceDirectory[] = 1;
readonly attribute access(read: manage) EcosystemLocationStruct locationDirectory[] = 2;
readonly attribute command_id generatedCommandList[] = 65528;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60768,7 +60768,6 @@ public void onSuccess(byte[] tlv) {
public static class EcosystemInformationCluster extends BaseChipCluster {
public static final long CLUSTER_ID = 1872L;

private static final long REMOVED_ON_ATTRIBUTE_ID = 0L;
private static final long DEVICE_DIRECTORY_ATTRIBUTE_ID = 1L;
private static final long LOCATION_DIRECTORY_ATTRIBUTE_ID = 2L;
private static final long GENERATED_COMMAND_LIST_ATTRIBUTE_ID = 65528L;
Expand All @@ -60788,10 +60787,6 @@ public long initWithDevice(long devicePtr, int endpointId) {
return 0L;
}

public interface RemovedOnAttributeCallback extends BaseAttributeCallback {
void onSuccess(@Nullable Long value);
}

public interface DeviceDirectoryAttributeCallback extends BaseAttributeCallback {
void onSuccess(List<ChipStructs.EcosystemInformationClusterEcosystemDeviceStruct> value);
}
Expand All @@ -60816,32 +60811,6 @@ public interface AttributeListAttributeCallback extends BaseAttributeCallback {
void onSuccess(List<Long> value);
}

public void readRemovedOnAttribute(
RemovedOnAttributeCallback callback) {
ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, REMOVED_ON_ATTRIBUTE_ID);

readAttribute(new ReportCallbackImpl(callback, path) {
@Override
public void onSuccess(byte[] tlv) {
@Nullable Long value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv);
callback.onSuccess(value);
}
}, REMOVED_ON_ATTRIBUTE_ID, true);
}

public void subscribeRemovedOnAttribute(
RemovedOnAttributeCallback callback, int minInterval, int maxInterval) {
ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, REMOVED_ON_ATTRIBUTE_ID);

subscribeAttribute(new ReportCallbackImpl(callback, path) {
@Override
public void onSuccess(byte[] tlv) {
@Nullable Long value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv);
callback.onSuccess(value);
}
}, REMOVED_ON_ATTRIBUTE_ID, minInterval, maxInterval);
}

public void readDeviceDirectoryAttribute(
DeviceDirectoryAttributeCallback callback) {
readDeviceDirectoryAttributeWithFabricFilter(callback, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17237,7 +17237,6 @@ public long getID() {
}

public enum Attribute {
RemovedOn(0L),
DeviceDirectory(1L),
LocationDirectory(2L),
GeneratedCommandList(65528L),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20222,27 +20222,6 @@ public void onError(Exception ex) {
}
}

public static class DelegatedEcosystemInformationClusterRemovedOnAttributeCallback implements ChipClusters.EcosystemInformationCluster.RemovedOnAttributeCallback, DelegatedClusterCallback {
private ClusterCommandCallback callback;
@Override
public void setCallbackDelegate(ClusterCommandCallback callback) {
this.callback = callback;
}

@Override
public void onSuccess(@Nullable Long value) {
Map<CommandResponseInfo, Object> responseValues = new LinkedHashMap<>();
CommandResponseInfo commandResponseInfo = new CommandResponseInfo("value", "Long");
responseValues.put(commandResponseInfo, value);
callback.onSuccess(responseValues);
}

@Override
public void onError(Exception ex) {
callback.onFailure(ex);
}
}

public static class DelegatedEcosystemInformationClusterDeviceDirectoryAttributeCallback implements ChipClusters.EcosystemInformationCluster.DeviceDirectoryAttributeCallback, DelegatedClusterCallback {
private ClusterCommandCallback callback;
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18678,18 +18678,7 @@ private static Map<String, InteractionInfo> readContentAppObserverInteractionInf
return result;
}
private static Map<String, InteractionInfo> readEcosystemInformationInteractionInfo() {
Map<String, InteractionInfo> result = new LinkedHashMap<>();Map<String, CommandParameterInfo> readEcosystemInformationRemovedOnCommandParams = new LinkedHashMap<String, CommandParameterInfo>();
InteractionInfo readEcosystemInformationRemovedOnAttributeInteractionInfo = new InteractionInfo(
(cluster, callback, commandArguments) -> {
((ChipClusters.EcosystemInformationCluster) cluster).readRemovedOnAttribute(
(ChipClusters.EcosystemInformationCluster.RemovedOnAttributeCallback) callback
);
},
() -> new ClusterInfoMapping.DelegatedEcosystemInformationClusterRemovedOnAttributeCallback(),
readEcosystemInformationRemovedOnCommandParams
);
result.put("readRemovedOnAttribute", readEcosystemInformationRemovedOnAttributeInteractionInfo);
Map<String, CommandParameterInfo> readEcosystemInformationDeviceDirectoryCommandParams = new LinkedHashMap<String, CommandParameterInfo>();
Map<String, InteractionInfo> result = new LinkedHashMap<>();Map<String, CommandParameterInfo> readEcosystemInformationDeviceDirectoryCommandParams = new LinkedHashMap<String, CommandParameterInfo>();
InteractionInfo readEcosystemInformationDeviceDirectoryAttributeInteractionInfo = new InteractionInfo(
(cluster, callback, commandArguments) -> {
((ChipClusters.EcosystemInformationCluster) cluster).readDeviceDirectoryAttribute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ class EcosystemInformationCluster(
private val controller: MatterController,
private val endpointId: UShort,
) {
class RemovedOnAttribute(val value: ULong?)

sealed class RemovedOnAttributeSubscriptionState {
data class Success(val value: ULong?) : RemovedOnAttributeSubscriptionState()

data class Error(val exception: Exception) : RemovedOnAttributeSubscriptionState()

object SubscriptionEstablished : RemovedOnAttributeSubscriptionState()
}

class DeviceDirectoryAttribute(val value: List<EcosystemInformationClusterEcosystemDeviceStruct>)

sealed class DeviceDirectoryAttributeSubscriptionState {
Expand Down Expand Up @@ -112,107 +102,6 @@ class EcosystemInformationCluster(
object SubscriptionEstablished : AttributeListAttributeSubscriptionState()
}

suspend fun readRemovedOnAttribute(): RemovedOnAttribute {
val ATTRIBUTE_ID: UInt = 0u

val attributePath =
AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID)

val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath))

val response = controller.read(readRequest)

if (response.successes.isEmpty()) {
logger.log(Level.WARNING, "Read command failed")
throw IllegalStateException("Read command failed with failures: ${response.failures}")
}

logger.log(Level.FINE, "Read command succeeded")

val attributeData =
response.successes.filterIsInstance<ReadData.Attribute>().firstOrNull {
it.path.attributeId == ATTRIBUTE_ID
}

requireNotNull(attributeData) { "Removedon attribute not found in response" }

// Decode the TLV data into the appropriate type
val tlvReader = TlvReader(attributeData.data)
val decodedValue: ULong? =
if (!tlvReader.isNull()) {
if (tlvReader.isNextTag(AnonymousTag)) {
tlvReader.getULong(AnonymousTag)
} else {
null
}
} else {
tlvReader.getNull(AnonymousTag)
null
}

return RemovedOnAttribute(decodedValue)
}

suspend fun subscribeRemovedOnAttribute(
minInterval: Int,
maxInterval: Int,
): Flow<RemovedOnAttributeSubscriptionState> {
val ATTRIBUTE_ID: UInt = 0u
val attributePaths =
listOf(
AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID)
)

val subscribeRequest: SubscribeRequest =
SubscribeRequest(
eventPaths = emptyList(),
attributePaths = attributePaths,
minInterval = Duration.ofSeconds(minInterval.toLong()),
maxInterval = Duration.ofSeconds(maxInterval.toLong()),
)

return controller.subscribe(subscribeRequest).transform { subscriptionState ->
when (subscriptionState) {
is SubscriptionState.SubscriptionErrorNotification -> {
emit(
RemovedOnAttributeSubscriptionState.Error(
Exception(
"Subscription terminated with error code: ${subscriptionState.terminationCause}"
)
)
)
}
is SubscriptionState.NodeStateUpdate -> {
val attributeData =
subscriptionState.updateState.successes
.filterIsInstance<ReadData.Attribute>()
.firstOrNull { it.path.attributeId == ATTRIBUTE_ID }

requireNotNull(attributeData) { "Removedon attribute not found in Node State update" }

// Decode the TLV data into the appropriate type
val tlvReader = TlvReader(attributeData.data)
val decodedValue: ULong? =
if (!tlvReader.isNull()) {
if (tlvReader.isNextTag(AnonymousTag)) {
tlvReader.getULong(AnonymousTag)
} else {
null
}
} else {
tlvReader.getNull(AnonymousTag)
null
}

decodedValue?.let { emit(RemovedOnAttributeSubscriptionState.Success(it)) }
}
SubscriptionState.SubscriptionEstablished -> {
emit(RemovedOnAttributeSubscriptionState.SubscriptionEstablished)
}
}
}
}

suspend fun readDeviceDirectoryAttribute(): DeviceDirectoryAttribute {
val ATTRIBUTE_ID: UInt = 1u

Expand Down
23 changes: 0 additions & 23 deletions src/controller/java/zap-generated/CHIPAttributeTLVValueDecoder.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading