Skip to content

Commit

Permalink
Adding Helpers for Outgoing cluster commands and adding tests for the…
Browse files Browse the repository at this point in the history
… same

GITHUB: project-chip#342
  • Loading branch information
brdandu committed Jan 24, 2022
1 parent 062c238 commit 32dd89c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 66 deletions.
122 changes: 58 additions & 64 deletions src-electron/db/query-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ async function selectAllClustersWithIncomingOrOutgoingCommands(
) {
let endpointTypeIds = endpointTypes.map((ep) => ep.endpointTypeId).toString()
let sqlGroupBy = uniqueClusterCodes ? 'CLUSTER.CODE' : 'CLUSTER.NAME'
let isIncomingSql = isIncoming
? `ENDPOINT_TYPE_COMMAND.INCOMING = 1 `
: `ENDPOINT_TYPE_COMMAND.OUTGOING = 1 `
let isIncomingOrOutgoingSql = isIncoming
? `ENDPOINT_TYPE_COMMAND.INCOMING = 1 AND COMMAND.SOURCE != ENDPOINT_TYPE_CLUSTER.SIDE`
: `ENDPOINT_TYPE_COMMAND.OUTGOING = 1 AND COMMAND.SOURCE == ENDPOINT_TYPE_CLUSTER.SIDE`
let mapFunction = (x) => {
return {
id: x.CLUSTER_ID,
Expand All @@ -232,46 +232,43 @@ async function selectAllClustersWithIncomingOrOutgoingCommands(
endpointClusterId: x.ENDPOINT_TYPE_CLUSTER_ID,
}
}

return dbApi
.dbAll(
db,
`
SELECT
CLUSTER.CLUSTER_ID,
CLUSTER.NAME AS CLUSTER_NAME,
CLUSTER.CODE AS CLUSTER_CODE,
CLUSTER.DEFINE AS CLUSTER_DEFINE,
CLUSTER.MANUFACTURER_CODE AS MANUFACTURER_CODE,
ENDPOINT_TYPE_CLUSTER.SIDE AS CLUSTER_SIDE,
ENDPOINT_TYPE_CLUSTER.ENABLED AS CLUSTER_ENABLED,
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID
CLUSTER.CLUSTER_ID,
CLUSTER.NAME AS CLUSTER_NAME,
CLUSTER.CODE AS CLUSTER_CODE,
CLUSTER.DEFINE AS CLUSTER_DEFINE,
CLUSTER.MANUFACTURER_CODE AS MANUFACTURER_CODE,
ENDPOINT_TYPE_CLUSTER.SIDE AS CLUSTER_SIDE,
ENDPOINT_TYPE_CLUSTER.ENABLED AS CLUSTER_ENABLED,
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID
FROM
COMMAND
COMMAND
INNER JOIN
ENDPOINT_TYPE_COMMAND
ENDPOINT_TYPE_COMMAND
ON
ENDPOINT_TYPE_COMMAND.COMMAND_REF = COMMAND.COMMAND_ID
ENDPOINT_TYPE_COMMAND.COMMAND_REF = COMMAND.COMMAND_ID
INNER JOIN
CLUSTER
CLUSTER
ON
CLUSTER.CLUSTER_ID = COMMAND.CLUSTER_REF
CLUSTER.CLUSTER_ID = COMMAND.CLUSTER_REF
INNER JOIN
ENDPOINT_TYPE_CLUSTER
ENDPOINT_TYPE_CLUSTER
ON
ENDPOINT_TYPE_CLUSTER.CLUSTER_REF = CLUSTER.CLUSTER_ID
ENDPOINT_TYPE_CLUSTER.CLUSTER_REF = CLUSTER.CLUSTER_ID
WHERE
ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_REF IN (${endpointTypeIds})
AND ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_REF = ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_REF
AND ENDPOINT_TYPE_CLUSTER.SIDE IN ("client", "server")
AND ENDPOINT_TYPE_CLUSTER.ENABLED = 1 AND ${isIncomingSql}
AND COMMAND.SOURCE != ENDPOINT_TYPE_CLUSTER.SIDE
ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_REF IN (${endpointTypeIds})
AND ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_REF = ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_REF
AND ENDPOINT_TYPE_CLUSTER.SIDE IN ("client", "server")
AND ENDPOINT_TYPE_CLUSTER.ENABLED = 1 AND ${isIncomingOrOutgoingSql}
GROUP BY
${sqlGroupBy}, ENDPOINT_TYPE_CLUSTER.SIDE ORDER BY CLUSTER.NAME, ENDPOINT_TYPE_CLUSTER.SIDE`
${sqlGroupBy}, ENDPOINT_TYPE_CLUSTER.SIDE ORDER BY CLUSTER.NAME, ENDPOINT_TYPE_CLUSTER.SIDE`
)
.then((rows) => rows.map(mapFunction))
}

/**
* All Clusters with available incoming commands.
* @param db
Expand All @@ -298,7 +295,6 @@ async function selectAllClustersWithIncomingCommands(
true
)
}

/**
* All Clusters with available outgoing commands.
* @param db
Expand Down Expand Up @@ -525,9 +521,9 @@ async function selectAllIncomingOrOutgoingCommandsForCluster(
: isMfgSpecific
? ` AND COMMAND.MANUFACTURER_CODE IS NOT NULL `
: ` AND COMMAND.MANUFACTURER_CODE IS NULL `
let isIncomingSql = isIncoming
? `ENDPOINT_TYPE_COMMAND.INCOMING=1 `
: `ENDPOINT_TYPE_COMMAND.OUTGOING=1 `
let isIncomingOrOutgoingSql = isIncoming
? `ENDPOINT_TYPE_COMMAND.INCOMING=1 AND COMMAND.SOURCE!=ENDPOINT_TYPE_CLUSTER.SIDE`
: `ENDPOINT_TYPE_COMMAND.OUTGOING=1 AND COMMAND.SOURCE==ENDPOINT_TYPE_CLUSTER.SIDE`
let mapFunction = (x) => {
return {
clusterId: x.CLUSTER_ID,
Expand All @@ -549,42 +545,40 @@ async function selectAllIncomingOrOutgoingCommandsForCluster(
mfgCommandCount: x.MANUFACTURING_SPECIFIC_COMMAND_COUNT,
}
}

return dbApi
.dbAll(
db,
`
SELECT
CLUSTER.CLUSTER_ID,
CLUSTER.NAME AS CLUSTER_NAME,
CLUSTER.CODE AS CLUSTER_CODE,
CLUSTER.DEFINE AS CLUSTER_DEFINE,
COMMAND.MANUFACTURER_CODE AS COMMAND_MANUFACTURER_CODE,
ENDPOINT_TYPE_CLUSTER.SIDE AS CLUSTER_SIDE,
ENDPOINT_TYPE_CLUSTER.ENABLED AS CLUSTER_ENABLED,
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID,
COUNT(*) OVER (PARTITION BY CLUSTER.NAME, COMMAND.NAME) AS NO_OF_CLUSTER_SIDES_ENABLED,
COMMAND.COMMAND_ID AS COMMAND_ID,
COMMAND.NAME AS COMMAND_NAME,
COMMAND.SOURCE AS COMMAND_SOURCE,
COMMAND.CODE AS COMMAND_CODE,
COMMAND.MUST_USE_TIMED_INVOKE AS MUST_USE_TIMED_INVOKE,
ENDPOINT_TYPE_COMMAND.INCOMING AS INCOMING,
ENDPOINT_TYPE_COMMAND.OUTGOING AS OUTGOING,
COUNT(COMMAND.MANUFACTURER_CODE) OVER () AS MANUFACTURING_SPECIFIC_COMMAND_COUNT
FROM COMMAND
INNER JOIN ENDPOINT_TYPE_COMMAND
ON ENDPOINT_TYPE_COMMAND.COMMAND_REF = COMMAND.COMMAND_ID
INNER JOIN CLUSTER
ON CLUSTER.CLUSTER_ID = COMMAND.CLUSTER_REF
INNER JOIN ENDPOINT_TYPE_CLUSTER
ON ENDPOINT_TYPE_CLUSTER.CLUSTER_REF = CLUSTER.CLUSTER_ID
WHERE ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_REF IN (${endpointTypeIds})
AND ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_REF = ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_REF
AND ENDPOINT_TYPE_CLUSTER.SIDE IN ("client", "server") AND ENDPOINT_TYPE_CLUSTER.ENABLED=1 AND ${isIncomingSql}
AND COMMAND.SOURCE!=ENDPOINT_TYPE_CLUSTER.SIDE
AND CLUSTER.NAME = "${clName}" AND ENDPOINT_TYPE_CLUSTER.SIDE = "${clSide}"
${mfgSpecificString} GROUP BY COMMAND.NAME`
SELECT
CLUSTER.CLUSTER_ID,
CLUSTER.NAME AS CLUSTER_NAME,
CLUSTER.CODE AS CLUSTER_CODE,
CLUSTER.DEFINE AS CLUSTER_DEFINE,
COMMAND.MANUFACTURER_CODE AS COMMAND_MANUFACTURER_CODE,
ENDPOINT_TYPE_CLUSTER.SIDE AS CLUSTER_SIDE,
ENDPOINT_TYPE_CLUSTER.ENABLED AS CLUSTER_ENABLED,
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID,
COUNT(*) OVER (PARTITION BY CLUSTER.NAME, COMMAND.NAME) AS NO_OF_CLUSTER_SIDES_ENABLED,
COMMAND.COMMAND_ID AS COMMAND_ID,
COMMAND.NAME AS COMMAND_NAME,
COMMAND.SOURCE AS COMMAND_SOURCE,
COMMAND.CODE AS COMMAND_CODE,
COMMAND.MUST_USE_TIMED_INVOKE AS MUST_USE_TIMED_INVOKE,
ENDPOINT_TYPE_COMMAND.INCOMING AS INCOMING,
ENDPOINT_TYPE_COMMAND.OUTGOING AS OUTGOING,
COUNT(COMMAND.MANUFACTURER_CODE) OVER () AS MANUFACTURING_SPECIFIC_COMMAND_COUNT
FROM COMMAND
INNER JOIN ENDPOINT_TYPE_COMMAND
ON ENDPOINT_TYPE_COMMAND.COMMAND_REF = COMMAND.COMMAND_ID
INNER JOIN CLUSTER
ON CLUSTER.CLUSTER_ID = COMMAND.CLUSTER_REF
INNER JOIN ENDPOINT_TYPE_CLUSTER
ON ENDPOINT_TYPE_CLUSTER.CLUSTER_REF = CLUSTER.CLUSTER_ID
WHERE ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_REF IN (${endpointTypeIds})
AND ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_REF = ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_REF
AND ENDPOINT_TYPE_CLUSTER.SIDE IN ("client", "server") AND ENDPOINT_TYPE_CLUSTER.ENABLED=1 AND ${isIncomingOrOutgoingSql}
AND CLUSTER.NAME = "${clName}" AND ENDPOINT_TYPE_CLUSTER.SIDE = "${clSide}"
${mfgSpecificString} GROUP BY COMMAND.NAME`
)
.then((rows) => rows.map(mapFunction))
}
Expand All @@ -596,7 +590,7 @@ async function selectAllIncomingOrOutgoingCommandsForCluster(
* @param clName
* @param clSide
* @param isMfgSpecific
* @returns Incoming Commands for a cluster
* @returns Incoming Commands for a given cluster
*/
async function selectAllIncomingCommandsForCluster(
db,
Expand All @@ -622,7 +616,7 @@ async function selectAllIncomingCommandsForCluster(
* @param clName
* @param clSide
* @param isMfgSpecific
* @returns Outgoing Commands for a cluster
* @returns Outgoing Commands for a given cluster
*/
async function selectAllOutgoingCommandsForCluster(
db,
Expand Down
2 changes: 1 addition & 1 deletion test/gen-template/zigbee/zap-outgoing-command.zapt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{#all_user_clusters_with_outgoing_commands}}
{{clusterName}} Cluster Ougtoing commands
{{clusterName}} {{clusterSide}} Cluster Ougtoing commands
{{#all_outgoing_commands_for_cluster clusterName clusterSide isMfgSpecific="false"}}
Outgoing Command: {{commandName}}
{{/all_outgoing_commands_for_cluster}}
Expand Down
2 changes: 1 addition & 1 deletion test/gen-zigbee.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ test(
let zapOutgoingCommands = genResult.content['zap-outgoing-command.out']
expect(zapOutgoingCommands).not.toBeNull()
expect(zapOutgoingCommands).toContain(
'ZLL Commissioning Cluster Ougtoing commands\nOutgoing Command: DeviceInformationResponse\nOutgoing Command: EndpointInformation\nOutgoing Command: GetEndpointListResponse\nOutgoing Command: GetGroupIdentifiersResponse\nOutgoing Command: NetworkJoinEndDeviceResponse\nOutgoing Command: NetworkJoinRouterResponse\nOutgoing Command: NetworkStartResponse\nOutgoing Command: ScanResponse\nZLL Commissioning Cluster Ougtoing commands\nOutgoing Command: DeviceInformationRequest\nOutgoing Command: IdentifyRequest\nOutgoing Command: NetworkJoinEndDeviceRequest\nOutgoing Command: NetworkJoinRouterRequest\nOutgoing Command: NetworkStartRequest\nOutgoing Command: NetworkUpdateRequest\nOutgoing Command: ResetToFactoryNewRequest\nOutgoing Command: ScanRequest\n'
'Groups client Cluster Ougtoing commands\nOutgoing Command: AddGroup\nOutgoing Command: AddGroupIfIdentifying\nOutgoing Command: GetGroupMembership\nOutgoing Command: RemoveAllGroups\nOutgoing Command: RemoveGroup\nOutgoing Command: ViewGroup\nGroups server Cluster Ougtoing commands\nOutgoing Command: AddGroupResponse\nOutgoing Command: GetGroupMembershipResponse\nOutgoing Command: RemoveGroupResponse\nOutgoing Command: ViewGroupResponse\nIdentify client Cluster Ougtoing commands\nOutgoing Command: Identify\nOutgoing Command: IdentifyQuery\nIdentify server Cluster Ougtoing commands\nOutgoing Command: IdentifyQueryResponse\nLevel Control client Cluster Ougtoing commands\nOutgoing Command: Move\nOutgoing Command: MoveToLevel\nOutgoing Command: MoveToLevelWithOnOff\nOutgoing Command: MoveWithOnOff\nOutgoing Command: Step\nOutgoing Command: StepWithOnOff\nOutgoing Command: Stop\nOutgoing Command: StopWithOnOff\nOn/off client Cluster Ougtoing commands\nOutgoing Command: Off\nOutgoing Command: On\nOutgoing Command: Toggle\nScenes server Cluster Ougtoing commands\nOutgoing Command: AddSceneResponse\nOutgoing Command: GetSceneMembershipResponse\nOutgoing Command: RemoveAllScenesResponse\nOutgoing Command: RemoveSceneResponse\nOutgoing Command: StoreSceneResponse\nOutgoing Command: ViewSceneResponse\nZLL Commissioning client Cluster Ougtoing commands\nOutgoing Command: DeviceInformationRequest\nOutgoing Command: IdentifyRequest\nOutgoing Command: NetworkJoinEndDeviceRequest\nOutgoing Command: NetworkJoinRouterRequest\nOutgoing Command: NetworkStartRequest\nOutgoing Command: NetworkUpdateRequest\nOutgoing Command: ResetToFactoryNewRequest\nOutgoing Command: ScanRequest\nZLL Commissioning server Cluster Ougtoing commands\nOutgoing Command: DeviceInformationResponse\nOutgoing Command: EndpointInformation\nOutgoing Command: GetEndpointListResponse\nOutgoing Command: GetGroupIdentifiersResponse\nOutgoing Command: NetworkJoinEndDeviceResponse\nOutgoing Command: NetworkJoinRouterResponse\nOutgoing Command: NetworkStartResponse\nOutgoing Command: ScanResponse'
)
},
testUtil.timeout.long()
Expand Down

0 comments on commit 32dd89c

Please sign in to comment.