Skip to content

Commit 80dfe7a

Browse files
authored
Fix the ordering of the device types using endpoint type device's device order. (#1421)
- Update query-endpoint-type and query-impexp with device type order such that ordering of device types is retained as per the order in the .zap file - Minor cleanup in unify workflow - Adding tests for primary device type ordering - Github: ZAP#1119
1 parent f8cf2ef commit 80dfe7a

File tree

6 files changed

+7399
-17659
lines changed

6 files changed

+7399
-17659
lines changed

.github/workflows/unify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ env:
1818
KEYCHAIN_PASSWORD: silabs
1919

2020
jobs:
21-
prepare-zap-and-regenerate-zigbee:
21+
prepare-zap-and-regenerate-unify:
2222
name: Prepare Zap and regenerate Unify
2323
runs-on: ${{ matrix.os }}
2424

src-electron/db/db-mapping.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ exports.map = {
451451
code: x.CODE,
452452
profileId: x.PROFILE_ID,
453453
label: x.NAME,
454-
name: x.NAME
454+
name: x.NAME,
455+
deviceTypeOrder: x.DEVICE_TYPE_ORDER
455456
}
456457
},
457458

src-electron/db/query-endpoint-type.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ WHERE SESSION_PARTITION.SESSION_REF = ? ORDER BY NAME`,
101101
SESSION_PARTITION.SESSION_REF = ?
102102
AND ENDPOINT_TYPE_DEVICE.ENDPOINT_TYPE_REF = ?
103103
ORDER BY
104+
ENDPOINT_TYPE_DEVICE.DEVICE_TYPE_ORDER,
104105
DEVICE_TYPE.NAME,
105106
DEVICE_TYPE.CODE,
106107
DEVICE_TYPE.PROFILE_ID`,

src-electron/db/query-impexp.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ ORDER BY
185185
DEVICE_TYPE.CODE,
186186
DEVICE_TYPE.NAME,
187187
DEVICE_TYPE.PROFILE_ID,
188+
ENDPOINT_TYPE_DEVICE.DEVICE_TYPE_ORDER,
188189
ENDPOINT_TYPE_DEVICE.DEVICE_VERSION
189190
FROM
190191
DEVICE_TYPE
@@ -204,6 +205,7 @@ ORDER BY
204205
SESSION_PARTITION.SESSION_REF = ?
205206
AND ENDPOINT_TYPE_DEVICE.ENDPOINT_TYPE_REF = ?
206207
ORDER BY
208+
ENDPOINT_TYPE_DEVICE.DEVICE_TYPE_ORDER,
207209
DEVICE_TYPE.NAME,
208210
DEVICE_TYPE.CODE,
209211
DEVICE_TYPE.PROFILE_ID`,
@@ -332,7 +334,7 @@ async function importEndpointType(
332334
[
333335
endpointTypeId,
334336
row.DEVICE_TYPE_ID,
335-
i,
337+
deviceTypes[i].deviceTypeOrder ? deviceTypes[i].deviceTypeOrder : i, // backwards compatibility when device type order is not present in a .zap file
336338
deviceVersions[i] ? deviceVersions[i] : 0,
337339
deviceIdentifiers[i]
338340
]

test/gen-matter-3-1.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,32 @@ test(
340340
expect(ept).toContain('Endpoint 2, DeviceId: 256, DeviceVersion: 1')
341341
expect(ept).toContain('Endpoint 2, DeviceId: 257, DeviceVersion: 1')
342342
expect(ept).toContain('Endpoint 65534, DeviceId: 61442, DeviceVersion: 1')
343+
344+
// Testing order of device types in different endpoints and making sure the
345+
// device type order is maintained for primary device type
346+
let epts = await queryEndpointType.selectAllEndpointTypes(db, sessionId)
347+
expect(epts.length).toEqual(4)
348+
let endpointType1 = ''
349+
let endpointType2 = ''
350+
let i = 1
351+
for (const et of epts) {
352+
if (et.deviceTypeRef.length == 2) {
353+
if (i == 1) {
354+
endpointType1 = et
355+
i++
356+
} else if (i == 2) {
357+
endpointType2 = et
358+
i++
359+
}
360+
}
361+
}
362+
// In the .zap configuration the endpoint types have alternate primary endpoints(reverse device type order)
363+
expect(endpointType1.deviceTypeRef[0]).toEqual(
364+
endpointType2.deviceTypeRef[1]
365+
)
366+
expect(endpointType1.deviceTypeRef[1]).toEqual(
367+
endpointType2.deviceTypeRef[0]
368+
)
343369
},
344370
testUtil.timeout.long()
345371
)

0 commit comments

Comments
 (0)