Skip to content

Commit

Permalink
[Android] Remove ChipIdLookup class from ZAP generation (#27588)
Browse files Browse the repository at this point in the history
* Modify ChipIdLookup class

* Restyled by google-java-format

* Add unknown cluster string

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
joonhaengHeo and restyled-commits authored Jul 4, 2023
1 parent 0522ef0 commit a9773c9
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 7,822 deletions.
2 changes: 1 addition & 1 deletion src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ android_library("java") {
"src/chip/devicecontroller/ChipCommandType.java",
"src/chip/devicecontroller/ChipDeviceController.java",
"src/chip/devicecontroller/ChipDeviceControllerException.java",
"src/chip/devicecontroller/ChipIdLookup.java",
"src/chip/devicecontroller/ControllerParams.java",
"src/chip/devicecontroller/DeviceAttestationDelegate.java",
"src/chip/devicecontroller/DiscoveredDevice.java",
Expand Down Expand Up @@ -345,7 +346,6 @@ android_library("java") {
"src/chip/devicecontroller/model/NodeState.java",
"zap-generated/chip/devicecontroller/ChipClusters.java",
"zap-generated/chip/devicecontroller/ChipEventStructs.java",
"zap-generated/chip/devicecontroller/ChipIdLookup.java",
"zap-generated/chip/devicecontroller/ChipStructs.java",
"zap-generated/chip/devicecontroller/ClusterInfoMapping.java",
]
Expand Down
67 changes: 67 additions & 0 deletions src/controller/java/src/chip/devicecontroller/ChipIdLookup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package chip.devicecontroller;

public final class ChipIdLookup {
/**
* Translates cluster ID to a cluster name in upper camel case. If no matching ID is found,
* returns an empty string.
*/
public static String clusterIdToName(long clusterId) {
ClusterIDMapping.BaseCluster cluster = ClusterIDMapping.getCluster(clusterId);
if (cluster == null) {
return String.format("UNKNOWN_CLUSTER(%d)", clusterId);
}

return cluster.getClass().getSimpleName();
}

/**
* Translates cluster ID and attribute ID to an attribute name in upper camel case. If no matching
* IDs are found, returns an empty string.
*/
public static String attributeIdToName(long clusterId, long attributeId) {
ClusterIDMapping.BaseCluster cluster = ClusterIDMapping.getCluster(clusterId);
if (cluster == null) {
return String.format("UNKNOWN_CLUSTER(%d)", clusterId);
}

try {
return cluster.getAttributeName(attributeId);
} catch (NoSuchFieldError e) {
return String.format("UNKNOWN_ATTRIBUTE(%d, %d)", clusterId, attributeId);
}
}

/**
* Translates cluster ID and event ID to an attribute name in upper camel case. If no matching IDs
* are found, returns an empty string.
*/
public static String eventIdToName(long clusterId, long eventId) {
ClusterIDMapping.BaseCluster cluster = ClusterIDMapping.getCluster(clusterId);
if (cluster == null) {
return String.format("UNKNOWN_CLUSTER(%d)", clusterId);
}

try {
return cluster.getEventName(eventId);
} catch (NoSuchFieldError e) {
return String.format("UNKNOWN_EVENT(%d, %d)", clusterId, eventId);
}
}
}
54 changes: 0 additions & 54 deletions src/controller/java/templates/ChipIdLookup-java.zapt

This file was deleted.

5 changes: 0 additions & 5 deletions src/controller/java/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@
"name": "CHIP ZCL API for Java",
"output": "src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java"
},
{
"path": "ChipIdLookup-java.zapt",
"name": "Generate utilities for looking up cluster/attribute IDs",
"output": "src/controller/java/zap-generated/chip/devicecontroller/ChipIdLookup.java"
},
{
"path": "ClusterInfo-java.zapt",
"name": "Cluster information mapping for Java",
Expand Down
Loading

0 comments on commit a9773c9

Please sign in to comment.