You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding upgrade rule mechanism in ZAP for SDKs (#1589)
- Users can now include an upgrade rules json file in the zcl.json file which has a list of all the upgrade rules that may be needed when a user updates an existing app from one version of the GSDK to another.
- The upgrade rules json file lists a set of upgrade rules scripts with their priority as can be seen in upgrade-rules.json file. The scripts are run in order of priority with lower number signifying higher priority
- The upgrade rules return an object including a message and status which helps determine if an upgrade rules was actually executed or not. These results can be output into a yaml file if required for post analysis on which upgrade rules ran on a certain .zap file once the GSDK was updated.
- Adding unit tests to update cluster revision attribute of all clusters
- Handling the multi protocol use case and adding unit tests that make sure that only the appropriate endpoints are updated when upgrade rules json files from both zigbee and matter exist
- Adding unit tests for matter only .zap file
- Adding documentation on how to add upgrade rules to your SDK
- Adding the update keys available to the context in postLoad
- Add unit tests to check the order in which the upgrade rules were run
- Github: ZAP#1020
Upgrading ZAP files is a critical step when transitioning to newer versions of the SDK. This process ensures compatibility with the latest features, bug fixes, and improvements provided by the SDK. By following the upgrade guidelines, you can maintain the integrity of your ZAP configuration files and avoid potential issues during development or deployment. This document outlines the steps and best practices for performing ZAP file upgrades effectively.
6
+
7
+
## How to upgrade the ZAP File?
8
+
9
+
Run the following command to update your .zap file
10
+
11
+
```bash
12
+
"${Path to ZAP executable} upgrade --results ${path to .yaml file to see results of upgrade} -d ${directory containing ZAP files} --zcl ${path to zcl json file} --generationTemplate ${path to templates json file} --noLoadingFailure"
13
+
```
14
+
15
+
## How to add upgrade rules for .zap files through your SDK
16
+
17
+
### - Create an `upgrade-rules.json` file with the following information if one already does not exist
18
+
19
+
```json
20
+
{
21
+
"version": 1,
22
+
"description": "Upgrade Rules for Zigbee .zap files",
**category**: Determines that these upgrade rules need to run for matter.
38
+
39
+
**upgradeRuleScripts**: List of upgrade rules to run on .zap files. Includes the relative path from upgrade-rules.json to the upgrade scripts written in Javascript. Priority determines the order of execution for the upgrade rules. The scripts are run in order of priority with lower number signifying higher priority.
40
+
41
+
### - Add relative path to the upgrade-rules.json from your zcl.json file
42
+
43
+
```json
44
+
"upgradeRules": "./upgrade-rules-matter.json"
45
+
```
46
+
47
+
### - Creating your own javascript upgrade rule
48
+
49
+
Add a postLoad function as below with api and context as parameters. Api argument gives access to all APIs that can be used within the `postLoad` function. [Refer to the post-import API documentation](../src-electron/util/post-import-api.js) . Context gives the state of the Data-Model/ZCL with respect to the .zap file that will be passied along to the API calls.
50
+
51
+
```javascript
52
+
// Example upgrade rule to update default value of Level Control cluster attribute in Matter.
53
+
asyncfunctionpostLoad(api, context) {
54
+
let resMsg =''
55
+
let epts =awaitapi.endpoints(context)
56
+
for (let i =0; i <epts.length; i++) {
57
+
let clusters =awaitapi.clusters(context, epts[i])
58
+
for (let j =0; j <clusters.length; j++) {
59
+
if (clusters[j].code=='0x0008') {
60
+
let attributes =awaitapi.attributes(context, epts[i], clusters[j])
61
+
for (let k =0; k <attributes.length; k++) {
62
+
let attributeCode =parseInt(attributes[k].code)
63
+
let attributeValue =parseInt(attributes[k].defaultValue)
resMsg +=`Current Value attribute's default value updated to 10 for Level Control cluster on endpoint ${epts[i].endpointIdentifier}${epts[i].category}\n`
82
+
}
83
+
}
84
+
}
85
+
}
86
+
}
87
+
return { message: resMsg, status:'automatic' } // Status can be 'nothing', 'automatic', 'user_verification', 'impossible'.
0 commit comments