Skip to content
Merged
63 changes: 63 additions & 0 deletions .github/workflows/generate-types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Generate TypeScript Types

on:
push:
branches:
- develop
paths:
- 'lib/clusters/**/*.js'
- 'scripts/generate-types.js'

jobs:
generate-types:
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: develop
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Generate TypeScript types
run: npm run generate-types

- name: Validate TypeScript types compile
run: npx tsc --noEmit index.d.ts

- name: Check for changes
id: check-changes
run: |
if git diff --quiet index.d.ts; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "No changes to index.d.ts"
else
echo "changed=true" >> $GITHUB_OUTPUT
echo "index.d.ts has been updated"
git diff --stat index.d.ts
fi

- name: Commit and push changes
if: steps.check-changes.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add index.d.ts
git commit -m "chore(types): auto-generate TypeScript definitions

Updated by GitHub Actions after cluster changes.

[skip ci]"
git push origin develop
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,28 @@ zclNode.endpoints[1].clusters["scenes"].ikeaSceneMove({ mode: 0, transitionTime:

This also works for `BoundClusters`, if a node sends commands to Homey using a custom cluster it is necessary to implement a custom `BoundCluster` and bind it to the `ZCLNode` instance. For an example check the implementation in the `com.ikea.tradfri` driver [remote_control](https://github.com/athombv/com.ikea.tradfri-example/tree/master/drivers/remote_control/device.js).

## TypeScript Types

This project includes auto-generated TypeScript definitions (`index.d.ts`) for all clusters, attributes, and commands.

### Manual Generation

To regenerate TypeScript types after modifying cluster definitions:

```bash
npm run generate-types
```

This runs `scripts/generate-types.js` which loads all cluster modules and generates typed interfaces.

### Automatic Generation (GitHub Actions)

TypeScript types are automatically regenerated when changes are pushed to the `develop` branch that affect:
- `lib/clusters/**/*.js` - cluster definitions
- `scripts/generate-types.js` - the generator script

The workflow commits updated types back to `develop` if changes are detected.

## Contributing

Great if you'd like to contribute to this project, a few things to take note of before submitting a PR:
Expand Down
Loading