Skip to content

Commit 1079408

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Be a bit more consistent about type handling in ZAP templates. (#10718)
* Instead of checking for "item.type == 'boolean'", which would not work right for command args (where the type is "BOOLEAN"), go through our normal type-mapping machinery and then use the resulting uniform output. * Add "single" to our atomic type overrides and remove manual handling of it in zapTypeToClusterObjectType. This incidentally fixes all the generated accessors for single-typed attributes. * Fix a debugging exception message to include the value that could not be handled in a more-correct way.
1 parent 53ad500 commit 1079408

File tree

6 files changed

+485
-489
lines changed

6 files changed

+485
-489
lines changed

src/app/zap-templates/common/ClusterTestGeneration.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ function chip_tests_item_parameters(options)
426426
value = new Boolean(value);
427427
break;
428428
default:
429-
throw new Error('Unsupported value: ', value);
429+
throw new Error('Unsupported value: ' + JSON.stringify(value));
430430
}
431431
}
432432

src/app/zap-templates/common/ClustersHelper.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ function asChipCallback(item)
196196
return { name : 'List', type : null };
197197
}
198198

199-
if (item.type == 'boolean') {
200-
return { name : 'Boolean', type : 'bool' };
201-
}
202-
203199
const basicType = ChipTypesHelper.asBasicType(item.chipType);
204200
switch (basicType) {
205201
case 'int8_t':
@@ -212,6 +208,8 @@ function asChipCallback(item)
212208
case 'uint32_t':
213209
case 'uint64_t':
214210
return { name : 'Int' + basicType.replace(/[^0-9]/g, '') + 'u', type : basicType };
211+
case 'bool':
212+
return { name : 'Boolean', type : 'bool' };
215213
default:
216214
return { name : 'Unsupported', type : null };
217215
}

src/app/zap-templates/common/override.js

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ function atomicType(arg)
2020
switch (arg.name) {
2121
case 'boolean':
2222
return 'bool';
23+
case 'single':
24+
return 'float';
2325
case 'int40s':
2426
case 'int48s':
2527
case 'int56s':

src/app/zap-templates/templates/app/helper.js

-4
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,6 @@ function asMEI(prefix, suffix)
350350
*/
351351
async function zapTypeToClusterObjectType(type, isDecodable, options)
352352
{
353-
if (type == 'single') {
354-
return 'float';
355-
}
356-
357353
async function fn(pkgId)
358354
{
359355
const ns = options.hash.ns ? ('chip::app::Clusters::' + asUpperCamelCase(options.hash.ns) + '::') : '';

0 commit comments

Comments
 (0)