Skip to content

Commit 14050e7

Browse files
authored
Add helper to determine the atomic identifier for attribute Id given (#1476)
- as_underlying_atomic_identifier_for_attributeId checks for the attribute type and returns the atomic identifier associated with it. - JIRA: ZAPP-1385
1 parent baa3034 commit 14050e7

File tree

7 files changed

+147
-13
lines changed

7 files changed

+147
-13
lines changed

apack.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Graphical configuration tool for application and libraries based on Zigbee Cluster Library.",
55
"path": [".", "node_modules/.bin/", "ZAP.app/Contents/MacOS"],
66
"requiredFeatureLevel": "apack.core:9",
7-
"featureLevel": 105,
7+
"featureLevel": 106,
88
"uc.triggerExtension": "zap",
99
"executable": {
1010
"zap:win32.x86_64": {

docs/api.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8448,6 +8448,7 @@ This module contains the API for templating. For more detailed instructions, rea
84488448
* [Templating API: Attribute helpers](#module_Templating API_ Attribute helpers)
84498449
* [~featureBits(options)](#module_Templating API_ Attribute helpers..featureBits) ⇒
84508450
* [~attributeDefault()](#module_Templating API_ Attribute helpers..attributeDefault) ⇒
8451+
* [~as_underlying_atomic_identifier_for_attribute_id(attributeId)](#module_Templating API_ Attribute helpers..as_underlying_atomic_identifier_for_attribute_id)
84518452

84528453
<a name="module_Templating API_ Attribute helpers..featureBits"></a>
84538454

@@ -8468,6 +8469,18 @@ Valid within a cluster context, requires code.
84688469

84698470
**Kind**: inner method of [<code>Templating API: Attribute helpers</code>](#module_Templating API_ Attribute helpers)
84708471
**Returns**: Produces attribute defaults.
8472+
<a name="module_Templating API_ Attribute helpers..as_underlying_atomic_identifier_for_attribute_id"></a>
8473+
8474+
### Templating API: Attribute helpers~as\_underlying\_atomic\_identifier\_for\_attribute\_id(attributeId)
8475+
Given an attribute Id determine its corresponding atomic identifier from the
8476+
atomic table.
8477+
8478+
**Kind**: inner method of [<code>Templating API: Attribute helpers</code>](#module_Templating API_ Attribute helpers)
8479+
8480+
| Param | Type |
8481+
| --- | --- |
8482+
| attributeId | <code>\*</code> |
8483+
84718484
<a name="module_Templating API_ C formatting helpers"></a>
84728485

84738486
## Templating API: C formatting helpers

docs/helpers.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ This module contains the API for templating. For more detailed instructions, rea
127127
* [Templating API: Attribute helpers](#module_Templating API_ Attribute helpers)
128128
* [~featureBits(options)](#module_Templating API_ Attribute helpers..featureBits) ⇒
129129
* [~attributeDefault()](#module_Templating API_ Attribute helpers..attributeDefault) ⇒
130+
* [~as_underlying_atomic_identifier_for_attribute_id(attributeId)](#module_Templating API_ Attribute helpers..as_underlying_atomic_identifier_for_attribute_id)
130131

131132
<a name="module_Templating API_ Attribute helpers..featureBits"></a>
132133

@@ -147,6 +148,18 @@ Valid within a cluster context, requires code.
147148

148149
**Kind**: inner method of [<code>Templating API: Attribute helpers</code>](#module_Templating API_ Attribute helpers)
149150
**Returns**: Produces attribute defaults.
151+
<a name="module_Templating API_ Attribute helpers..as_underlying_atomic_identifier_for_attribute_id"></a>
152+
153+
### Templating API: Attribute helpers~as\_underlying\_atomic\_identifier\_for\_attribute\_id(attributeId)
154+
Given an attribute Id determine its corresponding atomic identifier from the
155+
atomic table.
156+
157+
**Kind**: inner method of [<code>Templating API: Attribute helpers</code>](#module_Templating API_ Attribute helpers)
158+
159+
| Param | Type |
160+
| --- | --- |
161+
| attributeId | <code>\*</code> |
162+
150163
<a name="module_Templating API_ C formatting helpers"></a>
151164

152165
## Templating API: C formatting helpers

src-electron/generator/helper-attribute.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
*/
2323

2424
const queryAttribute = require('../db/query-attribute')
25+
const queryZcl = require('../db/query-zcl')
2526
const templateUtil = require('./template-util')
27+
const zclUtil = require('../util/zcl-util')
28+
const dbEnum = require('../../src-shared/db-enum')
2629

2730
/**
2831
* Get feature bits from the given context.
@@ -76,6 +79,89 @@ async function attributeDefault(options) {
7679
return templateUtil.templatePromise(this.global, p)
7780
}
7881

82+
/**
83+
* Given an attribute Id determine its corresponding atomic identifier from the
84+
* atomic table.
85+
* @param {*} attributeId
86+
*/
87+
async function as_underlying_atomic_identifier_for_attribute_id(attributeId) {
88+
let attributeDetails =
89+
await queryZcl.selectAttributeByAttributeIdAndClusterRef(
90+
this.global.db,
91+
attributeId,
92+
null
93+
)
94+
let atomicInfo = attributeDetails
95+
? await queryZcl.selectAtomicType(
96+
this.global.db,
97+
[attributeDetails.packageRef],
98+
attributeDetails.type
99+
)
100+
: null
101+
// If attribute type directly points to the atomic type then return that
102+
if (atomicInfo) {
103+
// All types in the number and string table should be found here.
104+
return atomicInfo.atomicId
105+
} else {
106+
// If attribute type does not point to atomic type
107+
let dataType = await queryZcl.selectDataTypeByNameAndClusterId(
108+
this.global.db,
109+
attributeDetails.type,
110+
attributeDetails.clusterRef,
111+
[attributeDetails.packageRef]
112+
)
113+
if (dataType.discriminatorName.toLowerCase() == dbEnum.zclType.enum) {
114+
let enumInfo = await queryZcl.selectEnumByNameAndClusterId(
115+
this.global.db,
116+
attributeDetails.type,
117+
attributeDetails.clusterRef,
118+
[attributeDetails.packageRef]
119+
)
120+
atomicInfo = await queryZcl.selectAtomicType(
121+
this.global.db,
122+
[attributeDetails.packageRef],
123+
dbEnum.zclType.enum + enumInfo.size * 8
124+
)
125+
return atomicInfo ? atomicInfo.atomicId : null
126+
} else if (
127+
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.bitmap
128+
) {
129+
let bitmapInfo = await queryZcl.selectBitmapByNameAndClusterId(
130+
this.global.db,
131+
attributeDetails.type,
132+
attributeDetails.clusterRef,
133+
[attributeDetails.packageRef]
134+
)
135+
atomicInfo = await queryZcl.selectAtomicType(
136+
this.global.db,
137+
[attributeDetails.packageRef],
138+
dbEnum.zclType.bitmap + bitmapInfo.size * 8
139+
)
140+
return atomicInfo ? atomicInfo.atomicId : null
141+
} else if (
142+
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.struct
143+
) {
144+
atomicInfo = await queryZcl.selectAtomicType(
145+
this.global.db,
146+
[attributeDetails.packageRef],
147+
dbEnum.zclType.struct
148+
)
149+
return atomicInfo ? atomicInfo.atomicId : null
150+
} else if (
151+
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.array
152+
) {
153+
atomicInfo = await queryZcl.selectAtomicType(
154+
this.global.db,
155+
[attributeDetails.packageRef],
156+
dbEnum.zclType.array
157+
)
158+
return atomicInfo ? atomicInfo.atomicId : null
159+
} else {
160+
return null
161+
}
162+
}
163+
}
164+
79165
// WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
80166
//
81167
// Note: these exports are public API. Templates that might have been created in the past and are
@@ -84,3 +170,5 @@ async function attributeDefault(options) {
84170

85171
exports.global_attribute_default = attributeDefault
86172
exports.feature_bits = featureBits
173+
exports.as_underlying_atomic_identifier_for_attribute_id =
174+
as_underlying_atomic_identifier_for_attribute_id

test/gen-template/zigbee/zap-config-version-3.zapt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@
298298
#define GENERATED_MULTI_PROTOCOL_ATTRIBUTE_MAPPING
299299
{
300300
{{#all_multi_protocol_attributes}}
301-
{ {{clusterCode1}}, {{clusterMfgCode1}}, {{clusterCode2}}, {{clusterMfgCode2}}, {{attributeCode1}}, {{attributeMfgCode1}}, {{attributeCode2}}, {{attributeMfgCode2}} },
301+
{ {{clusterCode1}}, {{clusterMfgCode1}}, {{clusterCode2}}, {{clusterMfgCode2}}, {{attributeCode1}}, {{attributeMfgCode1}}, {{as_underlying_atomic_identifier_for_attribute_id attributeRef1}}, {{attributeCode2}}, {{attributeMfgCode2}}, {{as_underlying_atomic_identifier_for_attribute_id attributeRef2}} },
302302
{{/all_multi_protocol_attributes}}
303303
}
304304
{{/if_multi_protocol_attributes_enabled}}

test/multi-protocol.test.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,18 @@ test(
159159
expect(zigbeeEndpointConfigGen).toContain(
160160
'#define GENERATED_MULTI_PROTOCOL_ATTRIBUTE_MAPPING'
161161
)
162-
expect(zigbeeEndpointConfigGen).toContain('{ 6, 0, 6, 0, 0, 0, 0, 0 },')
163-
expect(zigbeeEndpointConfigGen).toContain('{ 8, 0, 8, 0, 0, 0, 0, 0 },')
164-
expect(zigbeeEndpointConfigGen).toContain('{ 8, 0, 8, 0, 1, 0, 1, 0 },')
162+
expect(zigbeeEndpointConfigGen).toContain(
163+
'{ 6, 0, 6, 0, 0, 0, 16, 0, 0, 16 },'
164+
)
165+
expect(zigbeeEndpointConfigGen).toContain(
166+
'{ 8, 0, 8, 0, 0, 0, 32, 0, 0, 32 },'
167+
)
168+
expect(zigbeeEndpointConfigGen).toContain(
169+
'{ 8, 0, 8, 0, 1, 0, 33, 1, 0, 33 },'
170+
)
171+
expect(zigbeeEndpointConfigGen).toContain(
172+
'{ 6, 0, 6, 0, 16387, 0, 48, 16387, 0, 48 },'
173+
)
165174

166175
// Notifications test when opening multi-protocol zap file
167176
let sessionNotifications = await querySessionNotice.getNotification(
@@ -220,7 +229,7 @@ test(
220229
let importRes = await importJs.importDataFromFile(
221230
db,
222231
multiProtocolTestFile,
223-
{ sessionId: null },
232+
{ sessionId: null }
224233
)
225234

226235
// Get all session attributes
@@ -242,14 +251,14 @@ test(
242251
// Check both of them are the same
243252
expect(parseInt(zigbeeEndpointTypeAttribute.defaultValue)).toEqual(0)
244253
expect(parseInt(zigbeeEndpointTypeAttribute.defaultValue)).toEqual(
245-
parseInt(matterEndpointTypeAttribute.defaultValue),
254+
parseInt(matterEndpointTypeAttribute.defaultValue)
246255
)
247256

248257
// Change zigbee ETA and check for the change in the corresponding Matter ETA.
249258
await queryConfig.updateEndpointTypeAttribute(
250259
db,
251260
zigbeeEndpointTypeAttribute.endpointTypeAttributeId,
252-
[['defaultValue', 1]],
261+
[['defaultValue', 1]]
253262
)
254263
let allEndpointTypeAttributesAfterChange =
255264
await queryConfig.selectAllSessionAttributes(db, importRes.sessionId)
@@ -263,7 +272,7 @@ test(
263272
}
264273
expect(parseInt(zigbeeEndpointTypeAttribute.defaultValue)).toEqual(1)
265274
expect(parseInt(zigbeeEndpointTypeAttribute.defaultValue)).toEqual(
266-
parseInt(matterEndpointTypeAttribute.defaultValue),
275+
parseInt(matterEndpointTypeAttribute.defaultValue)
267276
)
268277

269278
// Negative test: Check that none of the other Endpoint Type Attribute values are not changed. Only the ones intended i.e. on/off
@@ -273,7 +282,7 @@ test(
273282
allEndpointTypeAttributes[i].name.toLowerCase() != 'onoff'
274283
) {
275284
expect(allEndpointTypeAttributes[i].defaultValue).toEqual(
276-
allEndpointTypeAttributesAfterChange[i].defaultValue,
285+
allEndpointTypeAttributesAfterChange[i].defaultValue
277286
)
278287
}
279288
}
@@ -282,7 +291,7 @@ test(
282291
await queryConfig.updateEndpointTypeAttribute(
283292
db,
284293
matterEndpointTypeAttribute.endpointTypeAttributeId,
285-
[['defaultValue', 0]],
294+
[['defaultValue', 0]]
286295
)
287296
allEndpointTypeAttributesAfterChange =
288297
await queryConfig.selectAllSessionAttributes(db, importRes.sessionId)
@@ -296,8 +305,8 @@ test(
296305
}
297306
expect(parseInt(matterEndpointTypeAttribute.defaultValue)).toEqual(0)
298307
expect(parseInt(matterEndpointTypeAttribute.defaultValue)).toEqual(
299-
parseInt(zigbeeEndpointTypeAttribute.defaultValue),
308+
parseInt(zigbeeEndpointTypeAttribute.defaultValue)
300309
)
301310
},
302-
testUtil.timeout.long(),
311+
testUtil.timeout.long()
303312
)

zcl-builtin/silabs/multi-protocol.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
"code": "0x0000",
2323
"manufacturerCode": null
2424
}
25+
},
26+
{
27+
"id": 2,
28+
"matter": {
29+
"code": "0x4003",
30+
"manufacturerCode": null
31+
},
32+
"zigbee": {
33+
"code": "0x4003",
34+
"manufacturerCode": null
35+
}
2536
}
2637
]
2738
},

0 commit comments

Comments
 (0)