Skip to content

Commit 03b2a3f

Browse files
Add ways to get a command name by ID, for known commands, to Matter.framework.
1 parent 83159c2 commit 03b2a3f

File tree

4 files changed

+4037
-0
lines changed

4 files changed

+4037
-0
lines changed

src/darwin/Framework/CHIP/MTRClusterNames.h

+18
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ MTR_EXTERN MTR_AVAILABLE(ios(17.6), macos(14.6), watchos(10.6), tvos(17.6)) NSSt
4242
*/
4343
MTR_EXTERN MTR_AVAILABLE(ios(17.6), macos(14.6), watchos(10.6), tvos(17.6)) NSString * MTRAttributeNameForID(MTRClusterIDType clusterID, MTRAttributeIDType attributeID);
4444

45+
/**
46+
* Resolve Matter request (client to server) command IDs into a descriptive string.
47+
*
48+
* For unknown IDs, a string '<Unknown clusterID %d>' (if the cluster ID is not known)
49+
* or '<Unknown commandID %d>' (if the cluster ID is known but the command ID is not known)
50+
* will be returned.
51+
*/
52+
MTR_EXTERN MTR_NEWLY_AVAILABLE NSString * MTRRequestCommandNameForID(MTRClusterIDType clusterID, MTRCommandIDType commandID);
53+
54+
/**
55+
* Resolve Matter response (server to client) command IDs into a descriptive string.
56+
*
57+
* For unknown IDs, a string '<Unknown clusterID %d>' (if the cluster ID is not known)
58+
* or '<Unknown commandID %d>' (if the cluster ID is known but the command ID is not known)
59+
* will be returned.
60+
*/
61+
MTR_EXTERN MTR_NEWLY_AVAILABLE NSString * MTRResponseCommandNameForID(MTRClusterIDType clusterID, MTRCommandIDType commandID);
62+
4563
/**
4664
* Resolve Matter event IDs into a descriptive string.
4765
*

src/darwin/Framework/CHIP/templates/MTRClusterNames-src.zapt

+56
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,62 @@ NSString * MTRAttributeNameForID(MTRClusterIDType clusterID, MTRAttributeIDType
8787
return result;
8888
}
8989

90+
#pragma mark - Command IDs
91+
92+
{{!Takes "source" as an argument, can be "client" or "server"}}
93+
{{~#*inline "commandIDOutput"}}
94+
NSString * result = nil;
95+
96+
switch (clusterID) {
97+
98+
{{#zcl_clusters}}
99+
{{#if (isSupported (asUpperCamelCase label preserveAcronyms=true) isForIds=true)}}
100+
{{~#*inline "cluster"}}{{asUpperCamelCase label preserveAcronyms=true}}{{/inline~}}
101+
case MTRClusterIDType{{>cluster}}ID:
102+
103+
switch (commandID) {
104+
105+
{{#*inline "commandIDs"}}
106+
{{#zcl_commands}}
107+
{{~#*inline "cluster"}}{{asUpperCamelCase ../clusterName preserveAcronyms=true}}{{/inline~}}
108+
{{~#*inline "command"}}{{asUpperCamelCase label preserveAcronyms=true}}{{/inline~}}
109+
{{#if (and (isSupported (asUpperCamelCase ../clusterName preserveAcronyms=true) command=(asUpperCamelCase label preserveAcronyms=true) isForIds=true)
110+
(isStrEqual source ../../../source))}}
111+
case MTRCommandIDTypeCluster{{>cluster}}Command{{>command}}ID:
112+
result = @"{{>command}}";
113+
break;
114+
115+
{{/if}}
116+
{{/zcl_commands}}
117+
{{/inline}}
118+
119+
{{> commandIDs clusterName=label}}
120+
121+
default:
122+
result = [NSString stringWithFormat:@"<Unknown commandID %d>", commandID];
123+
break;
124+
}
125+
break;
126+
{{/if}}
127+
128+
{{/zcl_clusters}}
129+
default:
130+
result = [NSString stringWithFormat:@"<Unknown clusterID %d>", clusterID];
131+
break;
132+
}
133+
134+
return result;
135+
{{/inline}}
136+
137+
NSString * MTRRequestCommandNameForID(MTRClusterIDType clusterID, MTRCommandIDType commandID)
138+
{
139+
{{> commandIDOutput source="client"}}
140+
}
141+
142+
NSString * MTRResponseCommandNameForID(MTRClusterIDType clusterID, MTRCommandIDType commandID)
143+
{
144+
{{> commandIDOutput source="server"}}
145+
}
90146

91147
#pragma mark - Event IDs
92148

0 commit comments

Comments
 (0)